ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
5 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
6 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDPermissionHelper.php');
7 include_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  // :TODO: hardwired?
222  if (in_array($obj_type, ['cat','crs','sess','grp','iass'])) {
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 
245  $definitions = ilAdvancedMDFieldDefinition::getInstancesByObjType($obj_type);
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);
555 
556  $sorted_positions = [];
557  $i = 1;
558  foreach ($positions as $record_id => $pos) {
559  $sorted_positions[$record_id] = $i++;
560  }
561 
562  $selected_global = array();
563  foreach ($this->getParsedRecordObjects() as $item) {
564  $perm = $this->getPermissions()->hasPermissions(
566  $item['id'],
567  array(
571  )
572  );
573 
574  if ($this->mode == self::MODE_ADMINISTRATION) {
575  $record_obj = ilAdvancedMDRecord::_getInstanceByRecordId($item['id']);
576 
578  $obj_types = array();
579  if (is_array($_POST['obj_types'][$record_obj->getRecordId()])) {
580  foreach ($_POST['obj_types'][$record_obj->getRecordId()] as $type => $status) {
581  if ($status) {
582  $type = explode(":", $type);
583  $obj_types[] = array(
584  "obj_type" => ilUtil::stripSlashes($type[0]),
585  "sub_type" => ilUtil::stripSlashes($type[1]),
586  "optional" => ((int) $status == 2)
587  );
588  }
589  }
590  }
591  $record_obj->setAssignedObjectTypes($obj_types);
592  }
593 
595  $record_obj->setActive(isset($_POST['active'][$record_obj->getRecordId()]));
596  }
597 
598  $record_obj->setGlobalPosition((int) $sorted_positions[$record_obj->getRecordId()]);
599  $record_obj->update();
601  // global, optional record
602  if ($item['readonly'] &&
603  $item['optional'] &&
604  $_POST['active'][$item['id']]) {
605  $selected_global[] = $item['id'];
606  } elseif ($item['local']) {
607  $record_obj = ilAdvancedMDRecord::_getInstanceByRecordId($item['id']);
608  $record_obj->setActive(isset($_POST['active'][$item['id']]));
609  $record_obj->update();
610  }
611  }
612 
613  // save local sorting
614  if ($this->mode == self::MODE_OBJECT) {
615  global $DIC;
616 
617  $local_position = new \ilAdvancedMDRecordObjectOrdering($item['id'], $this->obj_id, $DIC->database());
618  $local_position->setPosition((int) $sorted_positions[$item['id']]);
619  $local_position->save();
620  }
621  }
622 
623  if ($this->obj_type) {
624  ilAdvancedMDRecord::saveObjRecSelection($this->obj_id, $this->sub_type, $selected_global);
625  }
626 
627  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
628  $this->ctrl->redirect($this, "showRecords");
629  }
630 
637  public function confirmDeleteFields()
638  {
639  if (!isset($_POST['field_id'])) {
640  ilUtil::sendFailure($this->lng->txt('select_one'));
641  $this->editFields();
642  return false;
643  }
644 
645  $this->ctrl->saveParameter($this, 'record_id');
646 
647  include_once("Services/Utilities/classes/class.ilConfirmationGUI.php");
648  $c_gui = new ilConfirmationGUI();
649 
650  // set confirm/cancel commands
651  $c_gui->setFormAction($this->ctrl->getFormAction($this, "deleteFields"));
652  $c_gui->setHeaderText($this->lng->txt("md_adv_delete_fields_sure"));
653  $c_gui->setCancel($this->lng->txt("cancel"), "editFields");
654  $c_gui->setConfirm($this->lng->txt("confirm"), "deleteFields");
655 
656  // add items to delete
657  foreach ($_POST["field_id"] as $field_id) {
658  $field = ilAdvancedMDFieldDefinition::getInstance($field_id);
659  $c_gui->addItem("field_id[]", $field_id, $field->getTitle() ? $field->getTitle() : 'No Title');
660  }
661  $this->tpl->setContent($c_gui->getHTML());
662  }
663 
671  public function deleteFields()
672  {
673  $this->ctrl->saveParameter($this, 'record_id');
674 
675  if (!isset($_POST['field_id'])) {
676  ilUtil::sendFailure($this->lng->txt('select_one'));
677  $this->editFields();
678  return false;
679  }
680 
681  // all fields have to be deletable
682  $fail = array();
683  foreach ($_POST['field_id'] as $field_id) {
684  if (!$this->getPermissions()->hasPermission(
686  $field_id,
688  )) {
689  $field = ilAdvancedMDFieldDefinition::getInstance($field_id);
690  $fail[] = $field->getTitle();
691  }
692  }
693  if ($fail) {
694  ilUtil::sendFailure($this->lng->txt('msg_no_perm_delete') . " " . implode(", ", $fail), true);
695  $this->ctrl->redirect($this, "editFields");
696  }
697 
698  foreach ($_POST["field_id"] as $field_id) {
699  $field = ilAdvancedMDFieldDefinition::getInstance($field_id);
700  $field->delete();
701  }
702  ilUtil::sendSuccess($this->lng->txt('md_adv_deleted_fields'), true);
703  $this->ctrl->redirect($this, "editFields");
704  }
705 
713  public function editRecord()
714  {
715  $this->ctrl->saveParameter($this, 'record_id');
716  $this->initRecordObject();
717  $this->initForm('edit');
718  $this->tpl->setContent($this->form->getHTML());
719  }
720 
721  public function editFields()
722  {
723  global $DIC;
724 
725  $ilToolbar = $DIC['ilToolbar'];
726 
727  $this->ctrl->saveParameter($this, 'record_id');
728  $this->initRecordObject();
729 
730  $perm = $this->getPermissions()->hasPermissions(
732  $this->record->getRecordId(),
733  array(
736  )
737  );
738 
739  $filter_warn = array();
741  // type selection
742  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
743  $types = new ilSelectInputGUI("", "ftype");
744  $options = array();
746  $field = ilAdvancedMDFieldDefinition::getInstance(null, $type);
747  $options[$type] = $this->lng->txt($field->getTypeTitle());
748 
749  if (!$field->isFilterSupported()) {
750  $filter_warn[] = $this->lng->txt($field->getTypeTitle());
751  }
752  }
753  $types->setOptions($options);
754  $ilToolbar->addInputItem($types);
755 
756  $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "createField"));
757 
758  include_once "Services/UIComponent/Button/classes/class.ilSubmitButton.php";
759  $button = ilSubmitButton::getInstance();
760  $button->setCaption("add");
761  $button->setCommand("createField");
762  $ilToolbar->addButtonInstance($button);
763  }
764 
765  // #17092
766  if (sizeof($filter_warn)) {
767  ilUtil::sendInfo(sprintf($this->lng->txt("md_adv_field_filter_warning"), implode(", ", $filter_warn)));
768  }
769 
770  // show field table
771  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
772  $fields = ilAdvancedMDFieldDefinition::getInstancesByRecordId($this->record->getRecordId());
773 
774  include_once("./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldTableGUI.php");
775  $table_gui = new ilAdvancedMDFieldTableGUI($this, "editRecord", $this->getPermissions(), $perm[ilAdvancedMDPermissionHelper::ACTION_RECORD_FIELD_POSITIONS]);
776  $table_gui->setTitle($this->lng->txt("md_adv_field_table"));
777  $table_gui->parseDefinitions($fields);
778  if (sizeof($fields)) {
779  $table_gui->addCommandButton("updateFields", $this->lng->txt("save"));
780  }
781  $table_gui->addCommandButton("showRecords", $this->lng->txt('cancel'));
782  $table_gui->addMultiCommand("confirmDeleteFields", $this->lng->txt("delete"));
783  $table_gui->setSelectAllCheckbox("field_id");
784 
785  $this->tpl->setContent($table_gui->getHTML());
786  }
787 
794  public function updateFields()
795  {
796  $this->ctrl->saveParameter($this, 'record_id');
797 
798  if (!isset($_GET['record_id']) or !$_GET['record_id']) {
799  ilUtil::sendFailure($this->lng->txt('select_one'));
800  $this->editFields();
801  return false;
802  }
803 
804  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
806 
807  if ($this->getPermissions()->hasPermission(
809  $_GET['record_id'],
811  )) {
812  if (!isset($_POST['position']) or !is_array($_POST['position'])) {
813  $this->editFields();
814  return false;
815  }
816  // sort by position
817  asort($_POST['position'], SORT_NUMERIC);
818  $positions = array_flip(array_keys($_POST['position']));
819  foreach ($fields as $field) {
820  $field->setPosition($positions[$field->getFieldId()]);
821  $field->update();
822  }
823  }
824 
825  foreach ($fields as $field) {
826  if ($this->getPermissions()->hasPermission(
828  $field->getFieldId(),
831  )) {
832  $field->setSearchable(isset($_POST['searchable'][$field->getFieldId()]) ? true : false);
833  $field->update();
834  }
835  }
836 
837 
838  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
839  $this->ctrl->redirect($this, "editFields");
840  }
841 
849  public function updateRecord()
850  {
851  if (!isset($_GET['record_id']) or !$_GET['record_id']) {
852  ilUtil::sendFailure($this->lng->txt('select_one'));
853  $this->showRecords();
854  return false;
855  }
856  $this->initRecordObject();
857  $this->loadRecordFormData();
858 
859  $this->logger->dump($_POST);
860 
861  if (!$this->record->validate()) {
862  ilUtil::sendFailure($this->lng->txt('fill_out_all_required_fields'));
863  $this->editRecord();
864  return false;
865  }
866  $this->record->update();
867  ilUtil::sendSuccess($this->lng->txt('settings_saved'));
868  $this->showRecords();
869  return true;
870  }
871 
872 
880  public function createRecord()
881  {
882  $this->initRecordObject();
883  $this->initForm('create');
884  $this->tpl->setContent($this->form->getHTML());
885  return true;
886  }
887 
888  public function importRecords()
889  {
890  // Import Table
891  $this->initImportForm();
892  $this->tpl->setContent($this->import_form->getHTML());
893  }
894 
900  protected function initImportForm()
901  {
902  if (is_object($this->import_form)) {
903  return true;
904  }
905 
906  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
907  $this->import_form = new ilPropertyFormGUI();
908  $this->import_form->setMultipart(true);
909  $this->import_form->setFormAction($this->ctrl->getFormAction($this));
910 
911  // add file property
912  $file = new ilFileInputGUI($this->lng->txt('file'), 'file');
913  $file->setSuffixes(array('xml'));
914  $file->setRequired(true);
915  $this->import_form->addItem($file);
916 
917  $this->import_form->setTitle($this->lng->txt('md_adv_import_record'));
918  $this->import_form->addCommandButton('importRecord', $this->lng->txt('import'));
919  $this->import_form->addCommandButton('showRecords', $this->lng->txt('cancel'));
920  }
921 
929  public function importRecord()
930  {
931  $this->initImportForm();
932  if (!$this->import_form->checkInput()) {
933  $this->import_form->setValuesByPost();
934  $this->createRecord();
935  return false;
936  }
937 
938  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordImportFiles.php');
939  $import_files = new ilAdvancedMDRecordImportFiles();
940  if (!$create_time = $import_files->moveUploadedFile($_FILES['file']['tmp_name'])) {
941  $this->createRecord();
942  return false;
943  }
944 
945  try {
946  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordParser.php');
947  $parser = new ilAdvancedMDRecordParser($import_files->getImportFileByCreationDate($create_time));
948 
949  // local import?
950  if ($this->obj_id) {
951  $parser->setContext($this->obj_id, $this->obj_type, $this->sub_type);
952  }
953 
954  // Validate
956  $parser->startParsing();
957 
958  // Insert
960  $parser->startParsing();
961  ilUtil::sendSuccess($this->lng->txt('md_adv_added_new_record'), true);
962  $this->ctrl->redirect($this, "showRecords");
963  } catch (ilSAXParserException $exc) {
964  ilUtil::sendFailure($exc->getMessage(), true);
965  $this->ctrl->redirect($this, "importRecords");
966  }
967 
968  // Finally delete import file
969  $import_files->deleteFileByCreationDate($create_time);
970  return true;
971  }
972 
973 
981  public function saveRecord()
982  {
983  $this->initRecordObject();
984  $this->loadRecordFormData();
985 
986  if ($this->obj_type) {
987  $this->record->setAssignedObjectTypes(array(
988  array(
989  "obj_type" => $this->obj_type,
990  "sub_type" => $this->sub_type,
991  "optional" => false
992  )));
993  }
994 
995  if (!$this->record->validate()) {
996  ilUtil::sendFailure($this->lng->txt('fill_out_all_required_fields'));
997  $this->createRecord();
998  return false;
999  }
1000  $this->record->save();
1001 
1002  ilUtil::sendSuccess($this->lng->txt('md_adv_added_new_record'));
1003  $this->showRecords();
1004  }
1005 
1012  public function editField(ilPropertyFormGUI $a_form = null)
1013  {
1014  if (!$_REQUEST["record_id"] || !$_REQUEST["field_id"]) {
1015  return $this->editFields();
1016  }
1017 
1018  $this->ctrl->saveParameter($this, 'record_id');
1019  $this->ctrl->saveParameter($this, 'field_id');
1020 
1021  if (!$a_form) {
1022  $field_definition = ilAdvancedMDFieldDefinition::getInstance((int) $_REQUEST['field_id']);
1023  $a_form = $this->initFieldForm($field_definition);
1024  }
1025  $this->tpl->setContent($a_form->getHTML());
1026  }
1027 
1034  public function updateField()
1035  {
1036  if (!$_REQUEST["record_id"] || !$_REQUEST["field_id"]) {
1037  return $this->editFields();
1038  }
1039 
1040  $this->ctrl->saveParameter($this, 'record_id');
1041  $this->ctrl->saveParameter($this, 'field_id');
1042 
1043  $confirm = false;
1044  $field_definition = ilAdvancedMDFieldDefinition::getInstance((int) $_REQUEST['field_id']);
1045  $form = $this->initFieldForm($field_definition);
1046  if ($form->checkInput()) {
1047  $field_definition->importDefinitionFormPostValues($form, $this->getPermissions());
1048  if (!$field_definition->importDefinitionFormPostValuesNeedsConfirmation()) {
1049  $field_definition->update();
1050 
1051  ilUtil::sendSuccess($this->lng->txt('settings_saved'), true);
1052  $this->ctrl->redirect($this, "editFields");
1053  } else {
1054  $confirm = true;
1055  }
1056  }
1057 
1058  $form->setValuesByPost();
1059 
1060  // fields needs confirmation of updated settings
1061  if ($confirm) {
1062  ilUtil::sendInfo($this->lng->txt("md_adv_confirm_definition"));
1063  $field_definition->prepareDefinitionFormConfirmation($form);
1064  }
1065 
1066  $this->editField($form);
1067  }
1068 
1075  public function createField(ilPropertyFormGUI $a_form = null)
1076  {
1077  if (!$_REQUEST["record_id"] || !$_REQUEST["ftype"]) {
1078  return $this->editFields();
1079  }
1080 
1081  $this->ctrl->saveParameter($this, 'record_id');
1082  $this->ctrl->saveParameter($this, 'ftype');
1083 
1084  if (!$a_form) {
1085  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1086  $field_definition = ilAdvancedMDFieldDefinition::getInstance(null, $_REQUEST["ftype"]);
1087  $field_definition->setRecordId($_REQUEST["record_id"]);
1088  $a_form = $this->initFieldForm($field_definition);
1089  }
1090  $this->tpl->setContent($a_form->getHTML());
1091  }
1092 
1098  public function saveField()
1099  {
1100  if (!$_REQUEST["record_id"] || !$_REQUEST["ftype"]) {
1101  return $this->editFields();
1102  }
1103 
1104  $this->ctrl->saveParameter($this, 'record_id');
1105  $this->ctrl->saveParameter($this, 'ftype');
1106 
1107  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDFieldDefinition.php');
1108  $field_definition = ilAdvancedMDFieldDefinition::getInstance(null, $_REQUEST["ftype"]);
1109  $field_definition->setRecordId($_REQUEST["record_id"]);
1110  $form = $this->initFieldForm($field_definition);
1111 
1112  if ($form->checkInput()) {
1113  $field_definition->importDefinitionFormPostValues($form, $this->getPermissions());
1114  $field_definition->save();
1115 
1116  ilUtil::sendSuccess($this->lng->txt('save_settings'), true);
1117  $this->ctrl->redirect($this, "editFields");
1118  }
1119 
1120  $form->setValuesByPost();
1121  $this->createField($form);
1122  }
1123 
1129  protected function initFieldForm(ilAdvancedMDFieldDefinition $a_definition)
1130  {
1131  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1132 
1133  $form = new ilPropertyFormGUI();
1134  $form->setFormAction($this->ctrl->getFormAction($this));
1135 
1136  $type = new ilNonEditableValueGUI($this->lng->txt("type"));
1137  $type->setValue($this->lng->txt($a_definition->getTypeTitle()));
1138  $form->addItem($type);
1139 
1140  $a_definition->addToFieldDefinitionForm($form, $this->getPermissions());
1141 
1142  if (!$a_definition->getFieldId()) {
1143  $form->setTitle($this->lng->txt('md_adv_create_field'));
1144  $form->addCommandButton('saveField', $this->lng->txt('create'));
1145  } else {
1146  $form->setTitle($this->lng->txt('md_adv_edit_field'));
1147  $form->addCommandButton('updateField', $this->lng->txt('save'));
1148  }
1149 
1150  $form->addCommandButton('editFields', $this->lng->txt('cancel'));
1151 
1152  return $form;
1153  }
1154 
1160  protected function initForm($a_mode)
1161  {
1162  if (is_object($this->form)) {
1163  return true;
1164  }
1165 
1166  $perm = $this->getPermissions()->hasPermissions(
1168  $this->record->getRecordId(),
1169  array(
1177  )
1178  );
1179 
1180  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1181 
1182  $this->form = new ilPropertyFormGUI();
1183  $this->form->setFormAction($this->ctrl->getFormAction($this));
1184 
1185 
1186  // title
1187  $title = new ilTextInputGUI($this->lng->txt('title'), 'title');
1188  $title->setValue($this->record->getTitle());
1189  $title->setSize(20);
1190  $title->setMaxLength(70);
1191  $title->setRequired(true);
1192  $this->form->addItem($title);
1193 
1195  $title->setDisabled(true);
1196  }
1197 
1198  // desc
1199  $desc = new ilTextAreaInputGUI($this->lng->txt('description'), 'desc');
1200  $desc->setValue($this->record->getDescription());
1201  $desc->setRows(3);
1202  $desc->setCols(50);
1203  $this->form->addItem($desc);
1204 
1206  $desc->setDisabled(true);
1207  }
1208 
1209  // active
1210  $check = new ilCheckboxInputGUI($this->lng->txt('md_adv_active'), 'active');
1211  $check->setChecked($this->record->isActive());
1212  $check->setValue(1);
1213  $this->form->addItem($check);
1214 
1216  $check->setDisabled(true);
1217  }
1218 
1219  if (!$this->obj_type) {
1220  // scope
1221  $scope = new ilCheckboxInputGUI($this->lng->txt('md_adv_scope'), 'scope');
1222  $scope->setChecked($this->record->enabledScope());
1223  $scope->setValue(1);
1224  $this->form->addItem($scope);
1225 
1226  $subitems = new ilRepositorySelector2InputGUI($this->lng->txt("objects"), "scope_containers", true);
1227  $subitems->setValue($this->record->getScopeRefIds());
1228  $exp = $subitems->getExplorerGUI();
1229 
1230  $definition = $GLOBALS['DIC']['objDefinition'];
1231  $white_list = [];
1232  foreach ($definition->getAllRepositoryTypes() as $type) {
1233  if ($definition->isContainer($type)) {
1234  $white_list[] = $type;
1235  }
1236  }
1237 
1238 
1239  $exp->setTypeWhiteList($white_list);
1240  $exp->setSkipRootNode(false);
1241  $exp->setRootId(ROOT_FOLDER_ID);
1242  $scope->addSubItem($subitems);
1243  }
1244 
1245  if (!$this->obj_type) {
1247  $section->setTitle($this->lng->txt('md_obj_types'));
1248  $this->form->addItem($section);
1249 
1250  // see ilAdvancedMDRecordTableGUI::fillRow()
1251  $options = array(
1252  0 => $this->lng->txt("meta_obj_type_inactive"),
1253  1 => $this->lng->txt("meta_obj_type_mandatory"),
1254  2 => $this->lng->txt("meta_obj_type_optional")
1255  );
1256 
1257 
1259  $t = $type["obj_type"] . ":" . $type["sub_type"];
1260  $this->lng->loadLanguageModule($type["obj_type"]);
1261 
1262  $type_options = $options;
1263  switch ($type["obj_type"]) {
1264  case "orgu":
1265  // currently only optional records for org unit (types)
1266  unset($type_options[1]);
1267  break;
1268  case "prg":
1269  // currently only optional records for study programme (types)
1270  unset($type_options[1]);
1271  break;
1272  case "rcrs":
1273  // optional makes no sense for ecs-courses
1274  unset($type_options[2]);
1275  break;
1276  }
1277 
1278  $value = 0;
1279  if ($a_mode == "edit") {
1280  foreach ($this->record->getAssignedObjectTypes() as $item) {
1281  if ($item["obj_type"] == $type["obj_type"] &&
1282  $item["sub_type"] == $type["sub_type"]) {
1283  $value = $item["optional"]
1284  ? 2
1285  : 1;
1286  }
1287  }
1288  }
1289 
1290  $check = new ilSelectInputGUI($type["text"], 'obj_types[' . $t . ']');
1291  $check->setOptions($type_options);
1292  $check->setValue($value);
1293  $this->form->addItem($check);
1294 
1296  $check->setDisabled(true);
1297  }
1298  }
1299  }
1300 
1301  switch ($a_mode) {
1302  case 'create':
1303  $this->form->setTitle($this->lng->txt('md_adv_create_record'));
1304  $this->form->addCommandButton('saveRecord', $this->lng->txt('add'));
1305  $this->form->addCommandButton('showRecords', $this->lng->txt('cancel'));
1306 
1307  return true;
1308 
1309  case 'edit':
1310  $this->form->setTitle($this->lng->txt('md_adv_edit_record'));
1311  $this->form->addCommandButton('updateRecord', $this->lng->txt('save'));
1312  $this->form->addCommandButton('showRecords', $this->lng->txt('cancel'));
1313 
1314  return true;
1315  }
1316  }
1317 
1318  protected function getSubstitutionFieldPermissions($a_obj_type, $a_field_id)
1319  {
1320  if ($a_obj_type == "crs") {
1321  $perm = $this->getPermissions()->hasPermissions(
1323  $a_field_id,
1324  array(
1330  )
1331  );
1332  return array(
1336  );
1337  } elseif ($a_obj_type == "cat") {
1338  $perm = $this->getPermissions()->hasPermissions(
1340  $a_field_id,
1341  array(
1347  )
1348  );
1349  return array(
1353  );
1354  } elseif ($a_obj_type == "sess") {
1355  $perm = $this->getPermissions()->hasPermissions(
1357  $a_field_id,
1358  array(
1364  )
1365  );
1366  return array(
1370  );
1371  } elseif ($a_obj_type == "grp") {
1372  $perm = $this->getPermissions()->hasPermissions(
1374  $a_field_id,
1375  array(
1381  )
1382  );
1383  return array(
1387  );
1388  } elseif ($a_obj_type == "iass") {
1389  $perm = $this->getPermissions()->hasPermissions(
1391  $a_field_id,
1392  array(
1398  )
1399  );
1400  return array(
1404  );
1405  }
1406  }
1407 
1413  protected function initFormSubstitutions()
1414  {
1415  global $DIC;
1416 
1417  $ilAccess = $DIC['ilAccess'];
1418 
1419  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1420 
1421  if (!$visible_records = ilAdvancedMDRecord::_getAllRecordsByObjectType()) {
1422  return;
1423  }
1424 
1425  $this->form = new ilPropertyFormGUI();
1426  $this->form->setFormAction($this->ctrl->getFormAction($this));
1427  #$this->form->setTableWidth('100%');
1428 
1429  // substitution
1430  foreach ($visible_records as $obj_type => $records) {
1431  $perm = null;
1432  // :TODO: hardwird ?
1433  if (in_array($obj_type, ['crs','cat','sess','grp','iass'])) {
1434  $perm = $this->getPermissions()->hasPermissions(
1436  $obj_type,
1437  array(
1441  )
1442  );
1443  }
1444 
1445  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDSubstitution.php');
1447 
1448  // Show section
1450  $section->setTitle($this->lng->txt('objs_' . $obj_type));
1451  $this->form->addItem($section);
1452 
1453  $check = new ilCheckboxInputGUI($this->lng->txt('description'), 'enabled_desc_' . $obj_type);
1454  $check->setValue(1);
1455  $check->setOptionTitle($this->lng->txt('md_adv_desc_show'));
1456  $check->setChecked($sub->isDescriptionEnabled() ? true : false);
1457  $this->form->addItem($check);
1458 
1460  $check->setDisabled(true);
1461  }
1462 
1463  $check = new ilCheckboxInputGUI($this->lng->txt('md_adv_field_names'), 'enabled_field_names_' . $obj_type);
1464  $check->setValue(1);
1465  $check->setOptionTitle($this->lng->txt('md_adv_fields_show'));
1466  $check->setChecked($sub->enabledFieldNames() ? true : false);
1467  $this->form->addItem($check);
1468 
1470  $check->setDisabled(true);
1471  }
1472 
1473  #$area = new ilTextAreaInputGUI($this->lng->txt('md_adv_substitution'),'substitution_'.$obj_type);
1474  #$area->setUseRte(true);
1475  #$area->setRteTagSet('standard');
1476  #$area->setValue(ilUtil::prepareFormOutput($sub->getSubstitutionString()));
1477  #$area->setRows(5);
1478  #$area->setCols(80);
1479  #$this->form->addItem($area);
1480 
1481  if ($perm) {
1483  }
1484 
1486  $definitions = $sub->sortDefinitions($definitions);
1487 
1488  $counter = 1;
1489  foreach ($definitions as $def) {
1490  $definition_id = $def->getFieldId();
1491 
1492  $perm = $this->getSubstitutionFieldPermissions($obj_type, $definition_id);
1493 
1494  $title = ilAdvancedMDRecord::_lookupTitle($def->getRecordId());
1495  $title = $def->getTitle() . ' (' . $title . ')';
1496 
1497  $check = new ilCheckboxInputGUI($title, 'show[' . $obj_type . '][' . $definition_id . ']');
1498  $check->setValue(1);
1499  $check->setOptionTitle($this->lng->txt('md_adv_show'));
1500  $check->setChecked($sub->isSubstituted($definition_id));
1501 
1502  if ($perm && !$perm["show"]) {
1503  $check->setDisabled(true);
1504  }
1505 
1506  $pos = new ilNumberInputGUI($this->lng->txt('position'), 'position[' . $obj_type . '][' . $definition_id . ']');
1507  $pos->setSize(3);
1508  $pos->setMaxLength(4);
1509  $pos->allowDecimals(true);
1510  $pos->setValue(sprintf('%.1f', $counter++));
1511  $check->addSubItem($pos);
1512 
1513  if ($perm && !$perm_pos) {
1514  $pos->setDisabled(true);
1515  }
1516 
1517  $bold = new ilCheckboxInputGUI($this->lng->txt('bold'), 'bold[' . $obj_type . '][' . $definition_id . ']');
1518  $bold->setValue(1);
1519  $bold->setChecked($sub->isBold($definition_id));
1520  $check->addSubItem($bold);
1521 
1522  if ($perm && !$perm["bold"]) {
1523  $bold->setDisabled(true);
1524  }
1525 
1526  $bold = new ilCheckboxInputGUI($this->lng->txt('newline'), 'newline[' . $obj_type . '][' . $definition_id . ']');
1527  $bold->setValue(1);
1528  $bold->setChecked($sub->hasNewline($definition_id));
1529  $check->addSubItem($bold);
1530 
1531  if ($perm && !$perm["newline"]) {
1532  $bold->setDisabled(true);
1533  }
1534 
1535 
1536  $this->form->addItem($check);
1537  }
1538 
1539 
1540  // placeholder
1541  /*
1542  $custom = new ilCustomInputGUI($this->lng->txt('md_adv_placeholders'));
1543  $tpl = new ilTemplate('tpl.placeholder_info.html',true,true,'Services/AdvancedMetaData');
1544  foreach($records as $record)
1545  {
1546  foreach(ilAdvancedMDFieldDefinition::_getDefinitionsByRecordId($record->getRecordId()) as $definition)
1547  {
1548  $tpl->setCurrentBlock('field');
1549  $tpl->setVariable('FIELD_NAME',$definition->getTitle());
1550  $tpl->setVariable('MODULE_VARS','[IF_F_'.$definition->getFieldId().']...[F_'.$definition->getFieldId().']'.
1551  '[/IF_F_'.$definition->getFieldId().']');
1552  $tpl->parseCurrentBlock();
1553  }
1554 
1555  $tpl->setCurrentBlock('record');
1556  $tpl->setVariable('PLACEHOLDER_FOR',$this->lng->txt('md_adv_placeholder_for'));
1557  $tpl->setVariable('TITLE',$record->getTitle());
1558  $tpl->parseCurrentBlock();
1559  }
1560  $custom->setHTML($tpl->get());
1561  $this->form->addItem($custom);
1562  */
1563  }
1564  $this->form->setTitle($this->lng->txt('md_adv_substitution_table'));
1565 
1566  if ($ilAccess->checkAccess('write', '', $_REQUEST["ref_id"])) {
1567  $this->form->addCommandButton('updateSubstitutions', $this->lng->txt('save'));
1568  }
1569 
1570  return true;
1571  }
1572 
1578  protected function loadRecordFormData()
1579  {
1580  $perm = $this->getPermissions()->hasPermissions(
1582  $this->record->getRecordId(),
1583  array(
1591  )
1592  );
1593 
1595  $this->record->setActive(ilUtil::stripSlashes($_POST['active']));
1596  }
1598  $this->record->setTitle(ilUtil::stripSlashes($_POST['title']));
1599  }
1601  $this->record->setDescription(ilUtil::stripSlashes($_POST['desc']));
1602  }
1603 
1604  if (!$this->obj_type) {
1606  $obj_types = array();
1607  if (is_array($_POST['obj_types'])) {
1608  foreach ($_POST['obj_types'] as $t => $value) {
1609  if ($value) {
1610  $t = explode(":", $t);
1611  $obj_types[] = array(
1612  "obj_type" => ilUtil::stripSlashes($t[0]),
1613  "sub_type" => ilUtil::stripSlashes($t[1]),
1614  "optional" => ($value > 1)
1615  );
1616  }
1617  }
1618  }
1619  $this->record->setAssignedObjectTypes($obj_types);
1620  }
1621  }
1622 
1623  $scopes = [];
1624  foreach ((array) $_POST['scope_containers_sel'] as $ref_id) {
1625  $scope = new ilAdvancedMDRecordScope();
1626  $scope->setRefId($ref_id);
1627  $scopes[] = $scope;
1628  }
1629  $this->record->setScopes($_POST['scope'] ? $scopes : []);
1630  $this->record->enableScope($_POST['scope'] ? true : false);
1631  }
1632 
1638  protected function initRecordObject()
1639  {
1640  if (!is_object($this->record)) {
1641  $record_id = isset($_GET['record_id'])
1642  ? $_GET['record_id']
1643  : 0;
1644  $this->record = ilAdvancedMDRecord::_getInstanceByRecordId($record_id);
1645 
1646  // bind to parent object (aka local adv md)
1647  if (!$record_id &&
1648  $this->obj_id) {
1649  $this->record->setParentObject($this->obj_id);
1650  }
1651  }
1652 
1653  return $this->record;
1654  }
1655 
1661  protected function setSubTabs()
1662  {
1663  $this->tabs_gui->clearSubTabs();
1664 
1665  $this->tabs_gui->addSubTabTarget(
1666  "md_adv_record_list",
1667  $this->ctrl->getLinkTarget($this, "showRecords"),
1668  '',
1669  '',
1670  '',
1671  true
1672  );
1673 
1674 
1676  $this->tabs_gui->addSubTabTarget(
1677  "md_adv_presentation",
1678  $this->ctrl->getLinkTarget($this, "showPresentation")
1679  );
1680  }
1681 
1682  $this->tabs_gui->addSubTabTarget(
1683  "md_adv_file_list",
1684  $this->ctrl->getLinkTarget($this, "showFiles"),
1685  "showFiles"
1686  );
1687  }
1688 
1694  protected function getParsedRecordObjects()
1695  {
1696  $res = array();
1697 
1698  if ($this->mode == self::MODE_OBJECT) {
1699  $selected = ilAdvancedMDRecord::getObjRecSelection($this->obj_id, $this->sub_type);
1700  }
1701 
1703  $orderings = new ilAdvancedMDRecordObjectOrderings();
1704  $records = $orderings->sortRecords($records, $this->obj_id);
1705 
1706  $position = 0;
1707  foreach ($records as $record) {
1708  $parent_id = $record->getParentObject();
1709 
1710  if ($this->mode == self::MODE_ADMINISTRATION) {
1711  if ($parent_id) {
1712  continue;
1713  }
1714  } else {
1715  // does not match current object
1716  if ($parent_id && $parent_id != $this->obj_id) {
1717  continue;
1718  }
1719 
1720  // inactive records only in administration
1721  if (!$parent_id && !$record->isActive()) {
1722  continue;
1723  }
1724  // scope needs to match in object context
1725  if (
1727  $this->ref_id,
1728  $record->getScopes()
1729  )
1730  ) {
1731  continue;
1732  }
1733  }
1734 
1735  $tmp_arr = array();
1736  $tmp_arr['id'] = $record->getRecordId();
1737  $tmp_arr['active'] = $record->isActive();
1738  $tmp_arr['title'] = $record->getTitle();
1739  $tmp_arr['description'] = $record->getDescription();
1740  $tmp_arr['fields'] = array();
1741  $tmp_arr['obj_types'] = $record->getAssignedObjectTypes();
1742  $position += 10;
1743  $tmp_arr['position'] = $position;
1744 
1745  $tmp_arr['perm'] = $this->permissions->hasPermissions(
1747  $record->getRecordId(),
1748  array(
1754  )
1755  );
1756 
1757  if ($this->obj_type) {
1758  $tmp_arr["readonly"] = !(bool) $parent_id;
1759  $tmp_arr["local"] = $parent_id;
1760 
1761  // local records are never optional
1762  $assigned = $optional = false;
1763  foreach ($tmp_arr['obj_types'] as $idx => $item) {
1764  if ($item["obj_type"] == $this->obj_type &&
1765  $item["sub_type"] == $this->sub_type) {
1766  $assigned = true;
1767  $optional = $item["optional"];
1768  $tmp_arr['obj_types'][$idx]['context'] = true;
1769  break;
1770  }
1771  }
1772  if (!$assigned) {
1773  continue;
1774  }
1775  $tmp_arr['optional'] = $optional;
1776  if ($optional) {
1777  // in object context "active" means selected record
1778  $tmp_arr['active'] = in_array($record->getRecordId(), $selected);
1779  }
1780  }
1781 
1782  $res[] = $tmp_arr;
1783  }
1784 
1785  return $res;
1786  }
1787 }
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
Scope restrictions for advanced md records.
static getInstance($a_user_id=null, $a_ref_id=null)
Factory.
$files
Definition: metarefresh.php:49
This class represents a selection list property in a property form.
static _getRecords()
Get records.
This class represents a property form user interface.
$type
global $DIC
Definition: saml.php:7
deleteRecords()
Permanently delete records.
$_GET["client_id"]
updateRecords()
Save records (assigned object typed)
This class represents a section header in a property form.
This class represents a file property in a property form.
getSubstitutionFieldPermissions($a_obj_type, $a_field_id)
setValue($a_value)
Set Value.
This class represents a checkbox property in a property form.
getParsedRecordObjects()
Get and cache record objects.
$records
Definition: simple_test.php:22
static isFilteredByScope($a_ref_id, array $scopes)
Check if a given ref id is not filtered by scope restriction.
static saveObjRecSelection($a_obj_id, $a_sub_type="", array $a_records=null, $a_delete_before=true)
Save repository object record selection.
static _getInstanceByObjectType($a_type)
Singleton: use this method to get an instance.
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$section
Definition: Utf8Test.php:83
setChecked($a_checked)
Set Checked.
confirmDeleteFiles()
confirm delete files
static _getInstanceByRecordId($a_record_id)
Get instance by record id.
static getInstancesByRecordId($a_record_id, $a_only_searchable=false)
Get definitions by record id.
foreach($_POST as $key=> $value) $res
if(isset($_POST['submit'])) $form
This class represents a number property in a property form.
static getInstancesByObjType($a_obj_type, $a_active_only=true)
static getInstance($a_field_id, $a_type=null)
Get definition instance by type.
static _lookupObjId($a_id)
addToFieldDefinitionForm(ilPropertyFormGUI $a_form, ilAdvancedMDPermissionHelper $a_permissions)
Add input elements to definition form.
setValue($a_value)
Set Value.
This class represents a text property in a property form.
static _getAllRecordsByObjectType()
Get records by obj_type Note: this returns only records with no sub types! public.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static _lookupTitle($a_record_id)
Lookup title.
createField(ilPropertyFormGUI $a_form=null)
Show field type selection.
static getValidTypes()
Get all valid types.
static _lookupType($a_id, $a_reference=false)
lookup object type
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
editField(ilPropertyFormGUI $a_form=null)
Edit field.
setSize($a_size)
Set Size.
static _getAssignableObjectTypes($a_include_text=false)
Get assignable object type.
$parser
Definition: BPMN2Parser.php:23
updateSubstitutions()
Update substitution.
This class represents a non editable value in a property form.
This class represents a text area property in a property form.
$i
Definition: disco.tpl.php:19
$def
Definition: croninfo.php:21
initFormSubstitutions()
init form table &#39;substitutions&#39;
static _getActivatedObjTypes()
get activated obj types
initFieldForm(ilAdvancedMDFieldDefinition $a_definition)
init field form
SAX based XML parser for record import files.
$info
Definition: index.php:5
setSuffixes($a_suffixes)
Set Accepted Suffixes.
$_POST["username"]
static getObjRecSelection($a_obj_id, $a_sub_type="")
Get repository object record selection.
loadRecordFormData()
load record form data
confirmDeleteFields()
show delete fields confirmation screen
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
static deliverFile( $a_file, $a_filename, $a_mime='', $isInline=false, $removeAfterDelivery=false, $a_exit_after=true)
deliver file for download via browser.
__construct($a_ref_id=null, $a_obj_type=null, $a_sub_type=null)
Constructor.
Confirmation screen class.