/** * Creates an Comment object based on a DB row. * * @param array $row The DB row containing Comment data. * @return \DeadPoolCave\Domain\Comment */ protected function buildDomainObject($row) { $comment = new Comment(); $comment->setId($row['com_id']); $comment->setContent($row['com_content']); if (array_key_exists('art_id', $row)) { // Find and set the associated article $articleId = $row['art_id']; $article = $this->articleDAO->find($articleId); $comment->setArticle($article); } if (array_key_exists('usr_id', $row)) { // Find and set the associated author $userId = $row['usr_id']; $user = $this->userDAO->find($userId); $comment->setAuthor($user); } return $comment; }
/** * Article details controller. * * @param integer $id Article id * @param Request $request Incoming request * @param Application $app Silex application */ public function articleAction($id, Request $request, Application $app) { $article = $app['dao.article']->find($id); $genres = $app['dao.genre']->findAll(); $authors = $app['dao.author']->findAll(); $editors = $app['dao.editor']->findAll(); $authorsArticle = $app['dao.author']->findByArticle($id); $commentFormView = null; if ($app['security.authorization_checker']->isGranted('IS_AUTHENTICATED_FULLY')) { // A user is fully authenticated : he can add comments $comment = new Comment(); $comment->setArticle($article); $user = $app['user']; $comment->setAuthor($user); $commentForm = $app['form.factory']->create(new CommentType(), $comment); $commentForm->handleRequest($request); if ($commentForm->isSubmitted() && $commentForm->isValid()) { $app['dao.comment']->save($comment); $app['session']->getFlashBag()->add('success', 'Votre commentaire à été ajouté.'); } $commentFormView = $commentForm->createView(); } $comments = $app['dao.comment']->findAllByArticle($id); return $app['twig']->render('article.html.twig', array('article' => $article, 'authorsArticle' => $authorsArticle, 'genres' => $genres, 'authors' => $authors, 'editors' => $editors, 'comments' => $comments, 'commentForm' => $commentFormView)); }