Esempio n. 1
0
 /**
  * @Route("/comment/{slug}/create", name="ed_blog_admin_comment_create")
  * @ParamConverter("article", class="BlogBundle\Entity\Article", converter="abstract_converter")
  */
 public function createAction(Request $request, $article)
 {
     $user = $this->getUser();
     $blogSettings = $this->get('blog_settings');
     $object = $this->get('comment_generator')->getObject();
     $object->setArticle($article);
     $class = get_class($object);
     $form = $this->createForm('edcomment', $object);
     if ($request->isMethod('POST')) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $em = $this->getDoctrine()->getManager();
             $object->setCreatedAt(new \DateTime())->setModifiedAt(new \DateTime());
             if ($user && $user->hasRole('ROLE_BLOG_ADMIN')) {
                 $object->setStatus(Comment::STATUS_ACTIVE);
             } else {
                 $object->setStatus(Comment::STATUS_PENDING);
             }
             $em->persist($object);
             $em->flush();
             $dispatcher = $this->get("event_dispatcher");
             $dispatcher->dispatch(EDBlogEvents::ED_BLOG_COMMENT_CREATED, new CommentEvent($object));
             $resetObject = new $class();
             $resetObject->setArticle($article);
             $form = $this->createForm('edcomment', $resetObject);
         }
     }
     $comments = $this->getDoctrine()->getRepository($class)->findByArticle($article, $this->get("blog_settings")->getCommentsDisplayOrder());
     return new JsonResponse(array('success' => true, 'lock' => true, 'currentComment' => IDEncrypt::encrypt($object->getId()), 'html' => $this->renderView("@Blog/Comment/list.html.twig", array('form' => $form->createView(), 'article' => $article, 'comments' => $comments))));
 }
Esempio n. 2
0
 public function encrypt($id)
 {
     $return = IDEncrypt::encrypt($id);
     return $return;
 }