/** * * @param Request $request The request. * @param TopicInterface $topic The topic. */ public function viewAction(Request $request, TopicInterface $topic, $pageSize = 10) { /** @var $paginator \Knp\Components\Pager\Paginator */ $paginator = $this->get('knp_paginator'); $page = $request->query->get('page', 1); $posts = $this->postManager->findAllByTopic($topic); $paginatedPosts = $paginator->paginate($posts, $page, $pageSize); $view = View::create(array('topic' => $topic, 'page' => $page, 'posts' => $paginatedPosts))->setFormat($request->getRequestFormat('html'))->setSerializationContext(SerializationContext::create()->setGroups('context'))->setTemplate('LorecallChronicleBundle:Topic:view.html.twig'); $response = $this->createResponseBuilder($view); return array($topic, $response); }
/** * Returns an array of users who have commented on this action. * * @return array an array of users who have commented on this action. */ public function findUsersByTopic($topic) { $users = array(); $posts = $this->postManager->findAllByTopic($topic); // ** Add the rest of the commentors... foreach ($posts as $post) { try { $key = $post->author->getId(); if (!array_key_exists($key, $users)) { $users[$key] = $post->author; } } finally { // Do nothing } } return array_values($users); }