ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTMultiEnumDBBridge.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 public const TABLE_NAME = 'adv_md_values_enum';
24 public const SEPARATOR = "~|~";
25
26 protected bool $fake_single = false;
27
28 public function getTable(): ?string
29 {
30 return self::TABLE_NAME;
31 }
32
33 protected function isValidADT(ilADT $a_adt): bool
34 {
35 return ($a_adt instanceof ilADTMultiEnum);
36 }
37
38 public function setFakeSingle(bool $a_status): void
39 {
40 $this->fake_single = $a_status;
41 }
42
43 protected function doSingleFake(): bool
44 {
45 return $this->fake_single;
46 }
47
48 public function readRecord(array $a_row): void
49 {
50 if (isset($a_row[$this->getElementId()])) {
51 $this->getADT()->addSelection((int) $a_row[$this->getElementId()]);
52 }
53 }
54
55 public function afterInsert(): void
56 {
57 $this->afterUpdate();
58 }
59
60 public function afterUpdate(): void
61 {
62 $this->deleteIndices();
63 $this->insertIndices();
64 }
65
66 public function prepareInsert(array &$a_fields): void
67 {
68 $a_fields = [];
69 }
70
71 protected function deleteIndices(): void
72 {
73 $this->db->query(
74 'delete from ' . $this->getTable() . ' ' .
75 'where ' . $this->buildPrimaryWhere()
76 );
77 }
78
79 protected function insertIndices(): void
80 {
81 foreach ((array) $this->getADT()->getSelections() as $index) {
82 $fields = $this->getPrimary();
83 $fields['value_index'] = [ilDBConstants::T_INTEGER, $index];
84 $num_row = $this->db->insert($this->getTable(), $fields);
85 }
86 }
87
88 public function supportsDefaultValueColumn(): bool
89 {
90 return false;
91 }
92}
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:26