ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.arConnectorSession.php
Go to the documentation of this file.
1<?php
2
25{
26 public const AR_CONNECTOR_SESSION = 'arConnectorSession';
27
28 public static function resetSession(): void
29 {
30 $_SESSION[self::AR_CONNECTOR_SESSION] = [];
31 }
32
36 public static function getSession(): array
37 {
38 if (!$_SESSION[self::AR_CONNECTOR_SESSION]) {
40 }
41
42 return $_SESSION[self::AR_CONNECTOR_SESSION];
43 }
44
48 public static function getSessionForActiveRecord(ActiveRecord $activeRecord): array
49 {
50 $session = self::getSession();
51 $ar_session = $session[$activeRecord::returnDbTableName()];
52 if (!is_array($ar_session)) {
53 return [];
54 }
55
56 return $ar_session;
57 }
58
59 public function checkConnection(ActiveRecord $activeRecord): bool
60 {
61 return is_array(self::getSession());
62 }
63
67 public function nextID(ActiveRecord $activeRecord): int
68 {
69 return count(self::getSessionForActiveRecord($activeRecord)) + 1;
70 }
71
72 public function installDatabase(ActiveRecord $activeRecord, array $fields): bool
73 {
74 return $this->resetDatabase($activeRecord);
75 }
76
77 public function updateDatabase(ActiveRecord $activeRecord): bool
78 {
79 return true;
80 }
81
82 public function resetDatabase(ActiveRecord $activeRecord): bool
83 {
84 $_SESSION[self::AR_CONNECTOR_SESSION][$activeRecord::returnDbTableName()] = [];
85
86 return true;
87 }
88
89 public function truncateDatabase(ActiveRecord $activeRecord): bool
90 {
91 return $this->resetDatabase($activeRecord);
92 }
93
94 public function checkTableExists(ActiveRecord $activeRecord): bool
95 {
96 return is_array(self::getSessionForActiveRecord($activeRecord));
97 }
98
99 public function checkFieldExists(ActiveRecord $activeRecord, string $field_name): bool
100 {
101 $session = self::getSessionForActiveRecord($activeRecord);
102
103 return array_key_exists($field_name, $session[0]);
104 }
105
109 public function removeField(ActiveRecord $activeRecord, string $field_name): bool
110 {
111 return true;
112 }
113
117 public function renameField(ActiveRecord $activeRecord, string $old_name, string $new_name): bool
118 {
119 return true;
120 }
121
122 public function create(ActiveRecord $activeRecord): void
123 {
124 $_SESSION[self::AR_CONNECTOR_SESSION][$activeRecord::returnDbTableName()][$activeRecord->getPrimaryFieldValue(
125 )] = $activeRecord->asStdClass();
126 }
127
131 public function read(ActiveRecord $activeRecord): array
132 {
133 $session = self::getSessionForActiveRecord($activeRecord);
134
135 return [$session[$activeRecord->getPrimaryFieldValue()]];
136 }
137
138 public function update(ActiveRecord $activeRecord): void
139 {
140 $this->create($activeRecord);
141 }
142
143 public function delete(ActiveRecord $activeRecord): void
144 {
145 unset(
146 $_SESSION[self::AR_CONNECTOR_SESSION][$activeRecord::returnDbTableName(
147 )][$activeRecord->getPrimaryFieldValue()]
148 );
149 }
150
155 public function readSet(ActiveRecordList $activeRecordList): array
156 {
157 $session = self::getSessionForActiveRecord($activeRecordList->getAR());
158 foreach ($session as $i => $s) {
159 $session[$i] = (array) $s;
160 }
161 foreach ($activeRecordList->getArWhereCollection()->getWheres() as $arWhere) {
162 $fieldname = $arWhere->getFieldname();
163 $v = $arWhere->getValue();
164 $operator = $arWhere->getOperator();
165
166 foreach ($session as $i => $s) {
167 $session[$i] = (array) $s;
168 if ($operator !== '=') {
169 continue;
170 }
171 if ($s[$fieldname] === $v) {
172 continue;
173 }
174 unset($session[$i]);
175 }
176 }
177
178 return $session;
179 }
180
181 public function affectedRows(ActiveRecordList $activeRecordList): int
182 {
183 return count($this->readSet($activeRecordList));
184 }
185
189 public function quote($value, string $type): string
190 {
191 return $value;
192 }
193
194 public function updateIndices(ActiveRecord $activeRecord): void
195 {
196 // TODO: Implement updateIndices() method.
197 }
198}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
create(ActiveRecord $activeRecord)
update(ActiveRecord $activeRecord)
quote($value, string $type)
nextID(ActiveRecord $activeRecord)
read(ActiveRecord $activeRecord)
updateDatabase(ActiveRecord $activeRecord)
truncateDatabase(ActiveRecord $activeRecord)
checkTableExists(ActiveRecord $activeRecord)
affectedRows(ActiveRecordList $activeRecordList)
renameField(ActiveRecord $activeRecord, string $old_name, string $new_name)
readSet(ActiveRecordList $activeRecordList)
checkConnection(ActiveRecord $activeRecord)
updateIndices(ActiveRecord $activeRecord)
resetDatabase(ActiveRecord $activeRecord)
installDatabase(ActiveRecord $activeRecord, array $fields)
removeField(ActiveRecord $activeRecord, string $field_name)
static getSessionForActiveRecord(ActiveRecord $activeRecord)
checkFieldExists(ActiveRecord $activeRecord, string $field_name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...