ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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

 $db
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilLSPostConditionDB::__construct ( \ilDBInterface  $db)

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

References $db.

21  {
22  $this->db = $db;
23  }

Member Function Documentation

◆ delete()

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

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

References $db, and $query.

62  {
63  if (count($ref_ids) === 0) {
64  return;
65  }
66 
67  if (is_null($db)) {
68  $db = $this->db;
69  }
70 
71  $query = "DELETE FROM " . static::TABLE_NAME . PHP_EOL
72  . "WHERE ref_id IN ("
73  . implode(',', $ref_ids)
74  . ")";
75  $db->manipulate($query);
76  }
$query

◆ insert()

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

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

References ilDBInterface\insert().

Referenced by upsert().

79  {
80  foreach ($ls_post_conditions as $condition) {
81  $values = array(
82  "ref_id" => array("integer", $condition->getRefId()),
83  "condition_operator" => array("text", $condition->getConditionOperator())
84  );
85  $db->insert(static::TABLE_NAME, $values);
86  }
87  }
+ 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 28 of file class.ilLSPostConditionDB.php.

References $data, $query, and $result.

28  : array
29  {
30  if (count($ref_ids) === 0) {
31  return [];
32  }
33 
34  $data = [];
35  $query = "SELECT ref_id, condition_operator, value" . PHP_EOL
36  . "FROM " . static::TABLE_NAME . PHP_EOL
37  . "WHERE ref_id IN ("
38  . implode(',', $ref_ids)
39  . ")";
40 
41  $result = $this->db->query($query);
42  while ($row = $this->db->fetchAssoc($result)) {
43  $data[$row['ref_id']] = [$row['condition_operator'], (int) $row['value']];
44  }
45 
46  $conditions = [];
47  foreach ($ref_ids as $ref_id) {
48  //always-condition, standard
49  $op = self::STD_ALWAYS_OPERATOR;
50  $value = null;
51 
52  //if from db: proper values
53  if (array_key_exists($ref_id, $data)) {
54  list($op, $value) = $data[$ref_id];
55  }
56  $conditions[] = new \ilLSPostCondition($ref_id, $op, $value);
57  }
58  return $conditions;
59  }
$data
Definition: storeScorm.php:23
$result
$query

◆ upsert()

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

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

References $db, and insert().

93  {
94  if (count($ls_post_conditions) === 0) {
95  return;
96  }
97 
98  $ref_ids = array_map(
99  function ($condition) {
100  return (int) $condition->getRefId();
101  },
102  $ls_post_conditions
103  );
104 
105  $ilAtomQuery = $this->db->buildAtomQuery();
106  $ilAtomQuery->addTableLock(static::TABLE_NAME);
107  $ilAtomQuery->addQueryCallable(
108  function (\ilDBInterface $db) use ($ref_ids, $ls_post_conditions) {
109  $this->delete($ref_ids, $db);
110  $this->insert($ls_post_conditions, $db);
111  }
112  );
113  $ilAtomQuery->run();
114  }
insert(array $ls_post_conditions, \ilDBInterface $db)
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilLSPostConditionDB::$db
protected

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

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

◆ STD_ALWAYS_OPERATOR

const ilLSPostConditionDB::STD_ALWAYS_OPERATOR = 'always'

◆ TABLE_NAME

const ilLSPostConditionDB::TABLE_NAME = 'post_conditions'

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


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