function date_prepare_node in Date 6.2
Same name and namespace in other branches
- 5.2 date/date.module \date_prepare_node()
Helper function to adapt node date fields to formatter settings.
2 calls to date_prepare_node()
- theme_date_display_combination in date/
date.theme - Theme from/to date combination in the view.
- theme_date_format_interval in date/
date.theme - Theme a format interval for a date element
File
- date/
date.module, line 597 - Defines date/time field types for the Content Construction Kit (CCK).
Code
function date_prepare_node($node, $field, $type_name, $context, $options) {
// If there are options to limit multiple values,
// alter the node values to match.
$field_name = $field['field_name'];
$max_count = $options['multiple']['multiple_number'];
// If no results should be shown, empty the values and return.
if (is_numeric($max_count) && $max_count == 0) {
$node->{$field_name} = array();
return $node;
}
// Otherwise removed values that should not be displayed.
if (!empty($options['multiple']['multiple_from']) || !empty($options['multiple']['multiple_to']) || !empty($max_count)) {
$format = date_type_format($field['type']);
include_once drupal_get_path('module', 'date_api') . '/date_api_sql.inc';
$date_handler = new date_sql_handler($field);
$arg0 = !empty($options['multiple']['multiple_from']) ? date_format(date_create($options['multiple']['multiple_from'], date_default_timezone()), DATE_FORMAT_DATETIME) : variable_get('date_min_year', 100) . '-01-01T00:00:00';
$arg1 = !empty($options['multiple']['multiple_to']) ? date_format(date_create($options['multiple']['multiple_to'], date_default_timezone()), DATE_FORMAT_DATETIME) : variable_get('date_max_year', 4000) . '-12-31T23:59:59';
if (!empty($arg0) && !empty($arg1)) {
$arg = $arg0 . '--' . $arg1;
}
elseif (!empty($arg0)) {
$arg = $arg0;
}
elseif (!empty($arg1)) {
$arg = $arg1;
}
if (!empty($arg)) {
$range = $date_handler
->arg_range($arg);
$start = date_format($range[0], $format);
$end = date_format($range[1], $format);
// Empty out values we don't want to see.
$count = 0;
foreach ($node->{$field_name} as $delta => $value) {
if (!empty($node->date_repeat_show_all)) {
break;
}
elseif (!empty($max_count) && is_numeric($max_count) && $count >= $max_count || !empty($value['value']) && $value['value'] < $start || !empty($value['value2']) && $value['value2'] > $end) {
unset($node->{$field_name}[$delta]);
}
else {
$count++;
}
}
}
}
return $node;
}