Hello,
Thanks for writing this module, it's very helpful.
I added a few things on top of it to make it a little more useful for me. I wrote a small function to tie in the voting into this as well. It basically has three behaviors:
1. If vote average and vote count are high enough, replace the li bullet with a star.
2. If vote average or vote count are not high enough, leave the bullet as it is.
3. If vote count is high enough and average is too low, don't display the entry.
Very simple stuff, but I find this very useful for a good navigational flow.
I'll attach a screen-shot in the next post.
How to get this going:
First, download the attached .gif file and put it into /files - this will be your li star bullet.
In template.php, add this function:
/**
* MINI RATING
* OUTPUT:
* false: "normal" article, not too bad & not too amazing or just not enough votes
* numeric (80,100) is_numeric(): good rating, result is the average
* "low": pretty low rating
**/
function mini_rating($nid) {
$min_count = 1; // minimum number of votes
$min_average = 80; // minimum vote average
$low_average = 40; // too low threashold
if ($nid) {
$result = db_query(
'SELECT value, function
FROM {votingapi_cache} v
WHERE v.content_type = "node"
AND v.content_id = '.$nid.'
LIMIT 2');
while ($r = db_fetch_object($result)) {
$nodes[] = $r;
}
if ($nodes) {
foreach ($nodes as $node) {
if ($node->function == 'count') {
$count = $node->value;
}
if ($node->function == 'average') {
$average = $node->value;
}
}
if ($count >= $min_count && $average < $low_average) {
return "low"; // enough votes & average too low
} elseif ($count < $min_count || $average < $min_average) {
return false; // not enough info
} else {
return $average; // good rating
}
}
}
return false; // no node ratings
}
In style.css, add this (replace #node-inner with your own block):
/* --- MINI RATING --- */
#node-inner li.mini_star {
list-style-image: url('/files/mini_star.gif');
}
This next step ideally should be done in template.php, but for some reason phptemplate_similarterms($nodes) function doesn't want to get picked up (any ideas?), so instead rewrite this function in similarterms.module:
function theme_similarterms($nodes) {
if (!empty($nodes)) {
$output .= "<ul>\n";
foreach ($nodes as $node) {
$mini_rating = mini_rating($node->nid);
if (is_numeric($mini_rating)) {
$class = 'class="mini_star"';
} else {
$class = '';
}
if ($mini_rating != "low") {
$output .= '<li '.$class.'>'. l($node->title, 'node/'. $node->nid) ."</li>\n";
}
}
$output .= "</ul>\n";
}
return $output;
}
That's it, customize it to your own needs and if you have any ideas I'd love to hear some feedback.
Cheers!
Andrey.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | similar_by_terms_vote_addon_box.jpg | 148.58 KB | mr.andrey |
| mini_star.gif | 505 bytes | mr.andrey |
Comments
Comment #1
mr.andrey commentedScreenshot
Comment #2
rmiddle commentedI am not sure about this. It sounds like a useful option to add in. I will leave this open but wont include as is.
Thanks
Robert
Comment #3
rmiddle commented6.x-2.x uses views so this isn't needed any more.
Thanks
Robert