ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilAdvancedMDRecordGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4
15{
16 const MODE_EDITOR = 1;
17 const MODE_SEARCH = 2;
18 const MODE_INFO = 3;
19
20 // glossary
21 const MODE_REC_SELECTION = 4; // record selection (per object)
22 const MODE_FILTER = 5; // filter (as used e.g. in tables)
23 const MODE_TABLE_HEAD = 6; // table header (columns)
24 const MODE_TABLE_CELLS = 7; // table cells
25
26 protected $lng;
27
28 private $mode;
29 private $obj_type;
30 private $sub_type;
31 private $obj_id;
32
33 private $form;
34 private $search_values = array();
35
36 protected $editor_form; // [array]
37
46 public function __construct($a_mode,$a_obj_type = '',$a_obj_id = '', $a_sub_type = '', $a_sub_id = '')
47 {
48 global $lng;
49
50 $this->lng = $lng;
51 $this->mode = $a_mode;
52 $this->obj_type = $a_obj_type;
53 $this->obj_id = $a_obj_id;
54 $this->sub_type = $a_sub_type;
55 $this->sub_id = $a_sub_id;
56 }
57
65 public function setPropertyForm($form)
66 {
67 $this->form = $form;
68 }
69
76 public function setSearchValues($a_values)
77 {
78 $this->search_values = $a_values;
79 }
80
81
89 public function setInfoObject($info)
90 {
91 $this->info = $info;
92 }
93
101 public function parse()
102 {
103 switch($this->mode)
104 {
106 return $this->parseEditor();
107
109 return $this->parseSearch();
110
111 case self::MODE_INFO:
112 return $this->parseInfoPage();
113
115 return $this->parseRecordSelection();
116
118 return $this->parseFilter();
119
121 return $this->parseTableHead();
122
124 return $this->parseTableCells();
125
126 default:
127 die('Not implemented yet');
128 }
129 }
130
131
132 //
133 // editor
134 //
135
139 protected function parseEditor()
140 {
141 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
142 $this->editor_form = array();
143
144 foreach($this->getActiveRecords() as $record_obj)
145 {
146 /* :TODO:
147 if($this->handleECSDefinitions($def))
148 {
149 continue;
150 }
151 */
152
153 $record_id = $record_obj->getRecordId();
154
155 $values = new ilAdvancedMDValues($record_id, $this->obj_id, $this->sub_type, $this->sub_id);
156 $values->read();
157 $defs = $values->getDefinitions();
158
159 // empty record?
160 if(!sizeof($defs))
161 {
162 continue;
163 }
164
165 $adt_group_form = ilADTFactory::getInstance()->getFormBridgeForInstance($values->getADTGroup());
166 $adt_group_form->setForm($this->form);
167 $adt_group_form->setTitle($record_obj->getTitle());
168 $adt_group_form->setInfo($record_obj->getDescription());
169
170 foreach($defs as $def)
171 {
172 $element = $adt_group_form->getElement($def->getFieldId());
173 $element->setTitle($def->getTitle());
174 $element->setInfo($def->getDescription());
175
176 // definition may customize ADT form element
177 $def->prepareElementForEditor($element);
178
179 if($values->isDisabled($def->getFieldId()))
180 {
181 $element->setDisabled(true);
182 }
183 }
184
185 $adt_group_form->addToForm();
186
187 $this->editor_form[$record_id] = array("values"=>$values, "form"=>$adt_group_form);
188 }
189 }
190
196 public function importEditFormPostValues()
197 {
198 // #13774
199 if(!is_array($this->editor_form))
200 {
201 return false;
202 }
203
204 $valid = true;
205
206 foreach($this->editor_form as $item)
207 {
208 $item["form"]->importFromPost();
209 if(!$item["form"]->validate())
210 {
211 $valid = false;
212 }
213 }
214
215 return $valid;
216 }
217
223 public function writeEditForm()
224 {
225 if(!sizeof($this->editor_form))
226 {
227 return false;
228 }
229
230 foreach($this->editor_form as $item)
231 {
232 $item["values"]->write();
233 }
234
235 return true;
236 }
237
238
239 //
240 // search
241 //
242
246 private function parseSearch()
247 {
248 // this is NOT used for the global search, see ilLuceneAdvancedSearchFields::getFormElement()
249 // (so searchable flag is NOT relevant)
250 //
251 // current usage: wiki page element "[amd] page list"
252
253 $this->lng->loadLanguageModule('search');
254
255 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
256
257 $this->search_form = array();
258 foreach($this->getActiveRecords() as $record)
259 {
260 $fields = ilAdvancedMDFieldDefinition::getInstancesByRecordId($record->getRecordId(), true);
261
262 // empty record?
263 if(!sizeof($fields))
264 {
265 continue;
266 }
267
269 $section->setTitle($record->getTitle());
270 $section->setInfo($record->getDescription());
271 $this->form->addItem($section);
272
273 foreach($fields as $field)
274 {
275 $field_form = ilADTFactory::getInstance()->getSearchBridgeForDefinitionInstance($field->getADTDefinition(), true, false);
276 $field_form->setForm($this->form);
277 $field_form->setElementId("advmd[".$field->getFieldId()."]");
278 $field_form->setTitle($field->getTitle());
279
280 if(is_array($this->search_form_values) &&
281 isset($this->search_form_values[$field->getFieldId()]))
282 {
283 $field->setSearchValueSerialized($field_form, $this->search_form_values[$field->getFieldId()]);
284 }
285
286 $field->prepareElementForSearch($field_form);
287
288 $field_form->addToForm();
289
290 $this->search_form[$field->getFieldId()] = array("def"=>$field, "value"=>$field_form);
291 }
292 }
293 }
294
300 public function importSearchForm()
301 {
302 if(!sizeof($this->search_form))
303 {
304 return false;
305 }
306
307 $valid = true;
308 $res = array();
309
310 foreach($this->search_form as $field_id => $item)
311 {
312 $item["value"]->importFromPost();
313 if(!$item["value"]->validate())
314 {
315 $valid = false;
316 }
317 $value = $item["def"]->getSearchValueSerialized($item["value"]);
318 if($value !== null)
319 {
320 $res[$field_id] = $value;
321 }
322 }
323
324 if($valid)
325 {
326 return $res;
327 }
328 }
329
330 public function setSearchFormValues(array $a_values)
331 {
332 $this->search_form_values = $a_values;
333 }
334
335
336 //
337 // infoscreen
338 //
339
340 private function parseInfoPage()
341 {
342 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
343 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
344 include_once('Services/ADT/classes/class.ilADTFactory.php');
345
346 foreach(ilAdvancedMDValues::getInstancesForObjectId($this->obj_id, $this->obj_type, $this->sub_type, $this->sub_id) as $record_id => $a_values)
347 {
348 // this correctly binds group and definitions
349 $a_values->read();
350
351 $this->info->addSection(ilAdvancedMDRecord::_lookupTitle($record_id));
352
353 $defs = $a_values->getDefinitions();
354 foreach($a_values->getADTGroup()->getElements() as $element_id => $element)
355 {
356 if(!$element->isNull())
357 {
358 $this->info->addProperty($defs[$element_id]->getTitle(),
359 ilADTFactory::getInstance()->getPresentationBridgeForInstance($element)->getHTML());
360 }
361 }
362 }
363 }
364
365
366 //
367 // :TODO: ECS
368 //
369
377 private function handleECSDefinitions($a_definition)
378 {
379 include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
380 include_once('./Services/WebServices/ECS/classes/class.ilECSServerSettings.php');
381
382 if(ilECSServerSettings::getInstance()->activeServerExists() or
383 ($this->obj_type != 'crs' and $this->obj_type != 'rcrs')
384 )
385 {
386 return false;
387 }
388 return false;
389 /*
390 $mapping = ilECSDataMappingSettings::_getInstance();
391
392 if($mapping->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'begin') == $a_definition->getFieldId())
393 {
394 $this->showECSStart($a_definition);
395 return true;
396 }
397 if($mapping->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'end') == $a_definition->getFieldId())
398 {
399 return true;
400 }
401 if($mapping->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'cycle') == $a_definition->getFieldId())
402 {
403 return true;
404 }
405 if($mapping->getMappingByECSName(ilECSDataMappingSetting::MAPPING_IMPORT_RCRS, 'room') == $a_definition->getFieldId())
406 {
407 return true;
408 }
409 */
410 }
411
418 private function showECSStart($def)
419 {
420 global $ilUser;
421
422 $this->lng->loadLanguageModule('ecs');
423
424 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php');
425 $value_start = ilAdvancedMDValue::_getInstance($this->obj_id,$def->getFieldId());
426
427 $unixtime = $value_start->getValue() ? $value_start->getValue() : mktime(8,0,0,date('m'),date('d'),date('Y'));
428
429 $time = new ilDateTimeInputGUI($this->lng->txt('ecs_event_appointment'),'md['.$def->getFieldId().']');
430 $time->setShowTime(true);
431 $time->setDate(new ilDateTime($unixtime,IL_CAL_UNIX));
432 $time->enableDateActivation($this->lng->txt('enabled'),
433 'md_activated['.$def->getFieldId().']',
434 $value_start->getValue() ? true : false);
435 $time->setDisabled($value_start->isDisabled());
436
438 if($field_id = $mapping->getMappingByECSName(0,'end'))
439 {
440 $value_end = ilAdvancedMDValue::_getInstance($this->obj_id,$field_id);
441
442 list($hours,$minutes) = $this->parseDuration($value_start->getValue(),$value_end->getValue());
443
444 $duration = new ilDurationInputGUI($this->lng->txt('ecs_duration'),'ecs_duration');
445 $duration->setHours($hours);
446 $duration->setMinutes($minutes);
447 #$duration->setInfo($this->lng->txt('ecs_duration_info'));
448 $duration->setShowHours(true);
449 $duration->setShowMinutes(true);
450 $time->addSubItem($duration);
451 }
452
453 if($field_id = $mapping->getMappingByECSName(0,'cycle'))
454 {
455 $value = ilAdvancedMDValue::_getInstance($this->obj_id,$field_id);
456 $cycle_def = ilAdvancedMDFieldDefinition::getInstance($field_id);
457 switch($cycle_def->getFieldType())
458 {
460 $text = new ilTextInputGUI($cycle_def->getTitle(),'md['.$cycle_def->getFieldId().']');
461 $text->setValue($value->getValue());
462 $text->setSize(20);
463 $text->setMaxLength(512);
464 $text->setDisabled($value->isDisabled());
465 $time->addSubItem($text);
466 break;
467
469 $select = new ilSelectInputGUI($cycle_def->getTitle(),'md['.$cycle_def->getFieldId().']');
470 $select->setOptions($cycle_def->getFieldValuesForSelect());
471 $select->setValue($value->getValue());
472 $select->setDisabled($value->isDisabled());
473 $time->addSubItem($select);
474 break;
475 }
476 }
477 if($field_id = $mapping->getMappingByECSName(0,'room'))
478 {
479 $value = ilAdvancedMDValue::_getInstance($this->obj_id,$field_id);
480 $room_def = ilAdvancedMDFieldDefinition::getInstance($field_id);
481 switch($room_def->getFieldType())
482 {
484 $text = new ilTextInputGUI($room_def->getTitle(),'md['.$room_def->getFieldId().']');
485 $text->setValue($value->getValue());
486 $text->setSize(20);
487 $text->setMaxLength(512);
488 $text->setDisabled($value->isDisabled());
489 $time->addSubItem($text);
490 break;
491
493 $select = new ilSelectInputGUI($room_def->getTitle(),'md['.$room_def->getFieldId().']');
494 $select->setOptions($cycle_def->getFieldValuesForSelect());
495 $select->setValue($value->getValue());
496 $select->setDisabled($value->isDisabled());
497 $time->addSubItem($select);
498 break;
499 }
500 }
501 $this->form->addItem($time);
502 }
503
511 protected function parseDuration($u_start,$u_end)
512 {
513 if($u_start >= $u_end)
514 {
515 return array(0,0);
516 }
517 $diff = $u_end - $u_start;
518 $hours = (int) ($diff / (60 * 60));
519 $min = (int) (($diff % 3600) / 60);
520 return array($hours,$min);
521 }
522
523
524 //
525 // glossary
526 //
527
534 public function parseRecordSelection($a_sec_head = "")
535 {
536 global $ilUser;
537
538 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
539 $first = true;
540 foreach(ilAdvancedMDRecord::_getActivatedRecordsByObjectType($this->obj_type, $this->sub_type) as $record_obj)
541 {
542 $selected = ilAdvancedMDRecord::getObjRecSelection($this->obj_id, $this->sub_type);
543 if ($first)
544 {
545 $first = false;
547 $sec_tit = ($a_sec_head == "")
548 ? $this->lng->txt("meta_adv_records")
549 : $a_sec_head;
550 $section->setTitle($sec_tit);
551 $this->form->addItem($section);
552 }
553
554 // checkbox for each active record
555 $cb = new ilCheckboxInputGUI($record_obj->getTitle(), "amet_use_rec[]");
556 $cb->setInfo($record_obj->getDescription());
557 $cb->setValue($record_obj->getRecordId());
558 if (in_array($record_obj->getRecordId(), $selected))
559 {
560 $cb->setChecked(true);
561 }
562 $this->form->addItem($cb);
563 }
564 }
565
572 function saveSelection()
573 {
574 $sel = ilUtil::stripSlashesArray($_POST["amet_use_rec"]);
575 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
576 ilAdvancedMDRecord::saveObjRecSelection($this->obj_id, $this->sub_type, $sel);
577 }
578
584 function setTableGUI($a_val)
585 {
586 $this->table_gui = $a_val;
587 }
588
594 function getTableGUI()
595 {
596 return $this->table_gui;
597 }
598
604 function setRowData($a_val)
605 {
606 $this->row_data = $a_val;
607 }
608
614 function getRowData()
615 {
616 return $this->row_data;
617 }
618
619 protected function getActiveRecords()
620 {
621 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
622 return ilAdvancedMDRecord::_getSelectedRecordsByObject($this->obj_type, $this->obj_id, $this->sub_type);
623 }
624
631 private function parseFilter()
632 {
633 $this->adt_search = array();
634
635 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
636 foreach($this->getActiveRecords() as $record_obj)
637 {
638 $record_id = $record_obj->getRecordId();
639
641 foreach($defs as $def)
642 {
643 // some input GUIs do NOT support filter rendering yet
644 if(!$def->isFilterSupported())
645 {
646 continue;
647 }
648
649 /* :TODO:
650 if($this->handleECSDefinitions($def))
651 {
652 continue;
653 }
654 */
655
656 $this->adt_search[$def->getFieldId()] = ilADTFactory::getInstance()->getSearchBridgeForDefinitionInstance($def->getADTDefinition(), true, false);
657 $this->adt_search[$def->getFieldId()]->setTableGUI($this->table_gui);
658 $this->adt_search[$def->getFieldId()]->setTitle($def->getTitle());
659 $this->adt_search[$def->getFieldId()]->setElementId('md_'.$def->getFieldId());
660
661 $this->adt_search[$def->getFieldId()]->loadFilter();
662 $this->adt_search[$def->getFieldId()]->addToForm();
663 }
664 }
665 }
666
670 public function importFilter()
671 {
672 if(!is_array($this->adt_search))
673 {
674 return;
675 }
676
677 foreach($this->adt_search as $element)
678 {
679 $element->importFromPost();
680 }
681 }
682
688 public function getFilterElements($a_only_non_empty = true)
689 {
690 if(!is_array($this->adt_search))
691 {
692 return;
693 }
694
695 $res = array();
696
697 foreach($this->adt_search as $def_id => $element)
698 {
699 if(!$element->isNull() ||
700 !(bool)$a_only_non_empty)
701 {
702 $res[$def_id] = $element;
703 }
704 }
705
706 return $res;
707 }
708
709
710 //
711 // :TODO: OBSOLETE? not used in glossary
712 //
713
717 private function parseTableHead()
718 {
719 foreach($this->getActiveRecords() as $record_obj)
720 {
721 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
722 foreach(ilAdvancedMDFieldDefinition::_getDefinitionsByRecordId($record_obj->getRecordId()) as $def)
723 {
724 if($this->handleECSDefinitions($def))
725 {
726 continue;
727 }
728
729 $this->table_gui->addColumn($def->getTitle(),'md_'.$def->getFieldId());
730 }
731 }
732 }
733
737 private function parseTableCells()
738 {
739 $data = $this->getRowData();
740
741 $html = "";
742
743 foreach($this->getActiveRecords() as $record_obj)
744 {
745 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
746 foreach(ilAdvancedMDFieldDefinition::_getDefinitionsByRecordId($record_obj->getRecordId()) as $def)
747 {
748 if($this->handleECSDefinitions($def))
749 {
750 continue;
751 }
752
753 $html.= "<td class='std'>".$data['md_'.$def->getFieldId()]."</td>";
754 }
755 }
756 return $html;
757 }
758
759}
760
761
762?>
$section
Definition: Utf8Test.php:84
const IL_CAL_UNIX
static getInstance()
Get singleton.
static getInstance($a_field_id, $a_type=null)
Get definition instance by type.
static getInstancesByRecordId($a_record_id, $a_only_searchable=false)
Get definitions by record id.
parseRecordSelection($a_sec_head="")
Parse property form in editor mode.
importEditFormPostValues()
Load edit form values from post.
__construct($a_mode, $a_obj_type='', $a_obj_id='', $a_sub_type='', $a_sub_id='')
Constructor.
showECSStart($def)
Show special form for ecs start.
setInfoObject($info)
get info sections
writeEditForm()
Write edit form values to db.
importFilter()
Import filter (post) values.
parseFilter()
Parse property for filter (table)
parseTableHead()
Parse property for table head.
parseDuration($u_start, $u_end)
parse hours and minutes from duration
handleECSDefinitions($a_definition)
handle ecs definitions
importSearchForm()
Load edit form values from post.
setPropertyForm($form)
set property form object
setSearchValues($a_values)
Set values for search form.
saveSelection()
Save selection per object.
parseEditor()
Parse property form in editor mode.
getFilterElements($a_only_non_empty=true)
Get SQL conditions for current filter value(s)
static _lookupTitle($a_record_id)
Lookup title.
static _getSelectedRecordsByObject($a_obj_type, $a_obj_id, $a_sub_type="")
Get selected records by object.
static saveObjRecSelection($a_obj_id, $a_sub_type="", array $a_records=null, $a_delete_before=true)
Save repository object record selection.
static getObjRecSelection($a_obj_id, $a_sub_type="")
Get repository object record selection.
static _getActivatedRecordsByObjectType($a_obj_type, $a_sub_type="", $a_only_optional=false)
Get activated records by object type.
static getInstancesForObjectId($a_obj_id, $a_obj_type=null, $a_sub_type="-", $a_sub_id=0)
Get instances for given object id.
This class represents a checkbox property in a property form.
This class represents a date/time property in a property form.
@classDescription Date and time handling
This class represents a duration (typical hh:mm:ss) property in a property form.
static _getInstance()
Get Singleton instance.
static getInstance()
Get singleton instance.
This class represents a section header in a property form.
This class represents a selection list property in a property form.
This class represents a text property in a property form.
static stripSlashesArray($a_arr, $a_strip_html=true, $a_allow="")
Strip slashes from array.
$_POST['username']
Definition: cron.php:12
$valid
$html
Definition: example_001.php:87
$data
$text
$info
Definition: example_052.php:80
global $ilUser
Definition: imgupload.php:15