ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
All Data Structures Namespaces Files Functions Variables Typedefs Modules Pages
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 $ilDB;
38 
39  $query = "DELETE FROM cal_registrations " .
40  "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer');
41  $ilDB->manipulate($query);
42  }
43 
44  public static function deleteByAppointment($a_cal_id)
45  {
46  global $ilDB;
47 
48  $query = "DELETE FROM cal_registrations " .
49  "WHERE cal_id = " . $ilDB->quote($a_cal_id, 'integer');
50  $ilDB->manipulate($query);
51  }
52 
57  public function getAppointmentId()
58  {
59  return $this->appointment_id;
60  }
61 
66  public function getRegisteredUsers()
67  {
68  foreach ($this->registered as $reg_data) {
69  if ($reg_data['usr_id'] == $a_usr_id) {
70  if ($reg_data['dstart'] == $start->get(IL_CAL_UNIX) and $reg_data['dend'] == $end->get(IL_CAL_UNIX)) {
71  return true;
72  }
73  }
74  }
75  return (array) $this->registered;
76  }
77 
83  public function isRegistered($a_usr_id, ilDateTime $start, ilDateTime $end)
84  {
85  foreach ($this->registered as $reg_data) {
86  if ($reg_data['usr_id'] == $a_usr_id) {
87  if ($reg_data['dstart'] == $start->get(IL_CAL_UNIX) and $reg_data['dend'] == $end->get(IL_CAL_UNIX)) {
88  return true;
89  }
90  }
91  }
92  }
93 
99  public function register($a_usr_id, ilDateTime $start, ilDateTime $end)
100  {
101  global $ilDB;
102 
103  $this->unregister($a_usr_id, $start, $end);
104 
105  $query = "INSERT INTO cal_registrations (cal_id,usr_id,dstart,dend) " .
106  "VALUES ( " .
107  $ilDB->quote($this->getAppointmentId(), 'integer') . ", " .
108  $ilDB->quote($a_usr_id, 'integer') . ", " .
109  $ilDB->quote($start->get(IL_CAL_UNIX), 'integer') . ", " .
110  $ilDB->quote($end->get(IL_CAL_UNIX), 'integer') .
111  ")";
112  $ilDB->manipulate($query);
113 
114  $this->registered[] = $a_usr_id;
115  return true;
116  }
117 
123  public function unregister($a_usr_id, ilDateTime $start, ilDateTime $end)
124  {
125  global $ilDB;
126 
127  $query = "DELETE FROM cal_registrations " .
128  "WHERE cal_id = " . $ilDB->quote($this->getAppointmentId(), 'integer') . ' ' .
129  "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . ' ' .
130  "AND dstart = " . $ilDB->quote($start->get(IL_CAL_UNIX), 'integer') . ' ' .
131  "AND dend = " . $ilDB->quote($end->get(IL_CAL_UNIX), 'integer');
132  $res = $ilDB->manipulate($query);
133  }
134 
135 
140  protected function read()
141  {
142  global $ilDB;
143 
144  if (!$this->getAppointmentId()) {
145  return false;
146  }
147 
148  $query = "SELECT * FROM cal_registrations WHERE cal_id = " . $ilDB->quote($this->getAppointmentId(), 'integer');
149  $res = $ilDB->query($query);
150  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
151  $this->registered[] = array(
152  'usr_id'=> $row->usr_id,
153  'dstart' =>$row->dstart,
154  'dend' => $row->dend
155  );
156  }
157  }
158 }
$end
Definition: saml1-acs.php:18
const IL_CAL_UNIX
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
Create styles array
The data for the language used.
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()
Get all registered users.
static deleteByUser($a_usr_id)
Delete all user registrations.