Forums / General / How to make article rating?

How to make article rating?

Author Message

Mieczyslaw Morzonek

Friday 10 September 2004 3:20:49 am

Is it possible to do it using the template and without modification of source code?
Is threre any simple method to do it?

I need any help.

I am run out of ideas

Bård Farstad

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

Mieczyslaw Morzonek

Sunday 17 October 2004 1:51:38 pm

Hi Bård

Could you give me an advice how to setup right table for this article rating?

Is this a good project?

CREATE TABLE `ezarticle_rating` (
  `node_id` int(11) NOT NULL default '0',
  `rate` int(11) NOT NULL default '0',
  `votes` int(11) NOT NULL default '0',
  `ip` varchar(15) binary NOT NULL default '',
  PRIMARY KEY  (`node_id`)
) TYPE=MyISAM;
        

SQL

UPDATE ezarticle_rating SET rate=rate+$_POST['value'], 
              votes=votes+1, ip=$_SERVER[''] WHERE node_id=$_POST['RatingKey']

or

INSERT INTO ezarticle_rating(node_is, rate, votes, ip) 
            VALUES ($_POST['RatingKey'], $_POST['value'], '1', $_SERVER[''])

Thank you for any help

Marco Zinn

Monday 18 October 2004 12:50:01 pm

Well, Bard probably is in Munich this week, so i'll try to publish a posting "behing his back" ;)
Just kidding, but maybe this approach could work, too, without having to do coding:
Create a new class called "vote" (or re-use the "product review" from the shop). Add a "number" attribute (integer value, selector, enum or something like that, that stores a number)... for example to allow number 0..10
Let the user create these "vote"-objects as children of your article.
Now change the article template and add a section, that:
- loops (and possibly prints) all child votes
- adds up the "vote numbers" (l..10) of these children
- after finishing the section, divides the sum by the number of children of the vote class
Print that value as an average vote.

I see no reason, why this should not work.
Beware of
- bad statistics (only show, when you have 5 or more votes)
- double voting
- dividing by 0
- a good permission setup, so users can create votes only, where they should.

We had this request, too, but dropped it due to time restrictions. This was my conceptual approach, not validated yet. Let me know, if you try this.

Marco
http://www.hyperroad-design.com

Tim Dickinson

Monday 18 October 2004 1:40:40 pm

This was started a while ago, and hasn't been updated for a while.

But might be worth a look:

http://ezratings.sourceforge.net/

Cheers

Tim

http://www.AdBalance.com - Ad network news and reviews
http://www.DevPublisher.com - Website publisher guides, tools and news
http://www.AudioMelody.com - Make better music

Mieczyslaw Morzonek

Monday 18 October 2004 11:46:27 pm

Hi,

I think that I finished "ezarticlerating" as a ez module, maybe tomorrow I add it to contribution.
Thanks for yours suggestions.

Tim Dickinson

Tuesday 19 October 2004 12:40:13 pm

That would be great,

Tim

http://www.AdBalance.com - Ad network news and reviews
http://www.DevPublisher.com - Website publisher guides, tools and news
http://www.AudioMelody.com - Make better music