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
- class \VotingApi_Result
- class \VotingApi_ResultCriteria
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;
}
}