Index: fivestar.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/fivestar/fivestar.module,v
retrieving revision 1.2.2.27
diff -u -p -r1.2.2.27 fivestar.module
--- fivestar.module 21 Oct 2007 04:50:50 -0000 1.2.2.27
+++ fivestar.module 22 Oct 2007 04:46:28 -0000
@@ -240,8 +240,9 @@ function theme_fivestar_preview_page() {
* An XML chunk containing the results of the vote, for use by the client-side
* javascript code.
*/
-function fivestar_vote($type, $cid, $value) {
- $result = _fivestar_cast_vote($type, $cid, $value);
+function fivestar_vote($type, $cid, $value, $tag = NULL) {
+
+ $result = _fivestar_cast_vote($type, $cid, $value, $tag);
if ($type == 'node') {
$node = node_load($cid);
@@ -275,7 +276,12 @@ function fivestar_vote($type, $cid, $val
* Internal function to handle vote casting, flood control, XSS, IP based
* voting, etc...
*/
-function _fivestar_cast_vote($type, $cid, $value) {
+function _fivestar_cast_vote($type, $cid, $value, $tag = NULL) {
+
+ if (!isset($tag) || strlen($tag) < 1) {
+ $tag = 'vote'; //If there is no tag, use the default 'vote' tag\axis.
+ }
+
global $user;
// Bail out if the user's trying to vote on an invalid object.
@@ -322,13 +328,13 @@ function _fivestar_cast_vote($type, $cid
else {
if ($uid) {
// If the user is logged in, we'll look for votes from that uid.
- $sql = "SELECT vote_id FROM {votingapi_vote} WHERE content_type='%s' AND content_id=%d AND value_type='percent' AND uid=%d";
- $result = db_query($sql, $type, $cid, $uid);
+ $sql = "SELECT vote_id FROM {votingapi_vote} WHERE content_type='%s' AND content_id=%d AND value_type='percent' AND uid=%d AND tag = '%s'";
+ $result = db_query($sql, $type, $cid, $uid, $tag);
}
else {
// Otherwise, we'll look for votes from the same IP address in the past day.
- $sql = "SELECT vote_id FROM {votingapi_vote} WHERE content_type='%s' AND content_id=%d AND value_type='percent' AND uid=%d AND hostname='%s' AND timestamp > %d";
- $result = db_query($sql, $type, $cid, $uid, $hostname, time() - (60 * 60 * 24));
+ $sql = "SELECT vote_id FROM {votingapi_vote} WHERE content_type='%s' AND content_id=%d AND value_type='percent' AND uid=%d AND tag = '%s' AND hostname='%s' AND timestamp > %d";
+ $result = db_query($sql, $type, $cid, $uid, $tag, $hostname, time() - (60 * 60 * 24));
}
}
@@ -340,7 +346,7 @@ function _fivestar_cast_vote($type, $cid
votingapi_change_vote($old_vote, $value);
}
elseif ($value != 0) {
- votingapi_add_vote($type, $cid, $value, 'percent', 'vote', $uid);
+ votingapi_add_vote($type, $cid, $value, 'percent', $tag, $uid);
}
return votingapi_recalculate_results($type, $cid);
}
Index: fivestar_field.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/fivestar/fivestar_field.inc,v
retrieving revision 1.1.4.7
diff -u -p -r1.1.4.7 fivestar_field.inc
--- fivestar_field.inc 20 Oct 2007 17:04:41 -0000 1.1.4.7
+++ fivestar_field.inc 22 Oct 2007 04:46:29 -0000
@@ -49,9 +49,17 @@ function fivestar_field_settings($op, $f
'#value' => 1,
);
}
+
+ $form['axis'] = array(
+ '#type' => 'textfield',
+ '#title' => 'Voting Axis',
+ '#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'],
+ );
+
return $form;
case 'save':
- return array('stars', 'target', 'php');
+ return array('stars', 'target', 'php', 'axis');
case 'database columns':
$columns = array(
'target' => array('type' => 'int', 'default' => 'NULL'),
@@ -78,13 +86,15 @@ function fivestar_field($op, &$node, $fi
if ($field['php'] && !empty($item['target'])) {
$items[$delta]['target'] = drupal_eval($item['target']);
}
+
if (is_numeric($items[$delta]['target'])) {
$target_node = node_load($items[$delta]['target']);
if ($item['rating'] == 0) {
votingapi_unset_vote('node', $target_node->nid);
}
+
else {
- _fivestar_cast_vote('node', $target_node->nid, $item['rating']);
+ _fivestar_cast_vote('node', $target_node->nid, $item['rating'], $items[$delta]['axis']);
}
}
}
@@ -162,6 +172,10 @@ function fivestar_widget($op, &$node, $f
'#type' => 'value',
'#value' => $field['target'],
);
+ $form[$field['field_name']][0]['axis'] = array(
+ '#type' => 'value',
+ '#value' => $field['axis'],
+ );
return $form;
}
}