ILIAS  release_8 Revision v8.24
class.ilADTDBBridge.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
5
11abstract class ilADTDBBridge
12{
13 protected ilADT $adt;
14 protected string $table;
15 protected string $id;
16 protected array $primary = [];
17
18 protected ilDBInterface $db;
19
24 public function __construct(ilADT $a_adt)
25 {
26 global $DIC;
27
28 $this->db = $DIC->database();
29 $this->setADT($a_adt);
30 }
31
32 abstract protected function isValidADT(ilADT $a_adt): bool;
33
34 protected function setADT(ilADT $a_adt): void
35 {
36 if (!$this->isValidADT($a_adt)) {
37 throw new \InvalidArgumentException('ADTDBBridge Type mismatch.');
38 }
39 $this->adt = $a_adt;
40 }
41
42 public function getADT(): ilADT
43 {
44 return $this->adt;
45 }
46
47 public function setTable(string $a_table): void
48 {
49 $this->table = $a_table;
50 }
51
52 public function getTable(): ?string
53 {
54 return $this->table;
55 }
56
61 public function setElementId(string $a_value): void
62 {
63 $this->id = $a_value;
64 }
65
70 public function getElementId(): ?string
71 {
72 return $this->id;
73 }
74
79 public function setPrimary(array $a_value): void
80 {
81 $this->primary = $a_value;
82 }
83
84 public function getAdditionalPrimaryFields(): array
85 {
86 return [];
87 }
88
93 public function getPrimary(): array
94 {
95 return $this->primary;
96 }
97
103 public function buildPrimaryWhere(): string
104 {
105 $sql = [];
106 foreach ($this->primary as $field => $def) {
107 $sql[] = $field . "=" . $this->db->quote($def[1], $def[0]);
108 }
109 return implode(" AND ", $sql);
110 }
111
116 abstract public function readRecord(array $a_row): void;
117
122 abstract public function prepareInsert(array &$a_fields): void;
123
127 public function afterInsert(): void
128 {
129 }
130
131 public function prepareUpdate(array &$a_fields): void
132 {
133 $this->prepareInsert($a_fields);
134 }
135
139 public function afterUpdate(): void
140 {
141 }
142
146 public function afterDelete(): void
147 {
148 }
149
154 public function supportsDefaultValueColumn(): bool
155 {
156 return true;
157 }
158}
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:12
global $DIC
Definition: feed.php:28
Interface ilDBInterface.