ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilECSMappingSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
18 declare(strict_types=1);
19 
27 {
28  public const TAB_DIRECTORY = 1;
29  public const TAB_COURSE = 2;
30 
31  protected ilLogger $log;
32  protected ilLanguage $lng;
33  protected ilCtrl $ctrl;
35  private ilTabsGUI $tabs;
37 
40  private int $mid;
41 
42 
46  public function __construct(ilECSSettingsGUI $settingsContainer, int $server_id, int $mid)
47  {
48  global $DIC;
49 
50  $this->lng = $DIC->language();
51  $this->ctrl = $DIC->ctrl();
52  $this->tpl = $DIC->ui()->mainTemplate();
53  $this->log = $DIC->logger()->wsrv();
54  $this->tabs = $DIC->tabs();
55  $this->toolbar = $DIC->toolbar();
56 
57  $this->container = $settingsContainer;
58  $this->server = ilECSSetting::getInstanceByServerId($server_id);
59  $this->mid = $mid;
60  $this->lng->loadLanguageModule('ecs');
61  }
62 
66  public function getContainer(): \ilECSSettingsGUI
67  {
68  return $this->container;
69  }
70 
71  public function getServer(): \ilECSSetting
72  {
73  return $this->server;
74  }
75 
80  public function getMid(): int
81  {
82  return $this->mid;
83  }
84 
88  public function executeCommand(): void
89  {
90  $this->tpl->setTitle($this->lng->txt('ecs_campus_connect_title'));
91 
92  $this->ctrl->saveParameter($this, 'server_id');
93  $this->ctrl->saveParameter($this, 'mid');
94  $this->ctrl->saveParameter($this, 'tid');
95 
96  $next_class = $this->ctrl->getNextClass($this);
97  $cmd = $this->ctrl->getCmd();
98 
99  $this->setTabs();
100  if (!$cmd) {
101  $cmd = "cStart";
102  }
103  $this->$cmd();
104 
105  $this->tpl->setTitle($this->getServer()->getTitle());
106  $this->tpl->setDescription('');
107  }
108 
112  public function cancel(): void
113  {
114  $this->ctrl->returnToParent($this);
115  }
116 
117 
118 
119 
120 
121 
125  protected function cStart(): void
126  {
128  $this->getServer()->getServerId(),
129  $this->getMid()
130  )->isCourseAllocationEnabled()) {
131  $this->cInitOverview();
132  } else {
133  $this->cSettings();
134  }
135  }
136 
140  protected function dStart(): void
141  {
142  if (ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(), $this->getMid())->isDirectoryMappingEnabled()) {
143  $this->dTrees();
144  } else {
145  $this->dSettings();
146  }
147  }
148 
152  protected function cInitOverview($form = null, $current_attribute = null): void
153  {
154  $current_node = (array) (($_REQUEST['lnodes']) ?: ROOT_FOLDER_ID);
155  //TODO fix proper handling of input
156  $current_node = (int) end($current_node);
157 
158  $this->ctrl->setParameter($this, 'lnodes', $current_node);
159 
160  $this->setSubTabs(self::TAB_COURSE);
161  $this->tabs->activateTab('ecs_crs_allocation');
162  $this->tabs->activateSubTab('cInitTree');
163 
164  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.ecs_cmap_overview.html', 'Services/WebServices/ECS');
165 
166  $explorer = $this->cShowLocalExplorer();
167  if (!$form instanceof ilPropertyFormGUI) {
168  if ($current_attribute === null) {
169  // check request
170  $current_attribute = (string) $_REQUEST['ecs_ca'];
171  if (!$current_attribute) {
173  $this->getServer()->getServerId(),
174  $this->getMid(),
175  $current_node
176  );
177 
178  $current_attribute =
179  $existing ?:
180  '';
181  /*
182  ilECSCourseAttributes::getInstance(
183  $this->getServer()->getServerId(),
184  $this->getMid())->getFirstAttributeName()
185  );
186  */
187  }
188  }
189  $form = $this->cInitMappingForm($current_node, $current_attribute);
190  }
191 
192  $this->tpl->setVariable('TFORM_ACTION', $this->ctrl->getFormAction($this));
193  $this->tpl->setVariable('LOCAL_EXPLORER', $explorer->getOutput());
194  $this->tpl->setVariable('MAPPING_FORM', $form->getHTML());
195  }
196 
200  protected function cAddAttribute(): void
201  {
202  $next_attribute = ilECSCourseAttributes::getInstance($this->getServer()->getServerId(), $this->getMid())->getNextAttributeName((string) $_REQUEST['ecs_ca']);
203  $this->cInitOverview(null, $next_attribute);
204  }
205 
209  protected function cDeleteAttribute(): void
210  {
211  $prev_attribute = ilECSCourseAttributes::getInstance($this->getServer()->getServerId(), $this->getMid())->getPreviousAttributeName((string) $_REQUEST['ecs_ca']);
212  $this->cInitOverview(null, $prev_attribute);
213  }
214 
219  {
220  $explorer = new ilECSNodeMappingLocalExplorer(
221  $this->ctrl->getLinkTarget($this, 'cInitOverview'),
222  $this->getServer()->getServerId(),
223  $this->getMid()
224  );
225  $explorer->setPostVar('lnodes[]');
226 
227  $lnodes = (array) $_REQUEST['lnodes'];
228  $checked_node = (int) array_pop($lnodes);
229  if ((int) $_REQUEST['lid']) {
230  $checked_node = (int) $_REQUEST['lid'];
231  }
232 
233  if ($checked_node) {
234  $explorer->setCheckedItems(array($checked_node));
235  } else {
236  $explorer->setCheckedItems(array(ROOT_FOLDER_ID));
237  }
238  $explorer->setTargetGet('lref_id');
239  $explorer->setSessionExpandVariable('lexpand');
240  $explorer->setExpand((int) $_GET['lexpand']);
241  $explorer->setExpandTarget($this->ctrl->getLinkTarget($this, 'cInitOverview'));
242  $explorer->setOutput(0);
243  return $explorer;
244  }
245 
249  protected function cInitMappingForm(int $current_node, $current_attribute): \ilPropertyFormGUI
250  {
251  $attributes_obj = ilECSCourseAttributes::getInstance($this->getServer()->getServerId(), $this->getMid());
252 
253  $form = new ilPropertyFormGUI();
254  $form->setTableWidth("100%");
255  $this->ctrl->setParameter($this, 'ecs_ca', $current_attribute);
256  $form->setFormAction($this->ctrl->getFormAction($this));
257  $this->ctrl->setParameter($this, 'ecs_ca', '');
258 
259  $form->setTitle($this->lng->txt('ecs_cmap_mapping_form_title') . ' ' . ilObject::_lookupTitle(ilObject::_lookupObjId($current_node)));
260 
261  // Iterate through all current attributes
262  $attributes = $attributes_obj->getAttributeSequence($current_attribute);
263  foreach ($attributes as $att_name) {
264  $rule = ilECSCourseMappingRule::getInstanceByAttribute($this->getServer()->getServerId(), $this->getMid(), $current_node, $att_name);
265 
266  $section = new ilFormSectionHeaderGUI();
267  $section->setTitle($this->lng->txt('ecs_cmap_att_' . $att_name));
268 
269  // Filter
270  $form->addItem($section);
271 
272  $isfilter = new ilRadioGroupInputGUI($this->lng->txt('ecs_cmap_form_filter'), $att_name . '_is_filter');
273  $isfilter->setValue($rule->isFilterEnabled() ? "1" : "0");
274 
275  $all_values = new ilRadioOption($this->lng->txt('ecs_cmap_form_all_values'), "0");
276  $isfilter->addOption($all_values);
277 
278  $use_filter = new ilRadioOption($this->lng->txt('ecs_cmap_form_filter_by_values'), "1");
279  $filter = new ilTextInputGUI('', $att_name . '_filter');
280  $filter->setInfo($this->lng->txt('ecs_cmap_form_filter_info'));
281  $filter->setSize(50);
282  $filter->setMaxLength(512);
283  $filter->setRequired(true);
284  $filter->setValue($rule->getFilter());
285  $use_filter->addSubItem($filter);
286 
287  $isfilter->addOption($use_filter);
288 
289  $form->addItem($isfilter);
290 
291  // Create subdirs
292  $subdirs = new ilCheckboxInputGUI($this->lng->txt('ecs_cmap_form_create_subdirs'), $att_name . '_subdirs');
293  $subdirs->setChecked($rule->isSubdirCreationEnabled());
294  $subdirs->setValue("1");
295 
296  // Subdir types (disabled in spec)
297  /*
298  $subdir_type = new ilRadioGroupInputGUI($this->lng->txt('ecs_cmap_form_subdir_type'), $att_name.'_subdir_type');
299  $subdir_type->setValue($rule->getSubDirectoryType());
300 
301  $value = new ilRadioOption($this->lng->txt('ecs_cmap_form_subdir_value'), ilECSCourseMappingRule::SUBDIR_VALUE);
302  $subdir_type->addOption($value);
303 
304  $name = new ilRadioOption($this->lng->txt('ecs_cmap_form_subdir_name'), ilECSCourseMappingRule::SUBDIR_ATTRIBUTE_NAME);
305  $subdir_type->addOption($name);
306 
307  $subdirs->addSubItem($subdir_type);
308  */
309  $form->addItem($subdirs);
310 
311  // Directory relations
312  /*
313  $upper_attributes = ilECSCourseAttributes::getInstance(
314  $this->getServer()->getServerId(),
315  $this->getMid())->getUpperAttributes($att_name);
316 
317  if($upper_attributes)
318  {
319  $dir_relation = new ilRadioGroupInputGUI($this->lng->txt('ecs_cmap_form_dir_relation'),$att_name.'_dir_relation');
320 
321  $current_dir = new ilRadioOption($this->lng->txt('ecs_cmap_form_current_dir'),'');
322  $dir_relation->addOption($current_dir);
323  }
324  foreach($upper_attributes as $subdir_name)
325  {
326  $subdir = new ilRadioOption($this->lng->txt('ecs_cmap_att_'.$subdir_name),$subdir_name);
327  $dir_relation->addOption($subdir);
328  }
329  if($upper_attributes)
330  {
331  $dir_relation->setValue((string) $rule->getDirectory());
332  $form->addItem($dir_relation);
333  }
334  */
335  }
336 
337  // add list of attributes
338  $hidden_atts = new ilHiddenInputGUI('attributes');
339  $hidden_atts->setValue(implode(',', $attributes));
340  $form->addItem($hidden_atts);
341 
342 
343  if ($current_attribute) {
344  $form->addCommandButton('cSaveOverview', $this->lng->txt('save'));
345  }
346 
347  if ($attributes_obj->getNextAttributeName($current_attribute)) {
348  $form->addCommandButton('cAddAttribute', $this->lng->txt('ecs_cmap_add_attribute_btn'));
349  }
350  if ($attributes_obj->getPreviousAttributeName($current_attribute)) {
351  $form->addCommandButton('cDeleteAttribute', $this->lng->txt('ecs_cmap_delete_attribute_btn'));
352  }
354  $this->getServer()->getServerId(),
355  $this->getMid(),
356  $current_node
357  )) {
358  $form->addCommandButton('cDeleteRulesOfNode', $this->lng->txt('ecs_cmap_delete_rule'));
359  }
360 
361  #$form->addCommandButton('cInitOverview', $this->lng->txt('cancel'));
362 
363  $form->setShowTopButtons(false);
364 
365  return $form;
366  }
367 
371  protected function cSaveOverview(): void
372  {
373  $current_node = (int) $_REQUEST['lnodes'];
374  $current_att = (string) $_REQUEST['ecs_ca'];
375  $form = $this->cInitMappingForm($current_node, $current_att);
376 
377  if ($form->checkInput()) {
378  // save ...
379  $all_attributes = explode(',', $form->getInput('attributes'));
380  foreach ((array) $all_attributes as $att_name) {
382  $this->getServer()->getServerId(),
383  $this->getMid(),
384  $current_node,
385  $att_name
386  );
387  $rule->setServerId($this->getServer()->getServerId());
388  $rule->setMid($this->getMid());
389  $rule->setRefId($current_node);
390  $rule->setAttribute($att_name);
391  $rule->enableFilter((bool) $form->getInput($att_name . '_is_filter'));
392  $rule->setFilter($form->getInput($att_name . '_filter'));
393  $rule->enableSubdirCreation((bool) $form->getInput($att_name . '_subdirs'));
394  //$rule->setSubDirectoryType($form->getInput($att_name.'_subdir_type'));
395  //$rule->setDirectory($form->getInput($att_name.'_dir_relation'));
396 
397  if ($rule->getRuleId()) {
398  $rule->update();
399  } else {
400  $rule->save();
401  }
402  }
403 
404  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
405  $this->ctrl->setParameter($this, 'lnodes', $current_node);
406  $this->ctrl->redirect($this, 'cInitOverview');
407  }
408 
409  $form->setValuesByPost();
410  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'));
411  $this->cInitOverview($form, $current_att);
412  }
413 
414  protected function cDeleteRulesOfNode(): void
415  {
416  $current_node = (int) $_REQUEST['lnodes'];
417 
419  $this->getServer()->getServerId(),
420  $this->getMid(),
421  $current_node
422  );
423 
424  foreach ($rules as $rid) {
425  $rule = new ilECSCourseMappingRule($rid);
426  $rule->delete();
427  }
428  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
429  $this->ctrl->redirect($this, 'cInitOverview');
430  }
431 
432 
433 
434 
438  protected function cSettings(ilPropertyFormGUI $form = null): bool
439  {
440  $this->setSubTabs(self::TAB_COURSE);
441  $this->tabs->activateTab('ecs_crs_allocation');
442  $this->tabs->activateSubTab('cSettings');
443 
444  if (!$form instanceof ilPropertyFormGUI) {
445  $form = $this->initFormCSettings();
446  }
447 
448  $this->tpl->setContent($form->getHTML());
449 
450  return true;
451  }
452 
456  protected function initFormCSettings(): \ilPropertyFormGUI
457  {
458  $form = new ilPropertyFormGUI();
459  $form->setFormAction($this->ctrl->getFormAction($this));
460  $form->setTitle($this->lng->txt('settings'));
461 
462  // individual course allocation
463  $check = new ilCheckboxInputGUI($this->lng->txt('ecs_cmap_enable'), 'enabled');
464  $check->setChecked(ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(), $this->getMid())->isCourseAllocationEnabled());
465  $form->addItem($check);
466 
467 
468  // add default container
469  $imp = new ilCustomInputGUI($this->lng->txt('ecs_cmap_def_cat'), 'default_cat');
470  $imp->setRequired(true);
471 
472  $tpl = new ilTemplate('tpl.ecs_import_id_form.html', true, true, 'Services/WebServices/ECS');
473  $tpl->setVariable('SIZE', 5);
474  $tpl->setVariable('MAXLENGTH', 11);
475  $tpl->setVariable('POST_VAR', 'default_cat');
476 
477  $default = ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(), $this->getMid())->getDefaultCourseCategory();
478  $tpl->setVariable('PROPERTY_VALUE', $default);
479 
480  if ($default) {
481  $path = new ilPathGUI();
482  $path->enableTextOnly(false);
483  $path->enableHideLeaf(false);
484  $tpl->setVariable('COMPLETE_PATH', $path->getPath(ROOT_FOLDER_ID, $default));
485  }
486 
487  $imp->setHtml($tpl->get());
488  $imp->setInfo($this->lng->txt('ecs_cmap_def_cat_info'));
489  $form->addItem($imp);
490 
491  // all in one category
492  $allinone = new ilCheckboxInputGUI($this->lng->txt('ecs_cmap_all_in_one'), 'allinone');
493  $allinone->setChecked(ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(), $this->getMid())->isAllInOneCategoryEnabled());
494  $allinone->setInfo($this->lng->txt('ecs_cmap_all_in_one_info'));
495 
496  $allinone_cat = new ilCustomInputGUI($this->lng->txt('ecs_cmap_all_in_one_cat'), 'allinone_cat');
497  $allinone_cat->setRequired(true);
498 
499  $tpl = new ilTemplate('tpl.ecs_import_id_form.html', true, true, 'Services/WebServices/ECS');
500  $tpl->setVariable('SIZE', 5);
501  $tpl->setVariable('MAXLENGTH', 11);
502  $tpl->setVariable('POST_VAR', 'allinone_cat');
503 
504  $cat = ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(), $this->getMid())->getAllInOneCategory();
505  $tpl->setVariable('PROPERTY_VALUE', $cat);
506  if ($cat) {
507  $path = new ilPathGUI();
508  $path->enableTextOnly(false);
509  $path->enableHideLeaf(false);
510  $tpl->setVariable('COMPLETE_PATH', $path->getPath(ROOT_FOLDER_ID, $default));
511  }
512 
513  $allinone_cat->setHtml($tpl->get());
514  $allinone->addSubItem($allinone_cat);
515  $form->addItem($allinone);
516 
517  // multiple attributes
518  $multiple = new ilCheckboxInputGUI($this->lng->txt('ecs_cmap_multiple_atts'), 'multiple');
519  $multiple->setChecked(ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(), $this->getMid())->isAttributeMappingEnabled());
520 
521  // attribute selection
522  $attributes = new ilSelectInputGUI($this->lng->txt('ecs_cmap_attributes'), 'atts');
523  $attributes->setMulti(true);
524  $attributes->setValue(
526  $this->getServer()->getServerId(),
527  $this->getMid()
528  )->getAttributeValues()
529  );
530  $attributes->setRequired(true);
532  $multiple->addSubItem($attributes);
533 
534  $form->addItem($multiple);
535 
536  // role mapping
537  $rm = new ilFormSectionHeaderGUI();
538  $rm->setTitle($this->lng->txt('ecs_role_mappings'));
539  $form->addItem($rm);
540 
541  // auth type
542  $auth_type = new ilSelectInputGUI($this->lng->txt('ecs_member_auth_type'), 'auth_mode');
543  $auth_type->setOptions(ilECSMappingUtils::getAuthModeSelection());
544  $auth_type->setRequired(true);
545  $auth_type->setValue(ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(), $this->getMid())->getAuthMode());
546  $form->addItem($auth_type);
547 
548  $mapping_defs = ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(), $this->getMid())->getRoleMappings();
549 
550  foreach (ilECSMappingUtils::getRoleMappingInfo() as $name => $info) {
551  $role_map = new ilTextInputGUI($this->lng->txt($info['lang']), (string) $name);
552  if (isset($mapping_defs[$name])) {
553  $role_map->setValue($mapping_defs[$name]);
554  }
555  $role_map->setSize(32);
556  $role_map->setMaxLength(64);
557  $role_map->setRequired($info['required']);
558  $form->addItem($role_map);
559  }
560 
561  $form->addCommandButton('cUpdateSettings', $this->lng->txt('save'));
562  $form->addCommandButton('cSettings', $this->lng->txt('cancel'));
563 
564  return $form;
565  }
566 
570  protected function dSettings(ilPropertyFormGUI $form = null): bool
571  {
572  $this->setSubTabs(self::TAB_DIRECTORY);
573  $this->tabs->activateTab('ecs_dir_allocation');
574  $this->tabs->activateSubTab('dSettings');
575 
576  if (!$form instanceof ilPropertyFormGUI) {
577  $form = $this->initFormDSettings();
578  }
579 
580  $this->tpl->setContent($form->getHTML());
581 
582  return true;
583  }
584 
588  protected function cUpdateSettings(): void
589  {
590  $form = $this->initFormCSettings();
591  if ($form->checkInput()) {
592  $settings = ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(), $this->getMid());
593  $settings->enableCourseAllocation((bool) $form->getInput('enabled'));
594  $settings->setDefaultCourseCategory((int) $form->getInput('default_cat'));
595  $settings->enableAllInOne((bool) $form->getInput('allinone'));
596  $settings->setAllInOneCategory((int) $form->getInput('allinone_cat'));
597  $settings->enableAttributeMapping((bool) $form->getInput('multiple'));
598  $settings->setAuthMode($form->getInput('auth_mode'));
599 
600  $role_mappings = [];
601  foreach (ilECSMappingUtils::getRoleMappingInfo() as $role => $name) {
602  $role_mappings[$role] = $form->getInput((string) $role);
603  }
604  $settings->setRoleMappings($role_mappings);
605  $settings->update();
606 
607  // store attribute settings
608  $attributes = new ilECSCourseAttributes($this->getServer()->getServerId(), $this->getMid());
609  $attributes->delete();
610 
611  $form_atts = $form->getInput('atts');
612 
613  foreach ($form_atts as $name) {
614  if (!$name) {
615  continue;
616  }
617 
618  $att = new ilECSCourseAttribute();
619  $att->setServerId($this->getServer()->getServerId());
620  $att->setMid($this->getMid());
621  $att->setName($name);
622  $att->save();
623  }
624 
625  //$att = new ilECSCourseAttribute();
626  //$att->setName($a_name)
627 
628  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
629  $this->ctrl->redirect($this, 'cSettings');
630  }
631  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'));
632  $form->setValuesByPost();
633  $this->cSettings($form);
634  }
635 
639  protected function dUpdateSettings(): void
640  {
641  $form = $this->initFormDSettings();
642  if ($form->checkInput()) {
643  $settings = ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(), $this->getMid());
644  $settings->enableDirectoryMapping((bool) $form->getInput('active'));
645  $settings->enableEmptyContainerCreation(!$form->getInput('empty'));
646  $settings->update();
647  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
648  } else {
649  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'), true);
650  $form->setValuesByPost();
651  }
652  $this->ctrl->redirect($this, 'dSettings');
653  }
654 
658  protected function initFormDSettings(): \ilPropertyFormGUI
659  {
660  $form = new ilPropertyFormGUI();
661  $form->setFormAction($this->ctrl->getFormAction($this));
662  $form->setTitle($this->lng->txt('general_settings'));
663 
664  $active = new ilCheckboxInputGUI($this->lng->txt('ecs_node_mapping_activate'), 'active');
665  $active->setChecked(ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(), $this->getMid())->isDirectoryMappingEnabled());
666  $form->addItem($active);
667 
668  $create_empty = new ilCheckboxInputGUI($this->lng->txt('ecs_node_mapping_create_empty'), 'empty');
669  $create_empty->setChecked(!ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(), $this->getMid())->isEmptyContainerCreationEnabled());
670  $create_empty->setInfo($this->lng->txt('ecs_node_mapping_create_empty_info'));
671  $form->addItem($create_empty);
672 
673  $form->addCommandButton('dUpdateSettings', $this->lng->txt('save'));
674  $form->addCommandButton('cancel', $this->lng->txt('cancel'));
675 
676  return $form;
677  }
678 
682  protected function dTrees(): bool
683  {
684  $this->setSubTabs(self::TAB_DIRECTORY);
685  $this->tabs->activateSubTab('dTrees');
686  $this->tabs->activateTab('ecs_dir_allocation');
687 
688  $this->toolbar->addButton(
689  $this->lng->txt('ecs_sync_trees'),
690  $this->ctrl->getLinkTarget($this, 'dSynchronizeTrees')
691  );
692 
693  $dtreeTable = new ilECSNodeMappingTreeTableGUI(
694  $this->getServer()->getServerId(),
695  $this->getMid(),
696  $this,
697  'dtree'
698  );
699 
700 
701  $dtreeTable->parse();
702  $this->tpl->setContent($dtreeTable->getHTML());
703  return true;
704  }
705 
709  protected function dConfirmDeleteTree(): void
710  {
711  $this->setSubTabs(self::TAB_DIRECTORY);
712  $this->tabs->activateSubTab('dTrees');
713  $this->tabs->activateTab('ecs_dir_allocation');
714 
715  $confirm = new ilConfirmationGUI();
716  $confirm->setFormAction($this->ctrl->getFormAction($this));
717  $confirm->setHeaderText($this->lng->txt('ecs_confirm_delete_tree'));
718 
719  $confirm->addItem(
720  'tid',
721  $_REQUEST['tid'],
723  $this->getServer()->getServerId(),
724  $this->getMid(),
725  (int) $_REQUEST['tid']
726  )
727  );
728  $confirm->setConfirm($this->lng->txt('delete'), 'dDeleteTree');
729  $confirm->setCancel($this->lng->txt('cancel'), 'dTrees');
730 
731  $this->tpl->setContent($confirm->getHTML());
732  }
733 
737  protected function dDeleteTree(): void
738  {
739  $this->log->info('Deleting tree');
740 
741  $tree = new ilECSCmsTree((int) $_REQUEST['tid']);
742  $tree->deleteTree($tree->getNodeData(ilECSCmsTree::lookupRootId((int) $_REQUEST['tid'])));
743 
744 
745 
746  // also delete import information
747  ilECSImportManager::getInstance()->deleteRessources(
748  $this->getServer()->getServerId(),
749  $this->getMid(),
751  $this->getServer()->getServerId(),
752  $this->getMid(),
753  (int) $_REQUEST['tid']
754  )
755  );
756 
757  $data = new ilECSCmsData();
758  $data->setServerId($this->getServer()->getServerId());
759  $data->setMid($this->getMid());
760  $data->setTreeId((int) $_REQUEST['tid']);
761  $data->deleteTree();
762 
764  $this->getServer()->getServerId(),
765  $this->getMid(),
766  (int) $_REQUEST['tid']
767  );
768 
769  $this->tpl->setOnScreenMessage('success', $this->lng->txt('ecs_cms_tree_deleted'), true);
770  $this->ctrl->redirect($this, 'dTrees');
771  }
772 
776  protected function dEditTree(ilPropertyFormGUI $form = null): void
777  {
778  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.ecs_edit_tree.html', 'Services/WebServices/ECS');
779 
780  $this->ctrl->saveParameter($this, 'cid');
781 
782  $this->tabs->clearTargets();
783  $this->tabs->setBack2Target(
784  $this->lng->txt('ecs_back_settings'),
785  $this->ctrl->getLinkTarget($this, 'cancel')
786  );
787  $this->tabs->setBackTarget(
788  $this->lng->txt('ecs_cms_dir_tree'),
789  $this->ctrl->getLinkTarget($this, 'dTrees')
790  );
791 
792  $this->tpl->setVariable('LEGEND', $this->lng->txt('ecs_status_legend'));
793  $this->tpl->setVariable('PENDING_UNMAPPED', $this->lng->txt('ecs_status_pending_unmapped'));
794  $this->tpl->setVariable('PENDING_UNMAPPED_DISCON', $this->lng->txt('ecs_status_pending_unmapped_discon'));
795  $this->tpl->setVariable('PENDING_UNMAPPED_NONDISCON', $this->lng->txt('ecs_status_pending_unmapped_nondiscon'));
796  $this->tpl->setVariable('MAPPED', $this->lng->txt('ecs_status_mapped'));
797  $this->tpl->setVariable('DELETED', $this->lng->txt('ecs_status_deleted'));
798 
799  $form = $this->dInitFormTreeSettings($form);
800  $this->tpl->setVariable('GENERAL_FORM', $form->getHTML());
801  $this->tpl->setVariable('TFORM_ACTION', $this->ctrl->getFormAction($this, 'dEditTree'));
802 
803  $explorer = $this->dShowLocalExplorer();
804  $this->dShowCmsExplorer($explorer);
805  }
806 
810  protected function dInitFormTreeSettings(ilPropertyFormGUI $form = null): \ilPropertyFormGUI
811  {
812  if ($form instanceof ilPropertyFormGUI) {
813  return $form;
814  }
815 
816  $assignment = new ilECSNodeMappingAssignment(
817  $this->getServer()->getServerId(),
818  $this->getMid(),
819  (int) $_REQUEST['tid'],
820  0
821  );
822 
823  $form = new ilPropertyFormGUI();
824  $form->setFormAction($this->ctrl->getFormAction($this, 'dEditTree'));
825  $form->setTitle($this->lng->txt('general_settings'));
826  $form->addCommandButton('dUpdateTreeSettings', $this->lng->txt('save'));
827  $form->addCommandButton('dTrees', $this->lng->txt('cancel'));
828  $form->setTableWidth('30%');
829 
830  // CMS id (readonly)
831  $cmsid = new ilNumberInputGUI($this->lng->txt('ecs_cms_id'), 'cmsid');
832  $cmsid->setValue(
834  );
835  $cmsid->setDisabled(true);
836  $cmsid->setSize(7);
837  $cmsid->setMaxLength(12);
838  $form->addItem($cmsid);
839 
840 
841  $mapping_status = ilECSMappingUtils::lookupMappingStatus(
842  $this->getServer()->getServerId(),
843  $this->getMid(),
844  (int) $_REQUEST['tid']
845  );
846  $mapping_advanced = ($mapping_status !== ilECSMappingUtils::MAPPED_MANUAL);
847 
848  // Status (readonly)
849  $status = new ilNonEditableValueGUI($this->lng->txt('status'), '');
850  $status->setValue(ilECSMappingUtils::mappingStatusToString($mapping_status));
851  $form->addItem($status);
852 
853  // title update
854  $title = new ilCheckboxInputGUI($this->lng->txt('ecs_title_updates'), 'title');
855  $title->setValue("1");
856  $title->setChecked($assignment->isTitleUpdateEnabled());
857  #$title->setInfo($this->lng->txt('ecs_title_update_info'));
858  $form->addItem($title);
859 
860 
861  $position = new ilCheckboxInputGUI($this->lng->txt('ecs_position_updates'), 'position');
862  $position->setDisabled(!$mapping_advanced);
863  $position->setChecked($mapping_advanced && $assignment->isPositionUpdateEnabled());
864  $position->setValue("1");
865  #$position->setInfo($this->lng->txt('ecs_position_update_info'));
866  $form->addItem($position);
867 
868  $tree = new ilCheckboxInputGUI($this->lng->txt('ecs_tree_updates'), 'tree');
869  $tree->setDisabled(!$mapping_advanced);
870  $tree->setChecked($mapping_advanced && $assignment->isTreeUpdateEnabled());
871  $tree->setValue("1");
872  #$tree->setInfo($this->lng->txt('ecs_tree_update_info'));
873  $form->addItem($tree);
874 
875  return $form;
876  }
877 
882  protected function dUpdateTreeSettings(): bool
883  {
884  $assignment = new ilECSNodeMappingAssignment(
885  $this->getServer()->getServerId(),
886  $this->getMid(),
887  (int) $_REQUEST['tid'],
888  0
889  );
890  $assignment->setRefId(0);
891  $assignment->setObjId(0);
892 
893  $form = $this->dInitFormTreeSettings();
894  if ($form->checkInput()) {
895  $assignment->enableTitleUpdate($form->getInput('title'));
896  $assignment->enableTreeUpdate($form->getInput('tree'));
897  $assignment->enablePositionUpdate($form->getInput('position'));
898  $assignment->update();
899 
900  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved', "1"));
901  $this->ctrl->redirect($this, 'dEditTree');
902  }
903 
904  $form->setValuesByPost();
905  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'));
906  $this->dEditTree($form);
907  return true;
908  }
909 
913  protected function dSynchronizeTree(): void
914  {
915  $sync = new ilECSCmsTreeSynchronizer(
916  $this->getServer(),
917  $this->mid,
918  (int) $_REQUEST['tid']
919  );
920  $sync->sync();
921  $this->tpl->setOnScreenMessage('success', $this->lng->txt('ecs_cms_tree_synchronized'), true);
922  $this->ctrl->redirect($this, 'dTrees');
923  }
924 
925  protected function dSynchronizeTrees(): void
926  {
927  $this->log->dump('Start synchronizing cms directory trees');
928 
929  try {
930  $connector = new ilECSDirectoryTreeConnector($this->getServer());
931  $res = $connector->getDirectoryTrees();
932 
933  $this->log->dump($res, ilLogLevel::DEBUG);
934 
935  foreach ($res->getLinkIds() as $cms_id) {
936  $event = new ilECSEventQueueReader($this->getServer());
937  $event->add(
939  $cms_id,
941  );
942  }
943  $this->ctrl->redirect($this, 'dTrees');
944  } catch (Exception $e) {
945  $this->tpl->setOnScreenMessage('failure', $e->getMessage(), true);
946  $this->ctrl->redirect($this, 'dTrees');
947  }
948  }
949 
954  {
955  $explorer = new ilECSNodeMappingLocalExplorer(
956  $this->ctrl->getLinkTarget($this, 'dEditTree'),
957  $this->getServer()->getServerId(),
958  $this->getMid()
959  );
960  $explorer->setPostVar('lnodes[]');
961 
962  $lnodes = (array) $_REQUEST['lnodes'];
963  $checked_node = array_pop($lnodes);
964  if ((int) $_REQUEST['lid']) {
965  $checked_node = (int) $_REQUEST['lid'];
966  }
967 
968  if ($checked_node) {
969  $explorer->setCheckedItems(array($checked_node));
970  } else {
971  $explorer->setCheckedItems(array(ROOT_FOLDER_ID));
972  }
973  $explorer->setTargetGet('lref_id');
974  $explorer->setSessionExpandVariable('lexpand');
975  $explorer->setExpand((int) $_GET['lexpand']);
976  $explorer->setExpandTarget($this->ctrl->getLinkTarget($this, 'dEditTree'));
977  $explorer->setOutput(0);
978  $this->tpl->setVariable('LOCAL_EXPLORER', $explorer->getOutput());
979 
980  return $explorer;
981  }
982 
986  protected function dShowCmsExplorer(ilExplorer $localExplorer): void
987  {
988  $explorer = new ilECSNodeMappingCmsExplorer(
989  $this->ctrl->getLinkTarget($this, 'dEditTree'),
990  $this->getServer()->getServerId(),
991  $this->getMid(),
992  (int) $_REQUEST['tid']
993  );
994  $explorer->setRoot(ilECSCmsTree::lookupRootId((int) $_REQUEST['tid']));
995  $explorer->setTree(
996  new ilECSCmsTree(
997  (int) $_REQUEST['tid']
998  )
999  );
1000  $explorer->setPostVar('rnodes[]');
1001 
1002  // Read checked items from mapping of checked items in local explorer
1003  // $active_node = $this->tree->getRootId();
1004  foreach ($localExplorer->getCheckedItems() as $ref_id) {
1005  $explorer->setCheckedItems(
1007  $this->getServer()->getServerId(),
1008  $this->getMid(),
1009  (int) $_REQUEST['tid'],
1010  $ref_id
1011  )
1012  );
1013  // $active_node = $ref_id;
1014  }
1015 
1016  // $cmsTree = new ilECSCmsTree((int) $_REQUEST['tid']);
1017  // foreach (ilECSNodeMappingAssignments::lookupAssignmentsByRefId(
1018  // $this->getServer()->getServerId(),
1019  // $this->getMid(),
1020  // (int) $_REQUEST['tid'],
1021  // $active_node
1022  // ) as $cs_id) {
1023  // foreach ($cmsTree->getPathId($cs_id) as $path_id) {
1024  // #$explorer->setExpand($path_id);
1025  // }
1026  // }
1027 
1028  $explorer->setTargetGet('rref_id');
1029  $explorer->setSessionExpandVariable('rexpand');
1030 
1031  #if((int) $_REQUEST['rexpand'])
1032  {
1033  $explorer->setExpand((int) $_GET['rexpand']);
1034  }
1035  $explorer->setExpandTarget($this->ctrl->getLinkTarget($this, 'dEditTree'));
1036  $explorer->setOutput(0);
1037  $this->tpl->setVariable('REMOTE_EXPLORER', $explorer->getOutput());
1038  }
1039 
1043  protected function dInitEditTree(): void
1044  {
1046  $this->getServer()->getServerId(),
1047  $this->getMid(),
1048  (int) $_REQUEST['tid']
1049  );
1050  $this->dEditTree();
1051  }
1052 
1053 
1057  protected function dMap(): void
1058  {
1059  if (!$_POST['lnodes']) {
1060  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'), true);
1061  $this->ctrl->redirect($this, 'dEditTree');
1062  }
1063 
1064  $ref_id = end($_POST['lnodes']);
1065 
1067  $this->getServer()->getServerId(),
1068  $this->getMid(),
1069  (int) $_REQUEST['tid'],
1070  $ref_id
1071  );
1072 
1073 
1074  $nodes = (array) $_POST['rnodes'];
1075  $nodes = array_reverse($nodes);
1076 
1077  foreach ($nodes as $cms_id) {
1078  $assignment = new ilECSNodeMappingAssignment(
1079  $this->getServer()->getServerId(),
1080  $this->getMid(),
1081  (int) $_REQUEST['tid'],
1082  (int) $cms_id
1083  );
1084  $assignment->setRefId($ref_id);
1085  $assignment->setObjId(ilObject::_lookupObjId($ref_id));
1086  $assignment->enablePositionUpdate(false);
1087  $assignment->enableTreeUpdate(false);
1088  $assignment->enableTitleUpdate(ilECSNodeMappingAssignments::lookupDefaultTitleUpdate(
1089  $this->getServer()->getServerId(),
1090  $this->getMid(),
1091  (int) $_REQUEST['tid']
1092  ));
1093  $assignment->update();
1094 
1095  // Delete subitems mappings for cms subtree
1096  $cmsTree = new ilECSCmsTree((int) $_REQUEST['tid']);
1097  $childs = $cmsTree->getSubTreeIds($cms_id);
1098 
1100  $this->getServer()->getServerId(),
1101  $this->getMid(),
1102  (int) $_REQUEST['tid'],
1103  $childs
1104  );
1105  }
1106 
1108  $this->getServer()->getServerId(),
1109  $this->getMid(),
1110  (int) $_REQUEST['tid']
1111  );
1112 
1113  // Save parameter cid
1114  $this->ctrl->setParameter($this, 'lid', (int) $ref_id);
1115 
1116  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
1117  $this->ctrl->redirect($this, 'dEditTree');
1118  }
1119 
1123  protected function dMappingOverview(): void
1124  {
1125  $this->setSubTabs(self::TAB_DIRECTORY);
1126  $this->tabs->activateSubTab('dMappingOverview');
1127  $this->tabs->activateTab('ecs_dir_allocation');
1128  }
1129 
1130 
1131 
1135  protected function setTabs(): void
1136  {
1137  $this->tabs->clearTargets();
1138  $this->tabs->setBackTarget(
1139  $this->lng->txt('ecs_back_settings'),
1140  $this->ctrl->getParentReturnByClass(self::class)
1141  );
1142  // Directories are only visible for import type campus managment.
1143  if (ilECSParticipantSettings::getInstanceByServerId($this->getServer()->getServerId())->lookupCmsMid() === $this->getMid()) {
1144  $this->tabs->addTab(
1145  'ecs_dir_allocation',
1146  $this->lng->txt('ecs_dir_alloc'),
1147  $this->ctrl->getLinkTarget($this, 'dSettings')
1148  );
1149  }
1150 
1151  $this->tabs->addTab(
1152  'ecs_crs_allocation',
1153  $this->lng->txt('ecs_crs_alloc'),
1154  $this->ctrl->getLinkTarget($this, 'cStart')
1155  );
1156  }
1157 
1161  protected function setSubTabs(int $a_tab): void
1162  {
1163  if ($a_tab === self::TAB_DIRECTORY) {
1164  $this->tabs->addSubTab(
1165  'dMappingOverview',
1166  $this->lng->txt('ecs_cc_mapping_overview'),
1167  $this->ctrl->getLinkTarget($this, 'dMappingOverview')
1168  );
1169  $this->tabs->addSubTab(
1170  'dTrees',
1171  $this->lng->txt('ecs_cms_dir_tree'),
1172  $this->ctrl->getLinkTarget($this, 'dTrees')
1173  );
1174  $this->tabs->addSubTab(
1175  'dSettings',
1176  $this->lng->txt('settings'),
1177  $this->ctrl->getLinkTarget($this, 'dSettings')
1178  );
1179  }
1180  if ($a_tab === self::TAB_COURSE) {
1181  if (ilECSNodeMappingSettings::getInstanceByServerMid($this->getServer()->getServerId(), $this->getMid())->isCourseAllocationEnabled()) {
1182  $this->tabs->addSubTab(
1183  'cInitTree',
1184  $this->lng->txt('ecs_cmap_overview'),
1185  $this->ctrl->getLinkTarget($this, 'cInitOverview')
1186  );
1187  }
1188 
1189  $this->tabs->addSubTab(
1190  'cSettings',
1191  $this->lng->txt('settings'),
1192  $this->ctrl->getLinkTarget($this, 'cSettings')
1193  );
1194  }
1195  }
1196 }
static lookupCmsIdsOfTree($a_server_id, $a_mid, $a_tree_id)
Creates a path for a start and endnode.
$attributes
Definition: metadata.php:248
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$res
Definition: ltiservices.php:69
dMappingOverview()
Show directory trees.
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
static getRoleMappingInfo($a_role_type_info=0)
Get role mapping info.
static getInstanceByServerId(int $a_server_id)
Get instance by server id.
setSubTabs(int $a_tab)
Set Sub tabs.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance(int $a_server_id, int $a_mid)
Get instance.
const ROOT_FOLDER_ID
Definition: constants.php:32
cSettings(ilPropertyFormGUI $form=null)
Show course allocation.
getContainer()
Get container object.
static getInstanceByServerMid(int $a_server_id, int $a_mid)
Get instance.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static lookupRootId($a_tree_id)
lookup root id
setInfo(string $a_info)
executeCommand()
ilCtrl executeCommand
static deleteMappingsByCsId(int $a_server_id, int $a_mid, int $a_tree_id, array $cs_ids)
Delete mappings.
dShowCmsExplorer(ilExplorer $localExplorer)
Show cms explorer.
dShowLocalExplorer()
Show local explorer.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
dSettings(ilPropertyFormGUI $form=null)
Show directory allocation.
This class represents a checkbox property in a property form.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
static deleteMappings(int $a_server_id, int $a_mid, int $a_tree_id)
Delete mappings.
static updateStatus(int $a_server_id, int $a_mid, int $a_tree_id)
static lookupMappingStatus(int $a_server_id, int $a_mid, int $a_tree_id)
Lookup mapping status.
dEditTree(ilPropertyFormGUI $form=null)
Edit directory tree assignments.
$path
Definition: ltiservices.php:32
static getCourseMappingFieldSelectOptions()
static _lookupObjId(int $ref_id)
static lookupDefaultTitleUpdate($a_server_id, $a_mid, $a_tree_id)
Lookup default title update setting.
cancel()
return to parent container
static getRulesOfRefId(int $a_sid, int $a_mid, int $a_ref_id)
Get all rule of ref_id.
static lookupLastExistingAttribute(int $a_sid, int $a_mid, int $a_ref_id)
Lookup existing attributes.
__construct(ilECSSettingsGUI $settingsContainer, int $server_id, int $mid)
Constructor.
static mappingStatusToString(int $a_status)
Get mapping status as string.
global $DIC
Definition: feed.php:28
if($format !==null) $name
Definition: metadata.php:247
cShowLocalExplorer()
Show local explorer.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance()
Get the singleton instance of this ilECSImportManager.
$ref_id
Definition: ltiauth.php:67
This class represents a property in a property form.
static _lookupTitle(int $obj_id)
$_GET['client_id']
Definition: saml1-acs.php:21
cAddAttribute()
Add one attribute in form.
Storage of course attributes for assignment rules.
cInitOverview($form=null, $current_attribute=null)
Show overview page.
This class represents a number property in a property form.
setValue(?string $a_value)
static getAuthModeSelection()
Get auth mode selection with active authentication modes.
setValue(string $a_value)
static getInstanceByServerId(int $a_server_id)
Get singleton instance per server.
static deleteDisconnectableMappings(int $a_server_id, int $a_mid, int $a_tree_id, int $a_ref_id)
delete disconnectable mappings
Reads ECS events and stores them in the database.
static lookupTitle(int $a_server_id, int $a_mid, int $a_tree_id)
Lookup title by obj id.
cUpdateSettings()
Update course settings.
setRequired(bool $a_required)
dUpdateSettings()
Update node mapping settings.
dInitFormTreeSettings(ilPropertyFormGUI $form=null)
Init form settings.
static getInstanceByAttribute($a_sid, $a_mid, $a_ref_id, $a_att)
Get rule instance by attribute.
class for explorer view in admin frame
static hasRules(int $a_sid, int $a_mid, int $a_ref_id)
dConfirmDeleteTree()
Delete tree settings.
cDeleteAttribute()
Delete last attribute in form.
static lookupCmsId($a_obj_id)
Lookup cms id.
static lookupMappedItemsForRefId(int $a_server_id, int $a_mid, int $a_tree_id, int $a_ref_id)
Get cs ids for ref_id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Storage of course attributes for assignment rules.
$check
Definition: buildRTE.php:81
cInitMappingForm(int $current_node, $current_attribute)
Init the mapping form.
setDisabled(bool $a_disabled)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class for ECS node and directory mapping settings.