You are here

public function BaseRatingForm::getResults in Votingapi Widgets 8

Get results.

2 calls to BaseRatingForm::getResults()
BaseRatingForm::ajaxSubmit in src/Form/BaseRatingForm.php
Ajax submit handler.
BaseRatingForm::buildForm in src/Form/BaseRatingForm.php
Form constructor.

File

src/Form/BaseRatingForm.php, line 149

Class

BaseRatingForm
Form controller for Campaign edit forms.

Namespace

Drupal\votingapi_widgets\Form

Code

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