function date_api_ical_build_rrule in Date 6
Same name and namespace in other branches
- 5.2 date_api_ical.inc \date_api_ical_build_rrule()
- 6.2 date_api_ical.inc \date_api_ical_build_rrule()
- 7.3 date_api/date_api_ical.inc \date_api_ical_build_rrule()
- 7 date_api/date_api_ical.inc \date_api_ical_build_rrule()
- 7.2 date_api/date_api_ical.inc \date_api_ical_build_rrule()
Build an iCal RULE from $form_values.
Parameters
$form_values: an array constructed like the one created by date_ical_parse_rrule()
[RRULE] => Array ( [FREQ] => Array ( [0] => MONTHLY ) [BYDAY] => Array ( [0] => 1SU [1] => -1SU ) [UNTIL] => Array ( [datetime] => 1997-21-31 09:00:00 [all_day] => 0 [tz] => US/Eastern ) ) [EXDATE] => Array ( [0] = Array ( [datetime] => 1997-09-21 09:00:00 [all_day] => 0 [tz] => US/Eastern ) [1] = Array ( [datetime] => 1997-10-05 09:00:00 [all_day] => 0 [tz] => US/Eastern ) )
2 calls to date_api_ical_build_rrule()
- date_repeat_rrule_validate in date_repeat/
date_repeat_form.inc - Build a RRULE out of the form values.
- _date_repeat_rrule_process in date_repeat/
date_repeat_form.inc - Generate the repeat setting form.
File
- ./
date_api_ical.inc, line 638 - Parse iCal data.
Code
function date_api_ical_build_rrule($form_values) {
//grab the RRULE data and put them into iCal RRULE format
$RRULE = 'RRULE:FREQ=' . $form_values['FREQ'];
$RRULE .= ';INTERVAL=' . $form_values['INTERVAL'];
// Unset the empty 'All' values.
unset($form_values['BYDAY']['']);
unset($form_values['BYMONTH']['']);
unset($form_values['BYMONTHDAY']['']);
if ($form_values['BYDAY']) {
$RRULE .= ';BYDAY=' . implode(",", $form_values['BYDAY']);
}
if ($form_values['BYMONTH']) {
$RRULE .= ';BYMONTH=' . implode(",", $form_values['BYMONTH']);
}
if ($form_values['BYMONTHDAY']) {
$RRULE .= ';BYMONTHDAY=' . implode(",", $form_values['BYMONTHDAY']);
}
if ($form_values['UNTIL']['datetime']) {
$RRULE .= ';UNTIL=' . date_convert($form_values['UNTIL']['datetime'], DATE_DATETIME, DATE_ICAL);
}
// iCal rules presume the week starts on Monday unless otherwise specified,
// so we'll specify it.
if (isset($form_values['WKST'])) {
$RRULE .= ';WKST=' . $form_values['WKST'];
}
else {
$RRULE .= ';WKST=' . date_repeat_dow2day(variable_get('date_first_day', 1));
}
// Exceptions dates go last, on their own line.
if (is_array($form_values['EXDATE'])) {
$ex_dates = array();
foreach ($form_values['EXDATE'] as $value) {
$ex_date = date_convert($value['datetime'], DATE_DATETIME, DATE_ICAL);
if (!empty($ex_date)) {
$ex_dates[] = $ex_date;
}
}
if (!empty($ex_dates)) {
sort($ex_dates);
$RRULE .= chr(13) . chr(10) . 'EXDATE:' . implode(',', $ex_dates);
}
}
elseif (!empty($form_values['EXDATE'])) {
$RRULE .= chr(13) . chr(10) . 'EXDATE:' . $form_values['EXDATE'];
}
return $RRULE;
}