ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilLearningSequenceConditionController.php
Go to the documentation of this file.
1<?php
2
3declare(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 $post_condition->getValue()
58 );
59 }
60 }
61 }
62 }
63 }
64
65 $condition_set = $f->set($conditions);
66 return $condition_set;
67 }
68
69 protected function getConditionsFactory()
70 {
71 return $this->getDIC()->conditions()->factory();
72 }
73
74 protected function getDIC()
75 {
76 global $DIC;
77 return $DIC;
78 }
79
80 protected function getTree()
81 {
82 $dic = $this->getDIC();
83 return $dic['tree'];
84 }
85
86 protected function getAccess()
87 {
88 $dic = $this->getDIC();
89 return $dic['ilAccess'];
90 }
91
92 protected function getParentRefIdFor(int $child_ref_id) : int
93 {
94 $tree = $this->getTree();
95 return (int) $tree->getParentId($child_ref_id);
96 }
97
98 protected function getContainerObject(int $container_ref_id) : ilObjLearningSequence
99 {
100 return ilObjectFactory::getInstanceByRefId($container_ref_id);
101 }
102
103 protected function getSequencedItems(int $container_ref_id) : array
104 {
105 $container = $this->getContainerObject($container_ref_id);
106 return $container->getLSItems($container_ref_id);
107 }
108
109 protected function applyConditionsForCurrentUser(int $container_ref_id) : bool
110 {
111 $il_access = $this->getAccess();
112 $may_edit = $il_access->checkAccess('edit_permission', '', $container_ref_id);
113 return $may_edit === false;
114 }
115}
An exception for terminatinating execution or to throw for unit testing.
Handle Conditions within the LearningSequence Objects.
isContainerConditionController($a_container_ref_id)
Returns true, if the a container controls the conditions of its childrens.bool
getConditionSetForRepositoryObject($a_container_child_ref_id)
Returns condition set for a repository object which is children under a container that controls the c...
Class ilObjLearningSequence.
static getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
Interface for containers that take over control of conditions for repository object targets.
$index
Definition: metadata.php:128
$dic
Definition: result.php:13
$container
Definition: wac.php:13
$DIC
Definition: xapitoken.php:46