diff --git a/Block/Adminhtml/Category.php b/Block/Adminhtml/Category.php index ce34b424..d60708f7 100755 --- a/Block/Adminhtml/Category.php +++ b/Block/Adminhtml/Category.php @@ -2,32 +2,32 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml; class Category extends \Magento\Backend\Block\Widget\Grid\Container { - /** - * constructor - * - * @return void - */ - protected function _construct() - { - $this->_controller = 'adminhtml_category'; - $this->_blockGroup = 'Mageplaza_Blog'; - $this->_headerText = __('Categories'); - $this->_addButtonLabel = __('Create New Category'); - parent::_construct(); - } + /** + * constructor + * + * @return void + */ + protected function _construct() + { + $this->_controller = 'adminhtml_category'; + $this->_blockGroup = 'Mageplaza_Blog'; + $this->_headerText = __('Categories'); + $this->_addButtonLabel = __('Create New Category'); + parent::_construct(); + } } diff --git a/Block/Adminhtml/Category/AbstractCategory.php b/Block/Adminhtml/Category/AbstractCategory.php index 4792932e..759605a9 100755 --- a/Block/Adminhtml/Category/AbstractCategory.php +++ b/Block/Adminhtml/Category/AbstractCategory.php @@ -2,250 +2,244 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Category; class AbstractCategory extends \Magento\Backend\Block\Template { - /** - * Core registry - * - * @var \Magento\Framework\Registry - */ - protected $coreRegistry; - - /** - * Category tree model instance - * - * @var \Mageplaza\Blog\Model\ResourceModel\Category\Tree - */ - protected $categoryTree; - - /** - * Category factory - * - * @var \Mageplaza\Blog\Model\CategoryFactory - */ - protected $categoryFactory; - - /** - * Category collection factory - * - * @var \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory - */ - protected $categoryCollectionFactory; - - /** - * constructor - * - * @param \Magento\Framework\Registry $coreRegistry - * @param \Mageplaza\Blog\Model\ResourceModel\Category\Tree $categoryTree - * @param \Mageplaza\Blog\Model\CategoryFactory $categoryFactory - * @param \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory - * @param \Magento\Backend\Block\Widget\Context $context - * @param array $data - */ - public function __construct( - \Magento\Framework\Registry $coreRegistry, - \Mageplaza\Blog\Model\ResourceModel\Category\Tree $categoryTree, - \Mageplaza\Blog\Model\CategoryFactory $categoryFactory, - \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory, - \Magento\Backend\Block\Widget\Context $context, - array $data = [] - ) - { - $this->coreRegistry = $coreRegistry; - $this->categoryTree = $categoryTree; - $this->categoryFactory = $categoryFactory; - $this->categoryCollectionFactory = $categoryCollectionFactory; - parent::__construct($context, $data); - } - - /** - * Retrieve current Category instance - * - * @return \Mageplaza\Blog\Model\Category - */ - public function getCategory() - { - return $this->coreRegistry->registry('mageplaza_blog_category'); - } - - /** - * @return int|string|null - */ - public function getCategoryId() - { - if ($this->getCategory()) { - return $this->getCategory()->getId(); - } - - return \Mageplaza\Blog\Model\Category::TREE_ROOT_ID; - } - - /** - * @return string - */ - public function getCategoryName() - { - return $this->getCategory()->getName(); - } - - /** - * @return mixed - */ - public function getCategoryPath() - { - if ($this->getCategory()) { - return $this->getCategory()->getPath(); - } - - return \Mageplaza\Blog\Model\Category::TREE_ROOT_ID; - } - - - /** - * @param null $parentNodeCategory - * @param int $recursionLevel - * @return Node|mixed - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - */ - public function getRoot($parentNodeCategory = null, $recursionLevel = 3) - { - if ($parentNodeCategory !== null && $parentNodeCategory->getId()) { - return $this->getNode($parentNodeCategory, $recursionLevel); - } - $root = $this->coreRegistry->registry('mageplaza_blog_category_root'); - if ($root === null) { - $rootId = \Mageplaza\Blog\Model\Category::TREE_ROOT_ID; - - $tree = $this->categoryTree->load(null, $recursionLevel); - - if ($this->getCategory()) { - $tree->loadEnsuredNodes($this->getCategory(), $tree->getNodeById($rootId)); - } - - $tree->addCollectionData($this->getCategoryCollection()); - - $root = $tree->getNodeById($rootId); - - if ($root && $rootId != \Mageplaza\Blog\Model\Category::TREE_ROOT_ID) { - $root->setIsVisible(true); - } elseif ($root && $root->getId() == \Mageplaza\Blog\Model\Category::TREE_ROOT_ID) { - $root->setName(__('ROOT')); - } - - $this->coreRegistry->register('mageplaza_blog_category_root', $root); - } - - return $root; - } - - /** - * @return \Mageplaza\Blog\Model\ResourceModel\Category\Collection - */ - public function getCategoryCollection() - { - $collection = $this->getData('category_collection'); - if ($collection === null) { - $collection = $this->categoryCollectionFactory->create(); - $this->setData('category_collection', $collection); - } - - return $collection; - } - - /** - * Get and register Categories root by specified Categories IDs - * - * IDs can be arbitrary set of any Categories ids. - * Tree with minimal required nodes (all parents and neighbours) will be built. - * If ids are empty, default tree with depth = 2 will be returned. - * - * @param array $ids - * @return mixed - */ - public function getRootByIds($ids) - { - $root = $this->coreRegistry->registry('mageplaza_blog_category_root'); - if (null === $root) { - $ids = $this->categoryTree->getExistingCategoryIdsBySpecifiedIds($ids); - $tree = $this->categoryTree->loadByIds($ids); - $rootId = \Mageplaza\Blog\Model\Category::TREE_ROOT_ID; - $root = $tree->getNodeById($rootId); - if ($root && $rootId != \Mageplaza\Blog\Model\Category::TREE_ROOT_ID) { - $root->setIsVisible(true); - } elseif ($root && $root->getId() == \Mageplaza\Blog\Model\Category::TREE_ROOT_ID) { - $root->setName(__('Root')); - } - - $tree->addCollectionData($this->getCategoryCollection()); - $this->coreRegistry->register('mageplaza_blog_category_root', $root); - } - - return $root; - } - - /** - * @param $parentNodeCategory - * @param int $recursionLevel - * @return Node - */ - public function getNode($parentNodeCategory, $recursionLevel = 2) - { - $nodeId = $parentNodeCategory->getId(); - $node = $this->categoryTree->loadNode($nodeId); - $node->loadChildren($recursionLevel); - - if ($node && $nodeId != \Mageplaza\Blog\Model\Category::TREE_ROOT_ID) { - $node->setIsVisible(true); - } elseif ($node && $node->getId() == \Mageplaza\Blog\Model\Category::TREE_ROOT_ID) { - $node->setName(__('Root')); - } - - $this->categoryTree->addCollectionData($this->getCategoryCollection()); - - return $node; - } - - /** - * @param array $args - * @return string - */ - public function getSaveUrl(array $args = []) - { - $params = ['_current' => false, '_query' => false]; - $params = array_merge($params, $args); - - return $this->getUrl('mageplaza_blog/*/save', $params); - } - - /** - * @return string - */ - public function getEditUrl() - { - return $this->getUrl( - 'mageplaza_blog/category/edit', - ['_query' => false, 'id' => null, 'parent' => null] - ); - } - - /** - * @return [] - */ - public function getRootIds() - { - return [\Mageplaza\Blog\Model\Category::TREE_ROOT_ID]; - } + /** + * Core registry + * + * @var \Magento\Framework\Registry + */ + protected $coreRegistry; + + /** + * Category tree model instance + * + * @var \Mageplaza\Blog\Model\ResourceModel\Category\Tree + */ + protected $categoryTree; + + /** + * Category factory + * + * @var \Mageplaza\Blog\Model\CategoryFactory + */ + protected $categoryFactory; + + /** + * Category collection factory + * + * @var \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory + */ + protected $categoryCollectionFactory; + + /** + * constructor + * + * @param \Magento\Framework\Registry $coreRegistry + * @param \Mageplaza\Blog\Model\ResourceModel\Category\Tree $categoryTree + * @param \Mageplaza\Blog\Model\CategoryFactory $categoryFactory + * @param \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory + * @param \Magento\Backend\Block\Widget\Context $context + * @param array $data + */ + public function __construct( + \Magento\Framework\Registry $coreRegistry, + \Mageplaza\Blog\Model\ResourceModel\Category\Tree $categoryTree, + \Mageplaza\Blog\Model\CategoryFactory $categoryFactory, + \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory, + \Magento\Backend\Block\Widget\Context $context, + array $data = [] + ) + { + $this->coreRegistry = $coreRegistry; + $this->categoryTree = $categoryTree; + $this->categoryFactory = $categoryFactory; + $this->categoryCollectionFactory = $categoryCollectionFactory; + parent::__construct($context, $data); + } + + /** + * Retrieve current Category instance + * + * @return \Mageplaza\Blog\Model\Category + */ + public function getCategory() + { + return $this->coreRegistry->registry('mageplaza_blog_category'); + } + + /** + * @return int|string|null + */ + public function getCategoryId() + { + if ($this->getCategory()) { + return $this->getCategory()->getId(); + } + return \Mageplaza\Blog\Model\Category::TREE_ROOT_ID; + } + + /** + * @return string + */ + public function getCategoryName() + { + return $this->getCategory()->getName(); + } + + /** + * @return mixed + */ + public function getCategoryPath() + { + if ($this->getCategory()) { + return $this->getCategory()->getPath(); + } + return \Mageplaza\Blog\Model\Category::TREE_ROOT_ID; + } + + + /** + * @param null $parentNodeCategory + * @param int $recursionLevel + * @return Node|mixed + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + */ + public function getRoot($parentNodeCategory = null, $recursionLevel = 3) + { + if ($parentNodeCategory !== null && $parentNodeCategory->getId()) { + return $this->getNode($parentNodeCategory, $recursionLevel); + } + $root = $this->coreRegistry->registry('mageplaza_blog_category_root'); + if ($root === null) { + $rootId = \Mageplaza\Blog\Model\Category::TREE_ROOT_ID; + + $tree = $this->categoryTree->load(null, $recursionLevel); + + if ($this->getCategory()) { + $tree->loadEnsuredNodes($this->getCategory(), $tree->getNodeById($rootId)); + } + + $tree->addCollectionData($this->getCategoryCollection()); + + $root = $tree->getNodeById($rootId); + + if ($root && $rootId != \Mageplaza\Blog\Model\Category::TREE_ROOT_ID) { + $root->setIsVisible(true); + } elseif ($root && $root->getId() == \Mageplaza\Blog\Model\Category::TREE_ROOT_ID) { + $root->setName(__('ROOT')); + } + + $this->coreRegistry->register('mageplaza_blog_category_root', $root); + } + + return $root; + } + + /** + * @return \Mageplaza\Blog\Model\ResourceModel\Category\Collection + */ + public function getCategoryCollection() + { + $collection = $this->getData('category_collection'); + if ($collection === null) { + $collection = $this->categoryCollectionFactory->create(); + $this->setData('category_collection', $collection); + } + return $collection; + } + + /** + * Get and register Categories root by specified Categories IDs + * + * IDs can be arbitrary set of any Categories ids. + * Tree with minimal required nodes (all parents and neighbours) will be built. + * If ids are empty, default tree with depth = 2 will be returned. + * + * @param array $ids + * @return mixed + */ + public function getRootByIds($ids) + { + $root = $this->coreRegistry->registry('mageplaza_blog_category_root'); + if (null === $root) { + $ids = $this->categoryTree->getExistingCategoryIdsBySpecifiedIds($ids); + $tree = $this->categoryTree->loadByIds($ids); + $rootId = \Mageplaza\Blog\Model\Category::TREE_ROOT_ID; + $root = $tree->getNodeById($rootId); + if ($root && $rootId != \Mageplaza\Blog\Model\Category::TREE_ROOT_ID) { + $root->setIsVisible(true); + } elseif ($root && $root->getId() == \Mageplaza\Blog\Model\Category::TREE_ROOT_ID) { + $root->setName(__('Root')); + } + + $tree->addCollectionData($this->getCategoryCollection()); + $this->coreRegistry->register('mageplaza_blog_category_root', $root); + } + return $root; + } + + /** + * @param $parentNodeCategory + * @param int $recursionLevel + * @return Node + */ + public function getNode($parentNodeCategory, $recursionLevel = 2) + { + $nodeId = $parentNodeCategory->getId(); + $node = $this->categoryTree->loadNode($nodeId); + $node->loadChildren($recursionLevel); + + if ($node && $nodeId != \Mageplaza\Blog\Model\Category::TREE_ROOT_ID) { + $node->setIsVisible(true); + } elseif ($node && $node->getId() == \Mageplaza\Blog\Model\Category::TREE_ROOT_ID) { + $node->setName(__('Root')); + } + + $this->categoryTree->addCollectionData($this->getCategoryCollection()); + + return $node; + } + + /** + * @param array $args + * @return string + */ + public function getSaveUrl(array $args = []) + { + $params = ['_current' => false, '_query' => false]; + $params = array_merge($params, $args); + return $this->getUrl('mageplaza_blog/*/save', $params); + } + + /** + * @return string + */ + public function getEditUrl() + { + return $this->getUrl( + 'mageplaza_blog/category/edit', + ['_query' => false, 'id' => null, 'parent' => null] + ); + } + /** + * @return [] + */ + public function getRootIds() + { + return [\Mageplaza\Blog\Model\Category::TREE_ROOT_ID]; + } } diff --git a/Block/Adminhtml/Category/Edit.php b/Block/Adminhtml/Category/Edit.php index 5bd1004f..55f55dbb 100755 --- a/Block/Adminhtml/Category/Edit.php +++ b/Block/Adminhtml/Category/Edit.php @@ -2,34 +2,34 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Category; class Edit extends \Magento\Backend\Block\Widget\Form\Container { - /** - * prepare the form - */ - protected function _construct() - { - $this->_objectId = 'category_id'; - $this->_blockGroup = 'Mageplaza_Blog'; - $this->_controller = 'adminhtml_category'; - $this->_mode = 'edit'; - parent::_construct(); - $this->buttonList->remove('back'); - $this->buttonList->remove('reset'); - $this->buttonList->remove('save'); - } + /** + * prepare the form + */ + protected function _construct() + { + $this->_objectId = 'category_id'; + $this->_blockGroup = 'Mageplaza_Blog'; + $this->_controller = 'adminhtml_category'; + $this->_mode = 'edit'; + parent::_construct(); + $this->buttonList->remove('back'); + $this->buttonList->remove('reset'); + $this->buttonList->remove('save'); + } } diff --git a/Block/Adminhtml/Category/Edit/Form.php b/Block/Adminhtml/Category/Edit/Form.php index 1a63cd46..d6a4a0fa 100755 --- a/Block/Adminhtml/Category/Edit/Form.php +++ b/Block/Adminhtml/Category/Edit/Form.php @@ -2,319 +2,314 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Category\Edit; class Form extends \Mageplaza\Blog\Block\Adminhtml\Category\AbstractCategory { - /** - * Additional buttons - * - * @var array - */ - protected $additionalButtons = []; + /** + * Additional buttons + * + * @var array + */ + protected $additionalButtons = []; - /** - * Block template - * - * @var string - */ - protected $_template = 'category/edit/form.phtml'; + /** + * Block template + * + * @var string + */ + protected $_template = 'category/edit/form.phtml'; - /** - * JSON encoder - * - * @var \Magento\Framework\Json\EncoderInterface - */ - protected $jsonEncoder; + /** + * JSON encoder + * + * @var \Magento\Framework\Json\EncoderInterface + */ + protected $jsonEncoder; - /** - * constructor - * - * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder - * @param \Magento\Framework\Registry $registry - * @param \Mageplaza\Blog\Model\ResourceModel\Category\Tree $categoryTree - * @param \Mageplaza\Blog\Model\CategoryFactory $categoryFactory - * @param \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory - * @param \Magento\Backend\Block\Widget\Context $context - * @param array $data - */ - public function __construct( - \Magento\Framework\Json\EncoderInterface $jsonEncoder, - \Magento\Framework\Registry $registry, - \Mageplaza\Blog\Model\ResourceModel\Category\Tree $categoryTree, - \Mageplaza\Blog\Model\CategoryFactory $categoryFactory, - \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory, - \Magento\Backend\Block\Widget\Context $context, - array $data = [] - ) - { - $this->jsonEncoder = $jsonEncoder; - parent::__construct($registry, $categoryTree, $categoryFactory, $categoryCollectionFactory, $context, $data); - } + /** + * constructor + * + * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder + * @param \Magento\Framework\Registry $registry + * @param \Mageplaza\Blog\Model\ResourceModel\Category\Tree $categoryTree + * @param \Mageplaza\Blog\Model\CategoryFactory $categoryFactory + * @param \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory + * @param \Magento\Backend\Block\Widget\Context $context + * @param array $data + */ + public function __construct( + \Magento\Framework\Json\EncoderInterface $jsonEncoder, + \Magento\Framework\Registry $registry, + \Mageplaza\Blog\Model\ResourceModel\Category\Tree $categoryTree, + \Mageplaza\Blog\Model\CategoryFactory $categoryFactory, + \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory, + \Magento\Backend\Block\Widget\Context $context, + array $data = [] + ) + { + $this->jsonEncoder = $jsonEncoder; + parent::__construct($registry, $categoryTree, $categoryFactory, $categoryCollectionFactory, $context, $data); + } - /** - * @return $this - */ - protected function _prepareLayout() - { - $category = $this->getCategory(); - $categoryId = (int)$category->getId(); - // 0 when we create Category, otherwise some value for editing Category + /** + * @return $this + */ + protected function _prepareLayout() + { + $category = $this->getCategory(); + $categoryId = (int)$category->getId(); + // 0 when we create Category, otherwise some value for editing Category - $this->setChild( - 'tabs', - $this->getLayout()->createBlock('Mageplaza\Blog\Block\Adminhtml\Category\Edit\Tabs', 'tabs') - ); + $this->setChild( + 'tabs', + $this->getLayout()->createBlock('Mageplaza\Blog\Block\Adminhtml\Category\Edit\Tabs', 'tabs') + ); - // Save button - $this->addButton( - 'save', - [ - 'id' => 'save', - 'label' => __('Save Category'), - 'class' => 'save primary save-category', - 'data_attribute' => [ - 'mage-init' => [ - 'Mageplaza_Blog/category/edit' => [ - 'url' => $this->getSaveUrl(), - 'ajax' => true - ] - ] - ] - ] - ); + // Save button + $this->addButton( + 'save', + [ + 'id' => 'save', + 'label' => __('Save Category'), + 'class' => 'save primary save-category', + 'data_attribute' => [ + 'mage-init' => [ + 'Mageplaza_Blog/category/edit' => [ + 'url' => $this->getSaveUrl(), + 'ajax' => true + ] + ] + ] + ] + ); - // Delete button - if ($categoryId && !in_array($categoryId, $this->getRootIds())) { - $this->addButton( - 'delete', - [ - 'id' => 'delete', - 'label' => __('Delete Category'), - 'onclick' => "categoryDelete('" . $this->getUrl( - 'mageplaza_blog/*/delete', - ['_current' => true] - ) . "')", - 'class' => 'delete' - ] - ); - } + // Delete button + if ($categoryId && !in_array($categoryId, $this->getRootIds())) { + $this->addButton( + 'delete', + [ + 'id' => 'delete', + 'label' => __('Delete Category'), + 'onclick' => "categoryDelete('" . $this->getUrl( + 'mageplaza_blog/*/delete', + ['_current' => true] + ) . "')", + 'class' => 'delete' + ] + ); + } - // Reset button - $resetPath = $categoryId ? 'mageplaza_blog/*/edit' : 'mageplaza_blog/*/add'; - $this->addButton( - 'reset', - [ - 'id' => 'reset', - 'label' => __('Reset'), - 'onclick' => "categoryReset('" . $this->getUrl($resetPath, ['_current' => true]) . "',false)", - 'class' => 'reset' - ] - ); + // Reset button + $resetPath = $categoryId ? 'mageplaza_blog/*/edit' : 'mageplaza_blog/*/add'; + $this->addButton( + 'reset', + [ + 'id' => 'reset', + 'label' => __('Reset'), + 'onclick' => "categoryReset('" . $this->getUrl($resetPath, ['_current' => true]) . "',false)", + 'class' => 'reset' + ] + ); - return parent::_prepareLayout(); - } + return parent::_prepareLayout(); + } - /** - * Retrieve additional buttons html - * - * @return string - */ - public function getAdditionalButtonsHtml() - { - $html = ''; - foreach ($this->additionalButtons as $childName) { - $html .= $this->getChildHtml($childName); - } + /** + * Retrieve additional buttons html + * + * @return string + */ + public function getAdditionalButtonsHtml() + { + $html = ''; + foreach ($this->additionalButtons as $childName) { + $html .= $this->getChildHtml($childName); + } + return $html; + } - return $html; - } + /** + * Add additional button + * + * @param string $alias + * @param array $config + * @return $this + */ + public function addAdditionalButton($alias, $config) + { + if (isset($config['name'])) { + $config['element_name'] = $config['name']; + } + if ($this->hasToolbarBlock()) { + $this->addButton($alias, $config); + } else { + $this->setChild( + $alias . '_button', + $this->getLayout()->createBlock('Magento\Backend\Block\Widget\Button')->addData($config) + ); + $this->additionalButtons[$alias] = $alias . '_button'; + } - /** - * Add additional button - * - * @param string $alias - * @param array $config - * @return $this - */ - public function addAdditionalButton($alias, $config) - { - if (isset($config['name'])) { - $config['element_name'] = $config['name']; - } - if ($this->hasToolbarBlock()) { - $this->addButton($alias, $config); - } else { - $this->setChild( - $alias . '_button', - $this->getLayout()->createBlock('Magento\Backend\Block\Widget\Button')->addData($config) - ); - $this->additionalButtons[$alias] = $alias . '_button'; - } + return $this; + } - return $this; - } + /** + * Remove additional button + * + * @param string $alias + * @return $this + */ + public function removeAdditionalButton($alias) + { + if (isset($this->additionalButtons[$alias])) { + $this->unsetChild($this->additionalButtons[$alias]); + unset($this->additionalButtons[$alias]); + } - /** - * Remove additional button - * - * @param string $alias - * @return $this - */ - public function removeAdditionalButton($alias) - { - if (isset($this->additionalButtons[$alias])) { - $this->unsetChild($this->additionalButtons[$alias]); - unset($this->additionalButtons[$alias]); - } + return $this; + } - return $this; - } + /** + * @return string + */ + public function getTabsHtml() + { + return $this->getChildHtml('tabs'); + } - /** - * @return string - */ - public function getTabsHtml() - { - return $this->getChildHtml('tabs'); - } + /** + * @return \Magento\Framework\Phrase|string + */ + public function getHeader() + { + if ($this->getCategoryId()) { + return $this->getCategoryName(); + } else { + $parentId = (int)$this->getRequest()->getParam('parent'); + if ($parentId && $parentId != \Mageplaza\Blog\Model\Category::TREE_ROOT_ID) { + return __('New Child Category'); + } else { + return __('New Root Category'); + } + } + } - /** - * @return \Magento\Framework\Phrase|string - */ - public function getHeader() - { - if ($this->getCategoryId()) { - return $this->getCategoryName(); - } else { - $parentId = (int)$this->getRequest()->getParam('parent'); - if ($parentId && $parentId != \Mageplaza\Blog\Model\Category::TREE_ROOT_ID) { - return __('New Child Category'); - } else { - return __('New Root Category'); - } - } - } + /** + * @param array $args + * @return string + */ + public function getDeleteUrl(array $args = []) + { + $params = ['_current' => true]; + $params = array_merge($params, $args); + return $this->getUrl('mageplaza_blog/*/delete', $params); + } - /** - * @param array $args - * @return string - */ - public function getDeleteUrl(array $args = []) - { - $params = ['_current' => true]; - $params = array_merge($params, $args); + /** + * Return URL for refresh input element 'path' in form + * + * @param array $args + * @return string + */ + public function getRefreshPathUrl(array $args = []) + { + $params = ['_current' => true]; + $params = array_merge($params, $args); + return $this->getUrl('mageplaza_blog/*/refreshPath', $params); + } - return $this->getUrl('mageplaza_blog/*/delete', $params); - } + /** + * @return bool + */ + public function isAjax() + { + return $this->_request->isXmlHttpRequest() || $this->_request->getParam('isAjax'); + } - /** - * Return URL for refresh input element 'path' in form - * - * @param array $args - * @return string - */ - public function getRefreshPathUrl(array $args = []) - { - $params = ['_current' => true]; - $params = array_merge($params, $args); + /** + * Get parent Category id + * + * @return int + */ + public function getParentCategoryId() + { + return (int)$this->templateContext->getRequest()->getParam('parent'); + } - return $this->getUrl('mageplaza_blog/*/refreshPath', $params); - } + /** + * Get Category id + * + * @return int + */ + public function getCategoryId() + { + return (int)$this->templateContext->getRequest()->getParam('category_id'); + } - /** - * @return bool - */ - public function isAjax() - { - return $this->_request->isXmlHttpRequest() || $this->_request->getParam('isAjax'); - } + /** + * Add button block as a child block or to global Page Toolbar block if available + * + * @param string $buttonId + * @param array $data + * @return $this + */ + protected function addButton($buttonId, array $data) + { + $childBlockId = $buttonId . '_button'; + $button = $this->getButtonChildBlock($childBlockId); + $button->setData($data); + $block = $this->getLayout()->getBlock('page.actions.toolbar'); + if ($block) { + $block->setChild($childBlockId, $button); + } else { + $this->setChild($childBlockId, $button); + } + } - /** - * Get parent Category id - * - * @return int - */ - public function getParentCategoryId() - { - return (int)$this->templateContext->getRequest()->getParam('parent'); - } + /** + * @return bool + */ + protected function hasToolbarBlock() + { + return $this->getLayout()->isBlock('page.actions.toolbar'); + } - /** - * Get Category id - * - * @return int - */ - public function getCategoryId() - { - return (int)$this->templateContext->getRequest()->getParam('category_id'); - } + /** + * Adding child block with specified child's id. + * + * @param string $childId + * @param null|string $blockClassName + * @return \Magento\Backend\Block\Widget + */ + protected function getButtonChildBlock($childId, $blockClassName = null) + { + if (null === $blockClassName) { + $blockClassName = 'Magento\Backend\Block\Widget\Button'; + } + return $this->getLayout()->createBlock($blockClassName, $this->getNameInLayout() . '-' . $childId); + } - /** - * Add button block as a child block or to global Page Toolbar block if available - * - * @param string $buttonId - * @param array $data - * @return $this - */ - protected function addButton($buttonId, array $data) - { - $childBlockId = $buttonId . '_button'; - $button = $this->getButtonChildBlock($childBlockId); - $button->setData($data); - $block = $this->getLayout()->getBlock('page.actions.toolbar'); - if ($block) { - $block->setChild($childBlockId, $button); - } else { - $this->setChild($childBlockId, $button); - } - } - - /** - * @return bool - */ - protected function hasToolbarBlock() - { - return $this->getLayout()->isBlock('page.actions.toolbar'); - } - - /** - * Adding child block with specified child's id. - * - * @param string $childId - * @param null|string $blockClassName - * @return \Magento\Backend\Block\Widget - */ - protected function getButtonChildBlock($childId, $blockClassName = null) - { - if (null === $blockClassName) { - $blockClassName = 'Magento\Backend\Block\Widget\Button'; - } - - return $this->getLayout()->createBlock($blockClassName, $this->getNameInLayout() . '-' . $childId); - } - - /** - * @return string - */ - public function getPostsJson() - { - $posts = $this->getCategory()->getPostsPosition(); - if (!empty($posts)) { - return $this->jsonEncoder->encode($posts); - } - - return '{}'; - } + /** + * @return string + */ + public function getPostsJson() + { + $posts = $this->getCategory()->getPostsPosition(); + if (!empty($posts)) { + return $this->jsonEncoder->encode($posts); + } + return '{}'; + } } diff --git a/Block/Adminhtml/Category/Edit/Tab/Category.php b/Block/Adminhtml/Category/Edit/Tab/Category.php index 4990005c..66a689ee 100755 --- a/Block/Adminhtml/Category/Edit/Tab/Category.php +++ b/Block/Adminhtml/Category/Edit/Tab/Category.php @@ -2,239 +2,238 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Category\Edit\Tab; class Category extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Backend\Block\Widget\Tab\TabInterface { - /** - * Wysiwyg config - * - * @var \Magento\Cms\Model\Wysiwyg\Config - */ - protected $wysiwygConfig; + /** + * Wysiwyg config + * + * @var \Magento\Cms\Model\Wysiwyg\Config + */ + protected $wysiwygConfig; - /** - * Country options - * - * @var \Magento\Config\Model\Config\Source\Yesno - */ - protected $booleanOptions; + /** + * Country options + * + * @var \Magento\Config\Model\Config\Source\Yesno + */ + protected $booleanOptions; - /** - * Meta Robots options - * - * @var \Mageplaza\Blog\Model\Category\Source\MetaRobots - */ - protected $metaRobotsOptions; + /** + * Meta Robots options + * + * @var \Mageplaza\Blog\Model\Category\Source\MetaRobots + */ + protected $metaRobotsOptions; - /** - * constructor - * - * @param \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig - * @param \Magento\Config\Model\Config\Source\Yesno $booleanOptions - * @param \Mageplaza\Blog\Model\Category\Source\MetaRobots $metaRobotsOptions - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Data\FormFactory $formFactory - * @param array $data - */ - public function __construct( - \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig, - \Magento\Config\Model\Config\Source\Yesno $booleanOptions, - \Mageplaza\Blog\Model\Category\Source\MetaRobots $metaRobotsOptions, - \Magento\Backend\Block\Template\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Data\FormFactory $formFactory, - array $data = [] - ) - { - $this->wysiwygConfig = $wysiwygConfig; - $this->booleanOptions = $booleanOptions; - $this->metaRobotsOptions = $metaRobotsOptions; - parent::__construct($context, $registry, $formFactory, $data); - } + /** + * constructor + * + * @param \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig + * @param \Magento\Config\Model\Config\Source\Yesno $booleanOptions + * @param \Mageplaza\Blog\Model\Category\Source\MetaRobots $metaRobotsOptions + * @param \Magento\Backend\Block\Template\Context $context + * @param \Magento\Framework\Registry $registry + * @param \Magento\Framework\Data\FormFactory $formFactory + * @param array $data + */ + public function __construct( + \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig, + \Magento\Config\Model\Config\Source\Yesno $booleanOptions, + \Mageplaza\Blog\Model\Category\Source\MetaRobots $metaRobotsOptions, + \Magento\Backend\Block\Template\Context $context, + \Magento\Framework\Registry $registry, + \Magento\Framework\Data\FormFactory $formFactory, + array $data = [] + ) + { + $this->wysiwygConfig = $wysiwygConfig; + $this->booleanOptions = $booleanOptions; + $this->metaRobotsOptions = $metaRobotsOptions; + parent::__construct($context, $registry, $formFactory, $data); + } - /** - * Prepare form - * - * @return $this - */ - protected function _prepareForm() - { - /** @var \Mageplaza\Blog\Model\Category $category */ - $category = $this->_coreRegistry->registry('mageplaza_blog_category'); - $form = $this->_formFactory->create(); - $form->setHtmlIdPrefix('category_'); - $form->setFieldNameSuffix('category'); - $fieldset = $form->addFieldset( - 'base_fieldset', - [ - 'legend' => __('Category Information'), - 'class' => 'fieldset-wide' - ] - ); - if (!$category->getId()) { - // path - if ($this->getRequest()->getParam('parent')) { - $fieldset->addField( - 'path', - 'hidden', - ['name' => 'path', 'value' => $this->getRequest()->getParam('parent')] - ); - } else { - $fieldset->addField('path', 'hidden', ['name' => 'path', 'value' => 1]); - } - } else { - $fieldset->addField( - 'category_id', - 'hidden', - ['name' => 'category_id', 'value' => $category->getId()] - ); - $fieldset->addField( - 'path', - 'hidden', - ['name' => 'path', 'value' => $category->getPath()] - ); - } - $fieldset->addField( - 'name', - 'text', - [ - 'name' => 'name', - 'label' => __('Name'), - 'title' => __('Name'), - 'required' => true, - ] - ); - $fieldset->addField( - 'description', - 'editor', - [ - 'name' => 'description', - 'label' => __('Description'), - 'title' => __('Description'), - 'config' => $this->wysiwygConfig->getConfig() - ] - ); - $fieldset->addField( - 'url_key', - 'text', - [ - 'name' => 'url_key', - 'label' => __('URL Key'), - 'title' => __('URL Key'), - ] - ); - $fieldset->addField( - 'enabled', - 'select', - [ - 'name' => 'enabled', - 'label' => __('Enabled'), - 'title' => __('Enabled'), - 'values' => $this->booleanOptions->toOptionArray(), - ] - ); - $fieldset->addField( - 'meta_title', - 'text', - [ - 'name' => 'meta_title', - 'label' => __('Meta Title'), - 'title' => __('Meta Title'), - ] - ); - $fieldset->addField( - 'meta_description', - 'textarea', - [ - 'name' => 'meta_description', - 'label' => __('Meta Description'), - 'title' => __('Meta Description'), - ] - ); - $fieldset->addField( - 'meta_keywords', - 'textarea', - [ - 'name' => 'meta_keywords', - 'label' => __('Meta Keywords'), - 'title' => __('Meta Keywords'), - ] - ); - $fieldset->addField( - 'meta_robots', - 'select', - [ - 'name' => 'meta_robots', - 'label' => __('Meta Robots'), - 'title' => __('Meta Robots'), - 'values' => array_merge(['' => ''], $this->metaRobotsOptions->toOptionArray()), - ] - ); + /** + * Prepare form + * + * @return $this + */ + protected function _prepareForm() + { + /** @var \Mageplaza\Blog\Model\Category $category */ + $category = $this->_coreRegistry->registry('mageplaza_blog_category'); + $form = $this->_formFactory->create(); + $form->setHtmlIdPrefix('category_'); + $form->setFieldNameSuffix('category'); + $fieldset = $form->addFieldset( + 'base_fieldset', + [ + 'legend' => __('Category Information'), + 'class' => 'fieldset-wide' + ] + ); + if (!$category->getId()) { + // path + if ($this->getRequest()->getParam('parent')) { + $fieldset->addField( + 'path', + 'hidden', + ['name' => 'path', 'value' => $this->getRequest()->getParam('parent')] + ); + } else { + $fieldset->addField('path', 'hidden', ['name' => 'path', 'value' => 1]); + } + } else { + $fieldset->addField( + 'category_id', + 'hidden', + ['name' => 'category_id', 'value' => $category->getId()] + ); + $fieldset->addField( + 'path', + 'hidden', + ['name' => 'path', 'value' => $category->getPath()] + ); + } + $fieldset->addField( + 'name', + 'text', + [ + 'name' => 'name', + 'label' => __('Name'), + 'title' => __('Name'), + 'required' => true, + ] + ); + $fieldset->addField( + 'description', + 'editor', + [ + 'name' => 'description', + 'label' => __('Description'), + 'title' => __('Description'), + 'config' => $this->wysiwygConfig->getConfig() + ] + ); + $fieldset->addField( + 'url_key', + 'text', + [ + 'name' => 'url_key', + 'label' => __('URL Key'), + 'title' => __('URL Key'), + ] + ); + $fieldset->addField( + 'enabled', + 'select', + [ + 'name' => 'enabled', + 'label' => __('Enabled'), + 'title' => __('Enabled'), + 'values' => $this->booleanOptions->toOptionArray(), + ] + ); + $fieldset->addField( + 'meta_title', + 'text', + [ + 'name' => 'meta_title', + 'label' => __('Meta Title'), + 'title' => __('Meta Title'), + ] + ); + $fieldset->addField( + 'meta_description', + 'textarea', + [ + 'name' => 'meta_description', + 'label' => __('Meta Description'), + 'title' => __('Meta Description'), + ] + ); + $fieldset->addField( + 'meta_keywords', + 'textarea', + [ + 'name' => 'meta_keywords', + 'label' => __('Meta Keywords'), + 'title' => __('Meta Keywords'), + ] + ); + $fieldset->addField( + 'meta_robots', + 'select', + [ + 'name' => 'meta_robots', + 'label' => __('Meta Robots'), + 'title' => __('Meta Robots'), + 'values' => array_merge(['' => ''], $this->metaRobotsOptions->toOptionArray()), + ] + ); - $categoryData = $this->_session->getData('mageplaza_blog_category_data', true); - if ($categoryData) { - $category->addData($categoryData); - } else { - if (!$category->getId()) { - $category->addData($category->getDefaultValues()); - } - } - $form->addValues($category->getData()); - $this->setForm($form); + $categoryData = $this->_session->getData('mageplaza_blog_category_data', true); + if ($categoryData) { + $category->addData($categoryData); + } else { + if (!$category->getId()) { + $category->addData($category->getDefaultValues()); + } + } + $form->addValues($category->getData()); + $this->setForm($form); + return parent::_prepareForm(); + } - return parent::_prepareForm(); - } + /** + * Prepare label for tab + * + * @return string + */ + public function getTabLabel() + { + return __('Category'); + } - /** - * Prepare label for tab - * - * @return string - */ - public function getTabLabel() - { - return __('Category'); - } + /** + * Prepare title for tab + * + * @return string + */ + public function getTabTitle() + { + return $this->getTabLabel(); + } - /** - * Prepare title for tab - * - * @return string - */ - public function getTabTitle() - { - return $this->getTabLabel(); - } + /** + * Can show tab in tabs + * + * @return boolean + */ + public function canShowTab() + { + return true; + } - /** - * Can show tab in tabs - * - * @return boolean - */ - public function canShowTab() - { - return true; - } - - /** - * Tab is hidden - * - * @return boolean - */ - public function isHidden() - { - return false; - } + /** + * Tab is hidden + * + * @return boolean + */ + public function isHidden() + { + return false; + } } diff --git a/Block/Adminhtml/Category/Edit/Tab/Post.php b/Block/Adminhtml/Category/Edit/Tab/Post.php index 0a2d5ecd..bea05df9 100755 --- a/Block/Adminhtml/Category/Edit/Tab/Post.php +++ b/Block/Adminhtml/Category/Edit/Tab/Post.php @@ -2,305 +2,302 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Category\Edit\Tab; class Post extends \Magento\Backend\Block\Widget\Grid\Extended implements \Magento\Backend\Block\Widget\Tab\TabInterface { - /** - * Post collection factory - * - * @var \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory - */ - protected $postCollectionFactory; + /** + * Post collection factory + * + * @var \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory + */ + protected $postCollectionFactory; - /** - * Registry - * - * @var \Magento\Framework\Registry - */ - protected $coreRegistry; + /** + * Registry + * + * @var \Magento\Framework\Registry + */ + protected $coreRegistry; - /** - * Post factory - * - * @var \Mageplaza\Blog\Model\PostFactory - */ - protected $postFactory; + /** + * Post factory + * + * @var \Mageplaza\Blog\Model\PostFactory + */ + protected $postFactory; - /** - * constructor - * - * @param \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory - * @param \Magento\Framework\Registry $coreRegistry - * @param \Mageplaza\Blog\Model\PostFactory $postFactory - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\Backend\Helper\Data $backendHelper - * @param array $data - */ - public function __construct( - \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory, - \Magento\Framework\Registry $coreRegistry, - \Mageplaza\Blog\Model\PostFactory $postFactory, - \Magento\Backend\Block\Template\Context $context, - \Magento\Backend\Helper\Data $backendHelper, - array $data = [] - ) - { - $this->postCollectionFactory = $postCollectionFactory; - $this->coreRegistry = $coreRegistry; - $this->postFactory = $postFactory; - parent::__construct($context, $backendHelper, $data); - } + /** + * constructor + * + * @param \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory + * @param \Magento\Framework\Registry $coreRegistry + * @param \Mageplaza\Blog\Model\PostFactory $postFactory + * @param \Magento\Backend\Block\Template\Context $context + * @param \Magento\Backend\Helper\Data $backendHelper + * @param array $data + */ + public function __construct( + \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory, + \Magento\Framework\Registry $coreRegistry, + \Mageplaza\Blog\Model\PostFactory $postFactory, + \Magento\Backend\Block\Template\Context $context, + \Magento\Backend\Helper\Data $backendHelper, + array $data = [] + ) + { + $this->postCollectionFactory = $postCollectionFactory; + $this->coreRegistry = $coreRegistry; + $this->postFactory = $postFactory; + parent::__construct($context, $backendHelper, $data); + } - /** - * Set grid params - */ - public function _construct() - { - parent::_construct(); - $this->setId('post_grid'); - $this->setDefaultSort('position'); - $this->setDefaultDir('ASC'); - $this->setUseAjax(true); - if ($this->getCategory()->getId()) { - $this->setDefaultFilter(['in_posts' => 1]); - } - } + /** + * Set grid params + */ + public function _construct() + { + parent::_construct(); + $this->setId('post_grid'); + $this->setDefaultSort('position'); + $this->setDefaultDir('ASC'); + $this->setUseAjax(true); + if ($this->getCategory()->getId()) { + $this->setDefaultFilter(['in_posts'=>1]); + } + } - /** - * prepare the collection - * @return $this - */ - protected function _prepareCollection() - { - /** @var \Mageplaza\Blog\Model\ResourceModel\Post\Collection $collection */ - $collection = $this->postCollectionFactory->create(); - if ($this->getCategory()->getId()) { - $constraint = 'related.category_id=' . $this->getCategory()->getId(); - } else { - $constraint = 'related.category_id=0'; - } - $collection->getSelect()->joinLeft( - array('related' => $collection->getTable('mageplaza_blog_post_category')), - 'related.post_id=main_table.post_id AND ' . $constraint, - array('position') - ); - $this->setCollection($collection); - parent::_prepareCollection(); + /** + * prepare the collection - return $this; - } + * @return $this + */ + protected function _prepareCollection() + { + /** @var \Mageplaza\Blog\Model\ResourceModel\Post\Collection $collection */ + $collection = $this->postCollectionFactory->create(); + if ($this->getCategory()->getId()) { + $constraint = 'related.category_id='.$this->getCategory()->getId(); + } else { + $constraint = 'related.category_id=0'; + } + $collection->getSelect()->joinLeft( + array('related' => $collection->getTable('mageplaza_blog_post_category')), + 'related.post_id=main_table.post_id AND '.$constraint, + array('position') + ); + $this->setCollection($collection); + parent::_prepareCollection(); + return $this; + } - /** - * @return $this - */ - protected function _prepareMassaction() - { - return $this; - } + /** + * @return $this + */ + protected function _prepareMassaction() + { + return $this; + } - /** - * @return $this - */ - protected function _prepareColumns() - { - $this->addColumn( - 'in_posts', - [ - 'header_css_class' => 'a-center', - 'type' => 'checkbox', - 'name' => 'in_post', - 'values' => $this->_getSelectedPosts(), - 'align' => 'center', - 'index' => 'post_id' - ] - ); - $this->addColumn( - 'post_id', - [ - 'header' => __('ID'), - 'sortable' => true, - 'index' => 'post_id', - 'type' => 'number', - 'header_css_class' => 'col-id', - 'column_css_class' => 'col-id' - ] - ); + /** + * @return $this + */ + protected function _prepareColumns() + { + $this->addColumn( + 'in_posts', + [ + 'header_css_class' => 'a-center', + 'type' => 'checkbox', + 'name' => 'in_post', + 'values' => $this->_getSelectedPosts(), + 'align' => 'center', + 'index' => 'post_id' + ] + ); + $this->addColumn( + 'post_id', + [ + 'header' => __('ID'), + 'sortable' => true, + 'index' => 'post_id', + 'type' => 'number', + 'header_css_class' => 'col-id', + 'column_css_class' => 'col-id' + ] + ); - $this->addColumn( - 'title', - [ - 'header' => __('Name'), - 'index' => 'name', - 'header_css_class' => 'col-name', - 'column_css_class' => 'col-name' - ] - ); + $this->addColumn( + 'title', + [ + 'header' => __('Name'), + 'index' => 'name', + 'header_css_class' => 'col-name', + 'column_css_class' => 'col-name' + ] + ); - $this->addColumn( - 'position', - [ - 'header' => __('Position'), - 'name' => 'position', - 'width' => 60, - 'type' => 'number', - 'validate_class' => 'validate-number', - 'index' => 'position', - 'editable' => true, - ] - ); + $this->addColumn( + 'position', + [ + 'header' => __('Position'), + 'name' => 'position', + 'width' => 60, + 'type' => 'number', + 'validate_class' => 'validate-number', + 'index' => 'position', + 'editable' => true, + ] + ); + return $this; + } - return $this; - } + /** + * Retrieve selected Posts - /** - * Retrieve selected Posts - * @return array - */ - protected function _getSelectedPosts() - { - $posts = $this->getCategoryPosts(); - if (!is_array($posts)) { - $posts = $this->getCategory()->getPostsPosition(); + * @return array + */ + protected function _getSelectedPosts() + { + $posts = $this->getCategoryPosts(); + if (!is_array($posts)) { + $posts = $this->getCategory()->getPostsPosition(); + return array_keys($posts); + } + return $posts; + } - return array_keys($posts); - } + /** + * Retrieve selected Posts - return $posts; - } + * @return array + */ + public function getSelectedPosts() + { + $selected = $this->getCategory()->getPostsPosition(); + if (!is_array($selected)) { + $selected = []; + } else { + foreach ($selected as $key => $value) { + $selected[$key] = ['position' => $value]; + } + } + return $selected; + } - /** - * Retrieve selected Posts - * @return array - */ - public function getSelectedPosts() - { - $selected = $this->getCategory()->getPostsPosition(); - if (!is_array($selected)) { - $selected = []; - } else { - foreach ($selected as $key => $value) { - $selected[$key] = ['position' => $value]; - } - } + /** + * @param \Mageplaza\Blog\Model\Post|\Magento\Framework\Object $item + * @return string + */ + public function getRowUrl($item) + { + return '#'; + } - return $selected; - } + /** + * get grid url + * + * @return string + */ + public function getGridUrl() + { + return $this->getUrl( + '*/*/postsGrid', + [ + 'category_id' => $this->getCategory()->getId() + ] + ); + } - /** - * @param \Mageplaza\Blog\Model\Post|\Magento\Framework\Object $item - * @return string - */ - public function getRowUrl($item) - { - return '#'; - } + /** + * @return \Mageplaza\Blog\Model\Category + */ + public function getCategory() + { + return $this->coreRegistry->registry('mageplaza_blog_category'); + } - /** - * get grid url - * - * @return string - */ - public function getGridUrl() - { - return $this->getUrl( - '*/*/postsGrid', - [ - 'category_id' => $this->getCategory()->getId() - ] - ); - } + /** + * @param \Magento\Backend\Block\Widget\Grid\Column $column + * @return $this + */ + protected function _addColumnFilterToCollection($column) + { + if ($column->getId() == 'in_posts') { + $postIds = $this->_getSelectedPosts(); + if (empty($postIds)) { + $postIds = 0; + } + if ($column->getFilter()->getValue()) { + $this->getCollection()->addFieldToFilter('main_table.post_id', ['in'=>$postIds]); + } else { + if ($postIds) { + $this->getCollection()->addFieldToFilter('main_table.post_id', ['nin'=>$postIds]); + } + } + } else { + parent::_addColumnFilterToCollection($column); + } + return $this; + } - /** - * @return \Mageplaza\Blog\Model\Category - */ - public function getCategory() - { - return $this->coreRegistry->registry('mageplaza_blog_category'); - } + /** + * @return string + */ + public function getTabLabel() + { + return __('Posts'); + } - /** - * @param \Magento\Backend\Block\Widget\Grid\Column $column - * @return $this - */ - protected function _addColumnFilterToCollection($column) - { - if ($column->getId() == 'in_posts') { - $postIds = $this->_getSelectedPosts(); - if (empty($postIds)) { - $postIds = 0; - } - if ($column->getFilter()->getValue()) { - $this->getCollection()->addFieldToFilter('main_table.post_id', ['in' => $postIds]); - } else { - if ($postIds) { - $this->getCollection()->addFieldToFilter('main_table.post_id', ['nin' => $postIds]); - } - } - } else { - parent::_addColumnFilterToCollection($column); - } + /** + * @return bool + */ + public function isHidden() + { + return false; + } - return $this; - } + /** + * @return string + */ + public function getTabTitle() + { + return $this->getTabLabel(); + } - /** - * @return string - */ - public function getTabLabel() - { - return __('Posts'); - } + /** + * @return bool + */ + public function canShowTab() + { + return true; + } - /** - * @return bool - */ - public function isHidden() - { - return false; - } + /** + * @return string + */ + public function getTabUrl() + { + return $this->getUrl('mageplaza_blog/category/posts', ['_current' => true]); + } - /** - * @return string - */ - public function getTabTitle() - { - return $this->getTabLabel(); - } - - /** - * @return bool - */ - public function canShowTab() - { - return true; - } - - /** - * @return string - */ - public function getTabUrl() - { - return $this->getUrl('mageplaza_blog/category/posts', ['_current' => true]); - } - - /** - * @return string - */ - public function getTabClass() - { - return 'ajax only'; - } + /** + * @return string + */ + public function getTabClass() + { + return 'ajax only'; + } } diff --git a/Block/Adminhtml/Category/Edit/Tabs.php b/Block/Adminhtml/Category/Edit/Tabs.php index 67aef51c..d5118597 100755 --- a/Block/Adminhtml/Category/Edit/Tabs.php +++ b/Block/Adminhtml/Category/Edit/Tabs.php @@ -2,16 +2,16 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Category\Edit; @@ -20,97 +20,96 @@ */ class Tabs extends \Magento\Backend\Block\Widget\Tabs { - /** - * Tabs template - * - * @var string - */ - protected $_template = 'Magento_Backend::widget/tabshoriz.phtml'; + /** + * Tabs template + * + * @var string + */ + protected $_template = 'Magento_Backend::widget/tabshoriz.phtml'; - /** - * Registry - * - * @var \Magento\Framework\Registry - */ - protected $coreRegistry; + /** + * Registry + * + * @var \Magento\Framework\Registry + */ + protected $coreRegistry; - /** - * constructor - * - * @param \Magento\Framework\Registry $coreRegistry - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder - * @param \Magento\Backend\Model\Auth\Session $authSession - * @param array $data - */ - public function __construct( - \Magento\Framework\Registry $coreRegistry, - \Magento\Backend\Block\Template\Context $context, - \Magento\Framework\Json\EncoderInterface $jsonEncoder, - \Magento\Backend\Model\Auth\Session $authSession, - array $data = [] - ) - { - $this->coreRegistry = $coreRegistry; - parent::__construct($context, $jsonEncoder, $authSession, $data); - } + /** + * constructor + * + * @param \Magento\Framework\Registry $coreRegistry + * @param \Magento\Backend\Block\Template\Context $context + * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder + * @param \Magento\Backend\Model\Auth\Session $authSession + * @param array $data + */ + public function __construct( + \Magento\Framework\Registry $coreRegistry, + \Magento\Backend\Block\Template\Context $context, + \Magento\Framework\Json\EncoderInterface $jsonEncoder, + \Magento\Backend\Model\Auth\Session $authSession, + array $data = [] + ) + { + $this->coreRegistry = $coreRegistry; + parent::__construct($context, $jsonEncoder, $authSession, $data); + } - /** - * Initialize Tabs - * - * @return void - */ - protected function _construct() - { - parent::_construct(); - $this->setId('category_info_tabs'); - $this->setDestElementId('category_tab_content'); - $this->setTitle(__('Category Data')); - } + /** + * Initialize Tabs + * + * @return void + */ + protected function _construct() + { + parent::_construct(); + $this->setId('category_info_tabs'); + $this->setDestElementId('category_tab_content'); + $this->setTitle(__('Category Data')); + } - /** - * Retrieve Category object - * - * @return \Mageplaza\Blog\Model\Category - */ - public function getCategory() - { - return $this->coreRegistry->registry('mageplaza_blog_category'); - } + /** + * Retrieve Category object + * + * @return \Mageplaza\Blog\Model\Category + */ + public function getCategory() + { + return $this->coreRegistry->registry('mageplaza_blog_category'); + } - /** - * Prepare Layout Content - * - * @return $this - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - */ - protected function _prepareLayout() - { - $this->addTab( - 'category', - [ - 'label' => __('Category information'), - 'content' => $this->getLayout()->createBlock( - 'Mageplaza\Blog\Block\Adminhtml\Category\Edit\Tab\Category', - 'mageplaza_blog_category_edit_tab_category' - )->toHtml() - ] - ); - $this->addTab( - 'post', - [ - 'label' => __('Posts'), - 'content' => $this->getLayout()->createBlock( - 'Mageplaza\Blog\Block\Adminhtml\Category\Edit\Tab\Post', - 'mageplaza_blog_category_edit_tab_post' - )->toHtml() - ] - ); - // dispatch event add custom tabs - $this->_eventManager->dispatch('adminhtml_mageplaza_blog_category_tabs', ['tabs' => $this]); - - return parent::_prepareLayout(); - } + /** + * Prepare Layout Content + * + * @return $this + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + */ + protected function _prepareLayout() + { + $this->addTab( + 'category', + [ + 'label' => __('Category information'), + 'content' => $this->getLayout()->createBlock( + 'Mageplaza\Blog\Block\Adminhtml\Category\Edit\Tab\Category', + 'mageplaza_blog_category_edit_tab_category' + )->toHtml() + ] + ); + $this->addTab( + 'post', + [ + 'label' => __('Posts'), + 'content' => $this->getLayout()->createBlock( + 'Mageplaza\Blog\Block\Adminhtml\Category\Edit\Tab\Post', + 'mageplaza_blog_category_edit_tab_post' + )->toHtml() + ] + ); + // dispatch event add custom tabs + $this->_eventManager->dispatch('adminhtml_mageplaza_blog_category_tabs', ['tabs' => $this]); + return parent::_prepareLayout(); + } } diff --git a/Block/Adminhtml/Category/NewCategory.php b/Block/Adminhtml/Category/NewCategory.php index 5bf2295f..d1b123db 100755 --- a/Block/Adminhtml/Category/NewCategory.php +++ b/Block/Adminhtml/Category/NewCategory.php @@ -2,16 +2,16 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Category; @@ -21,153 +21,152 @@ */ class NewCategory extends \Magento\Backend\Block\Widget\Form\Generic { - /** - * JSON encoder - * - * @var \Magento\Framework\Json\EncoderInterface - */ - protected $jsonEncoder; + /** + * JSON encoder + * + * @var \Magento\Framework\Json\EncoderInterface + */ + protected $jsonEncoder; - /** - * Category collection factory - * - * @var \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory - */ - protected $categoryCollectionFactory; + /** + * Category collection factory + * + * @var \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory + */ + protected $categoryCollectionFactory; - /** - * constructor - * - * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder - * @param \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Data\FormFactory $formFactory - * @param array $data - */ - public function __construct( - \Magento\Framework\Json\EncoderInterface $jsonEncoder, - \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory, - \Magento\Backend\Block\Template\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Data\FormFactory $formFactory, - array $data = [] - ) - { - $this->jsonEncoder = $jsonEncoder; - $this->categoryCollectionFactory = $categoryCollectionFactory; - parent::__construct($context, $registry, $formFactory, $data); - $this->setUseContainer(true); - } + /** + * constructor + * + * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder + * @param \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory + * @param \Magento\Backend\Block\Template\Context $context + * @param \Magento\Framework\Registry $registry + * @param \Magento\Framework\Data\FormFactory $formFactory + * @param array $data + */ + public function __construct( + \Magento\Framework\Json\EncoderInterface $jsonEncoder, + \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory, + \Magento\Backend\Block\Template\Context $context, + \Magento\Framework\Registry $registry, + \Magento\Framework\Data\FormFactory $formFactory, + array $data = [] + ) + { + $this->jsonEncoder = $jsonEncoder; + $this->categoryCollectionFactory = $categoryCollectionFactory; + parent::__construct($context, $registry, $formFactory, $data); + $this->setUseContainer(true); + } - /** - * Form preparation - * - * @return void - */ - protected function _prepareForm() - { - /** @var \Magento\Framework\Data\Form $form */ - $form = $this->_formFactory->create( - [ - 'data' => [ - 'id' => 'new_category_form', - 'class' => 'admin__scope-old' - ] - ] - ); - $form->setUseContainer($this->getUseContainer()); + /** + * Form preparation + * + * @return void + */ + protected function _prepareForm() + { + /** @var \Magento\Framework\Data\Form $form */ + $form = $this->_formFactory->create( + [ + 'data' => [ + 'id' => 'new_category_form', + 'class' => 'admin__scope-old' + ] + ] + ); + $form->setUseContainer($this->getUseContainer()); - $form->addField('new_category_messages', 'note', []); + $form->addField('new_category_messages', 'note', []); - $fieldset = $form->addFieldset('new_category_form_fieldset', []); + $fieldset = $form->addFieldset('new_category_form_fieldset', []); - $fieldset->addField( - 'new_category_name', - 'text', - [ - 'label' => __('Name'), - 'title' => __('Name'), - 'required' => true, - 'name' => 'new_category_name' - ] - ); - //TODO: add all required fields here - $fieldset->addField( - 'new_category_parent', - 'select', - [ - 'label' => __('Parent Category'), - 'title' => __('Parent Category'), - 'required' => false, - 'options' => $this->getParentCategoryOptions(), - 'class' => 'validate-parent-category', - 'name' => 'new_category_parent', - // @codingStandardsIgnoreStart - 'note' => __( - 'You can reassign the Category at any time in ' . - 'Manage Categories.', - $this->getUrl('mageplaza_blog/category') - ) - // @codingStandardsIgnoreEnd - ] - ); + $fieldset->addField( + 'new_category_name', + 'text', + [ + 'label' => __('Name'), + 'title' => __('Name'), + 'required' => true, + 'name' => 'new_category_name' + ] + ); + //TODO: add all required fields here + $fieldset->addField( + 'new_category_parent', + 'select', + [ + 'label' => __('Parent Category'), + 'title' => __('Parent Category'), + 'required' => false, + 'options' => $this->getParentCategoryOptions(), + 'class' => 'validate-parent-category', + 'name' => 'new_category_parent', + // @codingStandardsIgnoreStart + 'note' => __( + 'You can reassign the Category at any time in ' . + 'Manage Categories.', + $this->getUrl('mageplaza_blog/category') + ) + // @codingStandardsIgnoreEnd + ] + ); - $this->setForm($form); - } + $this->setForm($form); + } - /** - * Get parent Category options - * - * @return array - */ - protected function getParentCategoryOptions() - { - $items = $this->categoryCollectionFactory->create() - ->addOrder('Category_id', 'ASC') - ->setPageSize(3)->load()->getItems(); + /** + * Get parent Category options + * + * @return array + */ + protected function getParentCategoryOptions() + { + $items = $this->categoryCollectionFactory->create() + ->addOrder('Category_id','ASC') + ->setPageSize(3)->load()->getItems(); - $result = []; - if (count($items) === 2) { - $item = array_pop($items); - $result = [$item->getCategoryId() => $item->getName()]; - } + $result = []; + if (count($items) === 2) { + $item = array_pop($items); + $result = [$item->getCategoryId() => $item->getName()]; + } - return $result; - } + return $result; + } - /** - * Category save action URL - * - * @return string - */ - public function getSaveCategoryUrl() - { - return $this->getUrl('mageplaza_blog/category/save'); - } + /** + * Category save action URL + * + * @return string + */ + public function getSaveCategoryUrl() + { + return $this->getUrl('mageplaza_blog/category/save'); + } - /** - * Attach new Category dialog widget initialization - * - * @return string - */ - public function getAfterElementHtml() - { - $widgetOptions = $this->jsonEncoder->encode( - [ - 'suggestOptions' => [ - 'source' => $this->getUrl('mageplaza_blog/category/suggestCategories'), - 'valueField' => '#new_category_parent', - 'className' => 'category-select', - 'multiselect' => true, - 'showAll' => true, - ], - 'saveCategoryUrl' => $this->getUrl('mageplaza_blog/category/save'), - ] - ); - - //TODO: JavaScript logic should be moved to separate file or reviewed - return <<jsonEncoder->encode( + [ + 'suggestOptions' => [ + 'source' => $this->getUrl('mageplaza_blog/category/suggestCategories'), + 'valueField' => '#new_category_parent', + 'className' => 'category-select', + 'multiselect' => true, + 'showAll' => true, + ], + 'saveCategoryUrl' => $this->getUrl('mageplaza_blog/category/save'), + ] + ); + //TODO: JavaScript logic should be moved to separate file or reviewed + return << require(["jquery","mage/mage"],function($) { // waiting for dependencies at first $(function(){ // waiting for page to load to have '#category_ids-template' available @@ -176,5 +175,4 @@ public function getAfterElementHtml() }); HTML; - } -} + }} diff --git a/Block/Adminhtml/Category/Tree.php b/Block/Adminhtml/Category/Tree.php index 0732c4b4..7169469d 100755 --- a/Block/Adminhtml/Category/Tree.php +++ b/Block/Adminhtml/Category/Tree.php @@ -2,16 +2,16 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Category; @@ -21,435 +21,426 @@ */ class Tree extends \Mageplaza\Blog\Block\Adminhtml\Category\AbstractCategory { - /** - * Tree template - * - * @var string - */ - protected $_template = 'category/tree.phtml'; - - /** - * JSON Encoder instance - * - * @var \Magento\Framework\Json\EncoderInterface - */ - protected $jsonEncoder; - - /** - * Backend Session - * - * @var \Magento\Backend\Model\Auth\Session - */ - protected $backendSession; - - /** - * Resource Helper - * - * @var \Magento\Framework\DB\Helper - */ - protected $resourceHelper; - - /** - * constructor - * - * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder - * @param \Magento\Backend\Model\Auth\Session $backendSession - * @param \Magento\Framework\DB\Helper $resourceHelper - * @param \Magento\Framework\Registry $registry - * @param \Mageplaza\Blog\Model\ResourceModel\Category\Tree $categoryTree - * @param \Mageplaza\Blog\Model\CategoryFactory $categoryFactory - * @param \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory - * @param \Magento\Backend\Block\Widget\Context $context - * @param array $data - */ - public function __construct( - \Magento\Framework\Json\EncoderInterface $jsonEncoder, - \Magento\Backend\Model\Auth\Session $backendSession, - \Magento\Framework\DB\Helper $resourceHelper, - \Magento\Framework\Registry $registry, - \Mageplaza\Blog\Model\ResourceModel\Category\Tree $categoryTree, - \Mageplaza\Blog\Model\CategoryFactory $categoryFactory, - \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory, - \Magento\Backend\Block\Widget\Context $context, - array $data = [] - ) - { - $this->jsonEncoder = $jsonEncoder; - $this->backendSession = $backendSession; - $this->resourceHelper = $resourceHelper; - parent::__construct($registry, $categoryTree, $categoryFactory, $categoryCollectionFactory, $context, $data); - } - - /** - * @return void - */ - protected function _construct() - { - parent::_construct(); - $this->setUseAjax(0); - } - - /** - * Add buttons - * - * @return $this - */ - protected function _prepareLayout() - { - $addUrl = $this->getUrl("*/*/new", ['_current' => true, 'category_id' => null, '_query' => false]); - - $this->addChild( - 'add_sub_button', - 'Magento\Backend\Block\Widget\Button', - [ - 'label' => __('Add Child Category'), - 'onclick' => "addNew('" . $addUrl . "', false)", - 'class' => 'add', - 'id' => 'add_child_category_button', - 'style' => $this->canAddChildCategory() ? '' : 'display: none;' - ] - ); - - if ($this->canAddChildCategory()) { - $this->addChild( - 'add_root_button', - 'Magento\Backend\Block\Widget\Button', - [ - 'label' => __('Add Root Category'), - 'onclick' => "addNew('" . $addUrl . "', true)", - 'class' => 'add', - 'id' => 'add_root_category_button' - ] - ); - } - - return parent::_prepareLayout(); - } - - /** - * @param $namePart - * @return string - */ - public function getSuggestedCategoriesJson($namePart) - { - /* @var $collection \Mageplaza\Blog\Model\ResourceModel\Category\Collection */ - $collection = $this->categoryCollectionFactory->create(); - - /* @var $matchingNameCollection \Mageplaza\Blog\Model\ResourceModel\Category\Collection */ - $matchingNameCollection = clone $collection; - $escapedNamePart = $this->resourceHelper->addLikeEscape( - $namePart, - ['position' => 'any'] - ); - $matchingNameCollection->addFieldToFilter( - 'name', - ['like' => $escapedNamePart] - ) - ->addFieldToFilter( - 'category_id', - ['neq' => \Mageplaza\Blog\Model\Category::TREE_ROOT_ID] - ); - - $shownCategoriesIds = []; - foreach ($matchingNameCollection as $category) { - /** @var \Mageplaza\Blog\Model\Category $category */ - foreach (explode('/', $category->getPath()) as $parentId) { - $shownCategoriesIds[$parentId] = 1; - } - } - $collection->addFieldToFilter( - 'category_id', - ['in' => array_keys($shownCategoriesIds)] - ); - - $categoriesById = [ - \Mageplaza\Blog\Model\Category::TREE_ROOT_ID => [ - 'id' => \Mageplaza\Blog\Model\Category::TREE_ROOT_ID, - 'children' => [], - ], - ]; - foreach ($collection as $category) { - /** @var \Mageplaza\Blog\Model\Category $category */ - foreach ([$category->getId(), $category->getParentId()] as $categoryId) { - if (!isset($categoriesById[$categoryId])) { - $categoriesById[$categoryId] = ['id' => $categoryId, 'children' => []]; - } - } - $categoriesById[$category->getId()]['is_active'] = true; - $categoriesById[$category->getId()]['label'] = $category->getName(); - $categoriesById[$category->getParentId()]['children'][] = &$categoriesById[$category->getId()]; - } - - return $this->jsonEncoder->encode($categoriesById[\Mageplaza\Blog\Model\Category::TREE_ROOT_ID]['children']); - } - - /** - * @return string - */ - public function getAddRootButtonHtml() - { - return $this->getChildHtml('add_root_button'); - } - - /** - * @return string - */ - public function getAddSubButtonHtml() - { - return $this->getChildHtml('add_sub_button'); - } - - /** - * @return string - */ - public function getExpandButtonHtml() - { - return $this->getChildHtml('expand_button'); - } - - /** - * @return string - */ - public function getCollapseButtonHtml() - { - return $this->getChildHtml('collapse_button'); - } - - - /** - * @param bool|null $expanded - * @return string - */ - public function getLoadTreeUrl($expanded = null) - { - $params = ['_current' => true, 'id' => null, 'store' => null]; - if (is_null($expanded) && $this->backendSession->getMageplazaBlogCategoryIsTreeWasExpanded() - || $expanded == true - ) { - $params['expand_all'] = true; - } - - return $this->getUrl('*/*/categoriesJson', $params); - } - - /** - * @return string - */ - public function getNodesUrl() - { - return $this->getUrl('mageplaza_blog/category/jsonTree'); - } - - /** - * @return string - */ - public function getSwitchTreeUrl() - { - return $this->getUrl( - 'mageplaza_blog/category/tree', - ['_current' => true, 'store' => null, '_query' => false, 'id' => null, 'parent' => null] - ); - } - - /** - * @return bool - * @SuppressWarnings(PHPMD.BooleanGetMethodName) - */ - public function getIsWasExpanded() - { - return $this->backendSession->getMageplazaBlogCategoryIsTreeWasExpanded(); - } - - /** - * @return string - */ - public function getMoveUrl() - { - return $this->getUrl('mageplaza_blog/category/move'); - } - - /** - * @param null $parentNodeCategory - * @return array - */ - public function getTree($parentNodeCategory = null) - { - $rootArray = $this->getNodeJson($this->getRoot($parentNodeCategory)); - $tree = isset($rootArray['children']) ? $rootArray['children'] : []; - - return $tree; - } - - /** - * @param mixed $parentNodeCategory - * @return string - */ - public function getTreeJson($parentNodeCategory = null) - { - $rootArray = $this->getNodeJson($this->getRoot($parentNodeCategory)); - $json = $this->jsonEncoder->encode(isset($rootArray['children']) ? $rootArray['children'] : []); - - return $json; - } - - /** - * Get JSON of array of Categories, that are breadcrumbs for specified Category path - * - * @param string $path - * @param string $javascriptVarName - * @return string - */ - public function getBreadcrumbsJavascript($path, $javascriptVarName) - { - if (empty($path)) { - return ''; - } - - $categories = $this->categoryTree->loadBreadcrumbsArray($path); - if (empty($categories)) { - return ''; - } - foreach ($categories as $key => $category) { - $categories[$key] = $this->getNodeJson($categories); - } - - return ''; - } - - /** - * Get JSON of a tree node or an associative array - * - * @param Node|array $node - * @param int $level - * @return string - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @SuppressWarnings(PHPMD.NPathComplexity) - */ - protected function getNodeJson($node, $level = 0) - { - // create a node from data array - if (is_array($node)) { - $node = new \Magento\Framework\Data\Tree\Node($node, 'category_id', new \Magento\Framework\Data\Tree()); - } - - $item = []; - $item['text'] = $this->buildNodeName($node); - - $item['id'] = $node->getId(); - $item['path'] = $node->getData('path'); - - $item['cls'] = 'folder ' . 'active-category'; - $allowMove = $this->isCategoryMoveable($node); - $item['allowDrop'] = $allowMove; - $item['allowDrag'] = $allowMove && ($node->getLevel() == 0 ? false : true); - - if ((int)$node->getChildrenCount() > 0) { - $item['children'] = []; - } - - $isParent = $this->isParentSelectedCategory($node); - - if ($node->hasChildren()) { - $item['children'] = []; - if (!($this->getUseAjax() && $node->getLevel() > 1 && !$isParent)) { - foreach ($node->getChildren() as $child) { - $item['children'][] = $this->getNodeJson($child, $level + 1); - } - } - } - - if ($isParent || $node->getLevel() < 2) { - $item['expanded'] = true; - } - - return $item; - } - - /** - * Get Category Name - * - * @param \Magento\Framework\DataObject $node - * @return string - */ - public function buildNodeName($node) - { - $result = $this->escapeHtml($node->getName()); - - return $result; - } - - /** - * @param Node|array $node - * @return bool - */ - protected function isCategoryMoveable($node) - { - $options = new \Magento\Framework\DataObject(['is_moveable' => true, 'category' => $node]); - $this->_eventManager->dispatch('adminhtml_mageplaza_blog_category_tree_is_moveable', ['options' => $options]); - - return $options->getIsMoveable(); - } - - /** - * @param \Magento\Framework\Data\Tree\Node $node - * @return bool - */ - protected function isParentSelectedCategory($node) - { - if ($node && $this->getCategory()) { - $pathIds = $this->getCategory()->getPathIds(); - if (in_array($node->getId(), $pathIds)) { - return true; - } - } - - return false; - } - - /** - * Check if page loaded by outside link to Category edit - * - * @return boolean - */ - public function isClearEdit() - { - return (bool)$this->getRequest()->getParam('clear'); - } - - /** - * Check availability of adding root Category - * - * @return boolean - */ - public function canAddRootCategory() - { - $options = new \Magento\Framework\DataObject(['is_allow' => true]); - $this->_eventManager->dispatch( - 'adminhtml_mageplaza_blog_category_tree_can_add_root_category', - ['category' => $this->getCategory(), 'options' => $options] - ); - - return $options->getIsAllow(); - } - - /** - * Check availability of adding child Category - * - * @return boolean - */ - public function canAddChildCategory() - { - $options = new \Magento\Framework\DataObject(['is_allow' => true]); - $this->_eventManager->dispatch( - 'adminhtml_mageplaza_blog_category_tree_can_add_child_category', - ['category' => $this->getCategory(), 'options' => $options] - ); - - return $options->getIsAllow(); - } + /** + * Tree template + * + * @var string + */ + protected $_template = 'category/tree.phtml'; + + /** + * JSON Encoder instance + * + * @var \Magento\Framework\Json\EncoderInterface + */ + protected $jsonEncoder; + + /** + * Backend Session + * + * @var \Magento\Backend\Model\Auth\Session + */ + protected $backendSession; + + /** + * Resource Helper + * + * @var \Magento\Framework\DB\Helper + */ + protected $resourceHelper; + + /** + * constructor + * + * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder + * @param \Magento\Backend\Model\Auth\Session $backendSession + * @param \Magento\Framework\DB\Helper $resourceHelper + * @param \Magento\Framework\Registry $registry + * @param \Mageplaza\Blog\Model\ResourceModel\Category\Tree $categoryTree + * @param \Mageplaza\Blog\Model\CategoryFactory $categoryFactory + * @param \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory + * @param \Magento\Backend\Block\Widget\Context $context + * @param array $data + */ + public function __construct( + \Magento\Framework\Json\EncoderInterface $jsonEncoder, + \Magento\Backend\Model\Auth\Session $backendSession, + \Magento\Framework\DB\Helper $resourceHelper, + \Magento\Framework\Registry $registry, + \Mageplaza\Blog\Model\ResourceModel\Category\Tree $categoryTree, + \Mageplaza\Blog\Model\CategoryFactory $categoryFactory, + \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory, + \Magento\Backend\Block\Widget\Context $context, + array $data = [] + ) + { + $this->jsonEncoder = $jsonEncoder; + $this->backendSession = $backendSession; + $this->resourceHelper = $resourceHelper; + parent::__construct($registry, $categoryTree, $categoryFactory, $categoryCollectionFactory, $context, $data); + } + + /** + * @return void + */ + protected function _construct() + { + parent::_construct(); + $this->setUseAjax(0); + } + + /** + * Add buttons + * + * @return $this + */ + protected function _prepareLayout() + { + $addUrl = $this->getUrl("*/*/new", ['_current' => true, 'category_id' => null, '_query' => false]); + + $this->addChild( + 'add_sub_button', + 'Magento\Backend\Block\Widget\Button', + [ + 'label' => __('Add Child Category'), + 'onclick' => "addNew('" . $addUrl . "', false)", + 'class' => 'add', + 'id' => 'add_child_category_button', + 'style' => $this->canAddChildCategory() ? '' : 'display: none;' + ] + ); + + if ($this->canAddChildCategory()) { + $this->addChild( + 'add_root_button', + 'Magento\Backend\Block\Widget\Button', + [ + 'label' => __('Add Root Category'), + 'onclick' => "addNew('" . $addUrl . "', true)", + 'class' => 'add', + 'id' => 'add_root_category_button' + ] + ); + } + return parent::_prepareLayout(); + } + + /** + * @param $namePart + * @return string + */ + public function getSuggestedCategoriesJson($namePart) + { + /* @var $collection \Mageplaza\Blog\Model\ResourceModel\Category\Collection */ + $collection = $this->categoryCollectionFactory->create(); + + /* @var $matchingNameCollection \Mageplaza\Blog\Model\ResourceModel\Category\Collection */ + $matchingNameCollection = clone $collection; + $escapedNamePart = $this->resourceHelper->addLikeEscape( + $namePart, + ['position' => 'any'] + ); + $matchingNameCollection->addFieldToFilter( + 'name', + ['like' => $escapedNamePart] + ) + ->addFieldToFilter( + 'category_id', + ['neq' => \Mageplaza\Blog\Model\Category::TREE_ROOT_ID] + ); + + $shownCategoriesIds = []; + foreach ($matchingNameCollection as $category) { + /** @var \Mageplaza\Blog\Model\Category $category */ + foreach (explode('/', $category->getPath()) as $parentId) { + $shownCategoriesIds[$parentId] = 1; + } + } + $collection->addFieldToFilter( + 'category_id', + ['in' => array_keys($shownCategoriesIds)] + ); + + $categoriesById = [ + \Mageplaza\Blog\Model\Category::TREE_ROOT_ID => [ + 'id' => \Mageplaza\Blog\Model\Category::TREE_ROOT_ID, + 'children' => [], + ], + ]; + foreach ($collection as $category) { + /** @var \Mageplaza\Blog\Model\Category $category */ + foreach ([$category->getId(), $category->getParentId()] as $categoryId) { + if (!isset($categoriesById[$categoryId])) { + $categoriesById[$categoryId] = ['id' => $categoryId, 'children' => []]; + } + } + $categoriesById[$category->getId()]['is_active'] = true; + $categoriesById[$category->getId()]['label'] = $category->getName(); + $categoriesById[$category->getParentId()]['children'][] = & $categoriesById[$category->getId()]; + } + return $this->jsonEncoder->encode($categoriesById[\Mageplaza\Blog\Model\Category::TREE_ROOT_ID]['children']); + } + + /** + * @return string + */ + public function getAddRootButtonHtml() + { + return $this->getChildHtml('add_root_button'); + } + + /** + * @return string + */ + public function getAddSubButtonHtml() + { + return $this->getChildHtml('add_sub_button'); + } + + /** + * @return string + */ + public function getExpandButtonHtml() + { + return $this->getChildHtml('expand_button'); + } + + /** + * @return string + */ + public function getCollapseButtonHtml() + { + return $this->getChildHtml('collapse_button'); + } + + + /** + * @param bool|null $expanded + * @return string + */ + public function getLoadTreeUrl($expanded = null) + { + $params = ['_current' => true, 'id' => null, 'store' => null]; + if (is_null($expanded) && $this->backendSession->getMageplazaBlogCategoryIsTreeWasExpanded() + || $expanded == true) { + $params['expand_all'] = true; + } + return $this->getUrl('*/*/categoriesJson', $params); + } + + /** + * @return string + */ + public function getNodesUrl() + { + return $this->getUrl('mageplaza_blog/category/jsonTree'); + } + + /** + * @return string + */ + public function getSwitchTreeUrl() + { + return $this->getUrl( + 'mageplaza_blog/category/tree', + ['_current' => true, 'store' => null, '_query' => false, 'id' => null, 'parent' => null] + ); + } + + /** + * @return bool + * @SuppressWarnings(PHPMD.BooleanGetMethodName) + */ + public function getIsWasExpanded() + { + return $this->backendSession->getMageplazaBlogCategoryIsTreeWasExpanded(); + } + + /** + * @return string + */ + public function getMoveUrl() + { + return $this->getUrl('mageplaza_blog/category/move'); + } + + /** + * @param null $parentNodeCategory + * @return array + */ + public function getTree($parentNodeCategory = null) + { + $rootArray = $this->getNodeJson($this->getRoot($parentNodeCategory)); + $tree = isset($rootArray['children']) ? $rootArray['children'] : []; + return $tree; + } + + /** + * @param mixed $parentNodeCategory + * @return string + */ + public function getTreeJson($parentNodeCategory = null) + { + $rootArray = $this->getNodeJson($this->getRoot($parentNodeCategory)); + $json = $this->jsonEncoder->encode(isset($rootArray['children']) ? $rootArray['children'] : []); + return $json; + } + + /** + * Get JSON of array of Categories, that are breadcrumbs for specified Category path + * + * @param string $path + * @param string $javascriptVarName + * @return string + */ + public function getBreadcrumbsJavascript($path, $javascriptVarName) + { + if (empty($path)) { + return ''; + } + + $categories = $this->categoryTree->loadBreadcrumbsArray($path); + if (empty($categories)) { + return ''; + } + foreach ($categories as $key => $category) { + $categories[$key] = $this->getNodeJson($categories); + } + return ''; + } + + /** + * Get JSON of a tree node or an associative array + * + * @param Node|array $node + * @param int $level + * @return string + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.NPathComplexity) + */ + protected function getNodeJson($node, $level = 0) + { + // create a node from data array + if (is_array($node)) { + $node = new \Magento\Framework\Data\Tree\Node($node, 'category_id', new \Magento\Framework\Data\Tree()); + } + + $item = []; + $item['text'] = $this->buildNodeName($node); + + $item['id'] = $node->getId(); + $item['path'] = $node->getData('path'); + + $item['cls'] = 'folder ' . 'active-category'; + $allowMove = $this->isCategoryMoveable($node); + $item['allowDrop'] = $allowMove; + $item['allowDrag'] = $allowMove && ($node->getLevel() == 0 ? false : true); + + if ((int)$node->getChildrenCount() > 0) { + $item['children'] = []; + } + + $isParent = $this->isParentSelectedCategory($node); + + if ($node->hasChildren()) { + $item['children'] = []; + if (!($this->getUseAjax() && $node->getLevel() > 1 && !$isParent)) { + foreach ($node->getChildren() as $child) { + $item['children'][] = $this->getNodeJson($child, $level + 1); + } + } + } + + if ($isParent || $node->getLevel() < 2) { + $item['expanded'] = true; + } + + return $item; + } + + /** + * Get Category Name + * + * @param \Magento\Framework\DataObject $node + * @return string + */ + public function buildNodeName($node) + { + $result = $this->escapeHtml($node->getName()); + return $result; + } + + /** + * @param Node|array $node + * @return bool + */ + protected function isCategoryMoveable($node) + { + $options = new \Magento\Framework\DataObject(['is_moveable' => true, 'category' => $node]); + $this->_eventManager->dispatch('adminhtml_mageplaza_blog_category_tree_is_moveable', ['options' => $options]); + return $options->getIsMoveable(); + } + + /** + * @param \Magento\Framework\Data\Tree\Node $node + * @return bool + */ + protected function isParentSelectedCategory($node) + { + if ($node && $this->getCategory()) { + $pathIds = $this->getCategory()->getPathIds(); + if (in_array($node->getId(), $pathIds)) { + return true; + } + } + + return false; + } + + /** + * Check if page loaded by outside link to Category edit + * + * @return boolean + */ + public function isClearEdit() + { + return (bool)$this->getRequest()->getParam('clear'); + } + + /** + * Check availability of adding root Category + * + * @return boolean + */ + public function canAddRootCategory() + { + $options = new \Magento\Framework\DataObject(['is_allow' => true]); + $this->_eventManager->dispatch( + 'adminhtml_mageplaza_blog_category_tree_can_add_root_category', + ['category' => $this->getCategory(), 'options' => $options] + ); + + return $options->getIsAllow(); + } + + /** + * Check availability of adding child Category + * + * @return boolean + */ + public function canAddChildCategory() + { + $options = new \Magento\Framework\DataObject(['is_allow' => true]); + $this->_eventManager->dispatch( + 'adminhtml_mageplaza_blog_category_tree_can_add_child_category', + ['category' => $this->getCategory(), 'options' => $options] + ); + + return $options->getIsAllow(); + } } diff --git a/Block/Adminhtml/Helper/Category.php b/Block/Adminhtml/Helper/Category.php index 4410eace..3a0fdcf3 100755 --- a/Block/Adminhtml/Helper/Category.php +++ b/Block/Adminhtml/Helper/Category.php @@ -2,155 +2,153 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Helper; class Category extends \Magento\Framework\Data\Form\Element\Multiselect { - /** - * Collection factory - * - * @var \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory - */ - protected $collectionFactory; + /** + * Collection factory + * + * @var \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory + */ + protected $collectionFactory; - /** - * Backend helper - * - * @var \Magento\Backend\Helper\Data - */ - protected $backendData; + /** + * Backend helper + * + * @var \Magento\Backend\Helper\Data + */ + protected $backendData; - /** - * Layout instance - * - * @var \Magento\Framework\View\LayoutInterface - */ - protected $layout; + /** + * Layout instance + * + * @var \Magento\Framework\View\LayoutInterface + */ + protected $layout; - /** - * Json encoder instance - * - * @var \Magento\Framework\Json\EncoderInterface - */ - protected $jsonEncoder; + /** + * Json encoder instance + * + * @var \Magento\Framework\Json\EncoderInterface + */ + protected $jsonEncoder; - /** - * Authorization - * - * @var \Magento\Framework\AuthorizationInterface - */ - protected $authorization; + /** + * Authorization + * + * @var \Magento\Framework\AuthorizationInterface + */ + protected $authorization; - /** - * constructor - * - * @param \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $collectionFactory - * @param \Magento\Backend\Helper\Data $backendData - * @param \Magento\Framework\View\LayoutInterface $layout - * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder - * @param \Magento\Framework\AuthorizationInterface $authorization - * @param \Magento\Framework\Data\Form\Element\Factory $factoryElement - * @param \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection - * @param \Magento\Framework\Escaper $escaper - * @param array $data - */ - public function __construct( - \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $collectionFactory, - \Magento\Backend\Helper\Data $backendData, - \Magento\Framework\View\LayoutInterface $layout, - \Magento\Framework\Json\EncoderInterface $jsonEncoder, - \Magento\Framework\AuthorizationInterface $authorization, - \Magento\Framework\Data\Form\Element\Factory $factoryElement, - \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection, - \Magento\Framework\Escaper $escaper, - array $data = [] - ) - { - $this->collectionFactory = $collectionFactory; - $this->backendData = $backendData; - $this->layout = $layout; - $this->jsonEncoder = $jsonEncoder; - $this->authorization = $authorization; - parent::__construct($factoryElement, $factoryCollection, $escaper, $data); - } + /** + * constructor + * + * @param \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $collectionFactory + * @param \Magento\Backend\Helper\Data $backendData + * @param \Magento\Framework\View\LayoutInterface $layout + * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder + * @param \Magento\Framework\AuthorizationInterface $authorization + * @param \Magento\Framework\Data\Form\Element\Factory $factoryElement + * @param \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection + * @param \Magento\Framework\Escaper $escaper + * @param array $data + */ + public function __construct( + \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $collectionFactory, + \Magento\Backend\Helper\Data $backendData, + \Magento\Framework\View\LayoutInterface $layout, + \Magento\Framework\Json\EncoderInterface $jsonEncoder, + \Magento\Framework\AuthorizationInterface $authorization, + \Magento\Framework\Data\Form\Element\Factory $factoryElement, + \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection, + \Magento\Framework\Escaper $escaper, + array $data = [] + ) + { + $this->collectionFactory = $collectionFactory; + $this->backendData = $backendData; + $this->layout = $layout; + $this->jsonEncoder = $jsonEncoder; + $this->authorization = $authorization; + parent::__construct($factoryElement, $factoryCollection, $escaper, $data); + } - /** - * Get no display - * - * @return bool - */ - public function getNoDisplay() - { - $isNotAllowed = !$this->authorization->isAllowed('Mageplaza_Blog::category'); + /** + * Get no display + * + * @return bool + */ + public function getNoDisplay() + { + $isNotAllowed = !$this->authorization->isAllowed('Mageplaza_Blog::category'); + return $this->getData('no_display') || $isNotAllowed; + } - return $this->getData('no_display') || $isNotAllowed; - } + /** + * Get values for select + * + * @return array + */ + public function getValues() + { + $collection = $this->getCategoriesCollection(); + $values = $this->getValue(); + if (!is_array($values)) { + $values = explode(',', $values); + } + $collection->addIdFilter($values); + $options = []; + foreach ($collection as $category) { + /** @var \Mageplaza\Blog\Model\Category $category */ + $options[] = ['label' => $category->getName(), 'value' => $category->getId()]; + } + return $options; + } - /** - * Get values for select - * - * @return array - */ - public function getValues() - { - $collection = $this->getCategoriesCollection(); - $values = $this->getValue(); - if (!is_array($values)) { - $values = explode(',', $values); - } - $collection->addIdFilter($values); - $options = []; - foreach ($collection as $category) { - /** @var \Mageplaza\Blog\Model\Category $category */ - $options[] = ['label' => $category->getName(), 'value' => $category->getId()]; - } + /** + * Get Category collection + * + * @return \Mageplaza\Blog\Model\ResourceModel\Category\Collection + */ + protected function getCategoriesCollection() + { + return $this->collectionFactory->create(); + } - return $options; - } - - /** - * Get Category collection - * - * @return \Mageplaza\Blog\Model\ResourceModel\Category\Collection - */ - protected function getCategoriesCollection() - { - return $this->collectionFactory->create(); - } - - /** - * Attach Category suggest widget initialization - * - * @return string - */ - public function getAfterElementHtml() - { - $htmlId = $this->getHtmlId(); - $suggestPlaceholder = __('start typing to search Category'); - $selectorOptions = $this->jsonEncoder->encode($this->getSelectorOptions()); - $newCategoryCaption = __('New Category'); - /** @var \Magento\Backend\Block\Widget\Button $button */ - $button = $this->layout->createBlock('Magento\Backend\Block\Widget\Button') - ->setData([ - 'id' => 'add_category_button', - 'label' => $newCategoryCaption, - 'title' => $newCategoryCaption, - 'onclick' => 'jQuery("#new-category").trigger("openModal")', - 'disabled' => $this->getDisabled() - ]); - //TODO: move this somewhere else when magento team decides to move it. - $return = <<getHtmlId(); + $suggestPlaceholder = __('start typing to search Category'); + $selectorOptions = $this->jsonEncoder->encode($this->getSelectorOptions()); + $newCategoryCaption = __('New Category'); + /** @var \Magento\Backend\Block\Widget\Button $button */ + $button = $this->layout->createBlock('Magento\Backend\Block\Widget\Button') + ->setData([ + 'id' => 'add_category_button', + 'label' => $newCategoryCaption, + 'title' => $newCategoryCaption, + 'onclick' => 'jQuery("#new-category").trigger("openModal")', + 'disabled' => $this->getDisabled() + ]); + //TODO: move this somewhere else when magento team decides to move it. + $return = <<
HTML; + return $return . $button->toHtml(); + } - return $return . $button->toHtml(); - } - - /** - * Get selector options - * - * @return array - */ - protected function getSelectorOptions() - { - return array( - 'source' => $this->backendData->getUrl('mageplaza_blog/category/suggestCategories'), - 'valueField' => '#' . $this->getHtmlId(), - 'className' => 'category-select', - 'multiselect' => true, - 'showAll' => true - ); - } + /** + * Get selector options + * + * @return array + */ + protected function getSelectorOptions() + { + return array( + 'source' => $this->backendData->getUrl('mageplaza_blog/category/suggestCategories'), + 'valueField' => '#' . $this->getHtmlId(), + 'className' => 'category-select', + 'multiselect' => true, + 'showAll' => true + ); + } } diff --git a/Block/Adminhtml/Post.php b/Block/Adminhtml/Post.php index de517a26..b3afb1f6 100755 --- a/Block/Adminhtml/Post.php +++ b/Block/Adminhtml/Post.php @@ -2,32 +2,32 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml; class Post extends \Magento\Backend\Block\Widget\Grid\Container { - /** - * constructor - * - * @return void - */ - protected function _construct() - { - $this->_controller = 'adminhtml_post'; - $this->_blockGroup = 'Mageplaza_Blog'; - $this->_headerText = __('Posts'); - $this->_addButtonLabel = __('Create New Post'); - parent::_construct(); - } + /** + * constructor + * + * @return void + */ + protected function _construct() + { + $this->_controller = 'adminhtml_post'; + $this->_blockGroup = 'Mageplaza_Blog'; + $this->_headerText = __('Posts'); + $this->_addButtonLabel = __('Create New Post'); + parent::_construct(); + } } diff --git a/Block/Adminhtml/Post/Edit.php b/Block/Adminhtml/Post/Edit.php index 342523b1..5bead302 100755 --- a/Block/Adminhtml/Post/Edit.php +++ b/Block/Adminhtml/Post/Edit.php @@ -2,89 +2,87 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Post; class Edit extends \Magento\Backend\Block\Widget\Form\Container { - /** - * Core registry - * - * @var \Magento\Framework\Registry - */ - protected $coreRegistry; + /** + * Core registry + * + * @var \Magento\Framework\Registry + */ + protected $coreRegistry; - /** - * constructor - * - * @param \Magento\Framework\Registry $coreRegistry - * @param \Magento\Backend\Block\Widget\Context $context - * @param array $data - */ - public function __construct( - \Magento\Framework\Registry $coreRegistry, - \Magento\Backend\Block\Widget\Context $context, - array $data = [] - ) - { - $this->coreRegistry = $coreRegistry; - parent::__construct($context, $data); - } + /** + * constructor + * + * @param \Magento\Framework\Registry $coreRegistry + * @param \Magento\Backend\Block\Widget\Context $context + * @param array $data + */ + public function __construct( + \Magento\Framework\Registry $coreRegistry, + \Magento\Backend\Block\Widget\Context $context, + array $data = [] + ) + { + $this->coreRegistry = $coreRegistry; + parent::__construct($context, $data); + } - /** - * Initialize Post edit block - * - * @return void - */ - protected function _construct() - { - $this->_objectId = 'post_id'; - $this->_blockGroup = 'Mageplaza_Blog'; - $this->_controller = 'adminhtml_post'; - parent::_construct(); - $this->buttonList->update('save', 'label', __('Save Post')); - $this->buttonList->add( - 'save-and-continue', - [ - 'label' => __('Save and Continue Edit'), - 'class' => 'save', - 'data_attribute' => [ - 'mage-init' => [ - 'button' => [ - 'event' => 'saveAndContinueEdit', - 'target' => '#edit_form' - ] - ] - ] - ], - -100 - ); - $this->buttonList->update('delete', 'label', __('Delete Post')); - } - - /** - * Retrieve text for header element depending on loaded Post - * - * @return string - */ - public function getHeaderText() - { - /** @var \Mageplaza\Blog\Model\Post $post */ - $post = $this->coreRegistry->registry('mageplaza_blog_post'); - if ($post->getId()) { - return __("Edit Post '%1'", $this->escapeHtml($post->getName())); - } - - return __('New Post'); - } + /** + * Initialize Post edit block + * + * @return void + */ + protected function _construct() + { + $this->_objectId = 'post_id'; + $this->_blockGroup = 'Mageplaza_Blog'; + $this->_controller = 'adminhtml_post'; + parent::_construct(); + $this->buttonList->update('save', 'label', __('Save Post')); + $this->buttonList->add( + 'save-and-continue', + [ + 'label' => __('Save and Continue Edit'), + 'class' => 'save', + 'data_attribute' => [ + 'mage-init' => [ + 'button' => [ + 'event' => 'saveAndContinueEdit', + 'target' => '#edit_form' + ] + ] + ] + ], + -100 + ); + $this->buttonList->update('delete', 'label', __('Delete Post')); + } + /** + * Retrieve text for header element depending on loaded Post + * + * @return string + */ + public function getHeaderText() + { + /** @var \Mageplaza\Blog\Model\Post $post */ + $post = $this->coreRegistry->registry('mageplaza_blog_post'); + if ($post->getId()) { + return __("Edit Post '%1'", $this->escapeHtml($post->getName())); + } + return __('New Post'); + } } diff --git a/Block/Adminhtml/Post/Edit/Form.php b/Block/Adminhtml/Post/Edit/Form.php index c84990e7..5bc26de7 100755 --- a/Block/Adminhtml/Post/Edit/Form.php +++ b/Block/Adminhtml/Post/Edit/Form.php @@ -2,42 +2,41 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Post\Edit; class Form extends \Magento\Backend\Block\Widget\Form\Generic { - /** - * Prepare form - * - * @return $this - */ - protected function _prepareForm() - { - /** @var \Magento\Framework\Data\Form $form */ - $form = $this->_formFactory->create( - [ - 'data' => [ - 'id' => 'edit_form', - 'action' => $this->getData('action'), - 'method' => 'post', - 'enctype' => 'multipart/form-data' - ] - ] - ); - $form->setUseContainer(true); - $this->setForm($form); - - return parent::_prepareForm(); - } + /** + * Prepare form + * + * @return $this + */ + protected function _prepareForm() + { + /** @var \Magento\Framework\Data\Form $form */ + $form = $this->_formFactory->create( + [ + 'data' => [ + 'id' => 'edit_form', + 'action' => $this->getData('action'), + 'method' => 'post', + 'enctype' => 'multipart/form-data' + ] + ] + ); + $form->setUseContainer(true); + $this->setForm($form); + return parent::_prepareForm(); + } } diff --git a/Block/Adminhtml/Post/Edit/Tab/Category.php b/Block/Adminhtml/Post/Edit/Tab/Category.php index 48689ceb..01ab3389 100755 --- a/Block/Adminhtml/Post/Edit/Tab/Category.php +++ b/Block/Adminhtml/Post/Edit/Tab/Category.php @@ -2,97 +2,96 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab; class Category extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Backend\Block\Widget\Tab\TabInterface { - /** - * Prepare form - * - * @return $this - */ - protected function _prepareForm() - { - /** @var \Mageplaza\Blog\Model\Post $post */ - $post = $this->_coreRegistry->registry('mageplaza_blog_post'); - $form = $this->_formFactory->create(); - $form->setHtmlIdPrefix('post_'); - $form->setFieldNameSuffix('post'); - $fieldset = $form->addFieldset( - 'base_fieldset', - [ - 'legend' => __('Categories'), - 'class' => 'fieldset-wide' - ] - ); - $fieldset->addField( - 'categories_ids', - '\Mageplaza\Blog\Block\Adminhtml\Helper\Category', - [ - 'name' => 'categories_ids', - 'label' => __('Categories'), - 'title' => __('Categories'), - ] - ); + /** + * Prepare form + * + * @return $this + */ + protected function _prepareForm() + { + /** @var \Mageplaza\Blog\Model\Post $post */ + $post = $this->_coreRegistry->registry('mageplaza_blog_post'); + $form = $this->_formFactory->create(); + $form->setHtmlIdPrefix('post_'); + $form->setFieldNameSuffix('post'); + $fieldset = $form->addFieldset( + 'base_fieldset', + [ + 'legend'=>__('Categories'), + 'class' => 'fieldset-wide' + ] + ); + $fieldset->addField( + 'categories_ids', + '\Mageplaza\Blog\Block\Adminhtml\Helper\Category', + [ + 'name' => 'categories_ids', + 'label' => __('Categories'), + 'title' => __('Categories'), + ] + ); - if (is_null($post->getCategoriesIds())) { - $post->setCategoriesIds($post->getCategoryIds()); - } - $form->addValues($post->getData()); - $this->setForm($form); + if (is_null($post->getCategoriesIds())) { + $post->setCategoriesIds($post->getCategoryIds()); + } + $form->addValues($post->getData()); + $this->setForm($form); + return parent::_prepareForm(); + } - return parent::_prepareForm(); - } + /** + * Prepare label for tab + * + * @return string + */ + public function getTabLabel() + { + return __('Categories'); + } - /** - * Prepare label for tab - * - * @return string - */ - public function getTabLabel() - { - return __('Categories'); - } + /** + * Prepare title for tab + * + * @return string + */ + public function getTabTitle() + { + return $this->getTabLabel(); + } - /** - * Prepare title for tab - * - * @return string - */ - public function getTabTitle() - { - return $this->getTabLabel(); - } + /** + * Can show tab in tabs + * + * @return boolean + */ + public function canShowTab() + { + return true; + } - /** - * Can show tab in tabs - * - * @return boolean - */ - public function canShowTab() - { - return true; - } - - /** - * Tab is hidden - * - * @return boolean - */ - public function isHidden() - { - return false; - } + /** + * Tab is hidden + * + * @return boolean + */ + public function isHidden() + { + return false; + } } diff --git a/Block/Adminhtml/Post/Edit/Tab/Post.php b/Block/Adminhtml/Post/Edit/Tab/Post.php index 50f7d1a0..76a337e7 100755 --- a/Block/Adminhtml/Post/Edit/Tab/Post.php +++ b/Block/Adminhtml/Post/Edit/Tab/Post.php @@ -2,266 +2,265 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab; class Post extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Backend\Block\Widget\Tab\TabInterface { - /** - * Wysiwyg config - * - * @var \Magento\Cms\Model\Wysiwyg\Config - */ - protected $wysiwygConfig; + /** + * Wysiwyg config + * + * @var \Magento\Cms\Model\Wysiwyg\Config + */ + protected $wysiwygConfig; - /** - * Country options - * - * @var \Magento\Config\Model\Config\Source\Yesno - */ - protected $booleanOptions; + /** + * Country options + * + * @var \Magento\Config\Model\Config\Source\Yesno + */ + protected $booleanOptions; - /** - * Meta Robots options - * - * @var \Mageplaza\Blog\Model\Post\Source\MetaRobots - */ - protected $metaRobotsOptions; + /** + * Meta Robots options + * + * @var \Mageplaza\Blog\Model\Post\Source\MetaRobots + */ + protected $metaRobotsOptions; - /** - * constructor - * - * @param \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig - * @param \Magento\Config\Model\Config\Source\Yesno $booleanOptions - * @param \Mageplaza\Blog\Model\Post\Source\MetaRobots $metaRobotsOptions - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Data\FormFactory $formFactory - * @param array $data - */ - public function __construct( - \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig, - \Magento\Config\Model\Config\Source\Yesno $booleanOptions, - \Mageplaza\Blog\Model\Post\Source\MetaRobots $metaRobotsOptions, - \Magento\Backend\Block\Template\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Data\FormFactory $formFactory, - array $data = [] - ) - { - $this->wysiwygConfig = $wysiwygConfig; - $this->booleanOptions = $booleanOptions; - $this->metaRobotsOptions = $metaRobotsOptions; - parent::__construct($context, $registry, $formFactory, $data); - } + /** + * constructor + * + * @param \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig + * @param \Magento\Config\Model\Config\Source\Yesno $booleanOptions + * @param \Mageplaza\Blog\Model\Post\Source\MetaRobots $metaRobotsOptions + * @param \Magento\Backend\Block\Template\Context $context + * @param \Magento\Framework\Registry $registry + * @param \Magento\Framework\Data\FormFactory $formFactory + * @param array $data + */ + public function __construct( + \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig, + \Magento\Config\Model\Config\Source\Yesno $booleanOptions, + \Mageplaza\Blog\Model\Post\Source\MetaRobots $metaRobotsOptions, + \Magento\Backend\Block\Template\Context $context, + \Magento\Framework\Registry $registry, + \Magento\Framework\Data\FormFactory $formFactory, + array $data = [] + ) + { + $this->wysiwygConfig = $wysiwygConfig; + $this->booleanOptions = $booleanOptions; + $this->metaRobotsOptions = $metaRobotsOptions; + parent::__construct($context, $registry, $formFactory, $data); + } - /** - * Prepare form - * - * @return $this - */ - protected function _prepareForm() - { - /** @var \Mageplaza\Blog\Model\Post $post */ - $post = $this->_coreRegistry->registry('mageplaza_blog_post'); - $form = $this->_formFactory->create(); - $form->setHtmlIdPrefix('post_'); - $form->setFieldNameSuffix('post'); - $fieldset = $form->addFieldset( - 'base_fieldset', - [ - 'legend' => __('Post Information'), - 'class' => 'fieldset-wide' - ] - ); - $fieldset->addType('image', 'Mageplaza\Blog\Block\Adminhtml\Post\Helper\Image'); - if ($post->getId()) { - $fieldset->addField( - 'post_id', - 'hidden', - ['name' => 'post_id'] - ); - } - $fieldset->addField( - 'name', - 'text', - [ - 'name' => 'name', - 'label' => __('Name'), - 'title' => __('Name'), - 'required' => true, - 'note' => __('Post name'), - ] - ); - $fieldset->addField( - 'short_description', - 'textarea', - [ - 'name' => 'short_description', - 'label' => __('Short Description'), - 'title' => __('Short Description'), - 'note' => __('Short Description'), - ] - ); - $fieldset->addField( - 'post_content', - 'editor', - [ - 'name' => 'post_content', - 'label' => __('Content'), - 'title' => __('Content'), - 'note' => __('Post Content'), - 'config' => $this->wysiwygConfig->getConfig() - ] - ); - $fieldset->addField( - 'image', - 'image', - [ - 'name' => 'image', - 'label' => __('Image'), - 'title' => __('Image'), - 'note' => __('Featured image'), - ] - ); - $fieldset->addField( - 'enabled', - 'select', - [ - 'name' => 'enabled', - 'label' => __('Enabled'), - 'title' => __('Enabled'), - 'values' => $this->booleanOptions->toOptionArray(), - ] - ); - $fieldset->addField( - 'url_key', - 'text', - [ - 'name' => 'url_key', - 'label' => __('URL Key'), - 'title' => __('URL Key'), - ] - ); - $fieldset->addField( - 'in_rss', - 'select', - [ - 'name' => 'in_rss', - 'label' => __('In RSS'), - 'title' => __('In RSS'), - 'values' => $this->booleanOptions->toOptionArray(), - ] - ); - $fieldset->addField( - 'allow_comment', - 'select', - [ - 'name' => 'allow_comment', - 'label' => __('Allow Comment'), - 'title' => __('Allow Comment'), - 'values' => $this->booleanOptions->toOptionArray(), - ] - ); - $fieldset->addField( - 'meta_title', - 'text', - [ - 'name' => 'meta_title', - 'label' => __('Meta Title'), - 'title' => __('Meta Title'), - ] - ); - $fieldset->addField( - 'meta_description', - 'textarea', - [ - 'name' => 'meta_description', - 'label' => __('Meta Description'), - 'title' => __('Meta Description'), - ] - ); - $fieldset->addField( - 'meta_keywords', - 'textarea', - [ - 'name' => 'meta_keywords', - 'label' => __('Meta Keywords'), - 'title' => __('Meta Keywords'), - ] - ); - $fieldset->addField( - 'meta_robots', - 'select', - [ - 'name' => 'meta_robots', - 'label' => __('Meta Robots'), - 'title' => __('Meta Robots'), - 'values' => array_merge(['' => ''], $this->metaRobotsOptions->toOptionArray()), - ] - ); + /** + * Prepare form + * + * @return $this + */ + protected function _prepareForm() + { + /** @var \Mageplaza\Blog\Model\Post $post */ + $post = $this->_coreRegistry->registry('mageplaza_blog_post'); + $form = $this->_formFactory->create(); + $form->setHtmlIdPrefix('post_'); + $form->setFieldNameSuffix('post'); + $fieldset = $form->addFieldset( + 'base_fieldset', + [ + 'legend' => __('Post Information'), + 'class' => 'fieldset-wide' + ] + ); + $fieldset->addType('image', 'Mageplaza\Blog\Block\Adminhtml\Post\Helper\Image'); + if ($post->getId()) { + $fieldset->addField( + 'post_id', + 'hidden', + ['name' => 'post_id'] + ); + } + $fieldset->addField( + 'name', + 'text', + [ + 'name' => 'name', + 'label' => __('Name'), + 'title' => __('Name'), + 'required' => true, + 'note' => __('Post name'), + ] + ); + $fieldset->addField( + 'short_description', + 'textarea', + [ + 'name' => 'short_description', + 'label' => __('Short Description'), + 'title' => __('Short Description'), + 'note' => __('Short Description'), + ] + ); + $fieldset->addField( + 'post_content', + 'editor', + [ + 'name' => 'post_content', + 'label' => __('Content'), + 'title' => __('Content'), + 'note' => __('Post Content'), + 'config' => $this->wysiwygConfig->getConfig() + ] + ); + $fieldset->addField( + 'image', + 'image', + [ + 'name' => 'image', + 'label' => __('Image'), + 'title' => __('Image'), + 'note' => __('Featured image'), + ] + ); + $fieldset->addField( + 'enabled', + 'select', + [ + 'name' => 'enabled', + 'label' => __('Enabled'), + 'title' => __('Enabled'), + 'values' => $this->booleanOptions->toOptionArray(), + ] + ); + $fieldset->addField( + 'url_key', + 'text', + [ + 'name' => 'url_key', + 'label' => __('URL Key'), + 'title' => __('URL Key'), + ] + ); + $fieldset->addField( + 'in_rss', + 'select', + [ + 'name' => 'in_rss', + 'label' => __('In RSS'), + 'title' => __('In RSS'), + 'values' => $this->booleanOptions->toOptionArray(), + ] + ); + $fieldset->addField( + 'allow_comment', + 'select', + [ + 'name' => 'allow_comment', + 'label' => __('Allow Comment'), + 'title' => __('Allow Comment'), + 'values' => $this->booleanOptions->toOptionArray(), + ] + ); + $fieldset->addField( + 'meta_title', + 'text', + [ + 'name' => 'meta_title', + 'label' => __('Meta Title'), + 'title' => __('Meta Title'), + ] + ); + $fieldset->addField( + 'meta_description', + 'textarea', + [ + 'name' => 'meta_description', + 'label' => __('Meta Description'), + 'title' => __('Meta Description'), + ] + ); + $fieldset->addField( + 'meta_keywords', + 'textarea', + [ + 'name' => 'meta_keywords', + 'label' => __('Meta Keywords'), + 'title' => __('Meta Keywords'), + ] + ); + $fieldset->addField( + 'meta_robots', + 'select', + [ + 'name' => 'meta_robots', + 'label' => __('Meta Robots'), + 'title' => __('Meta Robots'), + 'values' => array_merge(['' => ''], $this->metaRobotsOptions->toOptionArray()), + ] + ); - $postData = $this->_session->getData('mageplaza_blog_post_data', true); - if ($postData) { - $post->addData($postData); - } else { - if (!$post->getId()) { - $post->addData($post->getDefaultValues()); - } - } - $form->addValues($post->getData()); - $this->setForm($form); + $postData = $this->_session->getData('mageplaza_blog_post_data', true); + if ($postData) { + $post->addData($postData); + } else { + if (!$post->getId()) { + $post->addData($post->getDefaultValues()); + } + } + $form->addValues($post->getData()); + $this->setForm($form); + return parent::_prepareForm(); + } - return parent::_prepareForm(); - } + /** + * Prepare label for tab + * + * @return string + */ + public function getTabLabel() + { + return __('Post'); + } - /** - * Prepare label for tab - * - * @return string - */ - public function getTabLabel() - { - return __('Post'); - } + /** + * Prepare title for tab + * + * @return string + */ + public function getTabTitle() + { + return $this->getTabLabel(); + } - /** - * Prepare title for tab - * - * @return string - */ - public function getTabTitle() - { - return $this->getTabLabel(); - } + /** + * Can show tab in tabs + * + * @return boolean + */ + public function canShowTab() + { + return true; + } - /** - * Can show tab in tabs - * - * @return boolean - */ - public function canShowTab() - { - return true; - } - - /** - * Tab is hidden - * - * @return boolean - */ - public function isHidden() - { - return false; - } + /** + * Tab is hidden + * + * @return boolean + */ + public function isHidden() + { + return false; + } } diff --git a/Block/Adminhtml/Post/Edit/Tab/Tag.php b/Block/Adminhtml/Post/Edit/Tab/Tag.php index 42f89712..297727d1 100755 --- a/Block/Adminhtml/Post/Edit/Tab/Tag.php +++ b/Block/Adminhtml/Post/Edit/Tab/Tag.php @@ -2,305 +2,302 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab; class Tag extends \Magento\Backend\Block\Widget\Grid\Extended implements \Magento\Backend\Block\Widget\Tab\TabInterface { - /** - * Tag collection factory - * - * @var \Mageplaza\Blog\Model\ResourceModel\Tag\CollectionFactory - */ - protected $tagCollectionFactory; + /** + * Tag collection factory + * + * @var \Mageplaza\Blog\Model\ResourceModel\Tag\CollectionFactory + */ + protected $tagCollectionFactory; - /** - * Registry - * - * @var \Magento\Framework\Registry - */ - protected $coreRegistry; + /** + * Registry + * + * @var \Magento\Framework\Registry + */ + protected $coreRegistry; - /** - * Tag factory - * - * @var \Mageplaza\Blog\Model\TagFactory - */ - protected $tagFactory; + /** + * Tag factory + * + * @var \Mageplaza\Blog\Model\TagFactory + */ + protected $tagFactory; - /** - * constructor - * - * @param \Mageplaza\Blog\Model\ResourceModel\Tag\CollectionFactory $tagCollectionFactory - * @param \Magento\Framework\Registry $coreRegistry - * @param \Mageplaza\Blog\Model\TagFactory $tagFactory - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\Backend\Helper\Data $backendHelper - * @param array $data - */ - public function __construct( - \Mageplaza\Blog\Model\ResourceModel\Tag\CollectionFactory $tagCollectionFactory, - \Magento\Framework\Registry $coreRegistry, - \Mageplaza\Blog\Model\TagFactory $tagFactory, - \Magento\Backend\Block\Template\Context $context, - \Magento\Backend\Helper\Data $backendHelper, - array $data = [] - ) - { - $this->tagCollectionFactory = $tagCollectionFactory; - $this->coreRegistry = $coreRegistry; - $this->tagFactory = $tagFactory; - parent::__construct($context, $backendHelper, $data); - } + /** + * constructor + * + * @param \Mageplaza\Blog\Model\ResourceModel\Tag\CollectionFactory $tagCollectionFactory + * @param \Magento\Framework\Registry $coreRegistry + * @param \Mageplaza\Blog\Model\TagFactory $tagFactory + * @param \Magento\Backend\Block\Template\Context $context + * @param \Magento\Backend\Helper\Data $backendHelper + * @param array $data + */ + public function __construct( + \Mageplaza\Blog\Model\ResourceModel\Tag\CollectionFactory $tagCollectionFactory, + \Magento\Framework\Registry $coreRegistry, + \Mageplaza\Blog\Model\TagFactory $tagFactory, + \Magento\Backend\Block\Template\Context $context, + \Magento\Backend\Helper\Data $backendHelper, + array $data = [] + ) + { + $this->tagCollectionFactory = $tagCollectionFactory; + $this->coreRegistry = $coreRegistry; + $this->tagFactory = $tagFactory; + parent::__construct($context, $backendHelper, $data); + } - /** - * Set grid params - */ - public function _construct() - { - parent::_construct(); - $this->setId('tag_grid'); - $this->setDefaultSort('position'); - $this->setDefaultDir('ASC'); - $this->setUseAjax(true); - if ($this->getPost()->getId()) { - $this->setDefaultFilter(['in_tags' => 1]); - } - } + /** + * Set grid params + */ + public function _construct() + { + parent::_construct(); + $this->setId('tag_grid'); + $this->setDefaultSort('position'); + $this->setDefaultDir('ASC'); + $this->setUseAjax(true); + if ($this->getPost()->getId()) { + $this->setDefaultFilter(['in_tags'=>1]); + } + } - /** - * prepare the collection - * @return $this - */ - protected function _prepareCollection() - { - /** @var \Mageplaza\Blog\Model\ResourceModel\Tag\Collection $collection */ - $collection = $this->tagCollectionFactory->create(); - if ($this->getPost()->getId()) { - $constraint = 'related.post_id=' . $this->getPost()->getId(); - } else { - $constraint = 'related.post_id=0'; - } - $collection->getSelect()->joinLeft( - array('related' => $collection->getTable('mageplaza_blog_post_tag')), - 'related.tag_id=main_table.tag_id AND ' . $constraint, - array('position') - ); - $this->setCollection($collection); - parent::_prepareCollection(); + /** + * prepare the collection - return $this; - } + * @return $this + */ + protected function _prepareCollection() + { + /** @var \Mageplaza\Blog\Model\ResourceModel\Tag\Collection $collection */ + $collection = $this->tagCollectionFactory->create(); + if ($this->getPost()->getId()) { + $constraint = 'related.post_id='.$this->getPost()->getId(); + } else { + $constraint = 'related.post_id=0'; + } + $collection->getSelect()->joinLeft( + array('related' => $collection->getTable('mageplaza_blog_post_tag')), + 'related.tag_id=main_table.tag_id AND '.$constraint, + array('position') + ); + $this->setCollection($collection); + parent::_prepareCollection(); + return $this; + } - /** - * @return $this - */ - protected function _prepareMassaction() - { - return $this; - } + /** + * @return $this + */ + protected function _prepareMassaction() + { + return $this; + } - /** - * @return $this - */ - protected function _prepareColumns() - { - $this->addColumn( - 'in_tags', - [ - 'header_css_class' => 'a-center', - 'type' => 'checkbox', - 'name' => 'in_tag', - 'values' => $this->_getSelectedTags(), - 'align' => 'center', - 'index' => 'tag_id' - ] - ); - $this->addColumn( - 'tag_id', - [ - 'header' => __('ID'), - 'sortable' => true, - 'index' => 'tag_id', - 'type' => 'number', - 'header_css_class' => 'col-id', - 'column_css_class' => 'col-id' - ] - ); + /** + * @return $this + */ + protected function _prepareColumns() + { + $this->addColumn( + 'in_tags', + [ + 'header_css_class' => 'a-center', + 'type' => 'checkbox', + 'name' => 'in_tag', + 'values' => $this->_getSelectedTags(), + 'align' => 'center', + 'index' => 'tag_id' + ] + ); + $this->addColumn( + 'tag_id', + [ + 'header' => __('ID'), + 'sortable' => true, + 'index' => 'tag_id', + 'type' => 'number', + 'header_css_class' => 'col-id', + 'column_css_class' => 'col-id' + ] + ); - $this->addColumn( - 'title', - [ - 'header' => __('Name'), - 'index' => 'name', - 'header_css_class' => 'col-name', - 'column_css_class' => 'col-name' - ] - ); + $this->addColumn( + 'title', + [ + 'header' => __('Name'), + 'index' => 'name', + 'header_css_class' => 'col-name', + 'column_css_class' => 'col-name' + ] + ); - $this->addColumn( - 'position', - [ - 'header' => __('Position'), - 'name' => 'position', - 'width' => 60, - 'type' => 'number', - 'validate_class' => 'validate-number', - 'index' => 'position', - 'editable' => true, - ] - ); + $this->addColumn( + 'position', + [ + 'header' => __('Position'), + 'name' => 'position', + 'width' => 60, + 'type' => 'number', + 'validate_class' => 'validate-number', + 'index' => 'position', + 'editable' => true, + ] + ); + return $this; + } - return $this; - } + /** + * Retrieve selected Tags - /** - * Retrieve selected Tags - * @return array - */ - protected function _getSelectedTags() - { - $tags = $this->getPostTags(); - if (!is_array($tags)) { - $tags = $this->getPost()->getTagsPosition(); + * @return array + */ + protected function _getSelectedTags() + { + $tags = $this->getPostTags(); + if (!is_array($tags)) { + $tags = $this->getPost()->getTagsPosition(); + return array_keys($tags); + } + return $tags; + } - return array_keys($tags); - } + /** + * Retrieve selected Tags - return $tags; - } + * @return array + */ + public function getSelectedTags() + { + $selected = $this->getPost()->getTagsPosition(); + if (!is_array($selected)) { + $selected = []; + } else { + foreach ($selected as $key => $value) { + $selected[$key] = ['position' => $value]; + } + } + return $selected; + } - /** - * Retrieve selected Tags - * @return array - */ - public function getSelectedTags() - { - $selected = $this->getPost()->getTagsPosition(); - if (!is_array($selected)) { - $selected = []; - } else { - foreach ($selected as $key => $value) { - $selected[$key] = ['position' => $value]; - } - } + /** + * @param \Mageplaza\Blog\Model\Tag|\Magento\Framework\Object $item + * @return string + */ + public function getRowUrl($item) + { + return '#'; + } - return $selected; - } + /** + * get grid url + * + * @return string + */ + public function getGridUrl() + { + return $this->getUrl( + '*/*/tagsGrid', + [ + 'post_id' => $this->getPost()->getId() + ] + ); + } - /** - * @param \Mageplaza\Blog\Model\Tag|\Magento\Framework\Object $item - * @return string - */ - public function getRowUrl($item) - { - return '#'; - } + /** + * @return \Mageplaza\Blog\Model\Post + */ + public function getPost() + { + return $this->coreRegistry->registry('mageplaza_blog_post'); + } - /** - * get grid url - * - * @return string - */ - public function getGridUrl() - { - return $this->getUrl( - '*/*/tagsGrid', - [ - 'post_id' => $this->getPost()->getId() - ] - ); - } + /** + * @param \Magento\Backend\Block\Widget\Grid\Column $column + * @return $this + */ + protected function _addColumnFilterToCollection($column) + { + if ($column->getId() == 'in_tags') { + $tagIds = $this->_getSelectedTags(); + if (empty($tagIds)) { + $tagIds = 0; + } + if ($column->getFilter()->getValue()) { + $this->getCollection()->addFieldToFilter('main_table.tag_id', ['in'=>$tagIds]); + } else { + if ($tagIds) { + $this->getCollection()->addFieldToFilter('main_table.tag_id', ['nin'=>$tagIds]); + } + } + } else { + parent::_addColumnFilterToCollection($column); + } + return $this; + } - /** - * @return \Mageplaza\Blog\Model\Post - */ - public function getPost() - { - return $this->coreRegistry->registry('mageplaza_blog_post'); - } + /** + * @return string + */ + public function getTabLabel() + { + return __('Tags'); + } - /** - * @param \Magento\Backend\Block\Widget\Grid\Column $column - * @return $this - */ - protected function _addColumnFilterToCollection($column) - { - if ($column->getId() == 'in_tags') { - $tagIds = $this->_getSelectedTags(); - if (empty($tagIds)) { - $tagIds = 0; - } - if ($column->getFilter()->getValue()) { - $this->getCollection()->addFieldToFilter('main_table.tag_id', ['in' => $tagIds]); - } else { - if ($tagIds) { - $this->getCollection()->addFieldToFilter('main_table.tag_id', ['nin' => $tagIds]); - } - } - } else { - parent::_addColumnFilterToCollection($column); - } + /** + * @return bool + */ + public function isHidden() + { + return false; + } - return $this; - } + /** + * @return string + */ + public function getTabTitle() + { + return $this->getTabLabel(); + } - /** - * @return string - */ - public function getTabLabel() - { - return __('Tags'); - } + /** + * @return bool + */ + public function canShowTab() + { + return true; + } - /** - * @return bool - */ - public function isHidden() - { - return false; - } + /** + * @return string + */ + public function getTabUrl() + { + return $this->getUrl('mageplaza_blog/post/tags', ['_current' => true]); + } - /** - * @return string - */ - public function getTabTitle() - { - return $this->getTabLabel(); - } - - /** - * @return bool - */ - public function canShowTab() - { - return true; - } - - /** - * @return string - */ - public function getTabUrl() - { - return $this->getUrl('mageplaza_blog/post/tags', ['_current' => true]); - } - - /** - * @return string - */ - public function getTabClass() - { - return 'ajax only'; - } + /** + * @return string + */ + public function getTabClass() + { + return 'ajax only'; + } } diff --git a/Block/Adminhtml/Post/Edit/Tab/Topic.php b/Block/Adminhtml/Post/Edit/Tab/Topic.php index d28656d9..d4dbc962 100755 --- a/Block/Adminhtml/Post/Edit/Tab/Topic.php +++ b/Block/Adminhtml/Post/Edit/Tab/Topic.php @@ -2,305 +2,302 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Post\Edit\Tab; class Topic extends \Magento\Backend\Block\Widget\Grid\Extended implements \Magento\Backend\Block\Widget\Tab\TabInterface { - /** - * Topic collection factory - * - * @var \Mageplaza\Blog\Model\ResourceModel\Topic\CollectionFactory - */ - protected $topicCollectionFactory; + /** + * Topic collection factory + * + * @var \Mageplaza\Blog\Model\ResourceModel\Topic\CollectionFactory + */ + protected $topicCollectionFactory; - /** - * Registry - * - * @var \Magento\Framework\Registry - */ - protected $coreRegistry; + /** + * Registry + * + * @var \Magento\Framework\Registry + */ + protected $coreRegistry; - /** - * Topic factory - * - * @var \Mageplaza\Blog\Model\TopicFactory - */ - protected $topicFactory; + /** + * Topic factory + * + * @var \Mageplaza\Blog\Model\TopicFactory + */ + protected $topicFactory; - /** - * constructor - * - * @param \Mageplaza\Blog\Model\ResourceModel\Topic\CollectionFactory $topicCollectionFactory - * @param \Magento\Framework\Registry $coreRegistry - * @param \Mageplaza\Blog\Model\TopicFactory $topicFactory - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\Backend\Helper\Data $backendHelper - * @param array $data - */ - public function __construct( - \Mageplaza\Blog\Model\ResourceModel\Topic\CollectionFactory $topicCollectionFactory, - \Magento\Framework\Registry $coreRegistry, - \Mageplaza\Blog\Model\TopicFactory $topicFactory, - \Magento\Backend\Block\Template\Context $context, - \Magento\Backend\Helper\Data $backendHelper, - array $data = [] - ) - { - $this->topicCollectionFactory = $topicCollectionFactory; - $this->coreRegistry = $coreRegistry; - $this->topicFactory = $topicFactory; - parent::__construct($context, $backendHelper, $data); - } + /** + * constructor + * + * @param \Mageplaza\Blog\Model\ResourceModel\Topic\CollectionFactory $topicCollectionFactory + * @param \Magento\Framework\Registry $coreRegistry + * @param \Mageplaza\Blog\Model\TopicFactory $topicFactory + * @param \Magento\Backend\Block\Template\Context $context + * @param \Magento\Backend\Helper\Data $backendHelper + * @param array $data + */ + public function __construct( + \Mageplaza\Blog\Model\ResourceModel\Topic\CollectionFactory $topicCollectionFactory, + \Magento\Framework\Registry $coreRegistry, + \Mageplaza\Blog\Model\TopicFactory $topicFactory, + \Magento\Backend\Block\Template\Context $context, + \Magento\Backend\Helper\Data $backendHelper, + array $data = [] + ) + { + $this->topicCollectionFactory = $topicCollectionFactory; + $this->coreRegistry = $coreRegistry; + $this->topicFactory = $topicFactory; + parent::__construct($context, $backendHelper, $data); + } - /** - * Set grid params - */ - public function _construct() - { - parent::_construct(); - $this->setId('topic_grid'); - $this->setDefaultSort('position'); - $this->setDefaultDir('ASC'); - $this->setUseAjax(true); - if ($this->getPost()->getId()) { - $this->setDefaultFilter(['in_topics' => 1]); - } - } + /** + * Set grid params + */ + public function _construct() + { + parent::_construct(); + $this->setId('topic_grid'); + $this->setDefaultSort('position'); + $this->setDefaultDir('ASC'); + $this->setUseAjax(true); + if ($this->getPost()->getId()) { + $this->setDefaultFilter(['in_topics'=>1]); + } + } - /** - * prepare the collection - * @return $this - */ - protected function _prepareCollection() - { - /** @var \Mageplaza\Blog\Model\ResourceModel\Topic\Collection $collection */ - $collection = $this->topicCollectionFactory->create(); - if ($this->getPost()->getId()) { - $constraint = 'related.post_id=' . $this->getPost()->getId(); - } else { - $constraint = 'related.post_id=0'; - } - $collection->getSelect()->joinLeft( - array('related' => $collection->getTable('mageplaza_blog_post_topic')), - 'related.topic_id=main_table.topic_id AND ' . $constraint, - array('position') - ); - $this->setCollection($collection); - parent::_prepareCollection(); + /** + * prepare the collection - return $this; - } + * @return $this + */ + protected function _prepareCollection() + { + /** @var \Mageplaza\Blog\Model\ResourceModel\Topic\Collection $collection */ + $collection = $this->topicCollectionFactory->create(); + if ($this->getPost()->getId()) { + $constraint = 'related.post_id='.$this->getPost()->getId(); + } else { + $constraint = 'related.post_id=0'; + } + $collection->getSelect()->joinLeft( + array('related' => $collection->getTable('mageplaza_blog_post_topic')), + 'related.topic_id=main_table.topic_id AND '.$constraint, + array('position') + ); + $this->setCollection($collection); + parent::_prepareCollection(); + return $this; + } - /** - * @return $this - */ - protected function _prepareMassaction() - { - return $this; - } + /** + * @return $this + */ + protected function _prepareMassaction() + { + return $this; + } - /** - * @return $this - */ - protected function _prepareColumns() - { - $this->addColumn( - 'in_topics', - [ - 'header_css_class' => 'a-center', - 'type' => 'checkbox', - 'name' => 'in_topic', - 'values' => $this->_getSelectedTopics(), - 'align' => 'center', - 'index' => 'topic_id' - ] - ); - $this->addColumn( - 'topic_id', - [ - 'header' => __('ID'), - 'sortable' => true, - 'index' => 'topic_id', - 'type' => 'number', - 'header_css_class' => 'col-id', - 'column_css_class' => 'col-id' - ] - ); + /** + * @return $this + */ + protected function _prepareColumns() + { + $this->addColumn( + 'in_topics', + [ + 'header_css_class' => 'a-center', + 'type' => 'checkbox', + 'name' => 'in_topic', + 'values' => $this->_getSelectedTopics(), + 'align' => 'center', + 'index' => 'topic_id' + ] + ); + $this->addColumn( + 'topic_id', + [ + 'header' => __('ID'), + 'sortable' => true, + 'index' => 'topic_id', + 'type' => 'number', + 'header_css_class' => 'col-id', + 'column_css_class' => 'col-id' + ] + ); - $this->addColumn( - 'title', - [ - 'header' => __('Name'), - 'index' => 'name', - 'header_css_class' => 'col-name', - 'column_css_class' => 'col-name' - ] - ); + $this->addColumn( + 'title', + [ + 'header' => __('Name'), + 'index' => 'name', + 'header_css_class' => 'col-name', + 'column_css_class' => 'col-name' + ] + ); - $this->addColumn( - 'position', - [ - 'header' => __('Position'), - 'name' => 'position', - 'width' => 60, - 'type' => 'number', - 'validate_class' => 'validate-number', - 'index' => 'position', - 'editable' => true, - ] - ); + $this->addColumn( + 'position', + [ + 'header' => __('Position'), + 'name' => 'position', + 'width' => 60, + 'type' => 'number', + 'validate_class' => 'validate-number', + 'index' => 'position', + 'editable' => true, + ] + ); + return $this; + } - return $this; - } + /** + * Retrieve selected Topics - /** - * Retrieve selected Topics - * @return array - */ - protected function _getSelectedTopics() - { - $topics = $this->getPostTopics(); - if (!is_array($topics)) { - $topics = $this->getPost()->getTopicsPosition(); + * @return array + */ + protected function _getSelectedTopics() + { + $topics = $this->getPostTopics(); + if (!is_array($topics)) { + $topics = $this->getPost()->getTopicsPosition(); + return array_keys($topics); + } + return $topics; + } - return array_keys($topics); - } + /** + * Retrieve selected Topics - return $topics; - } + * @return array + */ + public function getSelectedTopics() + { + $selected = $this->getPost()->getTopicsPosition(); + if (!is_array($selected)) { + $selected = []; + } else { + foreach ($selected as $key => $value) { + $selected[$key] = ['position' => $value]; + } + } + return $selected; + } - /** - * Retrieve selected Topics - * @return array - */ - public function getSelectedTopics() - { - $selected = $this->getPost()->getTopicsPosition(); - if (!is_array($selected)) { - $selected = []; - } else { - foreach ($selected as $key => $value) { - $selected[$key] = ['position' => $value]; - } - } + /** + * @param \Mageplaza\Blog\Model\Topic|\Magento\Framework\Object $item + * @return string + */ + public function getRowUrl($item) + { + return '#'; + } - return $selected; - } + /** + * get grid url + * + * @return string + */ + public function getGridUrl() + { + return $this->getUrl( + '*/*/topicsGrid', + [ + 'post_id' => $this->getPost()->getId() + ] + ); + } - /** - * @param \Mageplaza\Blog\Model\Topic|\Magento\Framework\Object $item - * @return string - */ - public function getRowUrl($item) - { - return '#'; - } + /** + * @return \Mageplaza\Blog\Model\Post + */ + public function getPost() + { + return $this->coreRegistry->registry('mageplaza_blog_post'); + } - /** - * get grid url - * - * @return string - */ - public function getGridUrl() - { - return $this->getUrl( - '*/*/topicsGrid', - [ - 'post_id' => $this->getPost()->getId() - ] - ); - } + /** + * @param \Magento\Backend\Block\Widget\Grid\Column $column + * @return $this + */ + protected function _addColumnFilterToCollection($column) + { + if ($column->getId() == 'in_topics') { + $topicIds = $this->_getSelectedTopics(); + if (empty($topicIds)) { + $topicIds = 0; + } + if ($column->getFilter()->getValue()) { + $this->getCollection()->addFieldToFilter('main_table.topic_id', ['in'=>$topicIds]); + } else { + if ($topicIds) { + $this->getCollection()->addFieldToFilter('main_table.topic_id', ['nin'=>$topicIds]); + } + } + } else { + parent::_addColumnFilterToCollection($column); + } + return $this; + } - /** - * @return \Mageplaza\Blog\Model\Post - */ - public function getPost() - { - return $this->coreRegistry->registry('mageplaza_blog_post'); - } + /** + * @return string + */ + public function getTabLabel() + { + return __('Topics'); + } - /** - * @param \Magento\Backend\Block\Widget\Grid\Column $column - * @return $this - */ - protected function _addColumnFilterToCollection($column) - { - if ($column->getId() == 'in_topics') { - $topicIds = $this->_getSelectedTopics(); - if (empty($topicIds)) { - $topicIds = 0; - } - if ($column->getFilter()->getValue()) { - $this->getCollection()->addFieldToFilter('main_table.topic_id', ['in' => $topicIds]); - } else { - if ($topicIds) { - $this->getCollection()->addFieldToFilter('main_table.topic_id', ['nin' => $topicIds]); - } - } - } else { - parent::_addColumnFilterToCollection($column); - } + /** + * @return bool + */ + public function isHidden() + { + return false; + } - return $this; - } + /** + * @return string + */ + public function getTabTitle() + { + return $this->getTabLabel(); + } - /** - * @return string - */ - public function getTabLabel() - { - return __('Topics'); - } + /** + * @return bool + */ + public function canShowTab() + { + return true; + } - /** - * @return bool - */ - public function isHidden() - { - return false; - } + /** + * @return string + */ + public function getTabUrl() + { + return $this->getUrl('mageplaza_blog/post/topics', ['_current' => true]); + } - /** - * @return string - */ - public function getTabTitle() - { - return $this->getTabLabel(); - } - - /** - * @return bool - */ - public function canShowTab() - { - return true; - } - - /** - * @return string - */ - public function getTabUrl() - { - return $this->getUrl('mageplaza_blog/post/topics', ['_current' => true]); - } - - /** - * @return string - */ - public function getTabClass() - { - return 'ajax only'; - } + /** + * @return string + */ + public function getTabClass() + { + return 'ajax only'; + } } diff --git a/Block/Adminhtml/Post/Edit/Tabs.php b/Block/Adminhtml/Post/Edit/Tabs.php index d55752a2..a325ae94 100755 --- a/Block/Adminhtml/Post/Edit/Tabs.php +++ b/Block/Adminhtml/Post/Edit/Tabs.php @@ -2,16 +2,16 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Post\Edit; @@ -20,16 +20,16 @@ */ class Tabs extends \Magento\Backend\Block\Widget\Tabs { - /** - * constructor - * - * @return void - */ - protected function _construct() - { - parent::_construct(); - $this->setId('post_tabs'); - $this->setDestElementId('edit_form'); - $this->setTitle(__('Post Information')); - } + /** + * constructor + * + * @return void + */ + protected function _construct() + { + parent::_construct(); + $this->setId('post_tabs'); + $this->setDestElementId('edit_form'); + $this->setTitle(__('Post Information')); + } } diff --git a/Block/Adminhtml/Post/Grid.php b/Block/Adminhtml/Post/Grid.php index e95692e2..6ecf530d 100755 --- a/Block/Adminhtml/Post/Grid.php +++ b/Block/Adminhtml/Post/Grid.php @@ -2,16 +2,16 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Post; diff --git a/Block/Adminhtml/Post/Helper/Image.php b/Block/Adminhtml/Post/Helper/Image.php index 9377f12e..6aa7c169 100755 --- a/Block/Adminhtml/Post/Helper/Image.php +++ b/Block/Adminhtml/Post/Helper/Image.php @@ -2,16 +2,16 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Post\Helper; @@ -20,48 +20,47 @@ */ class Image extends \Magento\Framework\Data\Form\Element\Image { - /** - * Post image model - * - * @var \Mageplaza\Blog\Model\Post\Image - */ - protected $imageModel; + /** + * Post image model + * + * @var \Mageplaza\Blog\Model\Post\Image + */ + protected $imageModel; - /** - * constructor - * - * @param \Mageplaza\Blog\Model\Post\Image $imageModel - * @param \Magento\Framework\Data\Form\Element\Factory $factoryElement - * @param \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection - * @param \Magento\Framework\Escaper $escaper - * @param \Magento\Framework\UrlInterface $urlBuilder - * @param array $data - */ - public function __construct( - \Mageplaza\Blog\Model\Post\Image $imageModel, - \Magento\Framework\Data\Form\Element\Factory $factoryElement, - \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection, - \Magento\Framework\Escaper $escaper, - \Magento\Framework\UrlInterface $urlBuilder, - array $data - ) - { - $this->imageModel = $imageModel; - parent::__construct($factoryElement, $factoryCollection, $escaper, $urlBuilder, $data); - } + /** + * constructor + * + * @param \Mageplaza\Blog\Model\Post\Image $imageModel + * @param \Magento\Framework\Data\Form\Element\Factory $factoryElement + * @param \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection + * @param \Magento\Framework\Escaper $escaper + * @param \Magento\Framework\UrlInterface $urlBuilder + * @param array $data + */ + public function __construct( + \Mageplaza\Blog\Model\Post\Image $imageModel, + \Magento\Framework\Data\Form\Element\Factory $factoryElement, + \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection, + \Magento\Framework\Escaper $escaper, + \Magento\Framework\UrlInterface $urlBuilder, + array $data + ) + { + $this->imageModel = $imageModel; + parent::__construct($factoryElement, $factoryCollection, $escaper, $urlBuilder, $data); + } - /** - * Get image preview url - * - * @return string - */ - protected function getUrl() - { - $url = false; - if ($this->getValue()) { - $url = $this->imageModel->getBaseUrl() . $this->getValue(); - } - - return $url; - } + /** + * Get image preview url + * + * @return string + */ + protected function getUrl() + { + $url = false; + if ($this->getValue()) { + $url = $this->imageModel->getBaseUrl().$this->getValue(); + } + return $url; + } } diff --git a/Block/Adminhtml/System/Config/Head.php b/Block/Adminhtml/System/Config/Head.php index 96461bd8..700edf97 100755 --- a/Block/Adminhtml/System/Config/Head.php +++ b/Block/Adminhtml/System/Config/Head.php @@ -17,8 +17,7 @@ class Head extends \Magento\Config\Block\System\Config\Form\Field public function __construct( \Magento\Backend\Block\Template\Context $context, array $data = [] - ) - { + ) { parent::__construct($context, $data); } @@ -51,7 +50,7 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele // // '; // return $html; - + return parent::render($element); } diff --git a/Block/Adminhtml/Tag.php b/Block/Adminhtml/Tag.php index acdc29dd..0df9445f 100755 --- a/Block/Adminhtml/Tag.php +++ b/Block/Adminhtml/Tag.php @@ -2,32 +2,32 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml; class Tag extends \Magento\Backend\Block\Widget\Grid\Container { - /** - * constructor - * - * @return void - */ - protected function _construct() - { - $this->_controller = 'adminhtml_tag'; - $this->_blockGroup = 'Mageplaza_Blog'; - $this->_headerText = __('Tags'); - $this->_addButtonLabel = __('Create New Tag'); - parent::_construct(); - } + /** + * constructor + * + * @return void + */ + protected function _construct() + { + $this->_controller = 'adminhtml_tag'; + $this->_blockGroup = 'Mageplaza_Blog'; + $this->_headerText = __('Tags'); + $this->_addButtonLabel = __('Create New Tag'); + parent::_construct(); + } } diff --git a/Block/Adminhtml/Tag/Edit.php b/Block/Adminhtml/Tag/Edit.php index 776d174f..67aa462c 100755 --- a/Block/Adminhtml/Tag/Edit.php +++ b/Block/Adminhtml/Tag/Edit.php @@ -2,89 +2,87 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Tag; class Edit extends \Magento\Backend\Block\Widget\Form\Container { - /** - * Core registry - * - * @var \Magento\Framework\Registry - */ - protected $coreRegistry; + /** + * Core registry + * + * @var \Magento\Framework\Registry + */ + protected $coreRegistry; - /** - * constructor - * - * @param \Magento\Framework\Registry $coreRegistry - * @param \Magento\Backend\Block\Widget\Context $context - * @param array $data - */ - public function __construct( - \Magento\Framework\Registry $coreRegistry, - \Magento\Backend\Block\Widget\Context $context, - array $data = [] - ) - { - $this->coreRegistry = $coreRegistry; - parent::__construct($context, $data); - } + /** + * constructor + * + * @param \Magento\Framework\Registry $coreRegistry + * @param \Magento\Backend\Block\Widget\Context $context + * @param array $data + */ + public function __construct( + \Magento\Framework\Registry $coreRegistry, + \Magento\Backend\Block\Widget\Context $context, + array $data = [] + ) + { + $this->coreRegistry = $coreRegistry; + parent::__construct($context, $data); + } - /** - * Initialize Tag edit block - * - * @return void - */ - protected function _construct() - { - $this->_objectId = 'tag_id'; - $this->_blockGroup = 'Mageplaza_Blog'; - $this->_controller = 'adminhtml_tag'; - parent::_construct(); - $this->buttonList->update('save', 'label', __('Save Tag')); - $this->buttonList->add( - 'save-and-continue', - [ - 'label' => __('Save and Continue Edit'), - 'class' => 'save', - 'data_attribute' => [ - 'mage-init' => [ - 'button' => [ - 'event' => 'saveAndContinueEdit', - 'target' => '#edit_form' - ] - ] - ] - ], - -100 - ); - $this->buttonList->update('delete', 'label', __('Delete Tag')); - } - - /** - * Retrieve text for header element depending on loaded Tag - * - * @return string - */ - public function getHeaderText() - { - /** @var \Mageplaza\Blog\Model\Tag $tag */ - $tag = $this->coreRegistry->registry('mageplaza_blog_tag'); - if ($tag->getId()) { - return __("Edit Tag '%1'", $this->escapeHtml($tag->getName())); - } - - return __('New Tag'); - } + /** + * Initialize Tag edit block + * + * @return void + */ + protected function _construct() + { + $this->_objectId = 'tag_id'; + $this->_blockGroup = 'Mageplaza_Blog'; + $this->_controller = 'adminhtml_tag'; + parent::_construct(); + $this->buttonList->update('save', 'label', __('Save Tag')); + $this->buttonList->add( + 'save-and-continue', + [ + 'label' => __('Save and Continue Edit'), + 'class' => 'save', + 'data_attribute' => [ + 'mage-init' => [ + 'button' => [ + 'event' => 'saveAndContinueEdit', + 'target' => '#edit_form' + ] + ] + ] + ], + -100 + ); + $this->buttonList->update('delete', 'label', __('Delete Tag')); + } + /** + * Retrieve text for header element depending on loaded Tag + * + * @return string + */ + public function getHeaderText() + { + /** @var \Mageplaza\Blog\Model\Tag $tag */ + $tag = $this->coreRegistry->registry('mageplaza_blog_tag'); + if ($tag->getId()) { + return __("Edit Tag '%1'", $this->escapeHtml($tag->getName())); + } + return __('New Tag'); + } } diff --git a/Block/Adminhtml/Tag/Edit/Form.php b/Block/Adminhtml/Tag/Edit/Form.php index d56b9524..b2620cd9 100755 --- a/Block/Adminhtml/Tag/Edit/Form.php +++ b/Block/Adminhtml/Tag/Edit/Form.php @@ -2,42 +2,41 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Tag\Edit; class Form extends \Magento\Backend\Block\Widget\Form\Generic { - /** - * Prepare form - * - * @return $this - */ - protected function _prepareForm() - { - /** @var \Magento\Framework\Data\Form $form */ - $form = $this->_formFactory->create( - [ - 'data' => [ - 'id' => 'edit_form', - 'action' => $this->getData('action'), - 'method' => 'post', - 'enctype' => 'multipart/form-data' - ] - ] - ); - $form->setUseContainer(true); - $this->setForm($form); - - return parent::_prepareForm(); - } + /** + * Prepare form + * + * @return $this + */ + protected function _prepareForm() + { + /** @var \Magento\Framework\Data\Form $form */ + $form = $this->_formFactory->create( + [ + 'data' => [ + 'id' => 'edit_form', + 'action' => $this->getData('action'), + 'method' => 'post', + 'enctype' => 'multipart/form-data' + ] + ] + ); + $form->setUseContainer(true); + $this->setForm($form); + return parent::_prepareForm(); + } } diff --git a/Block/Adminhtml/Tag/Edit/Tab/Post.php b/Block/Adminhtml/Tag/Edit/Tab/Post.php index 72821d20..3d49d438 100755 --- a/Block/Adminhtml/Tag/Edit/Tab/Post.php +++ b/Block/Adminhtml/Tag/Edit/Tab/Post.php @@ -2,305 +2,302 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Tag\Edit\Tab; class Post extends \Magento\Backend\Block\Widget\Grid\Extended implements \Magento\Backend\Block\Widget\Tab\TabInterface { - /** - * Post collection factory - * - * @var \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory - */ - protected $postCollectionFactory; + /** + * Post collection factory + * + * @var \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory + */ + protected $postCollectionFactory; - /** - * Registry - * - * @var \Magento\Framework\Registry - */ - protected $coreRegistry; + /** + * Registry + * + * @var \Magento\Framework\Registry + */ + protected $coreRegistry; - /** - * Post factory - * - * @var \Mageplaza\Blog\Model\PostFactory - */ - protected $postFactory; + /** + * Post factory + * + * @var \Mageplaza\Blog\Model\PostFactory + */ + protected $postFactory; - /** - * constructor - * - * @param \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory - * @param \Magento\Framework\Registry $coreRegistry - * @param \Mageplaza\Blog\Model\PostFactory $postFactory - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\Backend\Helper\Data $backendHelper - * @param array $data - */ - public function __construct( - \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory, - \Magento\Framework\Registry $coreRegistry, - \Mageplaza\Blog\Model\PostFactory $postFactory, - \Magento\Backend\Block\Template\Context $context, - \Magento\Backend\Helper\Data $backendHelper, - array $data = [] - ) - { - $this->postCollectionFactory = $postCollectionFactory; - $this->coreRegistry = $coreRegistry; - $this->postFactory = $postFactory; - parent::__construct($context, $backendHelper, $data); - } + /** + * constructor + * + * @param \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory + * @param \Magento\Framework\Registry $coreRegistry + * @param \Mageplaza\Blog\Model\PostFactory $postFactory + * @param \Magento\Backend\Block\Template\Context $context + * @param \Magento\Backend\Helper\Data $backendHelper + * @param array $data + */ + public function __construct( + \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory, + \Magento\Framework\Registry $coreRegistry, + \Mageplaza\Blog\Model\PostFactory $postFactory, + \Magento\Backend\Block\Template\Context $context, + \Magento\Backend\Helper\Data $backendHelper, + array $data = [] + ) + { + $this->postCollectionFactory = $postCollectionFactory; + $this->coreRegistry = $coreRegistry; + $this->postFactory = $postFactory; + parent::__construct($context, $backendHelper, $data); + } - /** - * Set grid params - */ - public function _construct() - { - parent::_construct(); - $this->setId('post_grid'); - $this->setDefaultSort('position'); - $this->setDefaultDir('ASC'); - $this->setUseAjax(true); - if ($this->getTag()->getId()) { - $this->setDefaultFilter(['in_posts' => 1]); - } - } + /** + * Set grid params + */ + public function _construct() + { + parent::_construct(); + $this->setId('post_grid'); + $this->setDefaultSort('position'); + $this->setDefaultDir('ASC'); + $this->setUseAjax(true); + if ($this->getTag()->getId()) { + $this->setDefaultFilter(['in_posts'=>1]); + } + } - /** - * prepare the collection - * @return $this - */ - protected function _prepareCollection() - { - /** @var \Mageplaza\Blog\Model\ResourceModel\Post\Collection $collection */ - $collection = $this->postCollectionFactory->create(); - if ($this->getTag()->getId()) { - $constraint = 'related.tag_id=' . $this->getTag()->getId(); - } else { - $constraint = 'related.tag_id=0'; - } - $collection->getSelect()->joinLeft( - array('related' => $collection->getTable('mageplaza_blog_post_tag')), - 'related.post_id=main_table.post_id AND ' . $constraint, - array('position') - ); - $this->setCollection($collection); - parent::_prepareCollection(); + /** + * prepare the collection - return $this; - } + * @return $this + */ + protected function _prepareCollection() + { + /** @var \Mageplaza\Blog\Model\ResourceModel\Post\Collection $collection */ + $collection = $this->postCollectionFactory->create(); + if ($this->getTag()->getId()) { + $constraint = 'related.tag_id='.$this->getTag()->getId(); + } else { + $constraint = 'related.tag_id=0'; + } + $collection->getSelect()->joinLeft( + array('related' => $collection->getTable('mageplaza_blog_post_tag')), + 'related.post_id=main_table.post_id AND '.$constraint, + array('position') + ); + $this->setCollection($collection); + parent::_prepareCollection(); + return $this; + } - /** - * @return $this - */ - protected function _prepareMassaction() - { - return $this; - } + /** + * @return $this + */ + protected function _prepareMassaction() + { + return $this; + } - /** - * @return $this - */ - protected function _prepareColumns() - { - $this->addColumn( - 'in_posts', - [ - 'header_css_class' => 'a-center', - 'type' => 'checkbox', - 'name' => 'in_post', - 'values' => $this->_getSelectedPosts(), - 'align' => 'center', - 'index' => 'post_id' - ] - ); - $this->addColumn( - 'post_id', - [ - 'header' => __('ID'), - 'sortable' => true, - 'index' => 'post_id', - 'type' => 'number', - 'header_css_class' => 'col-id', - 'column_css_class' => 'col-id' - ] - ); + /** + * @return $this + */ + protected function _prepareColumns() + { + $this->addColumn( + 'in_posts', + [ + 'header_css_class' => 'a-center', + 'type' => 'checkbox', + 'name' => 'in_post', + 'values' => $this->_getSelectedPosts(), + 'align' => 'center', + 'index' => 'post_id' + ] + ); + $this->addColumn( + 'post_id', + [ + 'header' => __('ID'), + 'sortable' => true, + 'index' => 'post_id', + 'type' => 'number', + 'header_css_class' => 'col-id', + 'column_css_class' => 'col-id' + ] + ); - $this->addColumn( - 'title', - [ - 'header' => __('Name'), - 'index' => 'name', - 'header_css_class' => 'col-name', - 'column_css_class' => 'col-name' - ] - ); + $this->addColumn( + 'title', + [ + 'header' => __('Name'), + 'index' => 'name', + 'header_css_class' => 'col-name', + 'column_css_class' => 'col-name' + ] + ); - $this->addColumn( - 'position', - [ - 'header' => __('Position'), - 'name' => 'position', - 'width' => 60, - 'type' => 'number', - 'validate_class' => 'validate-number', - 'index' => 'position', - 'editable' => true, - ] - ); + $this->addColumn( + 'position', + [ + 'header' => __('Position'), + 'name' => 'position', + 'width' => 60, + 'type' => 'number', + 'validate_class' => 'validate-number', + 'index' => 'position', + 'editable' => true, + ] + ); + return $this; + } - return $this; - } + /** + * Retrieve selected Posts - /** - * Retrieve selected Posts - * @return array - */ - protected function _getSelectedPosts() - { - $posts = $this->getTagPosts(); - if (!is_array($posts)) { - $posts = $this->getTag()->getPostsPosition(); + * @return array + */ + protected function _getSelectedPosts() + { + $posts = $this->getTagPosts(); + if (!is_array($posts)) { + $posts = $this->getTag()->getPostsPosition(); + return array_keys($posts); + } + return $posts; + } - return array_keys($posts); - } + /** + * Retrieve selected Posts - return $posts; - } + * @return array + */ + public function getSelectedPosts() + { + $selected = $this->getTag()->getPostsPosition(); + if (!is_array($selected)) { + $selected = []; + } else { + foreach ($selected as $key => $value) { + $selected[$key] = ['position' => $value]; + } + } + return $selected; + } - /** - * Retrieve selected Posts - * @return array - */ - public function getSelectedPosts() - { - $selected = $this->getTag()->getPostsPosition(); - if (!is_array($selected)) { - $selected = []; - } else { - foreach ($selected as $key => $value) { - $selected[$key] = ['position' => $value]; - } - } + /** + * @param \Mageplaza\Blog\Model\Post|\Magento\Framework\Object $item + * @return string + */ + public function getRowUrl($item) + { + return '#'; + } - return $selected; - } + /** + * get grid url + * + * @return string + */ + public function getGridUrl() + { + return $this->getUrl( + '*/*/postsGrid', + [ + 'tag_id' => $this->getTag()->getId() + ] + ); + } - /** - * @param \Mageplaza\Blog\Model\Post|\Magento\Framework\Object $item - * @return string - */ - public function getRowUrl($item) - { - return '#'; - } + /** + * @return \Mageplaza\Blog\Model\Tag + */ + public function getTag() + { + return $this->coreRegistry->registry('mageplaza_blog_tag'); + } - /** - * get grid url - * - * @return string - */ - public function getGridUrl() - { - return $this->getUrl( - '*/*/postsGrid', - [ - 'tag_id' => $this->getTag()->getId() - ] - ); - } + /** + * @param \Magento\Backend\Block\Widget\Grid\Column $column + * @return $this + */ + protected function _addColumnFilterToCollection($column) + { + if ($column->getId() == 'in_posts') { + $postIds = $this->_getSelectedPosts(); + if (empty($postIds)) { + $postIds = 0; + } + if ($column->getFilter()->getValue()) { + $this->getCollection()->addFieldToFilter('main_table.post_id', ['in'=>$postIds]); + } else { + if ($postIds) { + $this->getCollection()->addFieldToFilter('main_table.post_id', ['nin'=>$postIds]); + } + } + } else { + parent::_addColumnFilterToCollection($column); + } + return $this; + } - /** - * @return \Mageplaza\Blog\Model\Tag - */ - public function getTag() - { - return $this->coreRegistry->registry('mageplaza_blog_tag'); - } + /** + * @return string + */ + public function getTabLabel() + { + return __('Posts'); + } - /** - * @param \Magento\Backend\Block\Widget\Grid\Column $column - * @return $this - */ - protected function _addColumnFilterToCollection($column) - { - if ($column->getId() == 'in_posts') { - $postIds = $this->_getSelectedPosts(); - if (empty($postIds)) { - $postIds = 0; - } - if ($column->getFilter()->getValue()) { - $this->getCollection()->addFieldToFilter('main_table.post_id', ['in' => $postIds]); - } else { - if ($postIds) { - $this->getCollection()->addFieldToFilter('main_table.post_id', ['nin' => $postIds]); - } - } - } else { - parent::_addColumnFilterToCollection($column); - } + /** + * @return bool + */ + public function isHidden() + { + return false; + } - return $this; - } + /** + * @return string + */ + public function getTabTitle() + { + return $this->getTabLabel(); + } - /** - * @return string - */ - public function getTabLabel() - { - return __('Posts'); - } + /** + * @return bool + */ + public function canShowTab() + { + return true; + } - /** - * @return bool - */ - public function isHidden() - { - return false; - } + /** + * @return string + */ + public function getTabUrl() + { + return $this->getUrl('mageplaza_blog/tag/posts', ['_current' => true]); + } - /** - * @return string - */ - public function getTabTitle() - { - return $this->getTabLabel(); - } - - /** - * @return bool - */ - public function canShowTab() - { - return true; - } - - /** - * @return string - */ - public function getTabUrl() - { - return $this->getUrl('mageplaza_blog/tag/posts', ['_current' => true]); - } - - /** - * @return string - */ - public function getTabClass() - { - return 'ajax only'; - } + /** + * @return string + */ + public function getTabClass() + { + return 'ajax only'; + } } diff --git a/Block/Adminhtml/Tag/Edit/Tab/Tag.php b/Block/Adminhtml/Tag/Edit/Tab/Tag.php index 1dc03f49..b6030ecd 100755 --- a/Block/Adminhtml/Tag/Edit/Tab/Tag.php +++ b/Block/Adminhtml/Tag/Edit/Tab/Tag.php @@ -2,128 +2,59 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Tag\Edit\Tab; class Tag extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Backend\Block\Widget\Tab\TabInterface { - /** - * Wysiwyg config - * - * @var \Magento\Cms\Model\Wysiwyg\Config - */ - protected $wysiwygConfig; - - /** - * Country options - * - * @var \Magento\Config\Model\Config\Source\Yesno - */ - protected $booleanOptions; + /** + * Wysiwyg config + * + * @var \Magento\Cms\Model\Wysiwyg\Config + */ + protected $wysiwygConfig; - /** - * constructor - * - * @param \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig - * @param \Magento\Config\Model\Config\Source\Yesno $booleanOptions - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Data\FormFactory $formFactory - * @param array $data - */ - public function __construct( - \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig, - \Magento\Config\Model\Config\Source\Yesno $booleanOptions, - \Magento\Backend\Block\Template\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Data\FormFactory $formFactory, - array $data = [] - ) - { - $this->wysiwygConfig = $wysiwygConfig; - $this->booleanOptions = $booleanOptions; - parent::__construct($context, $registry, $formFactory, $data); - } + /** + * Country options + * + * @var \Magento\Config\Model\Config\Source\Yesno + */ + protected $booleanOptions; -<<<<<<< HEAD - /** - * Prepare form - * - * @return $this - */ - protected function _prepareForm() - { - /** @var \Mageplaza\Blog\Model\Tag $tag */ - $tag = $this->_coreRegistry->registry('mageplaza_blog_tag'); - $form = $this->_formFactory->create(); - $form->setHtmlIdPrefix('tag_'); - $form->setFieldNameSuffix('tag'); - $fieldset = $form->addFieldset( - 'base_fieldset', - [ - 'legend' => __('Tag Information'), - 'class' => 'fieldset-wide' - ] - ); - if ($tag->getId()) { - $fieldset->addField( - 'tag_id', - 'hidden', - ['name' => 'tag_id'] - ); - } - $fieldset->addField( - 'name', - 'text', - [ - 'name' => 'name', - 'label' => __('Name'), - 'title' => __('Name'), - 'required' => true, - ] - ); - $fieldset->addField( - 'description', - 'editor', - [ - 'name' => 'description', - 'label' => __('Description'), - 'title' => __('Description'), - 'config' => $this->wysiwygConfig->getConfig() - ] - ); - $fieldset->addField( - 'enabled', - 'select', - [ - 'name' => 'enabled', - 'label' => __('Enabled'), - 'title' => __('Enabled'), - 'values' => $this->booleanOptions->toOptionArray(), - ] - ); + /** + * constructor + * + * @param \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig + * @param \Magento\Config\Model\Config\Source\Yesno $booleanOptions + * @param \Magento\Backend\Block\Template\Context $context + * @param \Magento\Framework\Registry $registry + * @param \Magento\Framework\Data\FormFactory $formFactory + * @param array $data + */ + public function __construct( + \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig, + \Magento\Config\Model\Config\Source\Yesno $booleanOptions, + \Magento\Backend\Block\Template\Context $context, + \Magento\Framework\Registry $registry, + \Magento\Framework\Data\FormFactory $formFactory, + array $data = [] + ) + { + $this->wysiwygConfig = $wysiwygConfig; + $this->booleanOptions = $booleanOptions; + parent::__construct($context, $registry, $formFactory, $data); + } - $tagData = $this->_session->getData('mageplaza_blog_tag_data', true); - if ($tagData) { - $tag->addData($tagData); - } else { - if (!$tag->getId()) { - $tag->addData($tag->getDefaultValues()); - } - } - $form->addValues($tag->getData()); - $this->setForm($form); -======= /** * Prepare form * @@ -201,48 +132,44 @@ protected function _prepareForm() $this->setForm($form); return parent::_prepareForm(); } ->>>>>>> a1920608f541f3e6df2a2db49e87688175ce6955 - - return parent::_prepareForm(); - } - /** - * Prepare label for tab - * - * @return string - */ - public function getTabLabel() - { - return __('Tag'); - } + /** + * Prepare label for tab + * + * @return string + */ + public function getTabLabel() + { + return __('Tag'); + } - /** - * Prepare title for tab - * - * @return string - */ - public function getTabTitle() - { - return $this->getTabLabel(); - } + /** + * Prepare title for tab + * + * @return string + */ + public function getTabTitle() + { + return $this->getTabLabel(); + } - /** - * Can show tab in tabs - * - * @return boolean - */ - public function canShowTab() - { - return true; - } + /** + * Can show tab in tabs + * + * @return boolean + */ + public function canShowTab() + { + return true; + } - /** - * Tab is hidden - * - * @return boolean - */ - public function isHidden() - { - return false; - } + /** + * Tab is hidden + * + * @return boolean + */ + public function isHidden() + { + return false; + } } diff --git a/Block/Adminhtml/Tag/Edit/Tabs.php b/Block/Adminhtml/Tag/Edit/Tabs.php index 3e93ffca..1d084813 100755 --- a/Block/Adminhtml/Tag/Edit/Tabs.php +++ b/Block/Adminhtml/Tag/Edit/Tabs.php @@ -2,16 +2,16 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Tag\Edit; @@ -20,16 +20,16 @@ */ class Tabs extends \Magento\Backend\Block\Widget\Tabs { - /** - * constructor - * - * @return void - */ - protected function _construct() - { - parent::_construct(); - $this->setId('tag_tabs'); - $this->setDestElementId('edit_form'); - $this->setTitle(__('Tag Information')); - } + /** + * constructor + * + * @return void + */ + protected function _construct() + { + parent::_construct(); + $this->setId('tag_tabs'); + $this->setDestElementId('edit_form'); + $this->setTitle(__('Tag Information')); + } } diff --git a/Block/Adminhtml/Tag/Grid.php b/Block/Adminhtml/Tag/Grid.php index fd010b50..e2b9b59a 100755 --- a/Block/Adminhtml/Tag/Grid.php +++ b/Block/Adminhtml/Tag/Grid.php @@ -2,16 +2,16 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Tag; diff --git a/Block/Adminhtml/Topic.php b/Block/Adminhtml/Topic.php index 59d28cfd..4186831f 100755 --- a/Block/Adminhtml/Topic.php +++ b/Block/Adminhtml/Topic.php @@ -2,32 +2,32 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml; class Topic extends \Magento\Backend\Block\Widget\Grid\Container { - /** - * constructor - * - * @return void - */ - protected function _construct() - { - $this->_controller = 'adminhtml_topic'; - $this->_blockGroup = 'Mageplaza_Blog'; - $this->_headerText = __('Topics'); - $this->_addButtonLabel = __('Create New Topic'); - parent::_construct(); - } + /** + * constructor + * + * @return void + */ + protected function _construct() + { + $this->_controller = 'adminhtml_topic'; + $this->_blockGroup = 'Mageplaza_Blog'; + $this->_headerText = __('Topics'); + $this->_addButtonLabel = __('Create New Topic'); + parent::_construct(); + } } diff --git a/Block/Adminhtml/Topic/Edit.php b/Block/Adminhtml/Topic/Edit.php index 47eeafd8..953109cc 100755 --- a/Block/Adminhtml/Topic/Edit.php +++ b/Block/Adminhtml/Topic/Edit.php @@ -2,89 +2,87 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Topic; class Edit extends \Magento\Backend\Block\Widget\Form\Container { - /** - * Core registry - * - * @var \Magento\Framework\Registry - */ - protected $coreRegistry; + /** + * Core registry + * + * @var \Magento\Framework\Registry + */ + protected $coreRegistry; - /** - * constructor - * - * @param \Magento\Framework\Registry $coreRegistry - * @param \Magento\Backend\Block\Widget\Context $context - * @param array $data - */ - public function __construct( - \Magento\Framework\Registry $coreRegistry, - \Magento\Backend\Block\Widget\Context $context, - array $data = [] - ) - { - $this->coreRegistry = $coreRegistry; - parent::__construct($context, $data); - } + /** + * constructor + * + * @param \Magento\Framework\Registry $coreRegistry + * @param \Magento\Backend\Block\Widget\Context $context + * @param array $data + */ + public function __construct( + \Magento\Framework\Registry $coreRegistry, + \Magento\Backend\Block\Widget\Context $context, + array $data = [] + ) + { + $this->coreRegistry = $coreRegistry; + parent::__construct($context, $data); + } - /** - * Initialize Topic edit block - * - * @return void - */ - protected function _construct() - { - $this->_objectId = 'topic_id'; - $this->_blockGroup = 'Mageplaza_Blog'; - $this->_controller = 'adminhtml_topic'; - parent::_construct(); - $this->buttonList->update('save', 'label', __('Save Topic')); - $this->buttonList->add( - 'save-and-continue', - [ - 'label' => __('Save and Continue Edit'), - 'class' => 'save', - 'data_attribute' => [ - 'mage-init' => [ - 'button' => [ - 'event' => 'saveAndContinueEdit', - 'target' => '#edit_form' - ] - ] - ] - ], - -100 - ); - $this->buttonList->update('delete', 'label', __('Delete Topic')); - } - - /** - * Retrieve text for header element depending on loaded Topic - * - * @return string - */ - public function getHeaderText() - { - /** @var \Mageplaza\Blog\Model\Topic $topic */ - $topic = $this->coreRegistry->registry('mageplaza_blog_topic'); - if ($topic->getId()) { - return __("Edit Topic '%1'", $this->escapeHtml($topic->getName())); - } - - return __('New Topic'); - } + /** + * Initialize Topic edit block + * + * @return void + */ + protected function _construct() + { + $this->_objectId = 'topic_id'; + $this->_blockGroup = 'Mageplaza_Blog'; + $this->_controller = 'adminhtml_topic'; + parent::_construct(); + $this->buttonList->update('save', 'label', __('Save Topic')); + $this->buttonList->add( + 'save-and-continue', + [ + 'label' => __('Save and Continue Edit'), + 'class' => 'save', + 'data_attribute' => [ + 'mage-init' => [ + 'button' => [ + 'event' => 'saveAndContinueEdit', + 'target' => '#edit_form' + ] + ] + ] + ], + -100 + ); + $this->buttonList->update('delete', 'label', __('Delete Topic')); + } + /** + * Retrieve text for header element depending on loaded Topic + * + * @return string + */ + public function getHeaderText() + { + /** @var \Mageplaza\Blog\Model\Topic $topic */ + $topic = $this->coreRegistry->registry('mageplaza_blog_topic'); + if ($topic->getId()) { + return __("Edit Topic '%1'", $this->escapeHtml($topic->getName())); + } + return __('New Topic'); + } } diff --git a/Block/Adminhtml/Topic/Edit/Form.php b/Block/Adminhtml/Topic/Edit/Form.php index ee983265..3ef8e74a 100755 --- a/Block/Adminhtml/Topic/Edit/Form.php +++ b/Block/Adminhtml/Topic/Edit/Form.php @@ -2,42 +2,41 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Topic\Edit; class Form extends \Magento\Backend\Block\Widget\Form\Generic { - /** - * Prepare form - * - * @return $this - */ - protected function _prepareForm() - { - /** @var \Magento\Framework\Data\Form $form */ - $form = $this->_formFactory->create( - [ - 'data' => [ - 'id' => 'edit_form', - 'action' => $this->getData('action'), - 'method' => 'post', - 'enctype' => 'multipart/form-data' - ] - ] - ); - $form->setUseContainer(true); - $this->setForm($form); - - return parent::_prepareForm(); - } + /** + * Prepare form + * + * @return $this + */ + protected function _prepareForm() + { + /** @var \Magento\Framework\Data\Form $form */ + $form = $this->_formFactory->create( + [ + 'data' => [ + 'id' => 'edit_form', + 'action' => $this->getData('action'), + 'method' => 'post', + 'enctype' => 'multipart/form-data' + ] + ] + ); + $form->setUseContainer(true); + $this->setForm($form); + return parent::_prepareForm(); + } } diff --git a/Block/Adminhtml/Topic/Edit/Tab/Post.php b/Block/Adminhtml/Topic/Edit/Tab/Post.php index 067d8b1a..54d33fd2 100755 --- a/Block/Adminhtml/Topic/Edit/Tab/Post.php +++ b/Block/Adminhtml/Topic/Edit/Tab/Post.php @@ -2,305 +2,302 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Topic\Edit\Tab; class Post extends \Magento\Backend\Block\Widget\Grid\Extended implements \Magento\Backend\Block\Widget\Tab\TabInterface { - /** - * Post collection factory - * - * @var \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory - */ - protected $postCollectionFactory; + /** + * Post collection factory + * + * @var \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory + */ + protected $postCollectionFactory; - /** - * Registry - * - * @var \Magento\Framework\Registry - */ - protected $coreRegistry; + /** + * Registry + * + * @var \Magento\Framework\Registry + */ + protected $coreRegistry; - /** - * Post factory - * - * @var \Mageplaza\Blog\Model\PostFactory - */ - protected $postFactory; + /** + * Post factory + * + * @var \Mageplaza\Blog\Model\PostFactory + */ + protected $postFactory; - /** - * constructor - * - * @param \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory - * @param \Magento\Framework\Registry $coreRegistry - * @param \Mageplaza\Blog\Model\PostFactory $postFactory - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\Backend\Helper\Data $backendHelper - * @param array $data - */ - public function __construct( - \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory, - \Magento\Framework\Registry $coreRegistry, - \Mageplaza\Blog\Model\PostFactory $postFactory, - \Magento\Backend\Block\Template\Context $context, - \Magento\Backend\Helper\Data $backendHelper, - array $data = [] - ) - { - $this->postCollectionFactory = $postCollectionFactory; - $this->coreRegistry = $coreRegistry; - $this->postFactory = $postFactory; - parent::__construct($context, $backendHelper, $data); - } + /** + * constructor + * + * @param \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory + * @param \Magento\Framework\Registry $coreRegistry + * @param \Mageplaza\Blog\Model\PostFactory $postFactory + * @param \Magento\Backend\Block\Template\Context $context + * @param \Magento\Backend\Helper\Data $backendHelper + * @param array $data + */ + public function __construct( + \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory, + \Magento\Framework\Registry $coreRegistry, + \Mageplaza\Blog\Model\PostFactory $postFactory, + \Magento\Backend\Block\Template\Context $context, + \Magento\Backend\Helper\Data $backendHelper, + array $data = [] + ) + { + $this->postCollectionFactory = $postCollectionFactory; + $this->coreRegistry = $coreRegistry; + $this->postFactory = $postFactory; + parent::__construct($context, $backendHelper, $data); + } - /** - * Set grid params - */ - public function _construct() - { - parent::_construct(); - $this->setId('post_grid'); - $this->setDefaultSort('position'); - $this->setDefaultDir('ASC'); - $this->setUseAjax(true); - if ($this->getTopic()->getId()) { - $this->setDefaultFilter(['in_posts' => 1]); - } - } + /** + * Set grid params + */ + public function _construct() + { + parent::_construct(); + $this->setId('post_grid'); + $this->setDefaultSort('position'); + $this->setDefaultDir('ASC'); + $this->setUseAjax(true); + if ($this->getTopic()->getId()) { + $this->setDefaultFilter(['in_posts'=>1]); + } + } - /** - * prepare the collection - * @return $this - */ - protected function _prepareCollection() - { - /** @var \Mageplaza\Blog\Model\ResourceModel\Post\Collection $collection */ - $collection = $this->postCollectionFactory->create(); - if ($this->getTopic()->getId()) { - $constraint = 'related.topic_id=' . $this->getTopic()->getId(); - } else { - $constraint = 'related.topic_id=0'; - } - $collection->getSelect()->joinLeft( - array('related' => $collection->getTable('mageplaza_blog_post_topic')), - 'related.post_id=main_table.post_id AND ' . $constraint, - array('position') - ); - $this->setCollection($collection); - parent::_prepareCollection(); + /** + * prepare the collection - return $this; - } + * @return $this + */ + protected function _prepareCollection() + { + /** @var \Mageplaza\Blog\Model\ResourceModel\Post\Collection $collection */ + $collection = $this->postCollectionFactory->create(); + if ($this->getTopic()->getId()) { + $constraint = 'related.topic_id='.$this->getTopic()->getId(); + } else { + $constraint = 'related.topic_id=0'; + } + $collection->getSelect()->joinLeft( + array('related' => $collection->getTable('mageplaza_blog_post_topic')), + 'related.post_id=main_table.post_id AND '.$constraint, + array('position') + ); + $this->setCollection($collection); + parent::_prepareCollection(); + return $this; + } - /** - * @return $this - */ - protected function _prepareMassaction() - { - return $this; - } + /** + * @return $this + */ + protected function _prepareMassaction() + { + return $this; + } - /** - * @return $this - */ - protected function _prepareColumns() - { - $this->addColumn( - 'in_posts', - [ - 'header_css_class' => 'a-center', - 'type' => 'checkbox', - 'name' => 'in_post', - 'values' => $this->_getSelectedPosts(), - 'align' => 'center', - 'index' => 'post_id' - ] - ); - $this->addColumn( - 'post_id', - [ - 'header' => __('ID'), - 'sortable' => true, - 'index' => 'post_id', - 'type' => 'number', - 'header_css_class' => 'col-id', - 'column_css_class' => 'col-id' - ] - ); + /** + * @return $this + */ + protected function _prepareColumns() + { + $this->addColumn( + 'in_posts', + [ + 'header_css_class' => 'a-center', + 'type' => 'checkbox', + 'name' => 'in_post', + 'values' => $this->_getSelectedPosts(), + 'align' => 'center', + 'index' => 'post_id' + ] + ); + $this->addColumn( + 'post_id', + [ + 'header' => __('ID'), + 'sortable' => true, + 'index' => 'post_id', + 'type' => 'number', + 'header_css_class' => 'col-id', + 'column_css_class' => 'col-id' + ] + ); - $this->addColumn( - 'title', - [ - 'header' => __('Name'), - 'index' => 'name', - 'header_css_class' => 'col-name', - 'column_css_class' => 'col-name' - ] - ); + $this->addColumn( + 'title', + [ + 'header' => __('Name'), + 'index' => 'name', + 'header_css_class' => 'col-name', + 'column_css_class' => 'col-name' + ] + ); - $this->addColumn( - 'position', - [ - 'header' => __('Position'), - 'name' => 'position', - 'width' => 60, - 'type' => 'number', - 'validate_class' => 'validate-number', - 'index' => 'position', - 'editable' => true, - ] - ); + $this->addColumn( + 'position', + [ + 'header' => __('Position'), + 'name' => 'position', + 'width' => 60, + 'type' => 'number', + 'validate_class' => 'validate-number', + 'index' => 'position', + 'editable' => true, + ] + ); + return $this; + } - return $this; - } + /** + * Retrieve selected Posts - /** - * Retrieve selected Posts - * @return array - */ - protected function _getSelectedPosts() - { - $posts = $this->getTopicPosts(); - if (!is_array($posts)) { - $posts = $this->getTopic()->getPostsPosition(); + * @return array + */ + protected function _getSelectedPosts() + { + $posts = $this->getTopicPosts(); + if (!is_array($posts)) { + $posts = $this->getTopic()->getPostsPosition(); + return array_keys($posts); + } + return $posts; + } - return array_keys($posts); - } + /** + * Retrieve selected Posts - return $posts; - } + * @return array + */ + public function getSelectedPosts() + { + $selected = $this->getTopic()->getPostsPosition(); + if (!is_array($selected)) { + $selected = []; + } else { + foreach ($selected as $key => $value) { + $selected[$key] = ['position' => $value]; + } + } + return $selected; + } - /** - * Retrieve selected Posts - * @return array - */ - public function getSelectedPosts() - { - $selected = $this->getTopic()->getPostsPosition(); - if (!is_array($selected)) { - $selected = []; - } else { - foreach ($selected as $key => $value) { - $selected[$key] = ['position' => $value]; - } - } + /** + * @param \Mageplaza\Blog\Model\Post|\Magento\Framework\Object $item + * @return string + */ + public function getRowUrl($item) + { + return '#'; + } - return $selected; - } + /** + * get grid url + * + * @return string + */ + public function getGridUrl() + { + return $this->getUrl( + '*/*/postsGrid', + [ + 'topic_id' => $this->getTopic()->getId() + ] + ); + } - /** - * @param \Mageplaza\Blog\Model\Post|\Magento\Framework\Object $item - * @return string - */ - public function getRowUrl($item) - { - return '#'; - } + /** + * @return \Mageplaza\Blog\Model\Topic + */ + public function getTopic() + { + return $this->coreRegistry->registry('mageplaza_blog_topic'); + } - /** - * get grid url - * - * @return string - */ - public function getGridUrl() - { - return $this->getUrl( - '*/*/postsGrid', - [ - 'topic_id' => $this->getTopic()->getId() - ] - ); - } + /** + * @param \Magento\Backend\Block\Widget\Grid\Column $column + * @return $this + */ + protected function _addColumnFilterToCollection($column) + { + if ($column->getId() == 'in_posts') { + $postIds = $this->_getSelectedPosts(); + if (empty($postIds)) { + $postIds = 0; + } + if ($column->getFilter()->getValue()) { + $this->getCollection()->addFieldToFilter('main_table.post_id', ['in'=>$postIds]); + } else { + if ($postIds) { + $this->getCollection()->addFieldToFilter('main_table.post_id', ['nin'=>$postIds]); + } + } + } else { + parent::_addColumnFilterToCollection($column); + } + return $this; + } - /** - * @return \Mageplaza\Blog\Model\Topic - */ - public function getTopic() - { - return $this->coreRegistry->registry('mageplaza_blog_topic'); - } + /** + * @return string + */ + public function getTabLabel() + { + return __('Posts'); + } - /** - * @param \Magento\Backend\Block\Widget\Grid\Column $column - * @return $this - */ - protected function _addColumnFilterToCollection($column) - { - if ($column->getId() == 'in_posts') { - $postIds = $this->_getSelectedPosts(); - if (empty($postIds)) { - $postIds = 0; - } - if ($column->getFilter()->getValue()) { - $this->getCollection()->addFieldToFilter('main_table.post_id', ['in' => $postIds]); - } else { - if ($postIds) { - $this->getCollection()->addFieldToFilter('main_table.post_id', ['nin' => $postIds]); - } - } - } else { - parent::_addColumnFilterToCollection($column); - } + /** + * @return bool + */ + public function isHidden() + { + return false; + } - return $this; - } + /** + * @return string + */ + public function getTabTitle() + { + return $this->getTabLabel(); + } - /** - * @return string - */ - public function getTabLabel() - { - return __('Posts'); - } + /** + * @return bool + */ + public function canShowTab() + { + return true; + } - /** - * @return bool - */ - public function isHidden() - { - return false; - } + /** + * @return string + */ + public function getTabUrl() + { + return $this->getUrl('mageplaza_blog/topic/posts', ['_current' => true]); + } - /** - * @return string - */ - public function getTabTitle() - { - return $this->getTabLabel(); - } - - /** - * @return bool - */ - public function canShowTab() - { - return true; - } - - /** - * @return string - */ - public function getTabUrl() - { - return $this->getUrl('mageplaza_blog/topic/posts', ['_current' => true]); - } - - /** - * @return string - */ - public function getTabClass() - { - return 'ajax only'; - } + /** + * @return string + */ + public function getTabClass() + { + return 'ajax only'; + } } diff --git a/Block/Adminhtml/Topic/Edit/Tab/Topic.php b/Block/Adminhtml/Topic/Edit/Tab/Topic.php index 95b4813d..f52ad511 100755 --- a/Block/Adminhtml/Topic/Edit/Tab/Topic.php +++ b/Block/Adminhtml/Topic/Edit/Tab/Topic.php @@ -2,223 +2,222 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Topic\Edit\Tab; class Topic extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Backend\Block\Widget\Tab\TabInterface { - /** - * Wysiwyg config - * - * @var \Magento\Cms\Model\Wysiwyg\Config - */ - protected $wysiwygConfig; + /** + * Wysiwyg config + * + * @var \Magento\Cms\Model\Wysiwyg\Config + */ + protected $wysiwygConfig; - /** - * Country options - * - * @var \Magento\Config\Model\Config\Source\Yesno - */ - protected $booleanOptions; + /** + * Country options + * + * @var \Magento\Config\Model\Config\Source\Yesno + */ + protected $booleanOptions; - /** - * Meta Robots options - * - * @var \Mageplaza\Blog\Model\Topic\Source\MetaRobots - */ - protected $metaRobotsOptions; + /** + * Meta Robots options + * + * @var \Mageplaza\Blog\Model\Topic\Source\MetaRobots + */ + protected $metaRobotsOptions; - /** - * constructor - * - * @param \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig - * @param \Magento\Config\Model\Config\Source\Yesno $booleanOptions - * @param \Mageplaza\Blog\Model\Topic\Source\MetaRobots $metaRobotsOptions - * @param \Magento\Backend\Block\Template\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Data\FormFactory $formFactory - * @param array $data - */ - public function __construct( - \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig, - \Magento\Config\Model\Config\Source\Yesno $booleanOptions, - \Mageplaza\Blog\Model\Topic\Source\MetaRobots $metaRobotsOptions, - \Magento\Backend\Block\Template\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Data\FormFactory $formFactory, - array $data = [] - ) - { - $this->wysiwygConfig = $wysiwygConfig; - $this->booleanOptions = $booleanOptions; - $this->metaRobotsOptions = $metaRobotsOptions; - parent::__construct($context, $registry, $formFactory, $data); - } + /** + * constructor + * + * @param \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig + * @param \Magento\Config\Model\Config\Source\Yesno $booleanOptions + * @param \Mageplaza\Blog\Model\Topic\Source\MetaRobots $metaRobotsOptions + * @param \Magento\Backend\Block\Template\Context $context + * @param \Magento\Framework\Registry $registry + * @param \Magento\Framework\Data\FormFactory $formFactory + * @param array $data + */ + public function __construct( + \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig, + \Magento\Config\Model\Config\Source\Yesno $booleanOptions, + \Mageplaza\Blog\Model\Topic\Source\MetaRobots $metaRobotsOptions, + \Magento\Backend\Block\Template\Context $context, + \Magento\Framework\Registry $registry, + \Magento\Framework\Data\FormFactory $formFactory, + array $data = [] + ) + { + $this->wysiwygConfig = $wysiwygConfig; + $this->booleanOptions = $booleanOptions; + $this->metaRobotsOptions = $metaRobotsOptions; + parent::__construct($context, $registry, $formFactory, $data); + } - /** - * Prepare form - * - * @return $this - */ - protected function _prepareForm() - { - /** @var \Mageplaza\Blog\Model\Topic $topic */ - $topic = $this->_coreRegistry->registry('mageplaza_blog_topic'); - $form = $this->_formFactory->create(); - $form->setHtmlIdPrefix('topic_'); - $form->setFieldNameSuffix('topic'); - $fieldset = $form->addFieldset( - 'base_fieldset', - [ - 'legend' => __('Topic Information'), - 'class' => 'fieldset-wide' - ] - ); - if ($topic->getId()) { - $fieldset->addField( - 'topic_id', - 'hidden', - ['name' => 'topic_id'] - ); - } - $fieldset->addField( - 'name', - 'text', - [ - 'name' => 'name', - 'label' => __('Name'), - 'title' => __('Name'), - 'required' => true, - ] - ); - $fieldset->addField( - 'description', - 'editor', - [ - 'name' => 'description', - 'label' => __('Description'), - 'title' => __('Description'), - 'config' => $this->wysiwygConfig->getConfig() - ] - ); - $fieldset->addField( - 'enabled', - 'select', - [ - 'name' => 'enabled', - 'label' => __('Enabled'), - 'title' => __('Enabled'), - 'values' => $this->booleanOptions->toOptionArray(), - ] - ); - $fieldset->addField( - 'url_key', - 'text', - [ - 'name' => 'url_key', - 'label' => __('URL Key'), - 'title' => __('URL Key'), - ] - ); - $fieldset->addField( - 'meta_title', - 'text', - [ - 'name' => 'meta_title', - 'label' => __('Meta Title'), - 'title' => __('Meta Title'), - ] - ); - $fieldset->addField( - 'meta_description', - 'textarea', - [ - 'name' => 'meta_description', - 'label' => __('Meta Description'), - 'title' => __('Meta Description'), - ] - ); - $fieldset->addField( - 'meta_keywords', - 'textarea', - [ - 'name' => 'meta_keywords', - 'label' => __('Meta Keywords'), - 'title' => __('Meta Keywords'), - ] - ); - $fieldset->addField( - 'meta_robots', - 'select', - [ - 'name' => 'meta_robots', - 'label' => __('Meta Robots'), - 'title' => __('Meta Robots'), - 'values' => array_merge(['' => ''], $this->metaRobotsOptions->toOptionArray()), - ] - ); + /** + * Prepare form + * + * @return $this + */ + protected function _prepareForm() + { + /** @var \Mageplaza\Blog\Model\Topic $topic */ + $topic = $this->_coreRegistry->registry('mageplaza_blog_topic'); + $form = $this->_formFactory->create(); + $form->setHtmlIdPrefix('topic_'); + $form->setFieldNameSuffix('topic'); + $fieldset = $form->addFieldset( + 'base_fieldset', + [ + 'legend' => __('Topic Information'), + 'class' => 'fieldset-wide' + ] + ); + if ($topic->getId()) { + $fieldset->addField( + 'topic_id', + 'hidden', + ['name' => 'topic_id'] + ); + } + $fieldset->addField( + 'name', + 'text', + [ + 'name' => 'name', + 'label' => __('Name'), + 'title' => __('Name'), + 'required' => true, + ] + ); + $fieldset->addField( + 'description', + 'editor', + [ + 'name' => 'description', + 'label' => __('Description'), + 'title' => __('Description'), + 'config' => $this->wysiwygConfig->getConfig() + ] + ); + $fieldset->addField( + 'enabled', + 'select', + [ + 'name' => 'enabled', + 'label' => __('Enabled'), + 'title' => __('Enabled'), + 'values' => $this->booleanOptions->toOptionArray(), + ] + ); + $fieldset->addField( + 'url_key', + 'text', + [ + 'name' => 'url_key', + 'label' => __('URL Key'), + 'title' => __('URL Key'), + ] + ); + $fieldset->addField( + 'meta_title', + 'text', + [ + 'name' => 'meta_title', + 'label' => __('Meta Title'), + 'title' => __('Meta Title'), + ] + ); + $fieldset->addField( + 'meta_description', + 'textarea', + [ + 'name' => 'meta_description', + 'label' => __('Meta Description'), + 'title' => __('Meta Description'), + ] + ); + $fieldset->addField( + 'meta_keywords', + 'textarea', + [ + 'name' => 'meta_keywords', + 'label' => __('Meta Keywords'), + 'title' => __('Meta Keywords'), + ] + ); + $fieldset->addField( + 'meta_robots', + 'select', + [ + 'name' => 'meta_robots', + 'label' => __('Meta Robots'), + 'title' => __('Meta Robots'), + 'values' => array_merge(['' => ''], $this->metaRobotsOptions->toOptionArray()), + ] + ); - $topicData = $this->_session->getData('mageplaza_blog_topic_data', true); - if ($topicData) { - $topic->addData($topicData); - } else { - if (!$topic->getId()) { - $topic->addData($topic->getDefaultValues()); - } - } - $form->addValues($topic->getData()); - $this->setForm($form); + $topicData = $this->_session->getData('mageplaza_blog_topic_data', true); + if ($topicData) { + $topic->addData($topicData); + } else { + if (!$topic->getId()) { + $topic->addData($topic->getDefaultValues()); + } + } + $form->addValues($topic->getData()); + $this->setForm($form); + return parent::_prepareForm(); + } - return parent::_prepareForm(); - } + /** + * Prepare label for tab + * + * @return string + */ + public function getTabLabel() + { + return __('Topic'); + } - /** - * Prepare label for tab - * - * @return string - */ - public function getTabLabel() - { - return __('Topic'); - } + /** + * Prepare title for tab + * + * @return string + */ + public function getTabTitle() + { + return $this->getTabLabel(); + } - /** - * Prepare title for tab - * - * @return string - */ - public function getTabTitle() - { - return $this->getTabLabel(); - } + /** + * Can show tab in tabs + * + * @return boolean + */ + public function canShowTab() + { + return true; + } - /** - * Can show tab in tabs - * - * @return boolean - */ - public function canShowTab() - { - return true; - } - - /** - * Tab is hidden - * - * @return boolean - */ - public function isHidden() - { - return false; - } + /** + * Tab is hidden + * + * @return boolean + */ + public function isHidden() + { + return false; + } } diff --git a/Block/Adminhtml/Topic/Edit/Tabs.php b/Block/Adminhtml/Topic/Edit/Tabs.php index b90d1f1f..65add546 100755 --- a/Block/Adminhtml/Topic/Edit/Tabs.php +++ b/Block/Adminhtml/Topic/Edit/Tabs.php @@ -2,16 +2,16 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Topic\Edit; @@ -20,16 +20,16 @@ */ class Tabs extends \Magento\Backend\Block\Widget\Tabs { - /** - * constructor - * - * @return void - */ - protected function _construct() - { - parent::_construct(); - $this->setId('topic_tabs'); - $this->setDestElementId('edit_form'); - $this->setTitle(__('Topic Information')); - } + /** + * constructor + * + * @return void + */ + protected function _construct() + { + parent::_construct(); + $this->setId('topic_tabs'); + $this->setDestElementId('edit_form'); + $this->setTitle(__('Topic Information')); + } } diff --git a/Block/Adminhtml/Topic/Grid.php b/Block/Adminhtml/Topic/Grid.php index 96670e9e..90c168bf 100755 --- a/Block/Adminhtml/Topic/Grid.php +++ b/Block/Adminhtml/Topic/Grid.php @@ -2,16 +2,16 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Block\Adminhtml\Topic; diff --git a/Block/Category/Listpost.php b/Block/Category/Listpost.php index e772947d..5e986434 100755 --- a/Block/Category/Listpost.php +++ b/Block/Category/Listpost.php @@ -20,16 +20,13 @@ class Listpost extends Frontend { - /** - * @throws \Magento\Framework\Exception\LocalizedException - */ protected function _prepareLayout() { $url = $this->helperData->getCurrentUrl(); $array = explode('/', $url); $key = array_search('category', $array) + 1; $categoryName = ($array[$key]); - $category = $this->helperData->getCategoryByParam('url_key', $categoryName); + $category=$this->helperData->getCategoryByParam('url_key',$categoryName); $breadcrumbs = $this->getLayout()->getBlock('breadcrumbs'); if ($breadcrumbs) { $breadcrumbs->addCrumb( @@ -42,13 +39,13 @@ protected function _prepareLayout() ); $breadcrumbs->addCrumb( $this->helperData->getBlogConfig('general/url_prefix'), - ['label' => $this->helperData->getBlogConfig('general/url_prefix'), + ['label' => ucfirst($this->helperData->getBlogConfig('general/url_prefix')), 'title' => $this->helperData->getBlogConfig('general/url_prefix'), 'link' => $this->_storeManager->getStore()->getBaseUrl() . $this->helperData->getBlogConfig('general/url_prefix')] ); $breadcrumbs->addCrumb( $categoryName, - ['label' => $category->getName(), + ['label' => ucfirst($category->getName()), 'title' => $category->getName() ] ); @@ -58,17 +55,11 @@ protected function _prepareLayout() } - /** - * @return $this|\Mageplaza\Blog\Model\Post - */ public function getPostList() { return $this->helperData->getPostList('category', $this->getRequest()->getParam('id')); } - /** - * @return bool|string - */ public function checkRss() { $categoryId = $this->getRequest()->getParam('id'); diff --git a/Block/Category/Widget.php b/Block/Category/Widget.php index b3e299b1..603e5588 100755 --- a/Block/Category/Widget.php +++ b/Block/Category/Widget.php @@ -20,18 +20,12 @@ class Widget extends Frontend { - /** - * @return $this - */ + public function getCategoryList() { return $this->helperData->getCategoryList(); } - /** - * @param $category - * @return string - */ public function getCategoryUrl($category) { return $this->helperData->getCategoryUrl($category); diff --git a/Block/Frontend.php b/Block/Frontend.php index 03572922..e8f0c8bd 100755 --- a/Block/Frontend.php +++ b/Block/Frontend.php @@ -29,14 +29,6 @@ class Frontend extends Template protected $storeManager; protected $localeDate; - /** - * Frontend constructor. - * @param \Magento\Framework\View\Element\Template\Context $context - * @param \Mageplaza\Blog\Helper\Data $helperData - * @param \Magento\Framework\ObjectManagerInterface $objectManager - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param array $data - */ public function __construct( Context $context, HelperData $helperData, @@ -52,68 +44,42 @@ public function __construct( parent::__construct($context, $data); } - /** - * @return $this - */ public function getCurrentPost() { return $this->helperData->getPost($this->getRequest()->getParam('id')); } - /** - * @param $post - * @return string - */ public function getUrlByPost($post) { return $this->helperData->getUrlByPost($post); } - /** - * @param $image - * @return string - */ public function getImageUrl($image) { return $this->helperData->getImageUrl($image); } - /** - * @param $createdAt - * @return \DateTime - */ public function getCreatedAtStoreDate($createdAt) { return $this->_localeDate->scopeDate($this->storeManager->getStore(), $createdAt, true); } - /** - * @param $post - * @return null - */ public function getPostCategoryHtml($post) { return $this->helperData->getPostCategoryHtml($post); } - /** - * @param $code - * @return mixed - */ public function getBlogConfig($code) { return $this->helperData->getBlogConfig($code); } - /** - * @return $this - * @throws \Magento\Framework\Exception\LocalizedException - */ protected function _prepareLayout() { $actionName = $this->getRequest()->getFullActionName(); $breadcrumbs = $this->getLayout()->getBlock('breadcrumbs'); + $breadcrumbsLabel = ucfirst($this->helperData->getBlogConfig('general/url_prefix')); if ($breadcrumbs) { if ($actionName == 'blog_post_index') { $breadcrumbs->addCrumb( @@ -125,7 +91,7 @@ protected function _prepareLayout() ] )->addCrumb( $this->helperData->getBlogConfig('general/url_prefix'), - ['label' => $this->helperData->getBlogConfig('general/url_prefix'), 'title' => $this->helperData->getBlogConfig('general/url_prefix')] + ['label' => $breadcrumbsLabel, 'title' => $this->helperData->getBlogConfig('general/url_prefix')] ); $this->applySeoCode(); @@ -142,21 +108,21 @@ protected function _prepareLayout() ); $breadcrumbs->addCrumb( $this->helperData->getBlogConfig('general/url_prefix'), - ['label' => $this->helperData->getBlogConfig('general/url_prefix'), + ['label' => $breadcrumbsLabel, 'title' => $this->helperData->getBlogConfig('general/url_prefix'), 'link' => $this->_storeManager->getStore()->getBaseUrl() . $this->helperData->getBlogConfig('general/url_prefix')] ); if ($category->getId()) { $breadcrumbs->addCrumb( $category->getUrlKey(), - ['label' => $category->getName(), + ['label' => ucfirst($category->getName()), 'title' => $category->getName(), 'link' => $this->helperData->getCategoryUrl($category)] ); } $breadcrumbs->addCrumb( $post->getUrlKey(), - ['label' => $post->getName(), + ['label' => ucfirst($post->getName()), 'title' => $post->getName()] ); $this->applySeoCode($post); @@ -195,7 +161,7 @@ protected function _prepareLayout() ] )->addCrumb( $this->helperData->getBlogConfig('general/url_prefix'), - ['label' => $this->helperData->getBlogConfig('general/url_prefix'), + ['label' => $breadcrumbsLabel, 'title' => $this->helperData->getBlogConfig('general/url_prefix'), 'link' => $this->_storeManager->getStore()->getBaseUrl() . $this->helperData->getBlogConfig('general/url_prefix')] @@ -205,7 +171,7 @@ protected function _prepareLayout() 'title' => 'Tag'] )->addCrumb( 'Tag' . $tag->getId(), - ['label' => $tag->getName(), + ['label' => ucfirst($tag->getName()), 'title' => $tag->getName()] ); $this->applySeoCode(); @@ -221,7 +187,7 @@ protected function _prepareLayout() ] )->addCrumb( $this->helperData->getBlogConfig('general/url_prefix'), - ['label' => $this->helperData->getBlogConfig('general/url_prefix'), + ['label' => $breadcrumbsLabel, 'title' => $this->helperData->getBlogConfig('general/url_prefix'), 'link' => $this->_storeManager->getStore()->getBaseUrl() . $this->helperData->getBlogConfig('general/url_prefix')] @@ -231,7 +197,7 @@ protected function _prepareLayout() 'title' => 'Topic'] )->addCrumb( 'topic' . $topic->getId(), - ['label' => $topic->getName(), + ['label' => ucfirst($topic->getName()), 'title' => $topic->getName()] ); $this->applySeoCode($topic); @@ -243,9 +209,6 @@ protected function _prepareLayout() return parent::_prepareLayout(); } - /** - * @param null $post - */ public function applySeoCode($post = null) { if ($post) { diff --git a/Block/Post/Listpost.php b/Block/Post/Listpost.php index b5b3e9bf..4d4c092e 100755 --- a/Block/Post/Listpost.php +++ b/Block/Post/Listpost.php @@ -20,17 +20,12 @@ class Listpost extends Frontend { - /** - * @return $this|\Mageplaza\Blog\Model\Post - */ + public function getPostList() { return $this->helperData->getPostList(); } - /** - * @return string - */ public function checkRss() { return $this->helperData->getBlogUrl('post/rss'); diff --git a/Block/Post/Rss/Category.php b/Block/Post/Rss/Category.php index 2e576082..e83a3eb5 100755 --- a/Block/Post/Rss/Category.php +++ b/Block/Post/Rss/Category.php @@ -82,9 +82,9 @@ public function isAllowed() */ public function getRssData() { - $categoryId = $this->getRequest()->getParam('category_id'); + $categoryId=$this->getRequest()->getParam('category_id'); $storeModel = $this->storeManager->getStore($this->getStoreId()); - $newUrl = $this->rssUrlBuilder->getUrl(['store_id' => $this->getStoreId(), 'type' => 'blog_categories', 'category_id' => $categoryId]); + $newUrl = $this->rssUrlBuilder->getUrl(['store_id' => $this->getStoreId(), 'type' => 'blog_categories','category_id'=>$categoryId]); $title = __('List Posts from %1', $storeModel->getFrontendName()); $lang = $this->_scopeConfig->getValue( 'general/locale/code', @@ -100,8 +100,8 @@ public function getRssData() ]; $limit = 10; $count = 0; - $category = $this->rssModel->create()->load($categoryId); - $posts = $category->getSelectedPostsCollection(); + $category = $this->rssModel->create()->load($categoryId); + $posts=$category->getSelectedPostsCollection(); $posts ->addFieldToFilter('enabled', 1) ->setOrder('post_id', 'DESC'); diff --git a/Block/Post/View.php b/Block/Post/View.php index ccae4fe3..1e00cbe7 100755 --- a/Block/Post/View.php +++ b/Block/Post/View.php @@ -19,36 +19,22 @@ class View extends Frontend { - /** - * @param $topic - * @return string - */ + public function getTopicUrl($topic) { return $this->helperData->getTopicUrl($topic); } - /** - * @param $tag - * @return string - */ public function getTagUrl($tag) { return $this->helperData->getTagUrl($tag); } - /** - * @param $category - * @return string - */ public function getCategoryUrl($category) { return $this->helperData->getCategoryUrl($category); } - /** - * @return bool|mixed - */ public function checkComment() { if (!$this->helperData->getBlogConfig('general/enabled')) @@ -58,12 +44,29 @@ public function checkComment() return $comment; } - /** - * @param $code - * @return mixed - */ public function helperComment($code) { return $this->helperData->getBlogConfig('comment/' . $code); } + + /** + * get tag list + * @param $post + * @return string + */ + public function getTagList($post) + { + $tagCollection = $post->getSelectedTagsCollection(); + $result = ''; + if (count($tagCollection)): + $listTags = array(); + foreach ($tagCollection as $tag) { + $listTags[] = '' . $tag->getName() . ''; + } + $result = implode(', ', $listTags); + endif; + + return $result; + } + } diff --git a/Block/Sidebar/Mostview.php b/Block/Sidebar/Mostview.php index 257f4131..edc9d38c 100755 --- a/Block/Sidebar/Mostview.php +++ b/Block/Sidebar/Mostview.php @@ -20,9 +20,6 @@ class Mostview extends Frontend { - /** - * @return mixed - */ public function getMosviewPosts() { $ob = $this->objectManager->get('Mageplaza\Blog\Model\Traffic'); @@ -32,14 +29,12 @@ public function getMosviewPosts() 'main_table.post_id=mageplaza_blog_post.post_id', '*' ); + $posts->setPageSize($this->getLimitPost())->setCurPage(1); $posts->setOrder('numbers_view', 'DESC'); return $posts; } - /** - * @return mixed - */ public function getLimitPost() { return $this->helperData->getBlogConfig('sidebar/number_mostview_posts'); diff --git a/Block/Tag/Listpost.php b/Block/Tag/Listpost.php index 49c4f18d..447d68a0 100755 --- a/Block/Tag/Listpost.php +++ b/Block/Tag/Listpost.php @@ -20,17 +20,10 @@ class Listpost extends Frontend { - /** - * @return $this|\Mageplaza\Blog\Model\Post - */ - public function getPostList() - { - return $this->helperData->getPostList('tag', $this->getRequest()->getParam('id')); - } - /** - * @return string - */ + public function getPostList(){ + return $this->helperData->getPostList('tag',$this->getRequest()->getParam('id')); + } public function checkRss() { return $this->helperData->getBlogUrl('post/rss'); diff --git a/Block/Tag/Widget.php b/Block/Tag/Widget.php index afb00d5b..240ecc77 100755 --- a/Block/Tag/Widget.php +++ b/Block/Tag/Widget.php @@ -20,19 +20,12 @@ class Widget extends Frontend { - /** - * @return $this - */ public function getTagList() { return $this->helperData->getTagList(); } - /** - * @param $tag - * @return string - */ public function getTagUrl($tag) { return $this->helperData->getTagUrl($tag); diff --git a/Block/Topic/Listpost.php b/Block/Topic/Listpost.php index 6e34dfba..a5420631 100755 --- a/Block/Topic/Listpost.php +++ b/Block/Topic/Listpost.php @@ -20,17 +20,11 @@ class Listpost extends Frontend { - /** - * @return $this|\Mageplaza\Blog\Model\Post - */ + public function getPostList() { return $this->helperData->getPostList('topic', $this->getRequest()->getParam('id')); } - - /** - * @return string - */ public function checkRss() { return $this->helperData->getBlogUrl('post/rss'); diff --git a/Controller/Adminhtml/Post/Save.php b/Controller/Adminhtml/Post/Save.php index 7dfc47a0..9a43592f 100755 --- a/Controller/Adminhtml/Post/Save.php +++ b/Controller/Adminhtml/Post/Save.php @@ -86,7 +86,7 @@ public function __construct( public function execute() { $data = $this->getRequest()->getPost('post'); - if (($_FILES['image']['name'] == '')) { + if (isset($_FILES['image']) AND ($_FILES['image']['name'] == '')) { if (isset($data['image'])) { unset($data['image']); } diff --git a/Controller/Category/Index.php b/Controller/Category/Index.php index 82caa5cd..9ef6666f 100755 --- a/Controller/Category/Index.php +++ b/Controller/Category/Index.php @@ -22,16 +22,6 @@ class Index extends Action protected $helperData; protected $storeManager; - /** - * Index constructor. - * @param \Magento\Framework\App\Action\Context $context - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Mageplaza\Blog\Helper\Data $helperBlog - * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Customer\Api\AccountManagementInterface $accountManagement - * @param \Magento\Customer\Model\Url $customerUrl - * @param \Magento\Customer\Model\Session $customerSession - */ public function __construct( Context $context, StoreManagerInterface $storeManager, @@ -51,9 +41,6 @@ public function __construct( } - /** - * @return \Magento\Framework\View\Result\Page - */ public function execute() { return $this->resultPageFactory->create(); diff --git a/Controller/Category/Rss.php b/Controller/Category/Rss.php index 3c862694..76a04e6a 100755 --- a/Controller/Category/Rss.php +++ b/Controller/Category/Rss.php @@ -5,9 +5,6 @@ class Rss extends \Magento\Rss\Controller\Feed { - /** - * @throws \Magento\Framework\Exception\NotFoundException - */ public function execute() { diff --git a/Controller/Category/View.php b/Controller/Category/View.php index 1e40aa16..4ccc8cf9 100755 --- a/Controller/Category/View.php +++ b/Controller/Category/View.php @@ -22,16 +22,6 @@ class View extends Action protected $helperData; protected $storeManager; - /** - * View constructor. - * @param \Magento\Framework\App\Action\Context $context - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Mageplaza\Blog\Helper\Data $helperBlog - * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Customer\Api\AccountManagementInterface $accountManagement - * @param \Magento\Customer\Model\Url $customerUrl - * @param \Magento\Customer\Model\Session $customerSession - */ public function __construct( Context $context, StoreManagerInterface $storeManager, @@ -51,9 +41,6 @@ public function __construct( } - /** - * @return \Magento\Framework\View\Result\Page - */ public function execute() { return $this->resultPageFactory->create(); diff --git a/Controller/Post/Index.php b/Controller/Post/Index.php index bf2e5bd1..83f5a6f0 100755 --- a/Controller/Post/Index.php +++ b/Controller/Post/Index.php @@ -22,16 +22,6 @@ class Index extends Action protected $helperData; protected $storeManager; - /** - * Index constructor. - * @param \Magento\Framework\App\Action\Context $context - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Mageplaza\Blog\Helper\Data $helperBlog - * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Customer\Api\AccountManagementInterface $accountManagement - * @param \Magento\Customer\Model\Url $customerUrl - * @param \Magento\Customer\Model\Session $customerSession - */ public function __construct( Context $context, StoreManagerInterface $storeManager, @@ -51,9 +41,6 @@ public function __construct( } - /** - * @return \Magento\Framework\View\Result\Page - */ public function execute() { return $this->resultPageFactory->create(); diff --git a/Controller/Post/Rss.php b/Controller/Post/Rss.php index 79b4eb2a..938aa46d 100755 --- a/Controller/Post/Rss.php +++ b/Controller/Post/Rss.php @@ -5,9 +5,6 @@ class Rss extends \Magento\Rss\Controller\Feed { - /** - * @throws \Magento\Framework\Exception\NotFoundException - */ public function execute() { diff --git a/Controller/Post/View.php b/Controller/Post/View.php index 042479e8..8ca29705 100755 --- a/Controller/Post/View.php +++ b/Controller/Post/View.php @@ -23,17 +23,6 @@ class View extends Action protected $session; protected $storeManager; - /** - * View constructor. - * @param \Magento\Framework\App\Action\Context $context - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Mageplaza\Blog\Helper\Data $helperBlog - * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Customer\Api\AccountManagementInterface $accountManagement - * @param \Magento\Customer\Model\Url $customerUrl - * @param \Magento\Customer\Model\Session $customerSession - * @param \Mageplaza\Blog\Model\TrafficFactory $trafficFactory - */ public function __construct( Context $context, StoreManagerInterface $storeManager, @@ -56,9 +45,6 @@ public function __construct( } - /** - * @return \Magento\Framework\View\Result\Page - */ public function execute() { $id=$this->getRequest()->getParams(); diff --git a/Controller/Tag/View.php b/Controller/Tag/View.php index 1ff5305e..ace311b6 100755 --- a/Controller/Tag/View.php +++ b/Controller/Tag/View.php @@ -22,16 +22,6 @@ class View extends Action protected $helperData; protected $storeManager; - /** - * View constructor. - * @param \Magento\Framework\App\Action\Context $context - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Mageplaza\Blog\Helper\Data $helperBlog - * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Customer\Api\AccountManagementInterface $accountManagement - * @param \Magento\Customer\Model\Url $customerUrl - * @param \Magento\Customer\Model\Session $customerSession - */ public function __construct( Context $context, StoreManagerInterface $storeManager, @@ -51,9 +41,6 @@ public function __construct( } - /** - * @return \Magento\Framework\View\Result\Page - */ public function execute() { return $this->resultPageFactory->create(); diff --git a/Controller/Topic/View.php b/Controller/Topic/View.php index ff705224..e04df12e 100755 --- a/Controller/Topic/View.php +++ b/Controller/Topic/View.php @@ -22,16 +22,6 @@ class View extends Action protected $helperData; protected $storeManager; - /** - * View constructor. - * @param \Magento\Framework\App\Action\Context $context - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Mageplaza\Blog\Helper\Data $helperBlog - * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Customer\Api\AccountManagementInterface $accountManagement - * @param \Magento\Customer\Model\Url $customerUrl - * @param \Magento\Customer\Model\Session $customerSession - */ public function __construct( Context $context, StoreManagerInterface $storeManager, @@ -51,9 +41,6 @@ public function __construct( } - /** - * @return \Magento\Framework\View\Result\Page - */ public function execute() { return $this->resultPageFactory->create(); diff --git a/Helper/Data.php b/Helper/Data.php index 14d199e2..fa07c103 100755 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -22,16 +22,6 @@ class Data extends AbstractHelper protected $tagfactory; protected $topicfactory; - /** - * Data constructor. - * @param \Magento\Framework\App\Helper\Context $context - * @param \Magento\Framework\ObjectManagerInterface $objectManager - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Mageplaza\Blog\Model\PostFactory $postFactory - * @param \Mageplaza\Blog\Model\CategoryFactory $categoryFactory - * @param \Mageplaza\Blog\Model\TagFactory $tagFactory - * @param \Mageplaza\Blog\Model\TopicFactory $topicFactory - */ public function __construct( Context $context, ObjectManagerInterface $objectManager, @@ -51,11 +41,6 @@ public function __construct( parent::__construct($context); } - /** - * @param $field - * @param null $storeId - * @return mixed - */ public function getConfigValue($field, $storeId = null) { return $this->scopeConfig->getValue( @@ -65,21 +50,11 @@ public function getConfigValue($field, $storeId = null) ); } - /** - * @param $code - * @param null $storeId - * @return mixed - */ public function getBlogConfig($code, $storeId = null) { return $this->getConfigValue(self::XML_PATH_BLOG . $code, $storeId); } - /** - * @param null $type - * @param null $id - * @return $this|\Mageplaza\Blog\Model\Post - */ public function getPostList($type = null, $id = null) { $list = ''; @@ -106,9 +81,6 @@ public function getPostList($type = null, $id = null) return $posts; } - /** - * @return $this - */ public function getCategoryList() { $category = $this->categoryfactory->create(); @@ -118,9 +90,6 @@ public function getCategoryList() return $list; } - /** - * @return $this - */ public function getTagList() { $tag = $this->tagfactory->create(); @@ -130,10 +99,6 @@ public function getTagList() return $list; } - /** - * @param $array - * @return $this - */ public function getCategoryCollection($array) { $category = $this->categoryfactory->create(); @@ -144,10 +109,6 @@ public function getCategoryCollection($array) return $list; } - /** - * @param $post - * @return string - */ public function getUrlByPost($post) { if ($post->getUrlKey()) { @@ -167,19 +128,11 @@ public function getUrlByPost($post) return $this->_getUrl($urlKey); } - /** - * @param $code - * @return string - */ public function getBlogUrl($code) { return $this->_getUrl($this->getBlogConfig('general/url_prefix') . '/' . $code); } - /** - * @param $url - * @return $this - */ public function getPostByUrl($url) { $url = $this->checkSuffix($url); @@ -188,10 +141,6 @@ public function getPostByUrl($url) return $posts; } - /** - * @param $url - * @return mixed - */ public function checkSuffix($url) { $url_suffix = $this->getBlogConfig('general/url_suffix'); @@ -202,10 +151,6 @@ public function checkSuffix($url) return $url; } - /** - * @param $tag - * @return \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection - */ public function getPostsByTag($tag) { $posts = $this->postfactory->create(); @@ -214,10 +159,6 @@ public function getPostsByTag($tag) return $collection; } - /** - * @param $category - * @return bool - */ public function getPostsByCategory($category) { $collection = true; @@ -225,54 +166,31 @@ public function getPostsByCategory($category) return $collection; } - /** - * @param $image - * @return string - */ public function getImageUrl($image) { - return $this->getBaseMediaUrl() . '/' . $image; + return $this->getBaseMediaUrl() . $image; } - /** - * @return mixed - */ public function getBaseMediaUrl() { return $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA); } - /** - * @param $category - * @return string - */ public function getCategoryUrl($category) { return $this->_getUrl($this->getBlogConfig('general/url_prefix') . '/category/' . $category->getUrlKey()); } - /** - * @param $tag - * @return string - */ public function getTagUrl($tag) { return $this->_getUrl($this->getBlogConfig('general/url_prefix') . '/tag/' . $tag->getUrlKey()); } - /** - * @param $topic - * @return string - */ public function getTopicUrl($topic) { return $this->_getUrl($this->getBlogConfig('general/url_prefix') . '/topic/' . $topic->getUrlKey()); } - /** - * @param $post - * @return null - */ public function getPostCategoryHtml($post) { @@ -291,10 +209,6 @@ public function getPostCategoryHtml($post) } - /** - * @param $id - * @return $this - */ public function getPost($id) { $post = $this->postfactory->create()->load($id); @@ -302,11 +216,6 @@ public function getPost($id) return $post; } - /** - * @param $code - * @param $param - * @return $this - */ public function getCategoryByParam($code, $param) { if ($code == 'id') { @@ -316,12 +225,6 @@ public function getCategoryByParam($code, $param) } } - - /** - * @param $code - * @param $param - * @return $this - */ public function getTagByParam($code, $param) { if ($code == 'id') { @@ -331,12 +234,6 @@ public function getTagByParam($code, $param) } } - - /** - * @param $code - * @param $param - * @return $this - */ public function getTopicByParam($code, $param) { if ($code == 'id') { @@ -346,11 +243,6 @@ public function getTopicByParam($code, $param) } } - - /** - * @param $postId - * @return \Mageplaza\Blog\Model\ResourceModel\Category\Collection - */ public function getCategoryByPost($postId) { $post = $this->postfactory->create()->load($postId); @@ -358,10 +250,6 @@ public function getCategoryByPost($postId) return $post->getSelectedCategoriesCollection(); } - /** - * @param $postId - * @return \Mageplaza\Blog\Model\ResourceModel\Tag\Collection - */ public function getTagsByPost($postId) { $post = $this->postfactory->create()->load($postId); @@ -369,20 +257,12 @@ public function getTagsByPost($postId) return $post->getSelectedTagsCollection(); } - /** - * @param $postId - * @return \Mageplaza\Blog\Model\ResourceModel\Topic\Collection - */ public function getTopicByPost($postId) { $post = $this->postfactory->create()->load($postId); return $post->getSelectedTopicsCollection(); } - - /** - * @return mixed - */ public function getCurrentUrl(){ $model=$this->objectManager->get('Magento\Framework\UrlInterface'); return $model->getCurrentUrl(); diff --git a/Model/Category/Source/MetaRobots.php b/Model/Category/Source/MetaRobots.php index c1bae506..72772249 100755 --- a/Model/Category/Source/MetaRobots.php +++ b/Model/Category/Source/MetaRobots.php @@ -2,62 +2,57 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Model\Category\Source; class MetaRobots implements \Magento\Framework\Option\ArrayInterface { - const INDEXFOLLOW = 1; - const NOINDEXNOFOLLOW = 2; - const NOINDEXFOLLOW = 3; - const INDEXNOFOLLOW = 4; + const INDEXFOLLOW = 1; + const NOINDEXNOFOLLOW = 2; + const NOINDEXFOLLOW = 3; + const INDEXNOFOLLOW = 4; - /** - * to option array - * - * @return array - */ - public function toOptionArray() - { - $options = [ - [ - 'value' => self::INDEXFOLLOW, - 'label' => __('INDEX,FOLLOW') - ], - [ - 'value' => self::NOINDEXNOFOLLOW, - 'label' => __('NOINDEX,NOFOLLOW') - ], - [ - 'value' => self::NOINDEXFOLLOW, - 'label' => __('NOINDEX,FOLLOW') - ], - [ - 'value' => self::INDEXNOFOLLOW, - 'label' => __('INDEX,NOFOLLOW') - ], - ]; + /** + * to option array + * + * @return array + */ + public function toOptionArray() + { + $options = [ + [ + 'value' => self::INDEXFOLLOW, + 'label' => __('INDEX,FOLLOW') + ], + [ + 'value' => self::NOINDEXNOFOLLOW, + 'label' => __('NOINDEX,NOFOLLOW') + ], + [ + 'value' => self::NOINDEXFOLLOW, + 'label' => __('NOINDEX,FOLLOW') + ], + [ + 'value' => self::INDEXNOFOLLOW, + 'label' => __('INDEX,NOFOLLOW') + ], + ]; + return $options; - return $options; - - } - - /** - * @return array - */ - public function getOptionArray() - { - return array(self::INDEXFOLLOW => 'INDEX,FOLLOW', self::NOINDEXNOFOLLOW => 'NOINDEX,NOFOLLOW', self::NOINDEXFOLLOW => 'NOINDEX,FOLLOW', self::INDEXNOFOLLOW => 'INDEX,NOFOLLOW'); - } + } + public function getOptionArray() + { + return array(self::INDEXFOLLOW => 'INDEX,FOLLOW', self::NOINDEXNOFOLLOW => 'NOINDEX,NOFOLLOW', self::NOINDEXFOLLOW => 'NOINDEX,FOLLOW', self::INDEXNOFOLLOW => 'INDEX,NOFOLLOW'); + } } diff --git a/Model/Config/Source/Comments/Facebook/Colorscheme.php b/Model/Config/Source/Comments/Facebook/Colorscheme.php index edba79f8..313ba4b1 100755 --- a/Model/Config/Source/Comments/Facebook/Colorscheme.php +++ b/Model/Config/Source/Comments/Facebook/Colorscheme.php @@ -13,15 +13,12 @@ class Colorscheme implements \Magento\Framework\Option\ArrayInterface { const LIGHT = 'light'; - const DARK = 'dark'; + const DARK = 'dark'; - /** - * @return array - */ public function toOptionArray() - { - return [['value' => self::LIGHT, 'label' => __('Light')], ['value' => self::DARK, 'label' => __('Dark')]]; - } +{ + return [['value' => self::LIGHT, 'label' => __('Light')], ['value' => self::DARK, 'label' => __('Dark')]]; +} /** * Get options in "key-value" format @@ -29,15 +26,12 @@ public function toOptionArray() * @return array */ public function toArray() - { - return [self::LIGHT => __('Light'), self::DARK => __('Dark')]; - } +{ + return [self::LIGHT => __('Light'), self::DARK => __('Dark')]; +} - /** - * @return array - */ public function getAllOptions() - { - return $this->toOptionArray(); - } +{ + return $this->toOptionArray(); +} } diff --git a/Model/Config/Source/Comments/Facebook/Orderby.php b/Model/Config/Source/Comments/Facebook/Orderby.php index c6a391fc..310b467f 100755 --- a/Model/Config/Source/Comments/Facebook/Orderby.php +++ b/Model/Config/Source/Comments/Facebook/Orderby.php @@ -13,16 +13,13 @@ class Orderby implements \Magento\Framework\Option\ArrayInterface { const SOCIAL = 'social'; - const REVERSE_TIME = 'reverse_time'; - const TIME = 'time'; + const REVERSE_TIME = 'reverse_time'; + const TIME = 'time'; - /** - * @return array - */ public function toOptionArray() - { - return [['value' => self::SOCIAL, 'label' => __('Social')], ['value' => self::REVERSE_TIME, 'label' => __('Reverse time')], ['value' => self::TIME, 'label' => __('Time')]]; - } +{ + return [['value' => self::SOCIAL, 'label' => __('Social')], ['value' => self::REVERSE_TIME, 'label' => __('Reverse time')], ['value' => self::TIME, 'label' => __('Time')]]; +} /** * Get options in "key-value" format @@ -30,15 +27,12 @@ public function toOptionArray() * @return array */ public function toArray() - { - return [self::SOCIAL => __('Social'), self::REVERSE_TIME => __('Reverse time'), self::TIME => __('Time')]; - } +{ + return [self::SOCIAL => __('Social'), self::REVERSE_TIME => __('Reverse time'), self::TIME => __('Time')]; +} - /** - * @return array - */ public function getAllOptions() - { - return $this->toOptionArray(); - } +{ + return $this->toOptionArray(); +} } diff --git a/Model/Config/Source/Comments/Type.php b/Model/Config/Source/Comments/Type.php index 60ea5bee..702cacd5 100755 --- a/Model/Config/Source/Comments/Type.php +++ b/Model/Config/Source/Comments/Type.php @@ -22,9 +22,6 @@ class Type implements \Magento\Framework\Option\ArrayInterface const DEFAULT_COMMENT = 1; const DISABLE = 4; - /** - * @return array - */ public function toOptionArray() { return [ ['value' => self::DISQUS, 'label' => __('Disqus Comment')], ['value' => self::FACEBOOK, 'label' => __('Facebook Comment')], ['value' => self::DISABLE, 'label' => __('Disable Completely')]]; diff --git a/Model/Post.php b/Model/Post.php index cdb4aa10..8ae32043 100755 --- a/Model/Post.php +++ b/Model/Post.php @@ -2,16 +2,16 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Model; @@ -67,236 +67,327 @@ */ class Post extends \Magento\Framework\Model\AbstractModel { - /** - * Cache tag - * - * @var string - */ - const CACHE_TAG = 'mageplaza_blog_post'; - - /** - * Cache tag - * - * @var string - */ - protected $_cacheTag = 'mageplaza_blog_post'; - - /** - * Event prefix - * - * @var string - */ - protected $_eventPrefix = 'mageplaza_blog_post'; - - /** - * Tag Collection - * - * @var \Mageplaza\Blog\Model\ResourceModel\Tag\Collection - */ - protected $tagCollection; - - /** - * Topic Collection - * - * @var \Mageplaza\Blog\Model\ResourceModel\Topic\Collection - */ - protected $topicCollection; - - /** - * Category Collection - * - * @var \Mageplaza\Blog\Model\ResourceModel\Category\Collection - */ - protected $categoryCollection; - - /** - * Tag Collection Factory - * - * @var \Mageplaza\Blog\Model\ResourceModel\Tag\CollectionFactory - */ - protected $tagCollectionFactory; - - /** - * Topic Collection Factory - * - * @var \Mageplaza\Blog\Model\ResourceModel\Topic\CollectionFactory - */ - protected $topicCollectionFactory; - - /** - * Category Collection Factory - * - * @var \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory - */ - protected $categoryCollectionFactory; - - /** - * constructor - * - * @param \Mageplaza\Blog\Model\ResourceModel\Tag\CollectionFactory $tagCollectionFactory - * @param \Mageplaza\Blog\Model\ResourceModel\Topic\CollectionFactory $topicCollectionFactory - * @param \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource - * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection - * @param array $data - */ - public function __construct( - \Mageplaza\Blog\Model\ResourceModel\Tag\CollectionFactory $tagCollectionFactory, - \Mageplaza\Blog\Model\ResourceModel\Topic\CollectionFactory $topicCollectionFactory, - \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory, - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] - ) - { - $this->tagCollectionFactory = $tagCollectionFactory; - $this->topicCollectionFactory = $topicCollectionFactory; - $this->categoryCollectionFactory = $categoryCollectionFactory; - parent::__construct($context, $registry, $resource, $resourceCollection, $data); - } - - - /** - * Initialize resource model - * - * @return void - */ - protected function _construct() - { - $this->_init('Mageplaza\Blog\Model\ResourceModel\Post'); - } - - /** - * Get identities - * - * @return array - */ - public function getIdentities() - { - return [self::CACHE_TAG . '_' . $this->getId()]; - } - - /** - * get entity default values - * - * @return array - */ - public function getDefaultValues() - { - $values = []; - $values['in_rss'] = '1'; - $values['allow_comment'] = '1'; - return $values; - } - /** - * @return array|mixed - */ - public function getTagsPosition() - { - if (!$this->getId()) { - return array(); - } - $array = $this->getData('tags_position'); - if (is_null($array)) { - $array = $this->getResource()->getTagsPosition($this); - $this->setData('tags_position', $array); - } - return $array; - } - - /** - * @return \Mageplaza\Blog\Model\ResourceModel\Tag\Collection - */ - public function getSelectedTagsCollection() - { - if (is_null($this->tagCollection)) { - $collection = $this->tagCollectionFactory->create(); - $collection->join( - 'mageplaza_blog_post_tag', - 'main_table.tag_id=mageplaza_blog_post_tag.tag_id AND mageplaza_blog_post_tag.post_id='.$this->getId(), - ['position'] - ); - $this->tagCollection = $collection; - } - return $this->tagCollection; - } - /** - * @return array|mixed - */ - public function getTopicsPosition() - { - if (!$this->getId()) { - return array(); - } - $array = $this->getData('topics_position'); - if (is_null($array)) { - $array = $this->getResource()->getTopicsPosition($this); - $this->setData('topics_position', $array); - } - return $array; - } - - /** - * @return \Mageplaza\Blog\Model\ResourceModel\Topic\Collection - */ - public function getSelectedTopicsCollection() - { - if (is_null($this->topicCollection)) { - $collection = $this->topicCollectionFactory->create(); - $collection->join( - 'mageplaza_blog_post_topic', - 'main_table.topic_id=mageplaza_blog_post_topic.topic_id AND mageplaza_blog_post_topic.post_id='.$this->getId(), - ['position'] - ); - $this->topicCollection = $collection; - } - return $this->topicCollection; - } - /** - * @return array|mixed - */ - public function getCategoriesPosition() - { - if (!$this->getId()) { - return array(); - } - $array = $this->getData('categories_position'); - if (is_null($array)) { - $array = $this->getResource()->getCategoriesPosition($this); - $this->setData('categories_position', $array); - } - return $array; - } - - /** - * @return \Mageplaza\Blog\Model\ResourceModel\Category\Collection - */ - public function getSelectedCategoriesCollection() - { - if (is_null($this->categoryCollection)) { - $collection = $this->categoryCollectionFactory->create(); - $collection->join( - 'mageplaza_blog_post_category', - 'main_table.category_id=mageplaza_blog_post_category.category_id AND mageplaza_blog_post_category.post_id='.$this->getId(), - ['position'] - ); - $this->categoryCollection = $collection; - } - return $this->categoryCollection; - } - /** - * @return array - */ - public function getCategoryIds() - { - if (!$this->hasData('category_ids')) { - $ids = $this->_getResource()->getCategoryIds($this); - $this->setData('category_ids', $ids); - } - return (array) $this->_getData('category_ids'); - } + /** + * Cache tag + * + * @var string + */ + const CACHE_TAG = 'mageplaza_blog_post'; + + /** + * Cache tag + * + * @var string + */ + protected $_cacheTag = 'mageplaza_blog_post'; + + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'mageplaza_blog_post'; + + /** + * Tag Collection + * + * @var \Mageplaza\Blog\Model\ResourceModel\Tag\Collection + */ + protected $tagCollection; + + /** + * Topic Collection + * + * @var \Mageplaza\Blog\Model\ResourceModel\Topic\Collection + */ + protected $topicCollection; + + /** + * Category Collection + * + * @var \Mageplaza\Blog\Model\ResourceModel\Category\Collection + */ + protected $categoryCollection; + + /** + * Tag Collection Factory + * + * @var \Mageplaza\Blog\Model\ResourceModel\Tag\CollectionFactory + */ + protected $tagCollectionFactory; + + /** + * Topic Collection Factory + * + * @var \Mageplaza\Blog\Model\ResourceModel\Topic\CollectionFactory + */ + protected $topicCollectionFactory; + + /** + * Category Collection Factory + * + * @var \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory + */ + protected $categoryCollectionFactory; + + /** + * Post Collection Factory + * @type \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory + */ + protected $postCollectionFactory; + + + /** + * Related Post Collection + * + * @var \Mageplaza\Blog\Model\ResourceModel\Post\Collection + */ + protected $relatedPostCollection; + + /** + * constructor + * + * @param \Mageplaza\Blog\Model\ResourceModel\Tag\CollectionFactory $tagCollectionFactory + * @param \Mageplaza\Blog\Model\ResourceModel\Topic\CollectionFactory $topicCollectionFactory + * @param \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory + * @param \Magento\Framework\Model\Context $context + * @param \Magento\Framework\Registry $registry + * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource + * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection + * @param array $data + */ + public function __construct( + \Mageplaza\Blog\Model\ResourceModel\Tag\CollectionFactory $tagCollectionFactory, + \Mageplaza\Blog\Model\ResourceModel\Topic\CollectionFactory $topicCollectionFactory, + \Mageplaza\Blog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory, + \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory, + \Magento\Framework\Model\Context $context, + \Magento\Framework\Registry $registry, + \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, + \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, + array $data = [] + ) + { + $this->tagCollectionFactory = $tagCollectionFactory; + $this->topicCollectionFactory = $topicCollectionFactory; + $this->categoryCollectionFactory = $categoryCollectionFactory; + $this->postCollectionFactory = $postCollectionFactory; + parent::__construct($context, $registry, $resource, $resourceCollection, $data); + } + + + /** + * Initialize resource model + * + * @return void + */ + protected function _construct() + { + $this->_init('Mageplaza\Blog\Model\ResourceModel\Post'); + } + + /** + * Get identities + * + * @return array + */ + public function getIdentities() + { + return [self::CACHE_TAG . '_' . $this->getId()]; + } + + /** + * get entity default values + * + * @return array + */ + public function getDefaultValues() + { + $values = []; + $values['in_rss'] = '1'; + $values['allow_comment'] = '1'; + + return $values; + } + + /** + * @return array|mixed + */ + public function getTagsPosition() + { + if (!$this->getId()) { + return array(); + } + $array = $this->getData('tags_position'); + if (is_null($array)) { + $array = $this->getResource()->getTagsPosition($this); + $this->setData('tags_position', $array); + } + + return $array; + } + + /** + * @return \Mageplaza\Blog\Model\ResourceModel\Tag\Collection + */ + public function getSelectedTagsCollection() + { + if (is_null($this->tagCollection)) { + $collection = $this->tagCollectionFactory->create(); + $collection->join( + 'mageplaza_blog_post_tag', + 'main_table.tag_id=mageplaza_blog_post_tag.tag_id AND mageplaza_blog_post_tag.post_id=' . $this->getId(), + ['position'] + ); + $this->tagCollection = $collection; + } + + return $this->tagCollection; + } + + /** + * @return array|mixed + */ + public function getTopicsPosition() + { + if (!$this->getId()) { + return array(); + } + $array = $this->getData('topics_position'); + if (is_null($array)) { + $array = $this->getResource()->getTopicsPosition($this); + $this->setData('topics_position', $array); + } + + return $array; + } + + /** + * @return \Mageplaza\Blog\Model\ResourceModel\Topic\Collection + */ + public function getSelectedTopicsCollection() + { + if (is_null($this->topicCollection)) { + $collection = $this->topicCollectionFactory->create(); + $collection->join( + 'mageplaza_blog_post_topic', + 'main_table.topic_id=mageplaza_blog_post_topic.topic_id AND mageplaza_blog_post_topic.post_id=' . $this->getId(), + ['position'] + ); + $this->topicCollection = $collection; + } + + return $this->topicCollection; + } + + /** + * @return array|mixed + */ + public function getCategoriesPosition() + { + if (!$this->getId()) { + return array(); + } + $array = $this->getData('categories_position'); + if (is_null($array)) { + $array = $this->getResource()->getCategoriesPosition($this); + $this->setData('categories_position', $array); + } + + return $array; + } + + /** + * @return \Mageplaza\Blog\Model\ResourceModel\Category\Collection + */ + public function getSelectedCategoriesCollection() + { + if (is_null($this->categoryCollection)) { + $collection = $this->categoryCollectionFactory->create(); + $collection->join( + 'mageplaza_blog_post_category', + 'main_table.category_id=mageplaza_blog_post_category.category_id AND mageplaza_blog_post_category.post_id=' . $this->getId(), + ['position'] + ); + $this->categoryCollection = $collection; + } + + return $this->categoryCollection; + } + + /** + * @return array + */ + public function getCategoryIds() + { + if (!$this->hasData('category_ids')) { + $ids = $this->_getResource()->getCategoryIds($this); + $this->setData('category_ids', $ids); + } + + return (array)$this->_getData('category_ids'); + } + + /** + * @return array + */ + public function getTopicIds() + { + if (!$this->hasData('topic_ids')) { + $ids = $this->_getResource()->getTopicIds($this); + $this->setData('topic_ids', $ids); + } + + return (array)$this->_getData('topic_ids'); + } + + + /** + * get category id string + * @return mixed + */ + public function getTopicSting() + { + if ($this->getTopicIds()) { + return implode(',', $this->getTopicIds()); + } else { + return ''; + } + } + + /** + * get format date + * @return mixed + */ + public function getFormatCreatedAt() + { + $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + $object = $objectManager->get('\Magento\Framework\Stdlib\DateTime'); + $dateFormat = $object->formatDate($this->getCreatedAt(), false); + + return $dateFormat; + } + + + /** + * get related posts + * @return \Mageplaza\Blog\Model\ResourceModel\Post\Collection + */ + public function getRelatedPostsCollection() + { + if ($this->getTopicSting()) { + // if (is_null($this->relatedPostCollection)) { + $collection = $this->postCollectionFactory->create(); + + $collection->join( + 'mageplaza_blog_post_topic', + 'main_table.post_id=mageplaza_blog_post_topic.post_id AND mageplaza_blog_post_topic.post_id != ' . $this->getId() . ' AND mageplaza_blog_post_topic.topic_id IN (' . $this->getTopicSting() . ')', + ['position'] + ); + $this->relatedPostCollection = $collection; +// } + } + return $this->relatedPostCollection; + } + } diff --git a/Model/Post/Source/MetaRobots.php b/Model/Post/Source/MetaRobots.php index e51e04bb..8e011406 100755 --- a/Model/Post/Source/MetaRobots.php +++ b/Model/Post/Source/MetaRobots.php @@ -53,9 +53,6 @@ public function toOptionArray() } - /** - * @return array - */ public function getOptionArray() { return array(self::INDEXFOLLOW => 'INDEX,FOLLOW', self::NOINDEXNOFOLLOW => 'NOINDEX,NOFOLLOW', self::NOINDEXFOLLOW => 'NOINDEX,FOLLOW', self::INDEXNOFOLLOW => 'INDEX,NOFOLLOW'); diff --git a/Model/ResourceModel/Category.php b/Model/ResourceModel/Category.php index c9c9f58e..d9894ff0 100755 --- a/Model/ResourceModel/Category.php +++ b/Model/ResourceModel/Category.php @@ -91,9 +91,9 @@ public function getCategoryNameById($id) */ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object) { - $object->setUpdatedAt($this->date->date()); + $object->setUpdatedAt($this->date->date('Y-m-d')); if ($object->isObjectNew()) { - $object->setCreatedAt($this->date->date()); + $object->setCreatedAt($this->date->date('Y-m-d')); } /** @var \Mageplaza\Blog\Model\Category $object */ parent::_beforeSave($object); diff --git a/Model/ResourceModel/Post.php b/Model/ResourceModel/Post.php index 2719586a..47d9232f 100755 --- a/Model/ResourceModel/Post.php +++ b/Model/ResourceModel/Post.php @@ -385,6 +385,27 @@ public function getCategoryIds(\Mageplaza\Blog\Model\Post $post) return $adapter->fetchCol($select); } + /** + * @param \Mageplaza\Blog\Model\Post $post + * @return array + */ + public function getTopicIds(\Mageplaza\Blog\Model\Post $post) + { + $adapter = $this->getConnection(); + $select = $adapter->select()->from( + $this->postTopicTable, + 'topic_id' + ) + ->where( + 'post_id = ?', + (int)$post->getId() + ); + + return $adapter->fetchCol($select); + } + + + public function generateUrlKey($name, $count) { // replace non letter or digits by - diff --git a/Model/Topic.php b/Model/Topic.php index a840148a..f4c6b7b2 100755 --- a/Model/Topic.php +++ b/Model/Topic.php @@ -2,16 +2,16 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Model; @@ -45,130 +45,126 @@ */ class Topic extends \Magento\Framework\Model\AbstractModel { - /** - * Cache tag - * - * @var string - */ - const CACHE_TAG = 'mageplaza_blog_topic'; + /** + * Cache tag + * + * @var string + */ + const CACHE_TAG = 'mageplaza_blog_topic'; - /** - * Cache tag - * - * @var string - */ - protected $_cacheTag = 'mageplaza_blog_topic'; + /** + * Cache tag + * + * @var string + */ + protected $_cacheTag = 'mageplaza_blog_topic'; - /** - * Event prefix - * - * @var string - */ - protected $_eventPrefix = 'mageplaza_blog_topic'; + /** + * Event prefix + * + * @var string + */ + protected $_eventPrefix = 'mageplaza_blog_topic'; - /** - * Post Collection - * - * @var \Mageplaza\Blog\Model\ResourceModel\Post\Collection - */ - protected $postCollection; + /** + * Post Collection + * + * @var \Mageplaza\Blog\Model\ResourceModel\Post\Collection + */ + protected $postCollection; - /** - * Post Collection Factory - * - * @var \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory - */ - protected $postCollectionFactory; + /** + * Post Collection Factory + * + * @var \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory + */ + protected $postCollectionFactory; - /** - * constructor - * - * @param \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory - * @param \Magento\Framework\Model\Context $context - * @param \Magento\Framework\Registry $registry - * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource - * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection - * @param array $data - */ - public function __construct( - \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory, - \Magento\Framework\Model\Context $context, - \Magento\Framework\Registry $registry, - \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, - \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, - array $data = [] - ) - { - $this->postCollectionFactory = $postCollectionFactory; - parent::__construct($context, $registry, $resource, $resourceCollection, $data); - } + /** + * constructor + * + * @param \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory + * @param \Magento\Framework\Model\Context $context + * @param \Magento\Framework\Registry $registry + * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource + * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection + * @param array $data + */ + public function __construct( + \Mageplaza\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory, + \Magento\Framework\Model\Context $context, + \Magento\Framework\Registry $registry, + \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, + \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, + array $data = [] + ) + { + $this->postCollectionFactory = $postCollectionFactory; + parent::__construct($context, $registry, $resource, $resourceCollection, $data); + } - /** - * Initialize resource model - * - * @return void - */ - protected function _construct() - { - $this->_init('Mageplaza\Blog\Model\ResourceModel\Topic'); - } + /** + * Initialize resource model + * + * @return void + */ + protected function _construct() + { + $this->_init('Mageplaza\Blog\Model\ResourceModel\Topic'); + } - /** - * Get identities - * - * @return array - */ - public function getIdentities() - { - return [self::CACHE_TAG . '_' . $this->getId()]; - } + /** + * 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'; + /** + * get entity default values + * + * @return array + */ + public function getDefaultValues() + { + $values = []; + $values['enabled'] = '1'; + return $values; + } + /** + * @return array|mixed + */ + public function getPostsPosition() + { + if (!$this->getId()) { + return array(); + } + $array = $this->getData('posts_position'); + if (is_null($array)) { + $array = $this->getResource()->getPostsPosition($this); + $this->setData('posts_position', $array); + } + return $array; + } - return $values; - } - - /** - * @return array|mixed - */ - public function getPostsPosition() - { - if (!$this->getId()) { - return array(); - } - $array = $this->getData('posts_position'); - if (is_null($array)) { - $array = $this->getResource()->getPostsPosition($this); - $this->setData('posts_position', $array); - } - - return $array; - } - - /** - * @return \Mageplaza\Blog\Model\ResourceModel\Post\Collection - */ - public function getSelectedPostsCollection() - { - if (is_null($this->postCollection)) { - $collection = $this->postCollectionFactory->create(); - $collection->join( - 'mageplaza_blog_post_topic', - 'main_table.post_id=mageplaza_blog_post_topic.post_id AND mageplaza_blog_post_topic.topic_id=' . $this->getId(), - ['position'] - ); - $this->postCollection = $collection; - } - - return $this->postCollection; - } + /** + * @return \Mageplaza\Blog\Model\ResourceModel\Post\Collection + */ + public function getSelectedPostsCollection() + { + if (is_null($this->postCollection)) { + $collection = $this->postCollectionFactory->create(); + $collection->join( + 'mageplaza_blog_post_topic', + 'main_table.post_id=mageplaza_blog_post_topic.post_id AND mageplaza_blog_post_topic.topic_id='.$this->getId(), + ['position'] + ); + $this->postCollection = $collection; + } + return $this->postCollection; + } } diff --git a/Model/Topic/Source/MetaRobots.php b/Model/Topic/Source/MetaRobots.php index f348c1b2..8b4b8af6 100755 --- a/Model/Topic/Source/MetaRobots.php +++ b/Model/Topic/Source/MetaRobots.php @@ -2,62 +2,57 @@ /** * Mageplaza_Blog extension * NOTICE OF LICENSE - * + * * This source file is subject to the MIT License * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/mit-license.php - * - * @category Mageplaza - * @package Mageplaza_Blog - * @copyright Copyright (c) 2016 - * @license http://opensource.org/licenses/mit-license.php MIT License + * + * @category Mageplaza + * @package Mageplaza_Blog + * @copyright Copyright (c) 2016 + * @license http://opensource.org/licenses/mit-license.php MIT License */ namespace Mageplaza\Blog\Model\Topic\Source; class MetaRobots implements \Magento\Framework\Option\ArrayInterface { - const INDEXFOLLOW = 1; - const NOINDEXNOFOLLOW = 2; - const NOINDEXFOLLOW = 3; - const INDEXNOFOLLOW = 4; + const INDEXFOLLOW = 1; + const NOINDEXNOFOLLOW = 2; + const NOINDEXFOLLOW = 3; + const INDEXNOFOLLOW = 4; - /** - * to option array - * - * @return array - */ - public function toOptionArray() - { - $options = [ - [ - 'value' => self::INDEXFOLLOW, - 'label' => __('INDEX,FOLLOW') - ], - [ - 'value' => self::NOINDEXNOFOLLOW, - 'label' => __('NOINDEX,NOFOLLOW') - ], - [ - 'value' => self::NOINDEXFOLLOW, - 'label' => __('NOINDEX,FOLLOW') - ], - [ - 'value' => self::INDEXNOFOLLOW, - 'label' => __('INDEX,NOFOLLOW') - ], - ]; + /** + * to option array + * + * @return array + */ + public function toOptionArray() + { + $options = [ + [ + 'value' => self::INDEXFOLLOW, + 'label' => __('INDEX,FOLLOW') + ], + [ + 'value' => self::NOINDEXNOFOLLOW, + 'label' => __('NOINDEX,NOFOLLOW') + ], + [ + 'value' => self::NOINDEXFOLLOW, + 'label' => __('NOINDEX,FOLLOW') + ], + [ + 'value' => self::INDEXNOFOLLOW, + 'label' => __('INDEX,NOFOLLOW') + ], + ]; + return $options; - return $options; - - } - - /** - * @return array - */ - public function getOptionArray() - { - return array(self::INDEXFOLLOW => 'INDEX,FOLLOW', self::NOINDEXNOFOLLOW => 'NOINDEX,NOFOLLOW', self::NOINDEXFOLLOW => 'NOINDEX,FOLLOW', self::INDEXNOFOLLOW => 'INDEX,NOFOLLOW'); - } + } + public function getOptionArray() + { + return array(self::INDEXFOLLOW => 'INDEX,FOLLOW', self::NOINDEXNOFOLLOW => 'NOINDEX,NOFOLLOW', self::NOINDEXFOLLOW => 'NOINDEX,FOLLOW', self::INDEXNOFOLLOW => 'INDEX,NOFOLLOW'); + } } diff --git a/README.md b/README.md index f35ae49d..723889dd 100755 --- a/README.md +++ b/README.md @@ -71,3 +71,8 @@ composer config repositories.mageplaza-magento-2-blog-extension git git@github.c sudo composer require mageplaza/magento-2-blog-extension:dev-master php bin/magento setup:upgrade ~~~ + + +## License + +https://www.mageplaza.com/LICENSE.txt diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index c2175e57..33e3c383 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -80,6 +80,29 @@getShortDescription(); ?>
-getShortDescription(); ?>
+getShortDescription(); ?>
-getShortDescription(); ?>
+
-
-
-
-+
+
+
+ +