You are here

class VotingApi_Criteria in Voting API 7.3

Criteria to select VotingApi_Votes

This is basically the same as VotingApi_Vote except that timestamp is interpreted as the vote-rollover.

Hierarchy

Expanded class hierarchy of VotingApi_Criteria

File

./votingapi.module, line 91
A generalized voting API for Drupal.

View source
class VotingApi_Criteria extends VotingApi_Vote {
  public function __construct($data) {
    parent::__construct($data);
    if ($this->uid != 0) {
      $this->vote_source = NULL;
    }
    $this
      ->calculateWindow();
  }

  /**
   * Calculate the correct timestamp for the vote-rollover.
   */
  protected function calculateWindow() {
    $window = -1;
    if ($this->uid == 0) {
      if (!empty($this->vote_source)) {
        $window = variable_get('votingapi_anonymous_window', 86400);
      }
    }
    else {
      $window = variable_get('votingapi_user_window', -1);
    }
    if ($window >= 0) {
      $this->timestamp = REQUEST_TIME - $window;
    }
  }

  /**
   * Select individual votes from the database.
   *
   * @param $limit
   *   An optional integer specifying the maximum number of votes to return.
   * @return
   *   An array of votes matching the criteria.
   */
  public function select($limit = 0) {
    return VotingApi_VoteStorage::get()
      ->selectVotes($this, $limit);
  }

  /**
   * Delete all matching votes.
   */
  public function delete() {
    VotingApi_Vote::deleteMultiple($this
      ->select());
  }
  public static function byEntity($entity_type, $entity_ids) {
    $class = get_called_class();
    return new $class(array(
      'entity_type' => $entity_type,
      'entity_id' => $entity_ids,
    ));
  }

  /**
   * Retrieve the value of the first vote matching the criteria.
   */
  public function singleValue() {
    $results = $this
      ->select();
    return $results[0]->value;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
VotingApi_Criteria::byEntity public static function
VotingApi_Criteria::calculateWindow protected function Calculate the correct timestamp for the vote-rollover.
VotingApi_Criteria::delete public function Delete all matching votes.
VotingApi_Criteria::select public function Select individual votes from the database.
VotingApi_Criteria::singleValue public function Retrieve the value of the first vote matching the criteria.
VotingApi_Criteria::__construct public function Overrides VotingApi_Vote::__construct
VotingApi_Vote::$entity_id public property
VotingApi_Vote::$entity_type public property
VotingApi_Vote::$tag public property
VotingApi_Vote::$timestamp public property
VotingApi_Vote::$uid public property
VotingApi_Vote::$value public property
VotingApi_Vote::$value_type public property
VotingApi_Vote::$vote_id public property
VotingApi_Vote::$vote_source public property
VotingApi_Vote::deleteMultiple public static function Delete votes from the database.
VotingApi_Vote::save public function
VotingApi_Vote::saveMultiple public static function Save a collection of votes to the database.