Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
core_calendar\rrule_manager Class Reference

Defines calendar class to manage recurrence rule (rrule) during ical imports. More...

Public Member Functions

 __construct ($rrule)
 Constructor for the class.
 
 create_events ($passedevent)
 Create events for specified rrule.
 
 parse_rrule ()
 Parse the recurrence rule and setup all properties.
 

Public Attributes

const DAY_FRIDAY = 'Friday'
 const string Day constant
 
const DAY_MONDAY = 'Monday'
 const string Day constant
 
const DAY_SATURDAY = 'Saturday'
 const string Day constant
 
const DAY_SUNDAY = 'Sunday'
 const string Day constant
 
const DAY_THURSDAY = 'Thursday'
 const string Day constant
 
const DAY_TUESDAY = 'Tuesday'
 const string Day constant
 
const DAY_WEDNESDAY = 'Wednesday'
 const string Day constant
 
const DAYS_OF_WEEK
 const array Array of days in a week.
 
const FREQ_DAILY = 'daily'
 const string Frequency constant
 
const FREQ_HOURLY = 'hourly'
 const string Frequency constant
 
const FREQ_MINUTELY = 'everyminute'
 const string Frequency constant
 
const FREQ_MONTHLY = 'monthly'
 const string Frequency constant
 
const FREQ_SECONDLY = 'everysecond'
 const string Frequency constant
 
const FREQ_WEEKLY = 'weekly'
 const string Frequency constant
 
const FREQ_YEARLY = 'yearly'
 const string Frequency constant
 
const TIME_UNLIMITED_YEARS = 10
 const int For forever repeating events, repeat for this many years
 

Protected Member Functions

 apply_hour_minute_second_rules (DateTime $eventdatetime, $eventdates)
 Applies BYHOUR, BYMINUTE and BYSECOND rules to the calculated event dates.
 
 create_recurring_events ($event, $eventtimes)
 Creates calendar events for the recurring events.
 
 filter_by_day ($event, $eventdates, $until)
 Filter event times based on the BYDAY rule.
 
 filter_by_month ($eventdates)
 Filter event times based on the BYMONTH rule.
 
 filter_by_monthday ($eventdates)
 Filter event times based on the BYMONTHDAY rule.
 
 filter_by_setpos ($event, $eventtimes, $until)
 Filter event times based on the BYSETPOS rule.
 
 filter_by_weekno ($eventdates)
 Filter event times based on the BYWEEKNO rule.
 
 filter_by_yearday ($eventdates)
 Filter event times based on the BYYEARDAY rule.
 
 generate_recurring_event_times ($event)
 Generates recurring events based on the parent event and the RRULE set.
 
 get_day ($daystring)
 Gets the day from day string.
 
 get_interval ()
 Generates a DateInterval object based on the FREQ and INTERVAL rules.
 
 get_period_boundaries ($eventtime)
 Determines the start and end DateTime objects that serve as references to determine whether a calculated event timestamp falls on the period defined by these DateTimes objects.
 
 get_period_bounds_list ($eventtime, $until)
 Gets the list of period boundaries covered by the recurring events.
 
 has_by_rules ()
 Determines whether the RRULE has BYxxx rules or not.
 
 in_bounds ($time, $bounds)
 Determine whether the date-time in question is within the bounds of the periods that are covered by the RRULE.
 
 parse_rrule_property ($prop)
 Parse a property of the recurrence rule.
 
 set_byday ($byday)
 Sets the BYDAY rule.
 
 set_byhour ($byhour)
 Sets the BYHOUR rule.
 
 set_byminute ($byminute)
 Sets the BYMINUTE rule.
 
 set_bymonth ($bymonth)
 Sets the BYMONTH rule.
 
 set_bymonthday ($bymonthday)
 Sets the BYMONTHDAY rule.
 
 set_bysecond ($bysecond)
 Sets the BYSECOND rule.
 
 set_bysetpos ($bysetpos)
 Sets the BYSETPOS rule.
 
 set_byweekno ($byweekno)
 Sets the BYWEEKNO rule.
 
 set_byyearday ($byyearday)
 Sets the BYYEARDAY rule.
 
 set_count ($count)
 Sets the COUNT rule.
 
 set_frequency ($freq)
 Sets Frequency property.
 
 set_interval ($intervalstr)
 Sets the INTERVAL rule.
 
 set_until ($until)
 Sets the UNTIL rule.
 
 validate_rules ()
 Validate the rules as a whole.
 

Protected Attributes

array $byday = array()
 List of day rules.
 
array $byhour = array()
 List of hour rules.
 
array $byminute = array()
 List of Minute rules.
 
array $bymonth = array()
 List of month rules.
 
array $bymonthday = array()
 List of monthday rules.
 
array $bysecond = array()
 List of second rules.
 
array $bysetpos = array()
 List of setpos rules.
 
array $byweekno = array()
 List of weekno rules.
 
array $byyearday = array()
 List of yearday rules.
 
int $count = 0
 Defines the number of occurrences at which to range-bound the recurrence.
 
string $freq
 Frequency of event.
 
int $interval = 1
 This rule part contains a positive integer representing how often the recurrence rule repeats.
 
string $rrule
 string representing the recurrence rule
 
int $until = 0
 defines a timestamp value which bounds the recurrence rule in an inclusive manner.
 
string $wkst = self::DAY_MONDAY
 Week start rule.
 

Detailed Description

Defines calendar class to manage recurrence rule (rrule) during ical imports.

Please refer to RFC 2445 for detail explanation of the logic. Here is a basic extract from it to explain various params:- recur = "FREQ"=freq *( ; either UNTIL or COUNT may appear in a 'recur', ; but UNTIL and COUNT MUST NOT occur in the same 'recur' ( ";" "UNTIL" "=" enddate ) / ( ";" "COUNT" "=" 1*DIGIT ) / ; the rest of these keywords are optional, ; but MUST NOT occur more than once ( ";" "INTERVAL" "=" 1*DIGIT ) / ( ";" "BYSECOND" "=" byseclist ) / ( ";" "BYMINUTE" "=" byminlist ) / ( ";" "BYHOUR" "=" byhrlist ) / ( ";" "BYDAY" "=" bywdaylist ) / ( ";" "BYMONTHDAY" "=" bymodaylist ) / ( ";" "BYYEARDAY" "=" byyrdaylist ) / ( ";" "BYWEEKNO" "=" bywknolist ) / ( ";" "BYMONTH" "=" bymolist ) / ( ";" "BYSETPOS" "=" bysplist ) / ( ";" "WKST" "=" weekday ) / ( ";" x-name "=" text ) )

freq = "SECONDLY" / "MINUTELY" / "HOURLY" / "DAILY" / "WEEKLY" / "MONTHLY" / "YEARLY" enddate = date enddate =/ date-time ;An UTC value byseclist = seconds / ( seconds *("," seconds) ) seconds = 1DIGIT / 2DIGIT ;0 to 59 byminlist = minutes / ( minutes *("," minutes) ) minutes = 1DIGIT / 2DIGIT ;0 to 59 byhrlist = hour / ( hour *("," hour) ) hour = 1DIGIT / 2DIGIT ;0 to 23 bywdaylist = weekdaynum / ( weekdaynum *("," weekdaynum) ) weekdaynum = [([plus] ordwk / minus ordwk)] weekday plus = "+" minus = "-" ordwk = 1DIGIT / 2DIGIT ;1 to 53 weekday = "SU" / "MO" / "TU" / "WE" / "TH" / "FR" / "SA" ;Corresponding to SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, ;FRIDAY, SATURDAY and SUNDAY days of the week. bymodaylist = monthdaynum / ( monthdaynum *("," monthdaynum) ) monthdaynum = ([plus] ordmoday) / (minus ordmoday) ordmoday = 1DIGIT / 2DIGIT ;1 to 31 byyrdaylist = yeardaynum / ( yeardaynum *("," yeardaynum) ) yeardaynum = ([plus] ordyrday) / (minus ordyrday) ordyrday = 1DIGIT / 2DIGIT / 3DIGIT ;1 to 366 bywknolist = weeknum / ( weeknum *("," weeknum) ) weeknum = ([plus] ordwk) / (minus ordwk) bymolist = monthnum / ( monthnum *("," monthnum) ) monthnum = 1DIGIT / 2DIGIT ;1 to 12 bysplist = setposday / ( setposday *("," setposday) ) setposday = yeardaynum

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

core_calendar\rrule_manager::__construct ( $rrule)

Constructor for the class.

Parameters
string$rruleRecurrence rule

Member Function Documentation

◆ apply_hour_minute_second_rules()

core_calendar\rrule_manager::apply_hour_minute_second_rules ( DateTime $eventdatetime,
$eventdates )
protected

Applies BYHOUR, BYMINUTE and BYSECOND rules to the calculated event dates.

Defaults to the DTSTART's hour/minute/second component when not defined.

Parameters
DateTime$eventdatetimeThe parent event DateTime object pertaining to the DTSTART.
int[]$eventdatesArray of candidate event date timestamps.
Return values
arrayList of updated event timestamps that contain the time component of the event times.

◆ create_events()

core_calendar\rrule_manager::create_events ( $passedevent)

Create events for specified rrule.

Parameters
calendar_event$passedeventProperties of event to create.
Exceptions
moodle_exception

◆ create_recurring_events()

core_calendar\rrule_manager::create_recurring_events ( $event,
$eventtimes )
protected

Creates calendar events for the recurring events.

Parameters
stdClass$eventThe parent event.
int[]$eventtimesThe timestamps of the recurring events.

◆ filter_by_day()

core_calendar\rrule_manager::filter_by_day ( $event,
$eventdates,
$until )
protected

Filter event times based on the BYDAY rule.

Parameters
stdClass$eventThe parent event.
int[]$eventdatesThe event times to be filtered.
int$untilEvent times generation limit date.
Return values
int[]Array of filtered timestamps.

◆ filter_by_month()

core_calendar\rrule_manager::filter_by_month ( $eventdates)
protected

Filter event times based on the BYMONTH rule.

Parameters
int[]$eventdatesTimestamps of event times to be filtered.
Return values
int[]Array of filtered timestamps.

◆ filter_by_monthday()

core_calendar\rrule_manager::filter_by_monthday ( $eventdates)
protected

Filter event times based on the BYMONTHDAY rule.

Parameters
int[]$eventdatesThe event times to be filtered.
Return values
int[]Array of filtered timestamps.

◆ filter_by_setpos()

core_calendar\rrule_manager::filter_by_setpos ( $event,
$eventtimes,
$until )
protected

Filter event times based on the BYSETPOS rule.

Parameters
stdClass$eventThe parent event.
int[]$eventtimesThe event times to be filtered.
int$untilEvent times generation limit date.
Return values
int[]Array of filtered timestamps.

◆ filter_by_weekno()

core_calendar\rrule_manager::filter_by_weekno ( $eventdates)
protected

Filter event times based on the BYWEEKNO rule.

Parameters
int[]$eventdatesTimestamps of event times to be filtered.
Return values
int[]Array of filtered timestamps.

◆ filter_by_yearday()

core_calendar\rrule_manager::filter_by_yearday ( $eventdates)
protected

Filter event times based on the BYYEARDAY rule.

Parameters
int[]$eventdatesTimestamps of event times to be filtered.
Return values
int[]Array of filtered timestamps.

◆ generate_recurring_event_times()

core_calendar\rrule_manager::generate_recurring_event_times ( $event)
protected

Generates recurring events based on the parent event and the RRULE set.

If multiple BYxxx rule parts are specified, then after evaluating the specified FREQ and INTERVAL rule parts, the BYxxx rule parts are applied to the current set of evaluated occurrences in the following order: BYMONTH, BYWEEKNO, BYYEARDAY, BYMONTHDAY, BYDAY, BYHOUR, BYMINUTE, BYSECOND and BYSETPOS; then COUNT and UNTIL are evaluated.

Parameters
stdClass$eventThe event object.
Return values
arrayThe list of timestamps that obey the given RRULE.

◆ get_day()

core_calendar\rrule_manager::get_day ( $daystring)
protected

Gets the day from day string.

Parameters
string$daystringDay string (MO, TU, etc)
Exceptions
moodle_exception
Return values
stringDay represented by the parameter.

◆ get_interval()

core_calendar\rrule_manager::get_interval ( )
protected

Generates a DateInterval object based on the FREQ and INTERVAL rules.

Return values
DateInterval
Exceptions
moodle_exception

◆ get_period_boundaries()

core_calendar\rrule_manager::get_period_boundaries ( $eventtime)
protected

Determines the start and end DateTime objects that serve as references to determine whether a calculated event timestamp falls on the period defined by these DateTimes objects.

Parameters
int$eventtimeUnix timestamp of the event time.
Return values
DateTime[]
Exceptions
moodle_exception

◆ get_period_bounds_list()

core_calendar\rrule_manager::get_period_bounds_list ( $eventtime,
$until )
protected

Gets the list of period boundaries covered by the recurring events.

Parameters
int$eventtimeThe event timestamp.
int$untilThe end timestamp.
Return values
arrayList of period bounds, with start and next properties.

◆ has_by_rules()

core_calendar\rrule_manager::has_by_rules ( )
protected

Determines whether the RRULE has BYxxx rules or not.

Return values
boolTrue if there is one or more BYxxx rules to process. False, otherwise.

◆ in_bounds()

core_calendar\rrule_manager::in_bounds ( $time,
$bounds )
protected

Determine whether the date-time in question is within the bounds of the periods that are covered by the RRULE.

Parameters
int$timeThe timestamp to be evaluated.
array$boundsArray of period boundaries covered by the RRULE.
Return values
bool

◆ parse_rrule_property()

core_calendar\rrule_manager::parse_rrule_property ( $prop)
protected

Parse a property of the recurrence rule.

Parameters
string$propproperty string with type-value pair
Exceptions
moodle_exception

◆ set_byday()

core_calendar\rrule_manager::set_byday ( $byday)
protected

Sets the BYDAY rule.

The BYDAY rule part specifies a comma-separated list of days of the week;

  • MO indicates Monday;
  • TU indicates Tuesday;
  • WE indicates Wednesday;
  • TH indicates Thursday;
  • FR indicates Friday;
  • SA indicates Saturday;
  • SU indicates Sunday.

Each BYDAY value can also be preceded by a positive (+n) or negative (-n) integer. If present, this indicates the nth occurrence of the specific day within the MONTHLY or YEARLY RRULE. For example, within a MONTHLY rule, +1MO (or simply 1MO) represents the first Monday within the month, whereas -1MO represents the last Monday of the month. If an integer modifier is not present, it means all days of this type within the specified frequency. For example, within a MONTHLY rule, MO represents all Mondays within the month.

Parameters
string$bydayComma-separated list of days of the week.
Exceptions
moodle_exception

◆ set_byhour()

core_calendar\rrule_manager::set_byhour ( $byhour)
protected

Sets the BYHOUR rule.

The BYHOUR rule part specifies a comma-separated list of hours of the day. Valid values are 0 to 23.

Parameters
string$byhourComma-separated list of hours of the day.
Exceptions
moodle_exception

◆ set_byminute()

core_calendar\rrule_manager::set_byminute ( $byminute)
protected

Sets the BYMINUTE rule.

The BYMINUTE rule part specifies a comma-separated list of seconds within an hour. Valid values are 0 to 59.

Parameters
string$byminuteComma-separated list of minutes within an hour.
Exceptions
moodle_exception

◆ set_bymonth()

core_calendar\rrule_manager::set_bymonth ( $bymonth)
protected

Sets the BYMONTH rule.

The BYMONTH rule part specifies a comma-separated list of months of the year. Valid values are 1 to 12.

Parameters
string$bymonthComma-separated list of months of the year.
Exceptions
moodle_exception

◆ set_bymonthday()

core_calendar\rrule_manager::set_bymonthday ( $bymonthday)
protected

Sets the BYMONTHDAY rule.

The BYMONTHDAY rule part specifies a comma-separated list of days of the month. Valid values are 1 to 31 or -31 to -1. For example, -10 represents the tenth to the last day of the month.

Parameters
string$bymonthdayComma-separated list of days of the month.
Exceptions
moodle_exception

◆ set_bysecond()

core_calendar\rrule_manager::set_bysecond ( $bysecond)
protected

Sets the BYSECOND rule.

The BYSECOND rule part specifies a comma-separated list of seconds within a minute. Valid values are 0 to 59.

Parameters
string$bysecondComma-separated list of seconds within a minute.
Exceptions
moodle_exception

◆ set_bysetpos()

core_calendar\rrule_manager::set_bysetpos ( $bysetpos)
protected

Sets the BYSETPOS rule.

The BYSETPOS rule part specifies a comma-separated list of values which corresponds to the nth occurrence within the set of events specified by the rule. Valid values are 1 to 366 or -366 to -1. It MUST only be used in conjunction with another BYxxx rule part.

For example "the last work day of the month" could be represented as: RRULE:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1

Parameters
string$bysetposComma-separated list of values.
Exceptions
moodle_exception

◆ set_byweekno()

core_calendar\rrule_manager::set_byweekno ( $byweekno)
protected

Sets the BYWEEKNO rule.

The BYWEEKNO rule part specifies a comma-separated list of ordinals specifying weeks of the year. Valid values are 1 to 53 or -53 to -1. This corresponds to weeks according to week numbering as defined in [ISO 8601]. A week is defined as a seven day period, starting on the day of the week defined to be the week start (see WKST). Week number one of the calendar year is the first week which contains at least four (4) days in that calendar year. This rule part is only valid for YEARLY rules. For example, 3 represents the third week of the year.

Note: Assuming a Monday week start, week 53 can only occur when Thursday is January 1 or if it is a leap year and Wednesday is January 1.

Parameters
string$byweeknoComma-separated list of number of weeks.
Exceptions
moodle_exception

◆ set_byyearday()

core_calendar\rrule_manager::set_byyearday ( $byyearday)
protected

Sets the BYYEARDAY rule.

The BYYEARDAY rule part specifies a comma-separated list of days of the year. Valid values are 1 to 366 or -366 to -1. For example, -1 represents the last day of the year (December 31st) and -306 represents the 306th to the last day of the year (March 1st).

Parameters
string$byyeardayComma-separated list of days of the year.
Exceptions
moodle_exception

◆ set_count()

core_calendar\rrule_manager::set_count ( $count)
protected

Sets the COUNT rule.

Parameters
string$countThe count value.
Exceptions
moodle_exception

◆ set_frequency()

core_calendar\rrule_manager::set_frequency ( $freq)
protected

Sets Frequency property.

Parameters
string$freqFrequency of event
Exceptions
moodle_exception

◆ set_interval()

core_calendar\rrule_manager::set_interval ( $intervalstr)
protected

Sets the INTERVAL rule.

The INTERVAL rule part contains a positive integer representing how often the recurrence rule repeats. The default value is "1", meaning:

  • every second for a SECONDLY rule, or
  • every minute for a MINUTELY rule,
  • every hour for an HOURLY rule,
  • every day for a DAILY rule,
  • every week for a WEEKLY rule,
  • every month for a MONTHLY rule and
  • every year for a YEARLY rule.
Parameters
string$intervalstrThe value for the interval rule.
Exceptions
moodle_exception

◆ set_until()

core_calendar\rrule_manager::set_until ( $until)
protected

Sets the UNTIL rule.

Parameters
string$untilThe date string representation of the UNTIL rule.
Exceptions
moodle_exception

◆ validate_rules()

core_calendar\rrule_manager::validate_rules ( )
protected

Validate the rules as a whole.

Exceptions
moodle_exception

Member Data Documentation

◆ $wkst

string core_calendar\rrule_manager::$wkst = self::DAY_MONDAY
protected

Week start rule.

Default is Monday.

◆ DAYS_OF_WEEK

const core_calendar\rrule_manager::DAYS_OF_WEEK
Initial value:
= [
]
const DAY_SUNDAY
const string Day constant
Definition rrule_manager.php:139
const DAY_MONDAY
const string Day constant
Definition rrule_manager.php:121
const DAY_SATURDAY
const string Day constant
Definition rrule_manager.php:136
const DAY_FRIDAY
const string Day constant
Definition rrule_manager.php:133
const DAY_WEDNESDAY
const string Day constant
Definition rrule_manager.php:127
const DAY_THURSDAY
const string Day constant
Definition rrule_manager.php:130
const DAY_TUESDAY
const string Day constant
Definition rrule_manager.php:124

const array Array of days in a week.


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