Révision 3461d8cb
Ajouté par Assos Assos il y a environ 10 ans
drupal7/sites/all/modules/fivestar/includes/fivestar.field.inc | ||
---|---|---|
77 | 77 |
'#return_value' => 1, |
78 | 78 |
); |
79 | 79 |
|
80 |
$form['allow_revote'] = array( |
|
81 |
'#type' => 'checkbox', |
|
82 |
'#title' => t('Allow users to re-vote on already voted content.'), |
|
83 |
'#default_value' => isset($instance['settings']['allow_revote']) ? $instance['settings']['allow_revote'] : FALSE, |
|
84 |
'#return_value' => 1, |
|
85 |
); |
|
86 |
|
|
87 |
$form['allow_ownvote'] = array( |
|
88 |
'#type' => 'checkbox', |
|
89 |
'#title' => t('Allow users to vote on their own content.'), |
|
90 |
'#default_value' => isset($instance['settings']['allow_ownvote']) ? $instance['settings']['allow_ownvote'] : FALSE, |
|
91 |
'#return_value' => 1, |
|
92 |
); |
|
93 |
|
|
80 | 94 |
$options = fivestar_get_targets($field, $instance); |
81 | 95 |
$form['target'] = array( |
82 | 96 |
'#title' => t('Voting target'), |
... | ... | |
119 | 133 |
else { |
120 | 134 |
$rating = (isset($items[$delta]['rating'])) ? $items[$delta]['rating'] : 0; |
121 | 135 |
} |
122 |
$target = _fivestar_field_target($entity, $field, $instance, $item, $langcode); |
|
136 |
$target = _fivestar_field_target($entity, $field, $instance, $item, $langcode);
|
|
123 | 137 |
if (!empty($target)) { |
124 |
_fivestar_cast_vote($target['entity_type'], $target['entity_id'], $rating, $field['settings']['axis'], $entity->uid, TRUE); |
|
138 |
if ($entity_type == 'comment' && $op == 'delete') { |
|
139 |
$target['vote_source'] = $entity->hostname; |
|
140 |
} |
|
141 |
else { |
|
142 |
$target['vote_source'] = NULL; |
|
143 |
} |
|
144 |
_fivestar_cast_vote($target['entity_type'], $target['entity_id'], $rating, $field['settings']['axis'], $entity->uid, TRUE, $target['vote_source']); |
|
125 | 145 |
votingapi_recalculate_results($target['entity_type'], $target['entity_id']); |
126 | 146 |
} |
127 | 147 |
// The original callback is only called for a single updated field, but the Field API |
... | ... | |
291 | 311 |
$settings = array( |
292 | 312 |
'stars' => $instance['settings']['stars'], |
293 | 313 |
'allow_clear' => !empty($instance['settings']['allow_clear']) ? $instance['settings']['allow_clear'] : FALSE, |
314 |
'allow_revote' => !empty($instance['settings']['allow_revote']) ? $instance['settings']['allow_revote'] : FALSE, |
|
315 |
'allow_ownvote' => !empty($instance['settings']['allow_ownvote']) ? $instance['settings']['allow_ownvote'] : FALSE, |
|
294 | 316 |
'style' => 'user', |
295 | 317 |
'text' => 'none', |
296 | 318 |
'widget' => $widget, |
... | ... | |
301 | 323 |
'#title' => isset($instance['label']) ? (($i18n) ? i18n_field_translate_property($instance, 'label') : t($instance['label'])) : FALSE, |
302 | 324 |
'#stars' => isset($instance['settings']['stars']) ? $instance['settings']['stars'] : 5, |
303 | 325 |
'#allow_clear' => isset($instance['settings']['allow_clear']) ? $instance['settings']['allow_clear'] : FALSE, |
326 |
'#allow_revote' => isset($instance['settings']['allow_revote']) ? $instance['settings']['allow_revote'] : FALSE, |
|
327 |
'#allow_ownvote' => isset($instance['settings']['allow_ownvote']) ? $instance['settings']['allow_ownvote'] : FALSE, |
|
304 | 328 |
'#default_value' => isset($items[$delta]['rating']) ? $items[$delta]['rating'] : (isset($instance['default_value'][$delta]['rating']) ? $instance['default_value'][$delta]['rating'] : 0), |
305 | 329 |
'#widget' => $widget, |
306 | 330 |
'#settings' => $settings, |
... | ... | |
485 | 509 |
$settings = _fivestar_custom_widget_settings($entity_type, $instance, $display, $id, $tag, $widget); |
486 | 510 |
// Store entity and field data for later reuse. |
487 | 511 |
$settings += array( |
488 |
'entity' => $entity, |
|
512 |
'entity_id' => $id, |
|
513 |
'entity_type' => $entity_type, |
|
489 | 514 |
'field_name' => $instance['field_name'], |
490 | 515 |
'langcode' => $langcode, |
491 | 516 |
); |
... | ... | |
616 | 641 |
$settings = array( |
617 | 642 |
'stars' => (!empty($instance['settings']['stars'])) ? $instance['settings']['stars'] : 5, |
618 | 643 |
'allow_clear' => (!empty($instance['settings']['allow_clear'])) ? $instance['settings']['allow_clear'] : 0, |
644 |
'allow_revote' => (!empty($instance['settings']['allow_revote'])) ? $instance['settings']['allow_revote'] : 0, |
|
645 |
'allow_ownvote' => (!empty($instance['settings']['allow_ownvote'])) ? $instance['settings']['allow_ownvote'] : 0, |
|
619 | 646 |
'style' => $settings['style'], |
620 | 647 |
'text' => $settings['text'], |
621 | 648 |
'content_type' => $entity_type, |
... | ... | |
685 | 712 |
*/ |
686 | 713 |
function fivestar_field_prepare_view($entity_type, $entities, $field, $instances, $langcode, &$items) { |
687 | 714 |
// TODO: Clean this function up! |
715 |
$exposed_widgets = array(); |
|
688 | 716 |
foreach ($entities as $id => $entity) { |
689 | 717 |
// Ensure the items aren't processed twice. |
690 | 718 |
if (!isset($items[$id][0]['count'])) { |
691 |
// Populating the $items[$id] array even for items with no value forces |
|
692 |
// the render system to output a widget. |
|
693 | 719 |
if ($instances[$id]['widget']['type'] == 'exposed') { |
694 |
// If the widget type is exposed then we want to look up the voting api |
|
695 |
// values. |
|
696 |
$tag = $field['settings']['axis']; |
|
697 |
$votes = fivestar_get_votes($entity_type, $id, $tag); |
|
698 |
$values['user'] = isset($votes['user']['value']) ? $votes['user']['value'] : 0; |
|
699 |
$values['average'] = isset($votes['average']['value']) ? $votes['average']['value'] : 0; |
|
700 |
$values['count'] = isset($votes['count']['value']) ? $votes['count']['value'] : 0; |
|
701 |
$items[$id] = array($values); |
|
720 |
$exposed_widgets[] = $id; |
|
702 | 721 |
} |
703 | 722 |
else { |
704 | 723 |
// If the widget type is not exposed, then the count is always 1 or 0. |
... | ... | |
716 | 735 |
$items[$id] = array($values); |
717 | 736 |
} |
718 | 737 |
} |
738 |
if(!empty($exposed_widgets)) { |
|
739 |
$votes = fivestar_get_votes_multiple($entity_type, $exposed_widgets, $field['settings']['axis']); |
|
740 |
foreach($votes[$entity_type] as $id => $vote) { |
|
741 |
// Populating the $items[$id] array even for items with no value forces |
|
742 |
// the render system to output a widget. |
|
743 |
$values['user'] = isset($vote['user']['value']) ? $vote['user']['value'] : 0; |
|
744 |
$values['average'] = isset($vote['average']['value']) ? $vote['average']['value'] : 0; |
|
745 |
$values['count'] = isset($vote['count']['value']) ? $vote['count']['value'] : 0; |
|
746 |
$items[$id] = array($values); |
|
747 |
} |
|
748 |
} |
|
719 | 749 |
} |
720 | 750 |
} |
721 | 751 |
|
... | ... | |
744 | 774 |
'type' => 'text', |
745 | 775 |
'microdata' => TRUE, |
746 | 776 |
), |
777 |
'rating_count' => array( |
|
778 |
'label' => t('Rating count'), |
|
779 |
'type' => 'text', |
|
780 |
'microdata' => TRUE, |
|
781 |
), |
|
747 | 782 |
); |
748 | 783 |
} |
749 | 784 |
|
Formats disponibles : Unified diff
Weekly update of contrib modules