You are here

function _rate_check_permissions in Rate 6.2

Same name and namespace in other branches
  1. 7 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 355
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) {
    if ($user->uid == 0) {
      return RATE_PERMISSION_DISALLOWED_ROLE;
    }
    if ($node && $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;
}