You are here

public function PhotosStatisticsUpdateController::updateCount in Album Photos 8.5

Same name and namespace in other branches
  1. 6.0.x src/Controller/PhotosStatisticsUpdateController.php \Drupal\photos\Controller\PhotosStatisticsUpdateController::updateCount()

Ajax callback to record photos_image visit.

Return value

\Symfony\Component\HttpFoundation\JsonResponse A JSON object containing the image visit count.

1 string reference to 'PhotosStatisticsUpdateController::updateCount'
photos.routing.yml in ./photos.routing.yml
photos.routing.yml

File

src/Controller/PhotosStatisticsUpdateController.php, line 49

Class

PhotosStatisticsUpdateController
Class PhotosStatisticsUpdateController.

Namespace

Drupal\photos\Controller

Code

public function updateCount() {
  $photosImageCountDisabled = $this
    ->config('photos.settings')
    ->get('photos_image_count');
  $json = [
    'count' => 1,
  ];
  if (!$photosImageCountDisabled) {
    $id = filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT);
    if ($id) {

      // $this->request_stack->push(Request::createFromGlobals());
      $json['count'] = $this
        ->recordView($id);
    }
  }
  return new JsonResponse($json);
}