function _date_repeat_rrule_process in Date 7
Same name and namespace in other branches
- 8 date_repeat/date_repeat_form.inc \_date_repeat_rrule_process()
- 5.2 date_repeat/date_repeat_form.inc \_date_repeat_rrule_process()
- 6.2 date_repeat/date_repeat_form.inc \_date_repeat_rrule_process()
- 6 date_repeat/date_repeat_form.inc \_date_repeat_rrule_process()
- 7.3 date_repeat/date_repeat_form.inc \_date_repeat_rrule_process()
- 7.2 date_repeat/date_repeat_form.inc \_date_repeat_rrule_process()
Generate the repeat setting form.
1 call to _date_repeat_rrule_process()
- date_repeat_rrule_process in date_repeat/
date_repeat.module - Generate the repeat rule setting form.
File
- date_repeat/
date_repeat_form.inc, line 36 - Code to add a date repeat selection form to a date field and create an iCal RRULE from the chosen selections.
Code
function _date_repeat_rrule_process($element, $form_state, $form) {
module_load_include('inc', 'date_api', 'date_api_ical');
if (empty($element['#date_repeat_widget'])) {
$element['#date_repeat_widget'] = module_exists('date_popup') ? 'date_popup' : 'date_select';
}
if (is_array($element['#default_value'])) {
$element['#value'] = date_repeat_merge($element['#value'], $element);
$rrule = date_api_ical_build_rrule($element['#value']);
}
else {
$rrule = $element['#default_value'];
}
// Empty the original string value of the RRULE so we can create
// an array of values for the form from the RRULE's contents.
$element['#value'] = '';
$parts = date_repeat_split_rrule($rrule);
$rrule = $parts[0];
$exceptions = $parts[1];
$additions = $parts[2];
$timezone = !empty($element['#date_timezone']) ? $element['#date_timezone'] : date_default_timezone();
$merged_values = date_repeat_merge($rrule, $element);
$UNTIL = '';
if (!empty($merged_values['UNTIL']['datetime'])) {
$until_date = new DateObject($merged_values['UNTIL']['datetime'], $merged_values['UNTIL']['tz']);
date_timezone_set($until_date, timezone_open($timezone));
$UNTIL = date_format($until_date, DATE_FORMAT_DATETIME);
}
$element['INTERVAL'] = array(
'#type' => 'select',
//'#title' => t('Interval'),
'#default_value' => !empty($rrule['INTERVAL']) ? $rrule['INTERVAL'] : 0,
'#options' => INTERVAL_options(),
'#prefix' => '<div class="date-repeat-input">',
'#suffix' => '</div>',
);
$element['FREQ'] = array(
'#type' => 'select',
//'#title' => t('Frequency'),
'#default_value' => !empty($rrule['FREQ']) ? $rrule['FREQ'] : 'NONE',
'#options' => FREQ_options(),
'#prefix' => '<div class="date-repeat-input">',
'#suffix' => '</div>',
);
$element['UNTIL'] = array(
'#tree' => TRUE,
'#prefix' => '<div class="date-clear">',
'#suffix' => '</div>',
'datetime' => array(
'#type' => $element['#date_repeat_widget'],
'#title' => t('Until'),
'#description' => t('Date to stop repeating this item.'),
'#default_value' => $UNTIL,
'#date_format' => !empty($element['#date_format']) ? date_limit_format($element['#date_format'], array(
'year',
'month',
'day',
)) : 'Y-m-d',
'#date_timezone' => $timezone,
'#date_text_parts' => !empty($element['#date_text_parts']) ? $element['#date_text_parts'] : array(),
'#date_year_range' => !empty($element['#date_year_range']) ? $element['#date_year_range'] : '-3:+3',
'#date_label_position' => !empty($element['#date_label_position']) ? $element['#date_label_position'] : 'within',
),
'tz' => array(
'#type' => 'hidden',
'#value' => $element['#date_timezone'],
),
'all_day' => array(
'#type' => 'hidden',
'#value' => 1,
),
'granularity' => array(
'#type' => 'hidden',
'#value' => serialize(array(
'year',
'month',
'day',
)),
),
);
$collapsed = TRUE;
if (!empty($merged_values['BYDAY']) || !empty($merged_values['BYMONTH'])) {
$collapsed = FALSE;
}
// start the advanced fieldset
$element['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced'),
'#collapsible' => TRUE,
'#collapsed' => $collapsed,
'#description' => t("If no advanced options are selected, the date will repeat on the day of week of the start date for weekly repeats, otherwise on the month and day of the start date. Use the options below to override that behavior to select specific months and days to repeat on. Use the 'Except' box to input dates that should be omitted from the results.") . ' ',
'#prefix' => '<div class="date-clear">',
'#suffix' => '</div>',
);
$element['advanced']['BYMONTH'] = array(
'#type' => 'select',
'#title' => t('Month', array(), array(
'context' => 'datetime',
)),
'#default_value' => !empty($rrule['BYMONTH']) ? $rrule['BYMONTH'] : '',
'#options' => array(
'' => t('-- Any'),
) + date_month_names(TRUE),
'#multiple' => TRUE,
'#size' => 10,
'#prefix' => '<div class="date-repeat-input">',
'#suffix' => '</div>',
);
$element['advanced']['BYMONTHDAY'] = array(
'#type' => 'select',
'#title' => t('Day of Month'),
'#default_value' => !empty($rrule['BYMONTHDAY']) ? $rrule['BYMONTHDAY'] : '',
'#options' => array(
'' => t('-- Any'),
) + drupal_map_assoc(range(1, 31)) + drupal_map_assoc(range(-1, -31)),
'#multiple' => TRUE,
'#size' => 10,
'#prefix' => '<div class="date-repeat-input">',
'#suffix' => '</div>',
);
$element['advanced']['BYDAY'] = array(
'#type' => 'select',
'#title' => t('Day of Week'),
'#default_value' => !empty($rrule['BYDAY']) ? $rrule['BYDAY'] : '',
'#options' => array(
'' => t('-- Any'),
) + date_repeat_dow_options(),
//'#attributes' => array('size' => '5'),
'#multiple' => TRUE,
'#size' => 10,
'#prefix' => '<div class="date-repeat-input">',
'#suffix' => '</div>',
);
if (empty($form_state['num_exceptions'])) {
$form_state['num_exceptions'] = count($exceptions);
}
$max = empty($form_state['num_exceptions']) ? 1 : $form_state['num_exceptions'];
$element['exceptions'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => empty($form_state['num_exceptions']) ? TRUE : FALSE,
'#title' => t('Except'),
'#description' => t('Dates to omit from the list of repeating dates.'),
'#prefix' => '<div id="date-repeat-exceptions" class="date-repeat">',
'#suffix' => '</div>',
);
for ($i = 0; $i < $max; $i++) {
$EXCEPT = '';
if (!empty($exceptions[$i]['datetime'])) {
$EXCEPT = $exceptions[$i]['datetime'];
}
$element['exceptions']['EXDATE'][$i] = array(
'#tree' => TRUE,
'datetime' => array(
'#type' => $element['#date_repeat_widget'],
'#default_value' => !empty($EXCEPT) ? $EXCEPT : '0000-00-00 11:59:59',
'#date_timezone' => !empty($element['#date_timezone']) ? $element['#date_timezone'] : date_default_timezone(),
'#date_format' => !empty($element['#date_format']) ? date_limit_format($element['#date_format'], array(
'year',
'month',
'day',
)) : 'Y-m-d',
'#date_text_parts' => !empty($element['#date_text_parts']) ? $element['#date_text_parts'] : array(),
'#date_year_range' => !empty($element['#date_year_range']) ? $element['#date_year_range'] : '-3:+3',
'#date_label_position' => !empty($element['#date_label_position']) ? $element['#date_label_position'] : 'within',
),
'tz' => array(
'#type' => 'hidden',
'#value' => $element['#date_timezone'],
),
'all_day' => array(
'#type' => 'hidden',
'#value' => 1,
),
'granularity' => array(
'#type' => 'hidden',
'#value' => serialize(array(
'year',
'month',
'day',
)),
),
);
}
// collect additions in the same way as exceptions - implements RDATE.
if (empty($form_state['num_additions'])) {
$form_state['num_additions'] = count($additions);
}
$max = empty($form_state['num_additions']) ? 1 : $form_state['num_additions'];
$element['additions'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => empty($form_state['num_additions']) ? TRUE : FALSE,
'#title' => t('Additional'),
'#description' => t('Dates to add to the list of repeating dates.'),
'#prefix' => '<div id="date-repeat-additions" class="date-repeat">',
'#suffix' => '</div>',
);
for ($i = 0; $i < $max; $i++) {
$RDATE = '';
if (!empty($additions[$i]['datetime'])) {
$RDATE = $additions[$i]['datetime'];
}
$element['additions']['RDATE'][$i] = array(
'#tree' => TRUE,
'datetime' => array(
'#type' => $element['#date_repeat_widget'],
'#default_value' => $RDATE,
'#date_timezone' => !empty($element['#date_timezone']) ? $element['#date_timezone'] : date_default_timezone_name(),
'#date_format' => !empty($element['#date_format']) ? date_limit_format($element['#date_format'], array(
'year',
'month',
'day',
)) : 'Y-m-d',
'#date_text_parts' => !empty($element['#date_text_parts']) ? $element['#date_text_parts'] : array(),
'#date_year_range' => !empty($element['#date_year_range']) ? $element['#date_year_range'] : '-3:+3',
'#date_label_position' => !empty($element['#date_label_position']) ? $element['#date_label_position'] : 'within',
),
'tz' => array(
'#type' => 'hidden',
'#value' => $element['#date_timezone'],
),
'all_day' => array(
'#type' => 'hidden',
'#value' => 1,
),
'granularity' => array(
'#type' => 'hidden',
'#value' => serialize(array(
'year',
'month',
'day',
)),
),
);
}
$element['exceptions']['exceptions_add'] = array(
'#type' => 'submit',
'#value' => t('Add exception'),
'#submit' => array(
'date_repeat_add_exception',
),
'#ajax' => array(
'callback' => 'date_repeat_add_exception_callback',
'wrapper' => 'date-repeat-exceptions',
),
);
$element['additions']['additions_add'] = array(
'#type' => 'submit',
'#value' => t('Add addition'),
'#submit' => array(
'date_repeat_add_addition',
),
'#ajax' => array(
'callback' => 'date_repeat_add_addition_callback',
'wrapper' => 'date-repeat-additions',
),
);
$element['#date_repeat_collapsed'] = !empty($rrule['INTERVAL']) || !empty($rrule['FREQ']) ? 0 : (!empty($element['#date_repeat_collapsed']) ? $element['#date_repeat_collapsed'] : 0);
return $element;
}