ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilADTMultiDBBridge.php
Go to the documentation of this file.
1 <?php
2 
3 require_once "Services/ADT/classes/Bridges/class.ilADTDBBridge.php";
4 
5 abstract 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 }
prepareInsert(array &$a_fields)
buildPrimaryWhere()
Convert primary keys array to sql string.
getSubTableName()
Build sub-table name.
global $DIC
Definition: saml.php:7
getTable()
Get table name.
getPrimary()
Get primary fields.
getElementId()
Get element id.
ADT DB bridge base class.
prepareMultiInsert()
Build insert-fields for each "value".
global $ilDB
readMultiRecord($a_set)
Import record-rows from sub-table.