plugin/blog/Controller/API/PostController.php
public function getAction(Request $request, Blog $blog, $postId)
    {
        $this->checkPermission('OPEN', $blog->getResourceNode(), [], true);
        $post = $this->postManager->getPostByIdOrSlug($blog, $postId);

        if (is_null($post)) {
            throw new NotFoundHttpException('Post not found');
        }

        $this->trackingManager->dispatchPostReadEvent($post);

        $session = $request->getSession();
        $sessionViewCounterKey = 'blog_post_view_counter_'.$post->getId();
        $now = time();

        if ($now >= ($session->get($sessionViewCounterKey) + $this->logThreshold)) {
            $session->set($sessionViewCounterKey, $now);
            $this->postManager->updatePostViewCount($post);
        }

        return new JsonResponse($this->postSerializer->serialize($post));
    }
public function getAction(Request $request, Blog $blog, $postId)
    {
        $this->checkPermission('OPEN', $blog->getResourceNode(), [], true);
        $post = $this->postManager->getPostByIdOrSlug($blog, $postId);

        if (is_null($post)) {
            throw new NotFoundHttpException('Post not found');
        }

        $this->trackingManager->dispatchPostReadEvent($post);

        $session = $request->getSession();
        $sessionViewCounterKey = 'blog_post_view_counter_'.$post->getId();
        $now = time();

        if ($now >= ($session->get($sessionViewCounterKey) + $this->logThreshold)) {
            $session->set($sessionViewCounterKey, $now);
            $this->postManager->updatePostViewCount($post);
        }

        return new JsonResponse($this->postSerializer->serialize($post));
    }
public function getAction ( Request $ request , Blog $ blog , $ postId ) { $ this -> checkPermission ( 'OPEN' , $ blog -> getResourceNode ( ) , [ ] , true ) ; $ post = $ this -> postManager -> getPostByIdOrSlug ( $ blog , $ postId ) ; if ( is_null ( $ post ) ) { throw new NotFoundHttpException ( 'Post not found' ) ; } $ this -> trackingManager -> dispatchPostReadEvent ( $ post ) ; $ session = $ request -> getSession ( ) ; $ sessionViewCounterKey = 'blog_post_view_counter_' . $ post -> getId ( ) ; $ now = time ( ) ; if ( $ now >= ( $ session -> get ( $ sessionViewCounterKey ) + $ this -> logThreshold ) ) { $ session -> set ( $ sessionViewCounterKey , $ now ) ; $ this -> postManager -> updatePostViewCount ( $ post ) ; } return new JsonResponse ( $ this -> postSerializer -> serialize ( $ post ) ) ; }
Get blog post.

@EXT\Route("/{postId}", name="apiv2_blog_post_get")
@EXT\Method("GET")
@EXT\ParamConverter("blog", options={"mapping": {"blogId": "uuid"}})

@param Blog $blog
@param Post $post

@return array
Get blog post .