ILIAS  release_7 Revision v7.30-3-g800a261c036
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
11abstract 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
204 public function supportsDefaultValueColumn() : bool
205 {
206 return true;
207 }
208}
An exception for terminatinating execution or to throw for unit testing.
ADT DB bridge base class.
__construct(ilADT $a_adt)
Constructor.
getElementId()
Get element id.
readRecord(array $a_row)
Import DB values to ADT.
prepareInsert(array &$a_fields)
Prepare ADT values for insert.
setADT(ilADT $a_adt)
Set ADT.
setTable($a_table)
Set table name.
afterInsert()
After insert hook to enable sub-tables.
isValidADT(ilADT $a_adt)
Check if given ADT is valid.
afterUpdate()
After update hook to enable sub-tables.
getPrimary()
Get primary fields.
supportsDefaultValueColumn()
true if table storage relies on the default 'value' column
buildPrimaryWhere()
Convert primary keys array to sql string.
setPrimary(array $a_value)
Set primary fields (in MDB2 format)
setElementId($a_value)
Set element id (aka DB column[s] [prefix])
afterDelete()
After delete hook to enable sub-tables.
prepareUpdate(array &$a_fields)
Prepare ADT values for update.
getTable()
Get table name.
ADT base class.
Definition: class.ilADT.php:12
global $DIC
Definition: goto.php:24
global $ilDB