You are here

class VotingApi_Result in Voting API 7.3

Hierarchy

Expanded class hierarchy of VotingApi_Result

1 string reference to 'VotingApi_Result'
VotingApi_ResultCriteria::select in ./votingapi.module
Select cached vote results from the database.

File

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

View source
class VotingApi_Result {
  public $vote_cache_id = NULL;
  public $entity_type = 'node';
  public $entity_id = NULL;
  public $value_type = 'percent';
  public $value = NULL;
  public $tag = 'vote';
  public $function = NULL;
  public $timestamp = REQUEST_TIME;
  public function __construct($data) {
    foreach ($data as $k => $v) {
      $this->{$k} = $v;
    }
  }

  /**
   * Save this result to the database.
   */
  public function save() {
    drupal_write_record('votingapi_cache', $vote_result);
  }

  /**
   * Save a bundle of vote results to the database.
   *
   * This function is called by votingapi_recalculate_results() after tallying
   * the values of all cast votes on a piece of content. This function will be of
   * little use for most third-party modules, unless they manually insert their
   * own result data.
   *
   * @param vote_results array of VotingApi_Result objects
   */
  public static function saveMultiple($vote_results = array()) {
    if (is_object($vote_results)) {
      $vote_results = array(
        $vote_results,
      );
    }
    foreach ($vote_results as $vote_result) {
      $vote_result
        ->save();
    }
  }

  /**
   * Delete vote results from the database.
   *
   * @param $vote_results
   *   An array of vote results to delete. Minimally, each vote result must have
   *   the 'vote_cache_id' key set.
   */
  public static function deleteMultiple($vote_results = array()) {
    if (!empty($vote_results)) {
      $vids = array();
      foreach ($vote_results as $vote) {
        $vids[] = $vote->vote_cache_id;
      }
      db_delete('votingapi_cache')
        ->condition('vote_cache_id', $vids, 'IN')
        ->execute();
    }
  }

}

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