You are here

public function RateWidgetBase::getResults in Rate 8.2

Get results.

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

File

src/Plugin/RateWidgetBase.php, line 311

Class

RateWidgetBase
Base class for Rate widget plugins.

Namespace

Drupal\rate\Plugin

Code

public function getResults($entity, $result_function = FALSE, $reset = FALSE) {
  if ($reset) {
    drupal_static_reset(__FUNCTION__);
  }
  $resultCache =& drupal_static(__FUNCTION__);
  if (!$resultCache || !isset($resultCache[$entity
    ->getVotedEntityType()][$entity
    ->getVotedEntityId()]) || !$entity
    ->id()) {
    $resultCache[$entity
      ->getVotedEntityType()][$entity
      ->getVotedEntityId()] = $this->votingapiResult
      ->getResults($entity
      ->getVotedEntityType(), $entity
      ->getVotedEntityId());
  }
  $result = isset($resultCache[$entity
    ->getVotedEntityType()][$entity
    ->getVotedEntityId()]) ? $resultCache[$entity
    ->getVotedEntityType()][$entity
    ->getVotedEntityId()] : [];
  $result = !empty($result) && array_key_exists($entity
    ->bundle(), $result) ? $result[$entity
    ->bundle()] : [];
  if ($result_function && array_key_exists($result_function, $result) && $result[$result_function]) {
    $result = $result[$result_function];
  }
  return $result;
}