ILIAS  trunk Revision v11.0_alpha-1861-g09f3d197f78
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilBookingParticipant Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilBookingParticipant:

Public Member Functions

 __construct (int $a_user_id, int $a_booking_pool_id)
 
 getIsNew ()
 

Static Public Member Functions

static getAssignableParticipants (int $a_bp_object_id)
 Get participants who can not have a reservation for this booking pool object id. More...
 
static getList (int $a_booking_pool, ?array $a_filter=null, ?int $a_object_id=null)
 
static getBookingPoolParticipants (int $a_booking_pool_id)
 Get all participants for a booking pool. More...
 
static getUserFilter (int $a_pool_id)
 Get user data from db for an specific pool id. More...
 

Protected Member Functions

 read ()
 
 save ()
 
 isParticipantAssigned (int $a_booking_object_id, int $a_participant_id)
 Returns true if the participant has a reservation for this object. More...
 

Protected Attributes

ILIAS BookingManager InternalDomainService $domain
 
ilLanguage $lng
 
ilDBInterface $db
 
int $participant_id
 
int $booking_pool_id
 
bool $is_new
 
ilObjUser $user
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

Todo:
split up to manager and repo class
Author
Jesús López lopez.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 23 of file class.ilBookingParticipant.php.

Constructor & Destructor Documentation

◆ __construct()

ilBookingParticipant::__construct ( int  $a_user_id,
int  $a_booking_pool_id 
)

Definition at line 33 of file class.ilBookingParticipant.php.

References $DIC, ilObject\_exists(), ILIAS\Repository\lng(), read(), save(), and ILIAS\Repository\user().

36  {
37  global $DIC;
38 
39  if (!ilObjUser::_exists($a_user_id)) {
40  throw new ilException("User $a_user_id does not exist.");
41  }
42  if (!ilObjBookingPool::_exists($a_booking_pool_id)) {
43  throw new ilException("Booking Pool $a_booking_pool_id does not exist.");
44  }
45 
46  $this->lng = $DIC->language();
47  $this->db = $DIC->database();
48  $this->user = $DIC->user();
49  $this->domain = $DIC->bookingManager()->internal()->domain();
50 
51  $this->participant_id = $a_user_id;
52  $this->booking_pool_id = $a_booking_pool_id;
53 
54  // if read and not exists, store it in db.
55  if (!$this->read()) {
56  $this->save();
57  $this->is_new = true;
58  } else {
59  $this->is_new = false;
60  }
61  }
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:

Member Function Documentation

◆ getAssignableParticipants()

static ilBookingParticipant::getAssignableParticipants ( int  $a_bp_object_id)
static

Get participants who can not have a reservation for this booking pool object id.

Parameters
int$a_bp_object_idbooking pool object
Returns
array formatted data to display in gui table.

Definition at line 102 of file class.ilBookingParticipant.php.

References $res, ilObjUser\_lookupName(), ilBookingReservation\getMembersWithoutReservation(), ILIAS\Repository\int(), and ilBookingReservation\isBookingPoolLimitReachedByUser().

Referenced by ilBookingAssignParticipantsTableGUI\getItems().

104  : array {
105  $booking_object = new ilBookingObject($a_bp_object_id);
106  $pool_id = $booking_object->getPoolId();
107  $pool = new ilObjBookingPool($pool_id, false);
108  $overall_limit = (int) $pool->getOverallLimit();
109 
110  $res = array();
111 
112  $members = ilBookingReservation::getMembersWithoutReservation($a_bp_object_id);
113 
114  foreach ($members as $member_id) {
115  //check if the user reached the limit of booking in this booking pool.
116  $total_reservations = ilBookingReservation::isBookingPoolLimitReachedByUser($member_id, $pool_id);
117 
118  if ($overall_limit === 0 || ($overall_limit > 0 && $total_reservations < $overall_limit)) {
119  $user_name = ilObjUser::_lookupName($member_id);
120  $name = $user_name['lastname'] . ", " . $user_name['firstname'];
121  $index = $a_bp_object_id . "_" . $member_id;
122 
123  if (!isset($res[$index])) {
124  $res[$index] = array(
125  "user_id" => $member_id,
126  "object_title" => array($booking_object->getTitle()),
127  "name" => $name
128  );
129  } elseif (!in_array($booking_object->getTitle(), $res[$index]['object_title'], true)) {
130  $res[$index]['object_title'][] = $booking_object->getTitle();
131  }
132  }
133  }
134 
135  return $res;
136  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$res
Definition: ltiservices.php:66
static _lookupName(int $a_user_id)
lookup user name
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getMembersWithoutReservation(int $a_object_id)
static isBookingPoolLimitReachedByUser(int $a_user_id, int $a_pool_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getBookingPoolParticipants()

static ilBookingParticipant::getBookingPoolParticipants ( int  $a_booking_pool_id)
static

Get all participants for a booking pool.

Returns
int[]

Definition at line 221 of file class.ilBookingParticipant.php.

References $DIC, $ilDB, and $res.

223  : array {
224  global $DIC;
225  $ilDB = $DIC->database();
226  $sql = 'SELECT * FROM booking_member WHERE booking_pool_id = ' . $ilDB->quote($a_booking_pool_id, 'integer');
227 
228  $set = $ilDB->query($sql);
229 
230  $res = array();
231  while ($row = $ilDB->fetchAssoc($set)) {
232  $res[] = $row['user_id'];
233  }
234 
235  return $res;
236  }
$res
Definition: ltiservices.php:66
global $DIC
Definition: shib_login.php:22

◆ getIsNew()

ilBookingParticipant::getIsNew ( )

Definition at line 92 of file class.ilBookingParticipant.php.

References $is_new.

92  : bool
93  {
94  return $this->is_new;
95  }

◆ getList()

static ilBookingParticipant::getList ( int  $a_booking_pool,
?array  $a_filter = null,
?int  $a_object_id = null 
)
static

Definition at line 138 of file class.ilBookingParticipant.php.

References $DIC, $ilDB, $res, ilObjUser\_lookupName(), and ilBookingReservation\STATUS_CANCELLED.

Referenced by ilBookingAssignParticipantsTableGUI\getItems(), and ilBookingParticipantsTableGUI\getItems().

142  : array {
143  global $DIC;
144 
145  $ilDB = $DIC->database();
146  $domain = $DIC->bookingManager()->internal()->domain();
147 
148  $res = array();
149 
150  $query = 'SELECT bm.user_id, bm.booking_pool_id, br.object_id, bo.title, br.status' .
151  ' FROM booking_member bm' .
152  ' LEFT JOIN booking_reservation br ON (bm.user_id = br.user_id)' .
153  ' LEFT JOIN booking_object bo ON (br.object_id = bo.booking_object_id AND bo.pool_id = ' . $ilDB->quote($a_booking_pool, 'integer') . ')';
154 
155  $where = array('bm.booking_pool_id =' . $ilDB->quote($a_booking_pool, 'integer'));
156  if ($a_object_id) {
157  $where[] = 'br.object_id = ' . $ilDB->quote($a_object_id, 'integer');
158  }
159  if ($a_filter['title'] ?? false) {
160  $where[] = '(' . $ilDB->like('title', 'text', '%' . $a_filter['title'] . '%') .
161  ' OR ' . $ilDB->like('description', 'text', '%' . $a_filter['title'] . '%') . ')';
162  }
163  if ($a_filter['user_id'] ?? false) {
164  $where[] = 'bm.user_id = ' . $ilDB->quote($a_filter['user_id'], 'integer');
165  }
166 
167  $query .= ' WHERE ' . implode(' AND ', $where);
168 
169  $set = $ilDB->query($query);
170 
171  while ($row = $ilDB->fetchAssoc($set)) {
172  $status = $row['status'];
173  //Nothing to show if the status is canceled when filtering by object
174  if ($status == ilBookingReservation::STATUS_CANCELLED && $a_object_id) {
175  continue;
176  }
177 
178  if (!$domain->profile()->exists((int) $row['user_id'])) {
179  continue;
180  }
181 
182  $user_name = ilObjUser::_lookupName($row['user_id']);
183  $name = $user_name['lastname'] . ", " . $user_name['firstname'];
184  $index = $a_booking_pool . "_" . $row['user_id'];
185  $actions = array();
186 
187  if (!isset($res[$index])) {
188  $res[$index] = array(
189  "object_title" => array(),
190  "name" => $name
191  );
192 
193  if ($status != ilBookingReservation::STATUS_CANCELLED && $row['title'] !== "") {
194  $res[$index]['object_title'] = array($row['title']);
195  $res[$index]['obj_count'] = 1;
196  $res[$index]['object_ids'][] = $row['object_id'];
197  }
198  } elseif ($row['title'] !== "" && (!in_array($row['title'], $res[$index]['object_title'], true) && $status != ilBookingReservation::STATUS_CANCELLED)) {
199  $res[$index]['object_title'][] = $row['title'];
200  if (!isset($res[$index]['obj_count'])) {
201  $res[$index]['obj_count'] = 0;
202  }
203  $res[$index]['obj_count'] += 1;
204  $res[$index]['object_ids'][] = $row['object_id'];
205  }
206  $res[$index]['user_id'] = $row['user_id'];
207  }
208 
209  foreach ($res as $index => $val) {
210  if (isset($row['object_id'])) {
211  $res[$index]['object_ids'][] = $row['object_id'];
212  }
213  }
214  return $res;
215  }
$res
Definition: ltiservices.php:66
static _lookupName(int $a_user_id)
lookup user name
ILIAS BookingManager InternalDomainService $domain
global $DIC
Definition: shib_login.php:22
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUserFilter()

static ilBookingParticipant::getUserFilter ( int  $a_pool_id)
static

Get user data from db for an specific pool id.

Returns
string[]

Definition at line 242 of file class.ilBookingParticipant.php.

References $DIC, $ilDB, $res, and ANONYMOUS_USER_ID.

Referenced by ilBookingParticipantsTableGUI\initFilter().

244  : array {
245  global $DIC;
246 
247  $ilDB = $DIC->database();
248 
249  $res = [];
250 
251  $sql = "SELECT ud.usr_id,ud.lastname,ud.firstname,ud.login" .
252  " FROM usr_data ud " .
253  " RIGHT JOIN booking_member m ON (ud.usr_id = m.user_id)" .
254  " WHERE ud.usr_id <> " . $ilDB->quote(ANONYMOUS_USER_ID, "integer") .
255  " AND m.booking_pool_id = " . $ilDB->quote($a_pool_id, "integer") .
256  " ORDER BY ud.lastname,ud.firstname";
257 
258  $set = $ilDB->query($sql);
259  while ($row = $ilDB->fetchAssoc($set)) {
260  $res[$row["usr_id"]] = $row["lastname"] . ", " . $row["firstname"] .
261  " (" . $row["login"] . ")";
262  }
263 
264  return $res;
265  }
$res
Definition: ltiservices.php:66
const ANONYMOUS_USER_ID
Definition: constants.php:27
global $DIC
Definition: shib_login.php:22
+ Here is the caller graph for this function:

◆ isParticipantAssigned()

ilBookingParticipant::isParticipantAssigned ( int  $a_booking_object_id,
int  $a_participant_id 
)
protected

Returns true if the participant has a reservation for this object.

Definition at line 270 of file class.ilBookingParticipant.php.

References ilBookingReservation\getObjectReservationForUser().

273  : bool {
274  return count(ilBookingReservation::getObjectReservationForUser($a_booking_object_id, $a_participant_id)) > 0;
275  }
static getObjectReservationForUser(int $a_object_id, int $a_user_id)
+ Here is the call graph for this function:

◆ read()

ilBookingParticipant::read ( )
protected

Definition at line 63 of file class.ilBookingParticipant.php.

References null.

Referenced by __construct().

63  : ?int
64  {
65  $query = 'SELECT participant_id FROM booking_member' .
66  ' WHERE user_id = ' . $this->db->quote($this->participant_id, 'integer') .
67  ' AND booking_pool_id = ' . $this->db->quote($this->booking_pool_id, 'integer');
68 
69  $set = $this->db->query($query);
70  $row = $this->db->fetchAssoc($set);
71  if (empty($row)) {
72  return null;
73  }
74  return (int) $row['participant_id'];
75  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the caller graph for this function:

◆ save()

ilBookingParticipant::save ( )
protected

Definition at line 77 of file class.ilBookingParticipant.php.

References ILIAS\Repository\user().

Referenced by __construct().

77  : void
78  {
79  $assigner_id = $this->user->getId();
80  $next_id = $this->db->nextId('booking_member');
81 
82  $query = 'INSERT INTO booking_member' .
83  ' (participant_id, user_id, booking_pool_id, assigner_user_id)' .
84  ' VALUES (' . $this->db->quote($next_id, 'integer') .
85  ',' . $this->db->quote($this->participant_id, 'integer') .
86  ',' . $this->db->quote($this->booking_pool_id, 'integer') .
87  ',' . $this->db->quote($assigner_id, 'integer') . ')';
88 
89  $this->db->manipulate($query);
90  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $booking_pool_id

int ilBookingParticipant::$booking_pool_id
protected

Definition at line 29 of file class.ilBookingParticipant.php.

◆ $db

ilDBInterface ilBookingParticipant::$db
protected

Definition at line 27 of file class.ilBookingParticipant.php.

◆ $domain

ILIAS BookingManager InternalDomainService ilBookingParticipant::$domain
protected

Definition at line 25 of file class.ilBookingParticipant.php.

◆ $is_new

bool ilBookingParticipant::$is_new
protected

Definition at line 30 of file class.ilBookingParticipant.php.

Referenced by getIsNew().

◆ $lng

ilLanguage ilBookingParticipant::$lng
protected

Definition at line 26 of file class.ilBookingParticipant.php.

◆ $participant_id

int ilBookingParticipant::$participant_id
protected

Definition at line 28 of file class.ilBookingParticipant.php.

◆ $user

ilObjUser ilBookingParticipant::$user
protected

Definition at line 31 of file class.ilBookingParticipant.php.


The documentation for this class was generated from the following file: