ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilADTMultiEnumDBBridge.php
Go to the documentation of this file.
1<?php
2
3require_once "Services/ADT/classes/Bridges/class.ilADTMultiDBBridge.php";
4
6{
7 protected $fake_single;
8
9 const SEPARATOR = "~|~";
10
11 protected function isValidADT(ilADT $a_adt)
12 {
13 return ($a_adt instanceof ilADTMultiEnum);
14 }
15
16 public function setFakeSingle($a_status)
17 {
18 $this->fake_single = (bool) $a_status;
19 }
20
21 protected function doSingleFake()
22 {
23 return $this->fake_single;
24 }
25
26 public function readRecord(array $a_row)
27 {
28 global $ilDB;
29
30 if (!$this->doSingleFake()) {
31 $sql = "SELECT " . $this->getElementId() .
32 " FROM " . $this->getSubTableName() .
33 " WHERE " . $this->buildPrimaryWhere();
34 $set = $ilDB->query($sql);
35
36 $this->readMultiRecord($set);
37 } else {
38 if (trim($a_row[$this->getElementId()])) {
39 $value = explode(self::SEPARATOR, $a_row[$this->getElementId()]);
40 array_pop($value);
41 array_shift($value);
42 $this->getADT()->setSelections($value);
43 }
44 }
45 }
46
47 protected function readMultiRecord($a_set)
48 {
49 global $ilDB;
50
51 $elements = array();
52
53 while ($row = $ilDB->fetchAssoc($a_set)) {
54 $elements[] = $row[$this->getElementId()];
55 }
56
57 $this->getADT()->setSelections($elements);
58 }
59
60 public function prepareInsert(array &$a_fields)
61 {
62 if ($this->doSingleFake()) {
63 $values = (array) $this->getADT()->getSelections();
64 if (sizeof($values)) {
65 $values = self::SEPARATOR . implode(self::SEPARATOR, $values) . self::SEPARATOR;
66 }
67 $a_fields[$this->getElementId()] = array("text", $values);
68 }
69 }
70
71 protected function prepareMultiInsert()
72 {
73 $res = array();
74
75 $type = ($this->getADT() instanceof ilADTMultiEnumNumeric)
76 ? "integer"
77 : "text";
78
79 foreach ((array) $this->getADT()->getSelections() as $element) {
80 $res[] = array($this->getElementId() => array($type, $element));
81 }
82
83 return $res;
84 }
85}
An exception for terminatinating execution or to throw for unit testing.
getElementId()
Get element id.
buildPrimaryWhere()
Convert primary keys array to sql string.
getSubTableName()
Build sub-table name.
prepareMultiInsert()
Build insert-fields for each "value".
readMultiRecord($a_set)
Import record-rows from sub-table.
prepareInsert(array &$a_fields)
Prepare ADT values for insert.
isValidADT(ilADT $a_adt)
Check if given ADT is valid.
readRecord(array $a_row)
Import DB values to ADT.
ADT base class.
Definition: class.ilADT.php:12
$type
foreach($_POST as $key=> $value) $res
global $ilDB