ILIAS  release_4-3 Revision
 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.ilECSServerSettings.php');
209 
210  if(!ilECSServerSettings::getInstance()->activeServerExists())
211  {
212  return false;
213  }
215 
216  if(!$start_id = $mapping->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'begin'))
217  {
218  return false;
219  }
220  if(!$end_id = $mapping->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, '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  {
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  {
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.ilECSServerSettings.php');
523 
524  if(ilECSServerSettings::getInstance()->activeServerExists() or
525  ($this->obj_type != 'crs' and $this->obj_type != 'rcrs')
526  )
527  {
528  return false;
529  }
530  return false;
531  /*
532  $mapping = ilECSDataMappingSettings::_getInstance();
533 
534  if($mapping->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'begin') == $a_definition->getFieldId())
535  {
536  $this->showECSStart($a_definition);
537  return true;
538  }
539  if($mapping->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'end') == $a_definition->getFieldId())
540  {
541  return true;
542  }
543  if($mapping->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'cycle') == $a_definition->getFieldId())
544  {
545  return true;
546  }
547  if($mapping->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'room') == $a_definition->getFieldId())
548  {
549  return true;
550  }
551  */
552  }
553 
560  private function showECSStart($def)
561  {
562  global $ilUser;
563 
564  $this->lng->loadLanguageModule('ecs');
565 
566  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php');
567  $value_start = ilAdvancedMDValue::_getInstance($this->obj_id,$def->getFieldId());
568 
569  $unixtime = $value_start->getValue() ? $value_start->getValue() : mktime(8,0,0,date('m'),date('d'),date('Y'));
570 
571  $time = new ilDateTimeInputGUI($this->lng->txt('ecs_event_appointment'),'md['.$def->getFieldId().']');
572  $time->setShowTime(true);
573  $time->setDate(new ilDateTime($unixtime,IL_CAL_UNIX));
574  $time->enableDateActivation($this->lng->txt('enabled'),
575  'md_activated['.$def->getFieldId().']',
576  $value_start->getValue() ? true : false);
577  $time->setDisabled($value_start->isDisabled());
578 
580  if($field_id = $mapping->getMappingByECSName('end'))
581  {
582  $value_end = ilAdvancedMDValue::_getInstance($this->obj_id,$field_id);
583 
584  list($hours,$minutes) = $this->parseDuration($value_start->getValue(),$value_end->getValue());
585 
586  $duration = new ilDurationInputGUI($this->lng->txt('ecs_duration'),'ecs_duration');
587  $duration->setHours($hours);
588  $duration->setMinutes($minutes);
589  #$duration->setInfo($this->lng->txt('ecs_duration_info'));
590  $duration->setShowHours(true);
591  $duration->setShowMinutes(true);
592  $time->addSubItem($duration);
593  }
594 
595  if($field_id = $mapping->getMappingByECSName('cycle'))
596  {
597  $value = ilAdvancedMDValue::_getInstance($this->obj_id,$field_id);
598  $cycle_def = new ilAdvancedMDFieldDefinition($field_id);
599  switch($cycle_def->getFieldType())
600  {
602  $text = new ilTextInputGUI($cycle_def->getTitle(),'md['.$cycle_def->getFieldId().']');
603  $text->setValue($value->getValue());
604  $text->setSize(20);
605  $text->setMaxLength(512);
606  $text->setDisabled($value->isDisabled());
607  $time->addSubItem($text);
608  break;
609 
611  $select = new ilSelectInputGUI($cycle_def->getTitle(),'md['.$cycle_def->getFieldId().']');
612  $select->setOptions($cycle_def->getFieldValuesForSelect());
613  $select->setValue($value->getValue());
614  $select->setDisabled($value->isDisabled());
615  $time->addSubItem($select);
616  break;
617  }
618  }
619  if($field_id = $mapping->getMappingByECSName('room'))
620  {
621  $value = ilAdvancedMDValue::_getInstance($this->obj_id,$field_id);
622  $room_def = new ilAdvancedMDFieldDefinition($field_id);
623  switch($room_def->getFieldType())
624  {
626  $text = new ilTextInputGUI($room_def->getTitle(),'md['.$room_def->getFieldId().']');
627  $text->setValue($value->getValue());
628  $text->setSize(20);
629  $text->setMaxLength(512);
630  $text->setDisabled($value->isDisabled());
631  $time->addSubItem($text);
632  break;
633 
635  $select = new ilSelectInputGUI($room_def->getTitle(),'md['.$room_def->getFieldId().']');
636  $select->setOptions($cycle_def->getFieldValuesForSelect());
637  $select->setValue($value->getValue());
638  $select->setDisabled($value->isDisabled());
639  $time->addSubItem($select);
640  break;
641  }
642  }
643  $this->form->addItem($time);
644  }
645 
653  protected function parseDuration($u_start,$u_end)
654  {
655  if($u_start >= $u_end)
656  {
657  return array(0,0);
658  }
659  $diff = $u_end - $u_start;
660  $hours = (int) ($diff / (60 * 60));
661  $min = (int) (($diff % 3600) / 60);
662  return array($hours,$min);
663  }
664 
665 }
666 
667 
668 ?>