/**
  * @param Tournament $tournament
  */
 public function notifyAboutNewTournament(Tournament $tournament)
 {
     $title = $this->container->get("templating")->render('Post/newtournament.topic.html.twig', ['tournament' => $tournament]);
     $postModel = new Post($this->container->getParameter("app_immortalchess.forum_playzone"), $tournament->getGameParams()->getTimeBase() === 180000 ? self::THREAD_FOR_3_MINUTES : self::THREAD_FOR_5_MINUTES, $this->container->getParameter("app_immortalchess.post_username_for_calls"), $this->container->getParameter("app_immortalchess.post_userid_for_calls"), $title, $this->container->get("templating")->render('Post/newtournament.html.twig', ['tournament' => $tournament]));
     $postModel->setThreadTitle($title);
     return $this->container->get("immortalchessnet.service.publish")->publishNewPost($postModel);
 }
Esempio n. 2
0
 /**
  * @param PostModel $postModel
  * @throws \Doctrine\DBAL\DBALException
  */
 public function publishNewThread(PostModel $postModel)
 {
     $thread = (new Thread())->setForumid($postModel->getForumId())->setTitle($postModel->getTitle())->setOpen(1)->setVisible(1)->setTaglist($postModel->getTaglist());
     $this->getManager()->persist($thread);
     $this->getManager()->flush();
     $post = (new Post())->setThreadid($thread->getThreadid())->setParentid(0)->setUsername($postModel->getLastPosterName())->setUserid($postModel->getLastPosterId())->setTitle($postModel->getTitle())->setPagetext($postModel->getPageText())->setVisible(1)->setDateline(time());
     $this->getManager()->persist($post);
     try {
         $this->getManager()->flush();
     } catch (\Exception $e) {
         $this->container->get("logger")->error(__METHOD__ . " " . $e->getMessage());
     }
     try {
         $thread = $this->getManager()->getRepository("ImmortalchessNetBundle:Thread")->find($post->getThreadid());
     } catch (ThreadNotFoundException $e) {
         $this->container->get("logger")->error("Thread #" . $post->getThreadid() . " is not found");
         return;
     }
     $thread->setLastpostid($post->getPostid())->setLastpost($post->getDateline())->setLastposter($post->getUsername())->setThreadid($post->getThreadid())->setReplycount($thread->getReplycount() + 1);
     $this->getManager()->persist($thread);
     try {
         $forum = $this->getManager()->getRepository("ImmortalchessNetBundle:Forum")->find($thread->getForumid());
     } catch (ForumNotFoundException $e) {
         $this->container->get("logger")->error("Forum #" . $thread->getForumid() . " is not found");
         return;
     }
     $forum->setLastpostid($post->getPostid())->setLastpost($post->getDateline())->setLastposter($post->getUsername())->setLastthreadid($post->getThreadid())->setLastthread($thread->getTitle());
     $this->getManager()->persist($forum);
     try {
         $this->getManager()->flush();
     } catch (\Exception $e) {
         $this->container->get("logger")->error(__METHOD__ . " " . $e->getMessage());
     }
 }