ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\LearningSequence\Content\Condition\ConditionHandler Class Reference
+ Collaboration diagram for ILIAS\LearningSequence\Content\Condition\ConditionHandler:

Public Member Functions

 __construct (protected \ilDBInterface $db, protected \ilLanguage $lng, private ConditionFactory $condition_factory)
 
 getInputConditionsByRefId (int $lso_ref_id, int $obj_ref_id)
 
 getOutputConditionsByRefId (int $lso_ref_id, int $obj_ref_id)
 
 deleteConditionsByRefId (int $lso_ref_id, int $obj_ref_id)
 Deletes all conditions attached to an object that is being removed from the Learning Sequence, regardless of the current operation mode. More...
 
 deleteConditionsByLSORefId (int $lso_ref_id)
 Deletes all conditions that belong to a Learning Sequence itself. More...
 
 deleteCondition (int $condition_id)
 Deletes a single condition entry from lso_conditions by its condition id. More...
 

Protected Member Functions

 formatConditionsForGui (array $db_conditions)
 
 getConditionsFromDb (int $lso_ref_id, int $obj_ref_id, array $available_classes)
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ILIAS\LearningSequence\Content\Condition\ConditionHandler::__construct ( protected \ilDBInterface  $db,
protected \ilLanguage  $lng,
private ConditionFactory  $condition_factory 
)

Definition at line 25 of file class.ilObjLearningSequenceConditionHandler.php.

29 {
30 }

Member Function Documentation

◆ deleteCondition()

ILIAS\LearningSequence\Content\Condition\ConditionHandler::deleteCondition ( int  $condition_id)

Deletes a single condition entry from lso_conditions by its condition id.

Parameters
int$condition_idid of the condition to delete

Definition at line 128 of file class.ilObjLearningSequenceConditionHandler.php.

128 : void
129 {
130 $this->db->manipulateF(
131 'DELETE FROM lso_conditions WHERE condition_id = %s',
132 ['integer'],
133 [$condition_id]
134 );
135 }

Referenced by ILIAS\LearningSequence\Content\Condition\ConditionHandler\deleteConditionsByRefId().

+ Here is the caller graph for this function:

◆ deleteConditionsByLSORefId()

ILIAS\LearningSequence\Content\Condition\ConditionHandler::deleteConditionsByLSORefId ( int  $lso_ref_id)

Deletes all conditions that belong to a Learning Sequence itself.

Besides the generic rows in lso_conditions this also clears all condition-specific payload rows from every lso_c_* table by condition_id.

Definition at line 91 of file class.ilObjLearningSequenceConditionHandler.php.

91 : void
92 {
93 $condition_ids = [];
94 $res = $this->db->queryF(
95 'SELECT condition_id FROM lso_conditions WHERE lso_ref_id = %s',
96 ['integer'],
97 [$lso_ref_id]
98 );
99
100 while ($row = $this->db->fetchAssoc($res)) {
101 $condition_ids[] = (int) $row['condition_id'];
102 }
103
104 if ($condition_ids !== []) {
105 foreach ($this->db->listTables() as $table) {
106 if (!str_starts_with((string) $table, 'lso_c_')) {
107 continue;
108 }
109
110 $this->db->manipulate(
111 'DELETE FROM ' . $table . ' WHERE ' . $this->db->in('condition_id', $condition_ids, false, 'integer')
112 );
113 }
114 }
115
116 $this->db->manipulateF(
117 'DELETE FROM lso_conditions WHERE lso_ref_id = %s',
118 ['integer'],
119 [$lso_ref_id]
120 );
121 }
foreach($_POST as $key=> $value) $res

References $res, and ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ deleteConditionsByRefId()

ILIAS\LearningSequence\Content\Condition\ConditionHandler::deleteConditionsByRefId ( int  $lso_ref_id,
int  $obj_ref_id 
)

Deletes all conditions attached to an object that is being removed from the Learning Sequence, regardless of the current operation mode.

For every condition found for the deleted object it delegates to the concrete condition instance's public delete() method, which removes both the condition-specific payload (deleteConditionData()) and the generic entry in lso_conditions. If the concrete condition can no longer be resolved, the generic lso_conditions entry is removed as a fallback.

Parameters
int$lso_ref_idref_id of the Learning Sequence object
int$obj_ref_idref_id of the deleted object

Definition at line 63 of file class.ilObjLearningSequenceConditionHandler.php.

63 : void
64 {
65 $res = $this->db->queryF(
66 "SELECT condition_id, type_id FROM lso_conditions WHERE lso_ref_id = %s AND obj_ref_id = %s",
67 ['integer', 'integer'],
68 [$lso_ref_id, $obj_ref_id]
69 );
70
71 while ($row = $this->db->fetchAssoc($res)) {
72 $condition_id = (int) $row['condition_id'];
73
74 try {
75 $condition = $this->condition_factory->getConditionInstanceById($condition_id);
76 $condition->delete();
77 } catch (\Throwable $e) {
78 // If the concrete condition can no longer be resolved we still
79 // remove the generic lso_conditions entry as a fallback.
80 $this->deleteCondition($condition_id);
81 }
82 }
83 }
deleteCondition(int $condition_id)
Deletes a single condition entry from lso_conditions by its condition id.

References Vendor\Package\$e, $res, ILIAS\LearningSequence\Content\Condition\ConditionHandler\deleteCondition(), and ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ formatConditionsForGui()

ILIAS\LearningSequence\Content\Condition\ConditionHandler::formatConditionsForGui ( array  $db_conditions)
protected
Parameters
array[]$db_conditions
Returns
array[]

Definition at line 141 of file class.ilObjLearningSequenceConditionHandler.php.

141 : array
142 {
143 $result = [];
144 foreach ($db_conditions as $db_cond) {
145 $type_id = $db_cond['type_id'];
146 $res = $this->db->queryF(
147 "SELECT condition_name FROM lso_condition_types WHERE type_id = %s",
148 ['integer'],
149 [$type_id]
150 );
151 $row = $this->db->fetchAssoc($res);
152 if ($row) {
153 $class = $this->condition_factory->getConditionTypes()->getConditionByName($row['condition_name']);
154 if ($class) {
155 try {
156 $condition = $this->condition_factory->getConditionInstanceById((int) $db_cond['condition_id']);
157 $result[] = [
158 'title' => $this->lng->txt((string) $condition->getName()),
159 'value' => $condition instanceof SubtypeAwareInterface
160 ? $condition->getSubtypeLabel($condition->getSubtype())
161 : '',
162 'internal_name' => $row['condition_name']
163 ];
164 } catch (\Throwable $e) {
165 continue;
166 }
167 }
168 }
169 }
170 return $result;
171 }

References Vendor\Package\$e, $res, ILIAS\LearningSequence\Content\Condition\SubtypeAwareInterface\getSubtypeLabel(), and ILIAS\Repository\lng().

Referenced by ILIAS\LearningSequence\Content\Condition\ConditionHandler\getInputConditionsByRefId(), and ILIAS\LearningSequence\Content\Condition\ConditionHandler\getOutputConditionsByRefId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getConditionsFromDb()

ILIAS\LearningSequence\Content\Condition\ConditionHandler::getConditionsFromDb ( int  $lso_ref_id,
int  $obj_ref_id,
array  $available_classes 
)
protected
Returns
array[]

Definition at line 176 of file class.ilObjLearningSequenceConditionHandler.php.

176 : array
177 {
178 $names = [];
179 foreach ($available_classes as $class) {
180 try {
181 $reflection = new \ReflectionClass($class);
182 if ($reflection->isInstantiable()) {
184 }
185 } catch (\Throwable $e) {
186 continue;
187 }
188 }
189
190 if (count($names) === 0) {
191 return [];
192 }
193
194 $query = "SELECT c.*
195 FROM lso_conditions c
196 INNER JOIN lso_condition_types t ON c.type_id = t.type_id
197 WHERE c.lso_ref_id = %s AND c.obj_ref_id = %s AND " . $this->db->in('t.condition_name', $names, false, 'text');
198
199 $res = $this->db->queryF($query, ['integer', 'integer'], [$lso_ref_id, $obj_ref_id]);
200 $result = [];
201 while ($row = $this->db->fetchAssoc($res)) {
202 $result[] = $row;
203 }
204 return $result;
205 }
static getIdentifierForClass(string $class)
Extracts the identifier for the condition type from the class name.

References Vendor\Package\$e, $res, and ILIAS\LearningSequence\Content\Condition\AbstractCondition\getIdentifierForClass().

Referenced by ILIAS\LearningSequence\Content\Condition\ConditionHandler\getInputConditionsByRefId(), and ILIAS\LearningSequence\Content\Condition\ConditionHandler\getOutputConditionsByRefId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getInputConditionsByRefId()

ILIAS\LearningSequence\Content\Condition\ConditionHandler::getInputConditionsByRefId ( int  $lso_ref_id,
int  $obj_ref_id 
)
Returns
array[]

Definition at line 35 of file class.ilObjLearningSequenceConditionHandler.php.

35 : array
36 {
37 $db_conditions = $this->getConditionsFromDb($lso_ref_id, $obj_ref_id, $this->condition_factory->getConditionTypes()->getAllInputConditions());
38 return $this->formatConditionsForGui($db_conditions);
39 }
getConditionsFromDb(int $lso_ref_id, int $obj_ref_id, array $available_classes)

References ILIAS\LearningSequence\Content\Condition\ConditionHandler\formatConditionsForGui(), and ILIAS\LearningSequence\Content\Condition\ConditionHandler\getConditionsFromDb().

+ Here is the call graph for this function:

◆ getOutputConditionsByRefId()

ILIAS\LearningSequence\Content\Condition\ConditionHandler::getOutputConditionsByRefId ( int  $lso_ref_id,
int  $obj_ref_id 
)
Returns
array[]

Definition at line 44 of file class.ilObjLearningSequenceConditionHandler.php.

44 : array
45 {
46 $db_conditions = $this->getConditionsFromDb($lso_ref_id, $obj_ref_id, $this->condition_factory->getConditionTypes()->getAllOutputConditions());
47 return $this->formatConditionsForGui($db_conditions);
48 }

References ILIAS\LearningSequence\Content\Condition\ConditionHandler\formatConditionsForGui(), and ILIAS\LearningSequence\Content\Condition\ConditionHandler\getConditionsFromDb().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: