postCollectionFactory = $postCollectionFactory; $this->topicCollectionFactory = $topicCollectionFactory; parent::__construct($context, $registry, $resource, $resourceCollection, $data); } /** * Initialize resource model * * @return void */ protected function _construct() { $this->_init(ResourceModel\Topic::class); } /** * Get identities * * @return array */ public function getIdentities() { return [self::CACHE_TAG . '_' . $this->getId()]; } /** * get entity default values * * @return array */ public function getDefaultValues() { $values = []; $values['enabled'] = '1'; $values['store_ids'] = '1'; return $values; } /** * @return array|mixed */ public function getPostsPosition() { if (!$this->getId()) { return []; } $array = $this->getData('posts_position'); if ($array === null) { $array = $this->getResource()->getPostsPosition($this); $this->setData('posts_position', $array); } return $array; } /** * @return Collection */ public function getSelectedPostsCollection() { if ($this->postCollection === null) { $collection = $this->postCollectionFactory->create(); $collection->join( ['topic' => $this->getResource()->getTable('mageplaza_blog_post_topic')], 'main_table.post_id=topic.post_id AND topic.topic_id=' . $this->getId(), ['position'] ); $this->postCollection = $collection; } return $this->postCollection; } }