2009-05-17 11:16:51 +00:00
< ? php
/**
* @ file
* Provide views data and handlers for user . module .
*
* @ ingroup views_module_handlers
*/
/**
* Implements hook_views_data () .
*/
function user_views_data () {
// users table
// Define the base group of this table. Fields that don't
// have a group defined will go into this field by default.
$data [ 'users' ][ 'table' ][ 'group' ] = t ( 'User' );
$data [ 'users' ][ 'table' ][ 'base' ] = array (
'field' => 'uid' ,
'title' => t ( 'User' ),
'help' => t ( 'Users who have created accounts on your site.' ),
'access query tag' => 'user_access' ,
);
$data [ 'users' ][ 'table' ][ 'entity type' ] = 'user' ;
2012-11-29 06:20:24 +00:00
$data [ 'users' ][ 'table' ][ 'wizard_id' ] = 'user' ;
2009-05-17 11:16:51 +00:00
// uid
$data [ 'users' ][ 'uid' ] = array (
'title' => t ( 'Uid' ),
'help' => t ( 'The user ID' ), // The help that appears on the UI,
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'user' ,
2009-05-17 11:16:51 +00:00
),
'argument' => array (
2012-08-11 11:46:07 +00:00
'id' => 'user_uid' ,
2009-05-17 11:16:51 +00:00
'name field' => 'name' , // display this field in the summary
),
'filter' => array (
'title' => t ( 'Name' ),
2012-08-11 11:46:07 +00:00
'id' => 'user_name' ,
2009-05-17 11:16:51 +00:00
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
'relationship' => array (
'title' => t ( 'Content authored' ),
'help' => t ( 'Relate content to the user who created it. This relationship will create one record for each content item created by the user.' ),
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
'base' => 'node' ,
'base field' => 'uid' ,
'field' => 'uid' ,
'label' => t ( 'nodes' ),
),
);
2012-05-28 07:22:07 +00:00
// uid_raw
$data [ 'users' ][ 'uid_raw' ] = array (
'help' => t ( 'The raw numeric user ID.' ),
'real field' => 'uid' ,
'filter' => array (
'title' => t ( 'The user ID' ),
2012-08-11 11:46:07 +00:00
'id' => 'numeric' ,
2012-05-28 07:22:07 +00:00
),
);
2009-05-17 11:16:51 +00:00
// uid
$data [ 'users' ][ 'uid_representative' ] = array (
'relationship' => array (
'title' => t ( 'Representative node' ),
'label' => t ( 'Representative node' ),
'help' => t ( 'Obtains a single representative node for each user, according to a chosen sort criterion.' ),
2012-08-11 11:46:07 +00:00
'id' => 'groupwise_max' ,
2009-05-17 11:16:51 +00:00
'relationship field' => 'uid' ,
'outer field' => 'users.uid' ,
'argument table' => 'users' ,
2012-10-12 08:49:10 +00:00
'argument field' => 'uid' ,
'base' => 'node' ,
'field' => 'nid' ,
'relationship' => 'node:uid'
2009-05-17 11:16:51 +00:00
),
);
// uid
$data [ 'users' ][ 'uid_current' ] = array (
'real field' => 'uid' ,
'title' => t ( 'Current' ),
'help' => t ( 'Filter the view to the currently logged in user.' ),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'user_current' ,
2009-05-17 11:16:51 +00:00
'type' => 'yes-no' ,
),
);
// name
$data [ 'users' ][ 'name' ] = array (
'title' => t ( 'Name' ), // The item it appears as on the UI,
'help' => t ( 'The user or author name.' ), // The help that appears on the UI,
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'user_name' ,
2009-05-17 11:16:51 +00:00
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
'argument' => array (
2012-08-11 11:46:07 +00:00
'id' => 'string' ,
2009-05-17 11:16:51 +00:00
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'string' ,
2009-05-17 11:16:51 +00:00
'title' => t ( 'Name (raw)' ),
'help' => t ( 'The user or author name. This filter does not check if the user exists and allows partial matching. Does not utilize autocomplete.' )
),
);
// mail
// Note that this field implements field level access control.
$data [ 'users' ][ 'mail' ] = array (
'title' => t ( 'E-mail' ), // The item it appears as on the UI,
'help' => t ( 'Email address for a given user. This field is normally not shown to users, so be cautious when using it.' ), // The help that appears on the UI,
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'user_mail' ,
2009-05-17 11:16:51 +00:00
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'string' ,
2009-05-17 11:16:51 +00:00
),
'argument' => array (
2012-08-11 11:46:07 +00:00
'id' => 'string' ,
2009-05-17 11:16:51 +00:00
),
);
// language
2012-08-26 19:44:59 +00:00
$data [ 'users' ][ 'langcode' ] = array (
2009-05-17 11:16:51 +00:00
'title' => t ( 'Language' ), // The item it appears as on the UI,
'help' => t ( 'Language of the user' ),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'user_language' ,
2009-05-17 11:16:51 +00:00
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
'filter' => array (
2012-09-12 22:26:07 +00:00
'id' => 'language' ,
2009-05-17 11:16:51 +00:00
),
'argument' => array (
2012-09-12 22:26:07 +00:00
'id' => 'language' ,
2009-05-17 11:16:51 +00:00
),
);
// link
$data [ 'users' ][ 'view_user' ] = array (
'field' => array (
'title' => t ( 'Link' ),
'help' => t ( 'Provide a simple link to the user.' ),
2012-08-11 11:46:07 +00:00
'id' => 'user_link' ,
2013-01-21 20:59:01 +00:00
'click sortable' => FALSE ,
2009-05-17 11:16:51 +00:00
),
);
// created field
$data [ 'users' ][ 'created' ] = array (
'title' => t ( 'Created date' ), // The item it appears as on the UI,
'help' => t ( 'The date the user was created.' ), // The help that appears on the UI,
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'date' ,
2009-05-17 11:16:51 +00:00
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'date'
2009-05-17 11:16:51 +00:00
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'date' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'users' ][ 'created_fulldate' ] = array (
'title' => t ( 'Created date' ),
'help' => t ( 'Date in the form of CCYYMMDD.' ),
'argument' => array (
'field' => 'created' ,
2012-08-11 11:46:07 +00:00
'id' => 'node_created_fulldate' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'users' ][ 'created_year_month' ] = array (
'title' => t ( 'Created year + month' ),
'help' => t ( 'Date in the form of YYYYMM.' ),
'argument' => array (
'field' => 'created' ,
2012-08-11 11:46:07 +00:00
'id' => 'node_created_year_month' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'users' ][ 'created_year' ] = array (
'title' => t ( 'Created year' ),
'help' => t ( 'Date in the form of YYYY.' ),
'argument' => array (
'field' => 'created' ,
2012-08-11 11:46:07 +00:00
'id' => 'node_created_year' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'users' ][ 'created_month' ] = array (
'title' => t ( 'Created month' ),
'help' => t ( 'Date in the form of MM (01 - 12).' ),
'argument' => array (
'field' => 'created' ,
2012-08-11 11:46:07 +00:00
'id' => 'node_created_month' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'users' ][ 'created_day' ] = array (
'title' => t ( 'Created day' ),
'help' => t ( 'Date in the form of DD (01 - 31).' ),
'argument' => array (
'field' => 'created' ,
2012-08-11 11:46:07 +00:00
'id' => 'node_created_day' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'users' ][ 'created_week' ] = array (
'title' => t ( 'Created week' ),
'help' => t ( 'Date in the form of WW (01 - 53).' ),
'argument' => array (
'field' => 'created' ,
2012-08-11 11:46:07 +00:00
'id' => 'node_created_week' ,
2009-05-17 11:16:51 +00:00
),
);
// access field
$data [ 'users' ][ 'access' ] = array (
'title' => t ( 'Last access' ), // The item it appears as on the UI,
'help' => t ( " The user's last access date. " ), // The help that appears on the UI,
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'date' ,
2009-05-17 11:16:51 +00:00
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'date'
2009-05-17 11:16:51 +00:00
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'date' ,
2009-05-17 11:16:51 +00:00
),
);
// login field
$data [ 'users' ][ 'login' ] = array (
'title' => t ( 'Last login' ), // The item it appears as on the UI,
'help' => t ( " The user's last login date. " ), // The help that appears on the UI,
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'date' ,
2009-05-17 11:16:51 +00:00
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'date'
2009-05-17 11:16:51 +00:00
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'date' ,
2009-05-17 11:16:51 +00:00
),
);
// active status
$data [ 'users' ][ 'status' ] = array (
'title' => t ( 'Active' ), // The item it appears as on the UI,
'help' => t ( 'Whether a user is active or blocked.' ), // The help that appears on the UI,
// Information for displaying a title as a field
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'boolean' ,
2009-05-17 11:16:51 +00:00
'output formats' => array (
'active-blocked' => array ( t ( 'Active' ), t ( 'Blocked' )),
),
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'boolean' ,
2009-05-17 11:16:51 +00:00
'label' => t ( 'Active' ),
'type' => 'yes-no' ,
),
'sort' => array (
2012-08-11 11:46:07 +00:00
'id' => 'standard' ,
2009-05-17 11:16:51 +00:00
),
);
// log field
$data [ 'users' ][ 'signature' ] = array (
'title' => t ( 'Signature' ), // The item it appears as on the UI,
'help' => t ( " The user's signature. " ), // The help that appears on the UI,
// Information for displaying a title as a field
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'markup' ,
2009-05-17 11:16:51 +00:00
'format' => filter_fallback_format (),
2013-01-21 20:59:01 +00:00
'click sortable' => FALSE ,
2009-05-17 11:16:51 +00:00
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'string' ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'users' ][ 'edit_node' ] = array (
'field' => array (
'title' => t ( 'Edit link' ),
'help' => t ( 'Provide a simple link to edit the user.' ),
2012-08-11 11:46:07 +00:00
'id' => 'user_link_edit' ,
2013-01-21 20:59:01 +00:00
'click sortable' => FALSE ,
2009-05-17 11:16:51 +00:00
),
);
$data [ 'users' ][ 'cancel_node' ] = array (
'field' => array (
'title' => t ( 'Cancel link' ),
'help' => t ( 'Provide a simple link to cancel the user.' ),
2012-08-11 11:46:07 +00:00
'id' => 'user_link_cancel' ,
2013-01-21 20:59:01 +00:00
'click sortable' => FALSE ,
2009-05-17 11:16:51 +00:00
),
);
// users_roles table
$data [ 'users_roles' ][ 'table' ][ 'group' ] = t ( 'User' );
// Explain how this table joins to others.
$data [ 'users_roles' ][ 'table' ][ 'join' ] = array (
// Directly links to users table.
'users' => array (
'left_field' => 'uid' ,
'field' => 'uid' ,
),
);
$data [ 'users_roles' ][ 'rid' ] = array (
'title' => t ( 'Roles' ),
'help' => t ( 'Roles that a user belongs to.' ),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'user_roles' ,
2009-05-17 11:16:51 +00:00
'no group by' => TRUE ,
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'user_roles' ,
2009-05-17 11:16:51 +00:00
'allow empty' => TRUE ,
),
'argument' => array (
2012-08-11 11:46:07 +00:00
'id' => 'users_roles_rid' ,
2009-05-17 11:16:51 +00:00
'name table' => 'role' ,
'name field' => 'name' ,
'empty field name' => t ( 'No role' ),
'zero is null' => TRUE ,
'numeric' => TRUE ,
),
);
// permission table
$data [ 'role_permission' ][ 'table' ][ 'group' ] = t ( 'User' );
$data [ 'role_permission' ][ 'table' ][ 'join' ] = array (
// Directly links to users table.
'users' => array (
'left_table' => 'users_roles' ,
'left_field' => 'rid' ,
'field' => 'rid' ,
),
);
$data [ 'role_permission' ][ 'permission' ] = array (
'title' => t ( 'Permission' ),
'help' => t ( 'The user permissions.' ),
'field' => array (
2012-08-11 11:46:07 +00:00
'id' => 'user_permissions' ,
2009-05-17 11:16:51 +00:00
'no group by' => TRUE ,
),
'filter' => array (
2012-08-11 11:46:07 +00:00
'id' => 'user_permissions' ,
2009-05-17 11:16:51 +00:00
),
);
return $data ;
}
/**
* Allow replacement of current userid so we can cache these queries
*/
function user_views_query_substitutions ( $view ) {
global $user ;
return array ( '***CURRENT_USER***' => intval ( $user -> uid ));
}