ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilObjectCustomUserFieldHistory.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 {
13  private $obj_id = 0;
14  private $user_id = 0;
15  private $update_user = 0;
16  private $editing_time = null;
17 
23  public function __construct($a_obj_id, $a_user_id)
24  {
25  $this->obj_id = $a_obj_id;
26  $this->user_id = $a_user_id;
27  $this->read();
28  }
29 
36  public static function lookupEntriesByObjectId($a_obj_id)
37  {
38  global $DIC;
39 
40  $ilDB = $DIC['ilDB'];
41 
42  $query = 'SELECT * FROM obj_user_data_hist ' .
43  'WHERE obj_id = ' . $ilDB->quote($a_obj_id, 'integer');
44  $res = $ilDB->query($query);
45 
46  $users = array();
47  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
48  $users[$row->usr_id]['update_user'] = $row->update_user;
49  $users[$row->usr_id]['editing_time'] = new ilDateTime($row->editing_time, IL_CAL_DATETIME, ilTimeZone::UTC);
50  }
51  return $users;
52  }
53 
58  public function setUpdateUser($a_id)
59  {
60  $this->update_user = $a_id;
61  }
62 
67  public function getUpdateUser()
68  {
69  return $this->update_user;
70  }
71 
76  public function setEditingTime(ilDateTime $dt)
77  {
78  $this->editing_time = $dt;
79  }
80 
85  public function getEditingTime()
86  {
87  return $this->editing_time;
88  }
89 
93  public function save()
94  {
95  global $DIC;
96 
97  $ilDB = $DIC['ilDB'];
98 
99  $this->delete();
100 
101  $query = 'INSERT INTO obj_user_data_hist (obj_id, usr_id, update_user, editing_time) ' .
102  'VALUES( ' .
103  $ilDB->quote($this->obj_id, 'integer') . ', ' .
104  $ilDB->quote($this->user_id, 'integer') . ', ' .
105  $ilDB->quote($this->getUpdateUser(), 'integer') . ', ' .
106  $ilDB->quote($this->getEditingTime()->get(IL_CAL_DATETIME, '', ilTimeZone::UTC)) . ' ' .
107  ')';
108  $ilDB->manipulate($query);
109  }
110 
114  public function delete()
115  {
116  global $DIC;
117 
118  $ilDB = $DIC['ilDB'];
119 
120  $query = 'DELETE FROM obj_user_data_hist ' .
121  'WHERE obj_id = ' . $ilDB->quote($this->obj_id, 'integer') . ' ' .
122  'AND usr_id = ' . $ilDB->quote($this->user_id, 'integer');
123  $ilDB->manipulate($query);
124  }
125 
130  protected function read()
131  {
132  global $DIC;
133 
134  $ilDB = $DIC['ilDB'];
135 
136  $query = 'SELECT * FROM obj_user_data_hist ' .
137  'WHERE obj_id = ' . $ilDB->quote($this->obj_id, 'integer') . ' ' .
138  'AND usr_id = ' . $ilDB->quote($this->user_id, 'integer');
139  $res = $ilDB->query($query);
140  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
141  $this->setEditingTime(new ilDateTime($row->editing_time, IL_CAL_DATETIME, ilTimeZone::UTC));
142  $this->setUpdateUser($row->update_user);
143  }
144  }
145 }
const IL_CAL_DATETIME
global $DIC
Definition: saml.php:7
Editing history for object custom user fields.
setEditingTime(ilDateTime $dt)
Set editing time.
__construct($a_obj_id, $a_user_id)
Constructor.
foreach($_POST as $key=> $value) $res
Date and time handling
$query
$users
Definition: authpage.php:44
$row
global $ilDB
static lookupEntriesByObjectId($a_obj_id)
Get entries by obj_id type $ilDB.