ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilADTMultiEnumDBBridge.php
Go to the documentation of this file.
1 <?php
2 
3 require_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 }
buildPrimaryWhere()
Convert primary keys array to sql string.
getSubTableName()
Build sub-table name.
$type
getElementId()
Get element id.
ADT base class.
Definition: class.ilADT.php:11
foreach($_POST as $key=> $value) $res
Create styles array
The data for the language used.
global $ilDB