Index: js/fivestar.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/fivestar/js/Attic/fivestar.js,v retrieving revision 1.1.2.5 diff -u -r1.1.2.5 fivestar.js --- js/fivestar.js 26 Apr 2008 18:30:01 -0000 1.1.2.5 +++ js/fivestar.js 30 Jun 2008 05:02:38 -0000 @@ -233,6 +233,7 @@ }, vote: { id: $("vote id", data).text(), + tag: $("vote tag", data).text(), type: $("vote type", data).text(), value: $("vote value", data).text() }, @@ -318,13 +319,14 @@ * voteResult.result.summary.user The textual description of the user's current vote. * voteResult.vote.id The id of the item the vote was placed on (such as the nid) * voteResult.vote.type The type of the item the vote was placed on (such as 'node') + * voteResult.vote.tag The multi-axis tag the vote was placed on (such as 'vote') * voteResult.vote.average The average of the new vote saved * voteResult.display.stars The type of star display we're using. Either 'average', 'user', or 'combo'. * voteResult.display.text The type of text display we're using. Either 'average', 'user', or 'combo'. */ function fivestarDefaultResult(voteResult) { // Update the summary text. - $('div.fivestar-summary-'+voteResult.vote.id).html(voteResult.result.summary[voteResult.display.text]); + $('div.fivestar-summary-'+voteResult.vote.tag+'-'+voteResult.vote.id).html(voteResult.result.summary[voteResult.display.text]); // If this is a combo display, update the average star display. if (voteResult.display.stars == 'combo') { $('div.fivestar-form-'+voteResult.vote.id).each(function() { Index: fivestar.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/fivestar/fivestar.module,v retrieving revision 1.2.2.94 diff -u -r1.2.2.94 fivestar.module --- fivestar.module 30 Jun 2008 03:40:18 -0000 1.2.2.94 +++ fivestar.module 30 Jun 2008 05:02:38 -0000 @@ -618,6 +618,8 @@ /** * Callback function for fivestar/vote. * + * @param tag + * Multi-axis tag to allow multiple votes per node. 'vote' is the most common. * @param type * A content-type to log the vote to. 'node' is the most common. * @param cid @@ -628,7 +630,7 @@ * An XML chunk containing the results of the vote, for use by the client-side * javascript code. */ -function fivestar_vote($type, $cid, $value, $tag = 'vote') { +function fivestar_vote($tag, $type, $cid, $value) { _fivestar_cast_vote($type, $cid, $value, $tag); $result = votingapi_recalculate_results($type, $cid); @@ -665,6 +667,7 @@ $output .= ''. $value .''; $output .= ''. $type .''; $output .= ''. $cid .''; + $output .= ''. $tag .''; $output .= ''; drupal_set_header("Content-Type: text/xml"); @@ -820,7 +823,7 @@ case 'below_static': $stars = variable_get('fivestar_stars_'. $node->type, 5); $node->content['fivestar_widget'] = array( - '#value' => fivestar_static('node', $node->nid, $node->type), + '#value' => fivestar_static('node', $node->nid, $tag, $node->type), '#weight' => $position == 'above_static' ? -10 : 50, ); break; @@ -877,8 +880,8 @@ } } -function fivestar_widget_form($node) { - return drupal_get_form('fivestar_form_node_'. $node->nid, 'node', $node->nid); +function fivestar_widget_form($node, $tag = 'vote') { + return drupal_get_form('fivestar_form_node_'. $node->nid .'_'. $tag, 'node', $node->nid, $tag); } /** @@ -889,7 +892,7 @@ function fivestar_forms() { $args = func_get_args(); if (strpos($args[0][0], 'fivestar_form') !== FALSE) { - if ($args[0][0] == 'fivestar_form_'. $args[0][1] .'_'. $args[0][2]) { + if ($args[0][0] == 'fivestar_form_'. $args[0][1] .'_'. $args[0][2] .'_'. $args[0][3]) { $forms[$args[0][0]] = array('callback' => 'fivestar_form'); return $forms; } @@ -901,7 +904,7 @@ * Note that this is not an implementation of hook_form(). We should probably * change the function to reflect that. */ -function fivestar_form($content_type, $content_id) { +function fivestar_form($content_type, $content_id, $tag) { global $user; if ($content_type == 'node') { @@ -913,10 +916,10 @@ } } - $current_avg = votingapi_get_voting_result($content_type, $content_id, 'percent', 'vote', 'average'); - $current_count = votingapi_get_voting_result($content_type, $content_id, 'percent', 'vote', 'count'); + $current_avg = votingapi_get_voting_result($content_type, $content_id, 'percent', $tag, 'average'); + $current_count = votingapi_get_voting_result($content_type, $content_id, 'percent', $tag, 'count'); if ($user->uid) { - $user_vote = votingapi_get_vote($content_type, $content_id, 'percent', 'vote', $user->uid); + $user_vote = votingapi_get_vote($content_type, $content_id, 'percent', $tag, $user->uid); } else { // If the user is anonymous, we never bother loading their existing votes. @@ -936,6 +939,7 @@ 'allow_clear' => variable_get('fivestar_unvote_'. $node->type, FALSE), 'style' => variable_get('fivestar_style_'. $node->type, 'average'), 'text' => variable_get('fivestar_text_'. $node->type, 'combo'), + 'tag' => $tag, 'content_type' => $content_type, 'content_id' => $content_id, 'autosubmit' => TRUE, @@ -948,12 +952,12 @@ return fivestar_custom_widget($values, $settings); } -function fivestar_static($content_type, $content_id, $node_type = NULL) { +function fivestar_static($content_type, $content_id, $tag = 'vote', $node_type = NULL) { global $user; - $current_avg = votingapi_get_voting_result($content_type, $content_id, 'percent', 'vote', 'average'); - $current_count = votingapi_get_voting_result($content_type, $content_id, 'percent', 'vote', 'count'); - $user_vote = $user->uid ? votingapi_get_vote($content_type, $content_id, 'percent', 'vote', $user->uid) : 0; + $current_avg = votingapi_get_voting_result($content_type, $content_id, 'percent', $tag, 'average'); + $current_count = votingapi_get_voting_result($content_type, $content_id, 'percent', $tag, 'count'); + $user_vote = $user->uid ? votingapi_get_vote($content_type, $content_id, 'percent', $tag, $user->uid) : 0; if ($content_type == 'node') { // Content type should always be passed to avoid this node load. @@ -1053,13 +1057,14 @@ '#vote_count' => $values['count'], '#vote_average' => $values['average'], '#auto_submit' => isset($settings['autosubmit']) ? $settings['autosubmit'] : TRUE, - '#auto_submit_path' => (!isset($settings['autosubmit']) || $settings['autosubmit']) ? 'fivestar/vote/'. $settings['content_type'] .'/'. $settings['content_id'] : NULL, + '#auto_submit_path' => (!isset($settings['autosubmit']) || $settings['autosubmit']) ? 'fivestar/vote/'. $settings['tag'] .'/'. $settings['content_type'] .'/'. $settings['content_id'] : NULL, '#allow_clear' => $settings['allow_clear'], '#content_id' => isset($settings['content_id']) ? $settings['content_id'] : NULL, '#required' => isset($settings['required']) ? $settings['required'] : FALSE, '#feedback_enable' => isset($settings['feedback_enable']) ? $settings['feedback_enable'] : TRUE, '#labels_enable' => isset($settings['labels_enable']) ? $settings['labels_enable'] : TRUE, '#labels' => isset($settings['labels']) ? $settings['labels'] : NULL, + '#tag' => isset($settings['tag']) ? $settings['tag'] : 'vote', ); $form['destination'] = array( @@ -1117,7 +1122,7 @@ $form['vote']['#default_value'] = $values['user']; $form['vote']['#attributes']['class'] .= ' fivestar-combo-stars'; $form['#attributes']['class'] .= ' fivestar-combo-stars'; - $static_average = theme('fivestar_static', $values['average'], $settings['stars']); + $static_average = theme('fivestar_static', $values['average'], $settings['stars'], $settings['tag']); if ($settings['text'] == 'none' && !$settings['labels_enable'] && !$settings['feedback_enable']) { $static_description = NULL; } @@ -1155,9 +1160,9 @@ * Submit handler for the above form (non-javascript version). */ function fivestar_form_submit($form_id, $form_values) { - if ($form_id == 'fivestar_form_'. $form_values['content_type'] .'_'. $form_values['content_id']) { + if ($form_id == 'fivestar_form_'. $form_values['content_type'] .'_'. $form_values['content_id'] .'_'. $form_values['vote']['#tag']) { // Cast the vote. - _fivestar_cast_vote($form_values['content_type'], $form_values['content_id'], $form_values['vote']); + _fivestar_cast_vote($form_values['content_type'], $form_values['content_id'], $form_values['vote'], $form_values['vote']['#tag']); votingapi_recalculate_results($form_values['content_type'], $form_values['content_id']); // Set a message that the vote was received. @@ -1238,8 +1243,12 @@ unset($form['vote']['#description']); } + $class = 'fivestar-form'; + $class .= '-'. (isset($form['vote']['#tag']) ? $form['tag']['#tag'] : 'vote'); + $class .= '-'. (isset($form['content_id']['#value']) ? $form['content_id']['#value'] : 0); + $output = ''; - $output .= '
'; + $output .= '
'; $output .= drupal_render($form); $output .= '
'; return $output; @@ -1253,16 +1262,18 @@ * The desired rating to display out of 100 (i.e. 80 is 4 out of 5 stars) * @param $stars * The total number of stars this rating is out of + * @param $tag + * Allows multiple ratings per node * @return * A themed HTML string representing the star widget * */ -function theme_fivestar_static($rating, $stars = 5) { +function theme_fivestar_static($rating, $stars = 5, $tag = 'vote') { // Add necessary CSS. fivestar_add_css(); $output = ''; - $output .= '
'; + $output .= '
'; $numeric_rating = $rating/(100/$stars); for ($n=1; $n <= $stars; $n++) { $star_value = ceil((100/$stars) * $n); @@ -1499,7 +1510,9 @@ $type = db_result(db_query("SELECT type FROM {node} WHERE nid = %d", $query->nid)); $stars = variable_get('fivestar_stars_'. (!isset($type) ? 'default' : $type), 5); } - return theme('fivestar_static', $value, $stars); + + // TODO: Find a reliable way of determining the tag. + return theme('fivestar_static', $value, $stars, 'vote'); } function fivestar_views_widget_compact_handler($op, $filter, $value, &$query) {