ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 {
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}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
registration for calendar appointments
getRegisteredUsers()
Get all registered users.
static deleteByUser($a_usr_id)
Delete all user registrations.
__construct($a_appointment_id)
Constructor.
unregister($a_usr_id, ilDateTime $start, ilDateTime $end)
unregister one user
isRegistered($a_usr_id, ilDateTime $start, ilDateTime $end)
Check if one user is registered.
@classDescription Date and time handling
get($a_format, $a_format_str='', $a_tz='')
get formatted date
$end
Definition: saml1-acs.php:18
$query
foreach($_POST as $key=> $value) $res
global $ilDB