ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjectCustomUserFieldHistory.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
27 {
28  private int $obj_id = 0;
29  private int $user_id = 0;
30  private int $update_user = 0;
31  private ?ilDateTime $editing_time = null;
32  protected ilDBInterface $db;
33 
34  public function __construct(int $a_obj_id, int $a_user_id)
35  {
36  global $DIC;
37 
38  $this->db = $DIC->database();
39  $this->obj_id = $a_obj_id;
40  $this->user_id = $a_user_id;
41  $this->read();
42  }
43 
48  public static function lookupEntriesByObjectId(int $a_obj_id): array
49  {
50  global $DIC;
51 
52  $ilDB = $DIC['ilDB'];
53 
54  $query = 'SELECT * FROM obj_user_data_hist ' .
55  'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
56  $res = $ilDB->query($query);
57 
58  $users = array();
59  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
60  $users[(int) $row->usr_id]['update_user'] = (int) $row->update_user;
61  $users[(int) $row->usr_id]['editing_time'] = new ilDateTime($row->editing_time, IL_CAL_DATETIME, ilTimeZone::UTC);
62  }
63  return $users;
64  }
65 
66  public function setUpdateUser(int $a_id): void
67  {
68  $this->update_user = $a_id;
69  }
70 
71  public function getUpdateUser(): int
72  {
73  return $this->update_user;
74  }
75 
76  public function setEditingTime(ilDateTime $dt): void
77  {
78  $this->editing_time = $dt;
79  }
80 
81  public function getEditingTime(): ?\ilDateTime
82  {
83  return $this->editing_time;
84  }
85 
86  public function save(): void
87  {
88  $this->delete();
89  $query = 'INSERT INTO obj_user_data_hist (obj_id, usr_id, update_user, editing_time) ' .
90  'VALUES( ' .
91  $this->db->quote($this->obj_id, 'integer') . ', ' .
92  $this->db->quote($this->user_id, 'integer') . ', ' .
93  $this->db->quote($this->getUpdateUser(), 'integer') . ', ' .
94  $this->db->quote(
97  ) . ' ' .
98  ')';
99  $this->db->manipulate($query);
100  }
101 
102  public function delete(): void
103  {
104  $query = 'DELETE FROM obj_user_data_hist ' .
105  'WHERE obj_id = ' . $this->db->quote($this->obj_id, 'integer') . ' ' .
106  'AND usr_id = ' . $this->db->quote($this->user_id, 'integer');
107  $this->db->manipulate($query);
108  }
109 
110  protected function read(): void
111  {
112  $query = 'SELECT * FROM obj_user_data_hist ' .
113  'WHERE obj_id = ' . $this->db->quote($this->obj_id, 'integer') . ' ' .
114  'AND usr_id = ' . $this->db->quote($this->user_id, 'integer');
115  $res = $this->db->query($query);
116  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
117  $this->setEditingTime(new ilDateTime($row->editing_time, IL_CAL_DATETIME, ilTimeZone::UTC));
118  $this->setUpdateUser((int) $row->update_user);
119  }
120  }
121 }
$res
Definition: ltiservices.php:69
const IL_CAL_DATETIME
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
$query