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

eZ debug

Timing: Jan 18 2025 20:49:10
Script start
Timing: Jan 18 2025 20:49:10
Module start 'content'
Timing: Jan 18 2025 20:49:11
Module end 'content'
Timing: Jan 18 2025 20:49:11
Script end

Main resources:

Total runtime1.0454 sec
Peak memory usage4,096.0000 KB
Database Queries210

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0085 587.7031180.8438
Module start 'content' 0.00850.8914 768.5469680.6797
Module end 'content' 0.89990.1454 1,449.2266341.0703
Script end 1.0453  1,790.2969 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00460.4377210.0002
Check MTime0.00200.1874210.0001
Mysql Total
Database connection0.00140.133110.0014
Mysqli_queries0.937689.68672100.0045
Looping result0.00280.26582080.0000
Template Total1.006796.320.5033
Template load0.00270.253920.0013
Template processing1.004096.042920.5020
Template load and register function0.00030.025710.0003
states
state_id_array0.00140.135710.0014
state_identifier_array0.00200.186720.0010
Override
Cache load0.00240.2328610.0000
Sytem overhead
Fetch class attribute can translate value0.00130.126350.0003
Fetch class attribute name0.00220.2071100.0002
XML
Image XML parsing0.00210.204750.0004
class_abstraction
Instantiating content class attribute0.00000.0022110.0000
General
dbfile0.00440.4203400.0001
String conversion0.00000.000830.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
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
4content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
14content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
5content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 36
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs