Exemplo n.º 1
0
 protected function addPostLike(\Symbb\Core\ForumBundle\Entity\Post $post, \Symbb\Core\UserBundle\Entity\UserInterface $user, $asDislike = false)
 {
     if (!$this->get('security.authorization_checker')->isGranted(RatingVoter::CREATE_RATING, $post->getTopic()->getForum(), $user)) {
         throw $this->createAccessDeniedException();
     }
     $likes = $this->get('doctrine')->getRepository('SymbbExtensionRatingBundle:Like', 'symbb')->findBy(array('post' => $post, 'user' => $user));
     $dislikes = $this->get('doctrine')->getRepository('SymbbExtensionRatingBundle:Dislike', 'symbb')->findBy(array('post' => $post, 'user' => $user));
     $myLikes = array();
     $myDislikes = array();
     $em = $this->get('doctrine')->getManager('symbb');
     foreach ($likes as $like) {
         if ($like->getUser()->getId() === $user->getId()) {
             $myLikes[] = $like;
         }
     }
     foreach ($dislikes as $dislike) {
         if ($dislike->getUser()->getId() === $user->getId()) {
             $myDislikes[] = $dislike;
         }
     }
     // if the user "like" it
     if (!$asDislike) {
         // remove "dislikes"
         foreach ($myDislikes as $myDislike) {
             //$post->removeDislike($myDislike);
             $em->remove($myDislike);
         }
         // create a new "like" if no one exist
         if (empty($myLikes)) {
             $myLike = new \Symbb\Extension\RatingBundle\Entity\Like();
             $myLike->setUser($user);
             $myLike->setPost($post);
             $em->persist($myLike);
             // i again then delete
         } else {
             foreach ($myLikes as $myLike) {
                 $em->remove($myLike);
             }
         }
     } else {
         // remove "likes"
         foreach ($myLikes as $myLike) {
             //$post->removeLike($myLike);
             $em->remove($myLike);
         }
         // create a new "dislike" if no one exist
         if (empty($myDislikes)) {
             $myDislike = new \Symbb\Extension\RatingBundle\Entity\Dislike();
             $myDislike->setUser($user);
             $myDislike->setPost($post);
             $em->persist($myDislike);
             // i again then delete
         } else {
             foreach ($myDislikes as $myDislike) {
                 $em->remove($myDislike);
             }
         }
     }
     $em->flush();
 }
Exemplo n.º 2
0
 /**
  * @param Request $request
  * @return mixed
  */
 public function createNewsAction(Request $request)
 {
     $entryId = $request->get("id");
     $entry = $this->get('symbb.core.manager.news')->find($entryId);
     if (is_object($entry)) {
         $forum = $entry->getCategory()->getTargetForum();
         if (!$this->get('security.authorization_checker')->isGranted(ForumVoter::CREATE_POST, $forum)) {
             throw $this->createAccessDeniedException();
         }
         $topic = new Topic();
         $topic->setForum($forum);
         $topic->setAuthor($this->getUser());
         $topic->setName($entry->getTitle());
         $entry->setTopic($topic);
         $this->get("doctrine.orm.symbb_entity_manager")->persist($entry);
         $post = new Post();
         $post->setAuthor($this->getUser());
         $post->setText($entry->getText());
         $post->setTopic($topic);
         $post->setName($entry->getTitle());
         $topic->setMainPost($post);
         return $this->handleTopic($request, $topic);
     }
     throw new \ErrorException("News not found!");
 }
Exemplo n.º 3
0
 public function newTopic($forumId, $subject, $text, $prefixId = "", $attachmentIds = array(), $groupId = 0)
 {
     $this->debug("newTopic");
     $forum = $this->forumManager->find($forumId);
     $access = $this->securityContext->isGranted(ForumVoter::CREATE_TOPIC, $forum);
     $success = false;
     $topicId = 0;
     if ($access) {
         if ($forum) {
             $topic = new Topic();
             $topic->setAuthor($this->userManager->getCurrentUser());
             $topic->setName($subject);
             $topic->setForum($forum);
             $post = new Post();
             $post->setName($subject);
             $post->setAuthor($this->userManager->getCurrentUser());
             $post->setText($text);
             $post->setTopic($topic);
             $topic->setMainPost($post);
             $success = $this->topicManager->save($topic);
             $topicId = $topic->getId();
         }
     } else {
         $this->debug("no access");
         $error = "no access";
         $success = false;
     }
     $configList = array('result' => new \Zend\XmlRpc\Value\Boolean($success), 'result_text' => new \Zend\XmlRpc\Value\Base64($error), 'topic_id' => new \Zend\XmlRpc\Value\String($topicId), 'state' => new \Zend\XmlRpc\Value\Integer(0));
     return $this->getResponse($configList, 'struct');
 }
Exemplo n.º 4
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()));
 }
Exemplo n.º 5
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;
 }
Exemplo n.º 6
0
 public function setName($value)
 {
     $post = $this->getMainPost();
     if (!is_object($post)) {
         $post = new Post();
         $post->setTopic($this);
     }
     $post->setName($value);
 }