Fix for Fix for UC_Views

  1. OK so this in the .module:
  2. <?php
  3. /**
  4.  * Implementation of hook_date_api_fields().
  5.  * on behalf of core fields.
  6.  *
  7.  * All modules that create custom fields that use the
  8.  * 'views_handler_field_date' handler can provide
  9.  * additional information here about the type of
  10.  * date they create so the date can be used by
  11.  * the Date API views date argument and date filter.
  12.  *
  13.  * Thank you justindodge for this!
  14.  */
  15. function uc_views_date_api_fields($field) {
  16.   $values = array(
  17.     // The type of date: DATE_UNIX, DATE_ISO, DATE_DATETIME.
  18.     'sql_type' => DATE_UNIX,
  19.     // Timezone handling options: 'none', 'site', 'date', 'utc'.
  20.     'tz_handling' => 'site',
  21.     // Needed only for dates that use 'date' tz_handling.
  22.     'timezone_field' => '',
  23.     // Needed only for dates that use 'date' tz_handling.
  24.     'offset_field' => '',
  25.     // Array of "table.field" values for related fields that should be
  26.     // loaded automatically in the Views SQL.
  27.     'related_fields' => array(),
  28.     // Granularity of this date field's db data.
  29.     'granularity' => array('year', 'month', 'day', 'hour', 'minute', 'second'),
  30.   );
  31.   return $values;
  32. }
  33.  
  34. ?>
  35.  
  36. code that works fine in this module's .views.inc (note that uc_orders is a base table)
  37.  
  38. <?php
  39.   $data['uc_orders']['modified'] = array(
  40.     'title' => t('Order Modification Date'),
  41.     'help' => $order_schema['fields']['modified']['description'],
  42.     'field' => array(
  43.       'handler' => 'views_handler_field_date',
  44.       'click sortable' => TRUE,
  45.     ),
  46.      'sort' => array(
  47.       'handler' => 'views_handler_sort_date',
  48.     ),
  49.     'filter' => array(
  50.       'handler' => 'views_handler_filter_date',
  51.     ),
  52.   );
  53.  
  54.   //Use the sleeker date_api views handler if the module is available
  55.   if(module_exists('date_api')) {
  56.     $data['uc_orders']['modified']['filter']['handler'] = 'date_api_filter_handler';
  57.   }
  58.  
  59. ?>
  60.  
  61. my code that doesn't work:
  62.  
  63. <?PHP //within uc_views.views.inc
  64.   // Add shipping details to uc_views
  65.   $data['uc_shipments']['table']['group'] = t('Ubercart shipment');
  66.   $data['uc_shipments']['table']['join']['uc_orders'] = array(
  67.     'left_field' => 'order_id',
  68.     'field' => 'order_id',
  69.   );
  70.   $data['uc_shipments']['carrier'] = array(
  71.     'title' => t('Shipping Carrier Title'),
  72.     'help' => t('The shipping carrier used.'),
  73.     'field' => array(
  74.       'handler' => 'views_handler_field',
  75.       'click sortable' => TRUE,
  76.     ),
  77.   );
  78.   $data['uc_shipments']['cost'] = array(
  79.     'title' => t('Shipping Cost Amount'),
  80.     'help' => t('The shipping actual cost.'),
  81.     'field' => array(
  82.       'handler' => 'uc_views_handler_field_money_amount',
  83.       'click sortable' => TRUE,
  84.     ),
  85.   );
  86.   $data['uc_shipments']['ship_date'] = array(
  87.     'title' => t('Order Ship Date'),
  88.     'help' => t('The shipment date.'),
  89.     'field' => array(
  90.       'handler' => 'views_handler_field_date',
  91.       'click sortable' => TRUE,
  92.     ),
  93.      'sort' => array(
  94.       'handler' => 'views_handler_sort_date',
  95.     ),
  96.     'filter' => array(
  97.       'handler' => 'views_handler_filter_date',
  98.     ),
  99.   );
  100.   //if the sexy date module is installed use that for filtering
  101.   if(module_exists('date_api')) {
  102.     $data['uc_shipments']['ship_date']['filter']['handler'] = 'date_api_filter_handler';
  103.   }
  104. ?>

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.