You are here

function date_node_import_values_alter_date_popup in Node import 6

1 call to date_node_import_values_alter_date_popup()
date_node_import_values_alter in supported/date/date.inc
Implementation of hook_node_import_values_alter().

File

supported/date/date.inc, line 113
Support file for the CCK Date module.

Code

function date_node_import_values_alter_date_popup(&$values, $fields, $fieldname, $fieldinfo) {
  foreach ($fieldinfo['columns'] as $colname => $colinfo) {

    // Provide default value if the field has no values.
    if (count($values[$fieldname]) == 0) {
      $values[$fieldname] = array();
      $values[$fieldname][0] = array();
      $values[$fieldname][0][$colname] = array(
        'date' => null,
        'time' => null,
      );
    }
    else {
      foreach ($values[$fieldname] as $i => $value) {

        //Timezone is handled separately - just wrap in an array('timezone' => $timezone)
        if ($colname == 'timezone') {
          $values[$fieldname][$i]['timezone'] = array(
            'timezone' => $values[$fieldname][$i]['timezone'],
          );
          continue;
        }

        // Get the format that is expected from the pop-up calendar.
        // If a custom format was entered, use it instead.
        if ($fieldinfo['widget']['input_format_custom']) {
          $widgetFormat = $fieldinfo['widget']['input_format_custom'];
        }
        else {
          $widgetFormat = $fieldinfo['widget']['input_format'];
        }

        // Remove parts that are not valid for the selected granularity
        $widgetFormat = date_limit_format($widgetFormat, $fieldinfo['granularity']);

        // Separate the widget format into a date part and a time part
        $widgetFormatPieces = explode(' - ', $widgetFormat, 2);
        $dateFormat = $widgetFormatPieces[0];
        $timeFormat = $widgetFormatPieces[1];

        // Get the original value format we need to convert
        $time = strtotime($value[$colname]);

        /* $colname is equal to 'value' in most cases.
         * We trash the original 'value' field and replace it with an array containing the various pieces
         * entered from the 'pop-up calendar'.
         */
        $values[$fieldname][$i][$colname] = array();
        if ($time == FALSE) {
          $values[$fieldname][$i][$colname]['date'] = '';
        }
        else {
          $values[$fieldname][$i][$colname]['date'] = date($dateFormat, $time);
        }

        // AM/PM are case sensitive...
        $values[$fieldname][$i][$colname]['time'] = strtoupper(date($timeFormat, $time));
      }
    }
  }
}