ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilConditionHandlerGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
23 
33 {
34  private const LIST_MODE_UNDEFINED = 'undefined';
35  private const LIST_MODE_ALL = 'all';
36  private const LIST_MODE_SUBSET = 'subset';
37 
38  protected ilCtrl $ctrl;
39  protected ilLanguage $lng;
41  protected ilTree $tree;
47  private Factory $refinery;
48 
50  protected ?ilObject $target_obj = null;
51  protected int $target_id = 0;
52  protected string $target_type = '';
53  protected string $target_title = '';
54  protected int $target_ref_id = 0;
55 
56  protected bool $automatic_validation = true;
57 
58  public function __construct(int $a_ref_id = null)
59  {
60  global $DIC;
61 
62  $this->ch_obj = new ilConditionHandler();
63  $this->ctrl = $DIC->ctrl();
64  $this->lng = $DIC->language();
65  $this->lng->loadLanguageModule('rbac');
66  $this->lng->loadLanguageModule('cond');
67  $this->tpl = $DIC->ui()->mainTemplate();
68  $this->tree = $DIC->repositoryTree();
69  $this->access = $DIC->access();
70  $this->toolbar = $DIC->toolbar();
71  $this->conditionUtil = $DIC->conditions()->util();
72  $this->objectDefinition = $DIC['objDefinition'];
73  $this->http = $DIC->http();
74  $this->refinery = $DIC->refinery();
75 
76  if ($a_ref_id) {
77  $target_obj = ilObjectFactory::getInstanceByRefId($a_ref_id);
78  if ($target_obj !== null) {
79  $this->setTargetId($target_obj->getId());
80  $this->setTargetRefId($target_obj->getRefId());
81  $this->setTargetType($target_obj->getType());
82  $this->setTargetTitle($target_obj->getTitle());
83  }
84  }
85  }
86 
87  protected function initConditionIdFromQuery(): int
88  {
89  if ($this->http->wrapper()->query()->has('condition_id')) {
90  return $this->http->wrapper()->query()->retrieve(
91  'condition_id',
92  $this->refinery->kindlyTo()->int()
93  );
94  }
95  return 0;
96  }
97 
98  protected function initConditionsIdsFromPost(): SplFixedArray
99  {
100  if ($this->http->wrapper()->post()->has('conditions')) {
101  return SplFixedArray::fromArray(
102  $this->http->wrapper()->post()->retrieve(
103  'conditions',
104  $this->refinery->kindlyTo()->listOf(
105  $this->refinery->kindlyTo()->int()
106  )
107  )
108  );
109  }
110  return new SplFixedArray(0);
111  }
112 
113  protected function initItemIdsFromPost(): SplFixedArray
114  {
115  if ($this->http->wrapper()->post()->has('item_ids')) {
116  return SplFixedArray::fromArray(
117  $this->http->wrapper()->post()->retrieve(
118  'item_ids',
119  $this->refinery->kindlyTo()->listOf(
120  $this->refinery->kindlyTo()->int()
121  )
122  )
123  );
124  }
125  return new SplFixedArray(0);
126  }
127 
128  protected function initObligatoryItemsFromPost(): SplFixedArray
129  {
130  if ($this->http->wrapper()->post()->has('obl')) {
131  return SplFixedArray::fromArray(
132  $this->http->wrapper()->post()->retrieve(
133  'obl',
134  $this->refinery->kindlyTo()->listOf(
135  $this->refinery->kindlyTo()->int()
136  )
137  )
138  );
139  }
140  return new SplFixedArray(0);
141  }
142 
143  protected function initListModeFromPost(): string
144  {
145  return $this->http->wrapper()->post()->retrieve(
146  'list_mode',
147  $this->refinery->byTrying([
148  $this->refinery->kindlyTo()->string(),
149  $this->refinery->always(self::LIST_MODE_UNDEFINED)
150  ])
151  );
152  }
153 
154  protected function initSourceIdFromQuery(): int
155  {
156  if ($this->http->wrapper()->query()->has('source_id')) {
157  return $this->http->wrapper()->query()->retrieve(
158  'source_id',
159  $this->refinery->kindlyTo()->int()
160  );
161  }
162  return 0;
163  }
164 
165  public static function translateOperator(int $a_obj_id, string $a_operator): string
166  {
167  global $DIC;
168 
169  $lng = $DIC->language();
170  switch ($a_operator) {
172  $lng->loadLanguageModule('trac');
173 
174  $obj_settings = new ilLPObjSettings($a_obj_id);
175  return ilLPObjSettings::_mode2Text($obj_settings->getMode());
176 
177  default:
178  $lng->loadLanguageModule('rbac');
179  return $lng->txt('condition_' . $a_operator);
180  }
181  }
182 
184  {
185  return $this->ch_obj;
186  }
187 
188  public function setBackButtons(array $a_btn_arr): void
189  {
190  ilSession::set('precon_btn', $a_btn_arr);
191  }
192 
193  public function getBackButtons(): array
194  {
195  if (ilSession::has('precon_btn')) {
196  return ilSession::get('precon_btn');
197  }
198  return [];
199  }
200 
201  public function executeCommand(): void
202  {
203  global $DIC;
204 
205  $ilErr = $DIC['ilErr'];
206 
207  if (!$this->access->checkAccess('write', '', $this->getTargetRefId())) {
208  $ilErr->raiseError($this->lng->txt('permission_denied'), $ilErr->WARNING);
209  }
210 
211  $next_class = $this->ctrl->getNextClass($this);
212  $cmd = $this->ctrl->getCmd();
213  switch ($next_class) {
214  default:
215  if (empty($cmd)) {
216  $cmd = "view";
217  }
218  $this->$cmd();
219  break;
220  }
221  }
222 
223  public function setAutomaticValidation(bool $a_status): void
224  {
225  $this->automatic_validation = $a_status;
226  }
227 
228  public function getAutomaticValidation(): bool
229  {
231  }
232 
233  public function setTargetId(int $a_target_id): void
234  {
235  $this->target_id = $a_target_id;
236  }
237 
238  public function getTargetId(): int
239  {
240  return $this->target_id;
241  }
242 
243  public function setTargetRefId(int $a_target_ref_id): void
244  {
245  $this->target_ref_id = $a_target_ref_id;
246  }
247 
248  public function getTargetRefId(): int
249  {
250  return $this->target_ref_id;
251  }
252 
253  public function setTargetType(string $a_target_type): void
254  {
255  $this->target_type = $a_target_type;
256  }
257 
258  public function getTargetType(): string
259  {
260  return $this->target_type;
261  }
262 
263  public function setTargetTitle(string $a_target_title): void
264  {
265  $this->target_title = $a_target_title;
266  }
267 
271  public function isTargetReferenced(): bool
272  {
273  return (bool) $this->getTargetRefId();
274  }
275 
276  public function getTargetTitle(): string
277  {
278  return $this->target_title;
279  }
280 
281  protected function listConditions(): void
282  {
283  // check if parent deals with conditions
284  if (
285  $this->getTargetRefId() > 0 &&
286  $this->conditionUtil->isUnderParentControl($this->getTargetRefId())
287  ) {
288  $this->tpl->setOnScreenMessage('info', $this->lng->txt("cond_under_parent_control"));
289  return;
290  }
291 
292  $this->toolbar->addButton($this->lng->txt('add_condition'), $this->ctrl->getLinkTarget($this, 'selector'));
293  $this->tpl->addBlockFile('ADM_CONTENT', 'adm_content', 'tpl.list_conditions.html', 'Services/AccessControl');
294 
296  $this->getTargetRefId(),
297  $this->getTargetId(),
298  $this->getTargetType()
299  );
300  $list_mode = $this->initListModeFromPost();
301  if (count($optional_conditions)) {
302  if ($list_mode === self::LIST_MODE_UNDEFINED) {
303  $list_mode = self::LIST_MODE_SUBSET;
304  }
305  } elseif ($list_mode === self::LIST_MODE_UNDEFINED) {
306  $list_mode = self::LIST_MODE_ALL;
307  }
308 
309  // Show form only if conditions are availabe
311  $this->getTargetRefId(),
312  $this->getTargetId(),
313  $this->getTargetType()
314  ))
315  ) {
316  $form = $this->showObligatoryForm($list_mode);
317  if ($form instanceof ilPropertyFormGUI) {
318  $this->tpl->setVariable('TABLE_SETTINGS', $form->getHTML());
319  }
320  }
321 
322  $table = new ilConditionHandlerTableGUI($this, 'listConditions', $list_mode !== self::LIST_MODE_ALL);
323  $table->setConditions(
325  $this->getTargetRefId(),
326  $this->getTargetId(),
327  $this->getTargetType()
328  )
329  );
330 
331  $h = $table->getHTML();
332  $this->tpl->setVariable('TABLE_CONDITIONS', $h);
333  }
334 
335  protected function saveObligatorySettings(): void
336  {
337  $form = $this->showObligatoryForm();
338  if ($form !== null && $form->checkInput()) {
339  $old_mode = $form->getInput("old_list_mode");
340  switch ($form->getInput("list_mode")) {
341  case "all":
342  if ($old_mode !== "all") {
344  $this->getTargetRefId(),
345  $this->getTargetId(),
346  $this->getTargetType()
347  );
348  // Set all optional conditions to obligatory
349  foreach ($optional_conditions as $item) {
350  ilConditionHandler::updateObligatory($item["condition_id"], true);
351  }
352  }
353  break;
354 
355  case "subset":
356  $num_req = $form->getInput('required');
357  if ($old_mode !== "subset") {
359  $this->getTargetRefId(),
360  $this->getTargetId(),
361  $this->getTargetType()
362  );
363  foreach ($all_conditions as $item) {
364  ilConditionHandler::updateObligatory($item["condition_id"], false);
365  }
366  }
368  $this->getTargetRefId(),
369  $this->getTargetId(),
370  (int) $num_req
371  );
372  break;
373  }
374 
375  $cond = new ilConditionHandler();
376  $cond->setTargetRefId($this->getTargetRefId());
377  $cond->updateHiddenStatus((bool) $form->getInput('hidden'));
378 
379  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
380  $this->ctrl->redirect($this, 'listConditions');
381  }
382 
383  $form->setValuesByPost();
384  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'));
385  $this->tpl->setContent($form->getHTML());
386  }
387 
388  protected function saveObligatoryList(): void
389  {
391  $this->getTargetRefId(),
392  $this->getTargetId(),
393  $this->getTargetType()
394  );
395 
396  $obligatory_ids = $this->initObligatoryItemsFromPost();
397  if (count($obligatory_ids) > count($all_conditions) - 2) {
398  $this->tpl->setOnScreenMessage('failure', $this->lng->txt("rbac_precondition_minimum_optional"), true);
399  $this->ctrl->redirect($this, 'listConditions');
400  }
401 
402  foreach ($all_conditions as $item) {
403  $status = false;
404  if (in_array($item['condition_id'], $obligatory_ids->toArray(), true)) {
405  $status = true;
406  }
407  ilConditionHandler::updateObligatory($item["condition_id"], $status);
408  }
409 
410  // re-calculate
412  $this->getTargetRefId(),
413  $this->getTargetId(),
414  $this->getTargetType(),
415  true
416  );
417 
418  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
419  $this->ctrl->redirect($this, 'listConditions');
420  }
421 
422  protected function showObligatoryForm(
423  string $list_mode = self::LIST_MODE_ALL
424  ): ?ilPropertyFormGUI {
425  if (!$this->objectDefinition->isRBACObject($this->getTargetType())) {
426  return null;
427  }
428 
430  $form = new ilPropertyFormGUI();
431  $form->setFormAction($this->ctrl->getFormAction($this, 'listConditions'));
432  $form->setTitle($this->lng->txt('precondition_obligatory_settings'));
433  $form->addCommandButton('saveObligatorySettings', $this->lng->txt('save'));
434 
435  $hide = new ilCheckboxInputGUI($this->lng->txt('rbac_precondition_hide'), 'hidden');
437  $hide->setValue("1");
438  $hide->setInfo($this->lng->txt('rbac_precondition_hide_info'));
439  $form->addItem($hide);
440 
441  $mode = new ilRadioGroupInputGUI($this->lng->txt("rbac_precondition_mode"), "list_mode");
442  $form->addItem($mode);
443  $mode->setValue($list_mode);
444 
445  $mall = new ilRadioOption($this->lng->txt("rbac_precondition_mode_all"), "all");
446  $mall->setInfo($this->lng->txt("rbac_precondition_mode_all_info"));
447  $mode->addOption($mall);
448 
449  if (count($all) > 1) {
450  $min = 1;
451  $max = count($all) - 1;
452 
453  $msubset = new ilRadioOption($this->lng->txt("rbac_precondition_mode_subset"), "subset");
454  $msubset->setInfo($this->lng->txt("rbac_precondition_mode_subset_info"));
455  $mode->addOption($msubset);
456 
457  $obl = new ilNumberInputGUI($this->lng->txt('precondition_num_obligatory'), 'required');
458  $obl->setInfo($this->lng->txt('precondition_num_optional_info'));
459 
461  $this->getTargetRefId(),
462  $this->getTargetId()
463  );
464  $obl->setValue($num_required > 0 ? (string) $num_required : null);
465  $obl->setRequired(true);
466  $obl->setSize(1);
467  $obl->setMinValue($min);
468  $obl->setMaxValue($max);
469  $msubset->addSubItem($obl);
470  }
471 
472  $old_mode = new ilHiddenInputGUI("old_list_mode");
473  $old_mode->setValue($list_mode);
474  $form->addItem($old_mode);
475 
476  return $form;
477  }
478 
479  public function edit(?ilPropertyFormGUI $form = null): void
480  {
481  $condition_id = $this->initConditionIdFromQuery();
482  if (!$condition_id) {
483  $this->tpl->setOnScreenMessage('failure', "Missing id: condition_id");
484  $this->listConditions();
485  return;
486  }
487  $this->ctrl->setParameter($this, 'condition_id', $condition_id);
488  $condition = ilConditionHandler::_getCondition($condition_id);
489 
490  if (!$form instanceof ilPropertyFormGUI) {
491  $form = $this->initFormCondition($condition['trigger_ref_id'], $condition_id, 'edit');
492  }
493  $this->tpl->setContent($form->getHTML());
494  }
495 
496  public function updateCondition(): void
497  {
498  $condition_id = $this->initConditionIdFromQuery();
499  if (!$condition_id) {
500  $this->tpl->setOnScreenMessage('failure', "Missing id: condition_id");
501  $this->listConditions();
502  return;
503  }
504  // Update condition
505  $condition_handler = new ilConditionHandler();
506  $condition = ilConditionHandler::_getCondition($condition_id);
507 
508  $form = $this->initFormCondition(
509  $condition['trigger_ref_id'],
510  $condition_id,
511  'edit'
512  );
513 
514  if (!$form->checkInput()) {
515  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'));
516  $this->edit($form);
517  return;
518  }
519 
520  $condition_handler->setOperator((string) $form->getInput('operator'));
521  $condition_handler->setObligatory((bool) $form->getInput('obligatory'));
522  $condition_handler->setTargetRefId($this->getTargetRefId());
523  $condition_handler->setValue('');
524  switch ($this->getTargetType()) {
525  case 'st':
526  $condition_handler->setReferenceHandlingType((int) $form->getInput('ref_handling'));
527  break;
528 
529  default:
530  $condition_handler->setReferenceHandlingType(ilConditionHandler::UNIQUE_CONDITIONS);
531  break;
532  }
533  $condition_handler->updateCondition($condition['id']);
534 
535  // Update relevant sco's
536  if ($condition['trigger_type'] === 'sahs') {
537  $olp = ilObjectLP::getInstance($condition['trigger_obj_id']);
538  $collection = $olp->getCollectionInstance();
539  if ($collection) {
540  $collection->delete();
541  }
542  $item_ids = $this->initItemIdsFromPost();
543  if (count($item_ids)) { // #12901
544  $collection->activateEntries($item_ids->toArray());
545  }
546  ilLPStatusWrapper::_refreshStatus($condition['trigger_obj_id']);
547  }
548  $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
549  $this->ctrl->redirect($this, 'listConditions');
550  }
551 
552  public function askDelete(): void
553  {
554  $condition_ids = $this->initConditionsIdsFromPost();
555  if (!count($condition_ids)) {
556  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('no_condition_selected'));
557  $this->listConditions();
558  return;
559  }
560 
561  // display confirmation message
562  $cgui = new ilConfirmationGUI();
563  $cgui->setFormAction($this->ctrl->getFormAction($this, "listConditions"));
564  $cgui->setHeaderText($this->lng->txt("rbac_condition_delete_sure"));
565  $cgui->setCancel($this->lng->txt("cancel"), "listConditions");
566  $cgui->setConfirm($this->lng->txt("delete"), "delete");
567 
568  // list conditions that should be deleted
569  foreach ($condition_ids as $condition_id) {
570  $condition = ilConditionHandler::_getCondition($condition_id);
571 
572  $title = ilObject::_lookupTitle($condition['trigger_obj_id']) .
573  " (" . $this->lng->txt("condition") . ": " .
574  $this->lng->txt('condition_' . $condition['operator']) . ")";
575  $icon = ilUtil::getImagePath('icon_' . $condition['trigger_type'] . '.svg');
576  $alt = $this->lng->txt('obj_' . $condition['trigger_type']);
577 
578  $cgui->addItem("conditions[]", (string) $condition_id, $title, $icon, $alt);
579  }
580 
581  $this->tpl->setContent($cgui->getHTML());
582  }
583 
584  public function delete(): void
585  {
586  $condition_ids = $this->initConditionsIdsFromPost();
587  if (!count($condition_ids)) {
588  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('no_condition_selected'));
589  $this->listConditions();
590  return;
591  }
592 
593  foreach ($condition_ids as $condition_id) {
594  $this->ch_obj->deleteCondition($condition_id);
595  }
596  $this->tpl->setOnScreenMessage('success', $this->lng->txt('condition_deleted'), true);
597  $this->ctrl->redirect($this, 'listConditions');
598  }
599 
600  public function selector(): void
601  {
602  $this->tpl->setOnScreenMessage('info', $this->lng->txt("condition_select_object"));
603 
604  $exp = new ilConditionSelector($this, "selector");
605  $exp->setTypeWhiteList(array_merge(
606  $this->getConditionHandler()->getTriggerTypes(),
607  array("root", "cat", "grp", "fold", "crs", "prg")
608  ));
609  //setRefId have to be after setTypeWhiteList!
610  $exp->setRefId($this->getTargetRefId());
611  $exp->setClickableTypes($this->getConditionHandler()->getTriggerTypes());
612 
613  if (!$exp->handleCommand()) {
614  $this->tpl->setContent($exp->getHTML());
615  }
616  }
617 
618  public function add(?ilPropertyFormGUI $form = null): void
619  {
620  $source_id = $this->initSourceIdFromQuery();
621  if (!$source_id) {
622  $this->tpl->setOnScreenMessage('failure', "Missing id: condition_id");
623  $this->selector();
624  return;
625  }
626  if (!$form instanceof ilPropertyFormGUI) {
627  $form = $this->initFormCondition($source_id, 0, 'add');
628  }
629  $this->tpl->setContent($form->getHTML());
630  }
631 
635  public function assign(): void
636  {
637  $source_id = $this->initSourceIdFromQuery();
638  if (!$source_id) {
639  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('no_condition_selected'));
640  $this->selector();
641  return;
642  }
643 
644  $form = $this->initFormCondition($source_id, 0, 'add');
645  if (!$form->checkInput()) {
646  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'));
647  $this->add($form);
648  return;
649  }
650  $this->ch_obj->setTargetRefId($this->getTargetRefId());
651  $this->ch_obj->setTargetObjId($this->getTargetId());
652  $this->ch_obj->setTargetType($this->getTargetType());
653 
654  switch ($this->getTargetType()) {
655  case 'st':
656  $this->ch_obj->setReferenceHandlingType((int) $form->getInput('ref_handling'));
657  break;
658 
659  default:
660  $this->ch_obj->setReferenceHandlingType(ilConditionHandler::UNIQUE_CONDITIONS);
661  break;
662  }
663  // this has to be changed, if non referenced trigger are implemted
664  $trigger_obj = ilObjectFactory::getInstanceByRefId($source_id);
665  if ($trigger_obj !== null) {
666  $this->ch_obj->setTriggerRefId($trigger_obj->getRefId());
667  $this->ch_obj->setTriggerObjId($trigger_obj->getId());
668  $this->ch_obj->setTriggerType($trigger_obj->getType());
669  }
670  $this->ch_obj->setOperator($form->getInput('operator'));
671  $this->ch_obj->setObligatory((bool) $form->getInput('obligatory'));
672  $this->ch_obj->setHiddenStatus(ilConditionHandler::lookupPersistedHiddenStatusByTarget($this->getTargetRefId()));
673  $this->ch_obj->setValue('');
674 
675  // Save assigned sco's
676  if ($this->ch_obj->getTriggerType() === 'sahs') {
677  $olp = ilObjectLP::getInstance($this->ch_obj->getTriggerObjId());
678  $collection = $olp->getCollectionInstance();
679  if ($collection) {
680  $collection->delete();
681  }
682 
683  $items_ids = $this->initItemIdsFromPost();
684  if (count($items_ids)) { // #12901
685  $collection->activateEntries($items_ids->toArray());
686  }
687  }
688  $this->ch_obj->enableAutomaticValidation($this->getAutomaticValidation());
689  if (!$this->ch_obj->storeCondition()) {
690  $this->tpl->setOnScreenMessage('failure', $this->ch_obj->getErrorMessage(), true);
691  } else {
692  $this->tpl->setOnScreenMessage('success', $this->lng->txt('added_new_condition'), true);
693  }
694  $this->ctrl->redirect($this, 'listConditions');
695  }
696 
697  public function getConditionsOfTarget(): array
698  {
699  $cond = [];
701  $this->getTargetRefId(),
702  $this->getTargetId(),
703  $this->getTargetType()
704  ) as $condition) {
705  if ($condition['operator'] === 'not_member') {
706  continue;
707  }
708 
709  $cond[] = $condition;
710  }
711  return $cond;
712  }
713 
714  private function initFormCondition(
715  int $a_source_id,
716  int $a_condition_id = 0,
717  string $a_mode = 'add'
718  ): ilPropertyFormGUI {
719  $trigger_obj_id = ilObject::_lookupObjId($a_source_id);
720  $trigger_type = ilObject::_lookupType($trigger_obj_id);
721 
722  $condition = ilConditionHandler::_getCondition($a_condition_id);
723  $form = new ilPropertyFormGUI();
724  $this->ctrl->setParameter($this, 'source_id', $a_source_id);
725  $form->setFormAction($this->ctrl->getFormAction($this));
726 
727  $info_source = new ilNonEditableValueGUI($this->lng->txt("rbac_precondition_source"));
728  $info_source->setValue(ilObject::_lookupTitle(ilObject::_lookupObjId($a_source_id)));
729  $form->addItem($info_source);
730 
731  $info_target = new ilNonEditableValueGUI($this->lng->txt("rbac_precondition_target"));
732  $info_target->setValue($this->getTargetTitle());
733  $form->addItem($info_target);
734 
735  $obl = new ilHiddenInputGUI('obligatory');
736  if ($a_condition_id) {
737  $obl->setValue((string) (bool) $condition['obligatory']);
738  } else {
739  $obl->setValue("1");
740  }
741  $form->addItem($obl);
742 
743  $sel = new ilSelectInputGUI($this->lng->txt('condition'), 'operator');
744  $ch_obj = new ilConditionHandler();
745  $operators = [];
746  if ($a_mode === 'add') {
747  $operators[''] = $this->lng->txt('select_one');
748  }
749  foreach ($ch_obj->getOperatorsByTriggerType($trigger_type) as $operator) {
750  $operators[$operator] = $this->lng->txt('condition_' . $operator);
751  }
752  $sel->setValue($condition['operator'] ?? '');
753  $sel->setOptions($operators);
754  $sel->setRequired(true);
755  $form->addItem($sel);
756 
758  $rad_opt = new ilRadioGroupInputGUI($this->lng->txt('cond_ref_handling'), 'ref_handling');
759  $rad_opt->setValue((string) ($condition['ref_handling'] ?? ilConditionHandler::SHARED_CONDITIONS));
760 
761  $opt2 = new ilRadioOption(
762  $this->lng->txt('cond_ref_shared'),
763  (string) ilConditionHandler::SHARED_CONDITIONS
764  );
765  $rad_opt->addOption($opt2);
766 
767  $opt1 = new ilRadioOption(
768  $this->lng->txt('cond_ref_unique'),
770  );
771  $rad_opt->addOption($opt1);
772 
773  $form->addItem($rad_opt);
774  }
775 
776  // Additional settings for SCO's
777  if ($trigger_type === 'sahs') {
778  $this->lng->loadLanguageModule('trac');
779 
780  $cus = new ilCheckboxGroupInputGUI($this->lng->txt('trac_sahs_relevant_items'), 'item_ids');
781  $cus->setInfo($this->lng->txt('trac_lp_determination_info_sco'));
782  $cus->setRequired(true);
783 
784  $olp = ilObjectLP::getInstance($trigger_obj_id);
785  $collection = $olp->getCollectionInstance();
786  $checked = [];
787  if ($collection) {
788  foreach ($collection->getPossibleItems() as $item_id => $sahs_item) {
789  $sco = new ilCheckboxOption($sahs_item['title'], (string) $item_id);
790  if ($collection->isAssignedEntry($item_id)) {
791  $checked[] = $item_id;
792  }
793  $cus->addOption($sco);
794  }
795  }
796  $cus->setValue($checked);
797  $form->addItem($cus);
798  }
799  switch ($a_mode) {
800  case 'edit':
801  $form->setTitleIcon(ilUtil::getImagePath('icon_' . $this->getTargetType() . '.svg'));
802  $form->setTitle($this->lng->txt('rbac_edit_condition'));
803  $form->addCommandButton('updateCondition', $this->lng->txt('save'));
804  $form->addCommandButton('listConditions', $this->lng->txt('cancel'));
805  break;
806 
807  case 'add':
808  $form->setTitleIcon(ilUtil::getImagePath('icon_' . $this->getTargetType() . '.svg'));
809  $form->setTitle($this->lng->txt('add_condition'));
810  $form->addCommandButton('assign', $this->lng->txt('save'));
811  $form->addCommandButton('selector', $this->lng->txt('back'));
812  break;
813  }
814  return $form;
815  }
816 }
Interface GlobalHttpState.
static get(string $a_var)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilGlobalTemplateInterface $tpl
class ilConditionHandlerGUI
static _getCondition(int $a_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static _isReferenceHandlingOptional(string $a_type)
setInfo(string $a_info)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static lookupObligatoryConditionsOfTarget(int $a_target_ref_id, int $a_target_obj_id)
setTargetRefId(int $a_target_ref_id)
static updateObligatory(int $a_id, bool $a_status)
Toggle condition obligatory status.
static calculatePersistedRequiredTriggers(int $a_target_ref_id, int $a_target_obj_id, string $a_target_obj_type='', bool $a_force_update=false)
This class represents a checkbox property in a property form.
showObligatoryForm(string $list_mode=self::LIST_MODE_ALL)
loadLanguageModule(string $a_module)
Load language module.
assign()
assign new trigger condition to target
static lookupPersistedHiddenStatusByTarget(int $a_target_ref_id)
setTargetTitle(string $a_target_title)
$ilErr
Definition: raiseError.php:17
static _lookupObjId(int $ref_id)
static saveNumberOfRequiredTriggers(int $a_target_ref_id, int $a_target_obj_id, int $a_num)
global $DIC
Definition: feed.php:28
parses the objects.xml it handles the xml-description of all ilias objects
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
This class represents a property in a property form.
add(?ilPropertyFormGUI $form=null)
static _lookupTitle(int $obj_id)
This class represents a number property in a property form.
Condition utility object Wraps some ilConditionHandler methods (which will become deprecated) Depende...
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _refreshStatus(int $a_obj_id, ?array $a_users=null)
static has($a_var)
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static translateOperator(int $a_obj_id, string $a_operator)
static getPersistedOptionalConditionsOfTarget(int $a_target_ref_id, int $a_target_obj_id, string $a_obj_type='')
setTargetType(string $a_target_type)
edit(?ilPropertyFormGUI $form=null)
initFormCondition(int $a_source_id, int $a_condition_id=0, string $a_mode='add')
isTargetReferenced()
Check if target has refernce id.
static _lookupType(int $id, bool $reference=false)
static getInstance(int $obj_id)
static set(string $a_var, $a_val)
Set a value.
static _getPersistedConditionsOfTarget(int $a_target_ref_id, int $a_target_obj_id, string $a_target_type="")
get all persisted conditions of target object
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _mode2Text(int $a_mode)