ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 {
32 $sql = "SELECT ".$this->getElementId().
33 " FROM ".$this->getSubTableName().
34 " WHERE ".$this->buildPrimaryWhere();
35 $set = $ilDB->query($sql);
36
37 $this->readMultiRecord($set);
38 }
39 else
40 {
41 if(trim($a_row[$this->getElementId()]))
42 {
43 $value = explode(self::SEPARATOR, $a_row[$this->getElementId()]);
44 array_pop($value);
45 array_shift($value);
46 $this->getADT()->setSelections($value);
47 }
48 }
49 }
50
51 protected function readMultiRecord($a_set)
52 {
53 global $ilDB;
54
55 $elements = array();
56
57 while($row = $ilDB->fetchAssoc($a_set))
58 {
59 $elements[] = $row[$this->getElementId()];
60 }
61
62 $this->getADT()->setSelections($elements);
63 }
64
65 public function prepareInsert(array &$a_fields)
66 {
67 if($this->doSingleFake())
68 {
69 $values = (array)$this->getADT()->getSelections();
70 if(sizeof($values))
71 {
72 $values = self::SEPARATOR.implode(self::SEPARATOR, $values).self::SEPARATOR;
73 }
74 $a_fields[$this->getElementId()] = array("text", $values);
75 }
76 }
77
78 protected function prepareMultiInsert()
79 {
80 $res = array();
81
82 $type = ($this->getADT() instanceof ilADTMultiEnumNumeric)
83 ? "integer"
84 : "text";
85
86 foreach((array)$this->getADT()->getSelections() as $element)
87 {
88 $res[] = array($this->getElementId() => array($type, $element));
89 }
90
91 return $res;
92 }
93}
94
95?>
getElementId()
Get element id.
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
global $ilDB