ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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)
 @access public More...
 
 calculateDateListByMonth ($a_month, $a_year)
 calculate day list by month(s) uses a cache of calculated recurring events @access public More...
 
 calculateDateList (ilDateTime $a_start, ilDateTime $a_end, $a_limit=-1)
 calculate date list More...
 

Protected Member Functions

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

Protected Attributes

 $timezone = null
 
 $log = null
 
 $limit_reached = false
 
 $valid_dates = null
 
 $period_start = null
 
 $period_end = null
 
 $start = null
 
 $event = null
 
 $duration = 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$

@ilCtrl_Calls

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

Constructor & Destructor Documentation

◆ __construct()

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

@access public

Parameters
ilDatePeriodinterface ilDatePeriod

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

66 {
67 $this->log = $GLOBALS['DIC']->logger()->cal();
68 $this->event = $entry;
69 $this->recurrence = $rec;
70
71 $this->duration = $entry->getEnd()->get(IL_CAL_UNIX) - $entry->getStart()->get(IL_CAL_UNIX);
72 }
const IL_CAL_UNIX
getEnd()
Interface method get end.
getStart()
Interface method get start.
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.

References $GLOBALS, ilDatePeriod\getEnd(), ilDatePeriod\getStart(), and IL_CAL_UNIX.

+ Here is the call graph for this function:

Member Function Documentation

◆ adjustTimeZones()

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

Adjust timezone.

@access protected

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

232 {
233 $this->timezone = $this->event->isFullday() ? ilTimeZone::UTC : $this->recurrence->getTimeZone();
234 ilTimeZone::_setDefaultTimeZone($this->timezone);
235
236 $this->period_start = clone $a_start;
237 $this->period_end = clone $a_end;
238 $this->start = clone $this->event->getStart();
239
240 try {
241 if ($this->event->isFullday()) {
242 $this->period_start->switchTimeZone(ilTimeZone::UTC);
243 $this->period_end->switchTimeZone(ilTimeZone::UTC);
244 $this->start->switchTimeZone(ilTimeZone::UTC);
245 } else {
246 $this->period_start->switchTimeZone($this->recurrence->getTimeZone());
247 $this->period_end->switchTimeZone($this->recurrence->getTimeZone());
248 $this->start->switchTimeZone($this->recurrence->getTimeZone());
249 }
250 return true;
251 } catch (ilDateTimeException $e) {
252 $this->log->write(__METHOD__ . ': ' . $e->getMessage());
253 return false;
254 }
255 }
Class for DateTime exceptions.
switchTimeZone($a_timezone_identifier='')
Switch timezone.
static _setDefaultTimeZone($a_tz)
set default timezone

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

Referenced by calculateDateList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ applyBYDAYRules()

ilCalendarRecurrenceCalculator::applyBYDAYRules ( ilDateList  $list)
protected

Apply BYDAY rules.

@access protected

Parameters
objectilDateList
Returns
object ilDateList

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

559 {
560 // return unmodified, if no byday rules are available
561 if (!$this->recurrence->getBYDAYList()) {
562 return $list;
563 }
564
565 $days_list = $this->initDateList();
566
567 // generate a list of e.g all Sundays for the given year
568 // or e.g a list of all week days in a give month (FREQ = MONTHLY,WEEKLY or DAILY)
569 foreach ($list->get() as $seed) {
570 $seed_info = $seed->get(IL_CAL_FKT_GETDATE);
571
572 // TODO: maybe not correct in dst cases
573 $date_info = $seed->get(IL_CAL_FKT_GETDATE);
574 $date_info['mday'] = 1;
575 $date_info['mon'] = 1;
576 $start = $this->createDate($date_info, IL_CAL_FKT_GETDATE);
577
578 switch ($this->frequence_context) {
580 $day_sequence = $this->getYearWeekDays($seed);
581 break;
582
584 $day_sequence = $this->getMonthWeekDays($seed_info['year'], $seed_info['mon']);
585 break;
586
588 // TODO or RFC bug: FREQ>WEEKLY;BYMONTH=1;BYDAY=FR returns FR 1.2.2008
589 // Ical says: apply BYMONTH rules and after that apply byday rules on that date list.
590 $day_sequence = $this->getWeekWeekDays($seed_info);
591 break;
592
594 $day_sequence[strtoupper(substr($seed->get(IL_CAL_FKT_DATE, 'D'), 0, 2))] = array($seed_info['yday']);
595 break;
596
597 }
598 foreach ($this->recurrence->getBYDAYList() as $byday) {
599 $year_day = array();
600 $day = strtoupper(substr($byday, -2));
601 $num_by_day = (int) $byday;
602
603 if ($num_by_day) {
604 if ($num_by_day > 0) {
605 if (isset($day_sequence[$day][$num_by_day - 1])) {
606 $year_day = array($day_sequence[$day][$num_by_day - 1]);
607 }
608 } else {
609 if (isset($day_sequence[$day][count($day_sequence[$day]) + $num_by_day])) {
610 $year_day = array($day_sequence[$day][count($day_sequence[$day]) + $num_by_day]);
611 }
612 }
613 } else {
614 if (isset($day_sequence[$day])) {
615 $year_day = $day_sequence[$day];
616 }
617 }
618 foreach ($year_day as $day) {
619 switch ($this->frequence_context) {
624 $tmp_date = clone $start;
625 $tmp_date->increment(IL_CAL_DAY, $day);
626 $days_list->add($tmp_date);
627 break;
628 }
629 }
630 }
631 }
632 #echo $days_list;
633
634 return $days_list;
635 }
const IL_CAL_FKT_GETDATE
const IL_CAL_FKT_DATE
const IL_CAL_DAY
getMonthWeekDays($year, $month)
get a list of month days
createDate($a_date, $a_format_type=IL_CAL_UNIX)
create date
getYearWeekDays(ilDateTime $seed)
get a list of year week days according to the BYMONTH rule
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41

References $list, $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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ applyBYMONTHDAYRules()

ilCalendarRecurrenceCalculator::applyBYMONTHDAYRules ( ilDateList  $list)
protected

Apply BYMONTHDAY rules.

@access protected

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

463 {
464 // return unmodified, if no byweekno rules are available
465 if (!$this->recurrence->getBYMONTHDAYList()) {
466 return $list;
467 }
468 $days_list = $this->initDateList();
469 foreach ($list->get() as $seed) {
471 $seed->get(IL_CAL_FKT_DATE, 'Y', $this->timezone),
472 $seed->get(IL_CAL_FKT_DATE, 'n', $this->timezone)
473 );
474 /*
475 $num_days = cal_days_in_month(CAL_GREGORIAN,
476 $seed->get(IL_CAL_FKT_DATE,'n',$this->timezone),
477 $seed->get(IL_CAL_FKT_DATE,'Y',$this->timezone));
478 */
479 #$this->log->write(__METHOD__.': Month '.$seed->get(IL_CAL_FKT_DATE,'M',$this->timezone).' has '.$num_days.' days.');
480
481 foreach ($this->recurrence->getBYMONTHDAYList() as $bymonth_no) {
482 $day_no = $bymonth_no < 0 ? ($num_days + $bymonth_no + 1) : $bymonth_no;
483 if ($this->frequence_context != ilCalendarRecurrence::FREQ_YEARLY) {
484 if ($day_no < 1 or $day_no > $num_days) {
485 $this->log->write(__METHOD__ . ': Ignoring BYMONTHDAY rule: ' . $day_no . ' for month ' .
486 $seed->get(IL_CAL_FKT_DATE, 'M', $this->timezone));
487 continue;
488 }
489 }
490 $day_diff = $day_no - $seed->get(IL_CAL_FKT_DATE, 'j', $this->timezone);
491 $new_day = $this->createDate($seed->get(IL_CAL_UNIX, '', $this->timezone));
492 $new_day->increment(ilDateTime::DAY, $day_diff);
493
494 switch ($this->frequence_context) {
496 // Check if day matches
497 #var_dump("<pre>",$seed->get(IL_CAL_FKT_DATE,'z',$this->timezone),$day_no,"</pre>");
498 if ($seed->get(IL_CAL_FKT_DATE, 'j', $this->timezone) == $day_no) {
499 $days_list->add($new_day);
500 }
501 break;
502
504 // Check if week matches
505 if ($seed->get(IL_CAL_FKT_DATE, 'W', $this->timezone) == $new_day->get(IL_CAL_FKT_DATE, 'W', $this->timezone)) {
506 $days_list->add($new_day);
507 }
508 break;
509
511 // seed and new day are in the same month.
512 $days_list->add($new_day);
513 break;
514
516 $h = $this->event->isFullday() ? 0 : $seed->get(IL_CAL_FKT_DATE, 'H', $this->timezone);
517 $i = $this->event->isFullday() ? 0 : $seed->get(IL_CAL_FKT_DATE, 'i', $this->timezone);
518 $s = $this->event->isFullday() ? 0 : $seed->get(IL_CAL_FKT_DATE, 's', $this->timezone);
519 $y = $seed->get(IL_CAL_FKT_DATE, 'Y', $this->timezone);
520
521 // TODO: the chosen monthday has to added to all months
522 for ($month = 1;$month <= 12;$month++) {
523 #$num_days = cal_days_in_month(CAL_GREGORIAN,
524 # $month,
525 # $y);
527 $y,
528 $month
529 );
530 $day_no = $bymonth_no < 0 ? ($num_days + $bymonth_no + 1) : $bymonth_no;
531 if ($day_no < 1 or $day_no > $num_days) {
532 $this->log->write(__METHOD__ . ': Ignoring BYMONTHDAY rule: ' . $day_no . ' for month ' . $month);
533 } else {
534 $tz_obj = ilTimeZone::_getInstance($this->timezone);
535 $tz_obj->switchTZ();
536 $unix = mktime($h, $i, $s, $month, $day_no, $y);
537 $tz_obj->restoreTZ();
538 $new_day = $this->createDate($unix);
539 $days_list->add($new_day);
540 }
541 }
542 break;
543 }
544 }
545 }
546 $this->frequence_context = ilCalendarRecurrence::FREQ_DAILY;
547 return $days_list;
548 }
static _getMaxDayOfMonth($a_year, $a_month)
get max day of month 2008,2 => 29
static _getInstance($a_tz='')
get instance by timezone
$i
Definition: disco.tpl.php:19
$y
Definition: example_007.php:83
$h
$s
Definition: pwgen.php:45

References $h, $i, $list, $s, $y, 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ applyBYMONTHRules()

ilCalendarRecurrenceCalculator::applyBYMONTHRules ( ilDateList  $list)
protected

Apply BYMONTH rules.

@access protected

Returns
object ilDateList

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

323 {
324 // return unmodified, if no bymonth rules are available
325 if (!$this->recurrence->getBYMONTHList()) {
326 return $list;
327 }
328 $month_list = $this->initDateList();
329 foreach ($list->get() as $date) {
330 #echo "SEED: ".$seed;
331
332 foreach ($this->recurrence->getBYMONTHList() as $month) {
333 #echo "RULW_MONTH:".$month;
334
335 // YEARLY rules extend the seed to every month given in the BYMONTH rule
336 // Rules < YEARLY must match the month of the seed
337 if ($this->recurrence->getFrequenceType() == ilCalendarRecurrence::FREQ_YEARLY) {
338 $month_date = $this->createDate($date->get(IL_CAL_UNIX, '', $this->timezone));
339 $month_date->increment(ilDateTime::MONTH, -($date->get(IL_CAL_FKT_DATE, 'n', $this->timezone) - $month));
340
341 #echo "BYMONTH: ".$month_date;
342 $month_list->add($month_date);
343 } elseif ($date->get(IL_CAL_FKT_DATE, 'n', $this->timezone) == $month) {
344 $month_list->add($date);
345 }
346 }
347 }
348 // decrease the frequence_context for YEARLY rules
349 if ($this->recurrence->getFrequenceType() == ilCalendarRecurrence::FREQ_YEARLY) {
350 $this->frequence_context = ilCalendarRecurrence::FREQ_MONTHLY;
351 }
352 return $month_list;
353 }

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

Referenced by calculateDateList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ applyBYSETPOSRules()

ilCalendarRecurrenceCalculator::applyBYSETPOSRules ( ilDateList  $list)
protected

Apply BYSETPOST rules.

@access protected

Parameters
objectilDateList
Returns
object ilDateList

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

727 {
728 // return unmodified, if no bysetpos rules are available
729 if (!$this->recurrence->getBYSETPOSList()) {
730 return $list;
731 }
732 $pos_list = $this->initDateList();
733 $list->sort();
734 $candidates = $list->get();
735 $candidates_count = count($candidates);
736 foreach ($this->recurrence->getBYSETPOSList() as $position) {
737 if ($position > 0 and $date = $list->getAtPosition($position)) {
738 $pos_list->add($date);
739 }
740 if ($position < 0 and $date = $list->getAtPosition($candidates_count + $position + 1)) {
741 $pos_list->add($date);
742 }
743 }
744 return $pos_list;
745 }
sort()
Sort list.

References $list, initDateList(), and ilDateList\sort().

Referenced by calculateDateList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ applyBYWEEKNORules()

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)

@access protected

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

362 {
363 if ($this->recurrence->getFrequenceType() != ilCalendarRecurrence::FREQ_YEARLY) {
364 return $list;
365 }
366 // return unmodified, if no byweekno rules are available
367 if (!$this->recurrence->getBYWEEKNOList()) {
368 return $list;
369 }
370 $weeks_list = $this->initDateList();
371 foreach ($list->get() as $seed) {
372 $weeks_in_year = date('W', mktime(0, 0, 0, 12, 28, $seed->get(IL_CAL_FKT_DATE, 'Y', $this->timezone)));
373 $this->log->write(__METHOD__ . ': Year ' . $seed->get(IL_CAL_FKT_DATE, 'Y', $this->timezone) . ' has ' . $weeks_in_year . ' weeks');
374 foreach ($this->recurrence->getBYWEEKNOList() as $week_no) {
375 $week_no = $week_no < 0 ? ($weeks_in_year + $week_no + 1) : $week_no;
376
377 switch ($this->frequence_context) {
379 $this->log->write(__METHOD__ . ': Handling BYWEEKNO in MONTHLY context');
380 // Check if week matches
381 if ($seed->get(IL_CAL_FKT_DATE, 'W', $this->timezone) == $week_no) {
382 $weeks_list->add($seed);
383 }
384 break;
385
387 $this->log->write(__METHOD__ . ': Handling BYWEEKNO in YEARLY context');
388 $week_diff = $week_no - $seed->get(IL_CAL_FKT_DATE, 'W', $this->timezone);
389
390 // TODO: think about tz here
391 $new_week = $this->createDate($seed->get(IL_CAL_UNIX, '', $this->timezone));
392 $new_week->increment(ilDateTime::WEEK, $week_diff);
393 $weeks_list->add($new_week);
394 break;
395 }
396 }
397 }
398 $this->frequence_context = ilCalendarRecurrence::FREQ_WEEKLY;
399
400 return $weeks_list;
401 }

References $list, 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ applyBYYEARDAYRules()

ilCalendarRecurrenceCalculator::applyBYYEARDAYRules ( ilDateList  $list)
protected

Apply BYYEARDAY rules.

@access protected

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

409 {
410 // return unmodified, if no byweekno rules are available
411 if (!$this->recurrence->getBYYEARDAYList()) {
412 return $list;
413 }
414 $days_list = $this->initDateList();
415 foreach ($list->get() as $seed) {
416 $num_days = date('z', mktime(0, 0, 0, 12, 31, $seed->get(IL_CAL_FKT_DATE, 'Y', $this->timezone)));
417 $this->log->write(__METHOD__ . ': Year ' . $seed->get(IL_CAL_FKT_DATE, 'Y', $this->timezone) . ' has ' . $num_days . ' days.');
418
419 foreach ($this->recurrence->getBYYEARDAYList() as $day_no) {
420 $day_no = $day_no < 0 ? ($num_days + $day_no + 1) : $day_no;
421
422 $day_diff = $day_no - $seed->get(IL_CAL_FKT_DATE, 'z', $this->timezone);
423 $new_day = $this->createDate($seed->get(IL_CAL_UNIX, '', $this->timezone));
424 $new_day->increment(ilDateTime::DAY, $day_diff);
425
426 switch ($this->frequence_context) {
428 // Check if day matches
429 if ($seed->get(IL_CAL_FKT_DATE, 'z', $this->timezone) == $day_no) {
430 $days_list->add($new_day);
431 }
432 break;
434 // Check if week matches
435 if ($seed->get(IL_CAL_FKT_DATE, 'W', $this->timezone) == $new_day->get(IL_CAL_FKT_DATE, 'W', $this->timezone)) {
436 $days_list->add($new_day);
437 }
438 break;
440 // Check if month matches
441 if ($seed->get(IL_CAL_FKT_DATE, 'n', $this->timezone) == $new_day->get(IL_CAL_FKT_DATE, 'n', $this->timezone)) {
442 $days_list->add($new_day);
443 }
444 break;
446 // Simply add
447 $days_list->add($new_day);
448 break;
449 }
450 }
451 }
452
453 $this->frequence_context = ilCalendarRecurrence::FREQ_DAILY;
454 return $days_list;
455 }

References $list, 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ applyDurationPeriod()

ilCalendarRecurrenceCalculator::applyDurationPeriod ( ilDateList  $list,
ilDateTime  $start,
ilDateTime  $end 
)
protected

Apply duration period.

Parameters
ilDateList$list

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

206 {
207 $list_copy = clone $list;
208 foreach ($list_copy as $start_date) {
209 $end_date = clone $start_date;
210 $end_date->increment(ilDateTime::MINUTE, $this->getDuration() / 60);
211
212 if (
213 (
214 ilDateTime::_after($start_date, $this->period_end)
215 ) ||
216 (
217 ilDateTime::_before($end_date, $this->period_start)
218 )
219 ) {
220 $this->log->debug('Removed invalid date ' . (string) $start_date . ' <-> ' . (string) $end_date);
221 $list->remove($start_date);
222 }
223 }
224 }
static _after(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is after end This method does not consider tz offsets.
static _before(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
compare two dates and check start is before end This method does not consider tz offsets.

References $list, ilDateTime\_after(), ilDateTime\_before(), getDuration(), and ilDateTime\MINUTE.

Referenced by calculateDateList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ applyExclusionDates()

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

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

809 {
810 if (!$this->recurrence->getExclusionDates()) {
811 return true;
812 }
813 foreach ($this->recurrence->getExclusionDates() as $excl) {
814 $this->valid_dates->removeByDAY($excl->getDate());
815 }
816 }

Referenced by calculateDateList().

+ Here is the caller graph for this function:

◆ applyLimits()

ilCalendarRecurrenceCalculator::applyLimits ( ilDateList  $list)
protected

Apply limits (count or until)

@access protected

Parameters
objectilDateList

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

755 {
756 $list->sort();
757
758 #echo "list: ";
759 #echo $list;
760 #echo '<br />';
761
762 // Check valid dates before starting time
763 foreach ($list->get() as $check_date) {
764 if (ilDateTime::_before($check_date, $this->event->getStart(), IL_CAL_DAY)) {
765 $this->log->debug('Removed invalid date: ' . (string) $check_date . ' before starting date: ' . (string) $this->event->getStart());
766 $list->remove($check_date);
767 }
768 }
769
770 #echo 'Until date '.$this->recurrence->getFrequenceUntilDate();
771
772 // Check count if given
773 if ($this->recurrence->getFrequenceUntilCount()) {
774 foreach ($list->get() as $res) {
775 // check smaller than since the start time counts as one
776 if (count($this->valid_dates->get()) < $this->recurrence->getFrequenceUntilCount()) {
777 $this->valid_dates->add($res);
778 } else {
779 $this->limit_reached = true;
780 return false;
781 }
782 }
783 return true;
784 } elseif ($this->recurrence->getFrequenceUntilDate()) {
785 #echo 'Until date '.$this->recurrence->getFrequenceUntilDate();
786 $date = $this->recurrence->getFrequenceUntilDate();
787 foreach ($list->get() as $res) {
788 #echo 'Check date '.$res;
789 if (ilDateTime::_after($res, $date, IL_CAL_DAY)) {
790 #echo 'Limit reached';
791 $this->limit_reached = true;
792 return false;
793 }
794 $this->valid_dates->add($res);
795 }
796 return true;
797 }
798
799 $this->valid_dates->merge($list);
800 return true;
801 }
foreach($_POST as $key=> $value) $res

References $list, $res, ilDateTime\_after(), ilDateTime\_before(), and IL_CAL_DAY.

Referenced by calculateDateList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ calculateDateList()

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

calculate date list

@access public

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

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

106 {
107 # echo $a_start;
108 # echo $a_end;
109 # echo $this->event->getStart();
110 # echo $this->event->getEnd();
111
112
113 $this->valid_dates = $this->initDateList();
114
115 // Check invalid settings: e.g no frequence given, invalid start/end dates ...
116 if (!$this->validateRecurrence()) {
117 $this->valid_dates->add($this->event->getStart());
118 return $this->valid_dates;
119 }
120
121 // Performance fix: Switching the timezone for many dates seems to be
122 // quite time consuming.
123 // Therfore we adjust the timezone of all input dates (start,end, event start)
124 // to the same tz (UTC for fullday events, Recurrence tz for all others).
125 $this->adjustTimeZones($a_start, $a_end);
126
127
128
129 // Add start of event if it is in the period
130 if ((ilDateTime::_after($this->event->getStart(), $this->period_start, IL_CAL_DAY) and
131 ilDateTime::_before($this->event->getStart(), $this->period_end, IL_CAL_DAY)) or
132 ilDateTime::_equals($this->event->getStart(), $this->period_start, IL_CAL_DAY)) {
133 // begin-patch aptar
134 $this->valid_dates->add($this->event->getStart());
135 #$this->valid_dates->add($this->event->getStart());
136 // end patch aptar
137 }
138
139 // Calculate recurrences based on frequency (e.g. MONTHLY)
140 $time = microtime(true);
141
142 $start = $this->optimizeStartingTime();
143
144 #echo "ZEIT: ADJUST: ".(microtime(true) - $time).'<br>';
145 $counter = 0;
146 do {
147 ++$counter;
148 // initialize context for applied rules
149 // E.g
150 // RRULE:FREQ=YEARLY;BYMONTH=1;BYWEEKNO=1,50 => context for BYWERKNO is monthly because it filters to the weeks in JAN
151 // RRULE:FREQ=YEARLY;BYWEEKNO=1,50 => context for BYWERKNO is yearly because it adds all weeks.
152 $this->frequence_context = $this->recurrence->getFrequenceType();
153
154 $freq_res = $this->initDateList();
155 $freq_res->add($start);
156
157 // Fixed sequence of applying rules (RFC 2445 4.3.10)
158 $freq_res = $this->applyBYMONTHRules($freq_res);
159 #echo "BYMONTH: ".$freq_res;
160
161 $freq_res = $this->applyBYWEEKNORules($freq_res);
162 #echo "BYWEEKNO: ".$freq_res;
163
164 $freq_res = $this->applyBYYEARDAYRules($freq_res);
165 #echo "BYYEARDAY: ".$freq_res;
166
167
168 $freq_res = $this->applyBYMONTHDAYRules($freq_res);
169 #echo "BYMONTHDAY: ".$freq_res;
170
171 #$time = microtime(true);
172 $freq_res = $this->applyBYDAYRules($freq_res);
173 #echo "ZEIT: ".(microtime(true) - $time);
174 #echo "BYDAY: ".$freq_res;
175
176
177 $freq_res = $this->applyBYSETPOSRules($freq_res);
178 #echo "BYSETPOS: ".$freq_res;
179
180 $freq_res = $this->applyLimits($freq_res);
181 #echo $freq_res;
182
184
185 if (ilDateTime::_after($start, $this->period_end) or $this->limit_reached) {
186 break;
187 }
188 } while (true);
189
190 $this->applyExclusionDates();
191
192 $this->applyDurationPeriod($this->valid_dates, $this->period_start, $this->period_end);
193
194 $this->valid_dates->sort();
195
196 // Restore default timezone
198 return $this->valid_dates;
199 }
applyBYMONTHDAYRules(ilDateList $list)
Apply BYMONTHDAY rules.
applyBYSETPOSRules(ilDateList $list)
Apply BYSETPOST rules.
applyBYMONTHRules(ilDateList $list)
Apply BYMONTH rules.
applyBYYEARDAYRules(ilDateList $list)
Apply BYYEARDAY rules.
incrementByFrequency($start)
increment starting time by frequency
applyLimits(ilDateList $list)
Apply limits (count or until)
adjustTimeZones(ilDateTime $a_start, ilDateTime $a_end)
Adjust timezone.
applyBYWEEKNORules(ilDateList $list)
Apply BYWEEKNO rules (1 to 53 and -1 to -53).
applyDurationPeriod(ilDateList $list, ilDateTime $start, ilDateTime $end)
Apply duration period.
applyBYDAYRules(ilDateList $list)
Apply BYDAY rules.
static _equals(ilDateTime $start, ilDateTime $end, $a_compare_field='', $a_tz='')
Check if two date are equal.
static _restoreDefaultTimeZone()
restore default timezone to server timezone
$time
Definition: cron.php:21

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

+ Here is the call graph for this function:

◆ calculateDateListByMonth()

ilCalendarRecurrenceCalculator::calculateDateListByMonth (   $a_month,
  $a_year 
)

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

Parameters
intmonth
intyear
Returns
object ilDateList

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

92 {
93 }

◆ createDate()

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

create date

@access protected

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

834 {
835 if ($this->event->isFullday()) {
836 return new ilDate($a_date, $a_format_type);
837 } else {
838 // TODO: the timezone for this recurrence must be stored in the db
839 return new ilDateTime($a_date, $a_format_type, $this->timezone);
840 }
841 }
@classDescription Date and time handling
Class for single dates.

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

+ Here is the caller graph for this function:

◆ getDuration()

ilCalendarRecurrenceCalculator::getDuration ( )
protected

Get duration of event.

Returns
type

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

References $duration.

Referenced by applyDurationPeriod().

+ Here is the caller graph for this function:

◆ getMonthWeekDays()

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

get a list of month days

@access protected

Parameters

return

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

675 {
676 static $month_days = array();
677
678 if (isset($month_days[$year][$month])) {
679 return $month_days[$year][$month];
680 }
681
682 $month_str = $month < 10 ? ('0' . $month) : $month;
683 $begin_month = new ilDate($year . '-' . $month_str . '-01', IL_CAL_DATE);
684 $begin_month_info = $begin_month->get(IL_CAL_FKT_GETDATE);
685
686 $days = array(0 => 'SU',1 => 'MO',2 => 'TU',3 => 'WE',4 => 'TH',5 => 'FR',6 => 'SA');
687 for ($i = 0;$i < $begin_month_info['wday'];$i++) {
688 next($days);
689 }
690 for ($i = $begin_month_info['yday']; $i < $begin_month_info['yday'] + ilCalendarUtil::_getMaxDayOfMonth($year, $month) ; $i++) {
691 if (($current_day = current($days)) == false) {
692 $current_day = reset($days);
693 }
694 $month_days[$year][$month][$current_day][] = $i;
695 next($days);
696 }
697 return $month_days[$year][$month];
698 }
const IL_CAL_DATE

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

Referenced by applyBYDAYRules().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getWeekWeekDays()

ilCalendarRecurrenceCalculator::getWeekWeekDays (   $seed_info)
protected

get weedays of week

@access protected

Parameters

return

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

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

Referenced by applyBYDAYRules().

+ Here is the caller graph for this function:

◆ getYearWeekDays()

ilCalendarRecurrenceCalculator::getYearWeekDays ( ilDateTime  $seed)
protected

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

@access protected

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

643 {
644 $time = microtime(true);
645
646 $year_days = array();
647
648 $current_year = $seed->get(IL_CAL_FKT_DATE, 'Y');
649 $start = new ilDate($current_year . '-01-01', IL_CAL_DATE);
650 $offset = $start->get(IL_CAL_FKT_DATE, 'w');
651 $days = array(0 => 'SU',1 => 'MO',2 => 'TU',3 => 'WE',4 => 'TH',5 => 'FR',6 => 'SA');
652 for ($i = 0;$i < $offset;$i++) {
653 next($days);
654 }
655
656 $num_days = ilCalendarUtil::_isLeapYear($current_year) ? 366 : 365;
657 for ($i = 0;$i < $num_days;$i++) {
658 if (($current_day = current($days)) == false) {
659 $current_day = reset($days);
660 }
661 $year_days[$current_day][] = $i;
662 next($days);
663 }
664 return $year_days;
665 }
static _isLeapYear($a_year)
check if a given year is a leap year
get($a_format, $a_format_str='', $a_tz='')
get formatted date

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

Referenced by applyBYDAYRules().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ incrementByFrequency()

ilCalendarRecurrenceCalculator::incrementByFrequency (   $start)
protected

increment starting time by frequency

@access protected

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

287 {
288 global $DIC;
289
290 $logger = $DIC->logger()->cal();
291
292 switch ($this->recurrence->getFrequenceType()) {
294 $start->increment(ilDateTime::YEAR, $this->recurrence->getInterval());
295 break;
296
298 $start->increment(ilDateTime::MONTH, $this->recurrence->getInterval());
299 break;
300
302 $start->increment(ilDateTime::WEEK, $this->recurrence->getInterval());
303 break;
304
306 $start->increment(ilDateTime::DAY, $this->recurrence->getInterval());
307 break;
308
309 default:
310 $logger->warning('No frequence defined.');
311 break;
312 }
313 return $start;
314 }
global $DIC
Definition: saml.php:7

References $DIC, $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().

+ Here is the caller graph for this function:

◆ initDateList()

ilCalendarRecurrenceCalculator::initDateList ( )
protected

init date list

@access protected

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

824 {
825 return new ilDateList($this->event->isFullday() ? ilDateList::TYPE_DATE : ilDateList::TYPE_DATETIME);
826 }
List of dates.

References ilDateList\TYPE_DATE, and ilDateList\TYPE_DATETIME.

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

+ Here is the caller graph for this function:

◆ optimizeStartingTime()

ilCalendarRecurrenceCalculator::optimizeStartingTime ( )
protected

optimize starting time

@access protected

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

263 {
264 $time = microtime(true);
265
266 // starting time cannot be optimzed if RRULE UNTIL is given.
267 // In that case we have to calculate all dates until "UNTIL" is reached.
268 if ($this->recurrence->getFrequenceUntilCount() > 0) {
269 // Switch the date to the original defined timzone for this recurrence
270 return $this->createDate($this->start->get(IL_CAL_UNIX, '', $this->timezone));
271 }
272 $optimized = $start = $this->createDate($this->start->get(IL_CAL_UNIX, '', $this->timezone));
273 while (ilDateTime::_before($start, $this->period_start)) {
274 $optimized = clone $start;
275 $start = $this->incrementByFrequency($start);
276 }
277
278 return $optimized;
279 }

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

Referenced by calculateDateList().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validateRecurrence()

ilCalendarRecurrenceCalculator::validateRecurrence ( )
protected

validate recurrence

@access protected

Returns
bool

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

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

Referenced by calculateDateList().

+ Here is the caller graph for this function:

Field Documentation

◆ $duration

ilCalendarRecurrenceCalculator::$duration = null
protected

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

Referenced by getDuration().

◆ $event

ilCalendarRecurrenceCalculator::$event = null
protected

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

◆ $frequence_context

ilCalendarRecurrenceCalculator::$frequence_context = 0
protected

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

◆ $limit_reached

ilCalendarRecurrenceCalculator::$limit_reached = false
protected

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

◆ $log

ilCalendarRecurrenceCalculator::$log = null
protected

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

◆ $period_end

ilCalendarRecurrenceCalculator::$period_end = null
protected

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

◆ $period_start

ilCalendarRecurrenceCalculator::$period_start = null
protected

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

◆ $recurrence

ilCalendarRecurrenceCalculator::$recurrence = null
protected

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

◆ $start

ilCalendarRecurrenceCalculator::$start = null
protected

◆ $timezone

ilCalendarRecurrenceCalculator::$timezone = null
protected

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

◆ $valid_dates

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: