ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCalendarRegistration.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
14 {
15  private $appointment_id = 0;
16 
17  private $registered = array();
18 
23  public function __construct($a_appointment_id)
24  {
25  $this->appointment_id = $a_appointment_id;
26 
27  $this->read();
28  }
29 
35  public static function deleteByUser($a_usr_id)
36  {
37  global $DIC;
38 
39  $ilDB = $DIC['ilDB'];
40 
41  $query = "DELETE FROM cal_registrations " .
42  "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer');
43  $ilDB->manipulate($query);
44  }
45 
46  public static function deleteByAppointment($a_cal_id)
47  {
48  global $DIC;
49 
50  $ilDB = $DIC['ilDB'];
51 
52  $query = "DELETE FROM cal_registrations " .
53  "WHERE cal_id = " . $ilDB->quote($a_cal_id, 'integer');
54  $ilDB->manipulate($query);
55  }
56 
61  public function getAppointmentId()
62  {
63  return $this->appointment_id;
64  }
65 
71  {
72  $users = [];
73  foreach ($this->registered as $reg_data) {
74  if (
75  $reg_data['dstart'] == $start->get(IL_CAL_UNIX) &&
76  $reg_data['dend'] == $end->get(IL_CAL_UNIX)
77  ) {
78  $users[] = $reg_data['usr_id'];
79  }
80  }
81  return $users;
82  }
83 
89  public function isRegistered($a_usr_id, ilDateTime $start, ilDateTime $end)
90  {
91  foreach ($this->registered as $reg_data) {
92  if ($reg_data['usr_id'] == $a_usr_id) {
93  if ($reg_data['dstart'] == $start->get(IL_CAL_UNIX) and $reg_data['dend'] == $end->get(IL_CAL_UNIX)) {
94  return true;
95  }
96  }
97  }
98  }
99 
105  public function register($a_usr_id, ilDateTime $start, ilDateTime $end)
106  {
107  global $DIC;
108 
109  $ilDB = $DIC['ilDB'];
110 
111  $this->unregister($a_usr_id, $start, $end);
112 
113  $query = "INSERT INTO cal_registrations (cal_id,usr_id,dstart,dend) " .
114  "VALUES ( " .
115  $ilDB->quote($this->getAppointmentId(), 'integer') . ", " .
116  $ilDB->quote($a_usr_id, 'integer') . ", " .
117  $ilDB->quote($start->get(IL_CAL_UNIX), 'integer') . ", " .
118  $ilDB->quote($end->get(IL_CAL_UNIX), 'integer') .
119  ")";
120  $ilDB->manipulate($query);
121 
122  $this->registered[] = $a_usr_id;
123  return true;
124  }
125 
131  public function unregister($a_usr_id, ilDateTime $start, ilDateTime $end)
132  {
133  global $DIC;
134 
135  $ilDB = $DIC['ilDB'];
136 
137  $query = "DELETE FROM cal_registrations " .
138  "WHERE cal_id = " . $ilDB->quote($this->getAppointmentId(), 'integer') . ' ' .
139  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . ' ' .
140  "AND dstart = " . $ilDB->quote($start->get(IL_CAL_UNIX), 'integer') . ' ' .
141  "AND dend = " . $ilDB->quote($end->get(IL_CAL_UNIX), 'integer');
142  $res = $ilDB->manipulate($query);
143  }
144 
145 
150  protected function read()
151  {
152  global $DIC;
153 
154  $ilDB = $DIC['ilDB'];
155 
156  if (!$this->getAppointmentId()) {
157  return false;
158  }
159 
160  $query = "SELECT * FROM cal_registrations WHERE cal_id = " . $ilDB->quote($this->getAppointmentId(), 'integer');
161  $res = $ilDB->query($query);
162  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
163  $this->registered[] = array(
164  'usr_id' => $row->usr_id,
165  'dstart' => $row->dstart,
166  'dend' => $row->dend
167  );
168  }
169  }
170 }
global $DIC
Definition: saml.php:7
const IL_CAL_UNIX
$start
Definition: bench.php:8
getAppointmentId()
Get appoinmtent id.
foreach($_POST as $key=> $value) $res
registration for calendar appointments
Date and time handling
$query
get($a_format, $a_format_str='', $a_tz='')
get formatted date
$users
Definition: authpage.php:44
$row
isRegistered($a_usr_id, ilDateTime $start, ilDateTime $end)
Check if one user is registered.
unregister($a_usr_id, ilDateTime $start, ilDateTime $end)
unregister one user
global $ilDB
__construct($a_appointment_id)
Constructor.
getRegisteredUsers(\ilDateTime $start, \ilDateTime $end)
Get all registered users.
static deleteByUser($a_usr_id)
Delete all user registrations.