Index: fivestar_field.inc
===================================================================
--- fivestar_field.inc (revision 18)
+++ fivestar_field.inc (working copy)
@@ -91,14 +91,22 @@
'#description' => t('The axis this rating will affect. Enter a property on which that this rating will affect, such as quality, satisfaction, overall, etc. If no axis is entered, the default axis vote will be used. Warning: changing this value will not update existing votes to the new axis.'),
'#default_value' => $field['axis'],
);
-
+
+ $form['multiple_votes'] = array(
+ '#type' => 'checkbox',
+ '#title' => 'Allow multiple votes on target.',
+ '#description' => t('When checked a user is allowed to vote multiple times on the target node.'),
+ '#default_value' => $field['multiple_votes'],
+ );
+
return $form;
case 'save':
- return array('stars', 'dynamic_target', 'php_target', 'axis');
+ return array('stars', 'dynamic_target', 'php_target', 'axis', 'multiple_votes');
case 'database columns':
return array(
'rating' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'sortable' => TRUE),
'target' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE),
+ 'vote_id' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE),
);
}
}
@@ -122,7 +130,17 @@
$items[$delta]['target'] = fivestar_field_target($node, $field, $item);
if (is_numeric($items[$delta]['target'])) {
- _fivestar_cast_vote('node', $items[$delta]['target'], $rating, $field['axis'], $node->uid, FALSE, TRUE);
+ if ($field['multiple_votes']) {
+ $vote_id = $item['vote_id'];
+ }
+ else {
+ $vote_id = null;
+ }
+ $result = _fivestar_cast_vote('node', $items[$delta]['target'], $rating, $field['axis'], $node->uid, FALSE, $vote_id);
+ $vote_id = $result['vote_id'];
+ if ($field['multiple_votes']) {
+ $items[$delta]['vote_id'] = $vote_id;
+ }
votingapi_recalculate_results('node', $items[$delta]['target']);
}
}
@@ -231,7 +249,11 @@
'#type' => 'value',
'#value' => $field['axis'],
);
-
+ $element['vote_id'] = array(
+ '#type' => 'value',
+ '#value' => isset($items[0]['vote_id']) ? $items[0]['vote_id'] : NULL,
+ );
+
// CCK likes to always have a 2D array for form elements.
$element = array($element);
Index: fivestar.module
===================================================================
--- fivestar.module (revision 18)
+++ fivestar.module (working copy)
@@ -742,7 +742,7 @@
* Internal function to handle vote casting, flood control, XSS, IP based
* voting, etc...
*/
-function _fivestar_cast_vote($type, $cid, $value, $tag = NULL, $uid = NULL, $skip_validation = FALSE) {
+function _fivestar_cast_vote($type, $cid, $value, $tag = NULL, $uid = NULL, $skip_validation = FALSE, $vote_id=null) {
global $user;
$tag = empty($tag) ? 'vote' : $tag;
$uid = empty($uid) ? $user->uid : $uid;
@@ -760,10 +760,14 @@
// Get the user's current vote.
$criteria = array('content_type' => $type, 'content_id' => $cid, 'tag' => $tag, 'uid' => $uid);
+ if (isset($vote_id)) {
+ $criteria+= array(
+ 'vote_id' => $vote_id,
+ );
+ }
// Get the unique identifier for the user (IP Address if anonymous).
$user_criteria = votingapi_current_user_identifier();
$user_votes = votingapi_select_votes($criteria + $user_criteria);
-
if ($value == 0) {
votingapi_delete_votes($user_votes);
return $user_votes[0];