ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilBookingParticipant.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
10{
11 protected $lng;
12 protected $db;
13 protected $participant_id;
15 protected $is_new;
16
22 public function __construct($a_user_id, $a_booking_pool_id)
23 {
24 if (!ilObjUser::_exists($a_user_id) || !ilObjBookingPool::_exists($a_booking_pool_id)) {
25 return false;
26 }
27
28 global $DIC;
29 $this->lng = $DIC->language();
30 $this->db = $DIC->database();
31 $this->il_user = $DIC->user();
32
33 $this->participant_id = $a_user_id;
34 $this->booking_pool_id = $a_booking_pool_id;
35
36 // if read and not exists, store it in db.
37 if (!$this->read()) {
38 $this->save();
39 $this->is_new = true;
40 } else {
41 $this->is_new = false;
42 }
43 }
44
49 protected function read()
50 {
51 $query = 'SELECT participant_id FROM booking_member' .
52 ' WHERE user_id = ' . $this->db->quote($this->participant_id, 'integer') .
53 ' AND booking_pool_id = ' . $this->db->quote($this->booking_pool_id, 'integer');
54
55 $set = $this->db->query($query);
56 $row = $this->db->fetchAssoc($set);
57 if (empty($row)) {
58 return false;
59 } else {
60 return $row['participant_id'];
61 }
62 }
63
67 protected function save()
68 {
69 $assigner_id = $this->il_user->getId();
70 $next_id = $this->db->nextId('booking_member');
71
72 $query = 'INSERT INTO booking_member' .
73 ' (participant_id, user_id, booking_pool_id, assigner_user_id)' .
74 ' VALUES (' . $this->db->quote($next_id, 'integer') .
75 ',' . $this->db->quote($this->participant_id, 'integer') .
76 ',' . $this->db->quote($this->booking_pool_id, 'integer') .
77 ',' . $this->db->quote($assigner_id, 'integer') . ')';
78
79 $this->db->manipulate($query);
80 }
81
85 public function getIsNew()
86 {
87 return $this->is_new;
88 }
89
96 public static function getAssignableParticipants($a_bp_object_id)
97 {
98 $booking_object = new ilBookingObject($a_bp_object_id);
99 $pool_id = $booking_object->getPoolId();
100 $pool = new ilObjBookingPool($pool_id, false);
101 $overall_limit = (int) $pool->getOverallLimit();
102
103 $res = array();
104
105 $members = ilBookingReservation::getMembersWithoutReservation($a_bp_object_id);
106
107 foreach ($members as $member_id) {
108 //check if the user reached the limit of booking in this booking pool.
109 $total_reservations = ilBookingReservation::isBookingPoolLimitReachedByUser($member_id, $pool_id);
110
111 if ($overall_limit == 0 || ($overall_limit > 0 && $total_reservations < $overall_limit)) {
112 $user_name = ilObjUser::_lookupName($member_id);
113 $name = $user_name['lastname'] . ", " . $user_name['firstname'];
114 $index = $a_bp_object_id . "_" . $member_id;
115
116 if (!isset($res[$index])) {
117 $res[$index] = array(
118 "user_id" => $member_id,
119 "object_title" => array($booking_object->getTitle()),
120 "name" => $name
121 );
122 } else {
123 if (!in_array($booking_object->getTitle(), $res[$index]['object_title'])) {
124 array_push($res[$index]['object_title'], $booking_object->getTitle());
125 }
126 }
127 }
128 }
129
130 return $res;
131 }
132
133 public static function getList($a_booking_pool, array $a_filter = null, $a_object_id = null)
134 {
135 global $DIC;
136
137 $ilDB = $DIC->database();
138 $lng = $DIC->language();
139 $ctrl = $DIC->ctrl();
140
141 $res = array();
142
143 $query = 'SELECT bm.user_id, bm.booking_pool_id, br.object_id, bo.title, br.status' .
144 ' FROM booking_member bm' .
145 ' LEFT JOIN booking_reservation br ON (bm.user_id = br.user_id)' .
146 ' LEFT JOIN booking_object bo ON (br.object_id = bo.booking_object_id AND bo.pool_id = ' . $ilDB->quote($a_booking_pool, 'integer') . ')';
147
148 $where = array('bm.booking_pool_id =' . $ilDB->quote($a_booking_pool, 'integer'));
149 if ($a_object_id) {
150 $where[] = 'br.object_id = ' . $ilDB->quote($a_object_id, 'integer');
151 }
152 if ($a_filter['title']) {
153 $where[] = '(' . $ilDB->like('title', 'text', '%' . $a_filter['title'] . '%') .
154 ' OR ' . $ilDB->like('description', 'text', '%' . $a_filter['title'] . '%') . ')';
155 }
156 if ($a_filter['user_id']) {
157 $where[] = 'bm.user_id = ' . $ilDB->quote($a_filter['user_id'], 'integer');
158 }
159
160 $query .= ' WHERE ' . implode(' AND ', $where);
161
162 $set = $ilDB->query($query);
163
164 while ($row = $ilDB->fetchAssoc($set)) {
165 $status = $row['status'];
166 //Nothing to show if the status is canceled when filtering by object
167 if ($status == ilBookingReservation::STATUS_CANCELLED && $a_object_id) {
168 continue;
169 }
170
171 $user_name = ilObjUser::_lookupName($row['user_id']);
172 $name = $user_name['lastname'] . ", " . $user_name['firstname'];
173 $index = $a_booking_pool . "_" . $row['user_id'];
174 $actions = array();
175
176 if (!isset($res[$index])) {
177 $res[$index] = array(
178 "object_title" => array(),
179 "name" => $name
180 );
181
182 if ($status != ilBookingReservation::STATUS_CANCELLED && $row['title'] != "") {
183 $res[$index]['object_title'] = array($row['title']);
184 $res[$index]['obj_count'] = 1;
185 $res[$index]['object_ids'][] = $row['object_id'];
186 }
187 } else {
188 if ($row['title'] != "" && (!in_array(
189 $row['title'],
190 $res[$index]['object_title']
192 array_push($res[$index]['object_title'], $row['title']);
193 $res[$index]['obj_count'] = $res[$index]['obj_count'] + 1;
194 $res[$index]['object_ids'][] = $row['object_id'];
195 }
196 }
197 $res[$index]['user_id'] = $row['user_id'];
198 }
199
200 // obsolete...?
201 $bp = new ilObjBookingPool($a_booking_pool, false);
202
203 foreach ($res as $index => $val) {
204 $actions = [];
205 // action assign only if user did not booked all objects.
206 //if($res[$index]['obj_count'] < ilBookingObject::getNumberOfObjectsForPool($a_booking_pool))
207
208 // alex: this does not seem to be correct: assignments are always possible for all objects
209 $has_schedule = ($bp->getScheduleType() == ilObjBookingPool::TYPE_FIX_SCHEDULE);
210 $limit_reached = (!$has_schedule && $bp->getOverallLimit() <= $val['obj_count']);
211 if (!$limit_reached) {
212 $ctrl->setParameterByClass('ilbookingparticipantgui', 'bkusr', $val['user_id']);
213 $actions[] = array(
214 'text' => $lng->txt("book_assign_object"),
215 'url' => $ctrl->getLinkTargetByClass(["ilobjbookingpoolgui", "ilbookingparticipantgui"], 'assignObjects')
216 );
217 $ctrl->setParameterByClass('ilbookingparticipantgui', 'bkusr', '');
218 }
219
220
221 if ($bp->getScheduleType() == ilObjBookingPool::TYPE_NO_SCHEDULE && $val['obj_count'] == 1) {
222 $ctrl->setParameterByClass('ilbookingreservationsgui', 'bkusr', $val['user_id']);
223 $ctrl->setParameterByClass('ilbookingreservationsgui', 'object_id', $val['object_ids'][0]);
224 $ctrl->setParameterByClass('ilbookingreservationsgui', 'part_view', ilBookingParticipantGUI::PARTICIPANT_VIEW);
225
226 $actions[] = array(
227 'text' => $lng->txt("book_deassign"),
228 'url' => $ctrl->getLinkTargetByClass("ilbookingreservationsgui", 'rsvConfirmCancelUser')
229 );
230
231 $ctrl->setParameterByClass('ilbookingreservationsgui', 'bkusr', '');
232 $ctrl->setParameterByClass('ilbookingreservationsgui', 'object_id', '');
233 $ctrl->setParameterByClass('ilbookingreservationsgui', 'part_view', '');
234 } elseif ($bp->getScheduleType() == ilObjBookingPool::TYPE_FIX_SCHEDULE || $res[$index]['obj_count'] > 1) {
235 $ctrl->setParameterByClass('ilobjbookingpoolgui', 'user_id', $val['user_id']);
236 $actions[] = array(
237 'text' => $lng->txt("book_deassign"),
238 'url' => $ctrl->getLinkTargetByClass("ilobjbookingpoolgui", 'log')
239 );
240 $ctrl->setParameterByClass('ilobjbookingpoolgui', 'user_id', '');
241 }
242
243 //add the actions
244 //$res[$index]['actions'] = $actions;
245 $res[$index]['object_ids'][] = $row['object_id'];
246 }
247 //echo "<pre>"; print_r($res); exit;
248 return $res;
249 }
250
256 public static function getBookingPoolParticipants(int $a_booking_pool_id) : array
257 {
258 global $DIC;
259 $ilDB = $DIC->database();
260 $sql = 'SELECT * FROM booking_member WHERE booking_pool_id = ' . $ilDB->quote($a_booking_pool_id, 'integer');
261
262 $set = $ilDB->query($sql);
263
264 $res = array();
265 while ($row = $ilDB->fetchAssoc($set)) {
266 $res[] = $row['user_id'];
267 }
268
269 return $res;
270 }
271
278 public static function getUserFilter($a_pool_id)
279 {
280 global $DIC;
281
282 $ilDB = $DIC->database();
283
284 $res = array();
285
286 $sql = "SELECT ud.usr_id,ud.lastname,ud.firstname,ud.login" .
287 " FROM usr_data ud " .
288 " RIGHT JOIN booking_member m ON (ud.usr_id = m.user_id)" .
289 " WHERE ud.usr_id <> " . $ilDB->quote(ANONYMOUS_USER_ID, "integer") .
290 " AND m.booking_pool_id = " . $ilDB->quote($a_pool_id, "integer") .
291 " ORDER BY ud.lastname,ud.firstname";
292
293 $set = $ilDB->query($sql);
294 while ($row = $ilDB->fetchAssoc($set)) {
295 $res[$row["usr_id"]] = $row["lastname"] . ", " . $row["firstname"] .
296 " (" . $row["login"] . ")";
297 }
298
299 return $res;
300 }
301
308 protected function isParticipantAssigned($a_booking_object_id, $a_participant_id)
309 {
310 if (!empty(ilBookingReservation::getObjectReservationForUser($a_booking_object_id, $a_participant_id))) {
311 return true;
312 } else {
313 return false;
314 }
315 }
316}
An exception for terminatinating execution or to throw for unit testing.
a bookable ressource
Class ilBookingParticipant.
static getUserFilter($a_pool_id)
Get user data from db for an specific pool id.
static getBookingPoolParticipants(int $a_booking_pool_id)
Get all participants for a booking pool.
isParticipantAssigned($a_booking_object_id, $a_participant_id)
Returns true if the participant has a reservation for this object.
static getAssignableParticipants($a_bp_object_id)
Get participants who can not have a reservation for this booking pool object id.
__construct($a_user_id, $a_booking_pool_id)
ilBookingParticipant constructor.
save()
Save booking participant in DB.
static getList($a_booking_pool, array $a_filter=null, $a_object_id=null)
static getObjectReservationForUser($a_object_id, $a_user_id, $a_multi=false)
static isBookingPoolLimitReachedByUser(int $a_user_id, int $a_pool_id)
static getMembersWithoutReservation(int $a_object_id)
Class ilObjBookingPool.
static _lookupName($a_user_id)
lookup user name
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
if($format !==null) $name
Definition: metadata.php:230
$index
Definition: metadata.php:128
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$DIC
Definition: xapitoken.php:46