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