/** * load the authors */ protected function _construct() { parent::_construct(); /** @var \Sample\News\Model\ResourceModel\Author\Collection $authors */ $authors = $this->authorCollectionFactory->create()->addFieldToSelect('*')->addFieldToFilter('is_active', 1)->addStoreFilter($this->_storeManager->getStore()->getId())->setOrder('name', 'ASC'); $this->setAuthors($authors); }
/** * prepare collection * @return $this */ protected function _prepareCollection() { $collection = $this->authorCollectionFactory->create(); if ($this->getProduct()->getId()) { $constraint = 'related.product_id=' . $this->getProduct()->getId(); } else { $constraint = 'related.product_id=0'; } $collection->getSelect()->joinLeft(['related' => $collection->getTable('sample_news_author_product')], 'related.author_id = main_table.author_id AND ' . $constraint, ['position']); $this->setCollection($collection); return parent::_prepareCollection(); }
/** * @return array */ public function getRssData() { $url = $this->urlModel->getListUrl(); $data = ['title' => __('Authors'), 'description' => __('Authors'), 'link' => $url, 'charset' => 'UTF-8']; $collection = $this->authorCollectionFactory->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 \Sample\News\Model\Author $item */ //TODO: add more attributes to RSS $description = '<table><tr><td><a href="%s">%s</a></td></tr></table>'; $description = sprintf($description, $item->getAuthorUrl(), $item->getName()); $data['entries'][] = ['title' => $item->getName(), 'link' => $item->getAuthorUrl(), 'description' => $description]; } return $data; }