You are here

function _fivestar_allow_vote in Fivestar 7.2

Helper function to determine if a user can vote on content.

Return value

bool

1 call to _fivestar_allow_vote()
fivestar_expand in ./fivestar.module
Process callback for fivestar_element -- see fivestar_element()

File

./fivestar.module, line 1047

Code

function _fivestar_allow_vote($element) {
  global $user;

  // Check allowed to re-vote.
  $can_revote = FALSE;
  if ($element['#allow_revote']) {
    $can_revote = TRUE;
  }
  else {
    $criteria = array(
      'entity_id' => isset($element['#settings']['content_id']) ? $element['#settings']['content_id'] : NULL,
      'entity_type' => isset($element['#settings']['content_type']) ? $element['#settings']['content_type'] : NULL,
      'tag' => isset($element['#settings']['tag']) ? $element['#settings']['tag'] : NULL,
      'uid' => $user->uid,
    );
    $can_revote = !votingapi_select_votes($criteria);
  }
  if (!$can_revote) {
    return FALSE;
  }

  // Check allowed own vote.
  if ($element['#allow_ownvote']) {
    return TRUE;
  }

  // Check that we have entity details, allow if not.
  if (!isset($element['#settings']['entity_id']) || !isset($element['#settings']['entity_type'])) {
    return TRUE;
  }
  $entity_id = $element['#settings']['entity_id'];
  $entity = entity_load($element['#settings']['entity_type'], array(
    $entity_id,
  ));
  $entity = $entity[$entity_id];
  $uid1 = $entity->uid;
  $uid2 = $user->uid;
  return $entity->uid != $user->uid;
}