ILIAS  Release_5_0_x_branch Revision 61816
 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)
 Constructor.
 getEventsLimit ()
 get current limit of events
 setEventsLimit ($a_limit)
 Set events limit.
 addSubitemCalendars ($a_status)
 Enable subitem calendars (session calendars for courses)
 enabledSubitemCalendars ()
 Are subitem calendars enabled.
 addFilter (ilCalendarScheduleFilter $a_filter)
 Add filter.
 getByDay (ilDate $a_start, $a_timezone)
 get byday
 calculate ()
 calculate
 getScheduledEvents ()
 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
const TYPE_PD_UPCOMING = 5

Protected Member Functions

 areEventsLimited ()
 Check if events are limited.
 filterCategories (array $a_cats)
 isValidEventByFilters (ilCalendarEntry $a_event)
 initPeriod (ilDate $seed)
 init period of events

Protected Attributes

 $limit_events = -1
 $schedule = array()
 $timezone
 $weekstart
 $type = 0
 $subitems_enabled = false
 $start = null
 $end = null
 $user = null
 $user_settings = null
 $db = null
 $filters = array()

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 
)

Constructor.

public

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

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

References $ilDB, $ilUser, ilCalendarCategories\_getInstance(), ilCalendarUserSettings\_getInstanceByUserId(), addFilter(), initPeriod(), ilCalendarCategories\MODE_CONSULTATION, and ilCalendarCategories\MODE_PORTFOLIO_CONSULTATION.

{
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->user_settings = ilCalendarUserSettings::_getInstanceByUserId($this->user->getId());
$this->weekstart = $this->user_settings->getWeekStart();
$this->timezone = $this->user->getTimeZone();
// category / event filters
include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
// portfolio does custom filter handling (booking group ids)
{
// consultation hour calendar views do not mind calendar category visibility
{
// this is the "default" filter which handles currently hidden categories for the user
include_once('./Services/Calendar/classes/class.ilCalendarScheduleFilterHidden.php');
$this->addFilter(new ilCalendarScheduleFilterHidden($this->user->getId()));
}
else
{
// handle booking visibility (target object, booked out)
include_once('./Services/Calendar/classes/class.ilCalendarScheduleFilterBookings.php');
$this->addFilter(new ilCalendarScheduleFilterBookings($this->user->getId()));
}
}
}

+ Here is the call graph for this function:

Member Function Documentation

ilCalendarSchedule::addFilter ( ilCalendarScheduleFilter  $a_filter)

Add filter.

Parameters
ilCalendarScheduleFilter$a_filter

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

Referenced by __construct().

{
$this->filters[] = $a_filter;
}

+ Here is the caller graph for this function:

ilCalendarSchedule::addSubitemCalendars (   $a_status)

Enable subitem calendars (session calendars for courses)

Parameters
@return

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

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

Check if events are limited.

Returns
type

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

Referenced by calculate().

{
return $this->limit_events != -1;
}

+ Here is the caller graph for this function:

ilCalendarSchedule::calculate ( )

calculate

protected

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

References ilCalendarCategoryAssignments\_getAppointmentCalendars(), ilCalendarRecurrences\_getRecurrences(), areEventsLimited(), getEvents(), getEventsLimit(), IL_CAL_FKT_GETDATE, IL_CAL_UNIX, and ilUtil\sortArray().

{
$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)
{
if($this->type == self::TYPE_PD_UPCOMING &&
$rec_date->get(IL_CAL_UNIX) < time())
{
continue;
}
$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++;
if($this->type != self::TYPE_PD_UPCOMING &&
$this->areEventsLimited() && $counter >= $this->getEventsLimit())
{
break;
}
}
}
}
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++;
if($this->type != self::TYPE_PD_UPCOMING &&
$this->areEventsLimited() && $counter >= $this->getEventsLimit())
{
break;
}
}
}
if($this->type == self::TYPE_PD_UPCOMING)
{
$this->schedule = ilUtil::sortArray($this->schedule, "dstart", "asc", true);
if($this->areEventsLimited() && sizeof($this->schedule) >= $this->getEventsLimit())
{
$this->schedule = array_slice($this->schedule, 0, $this->getEventsLimit());
}
}
}

+ Here is the call graph for this function:

ilCalendarSchedule::enabledSubitemCalendars ( )

Are subitem calendars enabled.

Returns

Definition at line 160 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::filterCategories ( array  $a_cats)
protected

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

Referenced by getChangedEvents(), and getEvents().

{
if(!sizeof($a_cats))
{
return;
}
foreach($this->filters as $filter)
{
if(sizeof($a_cats))
{
$a_cats = $filter->filterCategories($a_cats);
}
}
return $a_cats;
}

+ Here is the caller graph for this function:

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

get byday

public

Parameters
ilDatestart

Definition at line 182 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 392 of file class.ilCalendarSchedule.php.

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

{
global $ilDB;
include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
$cats = ilCalendarCategories::_getInstance($this->user->getId())->getCategories($a_include_subitem_calendars);
$cats = $this->filterCategories($cats);
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))
{
$event = new ilCalendarEntry($row->cal_id);
if($this->isValidEventByFilters($event))
{
$events[] = $event;
}
}
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 432 of file class.ilCalendarSchedule.php.

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

Referenced by calculate().

{
global $ilDB;
include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
$cats = ilCalendarCategories::_getInstance($this->user->getId())->getCategories($this->enabledSubitemCalendars());
$cats = $this->filterCategories($cats);
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();
while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
{
$event = new ilCalendarEntry($row->cal_id);
if($this->isValidEventByFilters($event))
{
$events[] = $event;
}
}
return $events;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarSchedule::getEventsLimit ( )

get current limit of events

Returns
type

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

References $limit_events.

Referenced by calculate().

{
}

+ Here is the caller graph for this function:

ilCalendarSchedule::getScheduledEvents ( )

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

References $schedule.

{
return (array) $this->schedule;
}
ilCalendarSchedule::initPeriod ( ilDate  $seed)
protected

init period of events

protected

Parameters
ilDateseed
Returns

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

References $start, ilCalendarUtil\_getMaxDayOfMonth(), IL_CAL_DATE, IL_CAL_DAY, IL_CAL_FKT_DATE, IL_CAL_FKT_GETDATE, IL_CAL_MONTH, 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;
case self::TYPE_PD_UPCOMING:
case self::TYPE_INBOX:
$this->start = $seed;
$this->end = clone $this->start;
$this->end->increment(IL_CAL_MONTH,3);
break;
}
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarSchedule::isValidEventByFilters ( ilCalendarEntry  $a_event)
protected

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

References $valid.

Referenced by getChangedEvents(), and getEvents().

{
$valid = true;
foreach($this->filters as $filter)
{
if(!$filter->isValidEvent($a_event))
{
$valid = false;
break;
}
}
return $valid;
}

+ Here is the caller graph for this function:

ilCalendarSchedule::setEventsLimit (   $a_limit)

Set events limit.

Parameters
type$a_limit

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

{
$this->limit_events = $a_limit;
}

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::$filters = array()
protected

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

ilCalendarSchedule::$limit_events = -1
protected

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

Referenced by getEventsLimit().

ilCalendarSchedule::$schedule = array()
protected

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

Referenced by getByDay(), and getScheduledEvents().

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 55 of file class.ilCalendarSchedule.php.

Referenced by enabledSubitemCalendars().

ilCalendarSchedule::$timezone
protected

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

Referenced by getByDay().

ilCalendarSchedule::$type = 0
protected

Definition at line 53 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 52 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_PD_UPCOMING = 5

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

Referenced by ilCalendarBlockGUI\getData().

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: