ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCalendarRegistration.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
26{
27 private int $appointment_id = 0;
28 private array $registered = array();
29
30 protected ilDBInterface $db;
31
32 public function __construct(int $a_appointment_id)
33 {
34 global $DIC;
35
36 $this->appointment_id = $a_appointment_id;
37
38 $this->db = $DIC->database();
39 $this->read();
40 }
41
42 public static function deleteByUser(int $a_usr_id): void
43 {
44 global $DIC;
45
46 $ilDB = $DIC['ilDB'];
47 $query = "DELETE FROM cal_registrations " .
48 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer');
49 $ilDB->manipulate($query);
50 }
51
52 public static function deleteByAppointment(int $a_cal_id): void
53 {
54 global $DIC;
55
56 $ilDB = $DIC['ilDB'];
57 $query = "DELETE FROM cal_registrations " .
58 "WHERE cal_id = " . $ilDB->quote($a_cal_id, 'integer');
59 $ilDB->manipulate($query);
60 }
61
62 public function getAppointmentId(): int
63 {
65 }
66
67 public function getRegisteredUsers(\ilDateTime $start, \ilDateTime $end): array
68 {
69 $users = [];
70 foreach ($this->registered as $reg_data) {
71 if (
72 $reg_data['dstart'] == $start->get(IL_CAL_UNIX) &&
73 $reg_data['dend'] == $end->get(IL_CAL_UNIX)
74 ) {
75 $users[] = (int) $reg_data['usr_id'];
76 }
77 }
78 return $users;
79 }
80
81 public function isRegistered($a_usr_id, ilDateTime $start, ilDateTime $end): bool
82 {
83 foreach ($this->registered as $reg_data) {
84 if ($reg_data['usr_id'] == $a_usr_id) {
85 if ($reg_data['dstart'] == $start->get(IL_CAL_UNIX) and $reg_data['dend'] == $end->get(IL_CAL_UNIX)) {
86 return true;
87 }
88 }
89 }
90 return false;
91 }
92
93 public function register(int $a_usr_id, ilDateTime $start, ilDateTime $end): void
94 {
95 $this->unregister($a_usr_id, $start, $end);
96
97 $query = "INSERT INTO cal_registrations (cal_id,usr_id,dstart,dend) " .
98 "VALUES ( " .
99 $this->db->quote($this->getAppointmentId(), 'integer') . ", " .
100 $this->db->quote($a_usr_id, 'integer') . ", " .
101 $this->db->quote($start->get(IL_CAL_UNIX), 'integer') . ", " .
102 $this->db->quote($end->get(IL_CAL_UNIX), 'integer') .
103 ")";
104 $this->db->manipulate($query);
105 $this->registered[] = [
106 'usr_id' => $a_usr_id,
107 'dstart' => $start->get(IL_CAL_UNIX),
108 'dend' => $end->get(IL_CAL_UNIX)
109 ];
110 }
111
115 public function unregister(int $a_usr_id, ilDateTime $start, ilDateTime $end): void
116 {
117 $query = "DELETE FROM cal_registrations " .
118 "WHERE cal_id = " . $this->db->quote($this->getAppointmentId(), 'integer') . ' ' .
119 "AND usr_id = " . $this->db->quote($a_usr_id, 'integer') . ' ' .
120 "AND dstart = " . $this->db->quote($start->get(IL_CAL_UNIX), 'integer') . ' ' .
121 "AND dend = " . $this->db->quote($end->get(IL_CAL_UNIX), 'integer');
122 $res = $this->db->manipulate($query);
123 }
124
128 protected function read(): void
129 {
130 if (!$this->getAppointmentId()) {
131 return;
132 }
133
134 $query = "SELECT * FROM cal_registrations WHERE cal_id = " . $this->db->quote(
135 $this->getAppointmentId(),
136 'integer'
137 );
138 $res = $this->db->query($query);
139 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
140 $this->registered[] = array(
141 'usr_id' => (int) $row->usr_id,
142 'dstart' => (int) $row->dstart,
143 'dend' => (int) $row->dend
144 );
145 }
146 }
147}
const IL_CAL_UNIX
registration for calendar appointments
unregister(int $a_usr_id, ilDateTime $start, ilDateTime $end)
unregister one user
getRegisteredUsers(\ilDateTime $start, \ilDateTime $end)
static deleteByAppointment(int $a_cal_id)
__construct(int $a_appointment_id)
isRegistered($a_usr_id, ilDateTime $start, ilDateTime $end)
@classDescription Date and time handling
get(int $a_format, string $a_format_str='', string $a_tz='')
get formatted date
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26