sample files from a smithsonian project
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Node-related functions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_preprocess_node__BUNDLE().
|
||||
*/
|
||||
function cdesai_emulsify_preprocess_node__event(&$variables) {
|
||||
// final date to be used - if no end_date available, then use start_date
|
||||
$date_to_use = NULL;
|
||||
$content = $variables['content'];
|
||||
$view_mode = $variables['view_mode'];
|
||||
|
||||
// check to see if a date has been entered at all
|
||||
if (isset($content['field_daterange'][0])) {
|
||||
|
||||
if (isset($start_date)) {
|
||||
// set date to use as start date, but if end date is available use that instead.
|
||||
$date_to_use = $start_date;
|
||||
if (!empty($end_date)) {
|
||||
$date_to_use = $end_date;
|
||||
}
|
||||
|
||||
// convert date_to_use string to date object
|
||||
$dateToUseObj = DateTime::createFromFormat("l, F j, Y - h:ia", $date_to_use);
|
||||
if ($dateToUseObj) {
|
||||
// convert date object to timestamp
|
||||
$date_timestamp = $dateToUseObj->getTimestamp();
|
||||
// convert current time to timestamp
|
||||
$current_timestamp = strtotime("now");
|
||||
// returns TRUE if past event, FALSE otherwise
|
||||
$variables['event_is_past'] = $current_timestamp > $date_timestamp ?: FALSE;
|
||||
|
||||
// break up the start and end dates
|
||||
$startDateObj = DateTime::createFromFormat("l, F j, Y - h:ia", $start_date);
|
||||
$event_start_date = $startDateObj->format($dateFormat);
|
||||
$event_start_time = $startDateObj->format('g:ia');
|
||||
|
||||
if (!empty($end_date)) {
|
||||
$endDateObj = DateTime::createFromFormat("l, F j, Y - h:ia", $end_date);
|
||||
$event_end_date = $endDateObj->format($dateFormat . ', Y');
|
||||
$event_end_time = $endDateObj->format('g:ia');
|
||||
|
||||
// default to display both the start and end dates
|
||||
$variables['event_date'] = $event_start_date . ' - ' . $event_end_date;
|
||||
// if the start date and end date are equal, display only the end date
|
||||
if ($startDateObj->format($dateFormat . ', Y') == $event_end_date) {
|
||||
$variables['event_date'] = $event_end_date;
|
||||
}
|
||||
// append the start and end times.
|
||||
$variables['event_time'] = $event_start_time . ' - ' . $event_end_time;
|
||||
// If the start and end time are the same, display "All Day" instead.
|
||||
if ($event_start_time == $event_end_time && $event_start_date == $event_end_date) {
|
||||
$variables['event_time'] = t('All Day');
|
||||
}
|
||||
} else {
|
||||
// If no end date, show only the start date and the text "All Day".
|
||||
$variables['event_date'] = $event_start_date;
|
||||
$variables['event_time'] = t('All Day');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user