/** * 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('usr_id', $row)) { // Find and set the associated author $userId = $row['usr_id']; $user = $this->userDAO->find($userId); $comment->setAuthor($user); } return $comment; }
$app->get('/admin', function () use($app) { $articles = $app['dao.article']->findAll(); $comments = $app['dao.comment']->findAll(); $users = $app['dao.user']->findAll(); return $app['twig']->render('admin.html.twig', array('articles' => $articles, 'comments' => $comments, 'users' => $users)); })->bind('admin'); // Article details with comments and basket $app->match('/article/{id}', function ($id, Request $request) use($app) { $article = $app['dao.article']->find($id); $commentFormView = null; $basketFormView = null; if ($app['security.authorization_checker']->isGranted('IS_AUTHENTICATED_FULLY')) { // A user is fully authenticated : he can add comments and article $user = $app['user']; $comment = new Comment(); $comment->setArticle($article); $comment->setAuthor($user); $commentForm = $app['form.factory']->create(new CommentType(), $comment); $commentForm->handleRequest($request); $tmp = 2; $basket = $app['dao.basket']->findByUsrArt($user->getId(), $article->getId()); if ($basket == null) { $tmp = 1; $basket = new Basket(); $basket->setUsrid($user->getId()); $basket->setArtid($article->getId()); } $basketForm = $app['form.factory']->create(new BasketType(), $basket); $basketForm->handleRequest($request); if ($commentForm->isSubmitted() && $commentForm->isValid()) { $app['dao.comment']->save($comment);