ILIAS  release_8 Revision v8.24
class.ilCalendarSharedStatus.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4/*
5 +-----------------------------------------------------------------------------+
6 | ILIAS open source |
7 +-----------------------------------------------------------------------------+
8 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
9 | |
10 | This program is free software; you can redistribute it and/or |
11 | modify it under the terms of the GNU General Public License |
12 | as published by the Free Software Foundation; either version 2 |
13 | of the License, or (at your option) any later version. |
14 | |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | GNU General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU General Public License |
21 | along with this program; if not, write to the Free Software |
22 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
23 +-----------------------------------------------------------------------------+
24*/
25
32{
33 public const STATUS_ACCEPTED = 1;
34 public const STATUS_DECLINED = 2;
35 public const STATUS_DELETED = 3;
36
37 protected ?ilDBInterface $db;
38
39 private int $usr_id = 0;
40
41 private array $calendars = array();
42 private array $writable = array();
43
44 public function __construct(int $a_usr_id)
45 {
46 global $DIC;
47 $this->usr_id = $a_usr_id;
48 $this->db = $DIC->database();
49 $this->read();
50 }
51
52 public function isAccepted(int $a_cal_id): bool
53 {
54 return
55 isset($this->calendars[$a_cal_id]) &&
56 $this->calendars[$a_cal_id] == self::STATUS_ACCEPTED;
57 }
58
59 public function isDeclined(int $a_cal_id): bool
60 {
61 return
62 isset($this->calendars[$a_cal_id]) &&
63 $this->calendars[$a_cal_id] == self::STATUS_DECLINED;
64 }
65
66 public static function getAcceptedCalendars(int $a_usr_id): array
67 {
68 global $DIC;
69
70 $ilDB = $DIC['ilDB'];
71 $query = "SELECT cal_id FROM cal_shared_status " .
72 "WHERE status = " . $ilDB->quote(self::STATUS_ACCEPTED, 'integer') . " " .
73 "AND usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
74 $res = $ilDB->query($query);
75 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
76 $cal_ids[] = $row->cal_id;
77 }
78 return $cal_ids ?? [];
79 }
80
81 public static function hasStatus(int $a_usr_id, int $a_calendar_id): bool
82 {
83 global $DIC;
84
85 $ilDB = $DIC['ilDB'];
86 $query = "SELECT * FROM cal_shared_status " .
87 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " " .
88 "AND cal_id = " . $ilDB->quote($a_calendar_id, 'integer') . " ";
89 $res = $ilDB->query($query);
90 return (bool) $res->numRows();
91 }
92
93 public static function deleteUser(int $a_usr_id): void
94 {
95 global $DIC;
96
97 $ilDB = $DIC['ilDB'];
98 $query = "DELETE FROM cal_shared_status " .
99 "WHERE usr_id = " . $ilDB->quote($a_usr_id, 'integer') . " ";
100 $res = $ilDB->manipulate($query);
101 }
102
103 public static function deleteCalendar(int $a_calendar_id): void
104 {
105 global $DIC;
106
107 $ilDB = $DIC['ilDB'];
108 $query = "DELETE FROM cal_shared_status " .
109 "WHERE cal_id = " . $ilDB->quote($a_calendar_id, 'integer') . " ";
110 $res = $ilDB->manipulate($query);
111 }
112
113 public static function deleteStatus(int $a_id, int $a_calendar_id): void
114 {
115 global $DIC;
116
117 $ilDB = $DIC['ilDB'];
118 $rbacreview = $DIC['rbacreview'];
119
120 if (ilObject::_lookupType($a_id) == 'usr') {
121 $query = "DELETE FROM cal_shared_status " .
122 "WHERE cal_id = " . $ilDB->quote($a_calendar_id, 'integer') . " " .
123 "AND usr_id = " . $ilDB->quote($a_id, 'integer') . " ";
124 $res = $ilDB->manipulate($query);
125 } elseif (ilObject::_lookupType($a_id) == 'role') {
126 $assigned_users = $rbacreview->assignedUsers($a_id);
127
128 if (!count($assigned_users)) {
129 return;
130 }
131
132 $query = "DELETE FROM cal_shared_status " .
133 "WHERE cal_id = " . $ilDB->quote($a_calendar_id, 'integer') . " " .
134 "AND " . $ilDB->in('usr_id', $assigned_users, false, 'integer');
135 $res = $ilDB->manipulate($query);
136 }
137 }
138
139 public function accept(int $a_calendar_id): void
140 {
141 self::deleteStatus($this->usr_id, $a_calendar_id);
142 $query = "INSERT INTO cal_shared_status (cal_id,usr_id,status) " .
143 "VALUES ( " .
144 $this->db->quote($a_calendar_id, 'integer') . ", " .
145 $this->db->quote($this->usr_id, 'integer') . ", " .
146 $this->db->quote(self::STATUS_ACCEPTED, 'integer') . " " .
147 ")";
148 $res = $this->db->manipulate($query);
149
150 $this->calendars[$a_calendar_id] = self::STATUS_ACCEPTED;
151 }
152
153 public function decline(int $a_calendar_id): void
154 {
155 self::deleteStatus($this->usr_id, $a_calendar_id);
156 $query = "INSERT INTO cal_shared_status (cal_id,usr_id,status) " .
157 "VALUES ( " .
158 $this->db->quote($a_calendar_id, 'integer') . ", " .
159 $this->db->quote($this->usr_id, 'integer') . ", " .
160 $this->db->quote(self::STATUS_DECLINED, 'integer') . " " .
161 ")";
162 $res = $this->db->manipulate($query);
163 $this->calendars[$a_calendar_id] = self::STATUS_DECLINED;
164 }
165
166 protected function read()
167 {
168 $query = "SELECT * FROM cal_shared_status " .
169 "WHERE usr_id = " . $this->db->quote($this->usr_id, 'integer') . " ";
170 $res = $this->db->query($query);
171 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
172 $this->calendars[(int) $row->cal_id] = (int) $row->status;
173 }
174 }
175
176 public function getOpenInvitations(): array
177 {
178 $shared = ilCalendarShared::getSharedCalendarsForUser($this->usr_id);
179
180 $invitations = array();
181 foreach ($shared as $data) {
182 if ($this->isDeclined($data['cal_id']) || $this->isAccepted($data['cal_id'])) {
183 continue;
184 }
185
186 $tmp_calendar = new ilCalendarCategory($data['cal_id']);
187
188 $invitations[] = array(
189 'cal_id' => (int) $data['cal_id'],
190 'create_date' => $data['create_date'],
191 'obj_type' => $data['obj_type'],
192 'name' => $tmp_calendar->getTitle(),
193 'owner' => $tmp_calendar->getObjId(),
194 'apps' => count(ilCalendarCategoryAssignments::_getAssignedAppointments(array((int) $data['cal_id']))),
195 'accepted' => $this->isAccepted((int) $data['cal_id']),
196 'declined' => $this->isDeclined((int) $data['cal_id'])
197 );
198 }
199 return $invitations;
200 }
201}
static _getAssignedAppointments(array $a_cat_id)
Get assigned apointments.
Stores calendar categories.
Stores status (accepted/declined) of shared calendars.
static getAcceptedCalendars(int $a_usr_id)
static deleteCalendar(int $a_calendar_id)
static deleteStatus(int $a_id, int $a_calendar_id)
static hasStatus(int $a_usr_id, int $a_calendar_id)
static getSharedCalendarsForUser(int $a_usr_id=0)
static _lookupType(int $id, bool $reference=false)
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$query