You are here

class VotingApi_ResultCriteria in Voting API 7.3

Criteria to select VotingApi_Results

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

Hierarchy

Expanded class hierarchy of VotingApi_ResultCriteria

File

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

View source
class VotingApi_ResultCriteria extends VotingApi_Result {

  /**
   * Select cached vote results from the database.
   *
   * @param $limit
   *   An optional integer specifying the maximum number of votes to return.
   * @return
   *   An array of vote results matching the criteria.
   */
  function select($limit = 0) {
    $query = db_select('votingapi_cache')
      ->fields('votingapi_cache');
    $this
      ->addConditions($query);
    if (!empty($limit)) {
      $query
        ->range(0, $limit);
    }
    $result = $query
      ->execute();
    $result->fetchOptions['class_name'] = 'VotingApi_Result';
    return $result
      ->fetchAll(PDO::FETCH_CLASS);
  }
  public static function byEntity($entity_type, $entity_ids) {
    $class = get_called_class();
    return new $class(array(
      'entity_type' => $entity_type,
      'entity_id' => $entity_ids,
    ));
  }
  protected function addConditions(&$query) {
    foreach ($this as $key => $value) {
      if (!isset($value)) {
        continue;
      }
      $query
        ->condition($key, $value, is_array($value) ? 'IN' : '=');
    }
  }
  public function delete() {
    $query = db_delete('votingapi_cache');
    $this
      ->addConditions($query);
    $query
      ->execute();
  }

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

}

Members

Namesort descending Modifiers Type Description Overrides
VotingApi_Result::$entity_id public property
VotingApi_Result::$entity_type public property
VotingApi_Result::$function public property
VotingApi_Result::$tag public property
VotingApi_Result::$timestamp public property
VotingApi_Result::$value public property
VotingApi_Result::$value_type public property
VotingApi_Result::$vote_cache_id public property
VotingApi_Result::deleteMultiple public static function Delete vote results from the database.
VotingApi_Result::save public function Save this result to the database.
VotingApi_Result::saveMultiple public static function Save a bundle of vote results to the database.
VotingApi_Result::__construct public function
VotingApi_ResultCriteria::addConditions protected function
VotingApi_ResultCriteria::byEntity public static function
VotingApi_ResultCriteria::delete public function
VotingApi_ResultCriteria::select function Select cached vote results from the database.
VotingApi_ResultCriteria::singleValue public function Retrieve the value of the first result matching the criteria.