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

Represents a list of calendar appointments (including recurring events) for a specific user in a given time range. More...

+ Collaboration diagram for ilCalendarSchedule:

Public Member Functions

 __construct (ilDate $seed, $a_type, $a_user_id=0, $filter_bookings=false)
 Constructor.
 addSubitemCalendars ($a_status)
 Enable subitem calendars (session calendars for courses)
 enabledSubitemCalendars ()
 Are subitem calendars enabled.
 getByDay (ilDate $a_start, $a_timezone)
 get byday
 calculate ()
 calculate
 getChangedEvents ($a_include_subitem_calendars=false)
 get new/changed events
 getEvents ()
 Read events (will be moved to another class, since only active and/or visible calendars are shown)

Data Fields

const TYPE_DAY = 1
const TYPE_WEEK = 2
const TYPE_MONTH = 3
const TYPE_INBOX = 4

Protected Member Functions

 initPeriod (ilDate $seed)
 init period of events

Protected Attributes

 $schedule = array()
 $timezone
 $weekstart
 $hidden_cat = null
 $type = 0
 $subitems_enabled = false
 $filter_bookings = false
 $start = null
 $end = null
 $user = null
 $user_settings = null
 $db = null

Detailed Description

Represents a list of calendar appointments (including recurring events) for a specific user in a given time range.

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

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

Constructor & Destructor Documentation

ilCalendarSchedule::__construct ( ilDate  $seed,
  $a_type,
  $a_user_id = 0,
  $filter_bookings = false 
)

Constructor.

public

Parameters
ilDateseed date
inttype of schedule (TYPE_DAY,TYPE_WEEK or TYPE_MONTH)
intuser_id

Definition at line 72 of file class.ilCalendarSchedule.php.

References $filter_bookings, $ilDB, ilCalendarUserSettings\_getInstanceByUserId(), ilCalendarHidden\_getInstanceByUserId(), and initPeriod().

{
global $ilUser,$ilDB;
$this->db = $ilDB;
$this->type = $a_type;
$this->initPeriod($seed);
if(!$a_user_id || $a_user_id == $ilUser->getId())
{
$this->user = $ilUser;
}
else
{
$this->user = new ilObjUser($a_user_id);
}
$this->filter_bookings = $filter_bookings;
$this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($this->user->getId());
$this->weekstart = $this->user_settings->getWeekStart();
$this->timezone = $this->user->getTimeZone();
$this->hidden_cat = ilCalendarHidden::_getInstanceByUserId($this->user->getId());
}

+ Here is the call graph for this function:

Member Function Documentation

ilCalendarSchedule::addSubitemCalendars (   $a_status)

Enable subitem calendars (session calendars for courses)

Parameters
@return

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

{
$this->subitems_enabled = $a_status;
}
ilCalendarSchedule::calculate ( )

calculate

protected

Definition at line 168 of file class.ilCalendarSchedule.php.

References $ilDB, ilCalendarCategoryAssignments\_getAppointmentCalendars(), ilCalendarRecurrences\_getRecurrences(), getEvents(), IL_CAL_FKT_GETDATE, and IL_CAL_UNIX.

{
global $ilDB;
$events = $this->getEvents();
// we need category type for booking handling
$ids = array();
foreach($events as $event)
{
$ids[] = $event->getEntryId();
}
include_once('Services/Calendar/classes/class.ilCalendarCategoryAssignments.php');
include_once('Services/Calendar/classes/class.ilCalendarCategory.php');
$cat_types = array();
foreach(array_unique($cat_map) as $cat_id)
{
$cat = new ilCalendarCategory($cat_id);
$cat_types[$cat_id] = $cat->getType();
}
$counter = 0;
foreach($events as $event)
{
// Calculdate recurring events
include_once('Services/Calendar/classes/class.ilCalendarRecurrences.php');
if($recs = ilCalendarRecurrences::_getRecurrences($event->getEntryId()))
{
$duration = $event->getEnd()->get(IL_CAL_UNIX) - $event->getStart()->get(IL_CAL_UNIX);
foreach($recs as $rec)
{
$calc = new ilCalendarRecurrenceCalculator($event,$rec);
foreach($calc->calculateDateList($this->start,$this->end)->get() as $rec_date)
{
$this->schedule[$counter]['event'] = $event;
$this->schedule[$counter]['dstart'] = $rec_date->get(IL_CAL_UNIX);
$this->schedule[$counter]['dend'] = $this->schedule[$counter]['dstart'] + $duration;
$this->schedule[$counter]['fullday'] = $event->isFullday();
$this->schedule[$counter]['category_id'] = $cat_map[$event->getEntryId()];
$this->schedule[$counter]['category_type'] = $cat_types[$cat_map[$event->getEntryId()]];
switch($this->type)
{
case self::TYPE_DAY:
case self::TYPE_WEEK:
// store date info (used for calculation of overlapping events)
$tmp_date = new ilDateTime($this->schedule[$counter]['dstart'],IL_CAL_UNIX,$this->timezone);
$this->schedule[$counter]['start_info'] = $tmp_date->get(IL_CAL_FKT_GETDATE,'',$this->timezone);
$tmp_date = new ilDateTime($this->schedule[$counter]['dend'],IL_CAL_UNIX,$this->timezone);
$this->schedule[$counter]['end_info'] = $tmp_date->get(IL_CAL_FKT_GETDATE,'',$this->timezone);
break;
default:
break;
}
$counter++;
}
}
}
else
{
$this->schedule[$counter]['event'] = $event;
$this->schedule[$counter]['dstart'] = $event->getStart()->get(IL_CAL_UNIX);
$this->schedule[$counter]['dend'] = $event->getEnd()->get(IL_CAL_UNIX);
$this->schedule[$counter]['fullday'] = $event->isFullday();
$this->schedule[$counter]['category_id'] = $cat_map[$event->getEntryId()];
$this->schedule[$counter]['category_type'] = $cat_types[$cat_map[$event->getEntryId()]];
if(!$event->isFullday())
{
switch($this->type)
{
case self::TYPE_DAY:
case self::TYPE_WEEK:
// store date info (used for calculation of overlapping events)
$tmp_date = new ilDateTime($this->schedule[$counter]['dstart'],IL_CAL_UNIX,$this->timezone);
$this->schedule[$counter]['start_info'] = $tmp_date->get(IL_CAL_FKT_GETDATE,'',$this->timezone);
$tmp_date = new ilDateTime($this->schedule[$counter]['dend'],IL_CAL_UNIX,$this->timezone);
$this->schedule[$counter]['end_info'] = $tmp_date->get(IL_CAL_FKT_GETDATE,'',$this->timezone);
break;
default:
break;
}
}
$counter++;
}
}
}

+ Here is the call graph for this function:

ilCalendarSchedule::enabledSubitemCalendars ( )

Are subitem calendars enabled.

Returns

Definition at line 111 of file class.ilCalendarSchedule.php.

References $subitems_enabled.

Referenced by getEvents().

{
return (bool) $this->subitems_enabled;
}

+ Here is the caller graph for this function:

ilCalendarSchedule::getByDay ( ilDate  $a_start,
  $a_timezone 
)

get byday

public

Parameters
ilDatestart

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

References $schedule, $start, $timezone, ilDateTime\DAY, ilDate\get(), ilDateTime\get(), IL_CAL_DATETIME, IL_CAL_UNIX, and ilDateTime\increment().

{
$fstart = new ilDate($a_start->get(IL_CAL_UNIX),IL_CAL_UNIX);
$fend = clone $fstart;
$f_unix_start = $fstart->get(IL_CAL_UNIX);
$f_unix_end = $fend->get(IL_CAL_UNIX);
$unix_start = $start->get(IL_CAL_UNIX);
$start->increment(ilDateTime::DAY,1);
$unix_end = $start->get(IL_CAL_UNIX);
$counter = 0;
$tmp_date = new ilDateTime($unix_start,IL_CAL_UNIX,$this->timezone);
$tmp_schedule = array();
foreach($this->schedule as $schedule)
{
if($schedule['fullday'])
{
if(($f_unix_start == $schedule['dstart']) or
$f_unix_start == $schedule['dend'] or
($f_unix_start > $schedule['dstart'] and $f_unix_end <= $schedule['dend']))
{
$tmp_schedule[] = $schedule;
}
}
elseif(($schedule['dstart'] == $unix_start) or
(($schedule['dstart'] <= $unix_start) and ($schedule['dend'] > $unix_start)) or
(($schedule['dstart'] >= $unix_start) and ($schedule['dstart'] < $unix_end)))
{
$tmp_schedule[] = $schedule;
}
}
return $tmp_schedule;
}

+ Here is the call graph for this function:

ilCalendarSchedule::getChangedEvents (   $a_include_subitem_calendars = false)

get new/changed events

Parameters
bool$a_include_subitem_calendarsE.g include session calendars of courses.
Returns
object $events[] Array of changed events protected

Definition at line 269 of file class.ilCalendarSchedule.php.

References $ilDB, $query, $res, $row, $start, ilCalendarCategories\_getInstance(), DB_FETCHMODE_OBJECT, IL_CAL_DATE, IL_CAL_DATETIME, and IL_CAL_MONTH.

{
global $ilDB;
include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
$cats = ilCalendarCategories::_getInstance($this->user->getId())->getCategories($a_include_subitem_calendars);
$cats = $this->hidden_cat->filterHidden($cats,ilCalendarCategories::_getInstance($this->user->getId())->getCategoriesInfo());
if(!count($cats))
{
return array();
}
$start = new ilDate(date('Y-m-d',time()),IL_CAL_DATE);
$start->increment(IL_CAL_MONTH,-1);
$query = "SELECT ce.cal_id cal_id FROM cal_entries ce ".
"JOIN cal_cat_assignments ca ON ca.cal_id = ce.cal_id ".
"WHERE last_update > ".$ilDB->quote($start->get(IL_CAL_DATETIME),'timestamp')." ".
"AND ".$ilDB->in('ca.cat_id',$cats,false,'integer').' '.
"ORDER BY last_update";
$res = $this->db->query($query);
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
if(!$this->hidden_cat->isAppointmentVisible($row->cal_id))
{
$events[] = new ilCalendarEntry($row->cal_id);
}
}
return $events ? $events : array();
}

+ Here is the call graph for this function:

ilCalendarSchedule::getEvents ( )

Read events (will be moved to another class, since only active and/or visible calendars are shown)

protected

Definition at line 308 of file class.ilCalendarSchedule.php.

References $filter_bookings, $ilDB, $query, $res, $row, ilCalendarCategories\_getInstance(), DB_FETCHMODE_OBJECT, enabledSubitemCalendars(), IL_CAL_DATETIME, and IL_CAL_UNIX.

Referenced by calculate().

{
global $ilDB;
include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
$cats = ilCalendarCategories::_getInstance($this->user->getId())->getCategories($this->enabledSubitemCalendars());
if(!$this->filter_bookings)
{
$cats = $this->hidden_cat->filterHidden($cats,ilCalendarCategories::_getInstance($this->user->getId())->getCategoriesInfo());
}
if(!count($cats))
{
return array();
}
// TODO: optimize
$query = "SELECT ce.cal_id cal_id FROM cal_entries ce LEFT JOIN cal_recurrence_rules crr ON ce.cal_id = crr.cal_id ".
"JOIN cal_cat_assignments ca ON ca.cal_id = ce.cal_id ";
if($this->type != self::TYPE_INBOX)
{
$query .= "WHERE ((starta <= ".$this->db->quote($this->end->get(IL_CAL_DATETIME,'','UTC'),'timestamp')." ".
"AND enda >= ".$this->db->quote($this->start->get(IL_CAL_DATETIME,'','UTC'),'timestamp').") ".
"OR (starta <= ".$this->db->quote($this->end->get(IL_CAL_DATETIME,'','UTC'),'timestamp')." ".
"AND NOT rule_id IS NULL)) ";
}
else
{
$date = new ilDateTime(mktime(0, 0, 0), IL_CAL_UNIX);
$query .= "WHERE starta >= ".$this->db->quote($date->get(IL_CAL_DATETIME,'','UTC'),'timestamp');
}
$query .= "AND ".$ilDB->in('ca.cat_id',$cats,false,'integer')." ".
"ORDER BY starta";
$res = $this->db->query($query);
$events = array();
include_once 'Services/Booking/classes/class.ilBookingEntry.php';
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
if(!$this->hidden_cat->isAppointmentVisible($row->cal_id) || $this->filter_bookings)
{
$event = new ilCalendarEntry($row->cal_id);
if(!$this->filter_bookings)
{
$events[] = $event;
}
else
{
$booking = new ilBookingEntry($event->getContextId());
if(!$booking->isBookedOut($row->cal_id, true))
{
$events[] = $event;
}
}
}
}
/*
foreach($events as $event)
{
var_dump("<pre>",$event->getTitle(),"</pre>");
}
*/
return $events;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarSchedule::initPeriod ( ilDate  $seed)
protected

init period of events

protected

Parameters
ilDateseed
Returns

Definition at line 384 of file class.ilCalendarSchedule.php.

References $start, ilCalendarUtil\_getMaxDayOfMonth(), IL_CAL_DATE, IL_CAL_DAY, IL_CAL_FKT_DATE, IL_CAL_FKT_GETDATE, and ilDateTime\increment().

Referenced by __construct().

{
switch($this->type)
{
case self::TYPE_DAY:
$this->start = clone $seed;
$this->end = clone $seed;
$this->start->increment(IL_CAL_DAY,-2);
$this->end->increment(IL_CAL_DAY,2);
break;
case self::TYPE_WEEK:
$this->start = clone $seed;
$start_info = $this->start->get(IL_CAL_FKT_GETDATE,'','UTC');
$day_diff = $this->weekstart - $start_info['isoday'];
if($day_diff == 7)
{
$day_diff = 0;
}
$this->start->increment(IL_CAL_DAY,$day_diff);
$this->start->increment(IL_CAL_DAY,-1);
$this->end = clone $this->start;
$this->end->increment(IL_CAL_DAY,9);
break;
case self::TYPE_MONTH:
$year_month = $seed->get(IL_CAL_FKT_DATE,'Y-m','UTC');
list($year,$month) = explode('-',$year_month);
$this->start = new ilDate($year_month.'-01',IL_CAL_DATE);
$this->start->increment(IL_CAL_DAY,-6);
$this->end = new ilDate($year_month.'-'.ilCalendarUtil::_getMaxDayOfMonth($year,$month),IL_CAL_DATE);
$this->end->increment(IL_CAL_DAY,6);
break;
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

ilCalendarSchedule::$db = null
protected

Definition at line 61 of file class.ilCalendarSchedule.php.

ilCalendarSchedule::$end = null
protected

Definition at line 58 of file class.ilCalendarSchedule.php.

ilCalendarSchedule::$filter_bookings = false
protected

Definition at line 55 of file class.ilCalendarSchedule.php.

Referenced by __construct(), and getEvents().

ilCalendarSchedule::$hidden_cat = null
protected

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

ilCalendarSchedule::$schedule = array()
protected

Definition at line 48 of file class.ilCalendarSchedule.php.

Referenced by getByDay().

ilCalendarSchedule::$start = null
protected

Definition at line 57 of file class.ilCalendarSchedule.php.

Referenced by getByDay(), getChangedEvents(), and initPeriod().

ilCalendarSchedule::$subitems_enabled = false
protected

Definition at line 54 of file class.ilCalendarSchedule.php.

Referenced by enabledSubitemCalendars().

ilCalendarSchedule::$timezone
protected

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

Referenced by getByDay().

ilCalendarSchedule::$type = 0
protected

Definition at line 52 of file class.ilCalendarSchedule.php.

ilCalendarSchedule::$user = null
protected

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

ilCalendarSchedule::$user_settings = null
protected

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

ilCalendarSchedule::$weekstart
protected

Definition at line 50 of file class.ilCalendarSchedule.php.

const ilCalendarSchedule::TYPE_DAY = 1

Definition at line 43 of file class.ilCalendarSchedule.php.

Referenced by ilCalendarDayGUI\show().

const ilCalendarSchedule::TYPE_INBOX = 4
const ilCalendarSchedule::TYPE_MONTH = 3
const ilCalendarSchedule::TYPE_WEEK = 2

Definition at line 44 of file class.ilCalendarSchedule.php.

Referenced by ilCalendarWeekGUI\show().


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