DrupalBin
Submit Code
About
Recent Posts
Code
Fix for Fix for Code
Fix for Code
Code
Node type whitelist
an axe coach accessories
coach purses married
Fix for de las ghd alturas
de las ghd alturas
Code
more
User login
Log in using OpenID:
What is OpenID?
Username:
*
Password:
*
Log in using OpenID
Cancel OpenID login
Create new account
Request new password
Tags
CCK
drupal
fapi
jquery
menu
module
php
simpletest
taxonomy
test
theme
views
more tags
Home
Fix for Fix for UC_Views
View
Fix
February 3, 2010 - 5:17pm — Anonymous
OK so this in the .module:
<?php
/**
* 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
;
}
?>
code that works fine in this module's .views.inc (note that uc_orders is a base table)
<?php
$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'
;
}
?>
my code that doesn't work:
<?PHP
//within uc_views.views.inc
// 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
,
)
,
)
;
$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'
;
}
?>
ubercart
views
Submit Fix
Summary:
Tags:
Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Show summary in full view
OK so this in the .module: <?php /** * 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; } ?> code that works fine in this module's .views.inc (note that uc_orders is a base table) <?php $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'; } ?> my code that doesn't work: <?PHP //within uc_views.views.inc // 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, ), ); $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'; } ?>
Syntax highlighting mode:
ActionScript
ColdFusion
Diff
Drupal 5
Drupal 6
HTML
INI
Javascript
MySQL
PHP
Python
robots.txt
SQL
Text
Select the syntax highlighting mode to use.
See Also:
Order
Title:
URL:
-1
0
1
Title:
URL:
-1
0
1
Any links you'd like to have associated with the post (Drupal.org issue, Wikipedia article, etc).
File attachments
Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.
Attach new file:
The maximum upload size is
1 MB
. Only files with the following extensions may be uploaded:
jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp phps
.