View to display user points and the reason for the points-Collection of common programming errors
I have userpoints active on one of my sites, and the display you are looking for is integrated with the module.
Look at the user account, there should be a tab (Points) (/user/$uid/points).
To create your own page, introduce a required relationship to the users table, then a contextual filter using that relationship on user:uid. When the configuration screen comes up, under ‘When the filter is not in the URL’ provide a default value > UID from currently logged in user. This should get your view working.
Note: The relationship must be created first, then it is available for the contextual filter.
Edit: Step by step.
- Add new view: (/admin/structure/views/add)
In the ‘Add View’ screen, enter view name, and choose to Show ‘Userpoints Transactions’ of type ‘all’. I chose a Table format to show fields. The rest is adjustable later.
Click ‘Continue and Edit’ to go to the edit screen.
-
Add a relationship for Userpoints Transactions:User. Check ‘Required’ and ‘Apply all displays’. This will bring the users table into the view.
-
Create a contextual filter on users:uid using the relationship you just created. Configure the default value provided as ‘UID from logged in user’, and Apply.
-
Add whatever fields you wish and format the view.
This is the export:
$view = new view();
$view->name = 'users_points';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'userpoints_txn';
$view->human_name = 'Users Points';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Users Points';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'none';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'full';
$handler->display->display_options['pager']['options']['items_per_page'] = '10';
$handler->display->display_options['style_plugin'] = 'table';
/* Relationship: Userpoints Transactions: User */
$handler->display->display_options['relationships']['uid']['id'] = 'uid';
$handler->display->display_options['relationships']['uid']['table'] = 'userpoints_txn';
$handler->display->display_options['relationships']['uid']['field'] = 'uid';
$handler->display->display_options['relationships']['uid']['required'] = TRUE;
/* Field: User: Name */
$handler->display->display_options['fields']['name']['id'] = 'name';
$handler->display->display_options['fields']['name']['table'] = 'users';
$handler->display->display_options['fields']['name']['field'] = 'name';
$handler->display->display_options['fields']['name']['relationship'] = 'uid';
/* Field: Userpoints Transactions: Description */
$handler->display->display_options['fields']['description']['id'] = 'description';
$handler->display->display_options['fields']['description']['table'] = 'userpoints_txn';
$handler->display->display_options['fields']['description']['field'] = 'description';
/* Field: Userpoints Transactions: Points */
$handler->display->display_options['fields']['points']['id'] = 'points';
$handler->display->display_options['fields']['points']['table'] = 'userpoints_txn';
$handler->display->display_options['fields']['points']['field'] = 'points';
/* Contextual filter: User: Uid */
$handler->display->display_options['arguments']['uid']['id'] = 'uid';
$handler->display->display_options['arguments']['uid']['table'] = 'users';
$handler->display->display_options['arguments']['uid']['field'] = 'uid';
$handler->display->display_options['arguments']['uid']['relationship'] = 'uid';
$handler->display->display_options['arguments']['uid']['default_action'] = 'default';
$handler->display->display_options['arguments']['uid']['default_argument_type'] = 'current_user';
$handler->display->display_options['arguments']['uid']['summary']['number_of_records'] = '0';
$handler->display->display_options['arguments']['uid']['summary']['format'] = 'default_summary';
$handler->display->display_options['arguments']['uid']['summary_options']['items_per_page'] = '25';
/* Display: Page */
$handler = $view->new_display('page', 'Page', 'page');
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['path'] = 'users-points';
/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block');
$handler->display->display_options['defaults']['hide_admin_links'] = FALSE;
$handler->display->display_options['defaults']['pager'] = FALSE;
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '5';
Second Edit:
The descriptions shown in the screen print you showed me are not stored in the database, but are generated on the fly when the page is requested.
Here is how you complete the view.
First, install and activate the Views PHP module.
Second, go into userpoints.views.inc, make the change on line 435 noted in my comment. Then insert the following code after line 466:
$data['userpoints_txn']['txn_id'] = array(
'title' => t('Transaction ID'),
'help' => t('The transaction ID for the points allocation.'),
'field' => array(
'handler' => 'views_handler_field',
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
This will make the Transaction ID accessible to views. (The necessary changes are included in a patch file linked at the end of this answer.)
Save your view in its current form to clear its temporary cache, then go to /admin/config/development/performance and clear your caches.
Return to your view, and add the Userpoints Transactions:Transaction ID as a field, and set it as excluded from the display.
Then add another field. In the Add Field screen, filter on Global, and select Global:PHP.
To configure the field, Create a label of your choosing, and in the Output box add the following:
Note: Do not place anything in the Value box! It is used for another purpose.
Save your view, and you are good to go.
BTW. The changes necessary in userpoints.views.inc are in a patch attached to the Features Request issue I opened on D.O.
Originally posted 2013-11-09 22:40:42.