ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilLearningSequenceConditionController.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
11 {
15  public function isContainerConditionController($a_container_ref_id) : bool
16  {
17  return true;
18  }
19 
23  public function getConditionSetForRepositoryObject($a_container_child_ref_id) : ilConditionSet
24  {
25  $f = $this->getConditionsFactory();
26  $conditions = [];
27 
28  $container_ref_id = $this->getParentRefIdFor((int) $a_container_child_ref_id);
29 
30  //for users with edit-permissions, do not apply conditions
31  if ($this->applyConditionsForCurrentUser($container_ref_id)) {
32  $sequence = $this->getSequencedItems($container_ref_id);
33 
34  //find position
35  foreach ($sequence as $index => $item) {
36  if ($item->getRefId() === (int) $a_container_child_ref_id) {
37  $pos = $index;
38  break;
39  }
40  }
41 
42  if ($pos > 0) {
43  $previous_item = $sequence[$pos - 1];
44  $post_conditions = array($previous_item->getPostCondition());
45 
46  if (count($post_conditions) > 0) {
47  foreach ($post_conditions as $post_condition) {
48  $operator = false;
49  $condition_op = $post_condition->getConditionOperator();
50  if ($condition_op === 'learning_progress') {
51  $condition_op = 'learningProgress';
52  }
53  if ($condition_op !== \ilLSPostConditionDB::STD_ALWAYS_OPERATOR) {
54  $conditions[] = $f->condition(
55  $f->repositoryTrigger($previous_item->getRefId()),
56  $f->operator()->$condition_op()
57  );
58  }
59  }
60  }
61  }
62  }
63 
64  $condition_set = $f->set($conditions);
65  return $condition_set;
66  }
67 
68  protected function getConditionsFactory()
69  {
70  return $this->getDIC()->conditions()->factory();
71  }
72 
73  protected function getDIC()
74  {
75  global $DIC;
76  return $DIC;
77  }
78 
79  protected function getTree()
80  {
81  $dic = $this->getDIC();
82  return $dic['tree'];
83  }
84 
85  protected function getAccess()
86  {
87  $dic = $this->getDIC();
88  return $dic['ilAccess'];
89  }
90 
91  protected function getParentRefIdFor(int $child_ref_id) : int
92  {
93  $tree = $this->getTree();
94  return (int) $tree->getParentId($child_ref_id);
95  }
96 
97  protected function getContainerObject(int $container_ref_id) : ilObjLearningSequence
98  {
99  return ilObjectFactory::getInstanceByRefId($container_ref_id);
100  }
101 
102  protected function getSequencedItems(int $container_ref_id) : array
103  {
104  $container = $this->getContainerObject($container_ref_id);
105  return $container->getLSItems($container_ref_id);
106  }
107 
108  protected function applyConditionsForCurrentUser(int $container_ref_id) : bool
109  {
110  $il_access = $this->getAccess();
111  $may_edit = $il_access->checkAccess('edit_permission', '', $container_ref_id);
112  return $may_edit === false;
113  }
114 }
global $DIC
Definition: saml.php:7
Class ilObjLearningSequence.
getConditionSetForRepositoryObject($a_container_child_ref_id)
Returns condition set for a repository object which is children under a container that controls the c...
$index
Definition: metadata.php:60
Interface for containers that take over control of conditions for repository object targets...
$container
Definition: wac.php:13
isContainerConditionController($a_container_ref_id)
Returns true, if the a container controls the conditions of its childrens.ref id of a container bool ...
Handle Conditions within the LearningSequence Objects.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id