ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilBookingReservation Class Reference

a booking reservation More...

+ Collaboration diagram for ilBookingReservation:

Public Member Functions

 __construct ($a_id=NULL)
 Constructor. More...
 
 getId ()
 Get id. More...
 
 setObjectId ($a_object_id)
 Set object id. More...
 
 getObjectId ()
 Get object id. More...
 
 setUserId ($a_user_id)
 Set booking user id. More...
 
 getUserId ()
 Get booking user id. More...
 
 setFrom ($a_from)
 Set booking from date. More...
 
 getFrom ()
 Get booking from date. More...
 
 setTo ($a_to)
 Set booking to date. More...
 
 getTo ()
 Get booking to date. More...
 
 setStatus ($a_status)
 Set booking status. More...
 
 getStatus ()
 Get booking status. More...
 
 setGroupId ($a_group_id)
 Set group id. More...
 
 getGroupId ()
 Get group id. More...
 
 save ()
 Create new entry in db. More...
 
 update ()
 Update entry in db. More...
 
 delete ()
 Delete single entry. More...
 
 getCalendarEntry ()
 

Static Public Member Functions

static isValidStatus ($a_status)
 Check if given status is valid. More...
 
static getNewGroupId ()
 Get next group id. More...
 
static getAvailableObject (array $a_ids, $a_from, $a_to, $a_return_single=true, $a_return_counter=false)
 Check if any of given objects are bookable. More...
 
static isObjectAvailableInPeriod ($a_obj_id, ilBookingSchedule $a_schedule, $a_from, $a_to)
 
static isObjectAvailableNoSchedule ($a_obj_id)
 
static getCurrentOrUpcomingReservation ($a_object_id)
 Get details about object reservation. More...
 
static getObjectReservationForUser ($a_object_id, $a_user_id, $a_multi=false)
 
static getList ($a_object_ids, $a_limit=10, $a_offset=0, array $filter)
 List all reservations. More...
 
static getListByDate ($a_has_schedule, array $a_object_ids, array $filter=null)
 List all reservations by date. More...
 
static getUserFilter (array $a_object_ids)
 Get all users who have reservations for object(s) More...
 
static changeStatus (array $a_ids, $a_status)
 List all reservations. More...
 
static getCancelDetails ($a_obj_id, $a_user_id, $a_from, $a_to)
 Get reservation ids from aggregated id for cancellation. More...
 

Data Fields

const STATUS_IN_USE = 2
 
const STATUS_CANCELLED = 5
 

Protected Member Functions

 read ()
 Get dataset from db. More...
 

Protected Attributes

 $id
 
 $object_id
 
 $user_id
 
 $from
 
 $to
 
 $status
 
 $group_id
 

Detailed Description

a booking reservation

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 12 of file class.ilBookingReservation.php.

Constructor & Destructor Documentation

◆ __construct()

ilBookingReservation::__construct (   $a_id = NULL)

Constructor.

if id is given will read dataset from db

Parameters
int$a_id

Definition at line 32 of file class.ilBookingReservation.php.

References read().

33  {
34  $this->id = (int)$a_id;
35  $this->read();
36  }
+ Here is the call graph for this function:

Member Function Documentation

◆ changeStatus()

static ilBookingReservation::changeStatus ( array  $a_ids,
  $a_status 
)
static

List all reservations.

Parameters
array$a_object_ids
int$a_limit
int$a_offset
array$filter
array$a_group_id
Returns
array Batch update reservation status
Parameters
array$a_ids
int$a_status
Returns
bool

Definition at line 1012 of file class.ilBookingReservation.php.

References $ilDB.

Referenced by ilObjBookingPoolGUI\changeStatusObject().

1013  {
1014  global $ilDB;
1015 
1016  if(self::isValidStatus($a_status))
1017  {
1018  return $ilDB->manipulate('UPDATE booking_reservation'.
1019  ' SET status = '.$ilDB->quote($a_status, 'integer').
1020  ' WHERE '.$ilDB->in('booking_reservation_id', $a_ids, '', 'integer'));
1021 
1022  }
1023  }
global $ilDB
+ Here is the caller graph for this function:

◆ delete()

ilBookingReservation::delete ( )

Delete single entry.

Returns
bool

Definition at line 261 of file class.ilBookingReservation.php.

References $ilDB.

262  {
263  global $ilDB;
264 
265  if($this->id)
266  {
267  return $ilDB->manipulate('DELETE FROM booking_reservation'.
268  ' WHERE booking_reservation_id = '.$ilDB->quote($this->id, 'integer'));
269  }
270  }
global $ilDB

◆ getAvailableObject()

static ilBookingReservation::getAvailableObject ( array  $a_ids,
  $a_from,
  $a_to,
  $a_return_single = true,
  $a_return_counter = false 
)
static

Check if any of given objects are bookable.

Parameters
array$a_ids
int$a_from
int$a_to
int$a_return_single
Returns
int

Definition at line 291 of file class.ilBookingReservation.php.

References $counter, $from, $id, $ilDB, $row, $to, array, ilBookingSchedule\getAvailabilityFrom(), ilBookingObject\getNrOfItemsForObjects(), IL_CAL_DATE, and IL_CAL_UNIX.

Referenced by ilObjBookingPoolGUI\buildDatesBySchedule(), ilObjBookingPoolGUI\confirmedBookingNumbersObject(), and ilObjBookingPoolGUI\confirmedBookingObject().

292  {
293  global $ilDB;
294 
295  $nr_map = ilBookingObject::getNrOfItemsForObjects($a_ids);
296 
297  $from = $ilDB->quote($a_from, 'integer');
298  $to = $ilDB->quote($a_to, 'integer');
299 
300  $set = $ilDB->query('SELECT count(*) cnt, object_id'.
301  ' FROM booking_reservation'.
302  ' WHERE '.$ilDB->in('object_id', $a_ids, '', 'integer').
303  ' AND (status IS NULL OR status <> '.$ilDB->quote(self::STATUS_CANCELLED, 'integer').')'.
304  ' AND ((date_from <= '.$from.' AND date_to >= '.$from.')'.
305  ' OR (date_from <= '.$to.' AND date_to >= '.$to.')'.
306  ' OR (date_from >= '.$from.' AND date_to <= '.$to.'))'.
307  ' GROUP BY object_id');
308  $blocked = $counter = array();
309  while($row = $ilDB->fetchAssoc($set))
310  {
311  if($row['cnt'] >= $nr_map[$row['object_id']])
312  {
313  $blocked[] = $row['object_id'];
314  }
315  else if($a_return_counter)
316  {
317  $counter[$row['object_id']] = (int)$nr_map[$row['object_id']]-(int)$row['cnt'];
318  }
319  }
320 
321  // #17868 - validate against schedule availability
322  foreach($a_ids as $obj_id)
323  {
324  $bobj = new ilBookingObject($obj_id);
325  if($bobj->getScheduleId())
326  {
327  include_once "Modules/BookingManager/classes/class.ilBookingSchedule.php";
328  $schedule = new ilBookingSchedule($bobj->getScheduleId());
329 
330  $av_from = ($schedule->getAvailabilityFrom() && !$schedule->getAvailabilityFrom()->isNull())
331  ? $schedule->getAvailabilityFrom()->get(IL_CAL_UNIX)
332  : null;
333  $av_to = ($schedule->getAvailabilityTo() && !$schedule->getAvailabilityTo()->isNull())
334  ? strtotime($schedule->getAvailabilityTo()->get(IL_CAL_DATE)." 23:59:59")
335  : null;
336 
337  if(($av_from && $a_from < $av_from) ||
338  ($av_to && $a_to > $av_to))
339  {
340  $blocked[] = $obj_id;
341  unset($counter[$obj_id]);
342  }
343  }
344  }
345 
346  $available = array_diff($a_ids, $blocked);
347  if(sizeof($available))
348  {
349  if($a_return_counter)
350  {
351  foreach($a_ids as $id)
352  {
353  if(!isset($counter[$id]))
354  {
355  $counter[$id] = (int)$nr_map[$id];
356  }
357  }
358  return $counter;
359  }
360  else if($a_return_single)
361  {
362  return array_shift($available);
363  }
364  else
365  {
366  return $available;
367  }
368  }
369  }
a bookable ressource
getAvailabilityFrom()
Get availability start.
schedule for booking ressource
const IL_CAL_UNIX
$counter
static getNrOfItemsForObjects(array $a_obj_ids)
Get nr of available items.
Create styles array
The data for the language used.
const IL_CAL_DATE
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCalendarEntry()

ilBookingReservation::getCalendarEntry ( )

Definition at line 1025 of file class.ilBookingReservation.php.

References $ilDB, $row, getId(), and ilCalendarCategory\TYPE_BOOK.

1026  {
1027  global $ilDB;
1028 
1029  include_once 'Services/Calendar/classes/class.ilCalendarCategory.php';
1030 
1031  $set = $ilDB->query("SELECT ce.cal_id FROM cal_entries ce".
1032  " JOIN cal_cat_assignments cca ON ce.cal_id = cca.cal_id".
1033  " JOIN cal_categories cc ON cca.cat_id = cc.cat_id".
1034  " JOIN booking_reservation br ON ce.context_id = br.booking_reservation_id".
1035  " WHERE cc.obj_id = ".$ilDB->quote($this->getUserId(),'integer').
1036  " AND br.user_id = ".$ilDB->quote($this->getUserId(),'integer').
1037  " AND cc.type = ".$ilDB->quote(ilCalendarCategory::TYPE_BOOK,'integer').
1038  " AND ce.context_id = ".$ilDB->quote($this->getId(), 'integer'));
1039  $row = $ilDB->fetchAssoc($set);
1040  return $row["cal_id"];
1041  }
global $ilDB
+ Here is the call graph for this function:

◆ getCancelDetails()

static ilBookingReservation::getCancelDetails (   $a_obj_id,
  $a_user_id,
  $a_from,
  $a_to 
)
static

Get reservation ids from aggregated id for cancellation.

Parameters
int$a_obj_id
int$a_user_id
int$a_from
int$a_to
Returns
array

Definition at line 1052 of file class.ilBookingReservation.php.

References $ilDB, $res, $row, and array.

Referenced by ilObjBookingPoolGUI\rsvConfirmCancelObject().

1053  {
1054  global $ilDB;
1055 
1056  $res = array();
1057 
1058  $sql = "SELECT booking_reservation_id".
1059  " FROM booking_reservation".
1060  " WHERE object_id = ".$ilDB->quote($a_obj_id, "integer").
1061  " AND user_id = ".$ilDB->quote($a_user_id, "integer").
1062  " AND date_from = ".$ilDB->quote($a_from, "integer").
1063  " AND date_to = ".$ilDB->quote($a_to, "integer").
1064  " AND (status IS NULL".
1065  " OR status <> ".$ilDB->quote(self::STATUS_CANCELLED, "integer").")";
1066  $set = $ilDB->query($sql);
1067  while($row = $ilDB->fetchAssoc($set))
1068  {
1069  $res[] = $row["booking_reservation_id"];
1070  }
1071 
1072  return $res;
1073  }
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ getCurrentOrUpcomingReservation()

static ilBookingReservation::getCurrentOrUpcomingReservation (   $a_object_id)
static

Get details about object reservation.

Parameters
int$a_object_id
Returns
array

Definition at line 478 of file class.ilBookingReservation.php.

References $ilDB, $row, and time.

479  {
480  global $ilDB;
481 
482  $now = $ilDB->quote(time(), 'integer');
483 
484  $ilDB->setLimit(1);
485  $set = $ilDB->query('SELECT user_id, status, date_from, date_to'.
486  ' FROM booking_reservation'.
487  ' WHERE ((date_from <= '.$now.' AND date_to >= '.$now.')'.
488  ' OR date_from > '.$now.')'.
489  ' AND (status <> '.$ilDB->quote(self::STATUS_CANCELLED, 'integer').
490  ' OR STATUS IS NULL) AND object_id = '.$ilDB->quote($a_object_id, 'integer').
491  ' ORDER BY date_from');
492  $row = $ilDB->fetchAssoc($set);
493  return $row;
494  }
global $ilDB
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.

◆ getFrom()

ilBookingReservation::getFrom ( )

Get booking from date.

Returns
int

Definition at line 96 of file class.ilBookingReservation.php.

References $from.

Referenced by save().

+ Here is the caller graph for this function:

◆ getGroupId()

ilBookingReservation::getGroupId ( )

Get group id.

Returns
int

Definition at line 171 of file class.ilBookingReservation.php.

References $group_id.

Referenced by save().

172  {
173  return $this->group_id;
174  }
+ Here is the caller graph for this function:

◆ getId()

ilBookingReservation::getId ( )

Get id.

Returns
int

Definition at line 42 of file class.ilBookingReservation.php.

References $id.

Referenced by getCalendarEntry().

43  {
44  return $this->id;
45  }
+ Here is the caller graph for this function:

◆ getList()

static ilBookingReservation::getList (   $a_object_ids,
  $a_limit = 10,
  $a_offset = 0,
array  $filter 
)
static

List all reservations.

Parameters
array$a_object_ids
int$a_limit
int$a_offset
array$a_offset
Returns
array

Definition at line 529 of file class.ilBookingReservation.php.

References $counter, $ilDB, $res, $row, and array.

Referenced by ilBookingObjectsTableGUI\getItems().

530  {
531  global $ilDB;
532 
533  $sql = 'SELECT r.*,o.title'.
534  ' FROM booking_reservation r'.
535  ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
536 
537  $count_sql = 'SELECT COUNT(*) AS counter'.
538  ' FROM booking_reservation r'.
539  ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
540 
541  $where = array($ilDB->in('r.object_id', $a_object_ids, '', 'integer'));
542  if($filter['status'])
543  {
544  if($filter['status'] > 0)
545  {
546  $where[] = 'status = '.$ilDB->quote($filter['status'], 'integer');
547  }
548  else
549  {
550  $where[] = '(status != '.$ilDB->quote(-$filter['status'], 'integer').
551  ' OR status IS NULL)';
552  }
553  }
554  if($filter['from'])
555  {
556  $where[] = 'date_from >= '.$ilDB->quote($filter['from'], 'integer');
557  }
558  if($filter['to'])
559  {
560  $where[] = 'date_to <= '.$ilDB->quote($filter['to'], 'integer');
561  }
562  if(sizeof($where))
563  {
564  $sql .= ' WHERE '.implode(' AND ', $where);
565  $count_sql .= ' WHERE '.implode(' AND ', $where);
566  }
567 
568  $set = $ilDB->query($count_sql);
569  $row = $ilDB->fetchAssoc($set);
570  $counter = $row['counter'];
571 
572  $sql .= ' ORDER BY date_from DESC, booking_reservation_id DESC';
573 
574  $ilDB->setLimit($a_limit, $a_offset);
575  $set = $ilDB->query($sql);
576  $res = array();
577  while($row = $ilDB->fetchAssoc($set))
578  {
579  $res[] = $row;
580  }
581 
582  return array('data'=>$res, 'counter'=>$counter);
583  }
$counter
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ getListByDate()

static ilBookingReservation::getListByDate (   $a_has_schedule,
array  $a_object_ids,
array  $filter = null 
)
static

List all reservations by date.

Parameters
bool$a_has_schedule
array$a_object_ids
string$a_order_field
string$a_order_direction
int$a_offset
int$a_limit
array$filter
Returns
array

Definition at line 596 of file class.ilBookingReservation.php.

References $ilDB, $res, $row, $user_id, ilObjUser\_lookupName(), array, date, and time.

Referenced by ilBookingReservationsTableGUI\getItems().

597  {
598  global $ilDB;
599 
600  $res = array();
601 
602  $sql = 'SELECT r.*, o.title'.
603  ' FROM booking_reservation r'.
604  ' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
605 
606  $where = array($ilDB->in('object_id', $a_object_ids, '', 'integer'));
607  if($filter['status'])
608  {
609  if($filter['status'] > 0)
610  {
611  $where[] = 'status = '.$ilDB->quote($filter['status'], 'integer');
612  }
613  else
614  {
615  $where[] = '(status != '.$ilDB->quote(-$filter['status'], 'integer').
616  ' OR status IS NULL)';
617  }
618  }
619  if($filter['title'])
620  {
621  $where[] = '('.$ilDB->like('title', 'text', '%'.$filter['title'].'%').
622  ' OR '.$ilDB->like('description', 'text', '%'.$filter['title'].'%').')';
623  }
624  if($a_has_schedule)
625  {
626  if($filter['from'])
627  {
628  $where[] = 'date_from >= '.$ilDB->quote($filter['from'], 'integer');
629  }
630  if($filter['to'])
631  {
632  $where[] = 'date_to <= '.$ilDB->quote($filter['to'], 'integer');
633  }
634  if(!$filter['past'])
635  {
636  $where[] = 'date_to > '.$ilDB->quote(time(), 'integer');
637  }
638  }
639  if($filter['user_id']) // #16584
640  {
641  $where[] = 'user_id = '.$ilDB->quote($filter['user_id'], 'integer');
642  }
643  /*
644  if($a_group_id)
645  {
646  $where[] = 'group_id = '.$ilDB->quote(substr($a_group_id, 1), 'integer');
647  }
648  */
649  if(sizeof($where))
650  {
651  $sql .= ' WHERE '.implode(' AND ', $where);
652  }
653 
654  if($a_has_schedule)
655  {
656  $sql .= ' ORDER BY date_from DESC';
657  }
658  else
659  {
660  // #16155 - could be cancelled and re-booked
661  $sql .= ' ORDER BY status';
662  }
663 
664  $set = $ilDB->query($sql);
665  while($row = $ilDB->fetchAssoc($set))
666  {
667  $obj_id = $row["object_id"];
668  $user_id = $row["user_id"];
669 
670  if($a_has_schedule)
671  {
672  $slot = $row["date_from"]."_".$row["date_to"];
673  $idx = $obj_id."_".$user_id."_".$slot;
674  }
675  else
676  {
677  $idx = $obj_id."_".$user_id;
678  }
679 
680  if($a_has_schedule && $filter["slot"])
681  {
682  $slot_idx = date("w", $row["date_from"])."_".date("H:i", $row["date_from"]).
683  "-".date("H:i", $row["date_to"]+1);
684  if($filter["slot"] != $slot_idx)
685  {
686  continue;
687  }
688  }
689 
690  if(!isset($res[$idx]))
691  {
693 
694  $res[$idx] = array(
695  "object_id" => $obj_id
696  ,"title" => $row["title"]
697  ,"user_id" => $user_id
698  ,"counter" => 1
699  ,"user_name" => $uname["lastname"].", ".$uname["firstname"] // #17862
700  );
701 
702  if($a_has_schedule)
703  {
704  $res[$idx]["booking_reservation_id"] = $idx;
705  $res[$idx]["date"] = date("Y-m-d", $row["date_from"]);
706  $res[$idx]["slot"] = date("H:i", $row["date_from"])." - ".
707  date("H:i", $row["date_to"]+1);
708  $res[$idx]["week"] = date("W", $row["date_from"]);
709  $res[$idx]["weekday"] = date("w", $row["date_from"]);
710  $res[$idx]["can_be_cancelled"] = ($row["status"] != self::STATUS_CANCELLED &&
711  $row["date_from"] > time());
712  $res[$idx]["_sortdate"] = $row["date_from"];
713  }
714  else
715  {
716  $res[$idx]["booking_reservation_id"] = $row["booking_reservation_id"];
717  $res[$idx]["status"] = $row["status"];
718  $res[$idx]["can_be_cancelled"] = ($row["status"] != self::STATUS_CANCELLED);
719  }
720  }
721  else
722  {
723  $res[$idx]["counter"]++;
724  }
725  }
726 
727  return $res;
728  }
static _lookupName($a_user_id)
lookup user name
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
Create styles array
The data for the language used.
global $ilDB
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNewGroupId()

static ilBookingReservation::getNewGroupId ( )
static

Get next group id.

Returns
int

Definition at line 276 of file class.ilBookingReservation.php.

References $ilDB.

Referenced by ilObjBookingPoolGUI\confirmedBookingObject().

277  {
278  global $ilDB;
279 
280  return $ilDB->nextId('booking_reservation_group');
281  }
global $ilDB
+ Here is the caller graph for this function:

◆ getObjectId()

ilBookingReservation::getObjectId ( )

Get object id.

Returns
int

Definition at line 60 of file class.ilBookingReservation.php.

References $object_id.

Referenced by save().

+ Here is the caller graph for this function:

◆ getObjectReservationForUser()

static ilBookingReservation::getObjectReservationForUser (   $a_object_id,
  $a_user_id,
  $a_multi = false 
)
static

Definition at line 496 of file class.ilBookingReservation.php.

References $ilDB, $res, $row, and array.

Referenced by ilObjBookingPoolGUI\confirmedBookingObject(), ilBookingObjectGUI\deliverPostFile(), ilBookingObjectGUI\displayPostInfo(), and ilBookingObjectGUI\rsvCancelUser().

497  {
498  global $ilDB;
499 
500  $set = $ilDB->query('SELECT booking_reservation_id FROM booking_reservation'.
501  ' WHERE user_id = '.$ilDB->quote($a_user_id, 'integer').
502  ' AND object_id = '.$ilDB->quote($a_object_id, 'integer').
503  ' AND (status <> '.$ilDB->quote(self::STATUS_CANCELLED, 'integer').
504  ' OR STATUS IS NULL)');
505  if(!$a_multi)
506  {
507  $row = $ilDB->fetchAssoc($set);
508  return $row['booking_reservation_id'];
509  }
510  else
511  {
512  $res = array();
513  while($row = $ilDB->fetchAssoc($set))
514  {
515  $res[] = $row['booking_reservation_id'];
516  }
517  return $res;
518  }
519  }
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ getStatus()

ilBookingReservation::getStatus ( )

Get booking status.

Returns
int

Definition at line 139 of file class.ilBookingReservation.php.

References $status.

Referenced by save().

140  {
141  return $this->status;
142  }
+ Here is the caller graph for this function:

◆ getTo()

ilBookingReservation::getTo ( )

Get booking to date.

Returns
int

Definition at line 114 of file class.ilBookingReservation.php.

References $to.

Referenced by save().

115  {
116  return $this->to;
117  }
+ Here is the caller graph for this function:

◆ getUserFilter()

static ilBookingReservation::getUserFilter ( array  $a_object_ids)
static

Get all users who have reservations for object(s)

Parameters
array$a_object_ids
Returns
array

Definition at line 736 of file class.ilBookingReservation.php.

References $ilDB, $res, $row, and array.

Referenced by ilBookingReservationsTableGUI\initFilter().

737  {
738  global $ilDB;
739 
740  $res = array();
741 
742  $sql = "SELECT ud.usr_id,ud.lastname,ud.firstname,ud.login".
743  " FROM usr_data ud ".
744  " LEFT JOIN booking_reservation r ON (r.user_id = ud.usr_id)".
745  " WHERE ud.usr_id <> ".$ilDB->quote(ANONYMOUS_USER_ID, "integer").
746  " AND ".$ilDB->in("r.object_id", $a_object_ids, "", "integer").
747  " ORDER BY ud.lastname,ud.firstname";
748  $set = $ilDB->query($sql);
749  while($row = $ilDB->fetchAssoc($set))
750  {
751  $res[$row["usr_id"]] = $row["lastname"].", ".$row["firstname"].
752  " (".$row["login"].")";
753  }
754 
755  return $res;
756  }
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ getUserId()

ilBookingReservation::getUserId ( )

Get booking user id.

Returns
int

Definition at line 78 of file class.ilBookingReservation.php.

References $user_id.

Referenced by save().

+ Here is the caller graph for this function:

◆ isObjectAvailableInPeriod()

static ilBookingReservation::isObjectAvailableInPeriod (   $a_obj_id,
ilBookingSchedule  $a_schedule,
  $a_from,
  $a_to 
)
static

Definition at line 371 of file class.ilBookingReservation.php.

References $from, $ilDB, $row, $to, array, date, ilBookingSchedule\getAvailabilityFrom(), ilBookingSchedule\getAvailabilityTo(), ilBookingSchedule\getDefinition(), ilBookingObject\getNrOfItemsForObjects(), IL_CAL_DATE, IL_CAL_UNIX, and time.

Referenced by ilBookingObjectsTableGUI\getItems().

372  {
373  global $ilDB;
374 
375  if(!$a_from)
376  {
377  $a_from = time();
378  }
379  if(!$a_to)
380  {
381  $a_to = strtotime("+1year", $a_from);
382  }
383 
384  if($a_from > $a_to)
385  {
386  return;
387  }
388 
389  $from = $ilDB->quote($a_from, 'integer');
390  $to = $ilDB->quote($a_to, 'integer');
391 
392  // all bookings in period
393  $set = $ilDB->query('SELECT count(*) cnt'.
394  ' FROM booking_reservation'.
395  ' WHERE object_id = '.$ilDB->quote($a_obj_id, 'integer').
396  ' AND (status IS NULL OR status <> '.$ilDB->quote(self::STATUS_CANCELLED, 'integer').')'.
397  ' AND ((date_from <= '.$from.' AND date_to >= '.$from.')'.
398  ' OR (date_from <= '.$to.' AND date_to >= '.$to.')'.
399  ' OR (date_from >= '.$from.' AND date_to <= '.$to.'))');
400  $row = $ilDB->fetchAssoc($set);
401  $booked_in_period = $row["cnt"];
402 
403  $per_slot = ilBookingObject::getNrOfItemsForObjects(array($a_obj_id));
404  $per_slot = $per_slot[$a_obj_id];
405 
406  // max available nr of items per (week)day
407  $schedule_slots = array();
408  $definition = $a_schedule->getDefinition();
409  $map = array_flip(array("su", "mo", "tu", "we", "th", "fr", "sa"));
410  foreach($definition as $day => $day_slots)
411  {
412  $schedule_slots[$map[$day]] = $day_slots;
413  }
414 
415  $av_from = ($a_schedule->getAvailabilityFrom() && !$a_schedule->getAvailabilityFrom()->isNull())
416  ? $a_schedule->getAvailabilityFrom()->get(IL_CAL_UNIX)
417  : null;
418  $av_to = ($a_schedule->getAvailabilityTo() && !$a_schedule->getAvailabilityTo()->isNull())
419  ? strtotime($a_schedule->getAvailabilityTo()->get(IL_CAL_DATE)." 23:59:59")
420  : null;
421 
422  // sum up max available items in period per (week)day
423  $available_in_period = 0;
424  $loop = 0;
425  while($a_from < $a_to &&
426  ++$loop < 1000)
427  {
428  // any slots for current weekday?
429  $day_slots = $schedule_slots[date("w", $a_from)];
430  if($day_slots)
431  {
432  foreach($day_slots as $slot)
433  {
434  // convert slot to current datetime
435  $slot = explode("-", $slot);
436  $slot_from = strtotime(date("Y-m-d", $a_from)." ".$slot[0]);
437  $slot_to = strtotime(date("Y-m-d", $a_from)." ".$slot[1]);
438 
439  // slot has to be in the future and part of schedule availability
440  if($slot_to > time() &&
441  $slot_from >= $av_from &&
442  $slot_to <= $av_to)
443  {
444  $available_in_period += $per_slot;
445  }
446  }
447  }
448 
449  $a_from += (60*60*24);
450  }
451 
452  return (bool)($available_in_period-$booked_in_period);
453  }
getAvailabilityFrom()
Get availability start.
getAvailabilityTo()
Get availability end.
const IL_CAL_UNIX
static getNrOfItemsForObjects(array $a_obj_ids)
Get nr of available items.
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
getDefinition()
Get definition.
Create styles array
The data for the language used.
const IL_CAL_DATE
global $ilDB
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isObjectAvailableNoSchedule()

static ilBookingReservation::isObjectAvailableNoSchedule (   $a_obj_id)
static

Definition at line 455 of file class.ilBookingReservation.php.

References $ilDB, array, and ilBookingObject\getNrOfItemsForObjects().

Referenced by ilObjBookingPoolGUI\confirmedBookingObject().

456  {
457  global $ilDB;
458 
460  $all = (int)$all[$a_obj_id];
461 
462  $set = $ilDB->query('SELECT COUNT(*) cnt'.
463  ' FROM booking_reservation r'.
464  ' JOIN booking_object o ON (o.booking_object_id = r.object_id)'.
465  ' WHERE (status IS NULL OR status <> '.$ilDB->quote(self::STATUS_CANCELLED, 'integer').')'.
466  ' AND r.object_id = '.$ilDB->quote($a_obj_id, 'integer'));
467  $cnt = $ilDB->fetchAssoc($set);
468  $cnt = (int)$cnt['cnt'];
469 
470  return (bool)($all-$cnt); // #11864
471  }
static getNrOfItemsForObjects(array $a_obj_ids)
Get nr of available items.
Create styles array
The data for the language used.
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isValidStatus()

static ilBookingReservation::isValidStatus (   $a_status)
static

Check if given status is valid.

Parameters
int$a_status
Returns
bool

Definition at line 149 of file class.ilBookingReservation.php.

References array.

Referenced by setStatus().

150  {
151  if(in_array($a_status, array(self::STATUS_IN_USE, self::STATUS_CANCELLED)))
152  {
153  return true;
154  }
155  return false;
156  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ read()

ilBookingReservation::read ( )
protected

Get dataset from db.

Definition at line 179 of file class.ilBookingReservation.php.

References $ilDB, $row, setFrom(), setGroupId(), setObjectId(), setStatus(), setTo(), and setUserId().

Referenced by __construct().

180  {
181  global $ilDB;
182 
183  if($this->id)
184  {
185  $set = $ilDB->query('SELECT *'.
186  ' FROM booking_reservation'.
187  ' WHERE booking_reservation_id = '.$ilDB->quote($this->id, 'integer'));
188  $row = $ilDB->fetchAssoc($set);
189  $this->setUserId($row['user_id']);
190  $this->setObjectId($row['object_id']);
191  $this->setFrom($row['date_from']);
192  $this->setTo($row['date_to']);
193  $this->setStatus($row['status']);
194  $this->setGroupId($row['group_id']);
195  }
196  }
setStatus($a_status)
Set booking status.
setGroupId($a_group_id)
Set group id.
setFrom($a_from)
Set booking from date.
setObjectId($a_object_id)
Set object id.
global $ilDB
setUserId($a_user_id)
Set booking user id.
setTo($a_to)
Set booking to date.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ save()

ilBookingReservation::save ( )

Create new entry in db.

Returns
bool

Definition at line 202 of file class.ilBookingReservation.php.

References $ilDB, getFrom(), getGroupId(), getObjectId(), getStatus(), getTo(), and getUserId().

203  {
204  global $ilDB;
205 
206  if($this->id)
207  {
208  return false;
209  }
210 
211  $this->id = $ilDB->nextId('booking_reservation');
212 
213  return $ilDB->manipulate('INSERT INTO booking_reservation'.
214  ' (booking_reservation_id,user_id,object_id,date_from,date_to,status,group_id)'.
215  ' VALUES ('.$ilDB->quote($this->id, 'integer').
216  ','.$ilDB->quote($this->getUserId(), 'integer').
217  ','.$ilDB->quote($this->getObjectId(), 'integer').
218  ','.$ilDB->quote($this->getFrom(), 'integer').
219  ','.$ilDB->quote($this->getTo(), 'integer').
220  ','.$ilDB->quote($this->getStatus(), 'integer').
221  ','.$ilDB->quote($this->getGroupId(), 'integer').')');
222  }
getStatus()
Get booking status.
getFrom()
Get booking from date.
global $ilDB
getUserId()
Get booking user id.
getTo()
Get booking to date.
+ Here is the call graph for this function:

◆ setFrom()

ilBookingReservation::setFrom (   $a_from)

Set booking from date.

Parameters
int$a_from

Definition at line 87 of file class.ilBookingReservation.php.

Referenced by read().

88  {
89  $this->from = (int)$a_from;
90  }
+ Here is the caller graph for this function:

◆ setGroupId()

ilBookingReservation::setGroupId (   $a_group_id)

Set group id.

Parameters
int$a_group_id

Definition at line 162 of file class.ilBookingReservation.php.

Referenced by read().

163  {
164  $this->group_id = $a_group_id;
165  }
+ Here is the caller graph for this function:

◆ setObjectId()

ilBookingReservation::setObjectId (   $a_object_id)

Set object id.

Parameters
int$a_object_id

Definition at line 51 of file class.ilBookingReservation.php.

Referenced by read().

52  {
53  $this->object_id = $a_object_id;
54  }
+ Here is the caller graph for this function:

◆ setStatus()

ilBookingReservation::setStatus (   $a_status)

Set booking status.

Parameters
int$a_status

Definition at line 123 of file class.ilBookingReservation.php.

References isValidStatus().

Referenced by ilCalendarAppointmentGUI\cancelConfirmed(), and read().

124  {
125  if($a_status === NULL)
126  {
127  $this->status = NULL;
128  }
129  if($this->isValidStatus((int)$a_status))
130  {
131  $this->status = (int)$a_status;
132  }
133  }
static isValidStatus($a_status)
Check if given status is valid.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setTo()

ilBookingReservation::setTo (   $a_to)

Set booking to date.

Parameters
int$a_to

Definition at line 105 of file class.ilBookingReservation.php.

References to.

Referenced by read().

106  {
107  $this->to = (int)$a_to;
108  }
File written to
+ Here is the caller graph for this function:

◆ setUserId()

ilBookingReservation::setUserId (   $a_user_id)

Set booking user id.

Parameters
int$a_user_id

Definition at line 69 of file class.ilBookingReservation.php.

Referenced by read().

70  {
71  $this->user_id = (int)$a_user_id;
72  }
+ Here is the caller graph for this function:

◆ update()

ilBookingReservation::update ( )

Update entry in db.

Returns
bool

Definition at line 228 of file class.ilBookingReservation.php.

References $ilDB.

229  {
230  global $ilDB;
231 
232  if(!$this->id)
233  {
234  return false;
235  }
236 
237  /* there can only be 1
238  if($this->getStatus() == self::STATUS_IN_USE)
239  {
240  $ilDB->manipulate('UPDATE booking_reservation'.
241  ' SET status = '.$ilDB->quote(NULL, 'integer').
242  ' WHERE object_id = '.$ilDB->quote($this->getObjectId(), 'integer').
243  ' AND status = '.$ilDB->quote(self::STATUS_IN_USE, 'integer'));
244  }
245  */
246 
247  return $ilDB->manipulate('UPDATE booking_reservation'.
248  ' SET object_id = '.$ilDB->quote($this->getObjectId(), 'text').
249  ', user_id = '.$ilDB->quote($this->getUserId(), 'integer').
250  ', date_from = '.$ilDB->quote($this->getFrom(), 'integer').
251  ', date_to = '.$ilDB->quote($this->getTo(), 'integer').
252  ', status = '.$ilDB->quote($this->getStatus(), 'integer').
253  ', group_id = '.$ilDB->quote($this->getGroupId(), 'integer').
254  ' WHERE booking_reservation_id = '.$ilDB->quote($this->id, 'integer'));
255  }
global $ilDB

Field Documentation

◆ $from

ilBookingReservation::$from
protected

◆ $group_id

ilBookingReservation::$group_id
protected

Definition at line 20 of file class.ilBookingReservation.php.

Referenced by getGroupId().

◆ $id

ilBookingReservation::$id
protected

Definition at line 14 of file class.ilBookingReservation.php.

Referenced by getAvailableObject(), and getId().

◆ $object_id

ilBookingReservation::$object_id
protected

Definition at line 15 of file class.ilBookingReservation.php.

Referenced by getObjectId().

◆ $status

ilBookingReservation::$status
protected

Definition at line 19 of file class.ilBookingReservation.php.

Referenced by getStatus().

◆ $to

ilBookingReservation::$to
protected

◆ $user_id

ilBookingReservation::$user_id
protected

Definition at line 16 of file class.ilBookingReservation.php.

Referenced by getListByDate(), and getUserId().

◆ STATUS_CANCELLED

◆ STATUS_IN_USE


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