protected function VoteResultFunctionManager::performAndStore in Voting API 8.3
Perform the result calculations on a set of votes and store the results.
Parameters
array $votes: The set of votes to perform the calculations on. All votes in the set are expected to be the same vote type and for the same entity.
1 call to VoteResultFunctionManager::performAndStore()
- VoteResultFunctionManager::recalculateResults in src/
VoteResultFunctionManager.php - Recalculates the aggregate voting results of all votes for a given entity.
File
- src/
VoteResultFunctionManager.php, line 158
Class
- VoteResultFunctionManager
- Manages vote result plugins.
Namespace
Drupal\votingapiCode
protected function performAndStore(array $votes) {
$entity_type_id = $votes[0]
->getVotedEntityType();
$entity_id = $votes[0]
->getVotedEntityId();
$vote_type = $votes[0]
->bundle();
foreach ($this
->getDefinitions() as $plugin_id => $definition) {
$plugin = $this
->createInstance($plugin_id);
$vote_results[] = [
'entity_id' => $entity_id,
'entity_type' => $entity_type_id,
'type' => $vote_type,
'function' => $plugin_id,
'value' => $plugin
->calculateResult($votes),
'value_type' => $votes[0]
->get('value_type')->value,
'timestamp' => $this->datetime
->getRequestTime(),
];
}
// Give other modules a chance to act on the results of vote calculations.
$this->moduleHandler
->alter('votingapi_results', $vote_results, $entity_type_id, $entity_id);
foreach ($vote_results as $id => $vote_result) {
if (!empty($vote_result)) {
$this->database
->insert('votingapi_result')
->fields($vote_result)
->execute();
}
}
}