public function RateWidgetBase::getVotes in Rate 8.2
Returns the votes for an entity.
Return value
array Vote entity results.
File
- src/
Plugin/ RateWidgetBase.php, line 384
Class
- RateWidgetBase
- Base class for Rate widget plugins.
Namespace
Drupal\rate\PluginCode
public function getVotes($entity_type, $entity_bundle, $entity_id, $vote_type, $value_type, $rate_widget, $user_id = FALSE) {
$storage = $this->entityTypeManager
->getStorage('vote');
$vote_data = [
'entity_type' => $entity_type,
'entity_id' => $entity_id,
'type' => $vote_type,
'value_type' => $value_type,
'rate_widget' => $rate_widget,
];
if (!empty($user_id)) {
$vote_data['user_id'] = $user_id;
}
$query = $this->entityTypeManager
->getStorage('vote')
->getQuery();
foreach ($vote_data as $key => $value) {
$query
->condition($key, $value);
}
$votes = $query
->execute();
$vote_values = [];
if ($votes && count($votes) > 0) {
foreach ($votes as $id) {
$vote = $storage
->load($id);
$vote_values[$vote
->getValue()][] = $vote
->getValue();
}
}
return $vote_values;
}