ILIAS  release_8 Revision v8.24
class.ilADTMultiEnumDBBridge.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
6{
7 public const TABLE_NAME = 'adv_md_values_enum';
8 public const SEPARATOR = "~|~";
9
10 protected bool $fake_single = false;
11
12 public function getTable(): ?string
13 {
14 return self::TABLE_NAME;
15 }
16
17 protected function isValidADT(ilADT $a_adt): bool
18 {
19 return ($a_adt instanceof ilADTMultiEnum);
20 }
21
22 public function setFakeSingle(bool $a_status): void
23 {
24 $this->fake_single = $a_status;
25 }
26
27 protected function doSingleFake(): bool
28 {
29 return $this->fake_single;
30 }
31
32 public function readRecord(array $a_row): void
33 {
34 if (isset($a_row[$this->getElementId()])) {
35 $this->getADT()->addSelection((int) $a_row[$this->getElementId()]);
36 }
37 }
38
39 public function afterInsert(): void
40 {
41 $this->afterUpdate();
42 }
43
44 public function afterUpdate(): void
45 {
46 $this->deleteIndices();
47 $this->insertIndices();
48 }
49
50 public function prepareInsert(array &$a_fields): void
51 {
52 $a_fields = [];
53 }
54
55 protected function deleteIndices(): void
56 {
57 $this->db->query(
58 'delete from ' . $this->getTable() . ' ' .
59 'where ' . $this->buildPrimaryWhere()
60 );
61 }
62
63 protected function insertIndices(): void
64 {
65 foreach ((array) $this->getADT()->getSelections() as $index) {
66 $fields = $this->getPrimary();
67 $fields['value_index'] = [ilDBConstants::T_INTEGER, $index];
68 $num_row = $this->db->insert($this->getTable(), $fields);
69 }
70 }
71
72 public function supportsDefaultValueColumn(): bool
73 {
74 return false;
75 }
76}
ADT DB bridge base class.
getElementId()
Get element id.
getPrimary()
Get primary fields.
buildPrimaryWhere()
Convert primary keys array to sql string.
supportsDefaultValueColumn()
true if table storage relies on the default 'value' column
prepareInsert(array &$a_fields)
Prepare ADT values for insert.
afterInsert()
After insert hook to enable sub-tables.
readRecord(array $a_row)
Import DB values to ADT.
afterUpdate()
After update hook to enable sub-tables.
ADT base class.
Definition: class.ilADT.php:12
$index
Definition: metadata.php:145