Example #1
0
 /**
  * @param Request $request
  * @param Post $post
  * @return mixed
  */
 public function handlePost(Request $request, Post $post)
 {
     $editReason = null;
     if ($post->getId() > 0) {
         if (!$this->get('security.authorization_checker')->isGranted(PostVoter::EDIT, $post)) {
             throw $this->createAccessDeniedException();
         }
         $editReason = $request->get("editReason", "");
     } else {
         if (!$this->get('security.authorization_checker')->isGranted(ForumVoter::CREATE_POST, $post->getTopic()->getForum())) {
             throw $this->createAccessDeniedException();
         }
     }
     $form = $this->createForm("post", $post);
     $oldText = $post->getText();
     $form->handleRequest($request);
     if ($form->isValid()) {
         // insert edit history
         if ($editReason !== null) {
             $history = new Post\History();
             $history->setPost($post);
             $history->setChanged(new \DateTime());
             $history->setEditor($this->getUser());
             $history->setOldText($oldText);
             $history->setReason($editReason);
             $post->addHistory($history);
         }
         $event = new PostFormSaveEvent($post, $request, $form);
         $this->get("event_dispatcher")->dispatch('symbb.core.forum.form.post.before.save', $event);
         $this->get("symbb.core.post.manager")->save($post);
         $this->get("event_dispatcher")->dispatch('symbb.core.forum.form.post.after.save', $event);
         $data = $request->get("post");
         if ($data["notifyMe"]) {
             $this->get("symbb.core.topic.manager")->subscribeNotification($post->getTopic());
         } else {
             $this->get("symbb.core.topic.manager")->unsubscribeNotification($post->getTopic());
         }
         return $this->redirect($this->generateUrl('symbb_forum_topic_show', array("id" => $post->getTopic()->getId(), "name" => $post->getTopic()->getSeoName(), "page" => "last")));
     }
     return $this->render($this->getTemplateBundleName('forum') . ':Forum:postEdit.html.twig', array("post" => $post, "form" => $form->createView()));
 }
Example #2
0
 /**
  * @param Post $post
  * @return bool
  */
 public function save(Post $post)
 {
     $new = false;
     if ($post->getId() <= 0) {
         $new = true;
     }
     $text = Utils::purifyHtml($post->getText());
     $post->setText($text);
     $this->em->persist($post);
     $this->em->flush();
     if ($new) {
         $this->markAsNew($post);
     }
     // if it is a new answer of an existing topic
     if ($post->getTopic()->getId() > 0 && $new) {
         // get all notify flags for this topic
         $flags = $this->topicFlagHandler->findFlagsByObjectAndFlag($post->getTopic(), AbstractFlagHandler::FLAG_NOTIFY);
         foreach ($flags as $flag) {
             // if the notify user is not the author of the new post
             if ($flag->getUser()->getId() !== $post->getAuthor()->getId()) {
                 // send a notify
                 $this->notifyHandler->sendTopicNotifications($post->getTopic(), $flag->getUser());
             }
         }
     }
     return true;
 }