class VoteService in Like & Dislike 7
@file
Hierarchy
- class \Drupal\like_and_dislike\Services\VoteService
Expanded class hierarchy of VoteService
File
- src/
Services/ VoteService.php, line 8
Namespace
Drupal\like_and_dislike\ServicesView source
class VoteService {
/**
* This function gives back the number of votes for a particular entit with a particular type of voting.
* For example it can be used to get number of likes and also dislikes. Just need to change the type.
*
* @param type $entity_id the node id of the node for which number of votes is requited.
* @param type $vote_tag the category of vote: like/dislike etc.
* @param type $entity_type
* @param type $uid
* @param type $ip
* @return int
*/
public static function getEntityVoteAmount($entity_id, $vote_tag, $entity_type, $uid = NULL, $ip = NULL) {
if ($uid === NULL) {
$criteria = array(
'entity_id' => $entity_id,
'tag' => $vote_tag,
'entity_type' => $entity_type,
);
}
else {
$criteria = array(
'entity_id' => $entity_id,
'tag' => $vote_tag,
'uid' => $uid,
'entity_type' => $entity_type,
);
if ($ip != NULL) {
$criteria['vote_source'] = $ip;
}
}
$count = sizeof(votingapi_select_votes($criteria));
if (!isset($count)) {
$count = 0;
}
return $count;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
VoteService:: |
public static | function | This function gives back the number of votes for a particular entit with a particular type of voting. For example it can be used to get number of likes and also dislikes. Just need to change the type. |