t('Bread'), 'description' => t('The quality of the food at a restaurant.'), 'module' => 'mymodule', // This is optional; we can add it for our own purposes. ); $data['tags']['circuses'] = array( 'name' => t('Circuses'), 'description' => t('The quality of the presentation and atmosphere at a restaurant.'), 'module' => 'mymodule', ); // Document two custom aggregate function. $data['functions']['standard_deviation'] = array( 'name' => t('Standard deviation'), 'description' => t('The standard deviation of all votes cast on a given piece of content. Use this to find controversial content.'), 'module' => 'mymodule', ); $data['functions']['median'] = array( 'name' => t('Median vote'), 'description' => t('The median vote value cast on a given piece of content. More accurate than a pure average when there are a few outlying votes.'), 'module' => 'mymodule', ); } /** * Returns callback functions and descriptions to format a VotingAPI Views field. * * Loads all votes for a given piece of content, then calculates and caches the * aggregate vote results. This is only intended for modules that have assumed * responsibility for the full voting cycle: the votingapi_set_vote() function * recalculates automatically. * * @param $field * A Views field object. This can be used to expose formatters only for tags, * vote values, aggregate functions, etc. * @return * An array of key-value pairs, in which each key is a callback function and * each value is a human-readable description of the formatter. * * @see votingapi_set_votes() */ function hook_votingapi_views_formatters($field) { if ($field->field == 'value') { return array('mymodule_funky_formatter' => t('MyModule value formatter')); } if ($field->field == 'tag') { return array('mymodule_funky_tags' => t('MyModule tag formatter')); } } /** * Save a vote in the database. * * @param $vote * See votingapi_add_votes() for the structure of this array, with the * defaults loaded from votingapi_prep_vote(). */ function hook_votingapi_storage_add_vote(&$vote) { _mongodb_votingapi_prepare_vote($criteria); mongodb_collection('votingapi_vote')->insert($vote); } /** * Delete votes from the database. * * @param $votes * An array of votes to delete. Minimally, each vote must have the 'vote_id' * key set. * @param $vids * A list of the 'vote_id' values from $voes. */ function hook_votingapi_storage_delete_votes($votes, $vids) { mongodb_collection('votingapi_vote')->delete(array('vote_id' => array('$in' => array_map('intval', $vids)))); } /** * Select invidual votes from the database * * @param $criteria * A keyed array used to build the select query. Keys can contain * a single value or an array of values to be matched. * $criteria['vote_id'] (If this is set, all other keys are skipped) * $criteria['entity_id'] * $criteria['entity_type'] * $criteria['value_type'] * $criteria['tag'] * $criteria['uid'] * $criteria['vote_source'] * $criteria['timestamp'] If this is set, records with timestamps * GREATER THAN the set value will be selected. Defaults to * REQUEST_TIME - variable_get('votingapi_anonymous_window', 3600); if * the anonymous window is above zero. * @param $limit * An integer specifying the maximum number of votes to return. 0 means * unlimited and is the default. * @return * An array of votes matching the criteria. */ function hook_votingapi_storage_select_votes($criteria, $limit) { _mongodb_votingapi_prepare_vote($criteria); $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; } /** * Allows to act on votes before being inserted. * * @param $votes * An array of votes, each with the following structure: * $vote['entity_type'] (Optional, defaults to 'node') * $vote['entity_id'] (Required) * $vote['value_type'] (Optional, defaults to 'percent') * $vote['value'] (Required) * $vote['tag'] (Optional, defaults to 'vote') * $vote['uid'] (Optional, defaults to current user) * $vote['vote_source'] (Optional, defaults to current IP) * $vote['timestamp'] (Optional, defaults to REQUEST_TIME) */ function hook_votingapi_preset_votes(&$votes) { foreach ($votes as $vote) { if ($vote['tag'] == 'recommend') { // Do something if the 'recommend' vote is being inserted. } } } /** * TODO * */ function hook_votingapi_storage_standard_results($entity_id, $entity) { // TODO }