Ejemplo n.º 1
0
 public function articleAction($id, Request $request, Application $app)
 {
     $article = $app['dao.article']->find($id);
     $articlepanier = new ArticlePanier();
     $articlepanier->setArticle($article->getId());
     $articleForm = $app['form.factory']->create(new ArticlePanierType(), $articlepanier, ['action' => $app['url_generator']->generate('add_article_to_basket')]);
     $articleForm->handleRequest($request);
     $articleFormView = $articleForm->createView();
     $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', 'Your comment was succesfully added.');
         }
         $commentFormView = $commentForm->createView();
     }
     $comments = $app['dao.comment']->findAllByArticle($id);
     return $app['twig']->render('article.html.twig', array('article' => $article, 'comments' => $comments, 'commentForm' => $commentFormView, 'articleForm' => $articleFormView));
 }
Ejemplo n.º 2
0
 /**
  * Creates an Comment object based on a DB row.
  *
  * @param array $row The DB row containing Comment data.
  * @return \MicroCMS\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('user_id', $row)) {
         // Find and set the associated author
         $userId = $row['user_id'];
         $user = $this->userDAO->find($userId);
         $comment->setAuthor($user);
     }
     return $comment;
 }