ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries Class Reference

Stores start and end object boundaries of adaptive learning sequences. More...

+ Collaboration diagram for ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries:

Public Member Functions

 __construct (ilDBInterface $db)
 Creates the boundary repository. More...
 
 getBoundariesFor (int $lso_obj_id)
 Gets the start and end boundaries of a learning sequence. More...
 
 setStartRefId (int $lso_obj_id, int $start_ref_id)
 Sets the start object reference ID of a learning sequence. More...
 
 setEndRefId (int $lso_obj_id, int $end_ref_id)
 Sets the end object reference ID of a learning sequence. More...
 
 unsetStartRefId (int $lso_obj_id)
 Removes the start object reference ID of a learning sequence. More...
 
 unsetEndRefId (int $lso_obj_id)
 Removes the end object reference ID of a learning sequence. More...
 
 removeRefIdFromBoundaries (int $lso_obj_id, int $ref_id)
 Removes a given ref_id from the boundaries of an LSO if it is currently stored as the start and/or end object. More...
 

Data Fields

const string TABLE_NAME = 'lso_item_boundaries'
 

Protected Member Functions

 cleanupIfEmpty (int $lso_obj_id)
 Removes an empty boundary record. More...
 

Protected Attributes

ilDBInterface $db
 Database connection. More...
 

Detailed Description

Stores start and end object boundaries of adaptive learning sequences.

Definition at line 28 of file LSOAdaptiveBoundaries.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries::__construct ( ilDBInterface  $db)

Creates the boundary repository.

Definition at line 40 of file LSOAdaptiveBoundaries.php.

41 {
42 $this->db = $db;
43 }

References ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries\$db.

Member Function Documentation

◆ cleanupIfEmpty()

ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries::cleanupIfEmpty ( int  $lso_obj_id)
protected

Removes an empty boundary record.

Definition at line 170 of file LSOAdaptiveBoundaries.php.

170 : void
171 {
172 $boundaries = $this->getBoundariesFor($lso_obj_id);
173 if ($boundaries['start_ref_id'] === 0 && $boundaries['end_ref_id'] === 0) {
174 $this->db->manipulate("DELETE FROM " . self::TABLE_NAME . " WHERE obj_id = " . $this->db->quote($lso_obj_id, 'integer'));
175 }
176 }
getBoundariesFor(int $lso_obj_id)
Gets the start and end boundaries of a learning sequence.

References ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries\getBoundariesFor().

Referenced by ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries\unsetEndRefId(), and ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries\unsetStartRefId().

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

◆ getBoundariesFor()

ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries::getBoundariesFor ( int  $lso_obj_id)

Gets the start and end boundaries of a learning sequence.

Returns
array{start_ref_id: int, end_ref_id: int}

Definition at line 50 of file LSOAdaptiveBoundaries.php.

50 : array
51 {
52 $query = "SELECT start_ref_id, end_ref_id FROM " . self::TABLE_NAME . " WHERE obj_id = " . $this->db->quote($lso_obj_id, 'integer');
53 $res = $this->db->query($query);
54 $row = $this->db->fetchAssoc($res);
55 if ($row) {
56 return [
57 'start_ref_id' => (int) ($row['start_ref_id'] ?? 0),
58 'end_ref_id' => (int) ($row['end_ref_id'] ?? 0)
59 ];
60 }
61 return ['start_ref_id' => 0, 'end_ref_id' => 0];
62 }
foreach($_POST as $key=> $value) $res

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

Referenced by ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries\cleanupIfEmpty(), ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries\removeRefIdFromBoundaries(), ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries\setEndRefId(), and ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries\setStartRefId().

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

◆ removeRefIdFromBoundaries()

ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries::removeRefIdFromBoundaries ( int  $lso_obj_id,
int  $ref_id 
)

Removes a given ref_id from the boundaries of an LSO if it is currently stored as the start and/or end object.

Only the affected field(s) are cleared - not the whole row (unless it becomes empty, in which case {

See also
self::cleanupIfEmpty()} removes it). This is used when an object is deleted from the learning sequence so that a dangling start/end reference does not remain in the database.
Parameters
int$lso_obj_idobj_id of the learning sequence
int$ref_idref_id of the deleted object
Returns
bool true if a boundary field was actually changed

Definition at line 145 of file LSOAdaptiveBoundaries.php.

145 : bool
146 {
147 if ($ref_id <= 0) {
148 return false;
149 }
150
151 $boundaries = $this->getBoundariesFor($lso_obj_id);
152 $changed = false;
153
154 if ($boundaries['start_ref_id'] === $ref_id) {
155 $this->unsetStartRefId($lso_obj_id);
156 $changed = true;
157 }
158
159 if ($boundaries['end_ref_id'] === $ref_id) {
160 $this->unsetEndRefId($lso_obj_id);
161 $changed = true;
162 }
163
164 return $changed;
165 }
unsetStartRefId(int $lso_obj_id)
Removes the start object reference ID of a learning sequence.
unsetEndRefId(int $lso_obj_id)
Removes the end object reference ID of a learning sequence.

References ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries\getBoundariesFor(), ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries\unsetEndRefId(), and ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries\unsetStartRefId().

+ Here is the call graph for this function:

◆ setEndRefId()

ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries::setEndRefId ( int  $lso_obj_id,
int  $end_ref_id 
)

Sets the end object reference ID of a learning sequence.

Definition at line 88 of file LSOAdaptiveBoundaries.php.

88 : void
89 {
90 $boundaries = $this->getBoundariesFor($lso_obj_id);
91 if ($boundaries['start_ref_id'] === 0 && $boundaries['end_ref_id'] === 0) {
92 $this->db->insert(self::TABLE_NAME, [
93 'obj_id' => ['integer', $lso_obj_id],
94 'start_ref_id' => ['integer', null],
95 'end_ref_id' => ['integer', $end_ref_id]
96 ]);
97 } else {
98 $this->db->update(
99 self::TABLE_NAME,
100 ['end_ref_id' => ['integer', $end_ref_id]],
101 ['obj_id' => ['integer', $lso_obj_id]]
102 );
103 }
104 }

References ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries\getBoundariesFor().

+ Here is the call graph for this function:

◆ setStartRefId()

ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries::setStartRefId ( int  $lso_obj_id,
int  $start_ref_id 
)

Sets the start object reference ID of a learning sequence.

Definition at line 67 of file LSOAdaptiveBoundaries.php.

67 : void
68 {
69 $boundaries = $this->getBoundariesFor($lso_obj_id);
70 if ($boundaries['start_ref_id'] === 0 && $boundaries['end_ref_id'] === 0) {
71 $this->db->insert(self::TABLE_NAME, [
72 'obj_id' => ['integer', $lso_obj_id],
73 'start_ref_id' => ['integer', $start_ref_id],
74 'end_ref_id' => ['integer', null]
75 ]);
76 } else {
77 $this->db->update(
78 self::TABLE_NAME,
79 ['start_ref_id' => ['integer', $start_ref_id]],
80 ['obj_id' => ['integer', $lso_obj_id]]
81 );
82 }
83 }

References ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries\getBoundariesFor().

+ Here is the call graph for this function:

◆ unsetEndRefId()

ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries::unsetEndRefId ( int  $lso_obj_id)

Removes the end object reference ID of a learning sequence.

Definition at line 122 of file LSOAdaptiveBoundaries.php.

122 : void
123 {
124 $this->db->update(
125 self::TABLE_NAME,
126 ['end_ref_id' => ['integer', null]],
127 ['obj_id' => ['integer', $lso_obj_id]]
128 );
129 $this->cleanupIfEmpty($lso_obj_id);
130 }
cleanupIfEmpty(int $lso_obj_id)
Removes an empty boundary record.

References ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries\cleanupIfEmpty().

Referenced by ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries\removeRefIdFromBoundaries().

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

◆ unsetStartRefId()

ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries::unsetStartRefId ( int  $lso_obj_id)

Removes the start object reference ID of a learning sequence.

Definition at line 109 of file LSOAdaptiveBoundaries.php.

109 : void
110 {
111 $this->db->update(
112 self::TABLE_NAME,
113 ['start_ref_id' => ['integer', null]],
114 ['obj_id' => ['integer', $lso_obj_id]]
115 );
116 $this->cleanupIfEmpty($lso_obj_id);
117 }

References ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries\cleanupIfEmpty().

Referenced by ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries\removeRefIdFromBoundaries().

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

Field Documentation

◆ $db

ilDBInterface ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries::$db
protected

◆ TABLE_NAME

const string ILIAS\LearningSequence\Content\Adaptive\LSOAdaptiveBoundaries::TABLE_NAME = 'lso_item_boundaries'

Definition at line 30 of file LSOAdaptiveBoundaries.php.


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