Example #1
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!");
 }
Example #2
0
 public function sendTopicNotifications(Topic $topic, $user)
 {
     if (is_numeric($user)) {
         $user = $this->em->getRepository('SymbbCoreUserBundle:User')->find($user);
     }
     $templateBundle = $this->siteManager->getTemplate("email");
     $subject = $this->translator->trans('It was written a new answer to "%topic%"', array('%topic%' => $topic->getName()), 'symbb_email');
     $sender = $this->siteManager->getSite()->getEmail();
     if (!empty($sender)) {
         $recipient = $user->getEmail();
         $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($sender)->setTo($recipient)->setBody($this->container->get('twig')->render($templateBundle . ':Email:topic_notify.' . $this->getLocale() . '.html.twig', array('topic' => $topic, 'user' => $user, 'site' => $this->siteManager->getSite())), 'text/html');
         $this->mailer->send($message);
     }
 }
Example #3
0
 /**
  *
  * @param int $topicId
  * @return array(<\Symbb\Core\ForumBundle\Entity\Post>)
  */
 public function findByTopic(Topic $topic, $limit = null, $pageNumber = 1)
 {
     $qb = $this->em->getRepository('SymbbCoreForumBundle:Post')->createQueryBuilder('p');
     $qb->select("p");
     $qb->where("p.topic = :topic ");
     $qb->orderBy("p.created", "ASC");
     $query = $qb->getQuery();
     $query->setParameter('topic', $topic->getId());
     $paginator = $this->paginator;
     $pagination = $paginator->paginate($query, $pageNumber, $limit);
     return $pagination;
 }
Example #4
0
 protected function createForTopic(\Symbb\Core\ForumBundle\Entity\Topic $object, $breadcrumb)
 {
     if ($object->getId() > 0) {
         $uri = $this->router->generate('symbb_forum_topic_show', array('id' => $object->getId(), 'name' => $object->getSeoName(), 'page' => 1));
         $breadcrumb[] = array('name' => $object->getName(), 'link' => $uri);
     }
     $forum = $object->getForum();
     $breadcrumb = $this->createForForum($forum, $breadcrumb);
     return $breadcrumb;
 }
Example #5
0
 /**
  * @param Request $request
  * @param Topic $topic
  * @return mixed
  */
 public function handleTopic(Request $request, Topic $topic)
 {
     $editReason = null;
     if ($topic->getId() > 0) {
         if (!$this->get('security.authorization_checker')->isGranted(TopicVoter::EDIT, $topic)) {
             throw $this->createAccessDeniedException();
         }
         $editReason = $request->get("editReason", "");
     } else {
         if (!$this->get('security.authorization_checker')->isGranted(ForumVoter::CREATE_TOPIC, $topic->getForum())) {
             throw $this->createAccessDeniedException();
         }
     }
     $form = $this->createForm("topic", $topic, array("attr" => array("class" => "css-form form-horizontal")));
     $oldText = $topic->getMainPost()->getText();
     $form->handleRequest($request);
     if ($form->isValid()) {
         // insert edit history
         if ($editReason !== null) {
             $history = new Post\History();
             $history->setPost($topic->getMainPost());
             $history->setChanged(new \DateTime());
             $history->setEditor($this->getUser());
             $history->setOldText($oldText);
             $history->setReason($editReason);
             $topic->getMainPost()->addHistory($history);
         }
         $event = new TopicFormSaveEvent($topic, $request, $form);
         $this->get("event_dispatcher")->dispatch('symbb.core.forum.form.topic.before.save', $event);
         $this->get("symbb.core.topic.manager")->save($topic);
         $this->get("event_dispatcher")->dispatch('symbb.core.forum.form.topic.after.save', $event);
         if ($form->get("mainPost")->get("notifyMe")->getData()) {
             $this->get("symbb.core.topic.manager")->subscribeNotification($topic);
         } else {
             $this->get("symbb.core.topic.manager")->unsubscribeNotification($topic);
         }
         $this->get('symbb.core.post.flag')->insertFlags($topic->getMainPost(), PostFlagHandler::FLAG_NEW);
         return $this->redirect($this->generateUrl('symbb_forum_topic_show', array("id" => $topic->getId(), "name" => $topic->getSeoName(), "page" => 1)));
     }
     return $this->render($this->getTemplateBundleName('forum') . ':Forum:topicEdit.html.twig', array("topic" => $topic, "form" => $form->createView()));
 }
Example #6
0
 protected function getTopicAsStruct(Topic $topic)
 {
     $forum = $topic->getForum();
     $author = $topic->getAuthor();
     $closed = $topic->isLocked();
     $new = $this->topicManager->checkFlag($topic, "new");
     return new \Zend\XmlRpc\Value\Struct(array('forum_id' => new \Zend\XmlRpc\Value\String($forum->getId()), 'forum_name' => new \Zend\XmlRpc\Value\Base64($forum->getName()), 'topic_id' => new \Zend\XmlRpc\Value\String($topic->getId()), 'topic_title' => new \Zend\XmlRpc\Value\Base64($topic->getName()), 'prefix' => new \Zend\XmlRpc\Value\Base64(""), 'post_author_id' => new \Zend\XmlRpc\Value\String($author->getId()), 'post_author_name' => new \Zend\XmlRpc\Value\Base64($author->getUsername()), 'is_subscribed' => new \Zend\XmlRpc\Value\Boolean(false), 'can_subscribe' => new \Zend\XmlRpc\Value\Boolean(false), 'is_closed' => new \Zend\XmlRpc\Value\Boolean($closed), 'icon_url' => new \Zend\XmlRpc\Value\String($this->userManager->getAbsoluteAvatarUrl($author)), 'post_time' => new \Zend\XmlRpc\Value\DateTime($topic->getCreated()), 'reply_number' => new \Zend\XmlRpc\Value\Integer($topic->getPostCount()), 'new_post' => new \Zend\XmlRpc\Value\Boolean($new), 'view_number' => new \Zend\XmlRpc\Value\Integer(0), 'short_content' => new \Zend\XmlRpc\Value\Base64("")));
 }
Example #7
0
 /**
  * @param Topic $topic
  * @return bool
  */
 public function open(Topic $topic)
 {
     $topic->setLocked(false);
     $this->em->persist($topic);
     $this->em->flush();
     return true;
 }