ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilADTActiveRecord.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
14{
15 protected $properties; // [ilADTGroupDBBridge]
16
23 public function __construct(ilADTGroupDBBridge $a_properties)
24 {
25 $this->properties = $a_properties;
26 }
27
33 public function read()
34 {
35 global $DIC;
36
37 $ilDB = $DIC['ilDB'];
38
39 // reset all group elements
40 $this->properties->getADT()->reset();
41
42 $sql = "SELECT * FROM " . $this->properties->getTable() .
43 " WHERE " . $this->properties->buildPrimaryWhere();
44 $set = $ilDB->query($sql);
45 if ($ilDB->numRows($set)) {
46 $row = $ilDB->fetchAssoc($set);
47 $this->properties->readRecord($row);
48 return true;
49 }
50 return false;
51 }
52
56 public function create()
57 {
58 global $DIC;
59
60 $ilDB = $DIC['ilDB'];
61
62 $fields = $this->properties->getPrimary();
63 $this->properties->prepareInsert($fields);
64
65 $ilDB->insert($this->properties->getTable(), $fields);
66
67 // enables subtables
68 $this->properties->afterInsert();
69 }
70
74 public function update()
75 {
76 global $DIC;
77
78 $ilDB = $DIC['ilDB'];
79
80 $fields = array();
81 $this->properties->prepareUpdate($fields);
82
83 // does return affected rows, but will also return 0 for unchanged records
84 $ilDB->update($this->properties->getTable(), $fields, $this->properties->getPrimary());
85
86 // enables subtables
87 $this->properties->afterUpdate();
88 }
89
93 public function delete()
94 {
95 global $DIC;
96
97 $ilDB = $DIC['ilDB'];
98
99 $ilDB->manipulate("DELETE FROM " . $this->properties->getTable() .
100 " WHERE " . $this->properties->buildPrimaryWhere());
101
102 // enables subtables
103 $this->properties->afterDelete();
104 }
105}
An exception for terminatinating execution or to throw for unit testing.
ADT Active Record helper class.
__construct(ilADTGroupDBBridge $a_properties)
Constructor.
create()
Create/insert record.
global $DIC
Definition: goto.php:24
global $ilDB