You are here

class Mongodb_VoteStorage in Voting API 7.3

Same name and namespace in other branches
  1. 8.3 votingapi.api.php \Mongodb_VoteStorage

Hierarchy

Expanded class hierarchy of Mongodb_VoteStorage

1 string reference to 'Mongodb_VoteStorage'
votingapi.api.php in ./votingapi.api.php
Provides hook documentation for the VotingAPI module.

File

./votingapi.api.php, line 128
Provides hook documentation for the VotingAPI module.

View source
class Mongodb_VoteStorage {

  /**
   * Save a vote in the database.
   *
   * @param $vote instance of VotingApi_Vote.
   */
  function addVote(&$vote) {
    mongodb_collection('votingapi_vote')
      ->insert($vote);
  }

  /**
   * Delete votes from the database.
   *
   * @param $votes An array of VotingApi_Vote instances to delete.
   *   Minimally, each vote must have the 'vote_id' key set.
   * @param $vids
   *   A list of the 'vote_id' values from $votes.
   */
  function deleteVotes($votes, $vids) {
    mongodb_collection('votingapi_vote')
      ->delete(array(
      'vote_id' => array(
        '$in' => array_map('intval', $vids),
      ),
    ));
  }

  /**
   * Select individual votes from the database.
   *
   * @param $criteria instance of VotingApi_Criteria.
   * @param $limit
   *   An integer specifying the maximum number of votes to return. 0 means
   *   unlimited and is the default.
   * @return
   *   An array of VotingApi_Vote objects matching the criteria.
   */
  function selectVotes($criteria, $limit) {
    $find = array();
    foreach ($criteria as $key => $value) {
      $find[$key] = is_array($value) ? array(
        '$in' => $value,
      ) : $value;
    }
    $cursor = mongodb_collection('votingapi_vote')
      ->find($find);
    if (!empty($limit)) {
      $cursor
        ->limit($limit);
    }
    $votes = array();
    foreach ($cursor as $vote) {
      $votes[] = $vote;
    }
    return $votes;
  }

  /**
   * TODO
   *
   */
  function standardResults($entity_id, $entity) {

    // TODO
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Mongodb_VoteStorage::addVote function Save a vote in the database.
Mongodb_VoteStorage::deleteVotes function Delete votes from the database.
Mongodb_VoteStorage::selectVotes function Select individual votes from the database.
Mongodb_VoteStorage::standardResults function TODO