ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAdvancedMDRecordGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
34 {
35  const MODE_EDITOR = 1;
36  const MODE_SEARCH = 2;
37  const MODE_INFO = 3;
38 
39  protected $lng;
40 
41  private $mode;
42  private $obj_type;
43  private $obj_id;
44 
45  private $form;
46  private $values = array();
47  private $search_values = array();
48 
57  public function __construct($a_mode,$a_obj_type = '',$a_obj_id = '')
58  {
59  global $lng;
60 
61  $this->lng = $lng;
62  $this->mode = $a_mode;
63  $this->obj_type = $a_obj_type;
64  $this->obj_id = $a_obj_id;
65  }
66 
74  public function setPropertyForm($form)
75  {
76  $this->form = $form;
77  }
78 
85  public function setSearchValues($a_values)
86  {
87  $this->search_values = $a_values;
88  }
89 
90 
98  public function setInfoObject($info)
99  {
100  $this->info = $info;
101  }
102 
110  public function parse()
111  {
112  switch($this->mode)
113  {
114  case self::MODE_EDITOR:
115  return $this->parseEditor();
116 
117  case self::MODE_SEARCH:
118  return $this->parseSearch();
119 
120  case self::MODE_INFO:
121  return $this->parseInfoPage();
122 
123  default:
124  die('Not implemented yet');
125  }
126  }
127 
134  public function loadFromPost()
135  {
136  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php');
137  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
138 
139  if(!isset($_POST['md']))
140  {
141  return false;
142  }
143  foreach($_POST['md'] as $field_id => $value)
144  {
146  switch($def->getFieldType())
147  {
149 
150  if(is_array($value) and $_POST['md_activated'][$field_id])
151  {
152  $dt['year'] = (int) $value['date']['y'];
153  $dt['mon'] = (int) $value['date']['m'];
154  $dt['mday'] = (int) $value['date']['d'];
155  $dt['hours'] = (int) 0;
156  $dt['minutes'] = (int) 0;
157  $dt['seconds'] = (int) 0;
158  $date = new ilDate($dt,IL_CAL_FKT_GETDATE);
159  $value = $date->get(IL_CAL_UNIX);
160  }
161  else
162  {
163  $value = 0;
164  }
165  break;
166 
168 
169  if(is_array($value) and $_POST['md_activated'][$field_id])
170  {
171  $dt['year'] = (int) $value['date']['y'];
172  $dt['mon'] = (int) $value['date']['m'];
173  $dt['mday'] = (int) $value['date']['d'];
174  $dt['hours'] = (int) $value['time']['h'];
175  $dt['minutes'] = (int) $value['time']['m'];
176  $dt['seconds'] = (int) 0;
177  $date = new ilDateTime($dt,IL_CAL_FKT_GETDATE);
178  $value = $date->get(IL_CAL_UNIX);
179  }
180  else
181  {
182  $value = 0;
183  }
184  break;
185 
186  default:
187  $value = ilUtil::stripSlashes($value);
188  break;
189  }
190  $val = ilAdvancedMDValue::_getInstance($this->obj_id,$field_id);
191  $val->setValue($value);
192  $this->values[] = $val;
193  unset($value);
194  }
195  $this->loadECSDurationPost();
196  }
197 
205  protected function loadECSDurationPost()
206  {
207  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
208  include_once('./Services/WebServices/ECS/classes/class.ilECSSettings.php');
209 
210  if(!ilECSSettings::_getInstance()->isEnabled())
211  {
212  return false;
213  }
215 
216  if(!$start_id = $mapping->getMappingByECSName('begin'))
217  {
218  return false;
219  }
220  if(!$end_id = $mapping->getMappingByECSName('end'))
221  {
222  return false;
223  }
224  if(!$_POST['md_activated'][$start_id])
225  {
226  $end = 0;
227  }
228  else
229  {
230  $end = $this->toUnixTime($_POST['md'][$start_id]['date'],$_POST['md'][$start_id]['time']);
231  $end = $end + (60 * 60 * $_POST['ecs_duration']['hh']) + (60 * $_POST['ecs_duration']['mm']);
232  }
233  $val = ilAdvancedMDValue::_getInstance($this->obj_id,$end_id);
234  $val->setValue($end);
235  $this->values[] = $val;
236  return true;
237  }
238 
245  public function saveValues()
246  {
247  foreach($this->values as $value)
248  {
249  $value->save();
250  }
251  return true;
252  }
253 
260  private function parseEditor()
261  {
262  global $ilUser;
263 
264  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
265  foreach(ilAdvancedMDRecord::_getActivatedRecordsByObjectType($this->obj_type) as $record_obj)
266  {
267  $section = new ilFormSectionHeaderGUI();
268  $section->setTitle($record_obj->getTitle());
269  $section->setInfo($record_obj->getDescription());
270  $this->form->addItem($section);
271 
272  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
273  foreach(ilAdvancedMDFieldDefinition::_getDefinitionsByRecordId($record_obj->getRecordId()) as $def)
274  {
275  if($this->handleECSDefinitions($def))
276  {
277  continue;
278  }
279 
280  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php');
281  $value = ilAdvancedMDValue::_getInstance($this->obj_id,$def->getFieldId());
282 
283  switch($def->getFieldType())
284  {
286  $text = new ilTextInputGUI($def->getTitle(),'md['.$def->getFieldId().']');
287  $text->setValue($value->getValue());
288  $text->setSize(40);
289  $text->setMaxLength(512);
290  $text->setDisabled($value->isDisabled());
291  $text->setInfo($def->getDescription());
292  $this->form->addItem($text);
293  break;
294 
296  $select = new ilSelectInputGUI($def->getTitle(),'md['.$def->getFieldId().']');
297  $select->setOptions($def->getFieldValuesForSelect());
298  $select->setValue($value->getValue());
299  $select->setDisabled($value->isDisabled());
300  $select->setInfo($def->getDescription());
301 
302  $this->form->addItem($select);
303  break;
304 
306 
307  $unixtime = $value->getValue() ? $value->getValue() : mktime(8,0,0,date('m'),date('d'),date('Y'));
308 
309  $time = new ilDateTimeInputGUI($def->getTitle(),'md['.$def->getFieldId().']');
310  $time->setShowTime(false);
311  $time->setDate(new ilDate($unixtime,IL_CAL_UNIX));
312  $time->enableDateActivation($this->lng->txt('enabled'),
313  'md_activated['.$def->getFieldId().']',
314  $value->getValue() ? true : false);
315  $time->setDisabled($value->isDisabled());
316  $time->setInfo($def->getDescription());
317  $this->form->addItem($time);
318  break;
319 
321 
322  $unixtime = $value->getValue() ? $value->getValue() : mktime(8,0,0,date('m'),date('d'),date('Y'));
323 
324  $time = new ilDateTimeInputGUI($def->getTitle(),'md['.$def->getFieldId().']');
325  $time->setShowTime(true);
326  $time->setDate(new ilDateTime($unixtime,IL_CAL_UNIX,$ilUser->getTimeZone()));
327  $time->enableDateActivation($this->lng->txt('enabled'),
328  'md_activated['.$def->getFieldId().']',
329  $value->getValue() ? true : false);
330  $time->setDisabled($value->isDisabled());
331  $this->form->addItem($time);
332  break;
333  }
334  }
335  }
336  }
337 
345  private function parseSearch()
346  {
347  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
349  {
350  $section = new ilFormSectionHeaderGUI();
351  $section->setTitle($record->getTitle());
352  $this->form->addItem($section);
353 
354  foreach(ilAdvancedMDFieldDefinition::_getDefinitionsByRecordId($record->getRecordId()) as $field)
355  {
356  if(!$field->isSearchable())
357  {
358  continue;
359  }
360  switch($field->getFieldType())
361  {
363 
364  $group = new ilRadioGroupInputGUI('','boolean['.$field->getFieldId().']');
365  $group->setValue(isset($this->search_values['boolean'][$field->getFieldId()]) ?
366  $this->search_values['boolean'][$field->getFieldId()] : 0);
367  $radio_option = new ilRadioOption($this->lng->txt("search_any_word"),0);
368  $radio_option->setValue(0);
369  $group->addOption($radio_option);
370  $radio_option = new ilRadioOption($this->lng->txt("search_all_words"),1);
371  $radio_option->setValue(1);
372  $group->addOption($radio_option);
373 
374  $text = new ilTextInputGUI($field->getTitle(),$field->getFieldId());
375  $text->setValue(isset($this->search_values[$field->getFieldId()]) ?
376  $this->search_values[$field->getFieldId()] :
377  '');
378  $text->setSize(30);
379  $text->setMaxLength(255);
380 
381 
382  $text->addSubItem($group);
383  $this->form->addItem($text);
384  break;
385 
387  $select = new ilSelectInputGUI($field->getTitle(),$field->getFieldId());
388  $select->setValue(isset($this->search_values[$field->getFieldId()]) ?
389  $this->search_values[$field->getFieldId()] :
390  0);
391  $options = array(0 => $this->lng->txt('search_any'));
392  $counter = 1;
393  foreach($field->getFieldValues() as $key => $value)
394  {
395  $options[$counter++] = $value;
396  }
397  $select->setOptions($options);
398  $this->form->addItem($select);
399  break;
400 
403  $check = new ilCheckboxInputGUI($field->getTitle(),$field->getFieldId());
404  $check->setValue(1);
405  $check->setChecked(isset($this->search_values[$field->getFieldId()]) ?
406  $this->search_values[$field->getFieldId()] : 0);
407 
408  $time = new ilDateTimeInputGUI($this->lng->txt('from'),'date_start['.$field->getFieldId().']');
409  if($field->getFieldType() == ilAdvancedMDFieldDefinition::TYPE_DATE)
410  {
411  $time->setShowTime(false);
412  }
413  else
414  {
415  $time->setShowTime(true);
416  }
417  if(isset($this->search_values['date_start'][$field->getFieldId()]) and 0)
418  {
419  #$time->setUnixTime($this->toUnixTime($this->search_values['date_start'][$field->getFieldId()]['date'],$this->search_values['date_start'][$field->getFieldId()]['time']));
420  }
421  else
422  {
423  $time->setDate(new ilDateTime(mktime(8,0,0,date('m'),date('d'),date('Y')),IL_CAL_UNIX));
424  }
425  $check->addSubItem($time);
426 
427  $time = new ilDateTimeInputGUI($this->lng->txt('until'),'date_end['.$field->getFieldId().']');
428  if($field->getFieldType() == ilAdvancedMDFieldDefinition::TYPE_DATE)
429  {
430  $time->setShowTime(false);
431  }
432  else
433  {
434  $time->setShowTime(true);
435  }
436  if(isset($this->search_values['date_end'][$field->getFieldId()]) and 0)
437  {
438  #$time->setUnixTime($this->toUnixTime($this->search_values['date_end'][$field->getFieldId()]['date'],$this->search_values['date_end'][$field->getFieldId()]['time']));
439  }
440  else
441  {
442  $time->setDate(new ilDateTime(mktime(16,0,0,date('m'),date('d'),date('Y')),IL_CAL_UNIX));
443  }
444  $check->addSubItem($time);
445 
446  $this->form->addItem($check);
447  break;
448  }
449  }
450  }
451  }
452 
453  private function parseInfoPage()
454  {
455  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
456  foreach(ilAdvancedMDRecord::_getActivatedRecordsByObjectType($this->obj_type) as $record_obj)
457  {
458  $this->info->addSection($record_obj->getTitle());
459 
460  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
461  foreach(ilAdvancedMDFieldDefinition::_getDefinitionsByRecordId($record_obj->getRecordId()) as $def)
462  {
463  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php');
464  $value = ilAdvancedMDValue::_getInstance($this->obj_id,$def->getFieldId());
465 
466  switch($def->getFieldType())
467  {
469  if($value->getValue())
470  {
471  $this->info->addProperty($def->getTitle(),$value->getValue());
472  }
473  break;
474 
476  if($value->getValue())
477  {
478  $this->info->addProperty($def->getTitle(),$value->getValue());
479  }
480  break;
481 
483  if($value->getValue())
484  {
485  $this->info->addProperty($def->getTitle(),ilDatePresentation::formatDate(new ilDate($value->getValue(),IL_CAL_UNIX)));
486  }
487  break;
489  if($value->getValue())
490  {
491  $this->info->addProperty($def->getTitle(),ilDatePresentation::formatDate(new ilDateTime($value->getValue(),IL_CAL_UNIX)));
492  }
493  break;
494  }
495  }
496  }
497 
498  }
499 
507  private function toUnixTime($date,$time = array())
508  {
509  return mktime($time['h'],$time['m'],0,$date['m'],$date['d'],$date['y']);
510  }
511 
519  private function handleECSDefinitions($a_definition)
520  {
521  include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
522  include_once('./Services/WebServices/ECS/classes/class.ilECSSettings.php');
523 
524  if(!ilECSSettings::_getInstance()->isEnabled() or ($this->obj_type != 'crs' and $this->obj_type != 'rcrs'))
525  {
526  return false;
527  }
529 
530  if($mapping->getMappingByECSName('begin') == $a_definition->getFieldId())
531  {
532  $this->showECSStart($a_definition);
533  return true;
534  }
535  if($mapping->getMappingByECSName('end') == $a_definition->getFieldId())
536  {
537  return true;
538  }
539  if($mapping->getMappingByECSName('cycle') == $a_definition->getFieldId())
540  {
541  return true;
542  }
543  if($mapping->getMappingByECSName('room') == $a_definition->getFieldId())
544  {
545  return true;
546  }
547  }
548 
555  private function showECSStart($def)
556  {
557  global $ilUser;
558 
559  $this->lng->loadLanguageModule('ecs');
560 
561  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php');
562  $value_start = ilAdvancedMDValue::_getInstance($this->obj_id,$def->getFieldId());
563 
564  $unixtime = $value_start->getValue() ? $value_start->getValue() : mktime(8,0,0,date('m'),date('d'),date('Y'));
565 
566  $time = new ilDateTimeInputGUI($this->lng->txt('ecs_event_appointment'),'md['.$def->getFieldId().']');
567  $time->setShowTime(true);
568  $time->setDate(new ilDateTime($unixtime,IL_CAL_UNIX));
569  $time->enableDateActivation($this->lng->txt('enabled'),
570  'md_activated['.$def->getFieldId().']',
571  $value_start->getValue() ? true : false);
572  $time->setDisabled($value_start->isDisabled());
573 
575  if($field_id = $mapping->getMappingByECSName('end'))
576  {
577  $value_end = ilAdvancedMDValue::_getInstance($this->obj_id,$field_id);
578 
579  list($hours,$minutes) = $this->parseDuration($value_start->getValue(),$value_end->getValue());
580 
581  $duration = new ilDurationInputGUI($this->lng->txt('ecs_duration'),'ecs_duration');
582  $duration->setHours($hours);
583  $duration->setMinutes($minutes);
584  #$duration->setInfo($this->lng->txt('ecs_duration_info'));
585  $duration->setShowHours(true);
586  $duration->setShowMinutes(true);
587  $time->addSubItem($duration);
588  }
589 
590  if($field_id = $mapping->getMappingByECSName('cycle'))
591  {
592  $value = ilAdvancedMDValue::_getInstance($this->obj_id,$field_id);
593  $cycle_def = new ilAdvancedMDFieldDefinition($field_id);
594  switch($cycle_def->getFieldType())
595  {
597  $text = new ilTextInputGUI($cycle_def->getTitle(),'md['.$cycle_def->getFieldId().']');
598  $text->setValue($value->getValue());
599  $text->setSize(20);
600  $text->setMaxLength(512);
601  $text->setDisabled($value->isDisabled());
602  $time->addSubItem($text);
603  break;
604 
606  $select = new ilSelectInputGUI($cycle_def->getTitle(),'md['.$cycle_def->getFieldId().']');
607  $select->setOptions($cycle_def->getFieldValuesForSelect());
608  $select->setValue($value->getValue());
609  $select->setDisabled($value->isDisabled());
610  $time->addSubItem($select);
611  break;
612  }
613  }
614  if($field_id = $mapping->getMappingByECSName('room'))
615  {
616  $value = ilAdvancedMDValue::_getInstance($this->obj_id,$field_id);
617  $room_def = new ilAdvancedMDFieldDefinition($field_id);
618  switch($room_def->getFieldType())
619  {
621  $text = new ilTextInputGUI($room_def->getTitle(),'md['.$room_def->getFieldId().']');
622  $text->setValue($value->getValue());
623  $text->setSize(20);
624  $text->setMaxLength(512);
625  $text->setDisabled($value->isDisabled());
626  $time->addSubItem($text);
627  break;
628 
630  $select = new ilSelectInputGUI($room_def->getTitle(),'md['.$room_def->getFieldId().']');
631  $select->setOptions($cycle_def->getFieldValuesForSelect());
632  $select->setValue($value->getValue());
633  $select->setDisabled($value->isDisabled());
634  $time->addSubItem($select);
635  break;
636  }
637  }
638  $this->form->addItem($time);
639  }
640 
648  protected function parseDuration($u_start,$u_end)
649  {
650  if($u_start >= $u_end)
651  {
652  return array(0,0);
653  }
654  $diff = $u_end - $u_start;
655  $hours = (int) ($diff / (60 * 60));
656  $min = (int) (($diff % 3600) / 60);
657  return array($hours,$min);
658  }
659 
660 }
661 
662 
663 ?>