Forums / Developer / Polls - Fetch to display User's Vote Value?

Polls - Fetch to display User's Vote Value?

Author Message

Paul Wilson

Saturday 18 February 2006 1:57:05 am

Hi,

<b>Question:</b> Has anyone created a fetch function to obtain the object/value of a user's poll response? Any clues or suggestions on ways forward gratefully accepted!

<b>Situation:</b> I want to adapt the standard EZ Publish Poll functions to show the vote that a (registered) user has made. Why? Because I want to allow users to revisit old polls and see how they voted. This might mean adding something like "your vote was for [option label]"

<b>Background:</b>
The standard EZ Publish Poll functions allow a user to enter their vote, and then a simple chart of the Poll's results is displayed. This is assisted by the "collected_info_count" and "collected_info_count_list" functions, but even though there is a "user_identifier" for ezinformationcollection objects, I can't see an easy means for accessing this value.

Thanks.

Paul Wilson

Saturday 18 February 2006 9:27:21 pm

Looking at EZP 3.7.2 or 3, fetch functions seem to be defined in:

<b>/kernel/content/ezcontentfunctioncollection.php</b>

And this refers to:

<b>/kernel/classes/ezinformationcollection.php</b>

This file contains a function called <b>"fetchByUserIdentifier"</b> which "fetches the information collection by user identifier" (line 419). But this seems to be internal to EZ Publish or not documented. Perhaps there is a way to access this or a completely different method somewhere.

Paul Wilson

Monday 20 February 2006 6:46:37 am

In case it is of use to anyone, here's where I got to...

<b>A Solution</b>
It isn't particularly pretty, but the code below shows a solution I put together. NB: I modified the poll class to include an additional information collector text-line for "user_id" - I realise this seems to be already stored somehow, but I couldn't figure out how to access it.

<b>Overview</b>
I added this code to the poll_result.tpl file so that the (registered) user's response to a Poll is can be displayed in the template. This code only identifies that response and displays it.

The code searches through collected_information attributes for ones that match the Poll attributes (question, and the "user_id" attribute I added). This is compared to the object_id for the Poll and the current user's id. If there is a match, then the user's response is stored in the $user_result variable.

The code follows ... in unrefined form. (Using EZP 3.7.2)

{def $user=fetch( 'user', 'current_user' )}
{let $user_id=$user.contentobject_id}
{def 	$total_counted=0
	$nullresult='F'	
	$current_collected_item=1
	$current_collected_user=$nullresult
	$current_collected_option=$nullresult
	$user_result=$nullresult
	$all_counted=0
	$my_total_count=fetch( 'content', 'collected_info_count', hash( 'object_id', $object.id ))
	$attribute_origin_object_id=""
	$collection=""
	$search_finished='FALSE'}

{while ne($search_finished,'TRUE')}
	{set $collection=fetch( 'content', 'collected_info_collection',
                        hash( 'collection_id',  $current_collected_item,
                              'contentobject_id', $object.id ))}
	{if ne($collection, FALSE)}
	{foreach $collection.attributes as $attribute}
		{if eq($attribute.contentobject_attribute.is_a, 'ezstring')}
			{set $current_collected_user=$attribute.data_text}
		{/if}
		{if eq($attribute.contentobject_attribute.is_a, 'ezoption')}
			{set $current_collected_option= $attribute.contentobject_attribute.content.option_list[$:attribute.data_int].value}
		{/if}
		{set $attribute_origin_object_id= $attribute.contentobject_attribute.contentobject_id}
	{/foreach}
	{section validobjecttype=eq($object.id, $attribute_origin_object_id)}
		{if eq($current_collected_user, $user_id)}
			{set $user_result=$current_collected_option}
		{/if}
		{* set $total_counted=inc($total_counted) *}
	{/section}
	{/if}
	{set $current_collected_item=inc($current_collected_item)}
	{if ne($user_result, $nullresult)}
		{set $search_finished='TRUE'}
	{/if}
{/while}
YOUR POLL SELECTION: {$user_result} <br />

eZ debug

Timing: Jan 19 2025 03:23:12
Script start
Timing: Jan 19 2025 03:23:12
Module start 'content'
Timing: Jan 19 2025 03:23:12
Module end 'content'
Timing: Jan 19 2025 03:23:13
Script end

Main resources:

Total runtime0.1982 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0095 589.0859180.8125
Module start 'content' 0.00950.0086 769.898498.0547
Module end 'content' 0.01810.1800 867.9531526.8750
Script end 0.1981  1,394.8281 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00402.0363200.0002
Check MTime0.00160.8018200.0001
Mysql Total
Database connection0.00130.638710.0013
Mysqli_queries0.144773.00881410.0010
Looping result0.00150.76361390.0000
Template Total0.179490.510.1794
Template load0.00100.482810.0010
Template processing0.178489.997710.1784
Override
Cache load0.00060.327410.0006
Sytem overhead
Fetch class attribute can translate value0.00080.421710.0008
XML
Image XML parsing0.00030.129210.0003
General
dbfile0.00412.0650200.0002
String conversion0.00000.004630.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs