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