You are here

public function VotingApiWidgetBase::getResults in Votingapi Widgets 8

Get results.

1 call to VotingApiWidgetBase::getResults()
VotingApiWidgetBase::getVoteSummary in src/Plugin/VotingApiWidgetBase.php
Generate summary.

File

src/Plugin/VotingApiWidgetBase.php, line 232

Class

VotingApiWidgetBase
Base class for Voting api widget plugins.

Namespace

Drupal\votingapi_widgets\Plugin

Code

public function getResults($entity, $result_function = FALSE, $reset = FALSE) {
  if ($reset) {
    drupal_static_reset(__FUNCTION__);
  }
  $resultCache =& drupal_static(__FUNCTION__);
  if (!$resultCache) {
    $resultCache = $this->votingapiResult
      ->getResults($entity
      ->getVotedEntityType(), $entity
      ->getVotedEntityId());
  }
  if ($result_function) {
    if (!$resultCache[$entity
      ->getEntityTypeId()][$entity
      ->getVotedEntityId()][$result_function]) {
      return [];
    }
    return $resultCache[$entity
      ->getEntityTypeId()][$entity
      ->getVotedEntityId()][$result_function];
  }
  if (!$result_function) {
    if (!isset($resultCache[$entity
      ->getEntityTypeId()][$entity
      ->getVotedEntityId()])) {
      return [];
    }
    return $resultCache[$entity
      ->getEntityTypeId()][$entity
      ->getVotedEntityId()];
  }
  return [];
}