Simple Rating System, How Do Get This Done?

GreenLED - March 17, 2008 - 05:35

My goal is to create a rating system where users can input a simple vote and that vote will affect the rating of the node. Example...

File Name
Rating: 4.0
* * * * *

Users would click to rate.

I have installed Voting API along with Fivestar.

The problem is -- how exactly to go about this... All that I want is a front-end widget that when clicked will rate that node then I need a variable like "$node->content['field_rating']['#value']; that I can print as a number -- like "5.0" which I would print on the page.

How should I go about this?

So to surmise again -- guests can vote on a page, once they cast, that is tallied up and the average would appear in a numeric format -- it has to be just a number by itself -- without "Score:" or something in front of it. Can anyone give me some instructions that I could try and then we can go from there?

Oh, also -- I find it

GreenLED - March 17, 2008 - 05:37

Oh, also -- I find it impossible to figure out how to actually select which widget to use when creating a cck field ... how do you select which one to use --- and can you create bigger stars then the standard "16x16" that most of the widgets have... can they be jpegs instead of .gif's? Sorry for so many questions... Just curious and anxious.

Not sure exactly what you need, but...

VValdo - March 17, 2008 - 06:42

Assuming Drupal 5.x...

Here's how I learned to do it from reading some of the online documentation...

What you can do is create a template ("node-mynode.tpl.php") file and chuck it in your theme to override the regular boring display of the node.

For example.. let's say you have a node type called "mynode" with a couple fields in it you added with CCK. Say there's the regular title and body, plus you added a "rating" (integer 1-10) and a "review" (some text) and you're using the "garland" theme.

First create a "star" image of whatever size you want, and put that star.png in /sites/default/files/

Next, copy the garland theme from /themes into your own directory at /sites/all/themes so you can mess with it.

Finally, create a custom template file at /sites/all/themes/garland/ called node-mynode.tpl.php and make it look like this:

<div class="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
    <?php if ($picture) {
      print
$picture;
    }
?>

    <?php if ($page == 0) { ?><h2 class="title"><a href="<?php print $node_url?>"><?php print $title?></a></h2><?php }; ?>
    <span class="submitted"><?php print $submitted?></span>
    <span class="taxonomy"><?php print $terms?></span>
    <div class="content">

<p /><b>Rating:</b><?php
 
for ($counttt=1; ($counttt <= content_format('field_rating', $field_rating[0])); $counttt++)
{ echo
"<img src=\"/sites/default/files/star.png\" alt=\"*\" />";  }  echo "(" . content_format('field_rating', $field_rating[0]) . "/10)";
?>
<p />

<b>Review:</b><p />
<?php print content_format('field_review', $field_review[0]); ?>

    </div>
    <?php if ($links) { ?><div class="links">&raquo; <?php print $links?></div><?php }; ?>
  </div>

This will repeat the star graphic for every # in the rating (ie, a rating of "4" will give ****). I use this instead of the fivestar module. Hope it makes sense.

If I screwed something up here, no doubt someone else will jump in with a fix.

W

Hmmm

VValdo - March 17, 2008 - 06:43

On second reading of your question it seems you DO want to calculate averages and stuff, so fivestar is probably your best bet. In any event you can use the above example to customize the look of your node in general...

W

Do you use fivestar? »

GreenLED - June 25, 2008 - 17:23

Do you use fivestar?

» Respectfully, GreenLED
» Stable Files . net

 
 

Drupal is a registered trademark of Dries Buytaert.