ILIAS  release_8 Revision v8.24
class.ilCalendarRegistration.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
5
12{
13 private int $appointment_id = 0;
14 private array $registered = array();
15
16 protected ilDBInterface $db;
17
18 public function __construct(int $a_appointment_id)
19 {
20 global $DIC;
21
22 $this->appointment_id = $a_appointment_id;
23
24 $this->db = $DIC->database();
25 $this->read();
26 }
27
28 public static function deleteByUser(int $a_usr_id): void
29 {
30 global $DIC;
31
32 $ilDB = $DIC['ilDB'];
33 $query = "DELETE FROM cal_registrations " .
34 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer');
35 $ilDB->manipulate($query);
36 }
37
38 public static function deleteByAppointment(int $a_cal_id): void
39 {
40 global $DIC;
41
42 $ilDB = $DIC['ilDB'];
43 $query = "DELETE FROM cal_registrations " .
44 "WHERE cal_id = " . $ilDB->quote($a_cal_id, 'integer');
45 $ilDB->manipulate($query);
46 }
47
48 public function getAppointmentId(): int
49 {
51 }
52
53 public function getRegisteredUsers(\ilDateTime $start, \ilDateTime $end): array
54 {
55 $users = [];
56 foreach ($this->registered as $reg_data) {
57 if (
58 $reg_data['dstart'] == $start->get(IL_CAL_UNIX) &&
59 $reg_data['dend'] == $end->get(IL_CAL_UNIX)
60 ) {
61 $users[] = (int) $reg_data['usr_id'];
62 }
63 }
64 return $users;
65 }
66
67 public function isRegistered($a_usr_id, ilDateTime $start, ilDateTime $end): bool
68 {
69 foreach ($this->registered as $reg_data) {
70 if ($reg_data['usr_id'] == $a_usr_id) {
71 if ($reg_data['dstart'] == $start->get(IL_CAL_UNIX) and $reg_data['dend'] == $end->get(IL_CAL_UNIX)) {
72 return true;
73 }
74 }
75 }
76 return false;
77 }
78
79 public function register(int $a_usr_id, ilDateTime $start, ilDateTime $end): void
80 {
81 $this->unregister($a_usr_id, $start, $end);
82
83 $query = "INSERT INTO cal_registrations (cal_id,usr_id,dstart,dend) " .
84 "VALUES ( " .
85 $this->db->quote($this->getAppointmentId(), 'integer') . ", " .
86 $this->db->quote($a_usr_id, 'integer') . ", " .
87 $this->db->quote($start->get(IL_CAL_UNIX), 'integer') . ", " .
88 $this->db->quote($end->get(IL_CAL_UNIX), 'integer') .
89 ")";
90 $this->db->manipulate($query);
91 $this->registered[] = [
92 'usr_id' => $a_usr_id,
93 'dstart' => $start->get(IL_CAL_UNIX),
94 'dend' => $end->get(IL_CAL_UNIX)
95 ];
96 }
97
101 public function unregister(int $a_usr_id, ilDateTime $start, ilDateTime $end): void
102 {
103 $query = "DELETE FROM cal_registrations " .
104 "WHERE cal_id = " . $this->db->quote($this->getAppointmentId(), 'integer') . ' ' .
105 "AND usr_id = " . $this->db->quote($a_usr_id, 'integer') . ' ' .
106 "AND dstart = " . $this->db->quote($start->get(IL_CAL_UNIX), 'integer') . ' ' .
107 "AND dend = " . $this->db->quote($end->get(IL_CAL_UNIX), 'integer');
108 $res = $this->db->manipulate($query);
109 }
110
114 protected function read(): void
115 {
116 if (!$this->getAppointmentId()) {
117 return;
118 }
119
120 $query = "SELECT * FROM cal_registrations WHERE cal_id = " . $this->db->quote(
121 $this->getAppointmentId(),
122 'integer'
123 );
124 $res = $this->db->query($query);
125 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
126 $this->registered[] = array(
127 'usr_id' => (int) $row->usr_id,
128 'dstart' => (int) $row->dstart,
129 'dend' => (int) $row->dend
130 );
131 }
132 }
133}
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
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$query