ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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('standard/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  }
597  $this->tpl->setOnScreenMessage('success', $this->lng->txt('condition_deleted'), true);
598  $this->ctrl->redirect($this, 'listConditions');
599  }
600 
601  protected function adjustConditionsAfterDeletion()
602  {
604  $this->getTargetRefId(),
605  $this->getTargetId()
606  );
608  $this->getTargetRefId(),
609  $this->getTargetId()
610  );
611  if (
612  count($conditions) === 1 &&
613  count($optional_conditions) > 0
614  ) {
615  // set to obligatory
616  foreach ($conditions as $condition) {
617  ilConditionHandler::updateObligatory($condition['id'], true);
618  }
619  }
621  $this->getTargetRefId(),
622  $this->getTargetId()
623  );
624  if (
625  $num_obligatory == count($conditions)
626  ) {
627  // set all obligatory
628  foreach ($conditions as $condition) {
629  ilConditionHandler::updateObligatory($condition['id'], true);
630  }
631  } elseif (
632  $num_obligatory > count($conditions)
633  ) {
634  // reduce required triggers to maximum
636  $this->getTargetRefId(),
637  $this->getTargetId(),
638  count($conditions) - 1
639  );
640  }
641  }
642 
643  public function selector(): void
644  {
645  $this->tpl->setOnScreenMessage('info', $this->lng->txt("condition_select_object"));
646 
647  $exp = new ilConditionSelector($this, "selector");
648  $exp->setTypeWhiteList(array_merge(
649  $this->getConditionHandler()->getTriggerTypes(),
650  array("root", "cat", "grp", "fold", "crs", "prg")
651  ));
652  //setRefId have to be after setTypeWhiteList!
653  $exp->setRefId($this->getTargetRefId());
654  $exp->setClickableTypes($this->getConditionHandler()->getTriggerTypes());
655 
656  if (!$exp->handleCommand()) {
657  $this->tpl->setContent($exp->getHTML());
658  }
659  }
660 
661  public function add(?ilPropertyFormGUI $form = null): void
662  {
663  $source_id = $this->initSourceIdFromQuery();
664  if (!$source_id) {
665  $this->tpl->setOnScreenMessage('failure', "Missing id: condition_id");
666  $this->selector();
667  return;
668  }
669  if (!$form instanceof ilPropertyFormGUI) {
670  $form = $this->initFormCondition($source_id, 0, 'add');
671  }
672  $this->tpl->setContent($form->getHTML());
673  }
674 
678  public function assign(): void
679  {
680  $source_id = $this->initSourceIdFromQuery();
681  if (!$source_id) {
682  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('no_condition_selected'));
683  $this->selector();
684  return;
685  }
686 
687  $form = $this->initFormCondition($source_id, 0, 'add');
688  if (!$form->checkInput()) {
689  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'));
690  $this->add($form);
691  return;
692  }
693  $this->ch_obj->setTargetRefId($this->getTargetRefId());
694  $this->ch_obj->setTargetObjId($this->getTargetId());
695  $this->ch_obj->setTargetType($this->getTargetType());
696 
697  switch ($this->getTargetType()) {
698  case 'st':
699  $this->ch_obj->setReferenceHandlingType((int) $form->getInput('ref_handling'));
700  break;
701 
702  default:
703  $this->ch_obj->setReferenceHandlingType(ilConditionHandler::UNIQUE_CONDITIONS);
704  break;
705  }
706  // this has to be changed, if non referenced trigger are implemted
707  $trigger_obj = ilObjectFactory::getInstanceByRefId($source_id);
708  if ($trigger_obj !== null) {
709  $this->ch_obj->setTriggerRefId($trigger_obj->getRefId());
710  $this->ch_obj->setTriggerObjId($trigger_obj->getId());
711  $this->ch_obj->setTriggerType($trigger_obj->getType());
712  }
713  $this->ch_obj->setOperator($form->getInput('operator'));
714  $this->ch_obj->setObligatory((bool) $form->getInput('obligatory'));
715  $this->ch_obj->setHiddenStatus(ilConditionHandler::lookupPersistedHiddenStatusByTarget($this->getTargetRefId()));
716  $this->ch_obj->setValue('');
717 
718  // Save assigned sco's
719  if ($this->ch_obj->getTriggerType() === 'sahs') {
720  $olp = ilObjectLP::getInstance($this->ch_obj->getTriggerObjId());
721  $collection = $olp->getCollectionInstance();
722  if ($collection) {
723  $collection->delete();
724  }
725 
726  $items_ids = $this->initItemIdsFromPost();
727  if (count($items_ids)) { // #12901
728  $collection->activateEntries($items_ids->toArray());
729  }
730  }
731  $this->ch_obj->enableAutomaticValidation($this->getAutomaticValidation());
732  if (!$this->ch_obj->storeCondition()) {
733  $this->tpl->setOnScreenMessage('failure', $this->ch_obj->getErrorMessage(), true);
734  } else {
735  $this->tpl->setOnScreenMessage('success', $this->lng->txt('added_new_condition'), true);
736  }
737  $this->ctrl->redirect($this, 'listConditions');
738  }
739 
740  public function getConditionsOfTarget(): array
741  {
742  $cond = [];
744  $this->getTargetRefId(),
745  $this->getTargetId(),
746  $this->getTargetType()
747  ) as $condition) {
748  if ($condition['operator'] === 'not_member') {
749  continue;
750  }
751 
752  $cond[] = $condition;
753  }
754  return $cond;
755  }
756 
757  private function initFormCondition(
758  int $a_source_id,
759  int $a_condition_id = 0,
760  string $a_mode = 'add'
761  ): ilPropertyFormGUI {
762  $trigger_obj_id = ilObject::_lookupObjId($a_source_id);
763  $trigger_type = ilObject::_lookupType($trigger_obj_id);
764 
765  $condition = ilConditionHandler::_getCondition($a_condition_id);
766  $form = new ilPropertyFormGUI();
767  $this->ctrl->setParameter($this, 'source_id', $a_source_id);
768  $form->setFormAction($this->ctrl->getFormAction($this));
769 
770  $info_source = new ilNonEditableValueGUI($this->lng->txt("rbac_precondition_source"));
771  $info_source->setValue(ilObject::_lookupTitle(ilObject::_lookupObjId($a_source_id)));
772  $form->addItem($info_source);
773 
774  $info_target = new ilNonEditableValueGUI($this->lng->txt("rbac_precondition_target"));
775  $info_target->setValue($this->getTargetTitle());
776  $form->addItem($info_target);
777 
778  $obl = new ilHiddenInputGUI('obligatory');
779  if ($a_condition_id) {
780  $obl->setValue((string) (bool) $condition['obligatory']);
781  } else {
782  $obl->setValue("1");
783  }
784  $form->addItem($obl);
785 
786  $sel = new ilSelectInputGUI($this->lng->txt('condition'), 'operator');
787  $ch_obj = new ilConditionHandler();
788  $operators = [];
789  if ($a_mode === 'add') {
790  $operators[''] = $this->lng->txt('select_one');
791  }
792  foreach ($ch_obj->getOperatorsByTriggerType($trigger_type) as $operator) {
793  $operators[$operator] = $this->lng->txt('condition_' . $operator);
794  }
795  $sel->setValue($condition['operator'] ?? '');
796  $sel->setOptions($operators);
797  $sel->setRequired(true);
798  $form->addItem($sel);
799 
801  $rad_opt = new ilRadioGroupInputGUI($this->lng->txt('cond_ref_handling'), 'ref_handling');
802  $rad_opt->setValue((string) ($condition['ref_handling'] ?? ilConditionHandler::SHARED_CONDITIONS));
803 
804  $opt2 = new ilRadioOption(
805  $this->lng->txt('cond_ref_shared'),
806  (string) ilConditionHandler::SHARED_CONDITIONS
807  );
808  $rad_opt->addOption($opt2);
809 
810  $opt1 = new ilRadioOption(
811  $this->lng->txt('cond_ref_unique'),
813  );
814  $rad_opt->addOption($opt1);
815 
816  $form->addItem($rad_opt);
817  }
818 
819  // Additional settings for SCO's
820  if ($trigger_type === 'sahs') {
821  $this->lng->loadLanguageModule('trac');
822 
823  $cus = new ilCheckboxGroupInputGUI($this->lng->txt('trac_sahs_relevant_items'), 'item_ids');
824  $cus->setInfo($this->lng->txt('trac_lp_determination_info_sco'));
825  $cus->setRequired(true);
826 
827  $olp = ilObjectLP::getInstance($trigger_obj_id);
828  $collection = $olp->getCollectionInstance();
829  $checked = [];
830  if ($collection) {
831  foreach ($collection->getPossibleItems() as $item_id => $sahs_item) {
832  $sco = new ilCheckboxOption($sahs_item['title'], (string) $item_id);
833  if ($collection->isAssignedEntry($item_id)) {
834  $checked[] = $item_id;
835  }
836  $cus->addOption($sco);
837  }
838  }
839  $cus->setValue($checked);
840  $form->addItem($cus);
841  }
842  switch ($a_mode) {
843  case 'edit':
844  $form->setTitleIcon(ilUtil::getImagePath('standard/icon_' . $this->getTargetType() . '.svg'));
845  $form->setTitle($this->lng->txt('rbac_edit_condition'));
846  $form->addCommandButton('updateCondition', $this->lng->txt('save'));
847  $form->addCommandButton('listConditions', $this->lng->txt('cancel'));
848  break;
849 
850  case 'add':
851  $form->setTitleIcon(ilUtil::getImagePath('standard/icon_' . $this->getTargetType() . '.svg'));
852  $form->setTitle($this->lng->txt('add_condition'));
853  $form->addCommandButton('assign', $this->lng->txt('save'));
854  $form->addCommandButton('selector', $this->lng->txt('back'));
855  break;
856  }
857  return $form;
858  }
859 }
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...
This class represents a selection list property in a property form.
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)
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)
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...
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
static _mode2Text(int $a_mode)