ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTDBBridge.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
25abstract class ilADTDBBridge
26{
27 protected ilADT $adt;
28 protected string $table;
29 protected string $id;
30 protected array $primary = [];
31
32 protected ilDBInterface $db;
33
38 public function __construct(ilADT $a_adt)
39 {
40 global $DIC;
41
42 $this->db = $DIC->database();
43 $this->setADT($a_adt);
44 }
45
46 abstract protected function isValidADT(ilADT $a_adt): bool;
47
48 protected function setADT(ilADT $a_adt): void
49 {
50 if (!$this->isValidADT($a_adt)) {
51 throw new \InvalidArgumentException('ADTDBBridge Type mismatch.');
52 }
53 $this->adt = $a_adt;
54 }
55
56 public function getADT(): ilADT
57 {
58 return $this->adt;
59 }
60
61 public function setTable(string $a_table): void
62 {
63 $this->table = $a_table;
64 }
65
66 public function getTable(): ?string
67 {
68 return $this->table;
69 }
70
75 public function setElementId(string $a_value): void
76 {
77 $this->id = $a_value;
78 }
79
84 public function getElementId(): ?string
85 {
86 return $this->id;
87 }
88
93 public function setPrimary(array $a_value): void
94 {
95 $this->primary = $a_value;
96 }
97
98 public function getAdditionalPrimaryFields(): array
99 {
100 return [];
101 }
102
107 public function getPrimary(): array
108 {
109 return $this->primary;
110 }
111
117 public function buildPrimaryWhere(): string
118 {
119 $sql = [];
120 foreach ($this->primary as $field => $def) {
121 $sql[] = $field . "=" . $this->db->quote($def[1], $def[0]);
122 }
123 return implode(" AND ", $sql);
124 }
125
130 abstract public function readRecord(array $a_row): void;
131
136 abstract public function prepareInsert(array &$a_fields): void;
137
141 public function afterInsert(): void
142 {
143 }
144
145 public function prepareUpdate(array &$a_fields): void
146 {
147 $this->prepareInsert($a_fields);
148 }
149
153 public function afterUpdate(): void
154 {
155 }
156
160 public function afterDelete(): void
161 {
162 }
163
168 public function supportsDefaultValueColumn(): bool
169 {
170 return true;
171 }
172}
ADT DB bridge base class.
__construct(ilADT $a_adt)
Constructor.
getElementId()
Get element id.
ilDBInterface $db
readRecord(array $a_row)
Import DB values to ADT.
prepareInsert(array &$a_fields)
Prepare ADT values for insert.
setADT(ilADT $a_adt)
setTable(string $a_table)
afterInsert()
After insert hook to enable sub-tables.
isValidADT(ilADT $a_adt)
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)
afterDelete()
After delete hook to enable sub-tables.
prepareUpdate(array &$a_fields)
setElementId(string $a_value)
Set element id (aka DB column[s] [prefix])
ADT base class.
Definition: class.ilADT.php:26
Interface ilDBInterface.
global $DIC
Definition: shib_login.php:26