/**
  * Render the viewhelper
  *
  * @param integer $category category uid
  * @param string $as name of the new object
  * @return string rendered content
  */
 public function render($category, $as)
 {
     $this->templateVariableContainer->add($as, $this->categoryRepository->findChildren($category));
     $output = $this->renderChildren();
     $this->templateVariableContainer->remove($as);
     return $output;
 }
 /**
  * List categories
  *
  * @param array $overwriteDemand
  * @return void
  */
 public function listAction(array $overwriteDemand = NULL)
 {
     $demand = $this->createDemandObjectFromSettings($this->settings);
     if ($this->settings['disableOverrideDemand'] != 1 && $overwriteDemand !== NULL) {
         $demand = $this->overwriteDemandObject($demand, $overwriteDemand);
     }
     $idList = explode(',', $this->settings['categories']);
     $this->view->assignMultiple(array('categories' => $this->categoryRepository->findTree($idList), 'overwriteDemand' => $overwriteDemand, 'demand' => $demand));
 }
Exemplo n.º 3
0
 /**
  * Edit news item
  *
  * @param News $news
  */
 public function editAction(News $news)
 {
     $this->view->assign('news', $news);
     if (!empty($this->settings['categories']['enabled'])) {
         $this->view->assign('categories', $this->categoryRepository->findAll());
     }
 }
Exemplo n.º 4
0
 /**
  * Create l10n relation
  *
  * @param array $queueItem
  * @return void
  */
 protected function createL10nChildrenCategory(array $queueItem)
 {
     /** @var $category Tx_News_Domain_Model_Category */
     $category = $queueItem['category'];
     $titleLanguageOverlay = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode('|', $queueItem['titleLanguageOverlay']);
     foreach ($titleLanguageOverlay as $key => $title) {
         $sysLanguageUid = $key + 1;
         $importItem = $queueItem['importItem'];
         $importItem['import_id'] = $importItem['import_id'] . '|L:' . $sysLanguageUid;
         /** @var $l10nChildrenCategory Tx_News_Domain_Model_Category */
         $l10nChildrenCategory = $this->hydrateCategory($importItem);
         $this->categoryRepository->add($l10nChildrenCategory);
         $l10nChildrenCategory->setTitle($title);
         $l10nChildrenCategory->setL10nParent((int) $category->getUid());
         $l10nChildrenCategory->setSysLanguageUid((int) $sysLanguageUid);
     }
 }
 /**
  * Main action for administration
  *
  * @param Tx_News_Domain_Model_Dto_AdministrationDemand $demand
  * @dontvalidate  $demand
  * @return void
  */
 public function indexAction(Tx_News_Domain_Model_Dto_AdministrationDemand $demand = NULL)
 {
     if (is_null($demand)) {
         $demand = $this->objectManager->get('Tx_News_Domain_Model_Dto_AdministrationDemand');
         // Preselect by TsConfig (e.g. tx_news.module.preselect.topNewsRestriction = 1)
         $tsConfig = t3lib_BEfunc::getPagesTSconfig($this->pageUid);
         if (isset($tsConfig['tx_news.']['module.']['preselect.']) && is_array($tsConfig['tx_news.']['module.']['preselect.'])) {
             unset($tsConfig['tx_news.']['module.']['preselect.']['orderByAllowed']);
             foreach ($tsConfig['tx_news.']['module.']['preselect.'] as $propertyName => $propertyValue) {
                 Tx_Extbase_Reflection_ObjectAccess::setProperty($demand, $propertyName, $propertyValue);
             }
         }
     }
     $demand = $this->createDemandObjectFromSettings($demand);
     $categories = $this->categoryRepository->findParentCategoriesByPid($this->pageUid);
     $idList = array();
     foreach ($categories as $c) {
         $idList[] = $c->getUid();
     }
     $this->view->assignMultiple(array('page' => $this->pageUid, 'demand' => $demand, 'news' => $this->newsRepository->findDemanded($demand, FALSE), 'categories' => $this->categoryRepository->findTree($idList), 'dateformat' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']));
 }
 /**
  * Main action for administration
  *
  * @param Tx_News_Domain_Model_Dto_AdministrationDemand $demand
  * @dontvalidate  $demand
  * @return void
  */
 public function indexAction(Tx_News_Domain_Model_Dto_AdministrationDemand $demand = NULL)
 {
     $this->redirectToPageOnStart();
     if (is_null($demand)) {
         $demand = $this->objectManager->get('Tx_News_Domain_Model_Dto_AdministrationDemand');
         // Preselect by TsConfig (e.g. tx_news.module.preselect.topNewsRestriction = 1)
         if (isset($this->tsConfiguration['preselect.']) && is_array($this->tsConfiguration['preselect.'])) {
             unset($this->tsConfiguration['preselect.']['orderByAllowed']);
             foreach ($this->tsConfiguration['preselect.'] as $propertyName => $propertyValue) {
                 \TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty($demand, $propertyName, $propertyValue);
             }
         }
     }
     $demand = $this->createDemandObjectFromSettings($demand);
     $categories = $this->categoryRepository->findParentCategoriesByPid($this->pageUid);
     $idList = array();
     foreach ($categories as $c) {
         $idList[] = $c->getUid();
     }
     $assignedValues = array('moduleToken' => $this->getToken(TRUE), 'page' => $this->pageUid, 'demand' => $demand, 'news' => $this->newsRepository->findDemanded($demand, FALSE), 'categories' => $this->categoryRepository->findTree($idList), 'dateformat' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']);
     $this->emitActionSignal('AdministrationController', self::SIGNAL_ADMINISTRATION_INDEX_ACTION, $assignedValues);
     $this->view->assignMultiple($assignedValues);
 }
Exemplo n.º 7
0
 /**
  * Test if by import source is done
  *
  * @test
  * @return void
  */
 public function findRecordByImportSource()
 {
     $category = $this->categoryRepository->findOneByImportSourceAndImportId('functional_test', '2');
     $this->assertEquals($category->getTitle(), 'findRecordByImportSource');
 }
 /**
  * @param Tx_News_Domain_Model_News $news
  * @param array $importItem
  * @param array $importItemOverwrite
  * @return Tx_News_Domain_Model_News
  */
 protected function hydrateNewsRecord(Tx_News_Domain_Model_News $news, array $importItem, array $importItemOverwrite)
 {
     if (!empty($importItemOverwrite)) {
         $importItem = array_merge($importItem, $importItemOverwrite);
     }
     $news->setPid($importItem['pid']);
     $news->setHidden($importItem['hidden']);
     $news->setStarttime($importItem['starttime']);
     $news->setEndtime($importItem['endtime']);
     $news->setFeGroup($importItem['fe_group']);
     $news->setTstamp($importItem['tstamp']);
     $news->setCrdate($importItem['crdate']);
     $news->setTitle($importItem['title']);
     $news->setTeaser($importItem['teaser']);
     $news->setBodytext($importItem['bodytext']);
     $news->setType($importItem['type']);
     $news->setKeywords($importItem['keywords']);
     $news->setDatetime(new DateTime(date('Y-m-d H:i:sP', $importItem['datetime'])));
     $news->setArchive(new DateTime(date('Y-m-d H:i:sP', $importItem['archive'])));
     $contentElementUidArray = \TYPO3\CMS\Extbase\Utility\ArrayUtility::trimExplode(',', $importItem['content_elements'], TRUE);
     foreach ($contentElementUidArray as $contentElementUid) {
         if (is_object($contentElement = $this->ttContentRepository->findByUid($contentElementUid))) {
             $news->addContentElement($contentElement);
         }
     }
     $news->setInternalurl($importItem['internalurl']);
     $news->setExternalurl($importItem['externalurl']);
     $news->setType($importItem['type']);
     $news->setKeywords($importItem['keywords']);
     $news->setAuthor($importItem['author']);
     $news->setAuthorEmail($importItem['author_email']);
     $news->setImportid($importItem['import_id']);
     $news->setImportSource($importItem['import_source']);
     if (is_array($importItem['categories'])) {
         foreach ($importItem['categories'] as $categoryUid) {
             if ($this->settings['findCategoriesByImportSource']) {
                 $category = $this->categoryRepository->findOneByImportSourceAndImportId($this->settings['findCategoriesByImportSource'], $categoryUid);
             } else {
                 $category = $this->categoryRepository->findByUid($categoryUid);
             }
             if ($category) {
                 $news->addCategory($category);
             }
         }
     }
     /** @var $basicFileFunctions \TYPO3\CMS\Core\Utility\File\BasicFileUtility */
     $basicFileFunctions = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\BasicFileUtility');
     // media relation
     if (is_array($importItem['media'])) {
         foreach ($importItem['media'] as $mediaItem) {
             // multi media
             if ($mediaItem['type'] === Tx_News_Domain_Model_Media::MEDIA_TYPE_MULTIMEDIA) {
                 if (($media = $this->getMultiMediaIfAlreadyExists($news, $mediaItem['multimedia'])) === FALSE) {
                     $media = $this->objectManager->get('Tx_News_Domain_Model_Media');
                     $media->setMultimedia($mediaItem['multimedia']);
                     $news->addMedia($media);
                 }
                 if (isset($mediaItem['caption'])) {
                     $media->setDescription($mediaItem['caption']);
                 }
                 if (isset($mediaItem['copyright'])) {
                     $media->setCopyright($mediaItem['copyright']);
                 }
                 if (isset($mediaItem['showinpreview'])) {
                     $media->setShowinpreview($mediaItem['showinpreview']);
                 }
                 $media->setType($mediaItem['type']);
                 $media->setPid($importItem['pid']);
                 // Images FAL enabled
             } elseif ($this->emSettings->getUseFal() > 0) {
                 // get fileobject by given identifier (file UID, combined identifier or path/filename)
                 try {
                     $file = $this->getResourceFactory()->retrieveFileOrFolderObject($mediaItem['image']);
                 } catch (\TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException $exception) {
                     $file = FALSE;
                 }
                 // no file found skip processing of this item
                 if ($file === FALSE) {
                     continue;
                 }
                 /** @var $media Tx_News_Domain_Model_FileReference */
                 if (!($media = $this->getIfFalRelationIfAlreadyExists($news->getFalMedia(), $file))) {
                     // file not inside a storage then search for existing file or copy the one form storage 0 to the import folder
                     if ($file->getStorage()->getUid() === 0) {
                         // search DB for same file based on hash (to prevent duplicates)
                         $existingFile = $this->findFileByHash($file->getSha1());
                         // no exciting file then copy file to import folder
                         if ($existingFile === NULL) {
                             $file = $this->getResourceStorage()->copyFile($file, $this->getImportFolder());
                             // temp work around (uid is not correctly set in $file, fixed in https://review.typo3.org/#/c/26520/)
                             $file = $this->getResourceFactory()->getFileObjectByStorageAndIdentifier($this->emSettings->getStorageUidImporter(), $file->getIdentifier());
                         } else {
                             $file = $existingFile;
                         }
                     }
                     $media = $this->objectManager->get('Tx_News_Domain_Model_FileReference');
                     $media->setFileUid($file->getUid());
                     $news->addFalMedia($media);
                 }
                 if ($media) {
                     $media->setTitle($mediaItem['title']);
                     $media->setAlternative($mediaItem['alt']);
                     $media->setDescription($mediaItem['caption']);
                     $media->setShowinpreview($mediaItem['showinpreview']);
                     $media->setPid($importItem['pid']);
                 }
             } else {
                 if (!($media = $this->getMediaIfAlreadyExists($news, $mediaItem['image']))) {
                     $uniqueName = $basicFileFunctions->getUniqueName($mediaItem['image'], PATH_site . self::UPLOAD_PATH);
                     copy(PATH_site . $mediaItem['image'], $uniqueName);
                     $media = $this->objectManager->get('Tx_News_Domain_Model_Media');
                     $news->addMedia($media);
                     $media->setImage(basename($uniqueName));
                 }
                 $media->setTitle($mediaItem['title']);
                 $media->setAlt($mediaItem['alt']);
                 $media->setCaption($mediaItem['caption']);
                 $media->setType($mediaItem['type']);
                 $media->setShowinpreview($mediaItem['showinpreview']);
                 $media->setPid($importItem['pid']);
             }
         }
     }
     // related files
     if (is_array($importItem['related_files'])) {
         // FAL enabled
         if ($this->emSettings->getUseFal() > 0) {
             foreach ($importItem['related_files'] as $fileItem) {
                 // get fileObject by given identifier (file UID, combined identifier or path/filename)
                 try {
                     $file = $this->getResourceFactory()->retrieveFileOrFolderObject($fileItem['file']);
                 } catch (\TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException $exception) {
                     $file = FALSE;
                 }
                 // no file found skip processing of this item
                 if ($file === FALSE) {
                     continue;
                 }
                 /** @var $relatedFile Tx_News_Domain_Model_FileReference */
                 if (!($relatedFile = $this->getIfFalRelationIfAlreadyExists($news->getFalRelatedFiles(), $file))) {
                     // file not inside a storage then search for existing file or copy the one form storage 0 to the import folder
                     if ($file->getStorage()->getUid() === 0) {
                         // search DB for same file based on hash (to prevent duplicates)
                         $existingFile = $this->findFileByHash($file->getSha1());
                         // no exciting file then copy file to import folder
                         if ($existingFile === NULL) {
                             $file = $this->getResourceStorage()->copyFile($file, $this->getImportFolder());
                             // temp work around (uid is not correctly set in $file, fixed in https://review.typo3.org/#/c/26520/)
                             $file = $this->getResourceFactory()->getFileObjectByStorageAndIdentifier($this->emSettings->getStorageUidImporter(), $file->getIdentifier());
                         } else {
                             $file = $existingFile;
                         }
                     }
                     $relatedFile = $this->objectManager->get('Tx_News_Domain_Model_FileReference');
                     $relatedFile->setFileUid($file->getUid());
                     $news->addFalRelatedFile($relatedFile);
                 }
                 if ($relatedFile) {
                     $relatedFile->setTitle($fileItem['title']);
                     $relatedFile->setDescription($fileItem['description']);
                     $relatedFile->setPid($importItem['pid']);
                 }
             }
         } else {
             foreach ($importItem['related_files'] as $file) {
                 if (!($relatedFile = $this->getRelatedFileIfAlreadyExists($news, $file['file']))) {
                     $uniqueName = $basicFileFunctions->getUniqueName($file['file'], PATH_site . self::UPLOAD_PATH);
                     copy(PATH_site . $file['file'], $uniqueName);
                     $relatedFile = $this->objectManager->get('Tx_News_Domain_Model_File');
                     $news->addRelatedFile($relatedFile);
                     $relatedFile->setFile(basename($uniqueName));
                 }
                 $relatedFile->setTitle($file['title']);
                 $relatedFile->setDescription($file['description']);
                 $relatedFile->setPid($importItem['pid']);
             }
         }
     }
     if (is_array($importItem['related_links'])) {
         foreach ($importItem['related_links'] as $link) {
             /** @var $relatedLink Tx_News_Domain_Model_Link */
             if (($relatedLink = $this->getRelatedLinkIfAlreadyExists($news, $link['uri'])) === FALSE) {
                 $relatedLink = $this->objectManager->get('Tx_News_Domain_Model_Link');
                 $relatedLink->setUri($link['uri']);
                 $news->addRelatedLink($relatedLink);
             }
             $relatedLink->setTitle($link['title']);
             $relatedLink->setDescription($link['description']);
             $relatedLink->setPid($importItem['pid']);
         }
     }
     return $news;
 }
 /**
  * @param Tx_News_Domain_Model_News $news
  * @param array $importItem
  * @param array $importItemOverwrite
  * @return Tx_News_Domain_Model_News
  */
 protected function hydrateNewsRecord(Tx_News_Domain_Model_News $news, array $importItem, array $importItemOverwrite)
 {
     if (!empty($importItemOverwrite)) {
         $importItem = array_merge($importItem, $importItemOverwrite);
     }
     $news->setPid($importItem['pid']);
     $news->setHidden($importItem['hidden']);
     $news->setStarttime($importItem['starttime']);
     $news->setEndtime($importItem['endtime']);
     $news->setTitle($importItem['title']);
     $news->setTeaser($importItem['teaser']);
     $news->setBodytext($importItem['bodytext']);
     $news->setType($importItem['type']);
     $news->setKeywords($importItem['keywords']);
     $news->setDatetime(new DateTime(date('Y-m-d H:i:sP', $importItem['datetime'])));
     $news->setArchive(new DateTime(date('Y-m-d H:i:sP', $importItem['archive'])));
     $contentElementUidArray = Tx_Extbase_Utility_Arrays::trimExplode(',', $importItem['content_elements'], TRUE);
     foreach ($contentElementUidArray as $contentElementUid) {
         if (is_object($contentElement = $this->ttContentRepository->findByUid($contentElementUid))) {
             $news->addContentElement($contentElement);
         }
     }
     $news->setInternalurl($importItem['internalurl']);
     $news->setExternalurl($importItem['externalurl']);
     $news->setType($importItem['type']);
     $news->setKeywords($importItem['keywords']);
     $news->setAuthor($importItem['author']);
     $news->setAuthorEmail($importItem['author_email']);
     $news->setImportid($importItem['import_id']);
     $news->setImportSource($importItem['import_source']);
     if (is_array($importItem['categories'])) {
         foreach ($importItem['categories'] as $categoryUid) {
             if ($this->settings['findCategoriesByImportSource']) {
                 $category = $this->categoryRepository->findOneByImportSourceAndImportId($this->settings['findCategoriesByImportSource'], $categoryUid);
             } else {
                 $category = $this->categoryRepository->findByUid($categoryUid);
             }
             if ($category) {
                 $news->addCategory($category);
             }
         }
     }
     /** @var $basicFileFunctions t3lib_basicFileFunctions */
     $basicFileFunctions = t3lib_div::makeInstance('t3lib_basicFileFunctions');
     // media relation
     if (is_array($importItem['media'])) {
         foreach ($importItem['media'] as $mediaItem) {
             if (!($media = $this->getMediaIfAlreadyExists($news, $mediaItem['image']))) {
                 $uniqueName = $basicFileFunctions->getUniqueName($mediaItem['image'], PATH_site . self::UPLOAD_PATH);
                 copy(PATH_site . $mediaItem['image'], $uniqueName);
                 $media = $this->objectManager->get('Tx_News_Domain_Model_Media');
                 $news->addMedia($media);
                 $media->setImage(basename($uniqueName));
             }
             $media->setTitle($mediaItem['title']);
             $media->setAlt($mediaItem['alt']);
             $media->setCaption($mediaItem['caption']);
             $media->setType($mediaItem['type']);
             $media->setShowinpreview($mediaItem['showinpreview']);
             $media->setPid($importItem['pid']);
         }
     }
     // related files
     if (is_array($importItem['related_files'])) {
         foreach ($importItem['related_files'] as $file) {
             if (!($relatedFile = $this->getRelatedFileIfAlreadyExists($news, $file['file']))) {
                 $uniqueName = $basicFileFunctions->getUniqueName($file['file'], PATH_site . self::UPLOAD_PATH);
                 copy(PATH_site . $file['file'], $uniqueName);
                 $relatedFile = $this->objectManager->get('Tx_News_Domain_Model_File');
                 $news->addRelatedFile($relatedFile);
                 $relatedFile->setFile(basename($uniqueName));
             }
             $relatedFile->setTitle($file['title']);
             $relatedFile->setDescription($file['description']);
             $relatedFile->setPid($importItem['pid']);
         }
     }
     if (is_array($importItem['related_links'])) {
         foreach ($importItem['related_links'] as $link) {
             /** @var $relatedLink Tx_News_Domain_Model_Link */
             $relatedLink = $this->objectManager->get('Tx_News_Domain_Model_Link');
             $relatedLink->setUri($link['uri']);
             $relatedLink->setTitle($link['title']);
             $relatedLink->setDescription($link['description']);
             $relatedLink->setPid($importItem['pid']);
             $news->addRelatedLink($relatedLink);
         }
     }
     return $news;
 }