ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjectCustomUserFieldHistory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
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 {
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(
95 $this->getEditingTime()->get(IL_CAL_DATETIME, '', ilTimeZone::UTC),
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}
const IL_CAL_DATETIME
@classDescription Date and time handling
Editing history for object custom user fields.
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26