function _rate_check_permissions in Rate 7
Same name and namespace in other branches
- 6.2 rate.module \_rate_check_permissions()
Check if the current user has permission to vote on the given widget.
Parameters
object $widget:
Return value
bool
2 calls to _rate_check_permissions()
- rate_generate_widget in ./
rate.module - Generate a widget.
- rate_save_vote in ./
rate.module - Save a vote to the database.
File
- ./
rate.module, line 414 - Rate module
Code
function _rate_check_permissions($widget, $node = NULL) {
global $user;
// This option should be available, check for legacy.
isset($widget->roles) or $widget->roles = array();
isset($widget->allow_voting_by_author) or $widget->allow_voting_by_author = TRUE;
if (!$widget->allow_voting_by_author) {
// This option only affects authenticated users.
if ($node && $user->uid && $node->uid == $user->uid) {
return RATE_PERMISSION_DISALLOWED_AUTHOR;
}
}
$roles_selected = FALSE;
foreach ($widget->roles as $rid => $role) {
if ($role) {
$roles_selected = TRUE;
if (isset($user->roles[$rid])) {
return RATE_PERMISSION_OK;
}
}
}
if (!$roles_selected) {
// Allow voting for all roles if no roles are selected.
return RATE_PERMISSION_OK;
}
return RATE_PERMISSION_DISALLOWED_ROLE;
}