ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilADTGroupDBBridge.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 {
7  protected array $elements = [];
8 
9  protected function isValidADT(ilADT $a_adt): bool
10  {
11  return ($a_adt instanceof ilADTGroup);
12  }
13 
14  // elements
15 
16  protected function prepareElements(): void
17  {
18  if (count($this->elements)) {
19  return;
20  }
21 
22  $this->elements = array();
24 
25  // convert ADTs to DB bridges
26 
27  foreach ($this->getADT()->getElements() as $name => $element) {
28  $this->elements[$name] = $factory->getDBBridgeForInstance($element);
29  $this->elements[$name]->setElementId((string) $name);
30  $this->elements[$name]->setTable($this->getTable());
31  $this->elements[$name]->setPrimary($this->getPrimary());
32  }
33  }
34 
38  public function getElements(): array
39  {
40  $this->prepareElements();
41  return $this->elements;
42  }
43 
44  public function getElement(string $a_element_id): ?ilADTDBBridge
45  {
46  if (array_key_exists($a_element_id, $this->getElements())) {
47  return $this->elements[$a_element_id];
48  }
49  return null;
50  }
51 
52  // properties
53  public function setTable(string $a_table): void
54  {
55  parent::setTable($a_table);
56  if (count($this->elements)) {
57  foreach (array_keys($this->getADT()->getElements()) as $name) {
58  $this->elements[$name]->setTable($this->getTable());
59  }
60  }
61  }
62 
63  public function setPrimary(array $a_value): void
64  {
65  parent::setPrimary($a_value);
66 
67  if (count($this->elements)) {
68  foreach (array_keys($this->getADT()->getElements()) as $name) {
69  $this->elements[$name]->setPrimary($this->getPrimary());
70  }
71  }
72  }
73 
74  // CRUD
75 
76  public function readRecord(array $a_row): void
77  {
78  foreach ($this->getElements() as $element) {
79  $element->readRecord($a_row);
80  }
81  }
82 
83  public function prepareInsert(array &$a_fields): void
84  {
85  foreach ($this->getElements() as $element) {
86  $element->prepareInsert($a_fields);
87  }
88  }
89 
90  public function afterInsert(): void
91  {
92  foreach ($this->getElements() as $element) {
93  $element->afterInsert();
94  }
95  }
96 
97  public function afterUpdate(): void
98  {
99  foreach ($this->getElements() as $element) {
100  $element->afterUpdate();
101  }
102  }
103 
109  public function afterUpdateElement(string $field_type, string $field_name, int $field_id)
110  {
111  $element = $this->getElement((string) $field_id);
112  if (!$element) {
113  return;
114  }
115  $element->setPrimary(
116  array_merge(
117  $this->getPrimary(),
118  [
119  $field_name => [$field_type, $field_id]
120  ]
121  )
122  );
123  $element->setElementId((string) $field_id);
124  $element->afterUpdate();
125  }
126 
127  public function afterDelete(): void
128  {
129  foreach ($this->getElements() as $element) {
130  $element->afterDelete();
131  }
132  }
133 }
afterUpdateElement(string $field_type, string $field_name, int $field_id)
getPrimary()
Get primary fields.
ADT base class.
Definition: class.ilADT.php:11
if($format !==null) $name
Definition: metadata.php:247
ADT DB bridge base class.
getElement(string $a_element_id)
prepareInsert(array &$a_fields)
$factory
Definition: metadata.php:75