ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilBookingEntry Class Reference

Booking definition. More...

+ Collaboration diagram for ilBookingEntry:

Public Member Functions

 __construct ($a_booking_id=0)
 Constructor.
 getId ()
 Get id.
 setObjId ($a_id)
 Set obj id.
 getObjId ()
 get obj id
 setDeadlineHours ($a_hours)
 set deadline hours
 getDeadlineHours ()
 get deadline hours
 setNumberOfBookings ($a_num)
 set number of bookings
 getNumberOfBookings ()
 get number of bookings
 setTargetObjId ($a_obj_id)
 set target object id
 getTargetObjId ()
 get target object id
 save ()
 Save a new booking entry.
 update ()
 Update an existing booking entry.
 delete ()
 Delete.
 isOwner ($a_user_id=NULL)
 check if current (or given) user is entry owner
 getCurrentNumberOfBookings ($a_entry_id)
 get current number of bookings
 getCurrentBookings ($a_entry_id)
 get current bookings
 hasBooked ($a_entry_id, $a_user_id=NULL)
 get current number of bookings
 isBookedOut ($a_entry_id, $a_check_current_user=false)
 get current number of bookings
 book ($a_entry_id, $a_user_id=false)
 book calendar entry for user
 cancelBooking ($a_entry_id, $a_user_id=false)
 cancel calendar booking for user

Static Public Member Functions

static removeObsoleteEntries ()
 Remove unused booking entries.
static getInstanceByCalendarEntryId ($a_id)
 Get instance by calendar entry.
static isBookable (array $a_obj_ids, $a_target_obj_id=NULL)
 Which objects are bookable?

Protected Member Functions

 setId ($a_id)
 Set id.
 read ()
 Read settings from db.

Private Attributes

 $id = 0
 $obj_id = 0
 $deadline = 0
 $num_bookings = 1
 $target_obj_id = NULL

Detailed Description

Booking definition.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 13 of file class.ilBookingEntry.php.

Constructor & Destructor Documentation

ilBookingEntry::__construct (   $a_booking_id = 0)

Constructor.

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

References getId(), read(), and setId().

{
$this->setId($a_booking_id);
if($this->getId())
{
$this->read();
}
}

+ Here is the call graph for this function:

Member Function Documentation

ilBookingEntry::book (   $a_entry_id,
  $a_user_id = false 
)

book calendar entry for user

Parameters
int$a_entry_id
int$a_user_id

Definition at line 396 of file class.ilBookingEntry.php.

References $ilDB, hasBooked(), and ilCalendarMailNotification\TYPE_BOOKING_CONFIRMATION.

Referenced by ilCalendarAppointmentGUI\bookconfirmed().

{
global $ilUser, $ilDB;
if(!$a_user_id)
{
$a_user_id = $ilUser->getId();
}
if(!$this->hasBooked($a_entry_id, $a_user_id))
{
$ilDB->manipulate('INSERT INTO booking_user (entry_id, user_id, tstamp)'.
' VALUES ('.$ilDB->quote($a_entry_id, 'integer').','.
$ilDB->quote($a_user_id, 'integer').','.$ilDB->quote(time(), 'integer').')');
include_once 'Services/Calendar/classes/class.ilCalendarMailNotification.php';
$mail->setAppointmentId($a_entry_id);
$mail->setRecipients(array($a_user_id));
$mail->send();
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilBookingEntry::cancelBooking (   $a_entry_id,
  $a_user_id = false 
)

cancel calendar booking for user

Parameters
int$a_entry_id
int$a_user_id

Definition at line 426 of file class.ilBookingEntry.php.

References $ilDB, hasBooked(), and ilCalendarMailNotification\TYPE_BOOKING_CANCELLATION.

Referenced by ilCalendarAppointmentGUI\cancelConfirmed().

{
global $ilUser, $ilDB;
if(!$a_user_id)
{
$a_user_id = $ilUser->getId();
}
if($this->hasBooked($a_entry_id, $a_user_id))
{
include_once 'Services/Calendar/classes/class.ilCalendarMailNotification.php';
$mail->setAppointmentId($a_entry_id);
$mail->setRecipients(array($a_user_id));
$mail->send();
$ilDB->manipulate('DELETE FROM booking_user'.
' WHERE entry_id = '.$ilDB->quote($a_entry_id, 'integer').
' AND user_id = '.$ilDB->quote($a_user_id, 'integer'));
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilBookingEntry::delete ( )

Delete.

Returns

Definition at line 175 of file class.ilBookingEntry.php.

References $ilDB, $query, and getId().

{
$query = "DELETE FROM booking_entry ".
"WHERE booking_id = ".$ilDB->quote($this->getId(),'integer');
$ilDB->manipulate($query);
return true;
}

+ Here is the call graph for this function:

ilBookingEntry::getCurrentBookings (   $a_entry_id)

get current bookings

Parameters
int$a_entry_id
Returns
array

Definition at line 315 of file class.ilBookingEntry.php.

References $ilDB, $res, and $row.

{
global $ilDB;
$set = $ilDB->query('SELECT user_id FROM booking_user'.
' WHERE entry_id = '.$ilDB->quote($a_entry_id, 'integer'));
$res = array();
while($row = $ilDB->fetchAssoc($set))
{
$res[] = $row['user_id'];
}
return $res;
}
ilBookingEntry::getCurrentNumberOfBookings (   $a_entry_id)

get current number of bookings

Parameters
int$a_entry_id
Returns
int

Definition at line 300 of file class.ilBookingEntry.php.

References $ilDB, and $row.

Referenced by isBookedOut().

{
global $ilDB;
$set = $ilDB->query('SELECT COUNT(*) AS counter FROM booking_user'.
' WHERE entry_id = '.$ilDB->quote($a_entry_id, 'integer'));
$row = $ilDB->fetchAssoc($set);
return (int)$row['counter'];
}

+ Here is the caller graph for this function:

ilBookingEntry::getDeadlineHours ( )

get deadline hours

Returns

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

References $deadline.

Referenced by isBookedOut(), save(), and update().

{
}

+ Here is the caller graph for this function:

ilBookingEntry::getId ( )

Get id.

Returns

Definition at line 49 of file class.ilBookingEntry.php.

References $id.

Referenced by __construct(), ilConsultationHoursGUI\createAppointments(), delete(), read(), save(), and update().

{
return $this->id;
}

+ Here is the caller graph for this function:

static ilBookingEntry::getInstanceByCalendarEntryId (   $a_id)
static

Get instance by calendar entry.

Parameters
int$id
Returns
self

Definition at line 254 of file class.ilBookingEntry.php.

Referenced by ilConsultationHoursGUI\updateMulti().

{
include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
$cal_entry = new ilCalendarEntry($a_id);
$booking_id = $cal_entry->getContextId();
if($booking_id)
{
return new self($booking_id);
}
}

+ Here is the caller graph for this function:

ilBookingEntry::getNumberOfBookings ( )

get number of bookings

Returns

Definition at line 106 of file class.ilBookingEntry.php.

References $num_bookings.

Referenced by isBookedOut(), save(), and update().

{
}

+ Here is the caller graph for this function:

ilBookingEntry::getObjId ( )

get obj id

Returns

Definition at line 68 of file class.ilBookingEntry.php.

References $obj_id.

Referenced by isBookedOut(), isOwner(), save(), and update().

{
return $this->obj_id;
}

+ Here is the caller graph for this function:

ilBookingEntry::getTargetObjId ( )

get target object id

Returns
int

Definition at line 125 of file class.ilBookingEntry.php.

References $target_obj_id.

Referenced by ilConsultationHoursTableGUI\parse(), save(), and update().

{
}

+ Here is the caller graph for this function:

ilBookingEntry::hasBooked (   $a_entry_id,
  $a_user_id = NULL 
)

get current number of bookings

Parameters
int$a_entry_id
int$a_user_id
Returns
bool

Definition at line 335 of file class.ilBookingEntry.php.

References $ilDB, and $row.

Referenced by book(), cancelBooking(), and isBookedOut().

{
global $ilUser, $ilDB;
if(!$a_user_id)
{
$a_user_id = $ilUser->getId();
}
$set = $ilDB->query('SELECT COUNT(*) AS counter FROM booking_user'.
' WHERE entry_id = '.$ilDB->quote($a_entry_id, 'integer').
' AND user_id = '.$ilDB->quote($a_user_id, 'integer'));
$row = $ilDB->fetchAssoc($set);
return (bool)$row['counter'];
}

+ Here is the caller graph for this function:

static ilBookingEntry::isBookable ( array  $a_obj_ids,
  $a_target_obj_id = NULL 
)
static

Which objects are bookable?

Parameters
array$a_obj_ids
int$a_target_obj_id
Returns
array

Definition at line 272 of file class.ilBookingEntry.php.

References $ilDB, $query, and $row.

Referenced by ilCalendarBlockGUI\getHTML().

{
global $ilDB;
if(sizeof($a_obj_ids))
{
$query = 'SELECT DISTINCT(obj_id) FROM booking_entry'.
' WHERE '.$ilDB->in('obj_id', $a_obj_ids, false, 'integer');
if($a_target_obj_id)
{
$query .= ' AND (target_obj_id = '.$ilDB->quote($a_target_obj_id, 'integer').
' OR target_obj_id IS NULL)';
}
$set = $ilDB->query($query);
$all = array();
while($row = $ilDB->fetchAssoc($set))
{
$all[] = $row['obj_id'];
}
return $all;
}
}

+ Here is the caller graph for this function:

ilBookingEntry::isBookedOut (   $a_entry_id,
  $a_check_current_user = false 
)

get current number of bookings

Parameters
int$a_entry_id
bool$a_check_current_user
Returns
bool

Definition at line 357 of file class.ilBookingEntry.php.

References $deadline, getCurrentNumberOfBookings(), getDeadlineHours(), getNumberOfBookings(), getObjId(), hasBooked(), and IL_CAL_UNIX.

{
global $ilUser;
if($this->getNumberOfBookings() == $this->getCurrentNumberOfBookings($a_entry_id))
{
// check against current user
if($a_check_current_user)
{
if($this->hasBooked($a_entry_id))
{
return false;
}
if($ilUser->getId() == $this->getObjId())
{
return false;
}
}
return true;
}
{
include_once 'Services/Calendar/classes/class.ilCalendarEntry.php';
$entry = new ilCalendarEntry($a_entry_id);
if(time()+$deadline > $entry->getStart()->get(IL_CAL_UNIX))
{
return true;
}
}
return false;
}

+ Here is the call graph for this function:

ilBookingEntry::isOwner (   $a_user_id = NULL)

check if current (or given) user is entry owner

Parameters
int$a_user_id
Returns
bool

Definition at line 214 of file class.ilBookingEntry.php.

References getObjId().

{
global $ilUser;
if(!$a_user_id)
{
$a_user_id = $ilUser->getId();
}
if($this->getObjId() == $a_user_id)
{
return true;
}
return false;
}

+ Here is the call graph for this function:

ilBookingEntry::read ( )
protected

Read settings from db.

Returns

Definition at line 187 of file class.ilBookingEntry.php.

References $ilDB, $query, $res, $row, DB_FETCHMODE_ASSOC, getId(), setDeadlineHours(), setNumberOfBookings(), setObjId(), and setTargetObjId().

Referenced by __construct().

{
global $ilDB;
if(!$this->getId())
{
return false;
}
$query = "SELECT * FROM booking_entry ".
"WHERE booking_id = ".$ilDB->quote($this->getId(),'integer');
$res = $ilDB->query($query);
while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
{
$this->setObjId($row['obj_id']);
$this->setDeadlineHours($row['deadline']);
$this->setNumberOfBookings($row['num_bookings']);
$this->setTargetObjId($row['target_obj_id']);
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilBookingEntry::removeObsoleteEntries ( )
static

Remove unused booking entries.

Definition at line 233 of file class.ilBookingEntry.php.

References $ilDB, $row, and ilCalendarCategory\TYPE_CH.

Referenced by ilConsultationHoursGUI\delete(), and ilConsultationHoursGUI\updateMulti().

{
global $ilDB;
$set = $ilDB->query('SELECT DISTINCT(context_id) FROM cal_entries e'.
' JOIN cal_cat_assignments a ON (e.cal_id = a.cal_id)'.
' JOIN cal_categories c ON (a.cat_id = c.cat_id) WHERE c.type = '.$ilDB->quote(ilCalendarCategory::TYPE_CH, 'integer'));
$used = array();
while($row = $ilDB->fetchAssoc($set))
{
$used[] = $row['context_id'];
}
return $ilDB->query('DELETE FROM booking_entry WHERE '.$ilDB->in('booking_id', $used, true, 'integer'));
}

+ Here is the caller graph for this function:

ilBookingEntry::save ( )

Save a new booking entry.

Returns

Definition at line 134 of file class.ilBookingEntry.php.

References $ilDB, $query, getDeadlineHours(), getId(), getNumberOfBookings(), getObjId(), getTargetObjId(), and setId().

{
global $ilDB;
$this->setId($ilDB->nextId('booking_entry'));
$query = 'INSERT INTO booking_entry (booking_id,obj_id,deadline,num_bookings,target_obj_id) '.
"VALUES ( ".
$ilDB->quote($this->getId(),'integer').', '.
$ilDB->quote($this->getObjId(),'integer').', '.
$ilDB->quote($this->getDeadlineHours(),'integer').', '.
$ilDB->quote($this->getNumberOfBookings(),'integer').','.
$ilDB->quote($this->getTargetObjId(),'integer').
") ";
$ilDB->manipulate($query);
return true;
}

+ Here is the call graph for this function:

ilBookingEntry::setDeadlineHours (   $a_hours)

set deadline hours

Parameters
int$a_hours
Returns

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

Referenced by read().

{
$this->deadline = (int)$a_hours;
}

+ Here is the caller graph for this function:

ilBookingEntry::setId (   $a_id)
protected

Set id.

Parameters
int$a_id
Returns

Definition at line 40 of file class.ilBookingEntry.php.

Referenced by __construct(), and save().

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

+ Here is the caller graph for this function:

ilBookingEntry::setNumberOfBookings (   $a_num)

set number of bookings

Parameters
int$a_num
Returns

Definition at line 97 of file class.ilBookingEntry.php.

Referenced by read().

{
$this->num_bookings = (int)$a_num;
}

+ Here is the caller graph for this function:

ilBookingEntry::setObjId (   $a_id)

Set obj id.

Parameters
int$a_id
Returns

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

Referenced by read().

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

+ Here is the caller graph for this function:

ilBookingEntry::setTargetObjId (   $a_obj_id)

set target object id

Parameters
int$a_obj_id
Returns

Definition at line 116 of file class.ilBookingEntry.php.

Referenced by read().

{
$this->target_obj_id = (int)$a_obj_id;
}

+ Here is the caller graph for this function:

ilBookingEntry::update ( )

Update an existing booking entry.

Returns

Definition at line 155 of file class.ilBookingEntry.php.

References $ilDB, $query, getDeadlineHours(), getId(), getNumberOfBookings(), getObjId(), and getTargetObjId().

{
if(!$this->getId())
{
return false;
}
$query = "UPDATE booking_entry SET ".
"SET obj_id = ".$ilDB->quote($this->getObjId(),'integer').", ".
" deadline = ".$ilDB->quote($this->getDeadlineHours(),'integer').", ".
" target_obj_id = ".$ilDB->quote($this->getTargetObjId(),'integer').", ".
" num_bookings = ".$ilDB->quote($this->getNumberOfBookings(),'integer');
$ilDB->manipulate($query);
return true;
}

+ Here is the call graph for this function:

Field Documentation

ilBookingEntry::$deadline = 0
private

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

Referenced by getDeadlineHours(), and isBookedOut().

ilBookingEntry::$id = 0
private

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

Referenced by getId().

ilBookingEntry::$num_bookings = 1
private

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

Referenced by getNumberOfBookings().

ilBookingEntry::$obj_id = 0
private

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

Referenced by getObjId().

ilBookingEntry::$target_obj_id = NULL
private

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

Referenced by getTargetObjId().


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