You are here

protected function RateWidget::getUserResults in Rate 7.2

Get users vote.

Return value

int Button value

1 call to RateWidget::getUserResults()
RateWidget::__construct in classes/widget.inc
Create a new Rate widget.

File

classes/widget.inc, line 362

Class

RateWidget

Code

protected function getUserResults() {
  $criteria = array(
    'entity_type' => $this->entity_type,
    'entity_id' => $this->entity_id,
    'tag' => $this->tag,
    'value_type' => $this->value_type,
    'uid' => $this->account->uid,
  );
  if (!$this->account->uid) {
    $criteria += array(
      'vote_source' => ip_address(),
    );
  }
  if ($results = votingapi_select_votes($criteria)) {

    // Check the anonymous window. We should not display this vote when its anonymous and casted too long ago.
    $anonymous_window = variable_get('votingapi_anonymous_window', 86400);

    // Use a minimum of 5 seconds. Needed to get the anonymous vote directly after the user has voted.
    $anonymous_window = max(5, $anonymous_window);
    if ($this->account->uid || $user_vote[0]['timestamp'] > REQUEST_TIME - $anonymous_window || $anonymous_window == -1) {
      return $results[0]['value'];
    }
  }
  return NULL;
}