function fivestar_get_votes in Fivestar 6
Same name and namespace in other branches
- 6.2 fivestar.module \fivestar_get_votes()
- 7.2 fivestar.module \fivestar_get_votes()
5 calls to fivestar_get_votes()
- fivestar_comment_form_alter in ./
fivestar_comment.module - Form alter specification for comments.
- fivestar_form in ./
fivestar.module - Create the fivestar form for the current item. Note that this is not an implementation of hook_form(). We should probably change the function to reflect that.
- fivestar_static in ./
fivestar.module - fivestar_views_widget_handler in ./
fivestar.module - Generic VotingAPI Views formatter for displaying rating widget.
- fivestar_vote in ./
fivestar.module - Callback function for fivestar/vote.
File
- ./
fivestar.module, line 785 - A simple n-star voting widget, usable in other forms.
Code
function fivestar_get_votes($type, $cid, $tag = 'vote', $uid = NULL) {
global $user;
if (!isset($uid)) {
$uid = $user->uid;
}
$criteria = array(
'content_type' => $type,
'content_id' => $cid,
'value_type' => 'percent',
'tag' => $tag,
);
$votes = array(
'average' => array(),
'count' => array(),
'user' => array(),
);
$results = votingapi_select_results($criteria);
foreach ($results as $result) {
if ($result['function'] == 'average') {
$votes['average'] = $result;
}
if ($result['function'] == 'count') {
$votes['count'] = $result;
}
}
if ($uid) {
$user_vote = votingapi_select_votes($criteria += array(
'uid' => $uid,
));
if ($user_vote) {
$votes['user'] = $user_vote[0];
$votes['user']['function'] = 'user';
}
}
else {
// If the user is anonymous, we never bother loading their existing votes.
// Not only would it be hit-or-miss, it would break page caching. Safer to always
// show the 'fresh' version to anon users.
$votes['user'] = array(
'value' => 0,
);
}
return $votes;
}