/** * * Recursively generates option rows for a forum and each subforum of this forum. * * @param \Mittwald\Typo3Forum\Domain\Model\Forum\Forum $forum * The forum for which to generate the option row. * @param boolean $isRoot TRUE, if the forum is a root category, otherwise * FALSE. * @return array An option row for the specified forum. * */ protected function getForumOptionRow(\Mittwald\Typo3Forum\Domain\Model\Forum\Forum $forum, $isRoot = FALSE) { $result = array('name' => $forum->getTitle(), 'uid' => $forum->getUid(), '_isRoot' => $isRoot, '_children' => array()); foreach ($forum->getChildren() as $childForum) { $result['_children'][] = $this->getForumOptionRow($childForum, FALSE); } return $result; }
/** * * Generates a data array that will be passed to the typoscript object for * rendering the icon. * @param \Mittwald\Typo3Forum\Domain\Model\Forum\Forum $forum * The topic for which the icon is to be displayed. * @return array The data array for the typoscript object. * */ protected function getDataArray(\Mittwald\Typo3Forum\Domain\Model\Forum\Forum $forum = NULL) { if ($forum === NULL) { return array(); } else { $user =& $this->frontendUserRepository->findCurrent(); return array('new' => !$forum->hasBeenReadByUser($user), 'closed' => !$forum->checkNewPostAccess($user)); } }
/** * Returns all parent forums in hiearchical order as a flat list (optionally * with or without this forum itself). * * @param boolean $withSelf TRUE to include this forum into the rootline, otherwise FALSE. * @return array<\Mittwald\Typo3Forum\Domain\Model\Forum\Forum> */ public function getRootline($withSelf = TRUE) { $rootline = $this->forum === NULL ? [] : $this->forum->getRootline(TRUE); if ($withSelf === TRUE) { $rootline[] = $this; } return $rootline; }
/** * Mark a whole forum as read * @param Forum $forum * * @throws NotLoggedInException * @return void */ public function markReadAction(Forum $forum) { $user = $this->getCurrentUser(); if ($user->isAnonymous()) { throw new NotLoggedInException("You need to be logged in.", 1288084981); } $forumStorage = array(); $forumStorage[] = $forum; foreach ($forum->getChildren() as $children) { $forumStorage[] = $children; } foreach ($forumStorage as $checkForum) { /** @var Forum $checkForum */ foreach ($checkForum->getTopics() as $topic) { /** @var Topic $topic */ $topic->addReader($user); } $checkForum->addReader($user); $this->forumRepository->update($checkForum); } $this->redirect('show', 'Forum', NULL, array('forum' => $forum)); }
/** * Moves a topic from one forum to another. This method will create a shadow * topic in the original place that will point to the new location of the * topic. * * @param Topic $topic The topic that is to be moved. * @param Forum $targetForum The target forum. The topic will be moved to this location. * * @throws InvalidClassException */ public function moveTopic(Topic $topic, Forum $targetForum) { if ($topic instanceof ShadowTopic) { throw new InvalidClassException("Topic is already a shadow topic", 1288702422); } $shadowTopic = $this->createShadowTopic($topic); $topic->getForum()->removeTopic($topic); $topic->getForum()->addTopic($shadowTopic); $targetForum->addTopic($topic); $this->forumRepository->update($topic->getForum()); $this->forumRepository->update($targetForum); }
/** * Removes a Post. * * @param Post $post The Post to be removed * * @return void * @throws \Mittwald\Typo3Forum\Domain\Exception\InvalidOperationException */ public function removePost(\Mittwald\Typo3Forum\Domain\Model\Forum\Post $post) { if ($this->postCount === 1) { throw new \Mittwald\Typo3Forum\Domain\Exception\InvalidOperationException('You cannot delete the last post of a topic without deleting the topic itself (use \\Mittwald\\Typo3Forum\\Domain\\Factory\\Forum\\TopicFactory::deleteTopic for that).', 1334603895); } $this->posts->detach($post); $this->postCount--; if ($this->lastPost == $post) { $postsArray = $this->posts->toArray(); $this->setLastPost(array_pop($postsArray)); } if ($this->forum !== NULL) { $this->forum->_increasePostCount(-1); if ($this->forum->getLastPost() === $post) { $this->forum->_resetLastPost(); } } }
/** * @param Forum $forum * @param FrontendUser $user * @return array */ public function getUnreadTopics(Forum $forum, FrontendUser $user) { $sql = 'SELECT t.uid FROM tx_typo3forum_domain_model_forum_topic AS t LEFT JOIN tx_typo3forum_domain_model_user_readtopic AS rt ON rt.uid_foreign = t.uid AND rt.uid_local = ' . (int) $user->getUid() . ' WHERE rt.uid_local IS NULL AND t.forum=' . (int) $forum->getUid(); /** @var Query $query */ $query = $this->createQuery(); $query->statement($sql); return $query->execute()->toArray(); }