Example #1
0
 /**
  * @param \GeorgRinger\News\Domain\Model\News $news
  * @param array $importItem
  * @param array $importItemOverwrite
  * @return \GeorgRinger\News\Domain\Model\News
  */
 protected function hydrateNewsRecord(\GeorgRinger\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->setSysLanguageUid($importItem['sys_language_uid']);
     $news->setSorting((int) $importItem['sorting']);
     $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);
             } else {
                 $this->logger->warning(sprintf('Category with ID "%s" was not found', $categoryUid));
             }
         }
     }
     /** @var $basicFileFunctions \TYPO3\CMS\Core\Utility\File\BasicFileUtility */
     $basicFileFunctions = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\File\\BasicFileUtility');
     // media relation
     if (is_array($importItem['media'])) {
         foreach ($importItem['media'] as $mediaItem) {
             // multi media
             if ((int) $mediaItem['type'] === Media::MEDIA_TYPE_MULTIMEDIA) {
                 if (($media = $this->getMultiMediaIfAlreadyExists($news, $mediaItem['multimedia'])) === FALSE) {
                     /** @var Media $media */
                     $media = $this->objectManager->get('GeorgRinger\\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;
                 }
                 // file not inside a storage then search for same file based on hash (to prevent duplicates)
                 if ($file->getStorage()->getUid() === 0) {
                     $existingFile = $this->findFileByHash($file->getSha1());
                     if ($existingFile !== NULL) {
                         $file = $existingFile;
                     }
                 }
                 /** @var $media FileReference */
                 if (!($media = $this->getIfFalRelationIfAlreadyExists($news->getFalMedia(), $file))) {
                     // file not inside a storage copy the one form storage 0 to the import folder
                     if ($file->getStorage()->getUid() === 0) {
                         $file = $this->getResourceStorage()->copyFile($file, $this->getImportFolder());
                     }
                     $media = $this->objectManager->get('GeorgRinger\\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('GeorgRinger\\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;
                 }
                 // file not inside a storage then search for same file based on hash (to prevent duplicates)
                 if ($file->getStorage()->getUid() === 0) {
                     $existingFile = $this->findFileByHash($file->getSha1());
                     if ($existingFile !== NULL) {
                         $file = $existingFile;
                     }
                 }
                 /** @var $relatedFile FileReference */
                 if (!($relatedFile = $this->getIfFalRelationIfAlreadyExists($news->getFalRelatedFiles(), $file))) {
                     // file not inside a storage copy the one form storage 0 to the import folder
                     if ($file->getStorage()->getUid() === 0) {
                         $file = $this->getResourceStorage()->copyFile($file, $this->getImportFolder());
                     }
                     $relatedFile = $this->objectManager->get('GeorgRinger\\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('GeorgRinger\\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 Link */
             if (($relatedLink = $this->getRelatedLinkIfAlreadyExists($news, $link['uri'])) === FALSE) {
                 $relatedLink = $this->objectManager->get('GeorgRinger\\News\\Domain\\Model\\Link');
                 $relatedLink->setUri($link['uri']);
                 $news->addRelatedLink($relatedLink);
             }
             $relatedLink->setTitle($link['title']);
             $relatedLink->setDescription($link['description']);
             $relatedLink->setPid($importItem['pid']);
         }
     }
     $arguments = array('importItem' => $importItem, 'news' => $news);
     $this->emitSignal('postHydrate', $arguments);
     return $news;
 }
Example #2
0
 /**
  * Test if bodytext can be set
  *
  * @test
  * @return void
  */
 public function bodytextCanBeSet()
 {
     $bodytext = 'News bodytext';
     $this->newsDomainModelInstance->setBodytext($bodytext);
     $this->assertEquals($bodytext, $this->newsDomainModelInstance->getBodytext());
 }
 /**
  * @param \GeorgRinger\News\Domain\Model\News $news
  * @param  integer $currentPage
  */
 public function detailActionSlot($news, $currentPage)
 {
     $plenigoFields = $this->getPlenigoFields($news->getUid());
     //        \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($plenigoFields);
     if (empty($plenigoFields)) {
         $GLOBALS['TSFE']->pageUnavailableAndExit("Plenigo Extension not configured yet or Error reading Data", 'HTTP/1.1 500 Internal Server Error');
         throw new \Exception("Plenigo Extension not configured yet or Error reading Data from News-Table");
         return true;
     }
     $this->plenigoSettings = $this->getPlenigoSettings();
     if (is_null($this->plenigoSettings)) {
         $GLOBALS['TSFE']->pageUnavailableAndExit("Plenigo Extension not configured yet or Error reading Data", 'HTTP/1.1 500 Internal Server Error');
     }
     $hasUserBought = null;
     //            $secret     = $plenigoSetting->getCompanyPrivateKey();
     //            $companyId  = $plenigoSetting->getCompanyID();
     //            $isTestMode = $plenigoSetting->isTestMode();
     $this->connect();
     // is there a category
     if ($plenigoFields['plenigo_category']) {
         $category = $this->getPlenigoCategory($plenigoFields['plenigo_category']);
         $productID = 'item-' . $news->getUid();
         // is it bought already?
         $hasUserBought = \plenigo\services\UserService::hasUserBought($productID);
         if (!$hasUserBought) {
             //creating the product ($productId, $productTitle, $price, $currency)
             try {
                 // new custom ProductID (https://github.com/plenigo/plenigo_php_sdk/wiki/Checkout#other-products)
                 $product = new \plenigo\models\ProductBase($productID, $news->getTitle());
                 $product->setCategoryId($category['plenigo_i_d']);
             } catch (\Exception $e) {
                 $GLOBALS['TSFE']->pageUnavailableAndExit("Could not create Plenigo-Product", 'HTTP/1.1 500 Internal Server Error');
             }
         }
     }
     // its not bought yet, but we have an associated product
     if (!$hasUserBought && $plenigoFields['plenigo_product']) {
         $productData = $this->getPlenigoProduct($plenigoFields['plenigo_product']);
         // ist it bought?
         $hasUserBought = \plenigo\services\UserService::hasUserBought($productData['product_i_d']);
         if (!$hasUserBought) {
             // https://github.com/plenigo/plenigo_php_sdk/wiki/Checkout#plenigo-managed-product
             try {
                 $product = new \plenigo\models\ProductBase($productData['product_i_d']);
                 //                    \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($productData);
             } catch (\Exception $e) {
                 $GLOBALS['TSFE']->pageUnavailableAndExit("Could not create Plenigo-Product", 'HTTP/1.1 500 Internal Server Error');
             }
         }
     }
     if (FALSE === $hasUserBought) {
         // inject our js-sdk into html-header
         $this->buildHeader();
         if (!is_object($product)) {
             $GLOBALS['TSFE']->pageUnavailableAndExit("Product is not bought, but no productidentity given", 'HTTP/1.1 500 Internal Server Error');
             throw new \Exception("no Product given!");
         }
         $curtain = new Curtain($this->plenigoSettings);
         $checkout = new \plenigo\builders\CheckoutSnippetBuilder($product);
         $builder = new \plenigo\builders\LoginSnippetBuilder();
         //This will generate the login snippet of the following format:
         //plenigo.login();
         $curtain->setLoginButton($builder->build());
         $curtain->setCheckoutCode($checkout->build());
         $news->setBodytext($this->getPaymentInfo($news->getBodytext()) . $curtain->getCode());
     }
     // else displaying normal news
 }