Example #1
0
 /**
  * load the articles
  */
 protected function _construct()
 {
     parent::_construct();
     /** @var \Gemtoo\Blog\Model\ResourceModel\Article\Collection $articles */
     $articles = $this->articleCollectionFactory->create()->addFieldToSelect('*')->addFieldToFilter('is_active', 1)->addStoreFilter($this->_storeManager->getStore()->getId())->setOrder('name', 'ASC');
     $this->setArticles($articles);
 }
Example #2
0
 /**
  * prepare collection
  * @return $this
  */
 protected function _prepareCollection()
 {
     $collection = $this->articleCollectionFactory->create();
     if ($this->getProduct()->getId()) {
         $constraint = 'related.product_id=' . $this->getProduct()->getId();
     } else {
         $constraint = 'related.product_id=0';
     }
     $collection->getSelect()->joinLeft(['related' => $collection->getTable('gemtoo_blog_article_product')], 'related.article_id = main_table.article_id AND ' . $constraint, ['position']);
     $this->setCollection($collection);
     return parent::_prepareCollection();
 }
Example #3
0
 /**
  * @return mixed
  */
 public function execute()
 {
     try {
         $collection = $this->filter->getCollection($this->collectionFactory->create());
         $collectionSize = $collection->getSize();
         foreach ($collection as $article) {
             $this->doTheAction($article);
         }
         $this->messageManager->addSuccess(__($this->successMessage, $collectionSize));
     } catch (LocalizedException $e) {
         $this->messageManager->addError($e->getMessage());
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __($this->errorMessage));
     }
     $redirectResult = $this->resultRedirectFactory->create();
     $redirectResult->setPath('gemtoo_blog/*/index');
     return $redirectResult;
 }
Example #4
0
 /**
  * @return array
  */
 public function getRssData()
 {
     $url = $this->urlModel->getListUrl();
     $data = ['title' => __('Articles'), 'description' => __('Articles'), 'link' => $url, 'charset' => 'UTF-8'];
     $collection = $this->articleCollectionFactory->create();
     $collection->addStoreFilter($this->getStoreId());
     $collection->addFieldToFilter('is_active', 1);
     //TODO: use constant
     $collection->addFieldToFilter('in_rss', 1);
     //TODO: use constant
     foreach ($collection as $item) {
         /** @var \Gemtoo\Blog\Model\Article $item */
         //TODO: add more attributes to RSS
         $description = '<table><tr><td><a href="%s">%s</a></td></tr></table>';
         $description = sprintf($description, $item->getArticleUrl(), $item->getName());
         $data['entries'][] = ['title' => $item->getName(), 'link' => $item->getArticleUrl(), 'description' => $description];
     }
     return $data;
 }