<?PHP //within uc.views.module
/**
* Implementation of hook_date_api_fields().
* on behalf of core fields.
*
* All modules that create custom fields that use the
* 'views_handler_field_date' handler can provide
* additional information here about the type of
* date they create so the date can be used by
* the Date API views date argument and date filter.
*
* Thank you justindodge for this!
*/
function uc_views_date_api_fields($field) {
$values = array(
// The type of date: DATE_UNIX, DATE_ISO, DATE_DATETIME.
'sql_type' => DATE_UNIX,
// Timezone handling options: 'none', 'site', 'date', 'utc'.
'tz_handling' => 'site',
// Needed only for dates that use 'date' tz_handling.
'timezone_field' => '',
// Needed only for dates that use 'date' tz_handling.
'offset_field' => '',
// Array of "table.field" values for related fields that should be
// loaded automatically in the Views SQL.
'related_fields' => array(),
// Granularity of this date field's db data.
'granularity' => array('year', 'month', 'day', 'hour', 'minute', 'second'),
);
return $values;
}
?>
<?PHP //within uc_views.views.inc
// here is how it is done for the order modified date, and this works...
$data['uc_orders']['modified'] = array(
'title' => t('Order Modification Date'),
'help' => $order_schema['fields']['modified']['description'],
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
//Use the sleeker date_api views handler if the module is available
if(module_exists('date_api')) {
$data['uc_orders']['modified']['filter']['handler'] = 'date_api_filter_handler';
}
// here is a little bit o stuff to add shipping details to uc_views
$data['uc_shipments']['table']['group'] = t('Ubercart shipment');
$data['uc_shipments']['table']['join']['uc_orders'] = array(
'left_field' => 'order_id',
'field' => 'order_id',
);
$data['uc_shipments']['carrier'] = array(
'title' => t('Shipping Carrier Title'),
'help' => t('The shipping carrier used.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
);
$data['uc_shipments']['cost'] = array(
'title' => t('Shipping Cost Amount'),
'help' => t('The shipping actual cost.'),
'field' => array(
'handler' => 'uc_views_handler_field_money_amount',
'click sortable' => TRUE,
),
);
// try to add the ship date as a filter as is done for modified & created dates...everything works but the field is missing from the list of options in the "date" modules dialog for filters
$data['uc_shipments']['ship_date'] = array(
'title' => t('Order Ship Date'),
'help' => t('The shipment date.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
//if the sexy date module is installed use that for filtering
if(module_exists('date_api')) {
$data['uc_shipments']['ship_date']['filter']['handler'] = 'date_api_filter_handler';
}
?>