public function getLabels(\Symbb\Core\ForumBundle\Entity\Topic $element) { $labels = array(); $flags = $this->topicFlagHandler->findAll($element); foreach ($flags as $flag) { $label = array('title' => $flag->getFlag(), 'type' => 'default'); if ($label["title"] == "new") { $label["type"] = 'success'; } else { if ($label["title"] == "answered") { $label["type"] = 'info'; } else { if ($label["title"] == "locked") { $label["type"] = 'warning'; } } } $labels[$label["title"]] = $label; } $event = new \Symbb\Core\EventBundle\Event\TopicLabelsEvent($element, $labels); $this->dispatcher->dispatch('symbb.topic.labels', $event); $labels = $event->getLabels(); foreach ($labels as $key => $label) { $labels[$key]['title'] = $this->translator->trans($label['title'], array(), 'symbb_frontend'); } return $labels; }
/** * @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; }
/** * @param Forum $forum * @param ForumFlagHandler $flagHandler * @return bool */ public function markAsRead(\Symbb\Core\ForumBundle\Entity\Forum $forum) { $this->forumFlagHandler->removeFlag($forum, AbstractFlagHandler::FLAG_NEW); $topics = $forum->getTopics(); foreach ($topics as $topic) { $this->topicFlagHandler->removeFlag($topic, AbstractFlagHandler::FLAG_NEW); } $subForms = $forum->getChildren(); foreach ($subForms as $subForm) { $this->markAsRead($subForm); } return true; }
/** * @param Topic $topic * @param UserInterface $user */ public function unsubscribeNotification(Topic $topic, UserInterface $user = null) { $this->topicFlagHandler->removeFlag($topic, TopicFlagHandler::FLAG_NOTIFY, $user); }