ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
class.ilADTGroupDBBridge.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  protected array $elements = [];
24 
25  protected function isValidADT(ilADT $a_adt): bool
26  {
27  return ($a_adt instanceof ilADTGroup);
28  }
29 
30  // elements
31 
32  protected function prepareElements(): void
33  {
34  if (count($this->elements)) {
35  return;
36  }
37 
38  $this->elements = array();
39  $factory = ilADTFactory::getInstance();
40 
41  // convert ADTs to DB bridges
42 
43  foreach ($this->getADT()->getElements() as $name => $element) {
44  $this->elements[$name] = $factory->getDBBridgeForInstance($element);
45  $this->elements[$name]->setElementId((string) $name);
46  $this->elements[$name]->setTable($this->getTable());
47  $this->elements[$name]->setPrimary($this->getPrimary());
48  }
49  }
50 
54  public function getElements(): array
55  {
56  $this->prepareElements();
57  return $this->elements;
58  }
59 
60  public function getElement(string $a_element_id): ?ilADTDBBridge
61  {
62  if (array_key_exists($a_element_id, $this->getElements())) {
63  return $this->elements[$a_element_id];
64  }
65  return null;
66  }
67 
68  // properties
69  public function setTable(string $a_table): void
70  {
71  parent::setTable($a_table);
72  if (count($this->elements)) {
73  foreach (array_keys($this->getADT()->getElements()) as $name) {
74  $this->elements[$name]->setTable($this->getTable());
75  }
76  }
77  }
78 
79  public function setPrimary(array $a_value): void
80  {
81  parent::setPrimary($a_value);
82 
83  if (count($this->elements)) {
84  foreach (array_keys($this->getADT()->getElements()) as $name) {
85  $this->elements[$name]->setPrimary($this->getPrimary());
86  }
87  }
88  }
89 
90  // CRUD
91 
92  public function readRecord(array $a_row): void
93  {
94  foreach ($this->getElements() as $element) {
95  $element->readRecord($a_row);
96  }
97  }
98 
99  public function prepareInsert(array &$a_fields): void
100  {
101  foreach ($this->getElements() as $element) {
102  $element->prepareInsert($a_fields);
103  }
104  }
105 
106  public function afterInsert(): void
107  {
108  foreach ($this->getElements() as $element) {
109  $element->afterInsert();
110  }
111  }
112 
113  public function afterUpdate(): void
114  {
115  foreach ($this->getElements() as $element) {
116  $element->afterUpdate();
117  }
118  }
119 
125  public function afterUpdateElement(string $field_type, string $field_name, int $field_id)
126  {
127  $element = $this->getElement((string) $field_id);
128  if (!$element) {
129  return;
130  }
131  $element->setPrimary(
132  array_merge(
133  $this->getPrimary(),
134  [
135  $field_name => [$field_type, $field_id]
136  ]
137  )
138  );
139  $element->setElementId((string) $field_id);
140  $element->afterUpdate();
141  }
142 
143  public function afterDelete(): void
144  {
145  foreach ($this->getElements() as $element) {
146  $element->afterDelete();
147  }
148  }
149 }
afterUpdateElement(string $field_type, string $field_name, int $field_id)
getPrimary()
Get primary fields.
ADT base class.
Definition: class.ilADT.php:25
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
ADT DB bridge base class.
getElement(string $a_element_id)
prepareInsert(array &$a_fields)