ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilLSPostConditionDB Class Reference

Storage for ilLSPostConditions. More...

+ Collaboration diagram for ilLSPostConditionDB:

Public Member Functions

 __construct (ilDBInterface $db)
 
 select (array $ref_ids)
 
 delete (array $ref_ids, ?ilDBInterface $db=null)
 
 upsert (array $ls_post_conditions)
 

Data Fields

const TABLE_NAME = 'post_conditions'
 
const STD_ALWAYS_OPERATOR = 'always'
 

Protected Member Functions

 insert (array $ls_post_conditions, ilDBInterface $db)
 

Protected Attributes

ilDBInterface $db
 

Detailed Description

Storage for ilLSPostConditions.

Definition at line 24 of file class.ilLSPostConditionDB.php.

Constructor & Destructor Documentation

◆ __construct()

ilLSPostConditionDB::__construct ( ilDBInterface  $db)

Definition at line 31 of file class.ilLSPostConditionDB.php.

32 {
33 $this->db = $db;
34 }

References $db.

Member Function Documentation

◆ delete()

ilLSPostConditionDB::delete ( array  $ref_ids,
?ilDBInterface  $db = null 
)

Definition at line 73 of file class.ilLSPostConditionDB.php.

73 : void
74 {
75 if ($ref_ids === []) {
76 return;
77 }
78
79 if (is_null($db)) {
80 $db = $this->db;
81 }
82
83 $query =
84 "DELETE FROM " . static::TABLE_NAME . PHP_EOL
85 . "WHERE ref_id IN (" . implode(',', $ref_ids) . ")" . PHP_EOL
86 ;
87
88 $db->manipulate($query);
89 }
manipulate(string $query)
Run a (write) Query on the database.

References $db, and ilDBInterface\manipulate().

+ Here is the call graph for this function:

◆ insert()

ilLSPostConditionDB::insert ( array  $ls_post_conditions,
ilDBInterface  $db 
)
protected

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

91 : void
92 {
93 foreach ($ls_post_conditions as $condition) {
94 $values = [
95 "ref_id" => ["integer", $condition->getRefId()],
96 "condition_operator" => ["text", $condition->getConditionOperator()],
97 "value" => ["text", $condition->getValue()]
98 ];
99 $db->insert(static::TABLE_NAME, $values);
100 }
101 }
insert(string $table_name, array $values)

References $db, and ilDBInterface\insert().

Referenced by upsert().

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

◆ select()

ilLSPostConditionDB::select ( array  $ref_ids)
Returns
ilLSPostCondition[]

Definition at line 39 of file class.ilLSPostConditionDB.php.

39 : array
40 {
41 if ($ref_ids === []) {
42 return [];
43 }
44
45 $data = [];
46 $query =
47 "SELECT ref_id, condition_operator, value" . PHP_EOL
48 . "FROM " . static::TABLE_NAME . PHP_EOL
49 . "WHERE ref_id IN (" . implode(',', $ref_ids) . ")" . PHP_EOL
50 ;
51
52 $result = $this->db->query($query);
53
54 while ($row = $this->db->fetchAssoc($result)) {
55 $data[$row['ref_id']] = [$row['condition_operator'], $row['value']];
56 }
57
58 $conditions = [];
59 foreach ($ref_ids as $ref_id) {
60 //always-condition, standard
62 $value = null;
63
64 //if from db: proper values
65 if (array_key_exists($ref_id, $data)) {
66 list($op, $value) = $data[$ref_id];
67 }
68 $conditions[] = new \ilLSPostCondition($ref_id, $op, $value);
69 }
70 return $conditions;
71 }
$ref_id
Definition: ltiauth.php:66

References $data, $ref_id, and STD_ALWAYS_OPERATOR.

◆ upsert()

ilLSPostConditionDB::upsert ( array  $ls_post_conditions)
Parameters
ilLSPostCondition[]

Definition at line 106 of file class.ilLSPostConditionDB.php.

106 : void
107 {
108 if ($ls_post_conditions === []) {
109 return;
110 }
111
112 $ref_ids = array_map(
113 fn (ilLSPostCondition $condition) => $condition->getRefId(),
114 $ls_post_conditions
115 );
116
117 $ilAtomQuery = $this->db->buildAtomQuery();
118 $ilAtomQuery->addTableLock(static::TABLE_NAME);
119 $ilAtomQuery->addQueryCallable(
120 function (ilDBInterface $db) use ($ref_ids, $ls_post_conditions): void {
121 $this->delete($ref_ids, $db);
122 $this->insert($ls_post_conditions, $db);
123 }
124 );
125 $ilAtomQuery->run();
126 }
insert(array $ls_post_conditions, ilDBInterface $db)
A PostCondition does restrict the progression of a user through the learning sequence.
Interface ilDBInterface.

References $db, ilLSPostCondition\getRefId(), and insert().

+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilLSPostConditionDB::$db
protected

Definition at line 29 of file class.ilLSPostConditionDB.php.

Referenced by __construct(), delete(), insert(), and upsert().

◆ STD_ALWAYS_OPERATOR

const ilLSPostConditionDB::STD_ALWAYS_OPERATOR = 'always'

◆ TABLE_NAME

const ilLSPostConditionDB::TABLE_NAME = 'post_conditions'

Definition at line 26 of file class.ilLSPostConditionDB.php.


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