Allow selective suppression of voting on selected nodes of a particular type
| Project: | Fivestar |
| Version: | 5.x-1.7 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | duplicate |
Jump to:
I wanted to set up a 'book page' hierarchy where a few nodes were essentially containers for many leaf nodes. I wanted voting allowed on all the leaf book pages but not on the containers. Of course I could have created two different node types but then I loose the ability to fully use the existing book class.
So, after using the normal fivestar configuration to set voting on all book pages I modified the fivestar.module code to place a 'Suppress voting on this page' option on the individual node edit pages. Any pages for which this option is set then skip the presentation of a voting form in their view modes.
The result is voting on all nodes of the specified type EXCEPT for those nodes for which it is specifically suppressed.
I have available code to implement this feature if it is of interest to anyone else.

#1
Do you still have this code? If so, would you mind posting it here? I'm looking for exactly what you described.
#2
me too.
At the moment I'm doing thru' the theme, so I have to update it everytime I have a url I don't want to use it at!
#3
BUMP!!
Where are you billirl?? It would be awesome if you could publish back what you did for the community to review. I suspect this would be a popular feature. =)
#4
Ack...I remember doing something similar for a project I did a while ago. I'll find it and try to give the patch tomorrow morning :)
#5
Ooo, that would be great! =)
#6
Ack...I found the code...but it was on an old version of fivestar (5.x-1.4)...no install file or anything at the time. I can see there are a fair number of changes since then as well :( Any ideas on the best way to have a patch?
#7
Hmmm, tricky. The patch won't apply itself to the latest version. I don't think there is an easy way. But if the thinking is done then re-writing the code should be easier. If it's a proper patch file then it should show you which lines it replaced and you should be able to find the equivalent lines in a clean copy of Fivestar 5.x-1.7, edit it and recreate the patch.
If you post the old patch here, I will take a look when I get a chance - probably at some point in April I'll have time. If you don't have a patch, then post your version of fivestar.module with the modifications, I'll download Fivestar 5.x-1.4 from the archive and build a patch file as a starting point. =)
#8
I initially thought of just adding the patches to drupal-5-x-dev but I have no idea which version is the dev (Drupal-5 or Drupal-5-11?) I'm just appending the code below (I didn't add the checks to display the node that should be there in hook_view or hook_block as we did that check in the theme but you can see its easy enough to add) The pieces of code that I had were:
(In fivestar.module as new functions):
/**
* Implementation of hook_link(),
*/
function fivestar_link($type, $object = NULL, $teaser = FALSE) {
if ($type == 'comment') {
return;
}
$links = array();
// Thinking is that if the user can administer nodes, then they should be able to set if ratings are allowed on it or not.
if (user_access('administer nodes')) {
if ($object->nid && fivestar_object_allowed($object->nid)) {
$links['fivestar_except_node'] = array(
'title' => t('Remove rating'),
'href' => 'fivestar/except/'. $object->nid,
'attributes' => array('title' => t('Remove ratings for this page'))
);
} else {
$links['fivestar_allow_node'] = array(
'title' => t('Allow rating'),
'href' => 'fivestar/allow/'. $object->nid,
'attributes' => array('title' => t('Allow ratings for this page'))
);
}
}
return $links;
}
/**
* Allow an node to be voted on by users
*/
function fivestar_object_allow($nid) {
db_query("DELETE FROM {fivestar_exceptions} WHERE nid=%d", $nid);
drupal_set_message("Voting now allowed on the set node");
drupal_goto('node/' . $nid);
}
/**
* Stop a node from being voted on by users
*/
function fivestar_object_except($nid) {
// Remove any druplicate that may already exist
db_query("DELETE FROM {fivestar_exceptions} WHERE nid=%d", $nid);
db_query("INSERT INTO {fivestar_exceptions} (nid) VALUES (%d)", $nid);
drupal_set_message("No more voting allowed on the set node");
drupal_goto('node/' . $nid);
}
/**
* Check if a node can be voted on
* @param nid integer or object (check is made to see if passed in an object)
*/
function fivestar_object_allowed($nid) {
if (is_object($nid)) {
$nid = $nid->nid;
}
$result = db_result(db_query("SELECT nid FROM {fivestar_exceptions} WHERE nid=%d", $nid));
if ($result == FALSE) {
return TRUE;
}
return FALSE;
}
(As part of hook_menu):
$items[] = array('path' => 'fivestar/except',
'callback' => 'fivestar_object_except',
'type' => MENU_CALLBACK,
'access' => user_access('administer nodes'),
);
$items[] = array(
'path' => 'fivestar/allow',
'callback' => 'fivestar_object_allow',
'type' => MENU_CALLBACK,
'access' => user_access('administer nodes'),
);
And finally in hook_install():
function fivestar_install() {switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
$result = db_query("
CREATE TABLE {fivestar_exceptions} (
nid INT(11) NOT NULL DEFAULT '0',
PRIMARY KEY (nid)
) /*!40100 DEFAULT CHARACTER SET utf8 */;"
);
break;
case 'pgsql':
$result = db_query("
CREATE TABLE {fivestar_exceptions} (
nid INTEGER NOT NULL DEFAULT '0',
PRIMARY KEY (nid)
)"
);
}
if ($result) {
drupal_set_message('Voting exception table installed correctly');
} else {
drupal_set_message('Voting exception table did not install correctly. Please install manually');
}
}
#9
One thing I'd like to add is you could add checks for
fivestar_object_allowed($nid)in hook_view, hook_block, and fivestar_widget_form (since some of them show titles and other sets of info so this would be a way to hide it from all 3 areas) though others here might have a better idea on the best places to perform the check.#10
I'd much rather make this an option on the node edit form than a link displayed on the node. This unfortunately should also use a separate database table rather than using a single variable per node type.
#11
The link portion of it could be on either part - however, it does use a separate database table (which simply stores the node id - so if it sees the node id is in the fivestar_exceptions table, then the form should not be displayed on the page.
#12
Me too, re: node edit form. But this is great, BTMash. Thanks so much for sharing. =)
#13
Regarding the node edit form versus a link, I remember trying out both ways at my workplace with most of the others around me preferring to use the link (so if they saw it on a page they felt didn't need it, it could be removed without going to the node edit page) - I preferred the node edit way but chalked it up to not understanding the main users around me >_<
#14
I'm marking this duplicate of #336365: Enable/Disable Rating per Node, since seeing "BUMP!!" in any issue immediately makes me not ever want to fix the issue because it ticks me off so much. This solution will not be implemented as link and will be a node-form option, just like enabling/disabling comments.
#15
1. Thanks for putting this feature in.
2. I'm really sorry if my post annoyed you, but be fair, take the "bump" in context... It feels like you saw the word and the red mist came down - you didn't read the comment at all:
It's 100% clear I'm a) not pestering the maintainer, but trying to continue a conversation with another developer and encouraging them to post code they'd already written - see opening post, not write stuff for me and b) not shouting about an open issue like some people do (which, I agree as a module maintainer myself, can be annoying...)
Anyway, good to see the feature in.
/me makes a note never to say BUMP around quicksketch :p