ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilADTMultiEnumDBBridge.php
Go to the documentation of this file.
1<?php
2
3require_once "Services/ADT/classes/Bridges/class.ilADTMultiDBBridge.php";
4
6{
7 const TABLE_NAME = 'adv_md_values_enum';
8
12 protected $db;
13
14 protected $fake_single;
15
16 const SEPARATOR = "~|~";
17
18 public function __construct(ilADT $a_adt)
19 {
20 global $DIC;
21
22 $this->db = $DIC->database();
23 parent::__construct($a_adt);
24 }
25
26 public function getTable() : string
27 {
28 return self::TABLE_NAME;
29 }
30
31 protected function isValidADT(ilADT $a_adt)
32 {
33 return ($a_adt instanceof ilADTMultiEnum);
34 }
35
36 public function setFakeSingle($a_status)
37 {
38 $this->fake_single = (bool) $a_status;
39 }
40
41 protected function doSingleFake()
42 {
43 return $this->fake_single;
44 }
45
46 public function readRecord(array $a_row)
47 {
48 if (isset($a_row[$this->getElementId()])) {
49 $this->getADT()->addSelection($a_row[$this->getElementId()]);
50 }
51 }
52
53 public function afterInsert()
54 {
55 return $this->afterUpdate();
56 }
57
58 public function afterUpdate()
59 {
60 $this->deleteIndices();
61 $this->insertIndices();
62 }
63
64 public function prepareInsert(array &$a_fields)
65 {
66 $a_fields = [];
67 }
68
69 protected function deleteIndices()
70 {
71 $this->db->query(
72 'delete from ' . $this->getTable() . ' ' .
73 'where ' . $this->buildPrimaryWhere()
74 );
75 }
76
77 protected function insertIndices()
78 {
79 foreach ($this->getADT()->getSelections() as $index)
80 {
81 $fields = $this->getPrimary();
82 $fields['value_index'] = [ilDBConstants::T_INTEGER, $index];
83 $num_row = $this->db->insert($this->getTable(), $fields);
84 ilLoggerFactory::getLogger('amet')->dump($num_row);
85 }
86 }
87
88 public function supportsDefaultValueColumn() : bool
89 {
90 return false;
91 }
92}
An exception for terminatinating execution or to throw for unit testing.
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.
__construct(ilADT $a_adt)
Constructor.
isValidADT(ilADT $a_adt)
Check if given ADT is valid.
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
static getLogger($a_component_id)
Get component logger.
global $DIC
Definition: goto.php:24
$index
Definition: metadata.php:128
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc