ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilBookingReservation Class Reference

a booking reservation More...

+ Collaboration diagram for ilBookingReservation:

Public Member Functions

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

Static Public Member Functions

static isValidStatus ($a_status)
 Check if given status is valid.
static getNewGroupId ()
 Get next group id.
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.
static isObjectAvailableNoSchedule ($a_obj_id)
static getCurrentOrUpcomingReservation ($a_object_id)
 Get details about object reservation.
static getObjectReservationForUser ($a_object_id, $a_user_id)
static getList ($a_object_ids, $a_limit=10, $a_offset=0, array $filter)
 List all reservations.
static getGroupedList ($a_object_ids, $a_limit=10, $a_offset=0, array $filter=null, $a_group_id=null)
 List all reservations.
static changeStatus (array $a_ids, $a_status)
 Batch update reservation status.

Data Fields

const STATUS_IN_USE = 2
const STATUS_CANCELLED = 5

Protected Member Functions

 read ()
 Get dataset from db.

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

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().

{
$this->id = (int)$a_id;
$this->read();
}

+ Here is the call graph for this function:

Member Function Documentation

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

Batch update reservation status.

Parameters
array$a_ids
int$a_status
Returns
bool

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

Referenced by ilObjBookingPoolGUI\changeStatusObject().

{
global $ilDB;
if(self::isValidStatus($a_status))
{
return $ilDB->manipulate('UPDATE booking_reservation'.
' SET status = '.$ilDB->quote($a_status, 'integer').
' WHERE '.$ilDB->in('booking_reservation_id', $a_ids, '', 'integer'));
}
}

+ Here is the caller graph for this function:

ilBookingReservation::delete ( )

Delete single entry.

Returns
bool

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

{
global $ilDB;
if($this->id)
{
return $ilDB->manipulate('DELETE FROM booking_reservation'.
' WHERE booking_reservation_id = '.$ilDB->quote($this->id, 'integer'));
}
}
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 $from, $id, $row, $to, and ilBookingObject\getNrOfItemsForObjects().

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

{
global $ilDB;
$from = $ilDB->quote($a_from, 'integer');
$to = $ilDB->quote($a_to, 'integer');
$set = $ilDB->query('SELECT count(*) cnt, object_id'.
' FROM booking_reservation'.
' WHERE '.$ilDB->in('object_id', $a_ids, '', 'integer').
' AND (status IS NULL OR status <> '.$ilDB->quote(self::STATUS_CANCELLED, 'integer').')'.
' AND ((date_from <= '.$from.' AND date_to >= '.$from.')'.
' OR (date_from <= '.$to.' AND date_to >= '.$to.')'.
' OR (date_from >= '.$from.' AND date_to <= '.$to.'))'.
' GROUP BY object_id');
$blocked = $counter = array();
while($row = $ilDB->fetchAssoc($set))
{
if($row['cnt'] >= $nr_map[$row['object_id']])
{
$blocked[] = $row['object_id'];
}
else if($a_return_counter)
{
$counter[$row['object_id']] = (int)$nr_map[$row['object_id']]-(int)$row['cnt'];
}
}
$available = array_diff($a_ids, $blocked);
if(sizeof($available))
{
if($a_return_counter)
{
foreach($a_ids as $id)
{
if(!isset($counter[$id]))
{
$counter[$id] = (int)$nr_map[$id];
}
}
return $counter;
}
else if($a_return_single)
{
return array_shift($available);
}
else
{
return $available;
}
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilBookingReservation::getCalendarEntry ( )

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

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

{
global $ilDB;
include_once 'Services/Calendar/classes/class.ilCalendarCategory.php';
$set = $ilDB->query("SELECT ce.cal_id FROM cal_entries ce".
" JOIN cal_cat_assignments cca ON ce.cal_id = cca.cal_id".
" JOIN cal_categories cc ON cca.cat_id = cc.cat_id".
" JOIN booking_reservation br ON ce.context_id = br.booking_reservation_id".
" WHERE cc.obj_id = ".$ilDB->quote($this->getUserId(),'integer').
" AND br.user_id = ".$ilDB->quote($this->getUserId(),'integer').
" AND cc.type = ".$ilDB->quote(ilCalendarCategory::TYPE_BOOK,'integer').
" AND ce.context_id = ".$ilDB->quote($this->getId(), 'integer'));
$row = $ilDB->fetchAssoc($set);
return $row["cal_id"];
}

+ Here is the call graph for this function:

static ilBookingReservation::getCurrentOrUpcomingReservation (   $a_object_id)
static

Get details about object reservation.

Parameters
int$a_object_id
Returns
array

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

References $row.

{
global $ilDB;
$now = $ilDB->quote(time(), 'integer');
$ilDB->setLimit(1);
$set = $ilDB->query('SELECT user_id, status, date_from, date_to'.
' FROM booking_reservation'.
' WHERE ((date_from <= '.$now.' AND date_to >= '.$now.')'.
' OR date_from > '.$now.')'.
' AND (status <> '.$ilDB->quote(self::STATUS_CANCELLED, 'integer').
' OR STATUS IS NULL) AND object_id = '.$ilDB->quote($a_object_id, 'integer').
' ORDER BY date_from');
$row = $ilDB->fetchAssoc($set);
return $row;
}
ilBookingReservation::getFrom ( )

Get booking from date.

Returns
int

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

References $from.

Referenced by save().

{
return $this->from;
}

+ Here is the caller graph for this function:

static ilBookingReservation::getGroupedList (   $a_object_ids,
  $a_limit = 10,
  $a_offset = 0,
array  $filter = null,
  $a_group_id = null 
)
static

List all reservations.

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

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

References $group_id, $res, and $row.

Referenced by ilBookingReservationsTableGUI\getItems().

{
global $ilDB;
$sql = 'SELECT r.*,o.title'.
' FROM booking_reservation r'.
' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
$where = array($ilDB->in('r.object_id', $a_object_ids, '', 'integer'));
if($filter['status'])
{
if($filter['status'] > 0)
{
$where[] = 'status = '.$ilDB->quote($filter['status'], 'integer');
}
else
{
$where[] = '(status != '.$ilDB->quote(-$filter['status'], 'integer').
' OR status IS NULL)';
}
}
if($filter['from'])
{
$where[] = 'date_from >= '.$ilDB->quote($filter['from'], 'integer');
}
if($filter['to'])
{
$where[] = 'date_to <= '.$ilDB->quote($filter['to'], 'integer');
}
if($a_group_id)
{
$where[] = 'group_id = '.$ilDB->quote(substr($a_group_id, 1), 'integer');
}
if(sizeof($where))
{
$sql .= ' WHERE '.implode(' AND ', $where);
}
$sql .= ' ORDER BY date_from DESC, booking_reservation_id DESC';
$set = $ilDB->query($sql);
$res = $grps = array();
$counter = 0;
while($row = $ilDB->fetchAssoc($set))
{
if($row["group_id"] && !$a_group_id)
{
if(!isset($grps[$row["group_id"]]))
{
$grps[$row["group_id"]] = 1;
$counter++;
}
else
{
$grps[$row["group_id"]]++;
}
}
else
{
$counter++;
}
if($a_group_id || ($counter > $a_offset && sizeof($res) < $a_limit))
{
if($row["group_id"] && !$a_group_id)
{
$group_id = "g".$row["group_id"];
$res[$group_id]["group_id"] = $group_id;
$res[$group_id]["details"][] = $row;
}
else
{
unset($row["group_id"]);
$res[] = $row;
}
}
}
foreach($res as $idx => $item)
{
if(isset($item["details"]))
{
$res[$idx]["date_from"] = null;
$res[$idx]["date_to"] = null;
foreach($item["details"] as $detail)
{
// same for each item
$res[$idx]["user_id"] = $detail["user_id"];
$res[$idx]["object_id"] = $detail["object_id"];
$res[$idx]["title"] = $detail["title"];
$res[$idx]["booking_reservation_id"] = $detail["booking_reservation_id"];
// min/max period
if(!$res[$idx]["date_from"] || $detail["date_from"] < $res[$idx]["date_from"])
{
$res[$idx]["date_from"] = $detail["date_from"];
}
if(!$res[$idx]["date_to"] || $detail["date_to"] > $res[$idx]["date_to"])
{
$res[$idx]["date_to"] = $detail["date_to"];
}
}
if(sizeof($item["details"]) > 1)
{
$res[$idx]["booking_reservation_id"] = $idx;
$res[$idx]["title"] .= " (".sizeof($item["details"]).")";
}
else
{
$res[$idx]["status"] = $detail["status"];
unset($res[$idx]["group_id"]);
}
}
}
return array('data'=>$res, 'counter'=>$counter);
}

+ Here is the caller graph for this function:

ilBookingReservation::getGroupId ( )

Get group id.

Returns
int

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

References $group_id.

Referenced by save().

{
}

+ Here is the caller graph for this function:

ilBookingReservation::getId ( )

Get id.

Returns
int

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

References $id.

Referenced by getCalendarEntry().

{
return $this->id;
}

+ Here is the caller graph for this function:

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 407 of file class.ilBookingReservation.php.

References $res, and $row.

Referenced by ilBookingObjectsTableGUI\fillRow().

{
global $ilDB;
$sql = 'SELECT r.*,o.title'.
' FROM booking_reservation r'.
' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
$count_sql = 'SELECT COUNT(*) AS counter'.
' FROM booking_reservation r'.
' JOIN booking_object o ON (o.booking_object_id = r.object_id)';
$where = array($ilDB->in('r.object_id', $a_object_ids, '', 'integer'));
if($filter['status'])
{
if($filter['status'] > 0)
{
$where[] = 'status = '.$ilDB->quote($filter['status'], 'integer');
}
else
{
$where[] = '(status != '.$ilDB->quote(-$filter['status'], 'integer').
' OR status IS NULL)';
}
}
if($filter['from'])
{
$where[] = 'date_from >= '.$ilDB->quote($filter['from'], 'integer');
}
if($filter['to'])
{
$where[] = 'date_to <= '.$ilDB->quote($filter['to'], 'integer');
}
if(sizeof($where))
{
$sql .= ' WHERE '.implode(' AND ', $where);
$count_sql .= ' WHERE '.implode(' AND ', $where);
}
$set = $ilDB->query($count_sql);
$row = $ilDB->fetchAssoc($set);
$counter = $row['counter'];
$sql .= ' ORDER BY date_from DESC, booking_reservation_id DESC';
$ilDB->setLimit($a_limit, $a_offset);
$set = $ilDB->query($sql);
$res = array();
while($row = $ilDB->fetchAssoc($set))
{
$res[] = $row;
}
return array('data'=>$res, 'counter'=>$counter);
}

+ Here is the caller graph for this function:

static ilBookingReservation::getNewGroupId ( )
static

Get next group id.

Returns
int

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

Referenced by ilObjBookingPoolGUI\confirmedBookingObject().

{
global $ilDB;
return $ilDB->nextId('booking_reservation_group');
}

+ Here is the caller graph for this function:

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:

static ilBookingReservation::getObjectReservationForUser (   $a_object_id,
  $a_user_id 
)
static

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

References $row.

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

{
global $ilDB;
$set = $ilDB->query('SELECT booking_reservation_id FROM booking_reservation'.
' WHERE user_id = '.$ilDB->quote($a_user_id, 'integer').
' AND object_id = '.$ilDB->quote($a_object_id, 'integer').
' AND (status <> '.$ilDB->quote(self::STATUS_CANCELLED, 'integer').
' OR STATUS IS NULL)');
$row = $ilDB->fetchAssoc($set);
return $row['booking_reservation_id'];
}

+ Here is the caller graph for this function:

ilBookingReservation::getStatus ( )

Get booking status.

Returns
int

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

References $status.

Referenced by save().

{
return $this->status;
}

+ Here is the caller graph for this function:

ilBookingReservation::getTo ( )

Get booking to date.

Returns
int

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

References $to.

Referenced by save().

{
return $this->to;
}

+ Here is the caller graph for this function:

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:

static ilBookingReservation::isObjectAvailableNoSchedule (   $a_obj_id)
static

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

References ilBookingObject\getNrOfItemsForObjects().

Referenced by ilObjBookingPoolGUI\confirmedBookingObject().

{
global $ilDB;
$all = ilBookingObject::getNrOfItemsForObjects(array($a_obj_id));
$all = (int)$all[$a_obj_id];
$set = $ilDB->query('SELECT COUNT(*) cnt'.
' FROM booking_reservation r'.
' JOIN booking_object o ON (o.booking_object_id = r.object_id)'.
' WHERE (status IS NULL OR status <> '.$ilDB->quote(self::STATUS_CANCELLED, 'integer').')'.
' AND r.object_id = '.$ilDB->quote($a_obj_id, 'integer'));
$cnt = $ilDB->fetchAssoc($set);
$cnt = (int)$cnt['cnt'];
return (bool)($all-$cnt); // #11864
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

Referenced by setStatus().

{
if(in_array($a_status, array(self::STATUS_IN_USE, self::STATUS_CANCELLED)))
{
return true;
}
return false;
}

+ Here is the caller graph for this function:

ilBookingReservation::read ( )
protected

Get dataset from db.

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

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

Referenced by __construct().

{
global $ilDB;
if($this->id)
{
$set = $ilDB->query('SELECT *'.
' FROM booking_reservation'.
' WHERE booking_reservation_id = '.$ilDB->quote($this->id, 'integer'));
$row = $ilDB->fetchAssoc($set);
$this->setUserId($row['user_id']);
$this->setObjectId($row['object_id']);
$this->setFrom($row['date_from']);
$this->setTo($row['date_to']);
$this->setStatus($row['status']);
$this->setGroupId($row['group_id']);
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilBookingReservation::save ( )

Create new entry in db.

Returns
bool

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

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

{
global $ilDB;
if($this->id)
{
return false;
}
$this->id = $ilDB->nextId('booking_reservation');
return $ilDB->manipulate('INSERT INTO booking_reservation'.
' (booking_reservation_id,user_id,object_id,date_from,date_to,status,group_id)'.
' VALUES ('.$ilDB->quote($this->id, 'integer').
','.$ilDB->quote($this->getUserId(), 'integer').
','.$ilDB->quote($this->getObjectId(), 'integer').
','.$ilDB->quote($this->getFrom(), 'integer').
','.$ilDB->quote($this->getTo(), 'integer').
','.$ilDB->quote($this->getStatus(), 'integer').
','.$ilDB->quote($this->getGroupId(), 'integer').')');
}

+ Here is the call graph for this function:

ilBookingReservation::setFrom (   $a_from)

Set booking from date.

Parameters
int$a_from

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

Referenced by read().

{
$this->from = (int)$a_from;
}

+ Here is the caller graph for this function:

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().

{
$this->group_id = $a_group_id;
}

+ Here is the caller graph for this function:

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().

{
$this->object_id = $a_object_id;
}

+ Here is the caller graph for this function:

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().

{
if($a_status === NULL)
{
$this->status = NULL;
}
if($this->isValidStatus((int)$a_status))
{
$this->status = (int)$a_status;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilBookingReservation::setTo (   $a_to)

Set booking to date.

Parameters
int$a_to

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

Referenced by read().

{
$this->to = (int)$a_to;
}

+ Here is the caller graph for this function:

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().

{
$this->user_id = (int)$a_user_id;
}

+ Here is the caller graph for this function:

ilBookingReservation::update ( )

Update entry in db.

Returns
bool

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

{
global $ilDB;
if(!$this->id)
{
return false;
}
/* there can only be 1
if($this->getStatus() == self::STATUS_IN_USE)
{
$ilDB->manipulate('UPDATE booking_reservation'.
' SET status = '.$ilDB->quote(NULL, 'integer').
' WHERE object_id = '.$ilDB->quote($this->getObjectId(), 'integer').
' AND status = '.$ilDB->quote(self::STATUS_IN_USE, 'integer'));
}
*/
return $ilDB->manipulate('UPDATE booking_reservation'.
' SET object_id = '.$ilDB->quote($this->getObjectId(), 'text').
', user_id = '.$ilDB->quote($this->getUserId(), 'integer').
', date_from = '.$ilDB->quote($this->getFrom(), 'integer').
', date_to = '.$ilDB->quote($this->getTo(), 'integer').
', status = '.$ilDB->quote($this->getStatus(), 'integer').
', group_id = '.$ilDB->quote($this->getGroupId(), 'integer').
' WHERE booking_reservation_id = '.$ilDB->quote($this->id, 'integer'));
}

Field Documentation

ilBookingReservation::$from
protected

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

Referenced by getAvailableObject(), and getFrom().

ilBookingReservation::$group_id
protected

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

Referenced by getGroupedList(), and getGroupId().

ilBookingReservation::$id
protected

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

Referenced by getAvailableObject(), and getId().

ilBookingReservation::$object_id
protected

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

Referenced by getObjectId().

ilBookingReservation::$status
protected

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

Referenced by getStatus().

ilBookingReservation::$to
protected

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

Referenced by getAvailableObject(), and getTo().

ilBookingReservation::$user_id
protected

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

Referenced by getUserId().


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