diff --git a/Controller/Adminhtml/Category/InlineEdit.php b/Controller/Adminhtml/Category/InlineEdit.php
new file mode 100644
index 00000000..d68c2def
--- /dev/null
+++ b/Controller/Adminhtml/Category/InlineEdit.php
@@ -0,0 +1,178 @@
+dataProcessor = $dataProcessor;
+ $this->categoryRepository = $categoryRepository;
+ $this->jsonFactory = $jsonFactory;
+ }
+
+ /**
+ * Process the request
+ *
+ * @return \Magento\Framework\Controller\ResultInterface
+ * @throws \Magento\Framework\Exception\LocalizedException
+ */
+ public function execute()
+ {
+ /** @var \Magento\Framework\Controller\Result\Json $resultJson */
+ $resultJson = $this->jsonFactory->create();
+ $error = false;
+ $messages = [];
+
+ $categoryItems = $this->getRequest()->getParam('items', []);
+ if (!($this->getRequest()->getParam('isAjax') && count($categoryItems))) {
+ return $resultJson->setData(
+ [
+ 'messages' => [__('Please correct the data sent.')],
+ 'error' => true,
+ ]
+ );
+ }
+
+ foreach (array_keys($categoryItems) as $categoryId) {
+ /** @var \Magefan\Blog\Model\Category $category */
+ $category = $this->categoryRepository->getById($categoryId);
+ try {
+ $categoryData = $this->filterPost($categoryItems[$categoryId]);
+ $this->validatePost($categoryData, $category, $error, $messages);
+ $extendedCategoryData = $category->getData();
+ $this->setBlogCategoryData($category, $extendedCategoryData, $categoryData);
+ $this->categoryRepository->save($category);
+ } catch (\Magento\Framework\Exception\LocalizedException $e) {
+ $messages[] = $this->getErrorWithPostId($category, $e->getMessage());
+ $error = true;
+ } catch (\RuntimeException $e) {
+ $messages[] = $this->getErrorWithPostId($category, $e->getMessage());
+ $error = true;
+ } catch (\Exception $e) {
+ $messages[] = $this->getErrorWithPostId(
+ $category,
+ __('Something went wrong while saving the post.')
+ );
+ $error = true;
+ }
+ }
+
+ return $resultJson->setData(
+ [
+ 'messages' => $messages,
+ 'error' => $error
+ ]
+ );
+ }
+
+ /**
+ * Filtering POSTed data.
+ *
+ * @param array $postData
+ * @return array
+ */
+ protected function filterPost($postData = [])
+ {
+ $blogCategoryData = $this->dataProcessor->filter($postData);
+ $blogCategoryData['custom_theme'] = isset($blogCategoryData['custom_theme']) ? $blogCategoryData['custom_theme'] : null;
+ $blogCategoryData['custom_root_template'] = isset($blogCategoryData['custom_root_template'])
+ ? $blogCategoryData['custom_root_template']
+ : null;
+ return $blogCategoryData;
+ }
+
+ /**
+ * Validate POST data
+ *
+ * @param array $blogCategoryData
+ * @param Category $category
+ * @param bool $error
+ * @param array $messages
+ * @return void
+ */
+ protected function validatePost(array $blogCategoryData, Category $category, &$error, array &$messages)
+ {
+ if (!$this->dataProcessor->validateRequireEntry($blogCategoryData)) {
+ $error = true;
+ foreach ($this->messageManager->getMessages(true)->getItems() as $error) {
+ $messages[] = $this->getErrorWithPostId($category, $error->getText());
+ }
+ }
+ }
+
+ /**
+ * Add post title to error message
+ *
+ * @param Category $category
+ * @param string $errorText
+ * @return string
+ */
+ protected function getErrorWithPostId(Category $category, $errorText)
+ {
+ return '[Category ID: ' . $category->getId() . '] ' . $errorText;
+ }
+
+ /**
+ * Set blog category data
+ *
+ * @param Category $category
+ * @param array $extendedCategoryData
+ * @param array $categoryData
+ * @return $this
+ */
+ public function setBlogCategoryData(Category $category, array $extendedCategoryData, array $categoryData)
+ {
+ $category->setData(array_merge($category->getData(), $extendedCategoryData, $categoryData));
+ return $this;
+ }
+}
diff --git a/Controller/Adminhtml/Category/MassDelete.php b/Controller/Adminhtml/Category/MassDelete.php
new file mode 100644
index 00000000..058618e1
--- /dev/null
+++ b/Controller/Adminhtml/Category/MassDelete.php
@@ -0,0 +1,72 @@
+filter = $filter;
+ $this->collectionFactory = $collectionFactory;
+ parent::__construct($context);
+ }
+
+ /**
+ * Execute action
+ *
+ * @return \Magento\Backend\Model\View\Result\Redirect
+ * @throws \Magento\Framework\Exception\LocalizedException|\Exception
+ */
+ public function execute()
+ {
+ $collection = $this->filter->getCollection($this->collectionFactory->create());
+ $collectionSize = $collection->getSize();
+
+ foreach ($collection as $item) {
+ $item->delete();
+ }
+ //$collection->walk('delete');
+ $this->messageManager->addSuccessMessage(__('A total of %1 record(s) have been deleted.', $collectionSize));
+
+ /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
+ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
+
+ return $resultRedirect->setPath('*/*/');
+ }
+}
diff --git a/Controller/Adminhtml/Category/MassDisable.php b/Controller/Adminhtml/Category/MassDisable.php
new file mode 100644
index 00000000..980278af
--- /dev/null
+++ b/Controller/Adminhtml/Category/MassDisable.php
@@ -0,0 +1,73 @@
+filter = $filter;
+ $this->collectionFactory = $collectionFactory;
+ parent::__construct($context);
+ }
+
+ /**
+ * Execute action
+ *
+ * @return \Magento\Backend\Model\View\Result\Redirect
+ * @throws \Magento\Framework\Exception\LocalizedException|\Exception
+ */
+ public function execute()
+ {
+ $collection = $this->filter->getCollection($this->collectionFactory->create());
+
+ foreach ($collection as $item) {
+ $item->setIsActive(false);
+ $item->save();
+ }
+
+ $this->messageManager->addSuccessMessage(
+ __('A total of %1 record(s) have been disabled.', $collection->getSize())
+ );
+
+ /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
+ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
+ return $resultRedirect->setPath('*/*/');
+ }
+}
diff --git a/Controller/Adminhtml/Category/MassEnable.php b/Controller/Adminhtml/Category/MassEnable.php
new file mode 100644
index 00000000..ad50aa1b
--- /dev/null
+++ b/Controller/Adminhtml/Category/MassEnable.php
@@ -0,0 +1,73 @@
+filter = $filter;
+ $this->collectionFactory = $collectionFactory;
+ parent::__construct($context);
+ }
+
+ /**
+ * Execute action
+ *
+ * @return \Magento\Backend\Model\View\Result\Redirect
+ * @throws \Magento\Framework\Exception\LocalizedException|\Exception
+ */
+ public function execute()
+ {
+ $collection = $this->filter->getCollection($this->collectionFactory->create());
+
+ foreach ($collection as $item) {
+ $item->setIsActive(true);
+ $item->save();
+ }
+
+ $this->messageManager->addSuccessMessage(
+ __('A total of %1 record(s) have been enabled.', $collection->getSize())
+ );
+
+ /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
+ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
+ return $resultRedirect->setPath('*/*/');
+ }
+}
diff --git a/Controller/Adminhtml/Post/InlineEdit.php b/Controller/Adminhtml/Post/InlineEdit.php
new file mode 100644
index 00000000..3aced0b9
--- /dev/null
+++ b/Controller/Adminhtml/Post/InlineEdit.php
@@ -0,0 +1,177 @@
+dataProcessor = $dataProcessor;
+ $this->postRepository = $postRepository;
+ $this->jsonFactory = $jsonFactory;
+ }
+
+ /**
+ * Process the request
+ *
+ * @return \Magento\Framework\Controller\ResultInterface
+ * @throws \Magento\Framework\Exception\LocalizedException
+ */
+ public function execute()
+ {
+ /** @var \Magento\Framework\Controller\Result\Json $resultJson */
+ $resultJson = $this->jsonFactory->create();
+ $error = false;
+ $messages = [];
+
+ $postItems = $this->getRequest()->getParam('items', []);
+ if (!($this->getRequest()->getParam('isAjax') && count($postItems))) {
+ return $resultJson->setData(
+ [
+ 'messages' => [__('Please correct the data sent.')],
+ 'error' => true,
+ ]
+ );
+ }
+
+ foreach (array_keys($postItems) as $postId) {
+ /** @var \Magefan\Blog\Model\Post $post */
+ $post = $this->postRepository->getById($postId);
+ try {
+ $postData = $this->filterPost($postItems[$postId]);
+ $this->validatePost($postData, $post, $error, $messages);
+ $extendedPostData = $post->getData();
+ $this->setBlogPostData($post, $extendedPostData, $postData);
+ $this->postRepository->save($post);
+ } catch (\Magento\Framework\Exception\LocalizedException $e) {
+ $messages[] = $this->getErrorWithPostId($post, $e->getMessage());
+ $error = true;
+ } catch (\RuntimeException $e) {
+ $messages[] = $this->getErrorWithPostId($post, $e->getMessage());
+ $error = true;
+ } catch (\Exception $e) {
+ $messages[] = $this->getErrorWithPostId(
+ $post,
+ __('Something went wrong while saving the post.')
+ );
+ $error = true;
+ }
+ }
+
+ return $resultJson->setData(
+ [
+ 'messages' => $messages,
+ 'error' => $error
+ ]
+ );
+ }
+
+ /**
+ * Filtering POSTed data.
+ *
+ * @param array $postData
+ * @return array
+ */
+ protected function filterPost($postData = [])
+ {
+ $blogPostData = $this->dataProcessor->filter($postData);
+ $blogPostData['custom_theme'] = isset($blogPostData['custom_theme']) ? $blogPostData['custom_theme'] : null;
+ $blogPostData['custom_root_template'] = isset($blogPostData['custom_root_template'])
+ ? $blogPostData['custom_root_template']
+ : null;
+ return $blogPostData;
+ }
+
+ /**
+ * Validate POST data
+ *
+ * @param array $blogPostData
+ * @param Post $post
+ * @param bool $error
+ * @param array $messages
+ * @return void
+ */
+ protected function validatePost(array $blogPostData, Post $post, &$error, array &$messages)
+ {
+ if (!$this->dataProcessor->validateRequireEntry($blogPostData)) {
+ $error = true;
+ foreach ($this->messageManager->getMessages(true)->getItems() as $error) {
+ $messages[] = $this->getErrorWithPostId($post, $error->getText());
+ }
+ }
+ }
+
+ /**
+ * Add post title to error message
+ *
+ * @param Post $post
+ * @param string $errorText
+ * @return string
+ */
+ protected function getErrorWithPostId(Post $post, $errorText)
+ {
+ return '[Post ID: ' . $post->getId() . '] ' . $errorText;
+ }
+
+ /**
+ * Set blog post data
+ *
+ * @param Post $post
+ * @param array $extendedPostData
+ * @param array $postData
+ * @return $this
+ */
+ public function setBlogPostData(Post $post, array $extendedPostData, array $postData)
+ {
+ $post->setData(array_merge($post->getData(), $extendedPostData, $postData));
+ return $this;
+ }
+}
diff --git a/Controller/Adminhtml/Post/MassDelete.php b/Controller/Adminhtml/Post/MassDelete.php
new file mode 100644
index 00000000..304dffc3
--- /dev/null
+++ b/Controller/Adminhtml/Post/MassDelete.php
@@ -0,0 +1,72 @@
+filter = $filter;
+ $this->collectionFactory = $collectionFactory;
+ parent::__construct($context);
+ }
+
+ /**
+ * Execute action
+ *
+ * @return \Magento\Backend\Model\View\Result\Redirect
+ * @throws \Magento\Framework\Exception\LocalizedException|\Exception
+ */
+ public function execute()
+ {
+ $collection = $this->filter->getCollection($this->collectionFactory->create());
+ $collectionSize = $collection->getSize();
+
+ foreach ($collection as $post) {
+ $post->delete();
+ }
+ //$collection->walk('delete');
+ $this->messageManager->addSuccessMessage(__('A total of %1 record(s) have been deleted.', $collectionSize));
+
+ /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
+ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
+
+ return $resultRedirect->setPath('*/*/');
+ }
+}
diff --git a/Controller/Adminhtml/Post/MassDisable.php b/Controller/Adminhtml/Post/MassDisable.php
new file mode 100644
index 00000000..18af66b9
--- /dev/null
+++ b/Controller/Adminhtml/Post/MassDisable.php
@@ -0,0 +1,73 @@
+filter = $filter;
+ $this->collectionFactory = $collectionFactory;
+ parent::__construct($context);
+ }
+
+ /**
+ * Execute action
+ *
+ * @return \Magento\Backend\Model\View\Result\Redirect
+ * @throws \Magento\Framework\Exception\LocalizedException|\Exception
+ */
+ public function execute()
+ {
+ $collection = $this->filter->getCollection($this->collectionFactory->create());
+
+ foreach ($collection as $item) {
+ $item->setIsActive(false);
+ $item->save();
+ }
+
+ $this->messageManager->addSuccessMessage(
+ __('A total of %1 record(s) have been disabled.', $collection->getSize())
+ );
+
+ /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
+ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
+ return $resultRedirect->setPath('*/*/');
+ }
+}
diff --git a/Controller/Adminhtml/Post/MassEnable.php b/Controller/Adminhtml/Post/MassEnable.php
new file mode 100644
index 00000000..55ba69e3
--- /dev/null
+++ b/Controller/Adminhtml/Post/MassEnable.php
@@ -0,0 +1,73 @@
+filter = $filter;
+ $this->collectionFactory = $collectionFactory;
+ parent::__construct($context);
+ }
+
+ /**
+ * Execute action
+ *
+ * @return \Magento\Backend\Model\View\Result\Redirect
+ * @throws \Magento\Framework\Exception\LocalizedException|\Exception
+ */
+ public function execute()
+ {
+ $collection = $this->filter->getCollection($this->collectionFactory->create());
+
+ foreach ($collection as $item) {
+ $item->setIsActive(true);
+ $item->save();
+ }
+
+ $this->messageManager->addSuccessMessage(
+ __('A total of %1 record(s) have been enabled.', $collection->getSize())
+ );
+
+ /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
+ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
+ return $resultRedirect->setPath('*/*/');
+ }
+}
diff --git a/Controller/Adminhtml/Tag/InlineEdit.php b/Controller/Adminhtml/Tag/InlineEdit.php
new file mode 100644
index 00000000..40c57047
--- /dev/null
+++ b/Controller/Adminhtml/Tag/InlineEdit.php
@@ -0,0 +1,178 @@
+dataProcessor = $dataProcessor;
+ $this->tagRepository = $tagRepository;
+ $this->jsonFactory = $jsonFactory;
+ }
+
+ /**
+ * Process the request
+ *
+ * @return \Magento\Framework\Controller\ResultInterface
+ * @throws \Magento\Framework\Exception\LocalizedException
+ */
+ public function execute()
+ {
+ /** @var \Magento\Framework\Controller\Result\Json $resultJson */
+ $resultJson = $this->jsonFactory->create();
+ $error = false;
+ $messages = [];
+
+ $tagItems = $this->getRequest()->getParam('items', []);
+ if (!($this->getRequest()->getParam('isAjax') && count($tagItems))) {
+ return $resultJson->setData(
+ [
+ 'messages' => [__('Please correct the data sent.')],
+ 'error' => true,
+ ]
+ );
+ }
+
+ foreach (array_keys($tagItems) as $tagId) {
+ /** @var \Magefan\Blog\Model\Tag $tag */
+ $tag = $this->tagRepository->getById($tagId);
+ try {
+ $tagData = $this->filterPost($tagItems[$tagId]);
+ $this->validatePost($tagData, $tag, $error, $messages);
+ $extendedTagData = $tag->getData();
+ $this->setBlogTagData($tag, $extendedTagData, $tagData);
+ $this->tagRepository->save($tag);
+ } catch (\Magento\Framework\Exception\LocalizedException $e) {
+ $messages[] = $this->getErrorWithPostId($tag, $e->getMessage());
+ $error = true;
+ } catch (\RuntimeException $e) {
+ $messages[] = $this->getErrorWithPostId($tag, $e->getMessage());
+ $error = true;
+ } catch (\Exception $e) {
+ $messages[] = $this->getErrorWithPostId(
+ $tag,
+ __('Something went wrong while saving the post.')
+ );
+ $error = true;
+ }
+ }
+
+ return $resultJson->setData(
+ [
+ 'messages' => $messages,
+ 'error' => $error
+ ]
+ );
+ }
+
+ /**
+ * Filtering POSTed data.
+ *
+ * @param array $postData
+ * @return array
+ */
+ protected function filterPost($postData = [])
+ {
+ $blogTagData = $this->dataProcessor->filter($postData);
+ $blogTagData['custom_theme'] = isset($blogTagData['custom_theme']) ? $blogTagData['custom_theme'] : null;
+ $blogTagData['custom_root_template'] = isset($blogTagData['custom_root_template'])
+ ? $blogTagData['custom_root_template']
+ : null;
+ return $blogTagData;
+ }
+
+ /**
+ * Validate POST data
+ *
+ * @param array $blogTagData
+ * @param Tag $tag
+ * @param bool $error
+ * @param array $messages
+ * @return void
+ */
+ protected function validatePost(array $blogTagData, Tag $tag, &$error, array &$messages)
+ {
+ if (!$this->dataProcessor->validateRequireEntry($blogTagData)) {
+ $error = true;
+ foreach ($this->messageManager->getMessages(true)->getItems() as $error) {
+ $messages[] = $this->getErrorWithPostId($tag, $error->getText());
+ }
+ }
+ }
+
+ /**
+ * Add post title to error message
+ *
+ * @param Tag $tag
+ * @param string $errorText
+ * @return string
+ */
+ protected function getErrorWithPostId(Tag $tag, $errorText)
+ {
+ return '[Tag ID: ' . $tag->getId() . '] ' . $errorText;
+ }
+
+ /**
+ * Set blog tag data
+ *
+ * @param Tag $tag
+ * @param array $extendedTagData
+ * @param array $tagData
+ * @return $this
+ */
+ public function setBlogTagData(Tag $tag, array $extendedTagData, array $tagData)
+ {
+ $tag->setData(array_merge($tag->getData(), $extendedTagData, $tagData));
+ return $this;
+ }
+}
diff --git a/Controller/Adminhtml/Tag/MassDelete.php b/Controller/Adminhtml/Tag/MassDelete.php
new file mode 100644
index 00000000..230e3c12
--- /dev/null
+++ b/Controller/Adminhtml/Tag/MassDelete.php
@@ -0,0 +1,72 @@
+filter = $filter;
+ $this->collectionFactory = $collectionFactory;
+ parent::__construct($context);
+ }
+
+ /**
+ * Execute action
+ *
+ * @return \Magento\Backend\Model\View\Result\Redirect
+ * @throws \Magento\Framework\Exception\LocalizedException|\Exception
+ */
+ public function execute()
+ {
+ $collection = $this->filter->getCollection($this->collectionFactory->create());
+ $collectionSize = $collection->getSize();
+
+ foreach ($collection as $item) {
+ $item->delete();
+ }
+ //$collection->walk('delete');
+ $this->messageManager->addSuccessMessage(__('A total of %1 record(s) have been deleted.', $collectionSize));
+
+ /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
+ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
+
+ return $resultRedirect->setPath('*/*/');
+ }
+}
diff --git a/Controller/Adminhtml/Tag/MassDisable.php b/Controller/Adminhtml/Tag/MassDisable.php
new file mode 100644
index 00000000..268c851f
--- /dev/null
+++ b/Controller/Adminhtml/Tag/MassDisable.php
@@ -0,0 +1,73 @@
+filter = $filter;
+ $this->collectionFactory = $collectionFactory;
+ parent::__construct($context);
+ }
+
+ /**
+ * Execute action
+ *
+ * @return \Magento\Backend\Model\View\Result\Redirect
+ * @throws \Magento\Framework\Exception\LocalizedException|\Exception
+ */
+ public function execute()
+ {
+ $collection = $this->filter->getCollection($this->collectionFactory->create());
+
+ foreach ($collection as $item) {
+ $item->setIsActive(false);
+ $item->save();
+ }
+
+ $this->messageManager->addSuccessMessage(
+ __('A total of %1 record(s) have been disabled.', $collection->getSize())
+ );
+
+ /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
+ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
+ return $resultRedirect->setPath('*/*/');
+ }
+}
diff --git a/Controller/Adminhtml/Tag/MassEnable.php b/Controller/Adminhtml/Tag/MassEnable.php
new file mode 100644
index 00000000..23f99443
--- /dev/null
+++ b/Controller/Adminhtml/Tag/MassEnable.php
@@ -0,0 +1,73 @@
+filter = $filter;
+ $this->collectionFactory = $collectionFactory;
+ parent::__construct($context);
+ }
+
+ /**
+ * Execute action
+ *
+ * @return \Magento\Backend\Model\View\Result\Redirect
+ * @throws \Magento\Framework\Exception\LocalizedException|\Exception
+ */
+ public function execute()
+ {
+ $collection = $this->filter->getCollection($this->collectionFactory->create());
+
+ foreach ($collection as $item) {
+ $item->setIsActive(true);
+ $item->save();
+ }
+
+ $this->messageManager->addSuccessMessage(
+ __('A total of %1 record(s) have been enabled.', $collection->getSize())
+ );
+
+ /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
+ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
+ return $resultRedirect->setPath('*/*/');
+ }
+}
diff --git a/Model/ResourceModel/Category/Collection.php b/Model/ResourceModel/Category/Collection.php
index e8ad67cf..2898272c 100755
--- a/Model/ResourceModel/Category/Collection.php
+++ b/Model/ResourceModel/Category/Collection.php
@@ -13,6 +13,18 @@
*/
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
+ /**
+ * @var string
+ */
+ protected $_idFieldName = 'category_id';
+
+ /**
+ * Load data for preview flag
+ *
+ * @var bool
+ */
+ protected $_previewFlag;
+
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
@@ -166,11 +178,15 @@ protected function _afterLoad()
if ($result[$categoryId] == 0) {
$stores = $this->_storeManager->getStores(false, true);
$storeId = current($stores)->getId();
+ $storeCode = key($stores);
} else {
- $storeId = $result[$item->getData('category_id')];
+ $storeId = current($result[$item->getData('category_id')]);
+ $storeCode = $this->_storeManager->getStore($storeId)->getCode();
}
$item->setData('_first_store_id', $storeId);
$item->setData('store_ids', $result[$categoryId]);
+ $item->setData('store_code', $storeCode);
+ $item->setData('store_id', $result[$item->getData('category_id')]);
}
}
diff --git a/Model/ResourceModel/Category/Grid/Collection.php b/Model/ResourceModel/Category/Grid/Collection.php
new file mode 100644
index 00000000..bd9419ec
--- /dev/null
+++ b/Model/ResourceModel/Category/Grid/Collection.php
@@ -0,0 +1,147 @@
+_eventPrefix = $eventPrefix;
+ $this->_eventObject = $eventObject;
+ $this->_init($model, $resourceModel);
+ $this->setMainTable($mainTable);
+ }
+
+ /**
+ * @return AggregationInterface
+ */
+ public function getAggregations()
+ {
+ return $this->aggregations;
+ }
+
+ /**
+ * @param AggregationInterface $aggregations
+ * @return $this
+ */
+ public function setAggregations($aggregations)
+ {
+ $this->aggregations = $aggregations;
+ return $this;
+ }
+
+ /**
+ * Get search criteria.
+ *
+ * @return \Magento\Framework\Api\SearchCriteriaInterface|null
+ */
+ public function getSearchCriteria()
+ {
+ return null;
+ }
+
+ /**
+ * Set search criteria.
+ *
+ * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
+ * @return $this
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ */
+ public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null)
+ {
+ return $this;
+ }
+
+ /**
+ * Get total count.
+ *
+ * @return int
+ */
+ public function getTotalCount()
+ {
+ return $this->getSize();
+ }
+
+ /**
+ * Set total count.
+ *
+ * @param int $totalCount
+ * @return $this
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ */
+ public function setTotalCount($totalCount)
+ {
+ return $this;
+ }
+
+ /**
+ * Set items list.
+ *
+ * @param \Magento\Framework\Api\ExtensibleDataInterface[] $items
+ * @return $this
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ */
+ public function setItems(array $items = null)
+ {
+ return $this;
+ }
+}
diff --git a/Model/ResourceModel/Post/Collection.php b/Model/ResourceModel/Post/Collection.php
index 7d2019c6..8d7b7314 100755
--- a/Model/ResourceModel/Post/Collection.php
+++ b/Model/ResourceModel/Post/Collection.php
@@ -13,6 +13,32 @@
*/
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
+ /**
+ * @var string
+ */
+ protected $_idFieldName = 'post_id';
+
+ /**
+ * Load data for preview flag
+ *
+ * @var bool
+ */
+ protected $_previewFlag;
+
+ /**
+ * Event prefix
+ *
+ * @var string
+ */
+ protected $_eventPrefix = 'blog_post_collection';
+
+ /**
+ * Event object
+ *
+ * @var string
+ */
+ protected $_eventObject = 'post_collection';
+
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
@@ -458,11 +484,15 @@ protected function _afterLoad()
if ($result[$postId] == 0) {
$stores = $this->_storeManager->getStores(false, true);
$storeId = current($stores)->getId();
+ $storeCode = key($stores);
} else {
- $storeId = $result[$item->getData('post_id')];
+ $storeId = current($result[$item->getData('post_id')]);
+ $storeCode = $this->_storeManager->getStore($storeId)->getCode();
}
$item->setData('_first_store_id', $storeId);
$item->setData('store_ids', $result[$postId]);
+ $item->setData('store_code', $storeCode);
+ $item->setData('store_id', $result[$item->getData('post_id')]);
}
}
diff --git a/Model/ResourceModel/Post/Grid/Collection.php b/Model/ResourceModel/Post/Grid/Collection.php
new file mode 100644
index 00000000..6f594f07
--- /dev/null
+++ b/Model/ResourceModel/Post/Grid/Collection.php
@@ -0,0 +1,148 @@
+_eventPrefix = $eventPrefix;
+ $this->_eventObject = $eventObject;
+ $this->_init($model, $resourceModel);
+ $this->setMainTable($mainTable);
+ }
+
+ /**
+ * @return AggregationInterface
+ */
+ public function getAggregations()
+ {
+ return $this->aggregations;
+ }
+
+ /**
+ * @param AggregationInterface $aggregations
+ * @return $this
+ */
+ public function setAggregations($aggregations)
+ {
+ $this->aggregations = $aggregations;
+ return $this;
+ }
+
+ /**
+ * Get search criteria.
+ *
+ * @return \Magento\Framework\Api\SearchCriteriaInterface|null
+ */
+ public function getSearchCriteria()
+ {
+ return null;
+ }
+
+ /**
+ * Set search criteria.
+ *
+ * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
+ * @return $this
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ */
+ public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null)
+ {
+ return $this;
+ }
+
+ /**
+ * Get total count.
+ *
+ * @return int
+ */
+ public function getTotalCount()
+ {
+ return $this->getSize();
+ }
+
+ /**
+ * Set total count.
+ *
+ * @param int $totalCount
+ * @return $this
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ */
+ public function setTotalCount($totalCount)
+ {
+ return $this;
+ }
+
+ /**
+ * Set items list.
+ *
+ * @param \Magento\Framework\Api\ExtensibleDataInterface[] $items
+ * @return $this
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
+ */
+ public function setItems(array $items = null)
+ {
+ return $this;
+ }
+}
diff --git a/Model/ResourceModel/Tag/Collection.php b/Model/ResourceModel/Tag/Collection.php
index a5f0e62b..5ef04923 100755
--- a/Model/ResourceModel/Tag/Collection.php
+++ b/Model/ResourceModel/Tag/Collection.php
@@ -13,6 +13,10 @@
*/
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
+ /**
+ * @var string
+ */
+ protected $_idFieldName = 'tag_id';
/**
* Constructor
diff --git a/Ui/Component/Source/Listing/CategoryActions.php b/Ui/Component/Source/Listing/CategoryActions.php
new file mode 100644
index 00000000..d49b0e75
--- /dev/null
+++ b/Ui/Component/Source/Listing/CategoryActions.php
@@ -0,0 +1,105 @@
+urlBuilder = $urlBuilder;
+ parent::__construct($context, $uiComponentFactory, $components, $data);
+ $this->scopeUrlBuilder = $scopeUrlBuilder ?: ObjectManager::getInstance()
+ ->get(\Magento\Cms\ViewModel\Page\Grid\UrlBuilder::class);
+ }
+
+ /**
+ * Prepare Data Source for actions column on dynamic grid
+ *
+ * @param array $dataSource
+ * @return array
+ */
+ public function prepareDataSource(array $dataSource)
+ {
+ if (isset($dataSource['data']['items'])) {
+ $requestFieldName = $this->getContext()->getDataProvider()->getRequestFieldName();
+
+ foreach ($dataSource['data']['items'] as &$item) {
+ if (isset($item['category_id'])) {
+ $item[$this->getData('name')] = [
+ 'edit' => [
+ 'href' => $this->urlBuilder->getUrl(
+ static::URL_PATH_EDIT,
+ [$requestFieldName => $item['category_id']]
+ ),
+ 'label' => __('Edit')
+ ],
+ 'delete' => [
+ 'href' => $this->urlBuilder->getUrl(
+ static::URL_PATH_DELETE,
+ [$requestFieldName => $item['category_id']]
+ ),
+ 'label' => __('Delete')
+ ],
+ ];
+ }
+ if (isset($item['identifier'])) {
+ $item[$this->getData('name')]['preview'] = [
+ 'href' => $this->scopeUrlBuilder->getUrl('blog/category/'.
+ $item['identifier'],
+ isset($item['_first_store_id']) ? $item['_first_store_id'] : null,
+ isset($item['store_code']) ? $item['store_code'] : null
+ ),
+ 'label' => __('View'),
+ '__disableTmpl' => true,
+ ];
+ }
+ }
+ }
+ return $dataSource;
+ }
+}
diff --git a/Ui/Component/Source/Listing/Column/Author.php b/Ui/Component/Source/Listing/Column/Author.php
new file mode 100644
index 00000000..d2439b1b
--- /dev/null
+++ b/Ui/Component/Source/Listing/Column/Author.php
@@ -0,0 +1,66 @@
+authorRepository = $authorRepository;
+ }
+
+ /**
+ * Prepare Data Source for actions column on dynamic grid
+ *
+ * @param array $dataSource
+ * @return array
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
+ */
+ public function prepareDataSource(array $dataSource)
+ {
+ if (isset($dataSource['data']['items'])) {
+
+ foreach ($dataSource['data']['items'] as &$item) {
+ if (isset($item['author_id'])) {
+ $author = $this->authorRepository->getById($item['author_id']);
+ $item[$this->getData('name')] = [
+ $author->getFirstname() . ' ' . $author->getLastname()
+ ];
+ }
+ }
+ }
+ return $dataSource;
+ }
+}
diff --git a/Ui/Component/Source/Listing/Column/Category.php b/Ui/Component/Source/Listing/Column/Category.php
new file mode 100644
index 00000000..0f5e27f2
--- /dev/null
+++ b/Ui/Component/Source/Listing/Column/Category.php
@@ -0,0 +1,81 @@
+_resource = $resource;
+ }
+
+ /**
+ * Prepare Data Source for actions column on dynamic grid
+ *
+ * @param array $dataSource
+ * @return array
+ */
+ public function prepareDataSource(array $dataSource)
+ {
+ $connection = $this->_resource->getConnection();
+ $tableName = $this->_resource->getTableName('magefan_blog_category');
+
+ if (isset($dataSource['data']['items'])) {
+
+ foreach ($dataSource['data']['items'] as &$item) {
+ if (isset($item['categories'])) {
+ if (count($item['categories']) > 1) {
+ $select = $connection->select()
+ ->from($tableName, 'title')
+ ->where('category_id IN(?)', $item['categories']);
+ $item[$this->getData('name')] = [
+ implode(', ', $connection->fetchCol($select))
+ ];
+ } else {
+ foreach ($item['categories'] as $categoryId) {
+ $select = $connection->select()
+ ->from($tableName, 'title')
+ ->where('category_id = ?', $categoryId);
+ $item[$this->getData('name')] = [
+ $connection->fetchOne($select)
+ ];
+ }
+ }
+ }
+ }
+ }
+ return $dataSource;
+ }
+}
diff --git a/Ui/Component/Source/Listing/PostActions.php b/Ui/Component/Source/Listing/PostActions.php
new file mode 100644
index 00000000..75d901eb
--- /dev/null
+++ b/Ui/Component/Source/Listing/PostActions.php
@@ -0,0 +1,105 @@
+urlBuilder = $urlBuilder;
+ parent::__construct($context, $uiComponentFactory, $components, $data);
+ $this->scopeUrlBuilder = $scopeUrlBuilder ?: ObjectManager::getInstance()
+ ->get(\Magento\Cms\ViewModel\Page\Grid\UrlBuilder::class);
+ }
+
+ /**
+ * Prepare Data Source for actions column on dynamic grid
+ *
+ * @param array $dataSource
+ * @return array
+ */
+ public function prepareDataSource(array $dataSource)
+ {
+ if (isset($dataSource['data']['items'])) {
+ $requestFieldName = $this->getContext()->getDataProvider()->getRequestFieldName();
+
+ foreach ($dataSource['data']['items'] as &$item) {
+ if (isset($item['post_id'])) {
+ $item[$this->getData('name')] = [
+ 'edit' => [
+ 'href' => $this->urlBuilder->getUrl(
+ static::URL_PATH_EDIT,
+ [$requestFieldName => $item['post_id']]
+ ),
+ 'label' => __('Edit')
+ ],
+ 'delete' => [
+ 'href' => $this->urlBuilder->getUrl(
+ static::URL_PATH_DELETE,
+ [$requestFieldName => $item['post_id']]
+ ),
+ 'label' => __('Delete')
+ ],
+ ];
+ }
+ if (isset($item['identifier'])) {
+ $item[$this->getData('name')]['preview'] = [
+ 'href' => $this->scopeUrlBuilder->getUrl('blog/post/'.
+ $item['identifier'],
+ isset($item['_first_store_id']) ? $item['_first_store_id'] : null,
+ isset($item['store_code']) ? $item['store_code'] : null
+ ),
+ 'label' => __('View'),
+ '__disableTmpl' => true,
+ ];
+ }
+ }
+ }
+ return $dataSource;
+ }
+}
diff --git a/Ui/Component/Source/Listing/TagActions.php b/Ui/Component/Source/Listing/TagActions.php
new file mode 100644
index 00000000..e6ae31b2
--- /dev/null
+++ b/Ui/Component/Source/Listing/TagActions.php
@@ -0,0 +1,105 @@
+urlBuilder = $urlBuilder;
+ parent::__construct($context, $uiComponentFactory, $components, $data);
+ $this->scopeUrlBuilder = $scopeUrlBuilder ?: ObjectManager::getInstance()
+ ->get(\Magento\Cms\ViewModel\Page\Grid\UrlBuilder::class);
+ }
+
+ /**
+ * Prepare Data Source for actions column on dynamic grid
+ *
+ * @param array $dataSource
+ * @return array
+ */
+ public function prepareDataSource(array $dataSource)
+ {
+ if (isset($dataSource['data']['items'])) {
+ $requestFieldName = $this->getContext()->getDataProvider()->getRequestFieldName();
+
+ foreach ($dataSource['data']['items'] as &$item) {
+ if (isset($item['tag_id'])) {
+ $item[$this->getData('name')] = [
+ 'edit' => [
+ 'href' => $this->urlBuilder->getUrl(
+ static::URL_PATH_EDIT,
+ [$requestFieldName => $item['tag_id']]
+ ),
+ 'label' => __('Edit')
+ ],
+ 'delete' => [
+ 'href' => $this->urlBuilder->getUrl(
+ static::URL_PATH_DELETE,
+ [$requestFieldName => $item['tag_id']]
+ ),
+ 'label' => __('Delete')
+ ],
+ ];
+ }
+ if (isset($item['identifier'])) {
+ $item[$this->getData('name')]['preview'] = [
+ 'href' => $this->scopeUrlBuilder->getUrl('blog/tag/'.
+ $item['identifier'],
+ isset($item['_first_store_id']) ? $item['_first_store_id'] : null,
+ isset($item['store_code']) ? $item['store_code'] : null
+ ),
+ 'label' => __('View'),
+ '__disableTmpl' => true,
+ ];
+ }
+ }
+ }
+ return $dataSource;
+ }
+}
diff --git a/Ui/Component/Source/Status.php b/Ui/Component/Source/Status.php
new file mode 100644
index 00000000..0cb8b452
--- /dev/null
+++ b/Ui/Component/Source/Status.php
@@ -0,0 +1,43 @@
+ __('Disabled'),
+ 'value' => self::STATUS_INACTIVE,
+ ],
+ [
+ 'label' => __('Enabled'),
+ 'value' => self::STATUS_ACTIVE,
+ ],
+ ];
+
+ return $options;
+ }
+}
diff --git a/etc/di.xml b/etc/di.xml
index 470490da..d7b3359f 100755
--- a/etc/di.xml
+++ b/etc/di.xml
@@ -84,4 +84,50 @@
Magefan\Blog\Api\AuthorRepositoryInterface
+
+
+
+
+ - Magefan\Blog\Model\ResourceModel\Post\Grid\Collection
+
+
+
+
+
+ magefan_blog_post
+ magefan_blog_post_grid_collection
+ blog_post_grid_collection
+ Magefan\Blog\Model\ResourceModel\Post
+
+
+
+
+
+
+ - Magefan\Blog\Model\ResourceModel\Category\Grid\Collection
+
+
+
+
+
+ magefan_blog_category
+ magefan_blog_category_grid_collection
+ blog_category_grid_collection
+ Magefan\Blog\Model\ResourceModel\Category
+
+
+
+
+
+ magefan_blog_tag
+ Magefan\Blog\Model\ResourceModel\Tag
+
+
+
+
+
+ - Magefan\Blog\Model\ResourceModel\Tag\Grid\Collection
+
+
+
diff --git a/view/adminhtml/layout/blog_category_index.xml b/view/adminhtml/layout/blog_category_index.xml
index 26897902..8aa073d8 100755
--- a/view/adminhtml/layout/blog_category_index.xml
+++ b/view/adminhtml/layout/blog_category_index.xml
@@ -7,7 +7,7 @@
* Glory to Ukraine! Glory to the heroes!
*/
-->
-
+
+
+
+
+
+
+
diff --git a/view/adminhtml/layout/blog_post_index.xml b/view/adminhtml/layout/blog_post_index.xml
index f77c0485..3b095b1b 100755
--- a/view/adminhtml/layout/blog_post_index.xml
+++ b/view/adminhtml/layout/blog_post_index.xml
@@ -7,7 +7,7 @@
* Glory to Ukraine! Glory to the heroes!
*/
-->
-
+
+
+
+
+
+
+
diff --git a/view/adminhtml/layout/blog_tag_index.xml b/view/adminhtml/layout/blog_tag_index.xml
index b79579c4..42d0d1b9 100755
--- a/view/adminhtml/layout/blog_tag_index.xml
+++ b/view/adminhtml/layout/blog_tag_index.xml
@@ -7,7 +7,7 @@
* Glory to Ukraine! Glory to the heroes!
*/
-->
-
+
+
+
+
+
+
+
diff --git a/view/adminhtml/ui_component/blog_category_listing.xml b/view/adminhtml/ui_component/blog_category_listing.xml
new file mode 100644
index 00000000..19c72a17
--- /dev/null
+++ b/view/adminhtml/ui_component/blog_category_listing.xml
@@ -0,0 +1,191 @@
+
+
+
+
+ -
+
- blog_category_listing.blog_category_listing_data_source
+
+
+
+
+
+
+
+ category_columns
+
+ blog_category_listing.blog_category_listing_data_source
+
+
+
+
+
+ category_id
+
+
+
+ Magefan_Blog::category
+
+
+ id
+ category_id
+
+
+
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+ store_id
+
+ componentType = column, index = ${ $.index }:visible
+
+
+
+
+
+
+
+
+ enable
+
+
+
+
+
+
+ disable
+
+
+
+
+
+
+ Are you sure you want to delete selected items?
+ Delete items
+
+
+ delete
+
+
+
+
+
+
+
+
+
+
+ - false
+
+ category_id
+ true
+ blog_category_listing.blog_category_listing.category_columns.ids
+
+
+
+ - blog_category_listing.blog_category_listing.category_columns_editor
+ - startEdit
+ -
+
- ${ $.$data.rowIndex }
+ - true
+
+
+
+
+
+
+ category_id
+
+
+
+
+ textRange
+
+ desc
+
+
+
+
+ text
+
+
+ true
+
+ text
+
+
+
+
+
+
+ text
+
+
+ true
+
+ text
+
+
+
+
+
+
+
+ ui/grid/cells/html
+ false
+
+
+
+
+
+ select
+
+ select
+
+ select
+
+
+
+
+
+ category_id
+
+
+
+
diff --git a/view/adminhtml/ui_component/blog_post_listing.xml b/view/adminhtml/ui_component/blog_post_listing.xml
new file mode 100644
index 00000000..cd09e858
--- /dev/null
+++ b/view/adminhtml/ui_component/blog_post_listing.xml
@@ -0,0 +1,219 @@
+
+
+
+
+ -
+
- blog_post_listing.blog_post_listing_data_source
+
+
+
+
+
+
+
+ post_columns
+
+ blog_post_listing.blog_post_listing_data_source
+
+
+
+
+
+ post_id
+
+
+
+ Magefan_Blog::post
+
+
+ id
+ post_id
+
+
+
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+ store_id
+
+ componentType = column, index = ${ $.index }:visible
+
+
+
+
+
+
+
+
+ enable
+
+
+
+
+
+
+ disable
+
+
+
+
+
+
+ Are you sure you want to delete selected items?
+ Delete items
+
+
+ delete
+
+
+
+
+
+
+
+
+
+
+ - false
+
+ post_id
+ true
+ blog_post_listing.blog_post_listing.post_columns.ids
+
+
+
+ - blog_post_listing.blog_post_listing.post_columns_editor
+ - startEdit
+ -
+
- ${ $.$data.rowIndex }
+ - true
+
+
+
+
+
+
+ post_id
+
+
+
+
+ textRange
+
+ asc
+
+
+
+
+ text
+
+
+ true
+
+ text
+
+
+
+
+
+
+ text
+
+
+ true
+
+ text
+
+
+
+
+
+
+
+ ui/grid/cells/html
+ false
+
+
+
+
+
+ ui/grid/cells/html
+ false
+
+
+
+
+
+ ui/grid/cells/html
+ false
+
+
+
+
+ dateRange
+ date
+
+
+
+
+
+ dateRange
+ date
+
+
+
+
+
+
+ select
+
+ select
+
+ select
+
+
+
+
+
+ post_id
+
+
+
+
diff --git a/view/adminhtml/ui_component/blog_tag_listing.xml b/view/adminhtml/ui_component/blog_tag_listing.xml
new file mode 100644
index 00000000..234d0544
--- /dev/null
+++ b/view/adminhtml/ui_component/blog_tag_listing.xml
@@ -0,0 +1,173 @@
+
+
+
+
+ -
+
- blog_tag_listing.blog_tag_listing_data_source
+
+
+
+
+
+
+
+ tag_columns
+
+ blog_tag_listing.blog_tag_listing_data_source
+
+
+
+
+
+ tag_id
+
+
+
+ Magefan_Blog::tag
+
+
+ id
+ tag_id
+
+
+
+
+
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ enable
+
+
+
+
+
+
+ disable
+
+
+
+
+
+
+ Are you sure you want to delete selected items?
+ Delete items
+
+
+ delete
+
+
+
+
+
+
+
+
+
+
+ - false
+
+ tag_id
+ true
+ blog_tag_listing.blog_tag_listing.tag_columns.ids
+
+
+
+ - blog_tag_listing.blog_tag_listing.tag_columns_editor
+ - startEdit
+ -
+
- ${ $.$data.rowIndex }
+ - true
+
+
+
+
+
+
+ tag_id
+
+
+
+
+ textRange
+
+ desc
+
+
+
+
+ text
+
+
+ true
+
+ text
+
+
+
+
+
+
+ text
+
+
+ true
+
+ text
+
+
+
+
+
+
+
+ select
+
+ select
+
+ select
+
+
+
+
+
+ tag_id
+
+
+
+