ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 {
53 throw new Exception('ADTDBBridge Type mismatch.');
54 }
55
56 $this->adt = $a_adt;
57 }
58
64 public function getADT()
65 {
66 return $this->adt;
67 }
68
74 public function setTable($a_table)
75 {
76 $this->table = (string)$a_table;
77 }
78
84 public function getTable()
85 {
86 return $this->table;
87 }
88
94 public function setElementId($a_value)
95 {
96 $this->id = (string)$a_value;
97 }
98
104 public function getElementId()
105 {
106 return $this->id;
107 }
108
114 public function setPrimary(array $a_value)
115 {
116 $this->primary = $a_value;
117 }
118
124 public function getPrimary()
125 {
126 return $this->primary;
127 }
128
135 public function buildPrimaryWhere()
136 {
137 global $ilDB;
138
139 $sql = array();
140
141 foreach($this->primary as $field => $def)
142 {
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 }
175
182 public function prepareUpdate(array &$a_fields)
183 {
184 $this->prepareInsert($a_fields);
185 }
186
190 public function afterUpdate()
191 {
192
193 }
194
198 public function afterDelete()
199 {
200
201 }
202}
203
204?>
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.
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 $ilDB