ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
29 
30  $ilDB = $DIC['ilDB'];
31 
32  if (!$this->doSingleFake()) {
33  $sql = "SELECT " . $this->getElementId() .
34  " FROM " . $this->getSubTableName() .
35  " WHERE " . $this->buildPrimaryWhere();
36  $set = $ilDB->query($sql);
37 
38  $this->readMultiRecord($set);
39  } else {
40  if (trim($a_row[$this->getElementId()])) {
41  $value = explode(self::SEPARATOR, $a_row[$this->getElementId()]);
42  array_pop($value);
43  array_shift($value);
44  $this->getADT()->setSelections($value);
45  }
46  }
47  }
48 
49  protected function readMultiRecord($a_set)
50  {
51  global $DIC;
52 
53  $ilDB = $DIC['ilDB'];
54 
55  $elements = array();
56 
57  while ($row = $ilDB->fetchAssoc($a_set)) {
58  $elements[] = $row[$this->getElementId()];
59  }
60 
61  $this->getADT()->setSelections($elements);
62  }
63 
64  public function prepareInsert(array &$a_fields)
65  {
66  if ($this->doSingleFake()) {
67  $values = (array) $this->getADT()->getSelections();
68  if (sizeof($values)) {
69  $values = self::SEPARATOR . implode(self::SEPARATOR, $values) . self::SEPARATOR;
70  }
71  $a_fields[$this->getElementId()] = array("text", $values);
72  }
73  }
74 
75  protected function prepareMultiInsert()
76  {
77  $res = array();
78 
79  $type = ($this->getADT() instanceof ilADTMultiEnumNumeric)
80  ? "integer"
81  : "text";
82 
83  foreach ((array) $this->getADT()->getSelections() as $element) {
84  $res[] = array($this->getElementId() => array($type, $element));
85  }
86 
87  return $res;
88  }
89 }
buildPrimaryWhere()
Convert primary keys array to sql string.
getSubTableName()
Build sub-table name.
$type
global $DIC
Definition: saml.php:7
getElementId()
Get element id.
ADT base class.
Definition: class.ilADT.php:11
foreach($_POST as $key=> $value) $res
$values
$row
global $ilDB