ILIAS  release_8 Revision v8.24
class.ilBookingParticipant.php
Go to the documentation of this file.
1<?php
2
23{
24 protected ilLanguage $lng;
25 protected ilDBInterface $db;
26 protected int $participant_id;
27 protected int $booking_pool_id;
28 protected bool $is_new;
29 protected ilObjUser $user;
30
31 public function __construct(
32 int $a_user_id,
33 int $a_booking_pool_id
34 ) {
35 global $DIC;
36
37 if (!ilObjUser::_exists($a_user_id)) {
38 throw new ilException("User $a_user_id does not exist.");
39 }
40 if (!ilObjBookingPool::_exists($a_booking_pool_id)) {
41 throw new ilException("Booking Pool $a_booking_pool_id does not exist.");
42 }
43
44 $this->lng = $DIC->language();
45 $this->db = $DIC->database();
46 $this->user = $DIC->user();
47
48 $this->participant_id = $a_user_id;
49 $this->booking_pool_id = $a_booking_pool_id;
50
51 // if read and not exists, store it in db.
52 if (!$this->read()) {
53 $this->save();
54 $this->is_new = true;
55 } else {
56 $this->is_new = false;
57 }
58 }
59
60 protected function read(): ?int
61 {
62 $query = 'SELECT participant_id FROM booking_member' .
63 ' WHERE user_id = ' . $this->db->quote($this->participant_id, 'integer') .
64 ' AND booking_pool_id = ' . $this->db->quote($this->booking_pool_id, 'integer');
65
66 $set = $this->db->query($query);
67 $row = $this->db->fetchAssoc($set);
68 if (empty($row)) {
69 return null;
70 }
71 return (int) $row['participant_id'];
72 }
73
74 protected function save(): void
75 {
76 $assigner_id = $this->user->getId();
77 $next_id = $this->db->nextId('booking_member');
78
79 $query = 'INSERT INTO booking_member' .
80 ' (participant_id, user_id, booking_pool_id, assigner_user_id)' .
81 ' VALUES (' . $this->db->quote($next_id, 'integer') .
82 ',' . $this->db->quote($this->participant_id, 'integer') .
83 ',' . $this->db->quote($this->booking_pool_id, 'integer') .
84 ',' . $this->db->quote($assigner_id, 'integer') . ')';
85
86 $this->db->manipulate($query);
87 }
88
89 public function getIsNew(): bool
90 {
91 return $this->is_new;
92 }
93
99 public static function getAssignableParticipants(
100 int $a_bp_object_id
101 ): array {
102 $booking_object = new ilBookingObject($a_bp_object_id);
103 $pool_id = $booking_object->getPoolId();
104 $pool = new ilObjBookingPool($pool_id, false);
105 $overall_limit = (int) $pool->getOverallLimit();
106
107 $res = array();
108
109 $members = ilBookingReservation::getMembersWithoutReservation($a_bp_object_id);
110
111 foreach ($members as $member_id) {
112 //check if the user reached the limit of booking in this booking pool.
113 $total_reservations = ilBookingReservation::isBookingPoolLimitReachedByUser($member_id, $pool_id);
114
115 if ($overall_limit === 0 || ($overall_limit > 0 && $total_reservations < $overall_limit)) {
116 $user_name = ilObjUser::_lookupName($member_id);
117 $name = $user_name['lastname'] . ", " . $user_name['firstname'];
118 $index = $a_bp_object_id . "_" . $member_id;
119
120 if (!isset($res[$index])) {
121 $res[$index] = array(
122 "user_id" => $member_id,
123 "object_title" => array($booking_object->getTitle()),
124 "name" => $name
125 );
126 } elseif (!in_array($booking_object->getTitle(), $res[$index]['object_title'], true)) {
127 $res[$index]['object_title'][] = $booking_object->getTitle();
128 }
129 }
130 }
131
132 return $res;
133 }
134
135 public static function getList(
136 int $a_booking_pool,
137 array $a_filter = null,
138 int $a_object_id = null
139 ): array {
140 global $DIC;
141
142 $ilDB = $DIC->database();
143
144 $res = array();
145
146 $query = 'SELECT bm.user_id, bm.booking_pool_id, br.object_id, bo.title, br.status' .
147 ' FROM booking_member bm' .
148 ' LEFT JOIN booking_reservation br ON (bm.user_id = br.user_id)' .
149 ' LEFT JOIN booking_object bo ON (br.object_id = bo.booking_object_id AND bo.pool_id = ' . $ilDB->quote($a_booking_pool, 'integer') . ')';
150
151 $where = array('bm.booking_pool_id =' . $ilDB->quote($a_booking_pool, 'integer'));
152 if ($a_object_id) {
153 $where[] = 'br.object_id = ' . $ilDB->quote($a_object_id, 'integer');
154 }
155 if ($a_filter['title'] ?? false) {
156 $where[] = '(' . $ilDB->like('title', 'text', '%' . $a_filter['title'] . '%') .
157 ' OR ' . $ilDB->like('description', 'text', '%' . $a_filter['title'] . '%') . ')';
158 }
159 if ($a_filter['user_id'] ?? false) {
160 $where[] = 'bm.user_id = ' . $ilDB->quote($a_filter['user_id'], 'integer');
161 }
162
163 $query .= ' WHERE ' . implode(' AND ', $where);
164
165 $set = $ilDB->query($query);
166
167 while ($row = $ilDB->fetchAssoc($set)) {
168 $status = $row['status'];
169 //Nothing to show if the status is canceled when filtering by object
170 if ($status == ilBookingReservation::STATUS_CANCELLED && $a_object_id) {
171 continue;
172 }
173
174 $user_name = ilObjUser::_lookupName($row['user_id']);
175 $name = $user_name['lastname'] . ", " . $user_name['firstname'];
176 $index = $a_booking_pool . "_" . $row['user_id'];
177 $actions = array();
178
179 if (!isset($res[$index])) {
180 $res[$index] = array(
181 "object_title" => array(),
182 "name" => $name
183 );
184
185 if ($status != ilBookingReservation::STATUS_CANCELLED && $row['title'] !== "") {
186 $res[$index]['object_title'] = array($row['title']);
187 $res[$index]['obj_count'] = 1;
188 $res[$index]['object_ids'][] = $row['object_id'];
189 }
190 } elseif ($row['title'] !== "" && (!in_array($row['title'], $res[$index]['object_title'], true) && $status != ilBookingReservation::STATUS_CANCELLED)) {
191 $res[$index]['object_title'][] = $row['title'];
192 if (!isset($res[$index]['obj_count'])) {
193 $res[$index]['obj_count'] = 0;
194 }
195 $res[$index]['obj_count'] += 1;
196 $res[$index]['object_ids'][] = $row['object_id'];
197 }
198 $res[$index]['user_id'] = $row['user_id'];
199 }
200
201 foreach ($res as $index => $val) {
202 if (isset($row['object_id'])) {
203 $res[$index]['object_ids'][] = $row['object_id'];
204 }
205 }
206 return $res;
207 }
208
213 public static function getBookingPoolParticipants(
214 int $a_booking_pool_id
215 ): array {
216 global $DIC;
217 $ilDB = $DIC->database();
218 $sql = 'SELECT * FROM booking_member WHERE booking_pool_id = ' . $ilDB->quote($a_booking_pool_id, 'integer');
219
220 $set = $ilDB->query($sql);
221
222 $res = array();
223 while ($row = $ilDB->fetchAssoc($set)) {
224 $res[] = $row['user_id'];
225 }
226
227 return $res;
228 }
229
234 public static function getUserFilter(
235 int $a_pool_id
236 ): array {
237 global $DIC;
238
239 $ilDB = $DIC->database();
240
241 $res = [];
242
243 $sql = "SELECT ud.usr_id,ud.lastname,ud.firstname,ud.login" .
244 " FROM usr_data ud " .
245 " RIGHT JOIN booking_member m ON (ud.usr_id = m.user_id)" .
246 " WHERE ud.usr_id <> " . $ilDB->quote(ANONYMOUS_USER_ID, "integer") .
247 " AND m.booking_pool_id = " . $ilDB->quote($a_pool_id, "integer") .
248 " ORDER BY ud.lastname,ud.firstname";
249
250 $set = $ilDB->query($sql);
251 while ($row = $ilDB->fetchAssoc($set)) {
252 $res[$row["usr_id"]] = $row["lastname"] . ", " . $row["firstname"] .
253 " (" . $row["login"] . ")";
254 }
255
256 return $res;
257 }
258
262 protected function isParticipantAssigned(
263 int $a_booking_object_id,
264 int $a_participant_id
265 ): bool {
266 return count(ilBookingReservation::getObjectReservationForUser($a_booking_object_id, $a_participant_id)) > 0;
267 }
268}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getAssignableParticipants(int $a_bp_object_id)
Get participants who can not have a reservation for this booking pool object id.
static getBookingPoolParticipants(int $a_booking_pool_id)
Get all participants for a booking pool.
isParticipantAssigned(int $a_booking_object_id, int $a_participant_id)
Returns true if the participant has a reservation for this object.
__construct(int $a_user_id, int $a_booking_pool_id)
static getUserFilter(int $a_pool_id)
Get user data from db for an specific pool id.
static getList(int $a_booking_pool, array $a_filter=null, int $a_object_id=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static isBookingPoolLimitReachedByUser(int $a_user_id, int $a_pool_id)
static getMembersWithoutReservation(int $a_object_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
static _lookupName(int $a_user_id)
lookup user name
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
const ANONYMOUS_USER_ID
Definition: constants.php:27
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
if($format !==null) $name
Definition: metadata.php:247
$index
Definition: metadata.php:145
$query