ILIAS  Release_4_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.
 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

Data Fields

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

Protected Member Functions

 getEvents ()
 Read events (will be moved to another class, since only active and/or visible calendars are shown)
 initPeriod (ilDate $seed)
 init period of events

Protected Attributes

 $schedule = array()
 $timezone
 $weekstart
 $hidden_cat = null
 $type = 0
 $subitems_enabled = 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 
)

Constructor.

public

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

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

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

{
global $ilUser,$ilDB;
$this->db = $ilDB;
$this->type = $a_type;
$this->initPeriod($seed);
if(!$a_user_id)
{
$this->user = $ilUser;
}
$this->user_settings = ilCalendarUserSettings::_getInstanceByUserId($this->user->getId());
$this->weekstart = $this->user_settings->getWeekStart();
$this->timezone = $ilUser->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 96 of file class.ilCalendarSchedule.php.

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

calculate

protected

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

References ilCalendarRecurrences\_getRecurrences(), getEvents(), IL_CAL_FKT_GETDATE, and IL_CAL_UNIX.

{
$counter = 0;
foreach($this->getEvents() 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();
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();
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 105 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 117 of file class.ilCalendarSchedule.php.

References $schedule, $start, $timezone, ilDateTime\DAY, elseif(), 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);
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 ? $tmp_schedule : array();
}

+ 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 238 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 $ilUser,$ilDB;
include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
$cats = ilCalendarCategories::_getInstance($ilUser->getId())->getCategories($a_include_subitem_calendars);
$cats = $this->hidden_cat->filterHidden($cats,ilCalendarCategories::_getInstance($ilUser->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 ( )
protected

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

protected

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

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

Referenced by calculate().

{
global $ilUser,$ilDB;
include_once('./Services/Calendar/classes/class.ilCalendarCategories.php');
$cats = ilCalendarCategories::_getInstance($ilUser->getId())->getCategories($this->enabledSubitemCalendars());
$cats = $this->hidden_cat->filterHidden($cats,ilCalendarCategories::_getInstance($ilUser->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 ".
"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)) ".
"AND ".$ilDB->in('ca.cat_id',$cats,false,'integer')." ".
"ORDER BY starta";
$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);
}
}
/*
foreach($events as $event)
{
var_dump("<pre>",$event->getTitle(),"</pre>");
}
*/
return $events ? $events : array();
}

+ 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 324 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 60 of file class.ilCalendarSchedule.php.

ilCalendarSchedule::$end = null
protected

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

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

ilCalendarSchedule::$user_settings = null
protected

Definition at line 59 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: