'vote.getVote', '#callback' => 'voting_service_get_vote', '#access arguments' => array('access content'), '#key' => FALSE, '#args' => array( array( '#name' => 'content_type', '#type' => 'string', '#description' => t('The type of content which you are voting for.')), array( '#name' => 'content_id', '#type' => 'int', '#description' => t('The ID of the content which you are voting for.')), array( '#name' => 'tag', '#type' => 'string', '#description' => t('The category of the vote within the content type.'), '#optional' => TRUE) ), '#return' => 'array', '#help' => t('Returns a vote.')), array( '#method' => 'vote.getUserVote', '#callback' => 'voting_service_get_user_vote', '#access arguments' => array('access content'), '#key' => FALSE, '#args' => array( array( '#name' => 'content_type', '#type' => 'string', '#description' => t('The type of content which you are voting for.')), array( '#name' => 'content_id', '#type' => 'int', '#description' => t('The ID of the content which you are voting for.')), array( '#name' => 'tag', '#type' => 'string', '#description' => t('The category of the vote within the content type.'), '#optional' => TRUE) ), '#return' => 'array', '#help' => t('Returns a vote.')), // vote.set array( '#method' => 'vote.setVote', '#callback' => 'voting_service_set_vote', '#access arguments' => array('allow remote voting'), '#args' => array( array( '#name' => 'content_type', '#type' => 'string', '#description' => t('The type of content which you are voting for.')), array( '#name' => 'content_id', '#type' => 'int', '#description' => t('The ID of the content which you are voting for.')), array( '#name' => 'vote_value', '#type' => 'int', '#description' => t('The value of the vote.')), array( '#name' => 'tag', '#type' => 'string', '#description' => t('The category of the vote within the content type.'), '#optional' => TRUE) ), '#return' => 'array', '#help' => t('Submit a new vote.')), // vote.delete array( '#method' => 'vote.deleteVote', '#callback' => 'voting_service_delete_vote', '#access arguments' => array('allow remote voting'), '#args' => array( array( '#name' => 'content_type', '#type' => 'string', '#description' => t('The type of content which you are deleting.')), array( '#name' => 'content_id', '#type' => 'int', '#description' => t('The ID of the content which you are deleting.')), array( '#name' => 'tag', '#type' => 'string', '#description' => t('The category of the vote within the content type.'), '#optional' => TRUE) ), '#return' => 'array', '#help' => t('Delete a vote.')), ); } function voting_service_get_user_vote($content_type, $content_id, $tag = "vote") { global $user; if( $user->uid ) { $criteria['content_type'] = $content_type; $criteria['content_id'] = $content_id; $criteria['tag'] = $tag; $criteria['value_type'] = 'percent'; $criteria['uid'] = $user->uid; $votes = votingapi_select_votes($criteria); } if($votes) { return $votes[0]; } else { return array('type'=> $content_type, 'tag' => $tag, 'value' => 0); } } /** * Returns a specified node. */ function voting_service_get_vote($content_type, $content_id, $tag = "vote") { $criteria['content_type'] = $content_type; $criteria['content_id'] = $content_id; $criteria['tag'] = $tag; $criteria['value_type'] = 'percent'; $criteria['function'] = 'average'; $votes = votingapi_select_results($criteria); if($votes) { return $votes[0]; } else { return array('type'=> $content_type, 'tag' => $tag, 'value' => 0); } } function voting_service_set_vote($content_type, $content_id, $vote_value, $tag = "vote") { $vote['content_type'] = $content_type; $vote['content_id'] = $content_id; $vote['value'] = $vote_value; $vote['tag'] = $tag; votingapi_set_votes( $vote ); votingapi_recalculate_results($content_type, $content_id, TRUE); return voting_service_get_vote( $content_type, $content_id, $tag ); } function voting_service_delete_vote($content_type, $content_id, $tag = "vote") { global $user; $criteria['content_type'] = $content_type; $criteria['content_type'] = $content_id; $criteria['tag'] = $tag; $criteria['uid'] = $user->uid; $criteria['value_type'] = 'percent'; $votes = votingapi_select_results($criteria); if($votes) { votingapi_delete_vote(array('vote_id' => $votes[0]->vote_id)); votingapi_recalculate_results($content_type, $content_id, TRUE); } return voting_service_get_vote( $content_type, $content_id, $tag ); }