DrupalBin
Submit Code
About
Recent Posts
Code
Fix for Code
Code
Fix for filefield implementation in an admin page. "An HTTP error 0 occurred. /drupal/?q=filefield/ahah///"
Undefined index:
searching for two different taxonomy terms - get this into views (2 on D6)?
Converting D6 to D7
error on clone same as earlier error on migrate
Reordering ORDER BY elements in selectQuery query
Fix for Fix for prefix_sufix_admin.inc
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 Manually created Views
View
Fix
November 29, 2007 - 3:46pm —
BrianJubal
function sitehelper_views_tables() {
// view created from email column in users table
$table = array(
// name of table
'name' => 'users',
'provider' => 'internal',
'join' => array(
'left' => array(
// all views (currently) must left join to the node table eventually (You can left join to some other table, which then left joins to the node table).
'table' => 'node',
// Left join means that the two tables have a field in common - the node table uses uid...
'field' => 'uid'
),
'right' => array(
// and the users table (named earlier in this function) uses uid.
'field' => 'uid'
),
),
'fields' => array(
// The field I want showing up in my view is the mail field in the users table - so I ask for it here.
'mail' => array(
// This next stuff is what you see when you go to build your view.
'name' => t('Sitehelper: Email'),
'sortable' => false,
'help' => t('This will display the email address of the node creator.'),
),
),
);
// I place all the info I just put together into $tables as "users".
$tables["users"] = $table;
// view from table limiting it to nodes with type 'cinfo' for future use.
$table = array(
'name'=> 'node',
'provider' => 'internal',
'join' => array(
'left' => array(
'table' => 'users',
'field' => 'uid'
),
'right' => array(
'field' => 'uid'
),
'extra' => array(
'type' => 'cinfo'
),
),
);
$tables["node_cinfo_filter"] = $table;
// here's the future use... uses the filtered info then grabs info from the content type cinfo table
$table = array(
'name' => 'content_type_cinfo',
'provider' => 'internal',
'join' => array(
'left' => array(
'table' => 'node_cinfo_filter',
'field' => 'nid'
),
'right' => array(
'field' => 'nid'
),
),
'fields' => array(
'field_batch_value' => array(
'name' => t('Sitehelper: Parent Batch'),
'sortable' => false,
'help' => t('Retrieves Batch field for client.'),
),
),
);
$tables["content_type_cinfo"] = $table;
// view created for table 'sitehelper_tracker' - created elsewhere in this module.
$table = array(
'name' => 'sitehelper_tracker',
'provider' => 'internal',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'nid'
),
'right' => array(
'field' => 'nid'
),
),
'fields' => array(
'transaction' => array(
'name' => t('Sitehelper: Node Changes'),
'sortable' => false,
'help' => t('This keeps track of node changes and provides the transaction type.'),
),
),
'filters' => array(
'timestamp' => array(
'name' => t('Sitehelper: Tracker Time'),
'operator' => 'views_handler_operator_gtlt',
'value' => views_handler_filter_date_value_form(),
'handler' => 'views_handler_filter_timestamp',
'option' => 'string',
'help' => t('This filter allows nodes to be filtered by the time of the Sitehelper Tracker.')
.' '. views_t_strings('filter date'),
),
),
);
$tables["sitehelper_tracker"] = $table;
// view for matrix fields
foreach (array(1,2,3,4) as $matrixrow) {
foreach (array(1,2) as $matrixcol) {
$matrixindex = $matrixrow.'_'.$matrixcol;
$table = array(
'name' => 'node_field_matrix_data',
'provider' => 'internal',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'nid'
),
'right' => array(
'field' => 'nid'
),
'extra' => array(
'row' => $matrixrow,
'col' => $matrixcol
),
),
'fields' => array(
'value' => array(
'name' => t("Sitehelper: Meter $matrixindex"),
'sortable' => false,
'help' => t("This will show the value of meter $matrixindex."),
),
),
);
$tables["node_field_matrix_data_$matrixindex"] = $table;
}
}
// views for the individual portions of cck_address
$table = array(
'name' => 'content_field_address',
'provider' => 'internal',
'join' => array(
'left' => array(
'table' => 'node',
'field' => 'nid'
),
'right' => array(
'field' => 'nid'
),
),
'fields' => array(
'field_address_street1' => array(
'name' => t('Sitehelper: Street Address'),
'sortable' => false,
'help' => t('This will display the Street Address.'),
),
'field_address_apt' => array(
'name' => t('Sitehelper: Apt'),
'sortable' => false,
'help' => t('This will display the Apt #.'),
),
'field_address_street2' => array(
'name' => t('Sitehelper: Street Address 2'),
'sortable' => false,
'help' => t('This will display the Street Address 2.'),
),
'field_address_city' => array(
'name' => t('Sitehelper: City'),
'sortable' => false,
'help' => t('This will display the City.'),
),
'field_address_state' => array(
'name' => t('Sitehelper: State'),
'sortable' => false,
'help' => t('This will display the State.'),
),
'field_address_zip' => array(
'name' => t('Sitehelper: Zip'),
'sortable' => false,
'help' => t('This will display the Zip Code.'),
),
'field_address_country' => array(
'name' => t('Sitehelper: Country'),
'sortable' => false,
'help' => t('This will display the Country.'),
),
),
);
$tables["content_field_address"] = $table;
return $tables;
}
// argument created for my sitehelper_tracker table
function sitehelper_views_arguments() {
$arguments = array(
'timestamp' => array(
'name' => t('Sitehelper: Transaction Time'),
'handler' => 'sitehelper_views_handler_arg_timestamp',
'help' => t('This argument is a complete date in the form of CCYYMMDD.'),
),
);
return $arguments;
}
function sitehelper_views_handler_arg_timestamp($op, &$query, $argtype, $arg = '') {
$timezone = _views_get_timezone();
switch($op) {
case 'summary':
$query->ensure_table('sitehelper_tracker');
$query->add_field('timestamp','sitehelper_tracker');
$fieldinfo['field'] = "DATE_FORMAT(FROM_UNIXTIME(sitehelper_tracker.timestamp+$timezone), '%Y%m%%d')";
$fieldinfo['fieldname'] = 'name';
return $fieldinfo;
break;
case 'sort':
$query->add_orderby(NULL, "DATE_FORMAT(FROM_UNIXTIME(sitehelper_tracker.timestamp+$timezone), '%Y%m%%d')", $argtype, 'name');
break;
case 'filter':
$query->add_where("DATE_FORMAT(FROM_UNIXTIME(sitehelper_tracker.timestamp+$timezone), '%Y%m%%d') = '%s'", $arg);
break;
case 'link':
return l(format_date($query->timestamp, 'custom', 'F j, Y'), "$arg/$query->name");
case 'title':
return format_date(strtotime($query), 'custom', 'F j, Y');
}
}
CCK
module
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
function sitehelper_views_tables() { // view created from email column in users table $table = array( // name of table 'name' => 'users', 'provider' => 'internal', 'join' => array( 'left' => array( // all views (currently) must left join to the node table eventually (You can left join to some other table, which then left joins to the node table). 'table' => 'node', // Left join means that the two tables have a field in common - the node table uses uid... 'field' => 'uid' ), 'right' => array( // and the users table (named earlier in this function) uses uid. 'field' => 'uid' ), ), 'fields' => array( // The field I want showing up in my view is the mail field in the users table - so I ask for it here. 'mail' => array( // This next stuff is what you see when you go to build your view. 'name' => t('Sitehelper: Email'), 'sortable' => false, 'help' => t('This will display the email address of the node creator.'), ), ), ); // I place all the info I just put together into $tables as "users". $tables["users"] = $table; // view from table limiting it to nodes with type 'cinfo' for future use. $table = array( 'name'=> 'node', 'provider' => 'internal', 'join' => array( 'left' => array( 'table' => 'users', 'field' => 'uid' ), 'right' => array( 'field' => 'uid' ), 'extra' => array( 'type' => 'cinfo' ), ), ); $tables["node_cinfo_filter"] = $table; // here's the future use... uses the filtered info then grabs info from the content type cinfo table $table = array( 'name' => 'content_type_cinfo', 'provider' => 'internal', 'join' => array( 'left' => array( 'table' => 'node_cinfo_filter', 'field' => 'nid' ), 'right' => array( 'field' => 'nid' ), ), 'fields' => array( 'field_batch_value' => array( 'name' => t('Sitehelper: Parent Batch'), 'sortable' => false, 'help' => t('Retrieves Batch field for client.'), ), ), ); $tables["content_type_cinfo"] = $table; // view created for table 'sitehelper_tracker' - created elsewhere in this module. $table = array( 'name' => 'sitehelper_tracker', 'provider' => 'internal', 'join' => array( 'left' => array( 'table' => 'node', 'field' => 'nid' ), 'right' => array( 'field' => 'nid' ), ), 'fields' => array( 'transaction' => array( 'name' => t('Sitehelper: Node Changes'), 'sortable' => false, 'help' => t('This keeps track of node changes and provides the transaction type.'), ), ), 'filters' => array( 'timestamp' => array( 'name' => t('Sitehelper: Tracker Time'), 'operator' => 'views_handler_operator_gtlt', 'value' => views_handler_filter_date_value_form(), 'handler' => 'views_handler_filter_timestamp', 'option' => 'string', 'help' => t('This filter allows nodes to be filtered by the time of the Sitehelper Tracker.') .' '. views_t_strings('filter date'), ), ), ); $tables["sitehelper_tracker"] = $table; // view for matrix fields foreach (array(1,2,3,4) as $matrixrow) { foreach (array(1,2) as $matrixcol) { $matrixindex = $matrixrow.'_'.$matrixcol; $table = array( 'name' => 'node_field_matrix_data', 'provider' => 'internal', 'join' => array( 'left' => array( 'table' => 'node', 'field' => 'nid' ), 'right' => array( 'field' => 'nid' ), 'extra' => array( 'row' => $matrixrow, 'col' => $matrixcol ), ), 'fields' => array( 'value' => array( 'name' => t("Sitehelper: Meter $matrixindex"), 'sortable' => false, 'help' => t("This will show the value of meter $matrixindex."), ), ), ); $tables["node_field_matrix_data_$matrixindex"] = $table; } } // views for the individual portions of cck_address $table = array( 'name' => 'content_field_address', 'provider' => 'internal', 'join' => array( 'left' => array( 'table' => 'node', 'field' => 'nid' ), 'right' => array( 'field' => 'nid' ), ), 'fields' => array( 'field_address_street1' => array( 'name' => t('Sitehelper: Street Address'), 'sortable' => false, 'help' => t('This will display the Street Address.'), ), 'field_address_apt' => array( 'name' => t('Sitehelper: Apt'), 'sortable' => false, 'help' => t('This will display the Apt #.'), ), 'field_address_street2' => array( 'name' => t('Sitehelper: Street Address 2'), 'sortable' => false, 'help' => t('This will display the Street Address 2.'), ), 'field_address_city' => array( 'name' => t('Sitehelper: City'), 'sortable' => false, 'help' => t('This will display the City.'), ), 'field_address_state' => array( 'name' => t('Sitehelper: State'), 'sortable' => false, 'help' => t('This will display the State.'), ), 'field_address_zip' => array( 'name' => t('Sitehelper: Zip'), 'sortable' => false, 'help' => t('This will display the Zip Code.'), ), 'field_address_country' => array( 'name' => t('Sitehelper: Country'), 'sortable' => false, 'help' => t('This will display the Country.'), ), ), ); $tables["content_field_address"] = $table; return $tables; } // argument created for my sitehelper_tracker table function sitehelper_views_arguments() { $arguments = array( 'timestamp' => array( 'name' => t('Sitehelper: Transaction Time'), 'handler' => 'sitehelper_views_handler_arg_timestamp', 'help' => t('This argument is a complete date in the form of CCYYMMDD.'), ), ); return $arguments; } function sitehelper_views_handler_arg_timestamp($op, &$query, $argtype, $arg = '') { $timezone = _views_get_timezone(); switch($op) { case 'summary': $query->ensure_table('sitehelper_tracker'); $query->add_field('timestamp','sitehelper_tracker'); $fieldinfo['field'] = "DATE_FORMAT(FROM_UNIXTIME(sitehelper_tracker.timestamp+$timezone), '%Y%m%%d')"; $fieldinfo['fieldname'] = 'name'; return $fieldinfo; break; case 'sort': $query->add_orderby(NULL, "DATE_FORMAT(FROM_UNIXTIME(sitehelper_tracker.timestamp+$timezone), '%Y%m%%d')", $argtype, 'name'); break; case 'filter': $query->add_where("DATE_FORMAT(FROM_UNIXTIME(sitehelper_tracker.timestamp+$timezone), '%Y%m%%d') = '%s'", $arg); break; case 'link': return l(format_date($query->timestamp, 'custom', 'F j, Y'), "$arg/$query->name"); case 'title': return format_date(strtotime($query), 'custom', 'F j, Y'); } }
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
.