ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilAdvancedMDSettingsGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
5include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
6include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDPermissionHelper.php');
7include_once './Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordScope.php';
17{
19 const MODE_OBJECT = 2;
20
25 private $mode = null;
26
27
28 protected $lng;
29 protected $tpl;
30 protected $ctrl;
31 protected $tabs;
32 protected $permissions; // [ilAdvancedMDPermissionHelper]
33 protected $ref_id = null;
34 protected $obj_id = null; // [int]
35 protected $obj_type = null; // [string]
36 protected $sub_type = null; // [string]
37
41 private $logger = null;
42
49 public function __construct($a_ref_id = null, $a_obj_type = null, $a_sub_type = null)
50 {
51 global $DIC;
52
53 $tpl = $DIC['tpl'];
54 $lng = $DIC['lng'];
55 $ilCtrl = $DIC['ilCtrl'];
56 $ilTabs = $DIC['ilTabs'];
57
58 $this->ctrl = $ilCtrl;
59 $this->lng = $lng;
60 $this->lng->loadLanguageModule('meta');
61 $this->tpl = $tpl;
62 $this->tabs_gui = $ilTabs;
63
64 $this->logger = $GLOBALS['DIC']->logger()->amet();
65
66 $this->ref_id = $a_ref_id;
67 if ($this->ref_id) {
68 $this->obj_id = ilObject::_lookupObjId($a_ref_id);
69 }
70
71 if (!$this->ref_id) {
72 $this->mode = self::MODE_ADMINISTRATION;
73 } else {
74 $this->mode = self::MODE_OBJECT;
75 }
76
77
78 $this->obj_type = $a_obj_type;
79 $this->sub_type = $a_sub_type
80 ? $a_sub_type
81 : "-";
82
83 if (
84 $this->obj_id &&
85 !$this->obj_type) {
86 $this->obj_type = ilObject::_lookupType($this->obj_id);
87 }
88
89 $this->permissions = ilAdvancedMDPermissionHelper::getInstance();
90 }
91
92 protected function getPermissions()
93 {
94 return $this->permissions;
95 }
96
104 public function executeCommand()
105 {
106 $next_class = $this->ctrl->getNextClass($this);
107 $cmd = $this->ctrl->getCmd();
108
109 if (!$this->obj_id) {
110 $this->setSubTabs();
111 }
112
113 switch ($next_class) {
114 case "ilpropertyformgui":
115 $this->initRecordObject();
116 $this->initForm(
117 $this->record->getRecordId() > 0 ? 'edit' : 'create'
118 );
119 $GLOBALS['DIC']->ctrl()->forwardCommand($this->form);
120 break;
121
122 default:
123 if (!$cmd) {
124 $cmd = 'showRecords';
125 }
126 $this->$cmd();
127 }
128 }
129
137 public function showRecords()
138 {
139 global $DIC;
140
141 $ilToolbar = $DIC['ilToolbar'];
142 $ilAccess = $DIC['ilAccess'];
143
144 $perm = $this->getPermissions()->hasPermissions(
146 $_REQUEST["ref_id"],
147 array(
150 )
151 );
152
154 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
155 $button = ilLinkButton::getInstance();
156 $button->setCaption("add");
157 $button->setUrl($this->ctrl->getLinkTarget($this, "createRecord"));
158 $ilToolbar->addButtonInstance($button);
159
161 $ilToolbar->addSeparator();
162 }
163 }
164
166 include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
167 $button = ilLinkButton::getInstance();
168 $button->setCaption("import");
169 $button->setUrl($this->ctrl->getLinkTarget($this, "importRecords"));
170 $ilToolbar->addButtonInstance($button);
171 }
172
173 include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordTableGUI.php");
174 $table_gui = new ilAdvancedMDRecordTableGUI($this, "showRecords", $this->getPermissions(), (bool) $this->obj_id);
175 $table_gui->setTitle($this->lng->txt("md_record_list_table"));
176 $table_gui->setData($this->getParsedRecordObjects());
177
178 // permissions?
179 //$table_gui->addCommandButton('createRecord',$this->lng->txt('add'));
180 $table_gui->addMultiCommand("exportRecords", $this->lng->txt('export'));
181 $table_gui->setSelectAllCheckbox("record_id");
182
183 if ($ilAccess->checkAccess('write', '', $_REQUEST["ref_id"])) {
184 $table_gui->addMultiCommand("confirmDeleteRecords", $this->lng->txt("delete"));
185 $table_gui->addCommandButton("updateRecords", $this->lng->txt("save"));
186 }
187
188 $DIC->ui()->mainTemplate()->setContent($table_gui->getHTML());
189 return true;
190 }
191
192 public function showPresentation()
193 {
194 if ($this->initFormSubstitutions()) {
195 if (is_object($this->form)) {
196 $this->tabs_gui->setSubTabActive('md_adv_presentation');
197 return $this->tpl->setContent($this->form->getHTML());
198 }
199 }
200 return $this->showRecords();
201 }
202
209 public function updateSubstitutions()
210 {
211 global $DIC;
212
213 $ilAccess = $DIC['ilAccess'];
214
215 if (!$ilAccess->checkAccess('write', '', $_REQUEST["ref_id"])) {
216 $this->ctrl->redirect($this, "showPresentation");
217 }
218
220 $perm = null;
221
222 if (in_array($obj_type, $this->permissions->getAllowedObjectTypes())) {
223 $perm = $this->getPermissions()->hasPermissions(
225 $obj_type,
226 array(
230 )
231 );
232 }
233
234 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDSubstitution.php');
236
238 $sub->enableDescription($_POST['enabled_desc_' . $obj_type]);
239 }
240
242 $sub->enableFieldNames((int) $_POST['enabled_field_names_' . $obj_type]);
243 }
244
246 $definitions = $sub->sortDefinitions($definitions);
247
248 // gather existing data
249 $counter = 1;
250 $old_sub = array();
251 foreach ($definitions as $def) {
252 $field_id = $def->getFieldId();
253 $old_sub[$field_id] = array(
254 "active" => $sub->isSubstituted($field_id),
255 "pos" => $counter++,
256 "bold" => $sub->isBold($field_id),
257 "newline" => $sub->hasNewline($field_id)
258 );
259 }
260
261 $sub->resetSubstitutions(array());
262
263 $new_sub = array();
264 foreach ($definitions as $def) {
265 $field_id = $def->getFieldId();
266 $old = $old_sub[$field_id];
267
268 $perm_def = $this->getSubstitutionFieldPermissions($obj_type, $field_id);
269 if ($perm_def["show"]) {
270 $active = (isset($_POST['show'][$obj_type][$field_id]) && $_POST['show'][$obj_type][$field_id]);
271 } else {
272 $active = $old["active"];
273 }
274
275 if ($active) {
276 $new_sub[$field_id] = $old;
277
279 $new_sub[$field_id]["pos"] = (int) $_POST['position'][$obj_type][$field_id];
280 }
281 if ($perm_def["bold"]) {
282 $new_sub[$field_id]["bold"] = (isset($_POST['bold'][$obj_type][$field_id]) && $_POST['bold'][$obj_type][$field_id]);
283 }
284 if ($perm_def["newline"]) {
285 $new_sub[$field_id]["newline"] = (isset($_POST['newline'][$obj_type][$field_id]) && $_POST['newline'][$obj_type][$field_id]);
286 }
287 }
288 }
289
290 if (sizeof($new_sub)) {
291 $new_sub = ilUtil::sortArray($new_sub, "pos", "asc", true, true);
292 foreach ($new_sub as $field_id => $field) {
293 $sub->appendSubstitution($field_id, $field["bold"], $field["newline"]);
294 }
295 }
296
297 $sub->update();
298 }
299
300
301 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
302 $this->ctrl->redirect($this, "showPresentation");
303 }
304
310 public function exportRecords()
311 {
312 if (!isset($_POST['record_id'])) {
313 ilUtil::sendFailure($this->lng->txt('select_one'));
314 $this->showRecords();
315 return false;
316 }
317
318 // all records have to be exportable
319 $fail = array();
320 foreach ($_POST['record_id'] as $record_id) {
321 if (!$this->getPermissions()->hasPermission(
323 $record_id,
325 )) {
326 $record = ilAdvancedMDRecord::_getInstanceByRecordId($record_id);
327 $fail[] = $record->getTitle();
328 }
329 }
330 if ($fail) {
331 ilUtil::sendFailure($this->lng->txt('msg_no_perm_copy') . " " . implode(", ", $fail), true);
332 $this->ctrl->redirect($this, "showRecords");
333 }
334
335 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordXMLWriter.php');
336 $xml_writer = new ilAdvancedMDRecordXMLWriter($_POST['record_id']);
337 $xml_writer->write();
338
339 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
340 $export_files = new ilAdvancedMDRecordExportFiles($this->obj_id);
341 $export_files->create($xml_writer->xmlDumpMem());
342
343 ilUtil::sendSuccess($this->lng->txt('md_adv_records_exported'));
344 $this->showFiles();
345 }
346
354 public function showFiles()
355 {
356 $this->tabs_gui->setSubTabActive('md_adv_file_list');
357
358 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
359 $files = new ilAdvancedMDRecordExportFiles($this->obj_id);
360 $file_data = $files->readFilesInfo();
361
362 include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFilesTableGUI.php");
363 $table_gui = new ilAdvancedMDRecordExportFilesTableGUI($this, "showFiles");
364 $table_gui->setTitle($this->lng->txt("md_record_export_table"));
365 $table_gui->parseFiles($file_data);
366 $table_gui->addMultiCommand("downloadFile", $this->lng->txt('download'));
367
368 if ($GLOBALS['DIC']->access()->checkAccess('write', '', $this->ref_id)) {
369 $table_gui->addMultiCommand("confirmDeleteFiles", $this->lng->txt("delete"));
370 }
371 $table_gui->addCommandButton('showFiles', $this->lng->txt('cancel'));
372 $table_gui->setSelectAllCheckbox("file_id");
373
374 $this->tpl->setContent($table_gui->getHTML());
375 }
376
384 public function downloadFile()
385 {
386 if (!isset($_POST['file_id']) or count($_POST['file_id']) != 1) {
387 ilUtil::sendFailure($this->lng->txt('md_adv_select_one_file'));
388 $this->showFiles();
389 return false;
390 }
391
392 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
393 $files = new ilAdvancedMDRecordExportFiles($this->obj_id);
394 $abs_path = $files->getAbsolutePathByFileId((int) $_POST['file_id'][0]);
395
396 ilUtil::deliverFile($abs_path, 'ilias_meta_data_record.xml', 'application/xml');
397 }
398
405 public function confirmDeleteFiles()
406 {
407 if (!isset($_POST['file_id'])) {
408 ilUtil::sendFailure($this->lng->txt('select_one'));
409 $this->showFiles();
410 return false;
411 }
412
413 include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
414 $c_gui = new ilConfirmationGUI();
415
416 // set confirm/cancel commands
417 $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteFiles"));
418 $c_gui->setHeaderText($this->lng->txt("md_adv_delete_files_sure"));
419 $c_gui->setCancel($this->lng->txt("cancel"), "showFiles");
420 $c_gui->setConfirm($this->lng->txt("confirm"), "deleteFiles");
421
422 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
423 $files = new ilAdvancedMDRecordExportFiles($this->obj_id);
424 $file_data = $files->readFilesInfo();
425
426
427 // add items to delete
428 foreach ($_POST["file_id"] as $file_id) {
429 $info = $file_data[$file_id];
430 $c_gui->addItem("file_id[]", $file_id, is_array($info['name']) ? implode(',', $info['name']) : 'No Records');
431 }
432 $this->tpl->setContent($c_gui->getHTML());
433 }
434
442 public function deleteFiles()
443 {
444 if (!isset($_POST['file_id'])) {
445 ilUtil::sendFailure($this->lng->txt('select_one'));
446 $this->editFiles();
447 return false;
448 }
449
450 if (!$GLOBALS['DIC']->access()->checkAccess('write', '', $this->ref_id)) {
451 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
452 $GLOBALS['DIC']->ctrl()->redirect($this, 'showFiles');
453 }
454
455 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordExportFiles.php');
456 $files = new ilAdvancedMDRecordExportFiles($this->obj_id);
457
458 foreach ($_POST['file_id'] as $file_id) {
459 $files->deleteByFileId((int) $file_id);
460 }
461 ilUtil::sendSuccess($this->lng->txt('md_adv_deleted_files'));
462 $this->showFiles();
463 }
464
471 public function confirmDeleteRecords()
472 {
473 if (!isset($_POST['record_id'])) {
474 ilUtil::sendFailure($this->lng->txt('select_one'));
475 $this->showRecords();
476 return false;
477 }
478
479 include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
480 $c_gui = new ilConfirmationGUI();
481
482 // set confirm/cancel commands
483 $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteRecords"));
484 $c_gui->setHeaderText($this->lng->txt("md_adv_delete_record_sure"));
485 $c_gui->setCancel($this->lng->txt("cancel"), "showRecords");
486 $c_gui->setConfirm($this->lng->txt("confirm"), "deleteRecords");
487
488 // add items to delete
489 foreach ($_POST["record_id"] as $record_id) {
490 $record = ilAdvancedMDRecord::_getInstanceByRecordId($record_id);
491 $c_gui->addItem("record_id[]", $record_id, $record->getTitle() ? $record->getTitle() : 'No Title');
492 }
493 $this->tpl->setContent($c_gui->getHTML());
494 }
495
502 public function deleteRecords()
503 {
504 if (!isset($_POST['record_id'])) {
505 ilUtil::sendFailure($this->lng->txt('select_one'));
506 $this->showRecords();
507 return false;
508 }
509
510 // all records have to be deletable
511 $fail = array();
512 foreach ($_POST['record_id'] as $record_id) {
513 // must not delete global records in local context
514 if ($this->obj_id) {
515 $record = ilAdvancedMDRecord::_getInstanceByRecordId($record_id);
516 if (!$record->getParentObject()) {
517 $fail[] = $record->getTitle();
518 }
519 }
520
521 if (!$this->getPermissions()->hasPermission(
523 $record_id,
525 )) {
526 $record = ilAdvancedMDRecord::_getInstanceByRecordId($record_id);
527 $fail[] = $record->getTitle();
528 }
529 }
530 if ($fail) {
531 ilUtil::sendFailure($this->lng->txt('msg_no_perm_delete') . " " . implode(", ", $fail), true);
532 $this->ctrl->redirect($this, "showRecords");
533 }
534
535 foreach ($_POST['record_id'] as $record_id) {
536 $record = ilAdvancedMDRecord::_getInstanceByRecordId($record_id);
537 $record->delete();
538 }
539 ilUtil::sendSuccess($this->lng->txt('md_adv_deleted_records'), true);
540 $this->ctrl->redirect($this, "showRecords");
541 }
542
550 public function updateRecords()
551 {
552 // sort positions and renumber
553 $positions = $_POST['pos'];
554 asort($positions, SORT_NUMERIC);
555
556 $sorted_positions = [];
557 $i = 1;
558 foreach ($positions as $record_id => $pos) {
559 $sorted_positions[$record_id] = $i++;
560 }
561
562 $this->logger->dump($sorted_positions);
563
564 $selected_global = array();
565 foreach ($this->getParsedRecordObjects() as $item) {
566 $perm = $this->getPermissions()->hasPermissions(
568 $item['id'],
569 array(
573 )
574 );
575
576 if ($this->mode == self::MODE_ADMINISTRATION) {
577 $record_obj = ilAdvancedMDRecord::_getInstanceByRecordId($item['id']);
578
580 $obj_types = array();
581 if (is_array($_POST['obj_types'][$record_obj->getRecordId()])) {
582 foreach ($_POST['obj_types'][$record_obj->getRecordId()] as $type => $status) {
583 if ($status) {
584 $type = explode(":", $type);
585 $obj_types[] = array(
586 "obj_type" => ilUtil::stripSlashes($type[0]),
587 "sub_type" => ilUtil::stripSlashes($type[1]),
588 "optional" => ((int) $status == 2)
589 );
590 }
591 }
592 }
593 $record_obj->setAssignedObjectTypes($obj_types);
594 }
595
597 $record_obj->setActive(isset($_POST['active'][$record_obj->getRecordId()]));
598 }
599
600 $record_obj->setGlobalPosition((int) $sorted_positions[$record_obj->getRecordId()]);
601 $record_obj->update();
603 // global, optional record
604 if ($item['readonly'] &&
605 $item['optional'] &&
606 $_POST['active'][$item['id']]) {
607 $selected_global[] = $item['id'];
608 } elseif ($item['local']) {
609 $record_obj = ilAdvancedMDRecord::_getInstanceByRecordId($item['id']);
610 $record_obj->setActive(isset($_POST['active'][$item['id']]));
611 $record_obj->update();
612 }
613 }
614
615 // save local sorting
616 if ($this->mode == self::MODE_OBJECT) {
617 global $DIC;
618
619 $local_position = new \ilAdvancedMDRecordObjectOrdering($item['id'], $this->obj_id, $DIC->database());
620 $local_position->setPosition((int) $sorted_positions[$item['id']]);
621 $local_position->save();
622 }
623 }
624
625 if ($this->obj_type) {
626 ilAdvancedMDRecord::saveObjRecSelection($this->obj_id, $this->sub_type, $selected_global);
627 }
628
629 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
630 $this->ctrl->redirect($this, "showRecords");
631 }
632
639 public function confirmDeleteFields()
640 {
641 if (!isset($_POST['field_id'])) {
642 ilUtil::sendFailure($this->lng->txt('select_one'));
643 $this->editFields();
644 return false;
645 }
646
647 $this->ctrl->saveParameter($this, 'record_id');
648
649 include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
650 $c_gui = new ilConfirmationGUI();
651
652 // set confirm/cancel commands
653 $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteFields"));
654 $c_gui->setHeaderText($this->lng->txt("md_adv_delete_fields_sure"));
655 $c_gui->setCancel($this->lng->txt("cancel"), "editFields");
656 $c_gui->setConfirm($this->lng->txt("confirm"), "deleteFields");
657
658 // add items to delete
659 foreach ($_POST["field_id"] as $field_id) {
661 $c_gui->addItem("field_id[]", $field_id, $field->getTitle() ? $field->getTitle() : 'No Title');
662 }
663 $this->tpl->setContent($c_gui->getHTML());
664 }
665
673 public function deleteFields()
674 {
675 $this->ctrl->saveParameter($this, 'record_id');
676
677 if (!isset($_POST['field_id'])) {
678 ilUtil::sendFailure($this->lng->txt('select_one'));
679 $this->editFields();
680 return false;
681 }
682
683 // all fields have to be deletable
684 $fail = array();
685 foreach ($_POST['field_id'] as $field_id) {
686 if (!$this->getPermissions()->hasPermission(
688 $field_id,
690 )) {
692 $fail[] = $field->getTitle();
693 }
694 }
695 if ($fail) {
696 ilUtil::sendFailure($this->lng->txt('msg_no_perm_delete') . " " . implode(", ", $fail), true);
697 $this->ctrl->redirect($this, "editFields");
698 }
699
700 foreach ($_POST["field_id"] as $field_id) {
702 $field->delete();
703 }
704 ilUtil::sendSuccess($this->lng->txt('md_adv_deleted_fields'), true);
705 $this->ctrl->redirect($this, "editFields");
706 }
707
715 public function editRecord()
716 {
717 $this->ctrl->saveParameter($this, 'record_id');
718 $this->initRecordObject();
719 $this->initForm('edit');
720 $this->tpl->setContent($this->form->getHTML());
721 }
722
723 public function editFields()
724 {
725 global $DIC;
726
727 $ilToolbar = $DIC['ilToolbar'];
728
729 $this->ctrl->saveParameter($this, 'record_id');
730 $this->initRecordObject();
731
732 $perm = $this->getPermissions()->hasPermissions(
734 $this->record->getRecordId(),
735 array(
738 )
739 );
740
741 $filter_warn = array();
743 // type selection
744 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
745 $types = new ilSelectInputGUI("", "ftype");
746 $options = array();
749 $options[$type] = $this->lng->txt($field->getTypeTitle());
750
751 if (!$field->isFilterSupported()) {
752 $filter_warn[] = $this->lng->txt($field->getTypeTitle());
753 }
754 }
755 $types->setOptions($options);
756 $ilToolbar->addInputItem($types);
757
758 $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "createField"));
759
760 include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
761 $button = ilSubmitButton::getInstance();
762 $button->setCaption("add");
763 $button->setCommand("createField");
764 $ilToolbar->addButtonInstance($button);
765 }
766
767 // #17092
768 if (sizeof($filter_warn)) {
769 ilUtil::sendInfo(sprintf($this->lng->txt("md_adv_field_filter_warning"), implode(", ", $filter_warn)));
770 }
771
772 // show field table
773 include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
774 $fields = ilAdvancedMDFieldDefinition::getInstancesByRecordId($this->record->getRecordId());
775
776 include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldTableGUI.php");
778 $table_gui->setTitle($this->lng->txt("md_adv_field_table"));
779 $table_gui->parseDefinitions($fields);
780 if (sizeof($fields)) {
781 $table_gui->addCommandButton("updateFields", $this->lng->txt("save"));
782 }
783 $table_gui->addCommandButton("showRecords", $this->lng->txt('cancel'));
784 $table_gui->addMultiCommand("confirmDeleteFields", $this->lng->txt("delete"));
785 $table_gui->setSelectAllCheckbox("field_id");
786
787 $this->tpl->setContent($table_gui->getHTML());
788 }
789
796 public function updateFields()
797 {
798 $this->ctrl->saveParameter($this, 'record_id');
799
800 if (!isset($_GET['record_id']) or !$_GET['record_id']) {
801 ilUtil::sendFailure($this->lng->txt('select_one'));
802 $this->editFields();
803 return false;
804 }
805
806 include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
808
809 if ($this->getPermissions()->hasPermission(
811 $_GET['record_id'],
813 )) {
814 if (!isset($_POST['position']) or !is_array($_POST['position'])) {
815 $this->editFields();
816 return false;
817 }
818 // sort by position
819 asort($_POST['position'], SORT_NUMERIC);
820 $positions = array_flip(array_keys($_POST['position']));
821 foreach ($fields as $field) {
822 $field->setPosition($positions[$field->getFieldId()]);
823 $field->update();
824 }
825 }
826
827 foreach ($fields as $field) {
828 if ($this->getPermissions()->hasPermission(
830 $field->getFieldId(),
833 )) {
834 $field->setSearchable(isset($_POST['searchable'][$field->getFieldId()]) ? true : false);
835 $field->update();
836 }
837 }
838
839
840 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
841 $this->ctrl->redirect($this, "editFields");
842 }
843
851 public function updateRecord()
852 {
853 if (!isset($_GET['record_id']) or !$_GET['record_id']) {
854 ilUtil::sendFailure($this->lng->txt('select_one'));
855 $this->showRecords();
856 return false;
857 }
858 $this->initRecordObject();
859 $this->loadRecordFormData();
860
861 $this->logger->dump($_POST);
862
863 if (!$this->record->validate()) {
864 ilUtil::sendFailure($this->lng->txt('fill_out_all_required_fields'));
865 $this->editRecord();
866 return false;
867 }
868 $this->record->update();
869 ilUtil::sendSuccess($this->lng->txt('settings_saved'));
870 $this->showRecords();
871 return true;
872 }
873
874
882 public function createRecord()
883 {
884 $this->initRecordObject();
885 $this->initForm('create');
886 $this->tpl->setContent($this->form->getHTML());
887 return true;
888 }
889
890 public function importRecords()
891 {
892 // Import Table
893 $this->initImportForm();
894 $this->tpl->setContent($this->import_form->getHTML());
895 }
896
902 protected function initImportForm()
903 {
904 if (is_object($this->import_form)) {
905 return true;
906 }
907
908 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
909 $this->import_form = new ilPropertyFormGUI();
910 $this->import_form->setMultipart(true);
911 $this->import_form->setFormAction($this->ctrl->getFormAction($this));
912
913 // add file property
914 $file = new ilFileInputGUI($this->lng->txt('file'), 'file');
915 $file->setSuffixes(array('xml'));
916 $file->setRequired(true);
917 $this->import_form->addItem($file);
918
919 $this->import_form->setTitle($this->lng->txt('md_adv_import_record'));
920 $this->import_form->addCommandButton('importRecord', $this->lng->txt('import'));
921 $this->import_form->addCommandButton('showRecords', $this->lng->txt('cancel'));
922 }
923
931 public function importRecord()
932 {
933 $this->initImportForm();
934 if (!$this->import_form->checkInput()) {
935 $this->import_form->setValuesByPost();
936 $this->createRecord();
937 return false;
938 }
939
940 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordImportFiles.php');
941 $import_files = new ilAdvancedMDRecordImportFiles();
942 if (!$create_time = $import_files->moveUploadedFile($_FILES['file']['tmp_name'])) {
943 $this->createRecord();
944 return false;
945 }
946
947 try {
948 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordParser.php');
949 $parser = new ilAdvancedMDRecordParser($import_files->getImportFileByCreationDate($create_time));
950
951 // local import?
952 if ($this->obj_id) {
953 $parser->setContext($this->obj_id, $this->obj_type, $this->sub_type);
954 }
955
956 // Validate
958 $parser->startParsing();
959
960 // Insert
962 $parser->startParsing();
963 ilUtil::sendSuccess($this->lng->txt('md_adv_added_new_record'), true);
964 $this->ctrl->redirect($this, "showRecords");
965 } catch (ilSAXParserException $exc) {
966 ilUtil::sendFailure($exc->getMessage(), true);
967 $this->ctrl->redirect($this, "importRecords");
968 }
969
970 // Finally delete import file
971 $import_files->deleteFileByCreationDate($create_time);
972 return true;
973 }
974
975
983 public function saveRecord()
984 {
985 $this->initRecordObject();
986 $this->loadRecordFormData();
987
988 if ($this->obj_type) {
989 $this->record->setAssignedObjectTypes(array(
990 array(
991 "obj_type" => $this->obj_type,
992 "sub_type" => $this->sub_type,
993 "optional" => false
994 )));
995 }
996
997 if (!$this->record->validate()) {
998 ilUtil::sendFailure($this->lng->txt('fill_out_all_required_fields'));
999 $this->createRecord();
1000 return false;
1001 }
1002 $this->record->save();
1003
1004 ilUtil::sendSuccess($this->lng->txt('md_adv_added_new_record'));
1005 $this->showRecords();
1006 }
1007
1014 public function editField(ilPropertyFormGUI $a_form = null)
1015 {
1016 if (!$_REQUEST["record_id"] || !$_REQUEST["field_id"]) {
1017 return $this->editFields();
1018 }
1019
1020 $this->ctrl->saveParameter($this, 'record_id');
1021 $this->ctrl->saveParameter($this, 'field_id');
1022
1023 $field_definition = ilAdvancedMDFieldDefinition::getInstance((int) $_REQUEST['field_id']);
1024
1025 if (!$a_form) {
1026 $a_form = $this->initFieldForm($field_definition);
1027 }
1028
1029 $table = null;
1030 if ($field_definition->hasComplexOptions()) {
1031 $table = $field_definition->getComplexOptionsOverview($this, "editField");
1032 }
1033
1034 $this->tpl->setContent($a_form->getHTML() . $table);
1035 }
1036
1043 public function updateField()
1044 {
1045 if (!$_REQUEST["record_id"] || !$_REQUEST["field_id"]) {
1046 return $this->editFields();
1047 }
1048
1049 $this->ctrl->saveParameter($this, 'record_id');
1050 $this->ctrl->saveParameter($this, 'field_id');
1051
1052 $confirm = false;
1053 $field_definition = ilAdvancedMDFieldDefinition::getInstance((int) $_REQUEST['field_id']);
1054 $form = $this->initFieldForm($field_definition);
1055 if ($form->checkInput()) {
1056 $field_definition->importDefinitionFormPostValues($form, $this->getPermissions());
1057 if (!$field_definition->importDefinitionFormPostValuesNeedsConfirmation()) {
1058 $field_definition->update();
1059
1060 ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
1061 $this->ctrl->redirect($this, "editFields");
1062 } else {
1063 $confirm = true;
1064 }
1065 }
1066
1067 $form->setValuesByPost();
1068
1069 // fields needs confirmation of updated settings
1070 if ($confirm) {
1071 ilUtil::sendInfo($this->lng->txt("md_adv_confirm_definition"));
1072 $field_definition->prepareDefinitionFormConfirmation($form);
1073 }
1074
1075 $this->editField($form);
1076 }
1077
1084 public function createField(ilPropertyFormGUI $a_form = null)
1085 {
1086 if (!$_REQUEST["record_id"] || !$_REQUEST["ftype"]) {
1087 return $this->editFields();
1088 }
1089
1090 $this->ctrl->saveParameter($this, 'record_id');
1091 $this->ctrl->saveParameter($this, 'ftype');
1092
1093 if (!$a_form) {
1094 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1095 $field_definition = ilAdvancedMDFieldDefinition::getInstance(null, $_REQUEST["ftype"]);
1096 $field_definition->setRecordId($_REQUEST["record_id"]);
1097 $a_form = $this->initFieldForm($field_definition);
1098 }
1099 $this->tpl->setContent($a_form->getHTML());
1100 }
1101
1107 public function saveField()
1108 {
1109 if (!$_REQUEST["record_id"] || !$_REQUEST["ftype"]) {
1110 return $this->editFields();
1111 }
1112
1113 $this->ctrl->saveParameter($this, 'record_id');
1114 $this->ctrl->saveParameter($this, 'ftype');
1115
1116 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1117 $field_definition = ilAdvancedMDFieldDefinition::getInstance(null, $_REQUEST["ftype"]);
1118 $field_definition->setRecordId($_REQUEST["record_id"]);
1119 $form = $this->initFieldForm($field_definition);
1120
1121 if ($form->checkInput()) {
1122 $field_definition->importDefinitionFormPostValues($form, $this->getPermissions());
1123 $field_definition->save();
1124
1125 ilUtil::sendSuccess($this->lng->txt('save_settings'), true);
1126 $this->ctrl->redirect($this, "editFields");
1127 }
1128
1129 $form->setValuesByPost();
1130 $this->createField($form);
1131 }
1132
1138 protected function initFieldForm(ilAdvancedMDFieldDefinition $a_definition)
1139 {
1140 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1141
1142 $form = new ilPropertyFormGUI();
1143 $form->setFormAction($this->ctrl->getFormAction($this));
1144
1145 $type = new ilNonEditableValueGUI($this->lng->txt("type"));
1146 $type->setValue($this->lng->txt($a_definition->getTypeTitle()));
1147 $form->addItem($type);
1148
1149 $a_definition->addToFieldDefinitionForm($form, $this->getPermissions());
1150
1151 if (!$a_definition->getFieldId()) {
1152 $form->setTitle($this->lng->txt('md_adv_create_field'));
1153 $form->addCommandButton('saveField', $this->lng->txt('create'));
1154 } else {
1155 $form->setTitle($this->lng->txt('md_adv_edit_field'));
1156 $form->addCommandButton('updateField', $this->lng->txt('save'));
1157 }
1158
1159 $form->addCommandButton('editFields', $this->lng->txt('cancel'));
1160
1161 return $form;
1162 }
1163
1169 protected function initForm($a_mode)
1170 {
1171 if (is_object($this->form)) {
1172 return true;
1173 }
1174
1175 $perm = $this->getPermissions()->hasPermissions(
1177 $this->record->getRecordId(),
1178 array(
1186 )
1187 );
1188
1189 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1190
1191 $this->form = new ilPropertyFormGUI();
1192 $this->form->setFormAction($this->ctrl->getFormAction($this));
1193
1194
1195 // title
1196 $title = new ilTextInputGUI($this->lng->txt('title'), 'title');
1197 $title->setValue($this->record->getTitle());
1198 $title->setSize(20);
1199 $title->setMaxLength(70);
1200 $title->setRequired(true);
1201 $this->form->addItem($title);
1202
1204 $title->setDisabled(true);
1205 }
1206
1207 // desc
1208 $desc = new ilTextAreaInputGUI($this->lng->txt('description'), 'desc');
1209 $desc->setValue($this->record->getDescription());
1210 $desc->setRows(3);
1211 $desc->setCols(50);
1212 $this->form->addItem($desc);
1213
1215 $desc->setDisabled(true);
1216 }
1217
1218 // active
1219 $check = new ilCheckboxInputGUI($this->lng->txt('md_adv_active'), 'active');
1220 $check->setChecked($this->record->isActive());
1221 $check->setValue(1);
1222 $this->form->addItem($check);
1223
1225 $check->setDisabled(true);
1226 }
1227
1228 if (!$this->obj_type) {
1229 // scope
1230 $scope = new ilCheckboxInputGUI($this->lng->txt('md_adv_scope'), 'scope');
1231 $scope->setChecked($this->record->enabledScope());
1232 $scope->setValue(1);
1233 $this->form->addItem($scope);
1234
1235 $subitems = new ilRepositorySelector2InputGUI($this->lng->txt("objects"), "scope_containers", true);
1236 $subitems->setValue($this->record->getScopeRefIds());
1237 $exp = $subitems->getExplorerGUI();
1238
1239 $definition = $GLOBALS['DIC']['objDefinition'];
1240 $white_list = [];
1241 foreach ($definition->getAllRepositoryTypes() as $type) {
1242 if ($definition->isContainer($type)) {
1243 $white_list[] = $type;
1244 }
1245 }
1246
1247
1248 $exp->setTypeWhiteList($white_list);
1249 $exp->setSkipRootNode(false);
1250 $exp->setRootId(ROOT_FOLDER_ID);
1251 $scope->addSubItem($subitems);
1252 }
1253
1254 if (!$this->obj_type) {
1256 $section->setTitle($this->lng->txt('md_obj_types'));
1257 $this->form->addItem($section);
1258
1259 // see ilAdvancedMDRecordTableGUI::fillRow()
1260 $options = array(
1261 0 => $this->lng->txt("meta_obj_type_inactive"),
1262 1 => $this->lng->txt("meta_obj_type_mandatory"),
1263 2 => $this->lng->txt("meta_obj_type_optional")
1264 );
1265
1266
1268 $t = $type["obj_type"] . ":" . $type["sub_type"];
1269 $this->lng->loadLanguageModule($type["obj_type"]);
1270
1271 $type_options = $options;
1272 switch ($type["obj_type"]) {
1273 case "orgu":
1274 // currently only optional records for org unit (types)
1275 unset($type_options[1]);
1276 break;
1277 case "prg":
1278 // currently only optional records for study programme (types)
1279 unset($type_options[1]);
1280 break;
1281 case "rcrs":
1282 // optional makes no sense for ecs-courses
1283 unset($type_options[2]);
1284 break;
1285 }
1286
1287 $value = 0;
1288 if ($a_mode == "edit") {
1289 foreach ($this->record->getAssignedObjectTypes() as $item) {
1290 if ($item["obj_type"] == $type["obj_type"] &&
1291 $item["sub_type"] == $type["sub_type"]) {
1292 $value = $item["optional"]
1293 ? 2
1294 : 1;
1295 }
1296 }
1297 }
1298
1299 $check = new ilSelectInputGUI($type["text"], 'obj_types[' . $t . ']');
1300 $check->setOptions($type_options);
1301 $check->setValue($value);
1302 $this->form->addItem($check);
1303
1305 $check->setDisabled(true);
1306 }
1307 }
1308 }
1309
1310 switch ($a_mode) {
1311 case 'create':
1312 $this->form->setTitle($this->lng->txt('md_adv_create_record'));
1313 $this->form->addCommandButton('saveRecord', $this->lng->txt('add'));
1314 $this->form->addCommandButton('showRecords', $this->lng->txt('cancel'));
1315
1316 return true;
1317
1318 case 'edit':
1319 $this->form->setTitle($this->lng->txt('md_adv_edit_record'));
1320 $this->form->addCommandButton('updateRecord', $this->lng->txt('save'));
1321 $this->form->addCommandButton('showRecords', $this->lng->txt('cancel'));
1322
1323 return true;
1324 }
1325 }
1326
1327 protected function getSubstitutionFieldPermissions($a_obj_type, $a_field_id)
1328 {
1329 if ($a_obj_type == "crs") {
1330 $perm = $this->getPermissions()->hasPermissions(
1332 $a_field_id,
1333 array(
1339 )
1340 );
1341 return array(
1345 );
1346 } elseif ($a_obj_type == "cat") {
1347 $perm = $this->getPermissions()->hasPermissions(
1349 $a_field_id,
1350 array(
1356 )
1357 );
1358 return array(
1362 );
1363 } elseif ($a_obj_type == "sess") {
1364 $perm = $this->getPermissions()->hasPermissions(
1366 $a_field_id,
1367 array(
1373 )
1374 );
1375 return array(
1379 );
1380 } elseif ($a_obj_type == "grp") {
1381 $perm = $this->getPermissions()->hasPermissions(
1383 $a_field_id,
1384 array(
1390 )
1391 );
1392 return array(
1396 );
1397 } elseif ($a_obj_type == "iass") {
1398 $perm = $this->getPermissions()->hasPermissions(
1400 $a_field_id,
1401 array(
1407 )
1408 );
1409 return array(
1413 );
1414 } elseif ($a_obj_type == "exc") {
1415 $perm = $this->getPermissions()->hasPermissions(
1417 $a_field_id,
1418 array(
1424 )
1425 );
1426 return array(
1430 );
1431 }
1432 }
1433
1439 protected function initFormSubstitutions()
1440 {
1441 global $DIC;
1442
1443 $ilAccess = $DIC['ilAccess'];
1444
1445 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1446
1447 if (!$visible_records = ilAdvancedMDRecord::_getAllRecordsByObjectType()) {
1448 return;
1449 }
1450
1451 $this->form = new ilPropertyFormGUI();
1452 $this->form->setFormAction($this->ctrl->getFormAction($this));
1453 #$this->form->setTableWidth('100%');
1454
1455 // substitution
1456 foreach ($visible_records as $obj_type => $records) {
1457 $perm = null;
1458
1459 if (in_array($obj_type, $this->permissions->getAllowedObjectTypes())) {
1460 $perm = $this->getPermissions()->hasPermissions(
1462 $obj_type,
1463 array(
1467 )
1468 );
1469 }
1470
1472
1473 // Show section
1475 $section->setTitle($this->lng->txt('objs_' . $obj_type));
1476 $this->form->addItem($section);
1477
1478 $check = new ilCheckboxInputGUI($this->lng->txt('description'), 'enabled_desc_' . $obj_type);
1479 $check->setValue(1);
1480 $check->setOptionTitle($this->lng->txt('md_adv_desc_show'));
1481 $check->setChecked($sub->isDescriptionEnabled() ? true : false);
1482 $this->form->addItem($check);
1483
1485 $check->setDisabled(true);
1486 }
1487
1488 $check = new ilCheckboxInputGUI($this->lng->txt('md_adv_field_names'), 'enabled_field_names_' . $obj_type);
1489 $check->setValue(1);
1490 $check->setOptionTitle($this->lng->txt('md_adv_fields_show'));
1491 $check->setChecked($sub->enabledFieldNames() ? true : false);
1492 $this->form->addItem($check);
1493
1495 $check->setDisabled(true);
1496 }
1497
1498 #$area = new ilTextAreaInputGUI($this->lng->txt('md_adv_substitution'),'substitution_'.$obj_type);
1499 #$area->setUseRte(true);
1500 #$area->setRteTagSet('standard');
1501 #$area->setValue(ilUtil::prepareFormOutput($sub->getSubstitutionString()));
1502 #$area->setRows(5);
1503 #$area->setCols(80);
1504 #$this->form->addItem($area);
1505
1506 if ($perm) {
1508 }
1509
1511 $definitions = $sub->sortDefinitions($definitions);
1512
1513 $counter = 1;
1514 foreach ($definitions as $def) {
1515 $definition_id = $def->getFieldId();
1516
1517 $perm = $this->getSubstitutionFieldPermissions($obj_type, $definition_id);
1518
1519 $title = ilAdvancedMDRecord::_lookupTitle($def->getRecordId());
1520 $title = $def->getTitle() . ' (' . $title . ')';
1521
1522 $check = new ilCheckboxInputGUI($title, 'show[' . $obj_type . '][' . $definition_id . ']');
1523 $check->setValue(1);
1524 $check->setOptionTitle($this->lng->txt('md_adv_show'));
1525 $check->setChecked($sub->isSubstituted($definition_id));
1526
1527 if ($perm && !$perm["show"]) {
1528 $check->setDisabled(true);
1529 }
1530
1531 $pos = new ilNumberInputGUI($this->lng->txt('position'), 'position[' . $obj_type . '][' . $definition_id . ']');
1532 $pos->setSize(3);
1533 $pos->setMaxLength(4);
1534 $pos->allowDecimals(true);
1535 $pos->setValue(sprintf('%.1f', $counter++));
1536 $check->addSubItem($pos);
1537
1538 if ($perm && !$perm_pos) {
1539 $pos->setDisabled(true);
1540 }
1541
1542 $bold = new ilCheckboxInputGUI($this->lng->txt('bold'), 'bold[' . $obj_type . '][' . $definition_id . ']');
1543 $bold->setValue(1);
1544 $bold->setChecked($sub->isBold($definition_id));
1545 $check->addSubItem($bold);
1546
1547 if ($perm && !$perm["bold"]) {
1548 $bold->setDisabled(true);
1549 }
1550
1551 $bold = new ilCheckboxInputGUI($this->lng->txt('newline'), 'newline[' . $obj_type . '][' . $definition_id . ']');
1552 $bold->setValue(1);
1553 $bold->setChecked($sub->hasNewline($definition_id));
1554 $check->addSubItem($bold);
1555
1556 if ($perm && !$perm["newline"]) {
1557 $bold->setDisabled(true);
1558 }
1559
1560
1561 $this->form->addItem($check);
1562 }
1563
1564
1565 // placeholder
1566 /*
1567 $custom = new ilCustomInputGUI($this->lng->txt('md_adv_placeholders'));
1568 $tpl = new ilTemplate('tpl.placeholder_info.html',true,true,'Services/AdvancedMetaData');
1569 foreach($records as $record)
1570 {
1571 foreach(ilAdvancedMDFieldDefinition::_getDefinitionsByRecordId($record->getRecordId()) as $definition)
1572 {
1573 $tpl->setCurrentBlock('field');
1574 $tpl->setVariable('FIELD_NAME',$definition->getTitle());
1575 $tpl->setVariable('MODULE_VARS','[IF_F_'.$definition->getFieldId().']...[F_'.$definition->getFieldId().']'.
1576 '[/IF_F_'.$definition->getFieldId().']');
1577 $tpl->parseCurrentBlock();
1578 }
1579
1580 $tpl->setCurrentBlock('record');
1581 $tpl->setVariable('PLACEHOLDER_FOR',$this->lng->txt('md_adv_placeholder_for'));
1582 $tpl->setVariable('TITLE',$record->getTitle());
1583 $tpl->parseCurrentBlock();
1584 }
1585 $custom->setHTML($tpl->get());
1586 $this->form->addItem($custom);
1587 */
1588 }
1589 $this->form->setTitle($this->lng->txt('md_adv_substitution_table'));
1590
1591 if ($ilAccess->checkAccess('write', '', $_REQUEST["ref_id"])) {
1592 $this->form->addCommandButton('updateSubstitutions', $this->lng->txt('save'));
1593 }
1594
1595 return true;
1596 }
1597
1603 protected function loadRecordFormData()
1604 {
1605 $perm = $this->getPermissions()->hasPermissions(
1607 $this->record->getRecordId(),
1608 array(
1616 )
1617 );
1618
1620 $this->record->setActive(ilUtil::stripSlashes($_POST['active']));
1621 }
1623 $this->record->setTitle(ilUtil::stripSlashes($_POST['title']));
1624 }
1626 $this->record->setDescription(ilUtil::stripSlashes($_POST['desc']));
1627 }
1628
1629 if (!$this->obj_type) {
1631 $obj_types = array();
1632 if (is_array($_POST['obj_types'])) {
1633 foreach ($_POST['obj_types'] as $t => $value) {
1634 if ($value) {
1635 $t = explode(":", $t);
1636 $obj_types[] = array(
1637 "obj_type" => ilUtil::stripSlashes($t[0]),
1638 "sub_type" => ilUtil::stripSlashes($t[1]),
1639 "optional" => ($value > 1)
1640 );
1641 }
1642 }
1643 }
1644 $this->record->setAssignedObjectTypes($obj_types);
1645 }
1646 }
1647
1648 $scopes = [];
1649 foreach ((array) $_POST['scope_containers_sel'] as $ref_id) {
1650 $scope = new ilAdvancedMDRecordScope();
1651 $scope->setRefId($ref_id);
1652 $scopes[] = $scope;
1653 }
1654 $this->record->setScopes($_POST['scope'] ? $scopes : []);
1655 $this->record->enableScope($_POST['scope'] ? true : false);
1656 }
1657
1663 protected function initRecordObject()
1664 {
1665 if (!is_object($this->record)) {
1666 $record_id = isset($_GET['record_id'])
1667 ? $_GET['record_id']
1668 : 0;
1669 $this->record = ilAdvancedMDRecord::_getInstanceByRecordId($record_id);
1670
1671 // bind to parent object (aka local adv md)
1672 if (!$record_id &&
1673 $this->obj_id) {
1674 $this->record->setParentObject($this->obj_id);
1675 }
1676 }
1677
1678 return $this->record;
1679 }
1680
1686 protected function setSubTabs()
1687 {
1688 $this->tabs_gui->clearSubTabs();
1689
1690 $this->tabs_gui->addSubTabTarget(
1691 "md_adv_record_list",
1692 $this->ctrl->getLinkTarget($this, "showRecords"),
1693 '',
1694 '',
1695 '',
1696 true
1697 );
1698
1699
1701 $this->tabs_gui->addSubTabTarget(
1702 "md_adv_presentation",
1703 $this->ctrl->getLinkTarget($this, "showPresentation")
1704 );
1705 }
1706
1707 $this->tabs_gui->addSubTabTarget(
1708 "md_adv_file_list",
1709 $this->ctrl->getLinkTarget($this, "showFiles"),
1710 "showFiles"
1711 );
1712 }
1713
1719 protected function getParsedRecordObjects()
1720 {
1721 $res = array();
1722
1723 if ($this->mode == self::MODE_OBJECT) {
1724 $selected = ilAdvancedMDRecord::getObjRecSelection($this->obj_id, $this->sub_type);
1725 }
1726
1728 $orderings = new ilAdvancedMDRecordObjectOrderings();
1729 $records = $orderings->sortRecords($records, $this->obj_id);
1730
1731 $position = 0;
1732 foreach ($records as $record) {
1733 $parent_id = $record->getParentObject();
1734
1735 if ($this->mode == self::MODE_ADMINISTRATION) {
1736 if ($parent_id) {
1737 continue;
1738 }
1739 } else {
1740 // does not match current object
1741 if ($parent_id && $parent_id != $this->obj_id) {
1742 continue;
1743 }
1744
1745 // inactive records only in administration
1746 if (!$parent_id && !$record->isActive()) {
1747 continue;
1748 }
1749 // scope needs to match in object context
1750 if (
1752 $this->ref_id,
1753 $record->getScopes()
1754 )
1755 ) {
1756 continue;
1757 }
1758 }
1759
1760 $tmp_arr = array();
1761 $tmp_arr['id'] = $record->getRecordId();
1762 $tmp_arr['active'] = $record->isActive();
1763 $tmp_arr['title'] = $record->getTitle();
1764 $tmp_arr['description'] = $record->getDescription();
1765 $tmp_arr['fields'] = array();
1766 $tmp_arr['obj_types'] = $record->getAssignedObjectTypes();
1767 $position += 10;
1768 $tmp_arr['position'] = $position;
1769
1770 $tmp_arr['perm'] = $this->permissions->hasPermissions(
1772 $record->getRecordId(),
1773 array(
1779 )
1780 );
1781
1782 if ($this->obj_type) {
1783 $tmp_arr["readonly"] = !(bool) $parent_id;
1784 $tmp_arr["local"] = $parent_id;
1785
1786 // local records are never optional
1787 $assigned = $optional = false;
1788 foreach ($tmp_arr['obj_types'] as $idx => $item) {
1789 if ($item["obj_type"] == $this->obj_type &&
1790 $item["sub_type"] == $this->sub_type) {
1791 $assigned = true;
1792 $optional = $item["optional"];
1793 $tmp_arr['obj_types'][$idx]['context'] = true;
1794 break;
1795 }
1796 }
1797 if (!$assigned) {
1798 continue;
1799 }
1800 $tmp_arr['optional'] = $optional;
1801 if ($optional) {
1802 // in object context "active" means selected record
1803 $tmp_arr['active'] = in_array($record->getRecordId(), $selected);
1804 }
1805 }
1806
1807 $res[] = $tmp_arr;
1808 }
1809
1810 return $res;
1811 }
1812
1813
1814 //
1815 // complex options
1816 //
1817
1818 public function editComplexOption(ilPropertyFormGUI $a_form = null)
1819 {
1820 $field_definition = ilAdvancedMDFieldDefinition::getInstance((int) $_REQUEST['field_id']);
1821 if (!$field_definition->hasComplexOptions()) {
1822 $this->ctrl->redirect($this, "editField");
1823 }
1824
1825 if (!$a_form) {
1826 $a_form = $this->initComplexOptionForm($field_definition);
1827 }
1828
1829 $this->tpl->setContent($a_form->getHTML());
1830 }
1831
1833 {
1834 $this->ctrl->saveParameter($this, "record_id");
1835 $this->ctrl->saveParameter($this, "field_id");
1836 $this->ctrl->saveParameter($this, "oid");
1837
1838 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1839 $form = new ilPropertyFormGUI();
1840 $form->setTitle($this->lng->txt("md_adv_edit_complex_option"));
1841 $form->setFormAction($this->ctrl->getFormAction($this, "updateComplexOption"));
1842
1843 $a_def->initOptionForm($form, $_REQUEST["oid"]);
1844
1845 $form->addCommandButton("updateComplexOption", $this->lng->txt("save"));
1846 $form->addCommandButton("editField", $this->lng->txt("cancel"));
1847
1848 return $form;
1849 }
1850
1851 public function updateComplexOption()
1852 {
1853 $field_definition = ilAdvancedMDFieldDefinition::getInstance((int) $_REQUEST['field_id']);
1854 if ($field_definition->hasComplexOptions()) {
1855 $form = $this->initComplexOptionForm($field_definition);
1856 if ($form->checkInput() &&
1857 $field_definition->updateComplexOption($form, $_REQUEST["oid"])) {
1858 $field_definition->update();
1859 ilUtil::sendSuccess($this->lng->txt("settings_saved"), true);
1860 }
1861 }
1862
1863 $this->ctrl->redirect($this, "editField");
1864 }
1865}
$parser
Definition: BPMN2Parser.php:23
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
$section
Definition: Utf8Test.php:83
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
static getInstance($a_field_id, $a_type=null)
Get definition instance by type.
static getInstancesByObjType($a_obj_type, $a_active_only=true)
addToFieldDefinitionForm(ilPropertyFormGUI $a_form, ilAdvancedMDPermissionHelper $a_permissions)
Add input elements to definition form.
static getInstancesByRecordId($a_record_id, $a_only_searchable=false)
Get definitions by record id.
SAX based XML parser for record import files.
Scope restrictions for advanced md records.
static _lookupTitle($a_record_id)
Lookup title.
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 _getAllRecordsByObjectType()
Get records by obj_type Note: this returns only records with no sub types! @access public.
static _getInstanceByRecordId($a_record_id)
Get instance by record id.
static _getActivatedObjTypes()
get activated obj types
static _getRecords()
Get records.
static _getAssignableObjectTypes($a_include_text=false)
Get assignable object type.
static isFilteredByScope($a_ref_id, array $scopes)
Check if a given ref id is not filtered by scope restriction.
updateRecords()
Save records (assigned object typed)
editField(ilPropertyFormGUI $a_form=null)
Edit field.
initFieldForm(ilAdvancedMDFieldDefinition $a_definition)
init field form
initFormSubstitutions()
init form table 'substitutions'
editComplexOption(ilPropertyFormGUI $a_form=null)
initComplexOptionForm(ilAdvancedMDFieldDefinition $a_def)
__construct($a_ref_id=null, $a_obj_type=null, $a_sub_type=null)
Constructor.
deleteRecords()
Permanently delete records.
getParsedRecordObjects()
Get and cache record objects.
getSubstitutionFieldPermissions($a_obj_type, $a_field_id)
createField(ilPropertyFormGUI $a_form=null)
Show field type selection.
confirmDeleteFields()
show delete fields confirmation screen
static _getInstanceByObjectType($a_type)
Singleton: use this method to get an instance.
This class represents a checkbox property in a property form.
static getInstance($a_user_id=null, $a_ref_id=null)
Factory.
Confirmation screen class.
This class represents a file property in a property form.
This class represents a section header in a property form.
static getInstance()
Factory.
This class represents a non editable value in a property form.
This class represents a number property in a property form.
static _lookupObjId($a_id)
static _lookupType($a_id, $a_reference=false)
lookup object type
This class represents a property form user interface.
This class represents a selection list property in a property form.
static getInstance()
Factory.
This class represents a text area property in a property form.
This class represents a text property in a property form.
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
global $ilCtrl
Definition: ilias.php:18
$i
Definition: metadata.php:24
$type
foreach($_POST as $key=> $value) $res
$DIC
Definition: xapitoken.php:46