ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
arConnectorDB Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for arConnectorDB:
+ Collaboration diagram for arConnectorDB:

Public Member Functions

 __construct (?ilDBInterface $ilDB=null)
 
 checkConnection (ActiveRecord $activeRecord)
 
 nextID (ActiveRecord $activeRecord)
 
 installDatabase (ActiveRecord $activeRecord, array $fields)
 
 updateIndices (ActiveRecord $activeRecord)
 
 updateDatabase (ActiveRecord $activeRecord)
 
 resetDatabase (ActiveRecord $activeRecord)
 
 truncateDatabase (ActiveRecord $activeRecord)
 
 checkTableExists (ActiveRecord $activeRecord)
 
 checkFieldExists (ActiveRecord $activeRecord, string $field_name)
 
 removeField (ActiveRecord $activeRecord, string $field_name)
 
 renameField (ActiveRecord $activeRecord, string $old_name, string $new_name)
 
 create (ActiveRecord $activeRecord)
 
 read (ActiveRecord $activeRecord)
 
 update (ActiveRecord $activeRecord)
 
 delete (ActiveRecord $activeRecord)
 
 readSet (ActiveRecordList $activeRecordList)
 
 affectedRows (ActiveRecordList $activeRecordList)
 
 quote ($value, string $type)
 
- Public Member Functions inherited from arConnector
 nextID (ActiveRecord $activeRecord)
 
 checkConnection (ActiveRecord $activeRecord)
 
 installDatabase (ActiveRecord $activeRecord, array $fields)
 
 updateDatabase (ActiveRecord $activeRecord)
 
 resetDatabase (ActiveRecord $activeRecord)
 
 truncateDatabase (ActiveRecord $activeRecord)
 
 checkTableExists (ActiveRecord $activeRecord)
 
 checkFieldExists (ActiveRecord $activeRecord, string $field_name)
 
 removeField (ActiveRecord $activeRecord, string $field_name)
 
 renameField (ActiveRecord $activeRecord, string $old_name, string $new_name)
 
 create (ActiveRecord $activeRecord)
 
 read (ActiveRecord $activeRecord)
 
 update (ActiveRecord $activeRecord)
 
 delete (ActiveRecord $activeRecord)
 
 readSet (ActiveRecordList $activeRecordList)
 
 affectedRows (ActiveRecordList $activeRecordList)
 
 quote (mixed $value, string $type)
 
 updateIndices (ActiveRecord $activeRecord)
 
 fixDate (string $value)
 

Protected Member Functions

 returnDB ()
 
 buildQuery (ActiveRecordList $activeRecordList)
 

Private Attributes

ilDBInterface $db = null
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Class arConnectorDB

Author
Fabian Schmid fs@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
Timon Amstutz timon.nosp@m..ams.nosp@m.tutz@.nosp@m.ilub.nosp@m..unib.nosp@m.e.ch
Version
2.0.7

Definition at line 25 of file class.arConnectorDB.php.

Constructor & Destructor Documentation

◆ __construct()

arConnectorDB::__construct ( ?ilDBInterface  $ilDB = null)

Definition at line 29 of file class.arConnectorDB.php.

30 {
31 if (is_null($ilDB)) {
32 global $DIC;
33
34 $this->db = $GLOBALS['ilDB'] ?? $DIC['ilDB'] ?? null;
35 } else {
36 $this->db = $ilDB;
37 }
38 }
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54

References $DIC, $GLOBALS, and $ilDB.

Member Function Documentation

◆ affectedRows()

arConnectorDB::affectedRows ( ActiveRecordList  $activeRecordList)

@noinspection PhpParamsInspection

Reimplemented from arConnector.

Definition at line 255 of file class.arConnectorDB.php.

255 : int
256 {
257 $ilDB = $this->returnDB();
258 $q = $this->buildQuery($activeRecordList);
259
260 $set = $ilDB->query($q);
261
263 return $ilDB->numRows($set);
264 }
buildQuery(ActiveRecordList $activeRecordList)
$q
Definition: shib_logout.php:23

References $ilDB, $q, buildQuery(), and returnDB().

+ Here is the call graph for this function:

◆ buildQuery()

arConnectorDB::buildQuery ( ActiveRecordList  $activeRecordList)
protected
Returns
mixed|string

Definition at line 269 of file class.arConnectorDB.php.

269 : string
270 {
271 // SELECTS
272 $q = $activeRecordList->getArSelectCollection()->asSQLStatement($this->db);
273 // Concats
274 $q .= $activeRecordList->getArConcatCollection()->asSQLStatement($this->db);
275 $q .= ' FROM ' . $activeRecordList->getAR()->getConnectorContainerName();
276 // JOINS
277 $q .= $activeRecordList->getArJoinCollection()->asSQLStatement($this->db);
278 // WHERE
279 $q .= $activeRecordList->getArWhereCollection()->asSQLStatement($this->db);
280 // HAVING
281 $q .= $activeRecordList->getArHavingCollection()->asSQLStatement($this->db);
282 // ORDER
283 $q .= $activeRecordList->getArOrderCollection()->asSQLStatement($this->db);
284 // LIMIT
285 $q .= $activeRecordList->getArLimitCollection()->asSQLStatement($this->db);
286
287 $activeRecordList->setLastQuery($q);
288
289 return $q;
290 }
static setLastQuery(string $last_query)

References $q, ActiveRecordList\getAR(), ActiveRecordList\getArConcatCollection(), ActiveRecordList\getArHavingCollection(), ActiveRecordList\getArJoinCollection(), ActiveRecordList\getArLimitCollection(), ActiveRecordList\getArOrderCollection(), ActiveRecordList\getArSelectCollection(), ActiveRecordList\getArWhereCollection(), and ActiveRecordList\setLastQuery().

Referenced by affectedRows(), and readSet().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkConnection()

arConnectorDB::checkConnection ( ActiveRecord  $activeRecord)

Reimplemented from arConnector.

Definition at line 48 of file class.arConnectorDB.php.

48 : bool
49 {
50 return is_object($this->returnDB());
51 }

References returnDB().

+ Here is the call graph for this function:

◆ checkFieldExists()

arConnectorDB::checkFieldExists ( ActiveRecord  $activeRecord,
string  $field_name 
)

Reimplemented from arConnector.

Definition at line 153 of file class.arConnectorDB.php.

153 : bool
154 {
155 $ilDB = $this->returnDB();
156
157 return $ilDB->tableColumnExists($activeRecord->getConnectorContainerName(), $field_name);
158 }
getConnectorContainerName()
@description Return the Name of your Connector Table

References $ilDB, ActiveRecord\getConnectorContainerName(), and returnDB().

+ Here is the call graph for this function:

◆ checkTableExists()

arConnectorDB::checkTableExists ( ActiveRecord  $activeRecord)

@TODO: This is the proper ILIAS approach on how to do this BUT: This is exteremely slow (listTables is used)! However, this is not the place to fix this issue. Report.

Reimplemented from arConnector.

Definition at line 142 of file class.arConnectorDB.php.

142 : bool
143 {
144 $ilDB = $this->returnDB();
145
150 return $ilDB->tableExists($activeRecord->getConnectorContainerName());
151 }

References $ilDB, ActiveRecord\getConnectorContainerName(), and returnDB().

+ Here is the call graph for this function:

◆ create()

arConnectorDB::create ( ActiveRecord  $activeRecord)

Reimplemented from arConnector.

Definition at line 185 of file class.arConnectorDB.php.

185 : void
186 {
187 $ilDB = $this->returnDB();
188 $ilDB->insert($activeRecord->getConnectorContainerName(), $activeRecord->getArrayForConnector());
189 }

References $ilDB, ActiveRecord\getArrayForConnector(), ActiveRecord\getConnectorContainerName(), and returnDB().

+ Here is the call graph for this function:

◆ delete()

arConnectorDB::delete ( ActiveRecord  $activeRecord)

Reimplemented from arConnector.

Definition at line 227 of file class.arConnectorDB.php.

227 : void
228 {
229 $ilDB = $this->returnDB();
230
231 $ilDB->manipulate(
232 'DELETE FROM ' . $activeRecord->getConnectorContainerName() . ' WHERE ' . arFieldCache::getPrimaryFieldName(
233 $activeRecord
234 ) . ' = '
235 . $ilDB->quote($activeRecord->getPrimaryFieldValue(), arFieldCache::getPrimaryFieldType($activeRecord))
236 );
237 }
static getPrimaryFieldType(ActiveRecord $activeRecord)
static getPrimaryFieldName(ActiveRecord $activeRecord)

References $ilDB, arFieldCache\getPrimaryFieldName(), arFieldCache\getPrimaryFieldType(), and returnDB().

+ Here is the call graph for this function:

◆ installDatabase()

arConnectorDB::installDatabase ( ActiveRecord  $activeRecord,
array  $fields 
)

Reimplemented from arConnector.

Definition at line 61 of file class.arConnectorDB.php.

61 : bool
62 {
63 $ilDB = $this->returnDB();
64 $ilDB->createTable($activeRecord->getConnectorContainerName(), $fields);
65 $arFieldList = $activeRecord->getArFieldList();
66 if ($arFieldList->getPrimaryField()->getName() !== '' && $arFieldList->getPrimaryField()->getName() !== '0') {
67 $ilDB->addPrimaryKey(
68 $activeRecord->getConnectorContainerName(),
69 [$arFieldList->getPrimaryField()->getName()]
70 );
71 }
72 if (!$ilDB->sequenceExists($activeRecord->getConnectorContainerName()) && $activeRecord->getArFieldList(
73 )->getPrimaryField()->getSequence()) {
74 $ilDB->createSequence($activeRecord->getConnectorContainerName());
75 }
76 $this->updateIndices($activeRecord);
77
78 return true;
79 }
updateIndices(ActiveRecord $activeRecord)

References $ilDB, ActiveRecord\getArFieldList(), ActiveRecord\getConnectorContainerName(), returnDB(), and updateIndices().

+ Here is the call graph for this function:

◆ nextID()

arConnectorDB::nextID ( ActiveRecord  $activeRecord)
Returns
mixed

Reimplemented from arConnector.

Definition at line 56 of file class.arConnectorDB.php.

56 : int
57 {
58 return $this->returnDB()->nextId($activeRecord->getConnectorContainerName());
59 }

References ActiveRecord\getConnectorContainerName(), and returnDB().

+ Here is the call graph for this function:

◆ quote()

arConnectorDB::quote (   $value,
string  $type 
)
Parameters
$value

Definition at line 295 of file class.arConnectorDB.php.

295 : string
296 {
297 $ilDB = $this->returnDB();
298
299 return $ilDB->quote($value, $type);
300 }

References $ilDB, and returnDB().

+ Here is the call graph for this function:

◆ read()

arConnectorDB::read ( ActiveRecord  $activeRecord)
Returns
mixed[]

Reimplemented from arConnector.

Definition at line 194 of file class.arConnectorDB.php.

194 : array
195 {
196 $ilDB = $this->returnDB();
197
198 $query = 'SELECT * FROM ' . $activeRecord->getConnectorContainerName(
199 ) . ' ' . ' WHERE ' . arFieldCache::getPrimaryFieldName($activeRecord) . ' = '
200 . $ilDB->quote($activeRecord->getPrimaryFieldValue(), arFieldCache::getPrimaryFieldType($activeRecord));
201
202 $set = $ilDB->query($query);
203 $records = [];
204 while ($rec = $ilDB->fetchObject($set)) {
205 $records[] = $rec;
206 }
207
208 return $records;
209 }

References $ilDB, ActiveRecord\getConnectorContainerName(), arFieldCache\getPrimaryFieldName(), arFieldCache\getPrimaryFieldType(), ActiveRecord\getPrimaryFieldValue(), and returnDB().

+ Here is the call graph for this function:

◆ readSet()

arConnectorDB::readSet ( ActiveRecordList  $activeRecordList)
Returns
mixed[]

Reimplemented from arConnector.

Definition at line 243 of file class.arConnectorDB.php.

243 : array
244 {
245 $ilDB = $this->returnDB();
246 $set = $ilDB->query($this->buildQuery($activeRecordList));
247 $records = [];
248 while ($rec = $ilDB->fetchAssoc($set)) {
249 $records[] = $rec;
250 }
251
252 return $records;
253 }

References $ilDB, buildQuery(), and returnDB().

+ Here is the call graph for this function:

◆ removeField()

arConnectorDB::removeField ( ActiveRecord  $activeRecord,
string  $field_name 
)

Reimplemented from arConnector.

Definition at line 160 of file class.arConnectorDB.php.

160 : bool
161 {
162 $ilDB = $this->returnDB();
163 if (!$ilDB->tableColumnExists($activeRecord->getConnectorContainerName(), $field_name)) {
164 throw new arException($field_name, arException::COLUMN_DOES_NOT_EXIST);
165 }
166 $ilDB->dropTableColumn($activeRecord->getConnectorContainerName(), $field_name);
167 return true;
168 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const COLUMN_DOES_NOT_EXIST

References $ilDB, arException\COLUMN_DOES_NOT_EXIST, ActiveRecord\getConnectorContainerName(), and returnDB().

+ Here is the call graph for this function:

◆ renameField()

arConnectorDB::renameField ( ActiveRecord  $activeRecord,
string  $old_name,
string  $new_name 
)

Reimplemented from arConnector.

Definition at line 170 of file class.arConnectorDB.php.

170 : bool
171 {
172 $ilDB = $this->returnDB();
173 //throw new arException($old_name, arException::COLUMN_DOES_NOT_EXIST);
174 if (!$ilDB->tableColumnExists($activeRecord->getConnectorContainerName(), $old_name)) {
175 return true;
176 }
177 if ($ilDB->tableColumnExists($activeRecord->getConnectorContainerName(), $new_name)) {
178 return true;
179 }
180 //throw new arException($new_name, arException::COLUMN_DOES_ALREADY_EXIST);
181 $ilDB->renameTableColumn($activeRecord->getConnectorContainerName(), $old_name, $new_name);
182 return true;
183 }

References $ilDB, ActiveRecord\getConnectorContainerName(), and returnDB().

+ Here is the call graph for this function:

◆ resetDatabase()

arConnectorDB::resetDatabase ( ActiveRecord  $activeRecord)

Reimplemented from arConnector.

Definition at line 118 of file class.arConnectorDB.php.

118 : bool
119 {
120 $ilDB = $this->returnDB();
121 if ($ilDB->tableExists($activeRecord->getConnectorContainerName())) {
122 $ilDB->dropTable($activeRecord->getConnectorContainerName());
123 }
124 $activeRecord->installDB();
125
126 return true;
127 }

References $ilDB, ActiveRecord\getConnectorContainerName(), ActiveRecord\installDB(), and returnDB().

+ Here is the call graph for this function:

◆ returnDB()

arConnectorDB::returnDB ( )
protected

Definition at line 40 of file class.arConnectorDB.php.

41 {
42 if (is_null($this->db)) {
43 throw new arException("No DB-Connection available");
44 }
45 return $this->db;
46 }
ilDBInterface $db
Interface ilDBInterface.

References $db.

Referenced by affectedRows(), checkConnection(), checkFieldExists(), checkTableExists(), create(), delete(), installDatabase(), nextID(), quote(), read(), readSet(), removeField(), renameField(), resetDatabase(), truncateDatabase(), update(), updateDatabase(), and updateIndices().

+ Here is the caller graph for this function:

◆ truncateDatabase()

arConnectorDB::truncateDatabase ( ActiveRecord  $activeRecord)

Reimplemented from arConnector.

Definition at line 129 of file class.arConnectorDB.php.

129 : bool
130 {
131 $ilDB = $this->returnDB();
132 $query = 'TRUNCATE TABLE ' . $activeRecord->getConnectorContainerName();
133 $ilDB->query($query);
134 if ($ilDB->tableExists($activeRecord->getConnectorContainerName() . '_seq')) {
135 $ilDB->dropSequence($activeRecord->getConnectorContainerName());
136 $ilDB->createSequence($activeRecord->getConnectorContainerName());
137 }
138
139 return true;
140 }

References $ilDB, ActiveRecord\getConnectorContainerName(), and returnDB().

+ Here is the call graph for this function:

◆ update()

arConnectorDB::update ( ActiveRecord  $activeRecord)

Reimplemented from arConnector.

Definition at line 211 of file class.arConnectorDB.php.

211 : void
212 {
213 $ilDB = $this->returnDB();
214
215 $ilDB->update(
216 $activeRecord->getConnectorContainerName(),
217 $activeRecord->getArrayForConnector(),
218 [
219 arFieldCache::getPrimaryFieldName($activeRecord) => [
221 $activeRecord->getPrimaryFieldValue()
222 ]
223 ]
224 );
225 }

References $ilDB, ActiveRecord\getArrayForConnector(), ActiveRecord\getConnectorContainerName(), arFieldCache\getPrimaryFieldName(), arFieldCache\getPrimaryFieldType(), ActiveRecord\getPrimaryFieldValue(), and returnDB().

+ Here is the call graph for this function:

◆ updateDatabase()

arConnectorDB::updateDatabase ( ActiveRecord  $activeRecord)

Reimplemented from arConnector.

Definition at line 101 of file class.arConnectorDB.php.

101 : bool
102 {
103 $ilDB = $this->returnDB();
104 foreach ($activeRecord->getArFieldList()->getFields() as $arField) {
105 if (!$ilDB->tableColumnExists($activeRecord->getConnectorContainerName(), $arField->getName())) {
106 $ilDB->addTableColumn(
107 $activeRecord->getConnectorContainerName(),
108 $arField->getName(),
109 $arField->getAttributesForConnector()
110 );
111 }
112 }
113 $this->updateIndices($activeRecord);
114
115 return true;
116 }

References $ilDB, ActiveRecord\getArFieldList(), ActiveRecord\getConnectorContainerName(), returnDB(), and updateIndices().

+ Here is the call graph for this function:

◆ updateIndices()

arConnectorDB::updateIndices ( ActiveRecord  $activeRecord)

Reimplemented from arConnector.

Definition at line 81 of file class.arConnectorDB.php.

81 : void
82 {
83 $ilDB = $this->returnDB();
84 $arFieldList = $activeRecord->getArFieldList();
85 $existing_indices = $ilDB->loadModule('Manager')->listTableIndexes($activeRecord->getConnectorContainerName());
86
87 foreach ($arFieldList->getFields() as $i => $arField) {
88 if (!$arField->getIndex()) {
89 continue;
90 }
91 if (in_array($arField->getName(), $existing_indices)) {
92 continue;
93 }
94 if ($ilDB->indexExistsByFields($activeRecord->getConnectorContainerName(), [$arField->getName()])) {
95 continue;
96 }
97 $ilDB->addIndex($activeRecord->getConnectorContainerName(), [$arField->getName()], 'i' . $i);
98 }
99 }

References $ilDB, ActiveRecord\getArFieldList(), ActiveRecord\getConnectorContainerName(), and returnDB().

Referenced by installDatabase(), and updateDatabase().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilDBInterface arConnectorDB::$db = null
private

Definition at line 27 of file class.arConnectorDB.php.

Referenced by returnDB().


The documentation for this class was generated from the following file: