ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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;
20
21 // glossary
22 const MODE_REC_SELECTION = 4; // record selection (per object)
23 const MODE_FILTER = 5; // filter (as used e.g. in tables)
24 const MODE_TABLE_HEAD = 6; // table header (columns)
25 const MODE_TABLE_CELLS = 7; // table cells
26
27 protected $lng;
28
29 private $mode;
30 private $obj_type;
31 private $sub_type;
32 private $obj_id;
33 private $ref_id = null;
34
35 private $form;
36 private $search_values = array();
37
38 protected $editor_form; // [array]
39
48 public function __construct($a_mode, $a_obj_type = '', $a_obj_id = '', $a_sub_type = '', $a_sub_id = '')
49 {
50 global $lng;
51
52 $this->lng = $lng;
53 $this->mode = $a_mode;
54 $this->obj_type = $a_obj_type;
55 $this->obj_id = $a_obj_id;
56 $this->sub_type = $a_sub_type;
57 $this->sub_id = $a_sub_id;
58
59 if ($a_obj_id) {
60 $refs = ilObject::_getAllReferences($a_obj_id);
61 $this->ref_id = end($refs);
62 }
63 }
64
70 public function setRefId($a_ref_id)
71 {
72 $this->ref_id = $a_ref_id;
73 }
74
82 public function setPropertyForm($form)
83 {
84 $this->form = $form;
85 }
86
93 public function setSearchValues($a_values)
94 {
95 $this->search_values = $a_values;
96 }
97
98
106 public function setInfoObject($info)
107 {
108 $this->info = $info;
109 }
110
118 public function parse()
119 {
120 switch ($this->mode) {
122 return $this->parseEditor();
123
125 return $this->parseSearch();
126
127 case self::MODE_INFO:
128 return $this->parseInfoPage();
129
131 return $this->parseAppointmentPresentation();
132
134 return $this->parseRecordSelection();
135
137 return $this->parseFilter();
138
140 return $this->parseTableHead();
141
143 return $this->parseTableCells();
144
145 default:
146 die('Not implemented yet');
147 }
148 }
149
150
151 //
152 // editor
153 //
154
158 protected function parseEditor()
159 {
160 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
161 $this->editor_form = array();
162
163 foreach ($this->getActiveRecords() as $record_obj) {
164 /* :TODO:
165 if($this->handleECSDefinitions($def))
166 {
167 continue;
168 }
169 */
170
171 $record_id = $record_obj->getRecordId();
172
173 $values = new ilAdvancedMDValues($record_id, $this->obj_id, $this->sub_type, $this->sub_id);
174 $values->read();
175 $defs = $values->getDefinitions();
176
177 // empty record?
178 if (!sizeof($defs)) {
179 continue;
180 }
181
182 $adt_group_form = ilADTFactory::getInstance()->getFormBridgeForInstance($values->getADTGroup());
183 $adt_group_form->setForm($this->form);
184 $adt_group_form->setTitle($record_obj->getTitle());
185 $adt_group_form->setInfo($record_obj->getDescription());
186
187 foreach ($defs as $def) {
188 $element = $adt_group_form->getElement($def->getFieldId());
189 $element->setTitle($def->getTitle());
190 $element->setInfo($def->getDescription());
191
192 // definition may customize ADT form element
193 $def->prepareElementForEditor($element);
194
195 if ($values->isDisabled($def->getFieldId())) {
196 $element->setDisabled(true);
197 }
198 }
199
200 $adt_group_form->addToForm();
201
202 $this->editor_form[$record_id] = array("values"=>$values, "form"=>$adt_group_form);
203 }
204 }
205
211 public function importEditFormPostValues()
212 {
213 // #13774
214 if (!is_array($this->editor_form)) {
215 return false;
216 }
217
218 $valid = true;
219
220 foreach ($this->editor_form as $item) {
221 $item["form"]->importFromPost();
222 if (!$item["form"]->validate()) {
223 $valid = false;
224 }
225 }
226
227 return $valid;
228 }
229
237 public function writeEditForm($a_obj_id = null, $a_sub_id = null)
238 {
239 if (!sizeof($this->editor_form)) {
240 return false;
241 }
242
243 // switch ids?
244 if ($a_obj_id) {
245 $this->obj_id = $a_obj_id;
246 }
247 if ($a_sub_id) {
248 $this->sub_id = $a_sub_id;
249 }
250
251 foreach ($this->editor_form as $item) {
252 if ($a_obj_id || $a_sub_id) {
253 // switch active record to updated primary keys, e.g. after creation
254 $item["values"]->setActiveRecordPrimary($this->obj_id, $this->sub_type, $this->sub_id);
255 }
256
257 $item["values"]->write();
258 }
259
260 return true;
261 }
262
263
264 //
265 // search
266 //
267
271 private function parseSearch()
272 {
273 // this is NOT used for the global search, see ilLuceneAdvancedSearchFields::getFormElement()
274 // (so searchable flag is NOT relevant)
275 //
276 // current usage: wiki page element "[amd] page list"
277
278 $this->lng->loadLanguageModule('search');
279
280 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
281
282 $this->search_form = array();
283 foreach ($this->getActiveRecords() as $record) {
284 $fields = ilAdvancedMDFieldDefinition::getInstancesByRecordId($record->getRecordId(), true);
285
286 // empty record?
287 if (!sizeof($fields)) {
288 continue;
289 }
290
292 $section->setTitle($record->getTitle());
293 $section->setInfo($record->getDescription());
294 $this->form->addItem($section);
295
296 foreach ($fields as $field) {
297 $field_form = ilADTFactory::getInstance()->getSearchBridgeForDefinitionInstance($field->getADTDefinition(), true, false);
298 $field_form->setForm($this->form);
299 $field_form->setElementId("advmd[" . $field->getFieldId() . "]");
300 $field_form->setTitle($field->getTitle());
301
302 if (is_array($this->search_form_values) &&
303 isset($this->search_form_values[$field->getFieldId()])) {
304 $field->setSearchValueSerialized($field_form, $this->search_form_values[$field->getFieldId()]);
305 }
306
307 $field->prepareElementForSearch($field_form);
308
309 $field_form->addToForm();
310
311 $this->search_form[$field->getFieldId()] = array("def"=>$field, "value"=>$field_form);
312 }
313 }
314 }
315
321 public function importSearchForm()
322 {
323 if (!sizeof($this->search_form)) {
324 return false;
325 }
326
327 $valid = true;
328 $res = array();
329
330 foreach ($this->search_form as $field_id => $item) {
331 $item["value"]->importFromPost();
332 if (!$item["value"]->validate()) {
333 $valid = false;
334 }
335 $value = $item["def"]->getSearchValueSerialized($item["value"]);
336 if ($value !== null) {
337 $res[$field_id] = $value;
338 }
339 }
340
341 if ($valid) {
342 return $res;
343 }
344 }
345
346 public function setSearchFormValues(array $a_values)
347 {
348 $this->search_form_values = $a_values;
349 }
350
355 private function parseInfoPage()
356 {
357 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
358 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
359 include_once('Services/ADT/classes/class.ilADTFactory.php');
360
361 foreach (ilAdvancedMDValues::getInstancesForObjectId($this->obj_id, $this->obj_type, $this->sub_type, $this->sub_id) as $record_id => $a_values) {
362 // this correctly binds group and definitions
363 $a_values->read();
364
365 $this->info->addSection(ilAdvancedMDRecord::_lookupTitle($record_id));
366
367 $defs = $a_values->getDefinitions();
368 foreach ($a_values->getADTGroup()->getElements() as $element_id => $element) {
369 if (!$element->isNull()) {
370 $this->info->addProperty(
371 $defs[$element_id]->getTitle(),
372 ilADTFactory::getInstance()->getPresentationBridgeForInstance($element)->getHTML()
373 );
374 }
375 }
376 }
377 }
378
384 {
386
387 $definitions = ilAdvancedMDFieldDefinition::getInstancesByObjType($this->obj_type);
388 $definitions = $sub->sortDefinitions($definitions);
389
390 $positions = array();
391 foreach ($definitions as $position => $value) {
392 $positions[$value->getFieldId()] = $position;
393 }
394
395 $array_elements = array();
396 foreach (ilAdvancedMDValues::getInstancesForObjectId($this->obj_id, $this->obj_type, $this->sub_type, $this->sub_id) as $record_id => $a_values) {
397 // this correctly binds group and definitions
398 $a_values->read();
399
400 $defs = $a_values->getDefinitions();
401 foreach ($a_values->getADTGroup()->getElements() as $element_id => $element) {
402 if (!$element->isNull()) {
403 $presentation_bridge = ilADTFactory::getInstance()->getPresentationBridgeForInstance($element);
404 #21615
405 if (get_class($element) == 'ilADTLocation') {
406 $presentation_bridge->setSize("100%", "200px");
407 #22638
408 $presentation_value = $presentation_bridge->getHTML();
409 $presentation_value .= "<script>ilInitMaps();</script>";
410 } else {
411 #22638
412 $presentation_value = strip_tags($presentation_bridge->getHTML());
413 }
414 $array_elements[$positions[$element_id]] =
415 [
416 "title" => $defs[$element_id]->getTitle(),
417 "value" => $presentation_value
418 ];
419 }
420 }
421 }
422
423 ksort($array_elements);
424 return $array_elements;
425 }
426
427 //
428 // :TODO: ECS
429 //
430
438 private function handleECSDefinitions($a_definition)
439 {
440 include_once('./Services/WebServices/ECS/classes/class.ilECSDataMappingSettings.php');
441 include_once('./Services/WebServices/ECS/classes/class.ilECSServerSettings.php');
442
443 if (ilECSServerSettings::getInstance()->activeServerExists() or
444 ($this->obj_type != 'crs' and $this->obj_type != 'rcrs')
445 ) {
446 return false;
447 }
448 return false;
449 }
450
457 private function showECSStart($def)
458 {
459 global $ilUser;
460
461 $this->lng->loadLanguageModule('ecs');
462
463 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValue.php');
464 $value_start = ilAdvancedMDValue::_getInstance($this->obj_id, $def->getFieldId());
465
466 $unixtime = $value_start->getValue() ? $value_start->getValue() : mktime(8, 0, 0, date('m'), date('d'), date('Y'));
467
468 $time = new ilDateTimeInputGUI($this->lng->txt('ecs_event_appointment'), 'md[' . $def->getFieldId() . ']');
469 $time->setShowTime(true);
470 $time->setDate(new ilDateTime($unixtime, IL_CAL_UNIX));
471 /*
472 $time->enableDateActivation($this->lng->txt('enabled'),
473 'md_activated['.$def->getFieldId().']',
474 $value_start->getValue() ? true : false);
475 */
476 $time->setDisabled($value_start->isDisabled());
477
479 if ($field_id = $mapping->getMappingByECSName(0, 'end')) {
480 $value_end = ilAdvancedMDValue::_getInstance($this->obj_id, $field_id);
481
482 list($hours, $minutes) = $this->parseDuration($value_start->getValue(), $value_end->getValue());
483
484 $duration = new ilDurationInputGUI($this->lng->txt('ecs_duration'), 'ecs_duration');
485 $duration->setHours($hours);
486 $duration->setMinutes($minutes);
487 #$duration->setInfo($this->lng->txt('ecs_duration_info'));
488 $duration->setShowHours(true);
489 $duration->setShowMinutes(true);
490 $time->addSubItem($duration);
491 }
492
493 if ($field_id = $mapping->getMappingByECSName(0, 'cycle')) {
494 $value = ilAdvancedMDValue::_getInstance($this->obj_id, $field_id);
495 $cycle_def = ilAdvancedMDFieldDefinition::getInstance($field_id);
496 switch ($cycle_def->getFieldType()) {
498 $text = new ilTextInputGUI($cycle_def->getTitle(), 'md[' . $cycle_def->getFieldId() . ']');
499 $text->setValue($value->getValue());
500 $text->setSize(20);
501 $text->setMaxLength(512);
502 $text->setDisabled($value->isDisabled());
503 $time->addSubItem($text);
504 break;
505
507 $select = new ilSelectInputGUI($cycle_def->getTitle(), 'md[' . $cycle_def->getFieldId() . ']');
508 $select->setOptions($cycle_def->getFieldValuesForSelect());
509 $select->setValue($value->getValue());
510 $select->setDisabled($value->isDisabled());
511 $time->addSubItem($select);
512 break;
513 }
514 }
515 if ($field_id = $mapping->getMappingByECSName(0, 'room')) {
516 $value = ilAdvancedMDValue::_getInstance($this->obj_id, $field_id);
517 $room_def = ilAdvancedMDFieldDefinition::getInstance($field_id);
518 switch ($room_def->getFieldType()) {
520 $text = new ilTextInputGUI($room_def->getTitle(), 'md[' . $room_def->getFieldId() . ']');
521 $text->setValue($value->getValue());
522 $text->setSize(20);
523 $text->setMaxLength(512);
524 $text->setDisabled($value->isDisabled());
525 $time->addSubItem($text);
526 break;
527
529 $select = new ilSelectInputGUI($room_def->getTitle(), 'md[' . $room_def->getFieldId() . ']');
530 $select->setOptions($cycle_def->getFieldValuesForSelect());
531 $select->setValue($value->getValue());
532 $select->setDisabled($value->isDisabled());
533 $time->addSubItem($select);
534 break;
535 }
536 }
537 $this->form->addItem($time);
538 }
539
547 protected function parseDuration($u_start, $u_end)
548 {
549 if ($u_start >= $u_end) {
550 return array(0,0);
551 }
552 $diff = $u_end - $u_start;
553 $hours = (int) ($diff / (60 * 60));
554 $min = (int) (($diff % 3600) / 60);
555 return array($hours,$min);
556 }
557
558
559 //
560 // glossary
561 //
562
569 public function parseRecordSelection($a_sec_head = "")
570 {
571 global $ilUser;
572
573 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
574 $first = true;
575 foreach (ilAdvancedMDRecord::_getActivatedRecordsByObjectType($this->obj_type, $this->sub_type) as $record_obj) {
576 $selected = ilAdvancedMDRecord::getObjRecSelection($this->obj_id, $this->sub_type);
577 if ($first) {
578 $first = false;
580 $sec_tit = ($a_sec_head == "")
581 ? $this->lng->txt("meta_adv_records")
582 : $a_sec_head;
583 $section->setTitle($sec_tit);
584 $this->form->addItem($section);
585 }
586
587 // checkbox for each active record
588 $cb = new ilCheckboxInputGUI($record_obj->getTitle(), "amet_use_rec[]");
589 $cb->setInfo($record_obj->getDescription());
590 $cb->setValue($record_obj->getRecordId());
591 if (in_array($record_obj->getRecordId(), $selected)) {
592 $cb->setChecked(true);
593 }
594 $this->form->addItem($cb);
595 }
596 }
597
604 public function saveSelection()
605 {
606 $sel = ilUtil::stripSlashesArray($_POST["amet_use_rec"]);
607 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
608 ilAdvancedMDRecord::saveObjRecSelection($this->obj_id, $this->sub_type, $sel);
609 }
610
616 public function setTableGUI($a_val)
617 {
618 $this->table_gui = $a_val;
619 }
620
626 public function getTableGUI()
627 {
628 return $this->table_gui;
629 }
630
636 public function setRowData($a_val)
637 {
638 $this->row_data = $a_val;
639 }
640
646 public function getRowData()
647 {
648 return $this->row_data;
649 }
650
651 protected function getActiveRecords()
652 {
653 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
654 return ilAdvancedMDRecord::_getSelectedRecordsByObject($this->obj_type, $this->ref_id, $this->sub_type);
655 }
656
663 private function parseFilter()
664 {
665 $this->adt_search = array();
666
667 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
668 foreach ($this->getActiveRecords() as $record_obj) {
669 $record_id = $record_obj->getRecordId();
670
672 foreach ($defs as $def) {
673 // some input GUIs do NOT support filter rendering yet
674 if (!$def->isFilterSupported()) {
675 continue;
676 }
677
678 /* :TODO:
679 if($this->handleECSDefinitions($def))
680 {
681 continue;
682 }
683 */
684
685 $this->adt_search[$def->getFieldId()] = ilADTFactory::getInstance()->getSearchBridgeForDefinitionInstance($def->getADTDefinition(), true, false);
686 $this->adt_search[$def->getFieldId()]->setTableGUI($this->table_gui);
687 $this->adt_search[$def->getFieldId()]->setTitle($def->getTitle());
688 $this->adt_search[$def->getFieldId()]->setElementId('md_' . $def->getFieldId());
689
690 $this->adt_search[$def->getFieldId()]->loadFilter();
691 $this->adt_search[$def->getFieldId()]->addToForm();
692 }
693 }
694 }
695
699 public function importFilter()
700 {
701 if (!is_array($this->adt_search)) {
702 return;
703 }
704
705 foreach ($this->adt_search as $element) {
706 $element->importFromPost();
707 }
708 }
709
715 public function getFilterElements($a_only_non_empty = true)
716 {
717 if (!is_array($this->adt_search)) {
718 return;
719 }
720
721 $res = array();
722
723 foreach ($this->adt_search as $def_id => $element) {
724 if (!$element->isNull() ||
725 !(bool) $a_only_non_empty) {
726 $res[$def_id] = $element;
727 }
728 }
729
730 return $res;
731 }
732
733
734 //
735 // :TODO: OBSOLETE? not used in glossary
736 //
737
741 private function parseTableHead()
742 {
743 foreach ($this->getActiveRecords() as $record_obj) {
744 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
745 foreach (ilAdvancedMDFieldDefinition::_getDefinitionsByRecordId($record_obj->getRecordId()) as $def) {
746 if ($this->handleECSDefinitions($def)) {
747 continue;
748 }
749
750 $this->table_gui->addColumn($def->getTitle(), 'md_' . $def->getFieldId());
751 }
752 }
753 }
754
758 private function parseTableCells()
759 {
760 $data = $this->getRowData();
761
762 $html = "";
763
764 foreach ($this->getActiveRecords() as $record_obj) {
765 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
766 foreach (ilAdvancedMDFieldDefinition::_getDefinitionsByRecordId($record_obj->getRecordId()) as $def) {
767 if ($this->handleECSDefinitions($def)) {
768 continue;
769 }
770
771 $html.= "<td class='std'>" . $data['md_' . $def->getFieldId()] . "</td>";
772 }
773 }
774 return $html;
775 }
776}
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$section
Definition: Utf8Test.php:83
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
static getInstance()
Get singleton.
static getInstance($a_field_id, $a_type=null)
Get definition instance by type.
static getInstancesByObjType($a_obj_type, $a_active_only=true)
static getInstancesByRecordId($a_record_id, $a_only_searchable=false)
Get definitions by record id.
parseInfoPage()
Presentation for info page.
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.
writeEditForm($a_obj_id=null, $a_sub_id=null)
Write edit form values to db.
showECSStart($def)
Show special form for ecs start.
setInfoObject($info)
get info sections
importFilter()
Import filter (post) values.
setRefId($a_ref_id)
Set ref_id for context.
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.
parseAppointmentPresentation()
Presentation for calendar agenda list.
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_ref_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 _getInstanceByObjectType($a_type)
Singleton: use this method to get an instance.
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.
static _getAllReferences($a_id)
get all reference ids of object
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.
$def
Definition: croninfo.php:21
$valid
$html
Definition: example_001.php:87
$time
Definition: cron.php:21
$info
Definition: index.php:5
foreach($_POST as $key=> $value) $res
$ilUser
Definition: imgupload.php:18
$text
Definition: errorreport.php:18