ILIAS  release_8 Revision v8.23
class.ilADTActiveRecordWrapper.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
5 
13 {
15  protected arFieldList $fields;
17  protected array $field_element_map = [];
18 
23  public function __construct(ilADTGroupActiveRecordBridge $a_properties)
24  {
25  $this->properties = $a_properties;
26  $this->initFieldList();
27  $this->arConnector = new arConnectorDB();
28  }
29 
30  protected function getActiveRecordFieldTypeFromMDB2(string $a_mdb2_type): ?string
31  {
32  // currently they are all the same
33  switch ($a_mdb2_type) {
34  case "integer":
36 
37  case "float":
39 
40  case "text":
42 
43  case "date":
45 
46  case "timestamp":
48  }
49  return null;
50  }
51 
52  protected function initFieldList(): void
53  {
54  $this->fields = new arFieldList($this);
55 
56  $fields = [];
57  foreach ($this->properties->getActiveRecordFields() as $element_id => $element_fields) {
58  foreach ($element_fields as $field) {
59  $this->field_element_map[$field->getName()] = $element_id;
60  }
61  $fields = array_merge($fields, $element_fields);
62  }
63  $this->fields->setFields($fields);
64 
65  // primary
66 
67  if (count($this->properties->getPrimary()) > 1) {
68  throw new ilException("ilADTActiveRecordWrapper - no complex primary keys supported yet");
69  }
70 
71  foreach ($this->properties->getPrimary() as $primary_id => $primary_element) {
72  $field = new arField();
73  $field->setHasField(true);
74  $field->setNotNull(true);
75  $field->setFieldType($this->getActiveRecordFieldTypeFromMDB2($primary_element[0] ?? ''));
76  $field->setName($primary_id);
77  $this->fields->setPrimaryField($field);
78  }
79  }
80 
81  public function getConnectorContainerName(): string
82  {
83  return $this->properties->getTable();
84  }
85 
86  public static function returnDbTableName(): string
87  {
88  throw new \RuntimeException('Not implemented yet');
89  }
90 
91  public function getPrimaryFieldValue(): string
92  {
93  $primaries = $this->properties->getPrimary();
94  $primary = array_shift($primaries);
95  return $primary[1];
96  }
97 
101  public function sleep($field_name)
102  {
103  if (array_key_exists($field_name, $this->field_element_map)) {
104  $element = $this->properties->getElement($this->field_element_map[$field_name]);
105  return $element->getFieldValue($field_name);
106  }
107  return false;
108  }
109 
110 
114  public function wakeUp($field_name, $field_value)
115  {
116  if (array_key_exists($field_name, $this->field_element_map)) {
117  $element = $this->properties->getElement($this->field_element_map[$field_name]);
118  $element->setFieldValue($field_name, $field_value);
119  return true;
120  }
121  return false;
122  }
123 }
const FIELD_TYPE_FLOAT
Class arField.
getActiveRecordFieldTypeFromMDB2(string $a_mdb2_type)
ADT Active Record service wrapper class This class expects a valid primary for all actions! ...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$errors fields
Definition: imgupload.php:67
const FIELD_TYPE_TEXT
Class arConnector.
const FIELD_TYPE_INTEGER
__construct(ilADTGroupActiveRecordBridge $a_properties)
Constructor.
const FIELD_TYPE_DATE
ilADTGroupActiveRecordBridge $properties
const FIELD_TYPE_TIMESTAMP
Class arFieldList.