ILIAS  release_8 Revision v8.24
class.ilLearningSequenceConditionController.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
27{
31 public function isContainerConditionController(int $a_container_ref_id): bool
32 {
33 return true;
34 }
35
39 public function getConditionSetForRepositoryObject(int $a_container_child_ref_id): ilConditionSet
40 {
41 $f = $this->getConditionsFactory();
42 $conditions = [];
43
44 $container_ref_id = $this->getParentRefIdFor((int) $a_container_child_ref_id);
45
46 //for users with edit-permissions, do not apply conditions
47 if ($this->applyConditionsForCurrentUser($container_ref_id)) {
48 $sequence = $this->getSequencedItems($container_ref_id);
49
50 //find position
51 $pos = 0;
52 foreach ($sequence as $index => $item) {
53 if ($item->getRefId() === (int) $a_container_child_ref_id) {
54 $pos = $index;
55 break;
56 }
57 }
58
59 if ($pos > 0) {
60 $previous_item = $sequence[$pos - 1];
61 $post_conditions = array($previous_item->getPostCondition());
62
63 foreach ($post_conditions as $post_condition) {
64 $condition_op = $post_condition->getConditionOperator();
65 if ($condition_op !== ilLSPostConditionDB::STD_ALWAYS_OPERATOR) {
66 $conditions[] = $f->condition(
67 $f->repositoryTrigger($previous_item->getRefId()),
68 $condition_op,
69 $post_condition->getValue()
70 );
71 }
72 }
73 }
74 }
75
76 return $f->set($conditions);
77 }
78
80 {
81 return $this->getDIC()->conditions()->factory();
82 }
83
84 protected function getDIC(): Container
85 {
86 global $DIC;
87 return $DIC;
88 }
89
90 protected function getTree(): ilTree
91 {
92 $dic = $this->getDIC();
93 return $dic['tree'];
94 }
95
96 protected function getAccess(): ilAccess
97 {
98 $dic = $this->getDIC();
99 return $dic['ilAccess'];
100 }
101
102 protected function getParentRefIdFor(int $child_ref_id): int
103 {
104 $tree = $this->getTree();
105 return (int) $tree->getParentId($child_ref_id);
106 }
107
108 protected function getContainerObject(int $container_ref_id): ilObjLearningSequence
109 {
111 $possible_object = ilObjectFactory::getInstanceByRefId($container_ref_id);
112
113 if (!$possible_object instanceof ilObjLearningSequence) {
114 throw new LogicException("Object type should be ilObjLearningSequence. Actually is " . get_class($possible_object));
115 }
116
117 if (!$possible_object) {
118 throw new Exception('No object found for ref id ' . $container_ref_id . '.');
119 }
120
121 return $possible_object;
122 }
123
127 protected function getSequencedItems(int $container_ref_id): array
128 {
129 $container = $this->getContainerObject($container_ref_id);
130 return $container->getLSItems();
131 }
132
133 protected function applyConditionsForCurrentUser(int $container_ref_id): bool
134 {
135 $il_access = $this->getAccess();
136 $may_edit = $il_access->checkAccess('edit_permission', '', $container_ref_id);
137 return $may_edit === false;
138 }
139}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Condition set Note: This object currently focuses on repository objects as targets.
Handle Conditions within the LearningSequence Objects.
getConditionSetForRepositoryObject(int $a_container_child_ref_id)
Returns condition set for a repository object which is children under a container that controls the c...
isContainerConditionController(int $a_container_ref_id)
Returns true, if the a container controls the conditions of its childrens.
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...
global $DIC
Definition: feed.php:28
Interface for containers that take over control of conditions for repository object targets.
$index
Definition: metadata.php:145
$dic
Definition: result.php:32
$container
@noRector
Definition: wac.php:14