ILIAS  Release_4_1_x_branch Revision 61804
 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 user type 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.
 save ()
 Create new entry in db.
 update ()
 Update entry in db.
 delete ()
 Delete single entry.

Static Public Member Functions

static isValidStatus ($a_status)
 Check if given status is valid.
static getAvailableObject (array $a_ids, $a_from, $a_to)
 Check if any of given objects are bookable.
static getCurrentOrUpcomingReservation ($a_object_id)
 Get details about object reservation.
static getList ($a_object_ids, $a_limit=10, $a_offset=0, array $filter)
 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

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

References $ilDB.

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

References $ilDB.

{
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 
)
static

Check if any of given objects are bookable.

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

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

References $from, $ilDB, $row, and $to.

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

{
global $ilDB;
$from = $ilDB->quote($a_from, 'integer');
$to = $ilDB->quote($a_to, 'integer');
$set = $ilDB->query('SELECT 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.'))');
$blocked = array();
while($row = $ilDB->fetchAssoc($set))
{
$blocked[] = $row['object_id'];
}
$available = array_diff($a_ids, $blocked);
if(sizeof($available))
{
return array_shift($available);
}
}

+ Here is the caller 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 284 of file class.ilBookingReservation.php.

References $ilDB, and $row.

Referenced by ilBookingObjectsTableGUI\fillRow().

{
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').
' AND object_id = '.$ilDB->quote($a_object_id, 'integer').
' ORDER BY date_from');
$row = $ilDB->fetchAssoc($set);
return $row;
}

+ Here is the caller graph for this function:

ilBookingReservation::getFrom ( )

Get booking from date.

Returns
int

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

References $from.

Referenced by save().

{
return $this->from;
}

+ Here is the caller graph for this function:

ilBookingReservation::getId ( )

Get id.

Returns
int

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

References $id.

{
return $this->id;
}
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 310 of file class.ilBookingReservation.php.

References $ilDB, $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)';
$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['type'])
{
$where[] = 'type_id = '.$ilDB->quote($filter['type'], 'integer');
}
if($filter['status'])
{
if($filter['status'] > 0)
{
$where[] = 'status = '.$ilDB->quote($filter['status'], 'integer');
}
else
{
$where[] = 'status != '.$ilDB->quote(-$filter['status'], 'integer');
}
}
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);
while($row = $ilDB->fetchAssoc($set))
{
$res[] = $row;
}
return array('data'=>$res, 'counter'=>$counter);
}

+ Here is the caller graph for this function:

ilBookingReservation::getObjectId ( )

Get object id.

Returns
int

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

References $object_id.

Referenced by save(), and update().

{
}

+ Here is the caller graph for this function:

ilBookingReservation::getStatus ( )

Get booking status.

Returns
int

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

References $status.

Referenced by save(), and update().

{
return $this->status;
}

+ Here is the caller graph for this function:

ilBookingReservation::getTo ( )

Get booking to date.

Returns
int

Definition at line 113 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 77 of file class.ilBookingReservation.php.

References $user_id.

Referenced by save().

{
}

+ 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 148 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 160 of file class.ilBookingReservation.php.

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

Referenced by __construct().

{
global $ilDB;
if($this->id)
{
$set = $ilDB->query('SELECT object_id,user_id,date_from,date_to,status'.
' 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']);
}
}

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

References $ilDB, getFrom(), 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)'.
' 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').')');
}

+ Here is the call graph for this function:

ilBookingReservation::setFrom (   $a_from)

Set booking from date.

Parameters
int$a_from

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

Referenced by read().

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

+ Here is the caller graph for this function:

ilBookingReservation::setObjectId (   $a_object_id)

Set object id.

Parameters
int$a_object_id

Definition at line 50 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 122 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 104 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 user type id.

Parameters
int$a_user_id

Definition at line 68 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 204 of file class.ilBookingReservation.php.

References $ilDB, getObjectId(), and getStatus().

{
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').
' WHERE booking_reservation_id = '.$ilDB->quote($this->id, 'integer'));
}

+ Here is the call graph for this function:

Field Documentation

ilBookingReservation::$from
protected

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

Referenced by getAvailableObject(), and getFrom().

ilBookingReservation::$id
protected

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

Referenced by 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: