ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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)
 
 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)
 

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)

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

References $query, and PHP_EOL.

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

◆ insert()

ilLSPostConditionDB::insert ( array  $ls_post_conditions)
protected

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

References $values.

Referenced by upsert().

75  {
76  foreach ($ls_post_conditions as $condition) {
77  $values = array(
78  "ref_id" => array("integer", $condition->getRefId()),
79  "condition_operator" => array("text", $condition->getConditionOperator())
80  );
81  $this->db->insert(static::TABLE_NAME, $values);
82  }
83  }
$values
+ 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, $result, $row, and PHP_EOL.

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  }
$result
PHP_EOL
Definition: complexTest.php:5
$query
$row
$data
Definition: bench.php:6

◆ upsert()

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

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

References $db, and insert().

89  {
90  if (count($ls_post_conditions) === 0) {
91  return;
92  }
93 
94  $ref_ids = array_map(
95  function ($condition) {
96  return (int) $condition->getRefId();
97  },
98  $ls_post_conditions
99  );
100 
101  $ilAtomQuery = $this->db->buildAtomQuery();
102  $ilAtomQuery->addTableLock(static::TABLE_NAME);
103  $ilAtomQuery->addQueryCallable(
104  function (\ilDBInterface $db) use ($ref_ids, $ls_post_conditions) {
105  $this->delete($ref_ids);
106  $this->insert($ls_post_conditions);
107  }
108  );
109  $ilAtomQuery->run();
110  }
insert(array $ls_post_conditions)
+ 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(), 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: