ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilCalendarRecurrenceCalculator Class Reference

Calculates an ilDateList for a given calendar entry and recurrence rule. More...

+ Collaboration diagram for ilCalendarRecurrenceCalculator:

Public Member Functions

 __construct (ilDatePeriod $entry, ilCalendarRecurrenceCalculation $rec)
 public
 calculateDateListByMonth ($a_month, $a_year)
 calculate day list by month(s) uses a cache of calculated recurring events public
 calculateDateList (ilDateTime $a_start, ilDateTime $a_end, $a_limit=-1)
 calculate date list

Protected Member Functions

 isNextIterationRequired (ilDateTime $nextIterationStart)
 Check if another frequence iteration is required.
 adjustTimeZones (ilDateTime $a_start, ilDateTime $a_end)
 Adjust timezone.
 optimizeStartingTime ()
 optimize starting time
 incrementByFrequency ($start)
 increment starting time by frequency
 applyBYMONTHRules (ilDateList $list)
 Apply BYMONTH rules.
 applyBYWEEKNORules (ilDateList $list)
 Apply BYWEEKNO rules (1 to 53 and -1 to -53).
 applyBYYEARDAYRules (ilDateList $list)
 Apply BYYEARDAY rules.
 applyBYMONTHDAYRules (ilDateList $list)
 Apply BYMONTHDAY rules.
 applyBYDAYRules (ilDateList $list)
 Apply BYDAY rules.
 getYearWeekDays (ilDateTime $seed)
 get a list of year week days according to the BYMONTH rule
 getMonthWeekDays ($year, $month)
 get a list of month days
 getWeekWeekDays ($seed_info)
 get weedays of week
 applyBYSETPOSRules (ilDateList $list)
 Apply BYSETPOST rules.
 applyLimits (ilDateList $list)
 Apply limits (count or until)
 applyExclusionDates ()
 initDateList ()
 init date list
 createDate ($a_date, $a_format_type=IL_CAL_UNIX)
 create date
 validateRecurrence ()
 validate recurrence

Protected Attributes

 $timezone = null
 $log = null
 $limit_reached = false
 $valid_dates = null
 $period_start = null
 $period_end = null
 $start = null
 $event = null
 $recurrence = null
 $frequence_context = 0

Detailed Description

Calculates an ilDateList for a given calendar entry and recurrence rule.

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

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

Constructor & Destructor Documentation

ilCalendarRecurrenceCalculator::__construct ( ilDatePeriod  $entry,
ilCalendarRecurrenceCalculation  $rec 
)

public

Parameters
ilDatePeriodinterface ilDatePeriod

Definition at line 64 of file class.ilCalendarRecurrenceCalculator.php.

References $ilLog.

{
global $ilLog;
$this->log = $ilLog;
$this->event = $entry;
$this->recurrence = $rec;
}

Member Function Documentation

ilCalendarRecurrenceCalculator::adjustTimeZones ( ilDateTime  $a_start,
ilDateTime  $a_end 
)
protected

Adjust timezone.

protected

Definition at line 244 of file class.ilCalendarRecurrenceCalculator.php.

References ilTimeZone\_setDefaultTimeZone(), ilDateTime\switchTimeZone(), and ilTimeZone\UTC.

Referenced by calculateDateList().

{
$this->timezone = $this->event->isFullday() ? ilTimeZone::UTC : $this->recurrence->getTimeZone();
$this->period_start = clone $a_start;
$this->period_end = clone $a_end;
$this->start = clone $this->event->getStart();
try
{
if($this->event->isFullday())
{
$this->period_start->switchTimeZone(ilTimeZone::UTC);
$this->period_end->switchTimeZone(ilTimeZone::UTC);
$this->start->switchTimeZone(ilTimeZone::UTC);
}
else
{
$this->period_start->switchTimeZone($this->recurrence->getTimeZone());
$this->period_end->switchTimeZone($this->recurrence->getTimeZone());
$this->start->switchTimeZone($this->recurrence->getTimeZone());
}
return true;
}
{
$this->log->write(__METHOD__.': '.$e->getMessage());
return false;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarRecurrenceCalculator::applyBYDAYRules ( ilDateList  $list)
protected

Apply BYDAY rules.

protected

Parameters
objectilDateList
Returns
object ilDateList

Definition at line 608 of file class.ilCalendarRecurrenceCalculator.php.

References $start, createDate(), ilCalendarRecurrence\FREQ_DAILY, ilCalendarRecurrence\FREQ_MONTHLY, ilCalendarRecurrence\FREQ_WEEKLY, ilCalendarRecurrence\FREQ_YEARLY, ilDateList\get(), getMonthWeekDays(), getWeekWeekDays(), getYearWeekDays(), IL_CAL_DAY, IL_CAL_FKT_DATE, IL_CAL_FKT_GETDATE, and initDateList().

Referenced by calculateDateList().

{
// return unmodified, if no byday rules are available
if(!$this->recurrence->getBYDAYList())
{
return $list;
}
$days_list = $this->initDateList();
// generate a list of e.g all Sundays for the given year
// or e.g a list of all week days in a give month (FREQ = MONTHLY,WEEKLY or DAILY)
foreach($list->get() as $seed)
{
$seed_info = $seed->get(IL_CAL_FKT_GETDATE);
// TODO: maybe not correct in dst cases
$date_info = $seed->get(IL_CAL_FKT_GETDATE);
$date_info['mday'] = 1;
$date_info['mon'] = 1;
$start = $this->createDate($date_info,IL_CAL_FKT_GETDATE);
switch($this->frequence_context)
{
$day_sequence = $this->getYearWeekDays($seed);
break;
$day_sequence = $this->getMonthWeekDays($seed_info['year'],$seed_info['mon']);
break;
// TODO or RFC bug: FREQ>WEEKLY;BYMONTH=1;BYDAY=FR returns FR 1.2.2008
// Ical says: apply BYMONTH rules and after that apply byday rules on that date list.
$day_sequence = $this->getWeekWeekDays($seed_info);
break;
$day_sequence[strtoupper(substr($seed->get(IL_CAL_FKT_DATE,'D'),0,2))] = array($seed_info['yday']);
break;
}
foreach($this->recurrence->getBYDAYList() as $byday)
{
$year_day = array();
$day = strtoupper(substr($byday,-2));
$num_by_day = (int) $byday;
if($num_by_day)
{
if($num_by_day > 0)
{
if(isset($day_sequence[$day][$num_by_day - 1]))
{
$year_day = array($day_sequence[$day][$num_by_day - 1]);
}
}
else
{
if(isset($day_sequence[$day][count($day_sequence[$day]) + $num_by_day]))
{
$year_day = array($day_sequence[$day][count($day_sequence[$day]) + $num_by_day]);
}
}
}
else
{
if(isset($day_sequence[$day]))
{
$year_day = $day_sequence[$day];
}
}
foreach($year_day as $day)
{
switch($this->frequence_context)
{
$tmp_date = clone $start;
$tmp_date->increment(IL_CAL_DAY,$day);
$days_list->add($tmp_date);
break;
}
}
}
}
#echo $days_list;
return $days_list;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarRecurrenceCalculator::applyBYMONTHDAYRules ( ilDateList  $list)
protected

Apply BYMONTHDAY rules.

protected

Definition at line 502 of file class.ilCalendarRecurrenceCalculator.php.

References ilTimeZone\_getInstance(), ilCalendarUtil\_getMaxDayOfMonth(), createDate(), ilDateTime\DAY, ilCalendarRecurrence\FREQ_DAILY, ilCalendarRecurrence\FREQ_MONTHLY, ilCalendarRecurrence\FREQ_WEEKLY, ilCalendarRecurrence\FREQ_YEARLY, ilDateList\get(), IL_CAL_FKT_DATE, IL_CAL_UNIX, and initDateList().

Referenced by calculateDateList().

{
// return unmodified, if no byweekno rules are available
if(!$this->recurrence->getBYMONTHDAYList())
{
return $list;
}
$days_list = $this->initDateList();
foreach($list->get() as $seed)
{
$seed->get(IL_CAL_FKT_DATE,'Y',$this->timezone),
$seed->get(IL_CAL_FKT_DATE,'n',$this->timezone));
/*
$num_days = cal_days_in_month(CAL_GREGORIAN,
$seed->get(IL_CAL_FKT_DATE,'n',$this->timezone),
$seed->get(IL_CAL_FKT_DATE,'Y',$this->timezone));
*/
#$this->log->write(__METHOD__.': Month '.$seed->get(IL_CAL_FKT_DATE,'M',$this->timezone).' has '.$num_days.' days.');
foreach($this->recurrence->getBYMONTHDAYList() as $bymonth_no)
{
$day_no = $bymonth_no < 0 ? ($num_days + $bymonth_no + 1) : $bymonth_no;
if($this->frequence_context != ilCalendarRecurrence::FREQ_YEARLY)
{
if($day_no < 1 or $day_no > $num_days)
{
$this->log->write(__METHOD__.': Ignoring BYMONTHDAY rule: '.$day_no.' for month '.
$seed->get(IL_CAL_FKT_DATE,'M',$this->timezone));
continue;
}
}
$day_diff = $day_no - $seed->get(IL_CAL_FKT_DATE,'j',$this->timezone);
$new_day = $this->createDate($seed->get(IL_CAL_UNIX,'',$this->timezone));
$new_day->increment(ilDateTime::DAY,$day_diff);
switch($this->frequence_context)
{
// Check if day matches
#var_dump("<pre>",$seed->get(IL_CAL_FKT_DATE,'z',$this->timezone),$day_no,"</pre>");
if($seed->get(IL_CAL_FKT_DATE,'j',$this->timezone) == $day_no)
{
$days_list->add($new_day);
}
break;
// Check if week matches
if($seed->get(IL_CAL_FKT_DATE,'W',$this->timezone) == $new_day->get(IL_CAL_FKT_DATE,'W',$this->timezone))
{
$days_list->add($new_day);
}
break;
// seed and new day are in the same month.
$days_list->add($new_day);
break;
$h = $this->event->isFullday() ? 0 : $seed->get(IL_CAL_FKT_DATE,'H',$this->timezone);
$i = $this->event->isFullday() ? 0 : $seed->get(IL_CAL_FKT_DATE,'i',$this->timezone);
$s = $this->event->isFullday() ? 0 : $seed->get(IL_CAL_FKT_DATE,'s',$this->timezone);
$y = $seed->get(IL_CAL_FKT_DATE,'Y',$this->timezone);
// TODO: the chosen monthday has to added to all months
for($month = 1;$month <= 12;$month++)
{
#$num_days = cal_days_in_month(CAL_GREGORIAN,
# $month,
# $y);
$y,
$month);
$day_no = $bymonth_no < 0 ? ($num_days + $bymonth_no + 1) : $bymonth_no;
if($day_no < 1 or $day_no > $num_days)
{
$this->log->write(__METHOD__.': Ignoring BYMONTHDAY rule: '.$day_no.' for month '.$month);
}
else
{
$tz_obj = ilTimeZone::_getInstance($this->timezone);
$tz_obj->switchTZ();
$unix = mktime($h,$i,$s,$month,$day_no,$y);
$tz_obj->restoreTZ();
$new_day = $this->createDate($unix);
$days_list->add($new_day);
}
}
break;
}
}
}
$this->frequence_context = ilCalendarRecurrence::FREQ_DAILY;
return $days_list;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarRecurrenceCalculator::applyBYMONTHRules ( ilDateList  $list)
protected

Apply BYMONTH rules.

protected

Returns
object ilDateList

Definition at line 342 of file class.ilCalendarRecurrenceCalculator.php.

References createDate(), ilCalendarRecurrence\FREQ_MONTHLY, ilCalendarRecurrence\FREQ_YEARLY, ilDateList\get(), IL_CAL_FKT_DATE, IL_CAL_UNIX, initDateList(), and ilDateTime\MONTH.

Referenced by calculateDateList().

{
// return unmodified, if no bymonth rules are available
if(!$this->recurrence->getBYMONTHList())
{
return $list;
}
$month_list = $this->initDateList();
foreach($list->get() as $date)
{
#echo "SEED: ".$seed;
foreach($this->recurrence->getBYMONTHList() as $month)
{
#echo "RULW_MONTH:".$month;
// YEARLY rules extend the seed to every month given in the BYMONTH rule
// Rules < YEARLY must match the month of the seed
if($this->recurrence->getFrequenceType() == ilCalendarRecurrence::FREQ_YEARLY)
{
$month_date = $this->createDate($date->get(IL_CAL_UNIX,'',$this->timezone));
$month_date->increment(ilDateTime::MONTH,-($date->get(IL_CAL_FKT_DATE,'n',$this->timezone) - $month));
#echo "BYMONTH: ".$month_date;
$month_list->add($month_date);
}
elseif($date->get(IL_CAL_FKT_DATE,'n',$this->timezone) == $month)
{
$month_list->add($date);
}
}
}
// decrease the frequence_context for YEARLY rules
if($this->recurrence->getFrequenceType() == ilCalendarRecurrence::FREQ_YEARLY)
{
$this->frequence_context = ilCalendarRecurrence::FREQ_MONTHLY;
}
return $month_list;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarRecurrenceCalculator::applyBYSETPOSRules ( ilDateList  $list)
protected

Apply BYSETPOST rules.

protected

Parameters
objectilDateList
Returns
object ilDateList

Definition at line 800 of file class.ilCalendarRecurrenceCalculator.php.

References ilDateList\get(), ilDateList\getAtPosition(), initDateList(), and ilDateList\sort().

Referenced by calculateDateList().

{
// return unmodified, if no bysetpos rules are available
if(!$this->recurrence->getBYSETPOSList())
{
return $list;
}
$pos_list = $this->initDateList();
$list->sort();
$candidates = $list->get();
$candidates_count = count($candidates);
foreach($this->recurrence->getBYSETPOSList() as $position)
{
if($position > 0 and $date = $list->getAtPosition($position))
{
$pos_list->add($date);
}
if($position < 0 and $date = $list->getAtPosition($candidates_count + $position + 1))
{
$pos_list->add($date);
}
}
return $pos_list;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarRecurrenceCalculator::applyBYWEEKNORules ( ilDateList  $list)
protected

Apply BYWEEKNO rules (1 to 53 and -1 to -53).

This rule can only be applied to YEARLY rules (RFC 2445 4.3.10)

protected

Definition at line 388 of file class.ilCalendarRecurrenceCalculator.php.

References createDate(), ilCalendarRecurrence\FREQ_MONTHLY, ilCalendarRecurrence\FREQ_WEEKLY, ilCalendarRecurrence\FREQ_YEARLY, ilDateList\get(), IL_CAL_FKT_DATE, IL_CAL_UNIX, initDateList(), and ilDateTime\WEEK.

Referenced by calculateDateList().

{
if($this->recurrence->getFrequenceType() != ilCalendarRecurrence::FREQ_YEARLY)
{
return $list;
}
// return unmodified, if no byweekno rules are available
if(!$this->recurrence->getBYWEEKNOList())
{
return $list;
}
$weeks_list = $this->initDateList();
foreach($list->get() as $seed)
{
$weeks_in_year = date('W',mktime(0,0,0,12,28,$seed->get(IL_CAL_FKT_DATE,'Y',$this->timezone)));
$this->log->write(__METHOD__.': Year '.$seed->get(IL_CAL_FKT_DATE,'Y',$this->timezone).' has '.$weeks_in_year.' weeks');
foreach($this->recurrence->getBYWEEKNOList() as $week_no)
{
$week_no = $week_no < 0 ? ($weeks_in_year + $week_no + 1) : $week_no;
switch($this->frequence_context)
{
$this->log->write(__METHOD__.': Handling BYWEEKNO in MONTHLY context');
// Check if week matches
if($seed->get(IL_CAL_FKT_DATE,'W',$this->timezone) == $week_no)
{
$weeks_list->add($seed);
}
break;
$this->log->write(__METHOD__.': Handling BYWEEKNO in YEARLY context');
$week_diff = $week_no - $seed->get(IL_CAL_FKT_DATE,'W',$this->timezone);
// TODO: think about tz here
$new_week = $this->createDate($seed->get(IL_CAL_UNIX,'',$this->timezone));
$new_week->increment(ilDateTime::WEEK,$week_diff);
$weeks_list->add($new_week);
break;
}
}
}
$this->frequence_context = ilCalendarRecurrence::FREQ_WEEKLY;
return $weeks_list;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarRecurrenceCalculator::applyBYYEARDAYRules ( ilDateList  $list)
protected

Apply BYYEARDAY rules.

protected

Definition at line 441 of file class.ilCalendarRecurrenceCalculator.php.

References createDate(), ilDateTime\DAY, ilCalendarRecurrence\FREQ_DAILY, ilCalendarRecurrence\FREQ_MONTHLY, ilCalendarRecurrence\FREQ_WEEKLY, ilCalendarRecurrence\FREQ_YEARLY, ilDateList\get(), IL_CAL_FKT_DATE, IL_CAL_UNIX, and initDateList().

Referenced by calculateDateList().

{
// return unmodified, if no byweekno rules are available
if(!$this->recurrence->getBYYEARDAYList())
{
return $list;
}
$days_list = $this->initDateList();
foreach($list->get() as $seed)
{
$num_days = date('z',mktime(0,0,0,12,31,$seed->get(IL_CAL_FKT_DATE,'Y',$this->timezone)));
$this->log->write(__METHOD__.': Year '.$seed->get(IL_CAL_FKT_DATE,'Y',$this->timezone).' has '.$num_days.' days.');
foreach($this->recurrence->getBYYEARDAYList() as $day_no)
{
$day_no = $day_no < 0 ? ($num_days + $day_no + 1) : $day_no;
$day_diff = $day_no - $seed->get(IL_CAL_FKT_DATE,'z',$this->timezone);
$new_day = $this->createDate($seed->get(IL_CAL_UNIX,'',$this->timezone));
$new_day->increment(ilDateTime::DAY,$day_diff);
switch($this->frequence_context)
{
// Check if day matches
if($seed->get(IL_CAL_FKT_DATE,'z',$this->timezone) == $day_no)
{
$days_list->add($new_day);
}
break;
// Check if week matches
if($seed->get(IL_CAL_FKT_DATE,'W',$this->timezone) == $new_day->get(IL_CAL_FKT_DATE,'W',$this->timezone))
{
$days_list->add($new_day);
}
break;
// Check if month matches
if($seed->get(IL_CAL_FKT_DATE,'n',$this->timezone) == $new_day->get(IL_CAL_FKT_DATE,'n',$this->timezone))
{
$days_list->add($new_day);
}
break;
// Simply add
$day_list->add($new_day);
break;
}
}
}
$this->frequence_context = ilCalendarRecurrence::FREQ_DAILY;
return $days_list;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarRecurrenceCalculator::applyExclusionDates ( )
protected
Parameters
ilDateList$list
Returns

Definition at line 897 of file class.ilCalendarRecurrenceCalculator.php.

Referenced by calculateDateList().

{
if(!$this->recurrence->getExclusionDates())
{
return true;
}
foreach($this->recurrence->getExclusionDates() as $excl)
{
$this->valid_dates->removeByDAY($excl->getDate());
}
}

+ Here is the caller graph for this function:

ilCalendarRecurrenceCalculator::applyLimits ( ilDateList  $list)
protected

Apply limits (count or until)

protected

Parameters
objectilDateList

Definition at line 832 of file class.ilCalendarRecurrenceCalculator.php.

References $res, ilDateTime\_after(), ilDateTime\_before(), ilDateList\get(), IL_CAL_DAY, ilDateList\remove(), and ilDateList\sort().

Referenced by calculateDateList().

{
$list->sort();
#echo "list: ";
#echo $list;
#echo '<br />';
// Check valid dates before starting time
foreach($list->get() as $check_date)
{
if(ilDateTime::_before($check_date,$this->event->getStart(),IL_CAL_DAY))
{
#echo 'Removed: '.$check_date.'<br/>';
$list->remove($check_date);
}
}
#echo 'Until date '.$this->recurrence->getFrequenceUntilDate();
// Check count if given
if($this->recurrence->getFrequenceUntilCount())
{
foreach($list->get() as $res)
{
// check smaller than since the start time counts as one
if(count($this->valid_dates->get()) < $this->recurrence->getFrequenceUntilCount())
{
$this->valid_dates->add($res);
}
else
{
$this->limit_reached = true;
return false;
}
}
return true;
}
elseif($this->recurrence->getFrequenceUntilDate())
{
#echo 'Until date '.$this->recurrence->getFrequenceUntilDate();
$date = $this->recurrence->getFrequenceUntilDate();
foreach($list->get() as $res)
{
#echo 'Check date '.$res;
{
#echo 'Limit reached';
$this->limit_reached = true;
return false;
}
$this->valid_dates->add($res);
}
return true;
}
$this->valid_dates->merge($list);
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarRecurrenceCalculator::calculateDateList ( ilDateTime  $a_start,
ilDateTime  $a_end,
  $a_limit = -1 
)

calculate date list

public

Parameters
objectilDateTime start of period
objectilDateTime end of period
intlimit number of returned dates
Returns
object ilDateList

Definition at line 96 of file class.ilCalendarRecurrenceCalculator.php.

References $period_end, $period_start, $start, $valid_dates, ilDateTime\_after(), ilDateTime\_before(), ilDateTime\_equals(), ilTimeZone\_restoreDefaultTimeZone(), adjustTimeZones(), applyBYDAYRules(), applyBYMONTHDAYRules(), applyBYMONTHRules(), applyBYSETPOSRules(), applyBYWEEKNORules(), applyBYYEARDAYRules(), applyExclusionDates(), applyLimits(), IL_CAL_DAY, incrementByFrequency(), initDateList(), isNextIterationRequired(), optimizeStartingTime(), and validateRecurrence().

Referenced by ilConsultationHoursGUI\createAppointments(), and ilObjSessionGUI\createRecurringSessions().

{
#echo $a_start;
#echo $a_end;
#echo $this->event->getStart();
#echo $this->event->getEnd();
$this->valid_dates = $this->initDateList();
// Check invalid settings: e.g no frequence given, invalid start/end dates ...
if(!$this->validateRecurrence())
{
$this->valid_dates->add($this->event->getStart());
}
// Performance fix: Switching the timezone for many dates seems to be
// quite time consuming.
// Therfore we adjust the timezone of all input dates (start,end, event start)
// to the same tz (UTC for fullday events, Recurrence tz for all others).
$this->adjustTimeZones($a_start,$a_end);
// Add start of event if it is in the period
if((ilDateTime::_after($this->event->getStart(),$this->period_start,IL_CAL_DAY) and
ilDateTime::_before($this->event->getStart(),$this->period_end,IL_CAL_DAY)) or
{
$this->valid_dates->add($this->event->getStart());
}
// Calculate recurrences based on frequency (e.g. MONTHLY)
$time = microtime(true);
#echo "ZEIT: ADJUST: ".(microtime(true) - $time).'<br>';
$counter = 0;
do
{
++$counter;
// initialize context for applied rules
// E.g
// RRULE:FREQ=YEARLY;BYMONTH=1;BYWEEKNO=1,50 => context for BYWERKNO is monthly because it filters to the weeks in JAN
// RRULE:FREQ=YEARLY;BYWEEKNO=1,50 => context for BYWERKNO is yearly because it adds all weeks.
$this->frequence_context = $this->recurrence->getFrequenceType();
$freq_res = $this->initDateList();
$freq_res->add($start);
// Fixed sequence of applying rules (RFC 2445 4.3.10)
$freq_res = $this->applyBYMONTHRules($freq_res);
#echo "BYMONTH: ".$freq_res;
$freq_res = $this->applyBYWEEKNORules($freq_res);
#echo "BYWEEKNO: ".$freq_res;
$freq_res = $this->applyBYYEARDAYRules($freq_res);
#echo "BYYEARDAY: ".$freq_res;
$freq_res = $this->applyBYMONTHDAYRules($freq_res);
#echo "BYMONTHDAY: ".$freq_res;
#$time = microtime(true);
$freq_res = $this->applyBYDAYRules($freq_res);
#echo "ZEIT: ".(microtime(true) - $time);
#echo "BYDAY: ".$freq_res;
$freq_res = $this->applyBYSETPOSRules($freq_res);
#echo "BYSETPOS: ".$freq_res;
$freq_res = $this->applyLimits($freq_res);
#echo $freq_res;
{
break;
}
}
while(true);
$this->valid_dates->sort();
// Restore default timezone
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarRecurrenceCalculator::calculateDateListByMonth (   $a_month,
  $a_year 
)

calculate day list by month(s) uses a cache of calculated recurring events public

Parameters
intmonth
intyear
Returns
object ilDateList

Definition at line 81 of file class.ilCalendarRecurrenceCalculator.php.

{
}
ilCalendarRecurrenceCalculator::createDate (   $a_date,
  $a_format_type = IL_CAL_UNIX 
)
protected

create date

protected

Definition at line 924 of file class.ilCalendarRecurrenceCalculator.php.

Referenced by applyBYDAYRules(), applyBYMONTHDAYRules(), applyBYMONTHRules(), applyBYWEEKNORules(), applyBYYEARDAYRules(), and optimizeStartingTime().

{
if($this->event->isFullday())
{
return new ilDate($a_date,$a_format_type);
}
else
{
// TODO: the timezone for this recurrence must be stored in the db
return new ilDateTime($a_date,$a_format_type,$this->timezone);
}
}

+ Here is the caller graph for this function:

ilCalendarRecurrenceCalculator::getMonthWeekDays (   $year,
  $month 
)
protected

get a list of month days

protected

Parameters
@return

Definition at line 743 of file class.ilCalendarRecurrenceCalculator.php.

References ilCalendarUtil\_getMaxDayOfMonth(), IL_CAL_DATE, and IL_CAL_FKT_GETDATE.

Referenced by applyBYDAYRules().

{
static $month_days = array();
if(isset($month_days[$year][$month]))
{
return $month_days[$year][$month];
}
$month_str = $month < 10 ? ('0'.$month) : $month;
$begin_month = new ilDate($year.'-'.$month_str.'-01',IL_CAL_DATE);
$begin_month_info = $begin_month->get(IL_CAL_FKT_GETDATE);
$days = array(0 => 'SU',1 => 'MO',2 => 'TU',3 => 'WE',4 => 'TH',5 => 'FR',6 => 'SA');
for($i = 0;$i < $begin_month_info['wday'];$i++)
{
next($days);
}
for($i = $begin_month_info['yday']; $i < $begin_month_info['yday'] + ilCalendarUtil::_getMaxDayOfMonth($year,$month) ; $i++)
{
if(($current_day = current($days)) == false)
{
$current_day = reset($days);
}
$month_days[$year][$month][$current_day][] = $i;
next($days);
}
return $month_days[$year][$month];
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarRecurrenceCalculator::getWeekWeekDays (   $seed_info)
protected

get weedays of week

protected

Parameters
@return

Definition at line 780 of file class.ilCalendarRecurrenceCalculator.php.

Referenced by applyBYDAYRules().

{
$days = array(0 => 'SU',1 => 'MO',2 => 'TU',3 => 'WE',4 => 'TH',5 => 'FR',6 => 'SA');
$start_day = $seed_info['yday'] - $seed_info['wday'];
foreach($days as $num => $day)
{
$week_days[$day][] = $start_day++;
}
return $week_days;
}

+ Here is the caller graph for this function:

ilCalendarRecurrenceCalculator::getYearWeekDays ( ilDateTime  $seed)
protected

get a list of year week days according to the BYMONTH rule

protected

Definition at line 708 of file class.ilCalendarRecurrenceCalculator.php.

References $start, ilCalendarUtil\_isLeapYear(), ilDateTime\get(), IL_CAL_DATE, and IL_CAL_FKT_DATE.

Referenced by applyBYDAYRules().

{
$time = microtime(true);
$year_days = array();
$current_year = $seed->get(IL_CAL_FKT_DATE,'Y');
$start = new ilDate($current_year.'-01-01',IL_CAL_DATE);
$offset = $start->get(IL_CAL_FKT_DATE,'w');
$days = array(0 => 'SU',1 => 'MO',2 => 'TU',3 => 'WE',4 => 'TH',5 => 'FR',6 => 'SA');
for($i = 0;$i < $offset;$i++)
{
next($days);
}
$num_days = ilCalendarUtil::_isLeapYear($current_year) ? 366 : 365;
for($i = 0;$i < $num_days;$i++)
{
if(($current_day = current($days)) == false)
{
$current_day = reset($days);
}
$year_days[$current_day][] = $i;
next($days);
}
return $year_days;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarRecurrenceCalculator::incrementByFrequency (   $start)
protected

increment starting time by frequency

protected

Definition at line 307 of file class.ilCalendarRecurrenceCalculator.php.

References $ilLog, $start, ilDateTime\DAY, ilCalendarRecurrence\FREQ_DAILY, ilCalendarRecurrence\FREQ_MONTHLY, ilCalendarRecurrence\FREQ_WEEKLY, ilCalendarRecurrence\FREQ_YEARLY, ilDateTime\MONTH, ilDateTime\WEEK, and ilDateTime\YEAR.

Referenced by calculateDateList(), and optimizeStartingTime().

{
global $ilLog;
switch($this->recurrence->getFrequenceType())
{
$start->increment(ilDateTime::YEAR,$this->recurrence->getInterval());
break;
$start->increment(ilDateTime::MONTH,$this->recurrence->getInterval());
break;
$start->increment(ilDateTime::WEEK,$this->recurrence->getInterval());
break;
$start->increment(ilDateTime::DAY,$this->recurrence->getInterval());
break;
default:
$ilLog->write(__METHOD__.'No frequence defined.');
break;
}
return $start;
}

+ Here is the caller graph for this function:

ilCalendarRecurrenceCalculator::initDateList ( )
protected

init date list

protected

Definition at line 914 of file class.ilCalendarRecurrenceCalculator.php.

References ilDateList\TYPE_DATE, and ilDateList\TYPE_DATETIME.

Referenced by applyBYDAYRules(), applyBYMONTHDAYRules(), applyBYMONTHRules(), applyBYSETPOSRules(), applyBYWEEKNORules(), applyBYYEARDAYRules(), and calculateDateList().

{
return new ilDateList($this->event->isFullday() ? ilDateList::TYPE_DATE : ilDateList::TYPE_DATETIME);
}

+ Here is the caller graph for this function:

ilCalendarRecurrenceCalculator::isNextIterationRequired ( ilDateTime  $nextIterationStart)
protected

Check if another frequence iteration is required.

false if the recurrence limit is reached of if the end date is reached

Returns
bool

Definition at line 196 of file class.ilCalendarRecurrenceCalculator.php.

References ilDateTime\_before(), ilDateTime\_equals(), ilDateTime\DAY, ilCalendarRecurrence\FREQ_DAILY, ilCalendarRecurrence\FREQ_MONTHLY, ilCalendarRecurrence\FREQ_WEEKLY, ilCalendarRecurrence\FREQ_YEARLY, ilDateTime\MONTH, ilDateTime\WEEK, and ilDateTime\YEAR.

Referenced by calculateDateList().

{
// Limit
if($this->limit_reached)
{
return false;
}
// Compare field depends on frequence type.
// E.g:
// appointment SA 2012 01 07 (weekly BYDAY WE)
// period end FR 2012 01 20
//
// The weekly recurrence hast to calculated for the weeek 2012-01-16 - 2012-01-22
// since the resulting appointment is WE 2012-01-25
//
switch($this->recurrence->getFrequenceType())
{
$compare_field = ilDateTime::DAY;
break;
$compare_field = ilDateTime::WEEK;
break;
$compare_field = ilDateTime::MONTH;
break;
$compare_field = ilDateTime::YEAR;
break;
default:
$compare_field = ilDateTime::DAY;
break;
}
return
ilDateTime::_before($nextIterationStart, $this->period_end, $compare_field,$this->timezone) or
ilDateTime::_equals($nextIterationStart, $this->period_end, $compare_field,$this->timezone);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarRecurrenceCalculator::optimizeStartingTime ( )
protected

optimize starting time

protected

Definition at line 281 of file class.ilCalendarRecurrenceCalculator.php.

References $start, ilDateTime\_before(), createDate(), IL_CAL_UNIX, and incrementByFrequency().

Referenced by calculateDateList().

{
$time = microtime(true);
// starting time cannot be optimzed if RRULE UNTIL is given.
// In that case we have to calculate all dates until "UNTIL" is reached.
if($this->recurrence->getFrequenceUntilCount() > 0)
{
// Switch the date to the original defined timzone for this recurrence
return $this->createDate($this->start->get(IL_CAL_UNIX,$this->timezone));
}
$optimized = $start = $this->createDate($this->start->get(IL_CAL_UNIX,$this->timezone));
while(ilDateTime::_before($start,$this->period_start))
{
$optimized = clone $start;
$start = $this->incrementByFrequency($start);
}
return $optimized;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCalendarRecurrenceCalculator::validateRecurrence ( )
protected

validate recurrence

protected

Returns
bool

Definition at line 943 of file class.ilCalendarRecurrenceCalculator.php.

Referenced by calculateDateList().

{
return $this->recurrence->validate();
}

+ Here is the caller graph for this function:

Field Documentation

ilCalendarRecurrenceCalculator::$event = null
protected

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

ilCalendarRecurrenceCalculator::$frequence_context = 0
protected

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

ilCalendarRecurrenceCalculator::$limit_reached = false
protected

Definition at line 46 of file class.ilCalendarRecurrenceCalculator.php.

ilCalendarRecurrenceCalculator::$log = null
protected

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

ilCalendarRecurrenceCalculator::$period_end = null
protected

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

Referenced by calculateDateList().

ilCalendarRecurrenceCalculator::$period_start = null
protected

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

Referenced by calculateDateList().

ilCalendarRecurrenceCalculator::$recurrence = null
protected

Definition at line 53 of file class.ilCalendarRecurrenceCalculator.php.

ilCalendarRecurrenceCalculator::$start = null
protected
ilCalendarRecurrenceCalculator::$timezone = null
protected

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

ilCalendarRecurrenceCalculator::$valid_dates = null
protected

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

Referenced by calculateDateList().


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