/**
  * @return void
  */
 public function listArticlesAction()
 {
     $articles = $this->articleRepository->findByPid($this->pageUid);
     $pages = $this->pageRepository->findPagesContainingRecordType('tx_cadabra_domain_model_article');
     $this->view->assign('articles', $articles);
     $this->view->assign('pages', $pages);
 }
Beispiel #2
0
 /**
  * Generate articles from an array of hashes
  *
  * @param array $hashes
  * @param boolean $persist
  * @return \SplObjectStorage
  */
 public function generateArticlesFromHashes($hashes, $persist = false)
 {
     $articles = new \SplObjectStorage();
     foreach ($hashes as $hash) {
         $article = $this->articleHashingService->resolveHash($hash);
         $article->setPid(self::getCurrentPageId());
         $articles->attach($article);
         if ($persist && $article->_isNew()) {
             $product = $article->getProduct();
             $product->addArticle($article);
             $this->productRepository->update($product);
             $this->articleRepository->add($article);
         }
     }
     if ($persist) {
         $this->persistenceManager->persistAll();
     }
     return $articles;
 }
 /**
  * Returns an article object based on the hash identifier
  *
  * @param string $hash
  * @throws \Abra\Cadabra\Exception
  * @return \Abra\Cadabra\Domain\Model\Article
  */
 public function resolveHash($hash)
 {
     $this->reset();
     $article = $this->articleRepository->findByHash($hash);
     //Return persisted article if available
     if ($article !== null) {
         return $article;
     }
     $json = json_decode($hash, true);
     $this->setProduct($json['p']);
     $features = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
     foreach ($json['a'] as $attribute => $attributeValue) {
         /**
          * @TODO: Use property mapper?!
          */
         $feature = new \Abra\Cadabra\Domain\Model\ArticleFeature();
         $feature->setProduct($this->product);
         /** @var \Abra\Cadabra\Domain\Model\Attribute\AbstractAttribute $attributeObject */
         $attributeObject = $this->attributeRepository->findByIdentifier($attribute);
         if ($attributeObject === null) {
             throw new \Abra\Cadabra\Exception('Attribute with identifier ' . $attribute . ' is not available in the database.', 1455116486);
         }
         $feature->setAttribute($attributeObject);
         /** @var \Abra\Cadabra\Domain\Model\Attribute\AttributeValue $value */
         foreach ($attributeObject->getValues() as $value) {
             //Check if attribute value belongs to supplied attribute
             if ($value->getUid() == $attributeValue) {
                 $feature->setAttributeValue($value);
             }
         }
         //No corresponding record found in attribute value list
         $obj = new self::$attributeValue();
         if (!$feature->getAttributeValue() instanceof $obj) {
             throw new \Abra\Cadabra\Exception('Attribute value with identifier ' . $attributeValue . 'does not belong to the attribute with identifier' . $attribute, 1455117095);
         }
         $features->attach($feature);
     }
     /**
      * @TODO: Use property mapper?!
      */
     $article = new \Abra\Cadabra\Domain\Model\Article();
     $article->setProduct($this->product);
     $article->setFeatures($features);
     $article->setHash($hash);
     return $article;
 }
 /**
  * list
  *
  * @return void
  */
 public function listAction()
 {
     $articles = $this->articleRepository->findAll();
     $this->view->assign('articles', $articles);
 }