You are here

function date_repeat_merge in Date 5.2

Same name and namespace in other branches
  1. 8 date_repeat/date_repeat_form.inc \date_repeat_merge()
  2. 6.2 date_repeat/date_repeat_form.inc \date_repeat_merge()
  3. 6 date_repeat/date_repeat_form.inc \date_repeat_merge()
  4. 7.3 date_repeat/date_repeat_form.inc \date_repeat_merge()
  5. 7 date_repeat/date_repeat_form.inc \date_repeat_merge()
  6. 7.2 date_repeat/date_repeat_form.inc \date_repeat_merge()

Regroup values back into a consistant array, no matter what state it is in.

3 calls to date_repeat_merge()
date_repeat_rrule_validate in date_repeat/date_repeat_form.inc
Build an RRULE out of the form values.
_date_repeat_rrule_process in date_repeat/date_repeat_form.inc
Generate the repeat setting form.
_date_repeat_widget_validate in date/date_repeat.inc
Validation for date repeat form element.

File

date_repeat/date_repeat_form.inc, line 208
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_merge($form_values, $element) {
  if (empty($form_values) || !is_array($form_values)) {
    return $form_values;
  }
  if (array_key_exists('advanced', $form_values) || array_key_exists('exceptions', $form_values)) {
    if (!array_key_exists('advanced', $form_values)) {
      $form_values['advanced'] = array();
    }
    if (!array_key_exists('exceptions', $form_values)) {
      $form_values['exceptions'] = array();
    }
    if (!array_key_exists('help', $form_values)) {
      $form_values['help'] = array();
    }
    $form_values = array_merge($form_values, (array) $form_values['advanced'], (array) $form_values['exceptions']);
    unset($form_values['advanced']);
    unset($form_values['exceptions']);
    unset($form_values['help']);
  }
  if (array_key_exists('BYDAY', $form_values)) {
    unset($form_values['BYDAY']['']);
  }
  if (array_key_exists('BYMONTH', $form_values)) {
    unset($form_values['BYMONTH']['']);
  }
  if (array_key_exists('BYMONTHDAY', $form_values)) {
    unset($form_values['BYMONTHDAY']['']);
  }
  if (is_array($form_values['UNTIL']['datetime'])) {
    $function = $element['#date_repeat_widget'] . '_input_value';
    $until_element = $element;
    $until_element['#value'] = $form_values['UNTIL']['datetime'];
    $form_values['UNTIL']['datetime'] = $function($until_element);
  }
  if (isset($form_values['EXDATE']) && is_array($form_values['EXDATE'])) {
    $function = $element['#date_repeat_widget'] . '_input_value';
    $exdate_element = $element;
    foreach ($form_values['EXDATE'] as $delta => $value) {
      if (is_array($value['datetime'])) {
        $exdate_element['#value'] = $form_values['EXDATE'][$delta]['datetime'];
        $form_values['EXDATE'][$delta]['datetime'] = $function($exdate_element);
      }
    }
  }
  return $form_values;
}