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 />

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 22:14:24
Script start
Timing: Jan 18 2025 22:14:24
Module start 'layout'
Timing: Jan 18 2025 22:14:24
Module start 'content'
Timing: Jan 18 2025 22:14:25
Module end 'content'
Timing: Jan 18 2025 22:14:25
Script end

Main resources:

Total runtime1.2630 sec
Peak memory usage4,096.0000 KB
Database Queries55

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0060 589.4766152.6406
Module start 'layout' 0.00600.0038 742.117239.4766
Module start 'content' 0.00981.2517 781.5938486.6953
Module end 'content' 1.26150.0015 1,268.289112.1250
Script end 1.2630  1,280.4141 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.2510160.0002
Check MTime0.00130.1058160.0001
Mysql Total
Database connection0.00080.065410.0008
Mysqli_queries1.215896.2643550.0221
Looping result0.00040.0324530.0000
Template Total1.234597.720.6172
Template load0.00190.147420.0009
Template processing1.232697.593520.6163
Template load and register function0.00010.009810.0001
states
state_id_array0.00110.083610.0011
state_identifier_array0.00070.057120.0004
Override
Cache load0.00150.1193270.0001
Sytem overhead
Fetch class attribute can translate value0.00060.046510.0006
Fetch class attribute name0.00090.069040.0002
XML
Image XML parsing0.00040.034410.0004
class_abstraction
Instantiating content class attribute0.00000.001160.0000
General
dbfile0.00110.0856160.0001
String conversion0.00000.000840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 18
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs