function newComment($slug, Request $request, Application $app) { if (!$this->build($slug, $request, $app)) { $app->abort(404, "Area does not exist."); } if ($this->parameters['area']->getIsDeleted()) { die("No"); // TODO } $comment = new AreaCommentModel(); $form = $app['form.factory']->create(new NewCommentForm(), $comment); if ('POST' == $request->getMethod()) { $form->bind($request); if ($form->isValid()) { $area = $this->parameters['area']; if ($request->request->get("area")) { foreach ($this->parameters['parentAreas'] as $parentArea) { if ($parentArea->getId() == $request->request->get("area")) { $area = $parentArea; } } } $repo = new AreaCommentRepository(); $repo->create($comment, $area, $app['currentUser']); $userWatchesAreaRepo = new UserWatchesAreaRepository(); $userWatchesAreaRepo->startUserWatchingAreaIfNotWatchedBefore($app['currentUser'], $area); return $app->redirect("/area/" . $area->getSlugforURL() . '/comment'); } } $this->parameters['form'] = $form->createView(); return $app['twig']->render('site/area/newComment.html.twig', $this->parameters); }
function index($slug, Request $request, Application $app) { if (!$this->build($slug, $request, $app)) { $app->abort(404, "Area does not exist."); } if ($request->request->get('areaCommentSlug') && $request->request->get('CSFRToken') == $app['websession']->getCSFRToken()) { $repo = new AreaCommentRepository(); $areaComment = $repo->getByAreaAndSlug($this->parameters['area'], $request->request->get('areaCommentSlug')); if ($areaComment) { if ($request->request->get('action') == 'delete') { $repo->delete($areaComment, $app['currentUser']); } else { if ($request->request->get('action') == 'undelete') { $repo->undelete($areaComment, $app['currentUser']); } else { if ($request->request->get('action') == 'close') { $repo->closeByAdmin($areaComment, $app['currentUser']); } else { if ($request->request->get('action') == 'unclose') { $repo->uncloseByAdmin($areaComment, $app['currentUser']); } } } } } } $ecrb = new AreaCommentRepositoryBuilder(); $ecrb->setIncludeDeleted(true); $ecrb->setIncludeClosedByAdmin(true); $ecrb->setArea($this->parameters['area']); $this->parameters['areaComments'] = $ecrb->fetchAll(); return $app['twig']->render('site/commentsadminarea/index.html.twig', $this->parameters); }