ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilADTActiveRecordWrapper.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
16{
17 protected $properties; // [ilADTGroupActiveRecordBridge]
18 protected $fields; // [arFieldList]
19 protected $field_element_map = []; // [array]
20
27 public function __construct(ilADTGroupActiveRecordBridge $a_properties)
28 {
29 $this->properties = $a_properties;
30
31 // see ActiveRecord::__construct();
32 $this->initFieldList();
33 $this->arConnector = new arConnectorDB();
34 }
35
36
37 //
38 // active record field(s)
39 //
40
41 protected function getActiveRecordFieldTypeFromMDB2($a_mdb2_type)
42 {
43 // currently they are all the same
44 switch ($a_mdb2_type) {
45 case "integer":
47
48 case "float":
50
51 case "text":
53
54 case "date":
56
57 case "timestamp":
59
60 case "integer":
62
63 /*
64 case "clob":
65 return arField::FIELD_TYPE_CLOB;
66
67 case "time":
68 return arField::FIELD_TYPE_TIME;
69 */
70 }
71 }
72
76 protected function initFieldList()
77 {
78 require_once "Services/ActiveRecord/classes/Fields/class.arFieldList.php";
79 $this->fields = new arFieldList();
80
81 // element => fields
82
83 $fields = array();
84 foreach ($this->properties->getActiveRecordFields() as $element_id => $element_fields) {
85 foreach ($element_fields as $field) {
86 $this->field_element_map[$field->getName()] = $element_id;
87 }
88
89 $fields = array_merge($fields, $element_fields);
90 }
91
92 $this->fields->setFields($fields);
93
94 // primary
95
96 if (sizeof($this->properties->getPrimary()) > 1) {
97 throw new ilException("ilADTActiveRecordWrapper - no complex primary keys supported yet");
98 }
99
100 foreach ($this->properties->getPrimary() as $primary_id => $primary_element) {
101 $field = new arField();
102 $field->setHasField(true);
103 $field->setNotNull(true);
104 $field->setFieldType($this->getActiveRecordFieldTypeFromMDB2($primary_element[0]));
105 $field->setName($primary_id);
106 $this->fields->setPrimaryField($field);
107 }
108 }
109
110
111 //
112 // active record meta (table/primary key)
113 //
114
116 {
117 return $this->properties->getTableName();
118 }
119
120 public static function returnDbTableName()
121 {
122 // :TODO: cannot be static
123 }
124
125 public function getPrimaryFieldValue()
126 {
127 $primary = array_shift($this->properties->getPrimary());
128 return $primary[1];
129 }
130
131
132 //
133 // active record CRUD
134 //
135
136 public function sleep($field_name)
137 {
138 if (array_key_exists($field_name, $this->field_element_map)) {
139 $element = $this->properties->getElement($this->field_element_map[$field_name]);
140 return $element->getFieldValue($field_name);
141 }
142
143 // returning NULL would result in direct property access!
144 return false;
145 }
146
147 public function wakeUp($field_name, $field_value)
148 {
149 if (array_key_exists($field_name, $this->field_element_map)) {
150 $element = $this->properties->getElement($this->field_element_map[$field_name]);
151 return $element->setFieldValue($field_name, $field_value);
152 }
153
154 // returning NULL would result in direct property access!
155 return false;
156 }
157}
Class ActiveRecord.
An exception for terminatinating execution or to throw for unit testing.
Class arConnectorDB.
Class arConnector.
Class arFieldList.
Class arField.
const FIELD_TYPE_TEXT
const FIELD_TYPE_FLOAT
const FIELD_TYPE_DATE
const FIELD_TYPE_INTEGER
const FIELD_TYPE_TIMESTAMP
ADT Active Record service wrapper class.
__construct(ilADTGroupActiveRecordBridge $a_properties)
Constructor.
initFieldList()
Get field list instance for ADT group.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$errors fields
Definition: imgupload.php:51