ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  {
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 ?>