Monday 13 September 2004 1:00:46 am
It is not possible to do this in templates. You can only fetch information and display it in the templates. You cannot do "business logic" like this in them. To do this you could e.g. write a module which would handle the actual storing of the rating. Then you could write an template operator which would display the results for your item. You would then append this to the article template ( or whatever content you would like to rate ):
<form action="/myratingmodule/rateview" method="post">
<input type="hidden" name="RatingKey" value="{$node.node_id}" />
Rating value (could be e.g. a select box ):
<input name="Value"/>
<input type="submit">
</form>
The module would then read the RatingKey value, checked if the user is logged in, and store the value. You would probably need to add some checking, e.g. only one vote pr user pr key. The template operator would be used to fetch the rating results. E.g.
Total number of votes {myratingOperatorResult( hash( 'key', $node.node_id,
'function', 'total_votes' ) )}
Average vote {myratingOperatorResult( hash( 'key', $node.node_id,
'function', 'average_value' ) )}
I hope this helped. To sum up you need a module which can do the storing of the form values (with validation) and you need a template operator to fetch the results, using a key to make the votes unique and re-useable. --bård
Documentation: http://ez.no/doc
|