示例#1
0
 /**
  * Converts string of tags to an object
  * @param string $tags
  * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage
  */
 public function initTags($tags)
 {
     /* @var \Mittwald\Typo3Forum\Domain\Model\Forum\Tag */
     $objTags = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
     $tagArray = array_unique(explode(',', $tags));
     foreach ($tagArray as $tagName) {
         $tagName = ucfirst(trim($tagName));
         if ($tagName == "") {
             continue;
         }
         $searchResult = $this->tagRepository->findTagWithSpecificName($tagName);
         if ($searchResult[0] != false) {
             $searchResult[0]->increaseTopicCount();
             $objTags->attach($searchResult[0]);
         } else {
             /* @var \Mittwald\Typo3Forum\Domain\Model\Forum\Tag $tag */
             $tag = $this->objectManager->get('Mittwald\\Typo3Forum\\Domain\\Model\\Forum\\Tag');
             $tag->setName($tagName);
             $tag->setCrdate(new \DateTime());
             $tag->increaseTopicCount();
             $objTags->attach($tag);
         }
     }
     return $objTags;
 }
示例#2
0
 /**
  * Check if $value is valid. If it is not valid, needs to add an error
  * to Result.
  *
  * @param string $name
  * @return bool
  */
 protected function isValid($name = "")
 {
     $result = TRUE;
     if (trim($name) === '') {
         $this->addError('The name can\'t be empty!.', 1373871955);
         $result = FALSE;
     }
     $name = ucfirst($name);
     $res = $this->tagRepository->findTagWithSpecificName($name);
     if ($res[0] != false) {
         $this->addError('The tag already exists!.', 1373871960);
         $result = FALSE;
     }
     return $result;
 }
 /**
  * Creates a new topic.
  *
  * @param Forum $forum The forum in which the new topic is to be created.
  * @param Post $post The first post of the new topic.
  * @param string $subject The subject of the new topic
  * @param array $attachments File attachments for the post.
  * @param string $question The flag if the new topic is declared as question
  * @param array $criteria All submitted criteria with option.
  * @param string $tags All defined tags for this topic
  * @param string $subscribe The flag if the new topic is subscribed by author
  *
  * @validate $post \Mittwald\Typo3Forum\Domain\Validator\Forum\PostValidator
  * @validate $attachments \Mittwald\Typo3Forum\Domain\Validator\Forum\AttachmentPlainValidator
  * @validate $subject NotEmpty
  */
 public function createAction(Forum $forum, Post $post, $subject, $attachments = array(), $question = '', $criteria = array(), $tags = '', $subscribe = '')
 {
     // Assert authorization
     $this->authenticationService->assertNewTopicAuthorization($forum);
     // Create the new post; add the new post to a new topic and add the new
     // topic to the forum. Then persist the forum object. Not as complicated
     // as is sounds, honestly!
     $this->postFactory->assignUserToPost($post);
     if (!empty($attachments)) {
         $attachments = $this->attachmentService->initAttachments($attachments);
         $post->setAttachments($attachments);
     }
     if ($tags) {
         $tags = $this->tagService->initTags($tags);
         foreach ($tags as $tag) {
             if ($tag->getUid === NULL) {
                 $this->tagRepository->add($tag);
             }
         }
     } else {
         $tags = NULL;
     }
     $topic = $this->topicFactory->createTopic($forum, $post, $subject, (int) $question, $criteria, $tags, (int) $subscribe);
     // Notify potential listeners.
     $this->signalSlotDispatcher->dispatch('Mittwald\\Typo3Forum\\Domain\\Model\\Forum\\Topic', 'topicCreated', ['topic' => $topic]);
     $this->clearCacheForCurrentPage();
     $uriBuilder = $this->controllerContext->getUriBuilder();
     $uri = $uriBuilder->setTargetPageUid($this->settings['pids']['Forum'])->setArguments(array('tx_typo3forum_pi1[forum]' => $forum->getUid(), 'tx_typo3forum_pi1[controller]' => 'Forum', 'tx_typo3forum_pi1[action]' => 'show'))->build();
     $this->purgeUrl('http://' . $_SERVER['HTTP_HOST'] . '/' . $uri);
     // Redirect to single forum display view
     $this->redirect('show', 'Forum', NULL, array('forum' => $forum));
 }
 /**
  * @param string $value
  * @return string as json array
  */
 public function autoCompleteAction($value)
 {
     $result = array();
     $tagObj = $this->tagRepository->findTagLikeAName($value);
     foreach ($tagObj as $tag) {
         $result[] = $tag->getName();
     }
     return json_encode($result);
 }