{"id":765,"date":"2022-08-30T15:06:48","date_gmt":"2022-08-30T15:06:48","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/view-to-display-user-points-and-the-reason-for-the-points-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:06:48","modified_gmt":"2022-08-30T15:06:48","slug":"view-to-display-user-points-and-the-reason-for-the-points-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/view-to-display-user-points-and-the-reason-for-the-points-collection-of-common-programming-errors\/","title":{"rendered":"View to display user points and the reason for the points-Collection of common programming errors"},"content":{"rendered":"<p>I have userpoints active on one of my sites, and the display you are looking for is integrated with the module.<\/p>\n<p>Look at the user account, there should be a tab (Points) (\/user\/$uid\/points).<\/p>\n<p>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 &#8216;When the filter is not in the URL&#8217; provide a default value &gt; UID from currently logged in user. This should get your view working.<\/p>\n<p>Note: The relationship must be created first, then it is available for the contextual filter.<\/p>\n<p>Edit: Step by step.<\/p>\n<ol>\n<li>Add new view: (\/admin\/structure\/views\/add)<\/li>\n<\/ol>\n<p>In the &#8216;Add View&#8217; screen, enter view name, and choose to Show &#8216;Userpoints Transactions&#8217; of type &#8216;all&#8217;. I chose a Table format to show fields. The rest is adjustable later.<\/p>\n<p>Click &#8216;Continue and Edit&#8217; to go to the edit screen.<\/p>\n<ol>\n<li>\n<p>Add a relationship for Userpoints Transactions:User. Check &#8216;Required&#8217; and &#8216;Apply all displays&#8217;. This will bring the users table into the view.<\/p>\n<\/li>\n<li>\n<p>Create a contextual filter on users:uid using the relationship you just created. Configure the default value provided as &#8216;UID from logged in user&#8217;, and Apply.<\/p>\n<\/li>\n<li>\n<p>Add whatever fields you wish and format the view.<\/p>\n<\/li>\n<\/ol>\n<p>This is the export:<\/p>\n<pre><code>$view = new view();\n$view-&gt;name = 'users_points';\n$view-&gt;description = '';\n$view-&gt;tag = 'default';\n$view-&gt;base_table = 'userpoints_txn';\n$view-&gt;human_name = 'Users Points';\n$view-&gt;core = 7;\n$view-&gt;api_version = '3.0';\n$view-&gt;disabled = FALSE; \/* Edit this to true to make a default view disabled initially *\/\n\n\/* Display: Master *\/\n$handler = $view-&gt;new_display('default', 'Master', 'default');\n$handler-&gt;display-&gt;display_options['title'] = 'Users Points';\n$handler-&gt;display-&gt;display_options['use_more_always'] = FALSE;\n$handler-&gt;display-&gt;display_options['access']['type'] = 'none';\n$handler-&gt;display-&gt;display_options['cache']['type'] = 'none';\n$handler-&gt;display-&gt;display_options['query']['type'] = 'views_query';\n$handler-&gt;display-&gt;display_options['exposed_form']['type'] = 'basic';\n$handler-&gt;display-&gt;display_options['pager']['type'] = 'full';\n$handler-&gt;display-&gt;display_options['pager']['options']['items_per_page'] = '10';\n$handler-&gt;display-&gt;display_options['style_plugin'] = 'table';\n\/* Relationship: Userpoints Transactions: User *\/\n$handler-&gt;display-&gt;display_options['relationships']['uid']['id'] = 'uid';\n$handler-&gt;display-&gt;display_options['relationships']['uid']['table'] = 'userpoints_txn';\n$handler-&gt;display-&gt;display_options['relationships']['uid']['field'] = 'uid';\n$handler-&gt;display-&gt;display_options['relationships']['uid']['required'] = TRUE;\n\/* Field: User: Name *\/\n$handler-&gt;display-&gt;display_options['fields']['name']['id'] = 'name';\n$handler-&gt;display-&gt;display_options['fields']['name']['table'] = 'users';\n$handler-&gt;display-&gt;display_options['fields']['name']['field'] = 'name';\n$handler-&gt;display-&gt;display_options['fields']['name']['relationship'] = 'uid';\n\/* Field: Userpoints Transactions: Description *\/\n$handler-&gt;display-&gt;display_options['fields']['description']['id'] = 'description';\n$handler-&gt;display-&gt;display_options['fields']['description']['table'] = 'userpoints_txn';\n$handler-&gt;display-&gt;display_options['fields']['description']['field'] = 'description';\n\/* Field: Userpoints Transactions: Points *\/\n$handler-&gt;display-&gt;display_options['fields']['points']['id'] = 'points';\n$handler-&gt;display-&gt;display_options['fields']['points']['table'] = 'userpoints_txn';\n$handler-&gt;display-&gt;display_options['fields']['points']['field'] = 'points';\n\/* Contextual filter: User: Uid *\/\n$handler-&gt;display-&gt;display_options['arguments']['uid']['id'] = 'uid';\n$handler-&gt;display-&gt;display_options['arguments']['uid']['table'] = 'users';\n$handler-&gt;display-&gt;display_options['arguments']['uid']['field'] = 'uid';\n$handler-&gt;display-&gt;display_options['arguments']['uid']['relationship'] = 'uid';\n$handler-&gt;display-&gt;display_options['arguments']['uid']['default_action'] = 'default';\n$handler-&gt;display-&gt;display_options['arguments']['uid']['default_argument_type'] = 'current_user';\n$handler-&gt;display-&gt;display_options['arguments']['uid']['summary']['number_of_records'] = '0';\n$handler-&gt;display-&gt;display_options['arguments']['uid']['summary']['format'] = 'default_summary';\n$handler-&gt;display-&gt;display_options['arguments']['uid']['summary_options']['items_per_page'] = '25';\n\n\/* Display: Page *\/\n$handler = $view-&gt;new_display('page', 'Page', 'page');\n$handler-&gt;display-&gt;display_options['defaults']['hide_admin_links'] = FALSE;\n$handler-&gt;display-&gt;display_options['path'] = 'users-points';\n\n\/* Display: Block *\/\n$handler = $view-&gt;new_display('block', 'Block', 'block');\n$handler-&gt;display-&gt;display_options['defaults']['hide_admin_links'] = FALSE;\n$handler-&gt;display-&gt;display_options['defaults']['pager'] = FALSE;\n$handler-&gt;display-&gt;display_options['pager']['type'] = 'some';\n$handler-&gt;display-&gt;display_options['pager']['options']['items_per_page'] = '5';\n<\/code><\/pre>\n<p>Second Edit:<\/p>\n<p>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.<\/p>\n<p>Here is how you complete the view.<\/p>\n<p>First, install and activate the Views PHP module.<\/p>\n<p>Second, go into userpoints.views.inc, make the change on line 435 noted in my comment. Then insert the following code after line 466:<\/p>\n<pre><code>$data['userpoints_txn']['txn_id'] = array(\n      'title' =&gt; t('Transaction ID'),\n      'help' =&gt; t('The transaction ID for the points allocation.'),\n      'field' =&gt; array(\n          'handler' =&gt; 'views_handler_field',\n      ),\n      'filter' =&gt; array(\n          'handler' =&gt; 'views_handler_filter_string',\n      ),\n      'sort' =&gt; array(\n          'handler' =&gt; 'views_handler_sort',\n      ),\n  );\n<\/code><\/pre>\n<p>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.)<\/p>\n<p>Save your view in its current form to clear its temporary cache, then go to \/admin\/config\/development\/performance and clear your caches.<\/p>\n<p>Return to your view, and add the Userpoints Transactions:Transaction ID as a field, and set it as excluded from the display.<\/p>\n<p>Then add another field. In the Add Field screen, filter on Global, and select Global:PHP.<\/p>\n<p>To configure the field, Create a label of your choosing, and in the Output box add the following:<\/p>\n<pre><code>\n<\/code><\/pre>\n<p>Note: Do not place anything in the Value box! It is used for another purpose.<\/p>\n<p>Save your view, and you are good to go.<\/p>\n<p>BTW. The changes necessary in userpoints.views.inc are in a patch attached to the Features Request issue I opened on D.O.<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 22:40:42. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>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. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-765","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/765","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=765"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/765\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}