Exemplo n.º 1
0
 /**
  * @param string $name
  * @param string $primaryFieldName
  * @param string $requestFieldName
  * @param CollectionFactory $tagCollectionFactory
  * @param DataPersistorInterface $dataPersistor
  * @param array $meta
  * @param array $data
  */
 public function __construct($name, $primaryFieldName, $requestFieldName, CollectionFactory $tagCollectionFactory, DataPersistorInterface $dataPersistor, array $meta = [], array $data = [])
 {
     $this->collection = $tagCollectionFactory->create();
     $this->dataPersistor = $dataPersistor;
     parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
     $this->meta = $this->prepareMeta($this->meta);
 }
Exemplo n.º 2
0
 /**
  * Retrieve tags
  * @return array
  */
 public function getTags()
 {
     if ($this->_tags === null) {
         $this->_tags = $this->_tagCollectionFactory->create();
         $resource = $this->_tags->getResource();
         $this->_tags->getSelect()->joinLeft(['pt' => $resource->getTable('magefan_blog_post_tag')], 'main_table.tag_id = pt.tag_id', [])->joinLeft(['p' => $resource->getTable('magefan_blog_post')], 'p.post_id = pt.post_id', [])->joinLeft(['ps' => $resource->getTable('magefan_blog_post_store')], 'p.post_id = pt.post_id', ['count' => 'count(main_table.tag_id)'])->group('main_table.tag_id')->where('ps.store_id IN (?)', [0, (int) $this->_storeManager->getStore()->getId()]);
     }
     return $this->_tags;
 }
Exemplo n.º 3
0
 /**
  * Options getter
  *
  * @return array
  */
 public function toOptionArray()
 {
     if ($this->options === null) {
         $this->options = [];
         $collection = $this->tagCollectionFactory->create();
         $collection->setOrder('title');
         foreach ($collection as $item) {
             $this->options[] = ['label' => $item->getTitle(), 'value' => $item->getId()];
         }
     }
     return $this->options;
 }
Exemplo n.º 4
0
 /**
  * Retrieve post tags
  * @return \Magefan\Blog\Model\ResourceModel\Tag\Collection
  */
 public function getRelatedTags()
 {
     if (is_null($this->_relatedTags)) {
         $this->_relatedTags = $this->_tagCollectionFactory->create()->addFieldToFilter('tag_id', ['in' => $this->getTags()])->setOrder('title');
     }
     return $this->_relatedTags;
 }