ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilADTDBBridge.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
11 abstract class ilADTDBBridge
12 {
13  protected $adt; // [ilADT]
14  protected $table; // [string]
15  protected $id; // [string]
16  protected $primary = []; // [array]
17 
24  public function __construct(ilADT $a_adt)
25  {
26  $this->setADT($a_adt);
27  }
28 
29  //
30  // properties
31  //
32 
41  abstract protected function isValidADT(ilADT $a_adt);
42 
49  protected function setADT(ilADT $a_adt)
50  {
51  if (!$this->isValidADT($a_adt)) {
52  throw new Exception('ADTDBBridge Type mismatch.');
53  }
54 
55  $this->adt = $a_adt;
56  }
57 
63  public function getADT()
64  {
65  return $this->adt;
66  }
67 
73  public function setTable($a_table)
74  {
75  $this->table = (string) $a_table;
76  }
77 
83  public function getTable()
84  {
85  return $this->table;
86  }
87 
93  public function setElementId($a_value)
94  {
95  $this->id = (string) $a_value;
96  }
97 
103  public function getElementId()
104  {
105  return $this->id;
106  }
107 
113  public function setPrimary(array $a_value)
114  {
115  $this->primary = $a_value;
116  }
117 
123  public function getPrimary()
124  {
125  return $this->primary;
126  }
127 
134  public function buildPrimaryWhere()
135  {
136  global $DIC;
137 
138  $ilDB = $DIC['ilDB'];
139 
140  $sql = array();
141 
142  foreach ($this->primary as $field => $def) {
143  $sql[] = $field . "=" . $ilDB->quote($def[1], $def[0]);
144  }
145 
146  return implode(" AND ", $sql);
147  }
148 
149 
150  //
151  // CRUD
152  //
153 
159  abstract public function readRecord(array $a_row);
160 
166  abstract public function prepareInsert(array &$a_fields);
167 
171  public function afterInsert()
172  {
173  }
174 
181  public function prepareUpdate(array &$a_fields)
182  {
183  $this->prepareInsert($a_fields);
184  }
185 
189  public function afterUpdate()
190  {
191  }
192 
196  public function afterDelete()
197  {
198  }
199 }
setADT(ilADT $a_adt)
Set ADT.
setPrimary(array $a_value)
Set primary fields (in MDB2 format)
buildPrimaryWhere()
Convert primary keys array to sql string.
global $DIC
Definition: saml.php:7
getTable()
Get table name.
getPrimary()
Get primary fields.
getElementId()
Get element id.
ADT base class.
Definition: class.ilADT.php:11
__construct(ilADT $a_adt)
Constructor.
ADT DB bridge base class.
afterInsert()
After insert hook to enable sub-tables.
readRecord(array $a_row)
Import DB values to ADT.
afterDelete()
After delete hook to enable sub-tables.
prepareInsert(array &$a_fields)
Prepare ADT values for insert.
global $ilDB
setElementId($a_value)
Set element id (aka DB column[s] [prefix])
isValidADT(ilADT $a_adt)
Check if given ADT is valid.
$def
Definition: croninfo.php:21
setTable($a_table)
Set table name.
afterUpdate()
After update hook to enable sub-tables.
prepareUpdate(array &$a_fields)
Prepare ADT values for update.