Index: fivestar.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/fivestar/fivestar.install,v
retrieving revision 1.5.2.4
diff -u -r1.5.2.4 fivestar.install
--- fivestar.install 17 Apr 2008 23:56:16 -0000 1.5.2.4
+++ fivestar.install 19 Apr 2008 05:57:40 -0000
@@ -22,11 +22,35 @@
function fivestar_install() {
drupal_install_schema('fivestar');
+ if (module_exists('content')) {
+ content_notify('install', 'fivestar');
+ }
}
function fivestar_uninstall() {
drupal_uninstall_schema('fivestar');
db_query("DELETE FROM {variable} WHERE name LIKE 'fivestar_%'");
+ if (module_exists('content')) {
+ content_notify('uninstall', 'fivestar');
+ }
+}
+
+/**
+* Implementation of hook_enable().
+*/
+function fivestar_enable() {
+ if (module_exists('content')) {
+ content_notify('enable', 'fivestar');
+ }
+}
+
+/**
+* Implementation of hook_disable().
+*/
+function fivestar_disable() {
+ if (module_exists('content')) {
+ content_notify('disable', 'fivestar');
+ }
}
/**
@@ -112,4 +136,17 @@
}
return $ret;
+}
+
+/**
+ * Set Fivestar weight to -1 so that it can load before content.module.
+ */
+function fivestar_update_6102() {
+ $ret = array();
+
+ // This update will already be run as fivestar_update_5701 on Drupal 5.
+ if (FIVESTAR_VERSION >= 6100) {
+ $ret[] = update_sql("UPDATE {system} SET weight = -1 WHERE type = 'module' AND name = 'fivestar'");
+ }
+ return $ret;
}
\ No newline at end of file
Index: fivestar.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/fivestar/fivestar.module,v
retrieving revision 1.13.2.25
diff -u -r1.13.2.25 fivestar.module
--- fivestar.module 15 Apr 2008 08:55:02 -0000 1.13.2.25
+++ fivestar.module 19 Apr 2008 05:57:41 -0000
@@ -121,7 +121,16 @@
// fivestar_color.inc.
'fivestar_color_form' => array(
'arguments' => array('form' => NULL),
-
+ ),
+ // fivestar_field.inc.
+ 'fivestar_formatter_default' => array(
+ 'arguments' => array('element' => NULL),
+ ),
+ 'fivestar_formatter_rating' => array(
+ 'arguments' => array('element' => NULL),
+ ),
+ 'fivestar_formatter_percentage' => array(
+ 'arguments' => array('element' => NULL),
),
);
}
@@ -670,6 +679,7 @@
function fivestar_vote($type, $cid, $value, $tag = 'vote') {
$result = _fivestar_cast_vote($type, $cid, $value, $tag, NULL, TRUE);
+ votingapi_recalculate_results($type, $cid);
if ($type == 'node') {
$node = node_load($cid);
@@ -739,10 +749,8 @@
else {
$votes = $criteria += array('value' => $value, 'uid' => $uid);
votingapi_set_votes($votes, $user_votes);
- return fivestar_get_votes($type, $cid, $tag, $uid);
- unset($votes['user']);
- return $votes;
}
+ return fivestar_get_votes($type, $cid, $tag, $uid);
}
}
@@ -921,8 +929,8 @@
if (_fivestar_validate_target('node', $node->nid)) {
$block['subject'] = t('Rate This');
$block['content'] = fivestar_widget_form($node);
+ return $block;
}
- return $block;
}
}
break;
@@ -968,9 +976,9 @@
$votes = fivestar_get_votes($content_type, $content_id);
$values = array(
- 'user' => $votes['user']['value'],
- 'average' => $votes['average']['value'],
- 'count' => $votes['count']['value'],
+ 'user' => isset($votes['user']['value']) ? $votes['user']['value'] : NULL,
+ 'average' => isset($votes['average']['value']) ? $votes['average']['value'] : NULL,
+ 'count' => isset($votes['count']['value']) ? $votes['count']['value'] : NULL,
);
$settings = array(
@@ -1201,6 +1209,7 @@
if ($form_state['values']['form_id'] == 'fivestar_form_'. $form_state['values']['content_type'] .'_'. $form_state['values']['content_id']) {
// Cast the vote.
_fivestar_cast_vote($form_state['values']['content_type'], $form_state['values']['content_id'], $form_state['values']['vote']);
+ votingapi_recalculate_results($form_state['values']['content_type'], $form_state['values']['content_id']);
// Set a message that the vote was received.
if ($form_state['values']['vote'] === '0') {
@@ -1332,6 +1341,7 @@
function theme_fivestar_summary($user_rating, $average_rating, $votes, $stars = 5, $feedback = TRUE) {
$output = '';
+ $div_class = '';
if (isset($user_rating)) {
$div_class = isset($votes) ? 'user-count' : 'user';
$user_stars = round(($user_rating * $stars) / 100, 1);
@@ -1502,7 +1512,7 @@
$label_class = $element['#labels_enable'] ? ' fivestar-labels-hover' : '';
$element['#id'] = 'edit-vote-'. $fivestar_id;
- $element['#prefix'] = '
';
+ $element['#prefix'] = '
';
$element['#suffix'] = '
';
// Add validation function that considers a 0 value as empty.
Index: fivestar_field.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/fivestar/fivestar_field.inc,v
retrieving revision 1.3.2.5
diff -u -r1.3.2.5 fivestar_field.inc
--- fivestar_field.inc 2 Apr 2008 04:47:25 -0000 1.3.2.5
+++ fivestar_field.inc 19 Apr 2008 05:57:41 -0000
@@ -24,7 +24,11 @@
function fivestar_field_settings($op, $field) {
switch ($op) {
case 'form':
- $form['multiple'] = array(); // Multiple not supported
+ // Multiple is not supported with Fivestar.
+ $form['multiple'] = array(
+ '#type' => 'value',
+ '#value' => 0,
+ );
$form['stars'] = array(
'#type' => 'select',
'#title' => t('Number of Options'),
@@ -74,11 +78,10 @@
case 'save':
return array('stars', 'dynamic_target', 'target', 'php', 'axis');
case 'database columns':
- $columns = array(
- 'target' => array('type' => 'int', 'default' => 'NULL'),
- 'rating' => array('type' => 'int', 'default' => 'NULL'),
+ return array(
+ 'target' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE),
+ 'rating' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE),
);
- return $columns;
}
}
@@ -87,12 +90,8 @@
*/
function fivestar_field($op, &$node, $field, &$items, $teaser, $page) {
$fieldname = $field['field_name'];
+
switch ($op) {
- case 'view':
- foreach ($items as $delta => $item) {
- $items[$delta]['view'] = content_format($field, $item);
- }
- return theme('field', $node, $field, $items, $teaser, $page);
case 'insert':
case 'update':
foreach ($items as $delta => $item) {
@@ -106,16 +105,12 @@
// Use eval rather than drupal_eval to allow access to local variables.
$items[$delta]['target'] = eval('?>'. $item['target']);
}
-
- if (is_numeric($items[$delta]['target'])) {
- if ($item['rating'] == 0) {
- votingapi_unset_vote('node', $items[$delta]['target'], $node->uid);
- }
- else {
- _fivestar_cast_vote('node', $items[$delta]['target'], $item['rating'], $items[$delta]['axis'], $node->uid);
- }
+ if (is_numeric($item['target'])) {
+ _fivestar_cast_vote('node', $item['target'], $item['rating'], $item['axis'], $node->uid);
+ votingapi_recalculate_results('node', $item['target']);
}
}
+ $items = array($item);
break;
case 'delete':
foreach ($items as $delta => $item) {
@@ -129,11 +124,15 @@
// Use eval rather than drupal_eval to allow access to local variables.
$items[$delta]['target'] = eval('?>'. $item['target']);
}
- if (is_numeric($items[$delta]['target'])) {
- votingapi_unset_vote('node', $items[$delta]['target'], $node->uid);
+ if (is_numeric($item['target'])) {
+ _fivestar_cast_vote('node', $item['target'], 0, $item['axis'], $node->uid);
+ votingapi_recalculate_results('node', $item['target']);
}
}
break;
+ case 'sanitize':
+ $items[0]['stars'] = $field['stars'];
+ break;
}
}
@@ -145,10 +144,12 @@
'radios' => array(
'label' => t('Radio Buttons'),
'field types' => array('fivestar'),
+ 'multiple values' => CONTENT_HANDLE_MODULE,
),
'stars' => array(
'label' => t('Stars'),
'field types' => array('fivestar'),
+ 'multiple values' => CONTENT_HANDLE_MODULE,
),
);
}
@@ -176,36 +177,35 @@
/**
* Implementation of hook_widget().
*/
-function fivestar_widget($op, &$node, $field, &$items) {
- switch ($op) {
- case 'form':
- $form = array();
-
- $form[$field['field_name']] = array('#tree' => TRUE);
- $form[$field['field_name']][0]['rating'] = array(
- '#type' => 'fivestar',
- '#title' => $field['widget']['label'],
- '#default_value' => $items[0]['rating'],
- '#stars' => $field['stars'] ? $field['stars'] : 5,
- '#allow_clear' => $field['widget']['allow_clear'],
- '#description' => $field['widget']['description'],
- '#weight' => $field['widget']['weight'],
- '#auto_submit' => FALSE,
- '#widget' => $field['widget']['type'],
- '#required' => $field['required'],
- '#labels_enable' => FALSE,
- );
+function fivestar_widget(&$form, &$form_state, $field, $items) {
+ $element = array('#tree' => TRUE);
+ $element['rating'] = array(
+ '#type' => 'fivestar',
+ '#title' => $field['widget']['label'],
+ '#default_value' => isset($items[0]['rating']) ? $items[0]['rating'] : NULL,
+ '#stars' => is_numeric($field['stars']) ? $field['stars'] : 5,
+ '#allow_clear' => $field['widget']['allow_clear'],
+ '#description' => $field['widget']['description'],
+ '#weight' => $field['widget']['weight'],
+ '#auto_submit' => FALSE,
+ '#widget' => $field['widget']['type'],
+ '#required' => $field['required'],
+ '#labels_enable' => FALSE,
+ );
- $form[$field['field_name']][0]['target'] = array(
- '#type' => 'value',
- '#value' => $field['target'],
- );
- $form[$field['field_name']][0]['axis'] = array(
- '#type' => 'value',
- '#value' => $field['axis'],
- );
- return $form;
- }
+ $element['target'] = array(
+ '#type' => 'value',
+ '#value' => $field['target'],
+ );
+ $element['axis'] = array(
+ '#type' => 'value',
+ '#value' => $field['axis'],
+ );
+
+ // CCK likes to always have a 2D array for form elements.
+ $element = array($element);
+
+ return $element;
}
/**
@@ -250,3 +250,36 @@
return theme('fivestar_static', $item['rating'], $field['stars']);
}
}
+
+/**
+ * Theme function for 'default' fivestar field formatter.
+ */
+function theme_fivestar_formatter_default($element) {
+ if (!isset($element['#item']['rating'])) {
+ $element['#item']['rating'] = 0;
+ }
+
+ return theme('fivestar_static', $element['#item']['rating'], $element['#item']['stars']);
+}
+
+/**
+ * Theme function for 'default' fivestar field formatter.
+ */
+function theme_fivestar_formatter_rating($element) {
+ if (!isset($element['#item']['rating'])) {
+ $element['#item']['rating'] = 0;
+ }
+
+ return theme('fivestar_static', $element['#item']['rating'], $element['#field']['stars']);
+}
+
+/**
+ * Theme function for 'default' fivestar field formatter.
+ */
+function theme_fivestar_formatter_percentage($element) {
+ if (!isset($element['#item']['rating'])) {
+ $element['#item']['rating'] = 0;
+ }
+
+ return round(100/$element['#item']['rating'], 1)/$element['#field']['stars'];
+}