ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilADTMultiDBBridge.php
Go to the documentation of this file.
1<?php
2
3require_once "Services/ADT/classes/Bridges/class.ilADTDBBridge.php";
4
5abstract class ilADTMultiDBBridge extends ilADTDBBridge
6{
7 // CRUD
8
14 protected function getSubTableName()
15 {
16 return $this->getTable() . "_" . $this->getElementId();
17 }
18
19 public function readRecord(array $a_row)
20 {
21 global $DIC;
22
23 $ilDB = $DIC['ilDB'];
24
25 $sql = "SELECT " . $this->getElementId() .
26 " FROM " . $this->getSubTableName() .
27 " WHERE " . $this->buildPrimaryWhere();
28 $set = $ilDB->query($sql);
29
30 $this->readMultiRecord($set);
31 }
32
38 abstract protected function readMultiRecord($a_set);
39
40 public function prepareInsert(array &$a_fields)
41 {
42 // see afterUpdate()
43 }
44
45 public function afterInsert()
46 {
47 $this->afterUpdate();
48 }
49
50 public function afterUpdate()
51 {
52 global $DIC;
53
54 $ilDB = $DIC['ilDB'];
55
56 // :TODO: build diff, save difference
57
58 $ilDB->manipulate("DELETE FROM " . $this->getSubTableName() .
59 " WHERE " . $this->buildPrimaryWhere());
60
61 foreach ($this->prepareMultiInsert() as $sub_items) {
62 $fields = array_merge($this->getPrimary(), $sub_items);
63
64 $ilDB->insert($this->getSubTableName(), $fields);
65 }
66 }
67
73 abstract protected function prepareMultiInsert();
74
75 public function afterDelete()
76 {
77 global $DIC;
78
79 $ilDB = $DIC['ilDB'];
80
81 $ilDB->manipulate("DELETE FROM " . $this->getSubTableName() .
82 " WHERE " . $this->buildPrimaryWhere());
83 }
84}
An exception for terminatinating execution or to throw for unit testing.
ADT DB bridge base class.
getElementId()
Get element id.
getPrimary()
Get primary fields.
buildPrimaryWhere()
Convert primary keys array to sql string.
getTable()
Get table name.
afterInsert()
After insert hook to enable sub-tables.
readRecord(array $a_row)
Import DB values to ADT.
afterUpdate()
After update hook to enable sub-tables.
prepareInsert(array &$a_fields)
Prepare ADT values for insert.
getSubTableName()
Build sub-table name.
readMultiRecord($a_set)
Import record-rows from sub-table.
afterDelete()
After delete hook to enable sub-tables.
prepareMultiInsert()
Build insert-fields for each "value".
global $ilDB
$DIC
Definition: xapitoken.php:46