ILIAS  release_8 Revision v8.23
class.ilADTActiveRecord.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
5 
13 {
15 
16  protected ilDBInterface $db;
17 
22  public function __construct(ilADTGroupDBBridge $a_properties)
23  {
24  global $DIC;
25 
26  $this->db = $DIC->database();
27  $this->properties = $a_properties;
28  }
29 
34  public function read(): bool
35  {
36  // reset all group elements
37  $this->properties->getADT()->reset();
38 
39  $sql = "SELECT * FROM " . $this->properties->getTable() .
40  " WHERE " . $this->properties->buildPrimaryWhere();
41  $set = $this->db->query($sql);
42  if ($this->db->numRows($set)) {
43  $row = $this->db->fetchAssoc($set);
44  $this->properties->readRecord($row);
45  return true;
46  }
47  return false;
48  }
49 
50  public function create(): void
51  {
52  $fields = $this->properties->getPrimary();
53  $this->properties->prepareInsert($fields);
54  $this->db->insert($this->properties->getTable(), $fields);
55  $this->properties->afterInsert();
56  }
57 
58  public function update(): void
59  {
60  $fields = array();
61  $this->properties->prepareUpdate($fields);
62  $this->db->update($this->properties->getTable(), $fields, $this->properties->getPrimary());
63  $this->properties->afterUpdate();
64  }
65 
66  public function delete(): void
67  {
68  $this->db->manipulate("DELETE FROM " . $this->properties->getTable() .
69  " WHERE " . $this->properties->buildPrimaryWhere());
70  $this->properties->afterDelete();
71  }
72 }
ilADTGroupDBBridge $properties
global $DIC
Definition: feed.php:28
ADT Active Record helper class This class expects a valid primary for all actions! ...
__construct(ilADTGroupDBBridge $a_properties)
Constructor.