/** * Checks if a user can create new posts inside this topic. Since this topic is * only a shadow topic, this method will ALWAYS return FALSE. * * @param FrontendUser $user The user. * @param string $accessType The access type to be checked. * * @return boolean TRUE, if the user can create new posts. Always FALSE. */ public function checkAccess(FrontendUser $user = NULL, $accessType = 'read') { if ($accessType === 'newPost') { return FALSE; } else { return parent::checkAccess($user, $accessType); } }
/** * Performs an access check for this post. * * @access private * * @param FrontendUser $user * @param string $accessType * * @return boolean */ public function checkAccess(FrontendUser $user = NULL, $accessType = 'read') { switch ($accessType) { case 'editPost': case 'deletePost': return $this->checkEditOrDeletePostAccess($user, $accessType); default: return $this->topic->checkAccess($user, $accessType); } }
/** * Adds a topic. * * @param Topic $topic * * @return void */ public function addTopic(Topic $topic) { if ($this->lastTopic === NULL || $this->lastTopic->getTimestamp() <= $topic->getTimestamp()) { $this->setLastTopic($topic); } $topicLastPost = $topic->getLastPost(); if ($topicLastPost !== NULL && ($this->lastPost === NULL || $this->lastPost->getTimestamp() <= $topicLastPost->getTimestamp())) { $this->setLastPost($topic->getLastPost()); } $this->_increaseTopicCount(+1); // topic will increase postCount itself when adding the initial post to it $topic->setForum($this); $this->topics->attach($topic); }
/** * * Generates a data array that will be passed to the typoscript object for * rendering the icon. * @param \Mittwald\Typo3Forum\Domain\Model\Forum\Topic $topic * 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\Topic $topic = NULL) { if ($topic === NULL) { return array(); } elseif ($topic instanceof \Mittwald\Typo3Forum\Domain\Model\Forum\ShadowTopic) { return array('moved' => TRUE); } else { return array('important' => $topic->getPostCount() >= $this->arguments['important'], 'new' => !$topic->hasBeenReadByUser($this->frontendUserRepository->findCurrent()), 'closed' => $topic->isClosed(), 'sticky' => $topic->isSticky(), 'solved' => $topic->getIsSolved()); } }
/** * Marks a topic as read by the current user. * * @param Topic $topic The topic that is to be marked as read. * */ protected function markTopicRead(Topic $topic) { $currentUser = $this->getCurrentUser(); if ($currentUser === NULL || $currentUser->isAnonymous()) { return; } else { if ($topic->hasBeenReadByUser($currentUser)) { $currentUser->addReadObject($topic); $this->frontendUserRepository->update($currentUser); } } }
/** * Delete a topic from repository! * * @param Topic $topic The topic that is be deleted. * * @return void */ public function topicConformDeleteAction(Topic $topic) { $this->authenticationService->assertModerationAuthorization($topic->getForum()); foreach ($topic->getPosts() as $post) { $this->postRepository->remove($post); } $this->topicRepository->remove($topic); $this->controllerContext->getFlashMessageQueue()->enqueue(new FlashMessage(Localization::translate('Moderation_DeleteTopic_Success', 'Typo3Forum'))); $this->clearCacheForCurrentPage(); $this->redirect('show', 'Forum', NULL, array('forum' => $topic->getForum())); }
/** * Fav Subscribes the current user to a forum or a topic. * * @param Forum $forum The forum that is to be subscribed. Either this value or the $topic parameter must be != NULL. * @param Topic $topic The topic that is to be subscribed. Either this value or the $forum parameter must be != NULL. * @param bool $unsubscribe TRUE to unsubscribe the forum or topic instead. * @return void * @throws InvalidArgumentValueException * @throws NotLoggedInException */ public function favSubscribeAction(Forum $forum = NULL, Topic $topic = NULL, $unsubscribe = FALSE) { // Validate arguments if ($forum === NULL && $topic === NULL) { throw new InvalidArgumentValueException("You need to subscribe a Forum or Topic!", 1285059341); } $user = $this->getCurrentUser(); if ($user->isAnonymous()) { throw new NotLoggedInException('You need to be logged in to subscribe or unsubscribe an object.', 1335121482); } # Create subscription $object = $forum ? $forum : $topic; if ($unsubscribe) { $user->removeFavSubscription($object); $topic->getAuthor()->decreasePoints((int) $this->settings['rankScore']['gotFavorite']); } else { $user->addFavSubscription($object); $topic->getAuthor()->increasePoints((int) $this->settings['rankScore']['gotFavorite']); } # Update user and redirect to subscription object. $this->frontendUserRepository->update($user); $this->frontendUserRepository->update($topic->getAuthor()); $this->controllerContext->getFlashMessageQueue()->enqueue(new FlashMessage($this->getSubscriptionFlashMessage($object, $unsubscribe))); $this->clearCacheForCurrentPage(); $this->redirectToSubscriptionObject($object); }
/** * Sets a post as solution * * @param Topic $topic * @param Post $post */ public function setPostAsSolution(Topic $topic, Post $post) { $topic->setSolution($post); $this->topicRepository->update($topic); $this->forumRepository->update($topic->getForum()); }