ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTActiveRecord.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
27{
29
30 protected ilDBInterface $db;
31
36 public function __construct(ilADTGroupDBBridge $a_properties)
37 {
38 global $DIC;
39
40 $this->db = $DIC->database();
41 $this->properties = $a_properties;
42 }
43
48 public function read(): bool
49 {
50 // reset all group elements
51 $this->properties->getADT()->reset();
52
53 $sql = "SELECT * FROM " . $this->properties->getTable() .
54 " WHERE " . $this->properties->buildPrimaryWhere();
55 $set = $this->db->query($sql);
56 if ($this->db->numRows($set)) {
57 $row = $this->db->fetchAssoc($set);
58 $this->properties->readRecord($row);
59 return true;
60 }
61 return false;
62 }
63
64 public function create(): void
65 {
66 $fields = $this->properties->getPrimary();
67 $this->properties->prepareInsert($fields);
68 $this->db->insert($this->properties->getTable(), $fields);
69 $this->properties->afterInsert();
70 }
71
72 public function update(): void
73 {
74 $fields = array();
75 $this->properties->prepareUpdate($fields);
76 $this->db->update($this->properties->getTable(), $fields, $this->properties->getPrimary());
77 $this->properties->afterUpdate();
78 }
79
80 public function delete(): void
81 {
82 $this->db->manipulate("DELETE FROM " . $this->properties->getTable() .
83 " WHERE " . $this->properties->buildPrimaryWhere());
84 $this->properties->afterDelete();
85 }
86}
ADT Active Record helper class This class expects a valid primary for all actions!
__construct(ilADTGroupDBBridge $a_properties)
Constructor.
ilADTGroupDBBridge $properties
Interface ilDBInterface.
global $DIC
Definition: shib_login.php:26