diff --git a/Block/Adminhtml/Banner.php b/Block/Adminhtml/Banner.php index a171f63..8daffa9 100644 --- a/Block/Adminhtml/Banner.php +++ b/Block/Adminhtml/Banner.php @@ -36,9 +36,9 @@ class Banner extends Container */ protected function _construct() { - $this->_controller = 'adminhtml_banner'; - $this->_blockGroup = 'Mageplaza_BannerSlider'; - $this->_headerText = __('Banners'); + $this->_controller = 'adminhtml_banner'; + $this->_blockGroup = 'Mageplaza_BannerSlider'; + $this->_headerText = __('Banners'); $this->_addButtonLabel = __('Create New Banner'); parent::_construct(); diff --git a/Block/Adminhtml/Banner/Edit.php b/Block/Adminhtml/Banner/Edit.php index 89b9166..2d98650 100644 --- a/Block/Adminhtml/Banner/Edit.php +++ b/Block/Adminhtml/Banner/Edit.php @@ -24,6 +24,7 @@ use Magento\Backend\Block\Widget\Context; use Magento\Backend\Block\Widget\Form\Container; use Magento\Framework\Registry; +use Mageplaza\BannerSlider\Model\Banner; /** * Class Edit @@ -34,23 +35,22 @@ class Edit extends Container /** * Core registry * - * @var \Magento\Framework\Registry + * @var Registry */ protected $coreRegistry; /** * constructor * - * @param \Magento\Framework\Registry $coreRegistry - * @param \Magento\Backend\Block\Widget\Context $context + * @param Registry $coreRegistry + * @param Context $context * @param array $data */ public function __construct( Registry $coreRegistry, Context $context, array $data = [] - ) - { + ) { parent::__construct($context, $data); $this->coreRegistry = $coreRegistry; @@ -63,7 +63,7 @@ public function __construct( */ protected function _construct() { - $this->_objectId = 'banner_id'; + $this->_objectId = 'banner_id'; $this->_blockGroup = 'Mageplaza_BannerSlider'; $this->_controller = 'adminhtml_banner'; parent::_construct(); @@ -94,7 +94,7 @@ protected function _construct() */ public function getHeaderText() { - /** @var \Mageplaza\BannerSlider\Model\Banner $banner */ + /** @var Banner $banner */ $banner = $this->getBanner(); if ($banner->getId()) { return __("Edit Banner '%1'", $this->escapeHtml($banner->getName())); diff --git a/Block/Adminhtml/Banner/Edit/Form.php b/Block/Adminhtml/Banner/Edit/Form.php index 9438230..b36bf13 100644 --- a/Block/Adminhtml/Banner/Edit/Form.php +++ b/Block/Adminhtml/Banner/Edit/Form.php @@ -24,6 +24,7 @@ use Magento\Backend\Block\Template\Context; use Magento\Backend\Block\Widget\Form\Generic; use Magento\Framework\Data\FormFactory; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Registry; use Mageplaza\BannerSlider\Model\Config\Source\Template; @@ -58,8 +59,7 @@ public function __construct( FormFactory $formFactory, Template $template, array $data = [] - ) - { + ) { $this->template = $template; parent::__construct($context, $registry, $formFactory, $data); @@ -67,7 +67,7 @@ public function __construct( /** * @return Generic - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ protected function _prepareForm() { diff --git a/Block/Adminhtml/Banner/Edit/Tab/Banner.php b/Block/Adminhtml/Banner/Edit/Tab/Banner.php index 121d220..eecddb9 100644 --- a/Block/Adminhtml/Banner/Edit/Tab/Banner.php +++ b/Block/Adminhtml/Banner/Edit/Tab/Banner.php @@ -29,6 +29,7 @@ use Magento\Config\Model\Config\Structure\Element\Dependency\FieldFactory; use Magento\Framework\Convert\DataObject; use Magento\Framework\Data\FormFactory; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Registry; use Mageplaza\BannerSlider\Block\Adminhtml\Banner\Edit\Tab\Render\Image as BannerImage; use Mageplaza\BannerSlider\Helper\Data; @@ -45,7 +46,7 @@ class Banner extends Generic implements TabInterface /** * Type options * - * @var \Mageplaza\BannerSlider\Model\Config\Source\Type + * @var Type */ protected $typeOptions; @@ -59,27 +60,27 @@ class Banner extends Generic implements TabInterface /** * Status options * - * @var \Magento\Config\Model\Config\Source\Enabledisable + * @var Enabledisable */ protected $statusOptions; /** - * @var \Mageplaza\BannerSlider\Helper\Image + * @var HelperImage */ protected $imageHelper; /** - * @var \Magento\Config\Model\Config\Structure\Element\Dependency\FieldFactory + * @var FieldFactory */ protected $_fieldFactory; /** - * @var \Magento\Framework\Convert\DataObject + * @var DataObject */ protected $_objectConverter; /** - * @var \Magento\Cms\Model\Wysiwyg\Config + * @var WysiwygConfig */ protected $_wysiwygConfig; @@ -110,28 +111,27 @@ public function __construct( DataObject $objectConverter, WysiwygConfig $wysiwygConfig, array $data = [] - ) - { - $this->typeOptions = $typeOptions; - $this->template = $template; - $this->statusOptions = $statusOptions; - $this->imageHelper = $imageHelper; - $this->_fieldFactory = $fieldFactory; + ) { + $this->typeOptions = $typeOptions; + $this->template = $template; + $this->statusOptions = $statusOptions; + $this->imageHelper = $imageHelper; + $this->_fieldFactory = $fieldFactory; $this->_objectConverter = $objectConverter; - $this->_wysiwygConfig = $wysiwygConfig; + $this->_wysiwygConfig = $wysiwygConfig; parent::__construct($context, $registry, $formFactory, $data); } /** * @return Generic - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ protected function _prepareForm() { /** @var \Mageplaza\BannerSlider\Model\Banner $banner */ $banner = $this->_coreRegistry->registry('mpbannerslider_banner'); - $form = $this->_formFactory->create(); + $form = $this->_formFactory->create(); $form->setHtmlIdPrefix('banner_'); $form->setFieldNameSuffix('banner'); $fieldset = $form->addFieldset('base_fieldset', [ @@ -212,7 +212,7 @@ protected function _prepareForm() 'label' => __('Load Template'), ] ]); - $insertbutton = $fieldset->addField('load_template', 'note', [ + $insertbutton = $fieldset->addField('load_template', 'note', [ 'text' => $insertVariableButton->toHtml(), 'label' => '' ]); diff --git a/Block/Adminhtml/Banner/Edit/Tab/Render/GridImage.php b/Block/Adminhtml/Banner/Edit/Tab/Render/GridImage.php index fe5fc29..082504b 100644 --- a/Block/Adminhtml/Banner/Edit/Tab/Render/GridImage.php +++ b/Block/Adminhtml/Banner/Edit/Tab/Render/GridImage.php @@ -48,8 +48,7 @@ public function __construct( Context $context, ImageModel $imageModel, array $data = [] - ) - { + ) { $this->imageModel = $imageModel; parent::__construct($context, $data); @@ -72,4 +71,4 @@ public function render(DataObject $row) return ''; } -} \ No newline at end of file +} diff --git a/Block/Adminhtml/Banner/Edit/Tab/Render/Image.php b/Block/Adminhtml/Banner/Edit/Tab/Render/Image.php index f1a903c..05a4703 100644 --- a/Block/Adminhtml/Banner/Edit/Tab/Render/Image.php +++ b/Block/Adminhtml/Banner/Edit/Tab/Render/Image.php @@ -56,8 +56,7 @@ public function __construct( Escaper $escaper, UrlInterface $urlBuilder, array $data - ) - { + ) { $this->imageModel = $imageModel; parent::__construct($factoryElement, $factoryCollection, $escaper, $urlBuilder, $data); diff --git a/Block/Adminhtml/Banner/Edit/Tab/Render/Slider.php b/Block/Adminhtml/Banner/Edit/Tab/Render/Slider.php index 24d16f2..bb9e1d8 100644 --- a/Block/Adminhtml/Banner/Edit/Tab/Render/Slider.php +++ b/Block/Adminhtml/Banner/Edit/Tab/Render/Slider.php @@ -27,6 +27,7 @@ use Magento\Framework\Data\Form\Element\Multiselect; use Magento\Framework\Escaper; use Mageplaza\BannerSlider\Helper\Data; +use Mageplaza\BannerSlider\Model\ResourceModel\Slider\Collection; use Mageplaza\BannerSlider\Model\ResourceModel\Slider\CollectionFactory as SliderCollectionFactory; /** @@ -38,7 +39,7 @@ class Slider extends Multiselect /** * Authorization * - * @var \Magento\Framework\AuthorizationInterface + * @var AuthorizationInterface */ public $authorization; @@ -64,10 +65,9 @@ public function __construct( SliderCollectionFactory $collectionFactory, AuthorizationInterface $authorization, array $data = [] - ) - { + ) { $this->collectionFactory = $collectionFactory; - $this->authorization = $authorization; + $this->authorization = $authorization; parent::__construct($factoryElement, $factoryCollection, $escaper, $data); } @@ -95,13 +95,13 @@ public function getElementHtml() */ public function getSliderCollection() { - /* @var $collection \Mageplaza\BannerSlider\Model\ResourceModel\Slider\Collection */ + /* @var $collection Collection */ $collection = $this->collectionFactory->create(); $sliderById = []; foreach ($collection as $slider) { - $sliderById[$slider->getId()]['value'] = $slider->getId(); + $sliderById[$slider->getId()]['value'] = $slider->getId(); $sliderById[$slider->getId()]['is_active'] = 1; - $sliderById[$slider->getId()]['label'] = $slider->getName(); + $sliderById[$slider->getId()]['label'] = $slider->getName(); } return $sliderById; @@ -124,7 +124,7 @@ public function getValues() return []; } - /* @var $collection \Mageplaza\BannerSlider\Model\ResourceModel\Slider\Collection */ + /* @var $collection Collection */ $collection = $this->collectionFactory->create()->addIdFilter($values); $options = []; @@ -176,4 +176,4 @@ public function getAfterElementHtml() return $html; } -} \ No newline at end of file +} diff --git a/Block/Adminhtml/Banner/Edit/Tab/Render/Status.php b/Block/Adminhtml/Banner/Edit/Tab/Render/Status.php index 4d06b54..e0f62d1 100644 --- a/Block/Adminhtml/Banner/Edit/Tab/Render/Status.php +++ b/Block/Adminhtml/Banner/Edit/Tab/Render/Status.php @@ -43,4 +43,4 @@ public function render(DataObject $row) return $status === '1' ? 'Enable' : 'Disable'; } -} \ No newline at end of file +} diff --git a/Block/Adminhtml/Banner/Edit/Tab/Render/Type.php b/Block/Adminhtml/Banner/Edit/Tab/Render/Type.php index f1ccbdf..102d4c7 100644 --- a/Block/Adminhtml/Banner/Edit/Tab/Render/Type.php +++ b/Block/Adminhtml/Banner/Edit/Tab/Render/Type.php @@ -51,4 +51,4 @@ public function render(DataObject $row) return $type; } -} \ No newline at end of file +} diff --git a/Block/Adminhtml/Banner/Edit/Tabs.php b/Block/Adminhtml/Banner/Edit/Tabs.php index f375fc9..65d81a0 100644 --- a/Block/Adminhtml/Banner/Edit/Tabs.php +++ b/Block/Adminhtml/Banner/Edit/Tabs.php @@ -22,7 +22,7 @@ namespace Mageplaza\BannerSlider\Block\Adminhtml\Banner\Edit; /** - * @method Tabs setTitle(\string $title) + * @method Tabs setTitle(string $title) */ class Tabs extends \Magento\Backend\Block\Widget\Tabs { diff --git a/Block/Adminhtml/Config/Field/Responsive.php b/Block/Adminhtml/Config/Field/Responsive.php index e79f78a..ef309f0 100644 --- a/Block/Adminhtml/Config/Field/Responsive.php +++ b/Block/Adminhtml/Config/Field/Responsive.php @@ -37,7 +37,7 @@ protected function _prepareToRender() $this->addColumn('size', ['label' => __('Screen size from'), 'renderer' => false, 'class' => 'required-entry validate-digits']); $this->addColumn('items', ['label' => __('Number of items'), 'renderer' => false, 'class' => 'required-entry validate-digits']); - $this->_addAfter = false; + $this->_addAfter = false; $this->_addButtonLabel = __('Add'); } -} \ No newline at end of file +} diff --git a/Block/Adminhtml/Slider.php b/Block/Adminhtml/Slider.php index f4093e6..8a01499 100644 --- a/Block/Adminhtml/Slider.php +++ b/Block/Adminhtml/Slider.php @@ -21,11 +21,13 @@ namespace Mageplaza\BannerSlider\Block\Adminhtml; +use Magento\Backend\Block\Widget\Grid\Container; + /** * Class Slider * @package Mageplaza\BannerSlider\Block\Adminhtml */ -class Slider extends \Magento\Backend\Block\Widget\Grid\Container +class Slider extends Container { /** * constructor @@ -34,9 +36,9 @@ class Slider extends \Magento\Backend\Block\Widget\Grid\Container */ protected function _construct() { - $this->_controller = 'adminhtml_slider'; - $this->_blockGroup = 'Mageplaza_BannerSlider'; - $this->_headerText = __('Sliders'); + $this->_controller = 'adminhtml_slider'; + $this->_blockGroup = 'Mageplaza_BannerSlider'; + $this->_headerText = __('Sliders'); $this->_addButtonLabel = __('Create New Slider'); parent::_construct(); diff --git a/Block/Adminhtml/Slider/Edit.php b/Block/Adminhtml/Slider/Edit.php index 9909665..197126a 100644 --- a/Block/Adminhtml/Slider/Edit.php +++ b/Block/Adminhtml/Slider/Edit.php @@ -24,6 +24,7 @@ use Magento\Backend\Block\Widget\Context; use Magento\Backend\Block\Widget\Form\Container; use Magento\Framework\Registry; +use Mageplaza\BannerSlider\Model\Slider; /** * Class Edit @@ -49,9 +50,9 @@ public function __construct( Registry $coreRegistry, Context $context, array $data = [] - ) - { + ) { $this->coreRegistry = $coreRegistry; + parent::__construct($context, $data); } @@ -62,7 +63,7 @@ public function __construct( */ protected function _construct() { - $this->_objectId = 'slider_id'; + $this->_objectId = 'slider_id'; $this->_blockGroup = 'Mageplaza_BannerSlider'; $this->_controller = 'adminhtml_slider'; parent::_construct(); @@ -93,7 +94,7 @@ protected function _construct() */ public function getHeaderText() { - /** @var \Mageplaza\BannerSlider\Model\Slider $slider */ + /** @var Slider $slider */ $slider = $this->getSlider(); if ($slider->getId()) { return __("Edit Slider '%1'", $this->escapeHtml($slider->getName())); @@ -107,8 +108,6 @@ public function getHeaderText() */ public function getSlider() { - $slider = $this->coreRegistry->registry('mpbannerslider_slider'); - - return $slider; + return $this->coreRegistry->registry('mpbannerslider_slider'); } } diff --git a/Block/Adminhtml/Slider/Edit/Form.php b/Block/Adminhtml/Slider/Edit/Form.php index 295f48c..81baba0 100644 --- a/Block/Adminhtml/Slider/Edit/Form.php +++ b/Block/Adminhtml/Slider/Edit/Form.php @@ -22,6 +22,7 @@ namespace Mageplaza\BannerSlider\Block\Adminhtml\Slider\Edit; use Magento\Backend\Block\Widget\Form\Generic; +use Magento\Framework\Exception\LocalizedException; /** * Class Form @@ -31,7 +32,7 @@ class Form extends Generic { /** * @return Generic - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ protected function _prepareForm() { diff --git a/Block/Adminhtml/Slider/Edit/Tab/Banner.php b/Block/Adminhtml/Slider/Edit/Tab/Banner.php index 41f1816..d99bbb1 100644 --- a/Block/Adminhtml/Slider/Edit/Tab/Banner.php +++ b/Block/Adminhtml/Slider/Edit/Tab/Banner.php @@ -21,13 +21,20 @@ namespace Mageplaza\BannerSlider\Block\Adminhtml\Slider\Edit\Tab; +use Exception; use Magento\Backend\Block\Template\Context; +use Magento\Backend\Block\Widget\Grid\Column; use Magento\Backend\Block\Widget\Grid\Extended; use Magento\Backend\Block\Widget\Tab\TabInterface; use Magento\Backend\Helper\Data as backendHelper; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Registry; +use Mageplaza\BannerSlider\Block\Adminhtml\Banner\Edit\Tab\Render\GridImage; +use Mageplaza\BannerSlider\Block\Adminhtml\Banner\Edit\Tab\Render\Status; +use Mageplaza\BannerSlider\Block\Adminhtml\Banner\Edit\Tab\Render\Type; use Mageplaza\BannerSlider\Model\BannerFactory; -use Mageplaza\BannerSlider\Model\ResourceModel\Banner\CollectionFactory as bannerCollectionFactory; +use Mageplaza\BannerSlider\Model\ResourceModel\Banner\Collection; +use Mageplaza\BannerSlider\Model\ResourceModel\Banner\CollectionFactory as BannerCollectionFactory; /** * Class Banner @@ -38,28 +45,28 @@ class Banner extends Extended implements TabInterface /** * Banner collection factory * - * @var \Mageplaza\BannerSlider\Model\ResourceModel\Banner\CollectionFactory + * @var BannerCollectionFactory */ protected $bannerCollectionFactory; /** * Registry * - * @var \Magento\Framework\Registry + * @var Registry */ protected $coreRegistry; /** * Banner factory * - * @var \Mageplaza\BannerSlider\Model\BannerFactory + * @var BannerFactory */ protected $bannerFactory; /** * Banner constructor. * - * @param bannerCollectionFactory $bannerCollectionFactory + * @param BannerCollectionFactory $bannerCollectionFactory * @param Registry $coreRegistry * @param BannerFactory $bannerFactory * @param Context $context @@ -67,17 +74,16 @@ class Banner extends Extended implements TabInterface * @param array $data */ public function __construct( - bannerCollectionFactory $bannerCollectionFactory, + BannerCollectionFactory $bannerCollectionFactory, Registry $coreRegistry, BannerFactory $bannerFactory, Context $context, backendHelper $backendHelper, array $data = [] - ) - { + ) { $this->bannerCollectionFactory = $bannerCollectionFactory; - $this->coreRegistry = $coreRegistry; - $this->bannerFactory = $bannerFactory; + $this->coreRegistry = $coreRegistry; + $this->bannerFactory = $bannerFactory; parent::__construct($context, $backendHelper, $data); } @@ -103,7 +109,7 @@ public function _construct() */ protected function _prepareCollection() { - /** @var \Mageplaza\BannerSlider\Model\ResourceModel\Banner\Collection $collection */ + /** @var Collection $collection */ $collection = $this->bannerCollectionFactory->create(); if ($this->getSlider()->getId()) { $constraint = 'related.slider_id=' . $this->getSlider()->getId(); @@ -130,7 +136,7 @@ protected function _prepareMassaction() /** * @return $this|Extended - * @throws \Exception + * @throws Exception */ protected function _prepareColumns() { @@ -157,7 +163,7 @@ protected function _prepareColumns() 'header_css_class' => 'col-image', 'column_css_class' => 'col-image', 'sortable' => false, - 'renderer' => "Mageplaza\BannerSlider\Block\Adminhtml\Banner\Edit\Tab\Render\GridImage" + 'renderer' => GridImage::class ]); $this->addColumn('name', [ @@ -172,7 +178,7 @@ protected function _prepareColumns() 'index' => 'type', 'header_css_class' => 'col-type', 'column_css_class' => 'col-type', - 'renderer' => 'Mageplaza\BannerSlider\Block\Adminhtml\Banner\Edit\Tab\Render\Type' + 'renderer' => Type::class ]); $this->addColumn('status', [ @@ -180,7 +186,7 @@ protected function _prepareColumns() 'index' => 'status', 'header_css_class' => 'col-status', 'column_css_class' => 'col-status', - 'renderer' => 'Mageplaza\BannerSlider\Block\Adminhtml\Banner\Edit\Tab\Render\Status' + 'renderer' => Status::class ]); $this->addColumn('position', [ @@ -230,7 +236,7 @@ public function getSelectedBanners() } /** - * @param \Mageplaza\BannerSlider\Model\Banner|\Magento\Framework\Object $item + * @param \Mageplaza\BannerSlider\Model\Banner|Object $item * * @return string */ @@ -263,10 +269,10 @@ public function getSlider() } /** - * @param \Magento\Backend\Block\Widget\Grid\Column $column + * @param Column $column * * @return $this|Extended - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ protected function _addColumnFilterToCollection($column) { diff --git a/Block/Adminhtml/Slider/Edit/Tab/Design.php b/Block/Adminhtml/Slider/Edit/Tab/Design.php index dc64fc0..78db01b 100644 --- a/Block/Adminhtml/Slider/Edit/Tab/Design.php +++ b/Block/Adminhtml/Slider/Edit/Tab/Design.php @@ -22,11 +22,14 @@ namespace Mageplaza\BannerSlider\Block\Adminhtml\Slider\Edit\Tab; use Magento\Backend\Block\Template\Context; +use Magento\Backend\Block\Widget\Form\Element\Dependence; use Magento\Backend\Block\Widget\Form\Generic; use Magento\Backend\Block\Widget\Tab\TabInterface; use Magento\Config\Model\Config\Source\Yesno; use Magento\Framework\Data\FormFactory; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Registry; +use Mageplaza\BannerSlider\Block\Adminhtml\Slider\Edit\Tab\Renderer\Responsive; use Mageplaza\BannerSlider\Model\Config\Source\Effect; /** @@ -62,17 +65,16 @@ public function __construct( Effect $effect, Yesno $yesno, array $data = [] - ) - { + ) { $this->_effect = $effect; - $this->_yesno = $yesno; + $this->_yesno = $yesno; parent::__construct($context, $registry, $formFactory, $data); } /** * @return Generic - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ protected function _prepareForm() { @@ -92,7 +94,7 @@ protected function _prepareForm() 'title' => __('Animation Effect'), 'values' => $this->_effect->toOptionArray() ]); - $design = $fieldset->addField('design', 'select', [ + $design = $fieldset->addField('design', 'select', [ 'name' => 'design', 'label' => __('Manually Design'), 'title' => __('Manually Design'), @@ -101,66 +103,66 @@ protected function _prepareForm() '1' => __('Yes') ] ]); - $responsive = $fieldset->addField('is_responsive', 'select', [ + $responsive = $fieldset->addField('is_responsive', 'select', [ 'name' => 'is_responsive', 'label' => __('Is Responsive'), 'title' => __('Is Responsive'), 'values' => $this->_yesno->toOptionArray() ]); - $responsiveItem = $fieldset->addField('responsive_items', 'Mageplaza\BannerSlider\Block\Adminhtml\Slider\Edit\Tab\Renderer\Responsive', [ + $responsiveItem = $fieldset->addField('responsive_items', Responsive::class, [ 'name' => 'responsive_items', 'label' => __('Max Items Slider'), 'title' => __('Max Items Slider'), ]); - $autoWidth = $fieldset->addField('autoWidth', 'select', [ + $autoWidth = $fieldset->addField('autoWidth', 'select', [ 'name' => 'autoWidth', 'label' => __('Auto Width'), 'title' => __('Auto Width'), 'values' => $this->_yesno->toOptionArray() ]); - $autoHeight = $fieldset->addField('autoHeight', 'select', [ + $autoHeight = $fieldset->addField('autoHeight', 'select', [ 'name' => 'autoHeight', 'label' => __('Auto Height'), 'title' => __('Auto Height'), 'values' => $this->_yesno->toOptionArray() ]); - $loop = $fieldset->addField('loop', 'select', [ + $loop = $fieldset->addField('loop', 'select', [ 'name' => 'loop', 'label' => __('Infinity Loop'), 'title' => __('Infinity Loop'), 'values' => $this->_yesno->toOptionArray() ]); - $nav = $fieldset->addField('nav', 'select', [ + $nav = $fieldset->addField('nav', 'select', [ 'name' => 'nav', 'label' => __('Show Next/Prev Buttons'), 'title' => __('Show Next/Prev Buttons'), 'values' => $this->_yesno->toOptionArray() ]); - $dots = $fieldset->addField('dots', 'select', [ + $dots = $fieldset->addField('dots', 'select', [ 'name' => 'dots', 'label' => __('Show Dots Navigation'), 'title' => __('Show Dots Navigation'), 'values' => $this->_yesno->toOptionArray() ]); - $lazyload = $fieldset->addField('lazyLoad', 'select', [ + $lazyload = $fieldset->addField('lazyLoad', 'select', [ 'name' => 'lazyLoad', 'label' => __('Lazy Loading Images'), 'title' => __('Lazy Loading Images'), 'values' => $this->_yesno->toOptionArray() ]); - $autoplay = $fieldset->addField('autoplay', 'select', [ + $autoplay = $fieldset->addField('autoplay', 'select', [ 'name' => 'autoplay', 'label' => __('Autoplay'), 'title' => __('Autoplay'), 'values' => $this->_yesno->toOptionArray() ]); - $timeout = $fieldset->addField('autoplayTimeout', 'text', [ + $timeout = $fieldset->addField('autoplayTimeout', 'text', [ 'name' => 'autoplayTimeout', 'label' => __('Autoplay Time-Out'), 'title' => __('Autoplay Time-Out') ]); - $dependencies = $this->getLayout()->createBlock('Magento\Backend\Block\Widget\Form\Element\Dependence') + $dependencies = $this->getLayout()->createBlock(Dependence::class) ->addFieldMap($design->getHtmlId(), $design->getName()) ->addFieldMap($responsive->getHtmlId(), $responsive->getName()) ->addFieldMap($responsiveItem->getHtmlId(), $responsiveItem->getName()) diff --git a/Block/Adminhtml/Slider/Edit/Tab/Renderer/Responsive.php b/Block/Adminhtml/Slider/Edit/Tab/Renderer/Responsive.php index 3f303db..655a084 100644 --- a/Block/Adminhtml/Slider/Edit/Tab/Renderer/Responsive.php +++ b/Block/Adminhtml/Slider/Edit/Tab/Renderer/Responsive.php @@ -53,8 +53,7 @@ public function __construct( Escaper $escaper, LayoutInterface $layout, array $data = [] - ) - { + ) { $this->layout = $layout; parent::__construct($factoryElement, $factoryCollection, $escaper, $data); @@ -73,4 +72,4 @@ public function getElementHtml() return $html; } -} \ No newline at end of file +} diff --git a/Block/Adminhtml/Slider/Edit/Tab/Renderer/Snippet.php b/Block/Adminhtml/Slider/Edit/Tab/Renderer/Snippet.php index 27187db..5baf2a8 100644 --- a/Block/Adminhtml/Slider/Edit/Tab/Renderer/Snippet.php +++ b/Block/Adminhtml/Slider/Edit/Tab/Renderer/Snippet.php @@ -35,18 +35,18 @@ class Snippet extends AbstractElement public function getElementHtml() { $sliderId = '1'; - $html = ''; + $html = ''; return $html; } -} \ No newline at end of file +} diff --git a/Block/Adminhtml/Slider/Edit/Tab/Slider.php b/Block/Adminhtml/Slider/Edit/Tab/Slider.php index 440e26d..ecdf6ea 100644 --- a/Block/Adminhtml/Slider/Edit/Tab/Slider.php +++ b/Block/Adminhtml/Slider/Edit/Tab/Slider.php @@ -21,6 +21,7 @@ namespace Mageplaza\BannerSlider\Block\Adminhtml\Slider\Edit\Tab; +use Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element; use Magento\Backend\Block\Template\Context; use Magento\Backend\Block\Widget\Form\Generic; use Magento\Backend\Block\Widget\Tab\TabInterface; @@ -28,10 +29,13 @@ use Magento\Customer\Api\GroupRepositoryInterface; use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\Convert\DataObject; +use Magento\Framework\Data\Form\Element\Renderer\RendererInterface; use Magento\Framework\Data\FormFactory; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Registry; use Magento\Framework\Stdlib\DateTime; use Magento\Store\Model\System\Store; +use Mageplaza\BannerSlider\Block\Adminhtml\Slider\Edit\Tab\Renderer\Snippet; use Mageplaza\BannerSlider\Model\Config\Source\Location; /** @@ -43,32 +47,32 @@ class Slider extends Generic implements TabInterface /** * Status options * - * @var \Magento\Config\Model\Config\Source\Enabledisable + * @var Enabledisable */ protected $statusOptions; /** - * @var \Mageplaza\BannerSlider\Model\Config\Source\Location + * @var Location */ protected $_location; /** - * @var \Magento\Store\Model\System\Store + * @var Store */ protected $_systemStore; /** - * @var \Magento\Customer\Api\GroupRepositoryInterface + * @var GroupRepositoryInterface */ protected $_groupRepository; /** - * @var \Magento\Framework\Api\SearchCriteriaBuilder + * @var SearchCriteriaBuilder */ protected $_searchCriteriaBuilder; /** - * @var \Magento\Framework\Convert\DataObject + * @var DataObject */ protected $_objectConverter; @@ -97,27 +101,26 @@ public function __construct( DataObject $objectConverter, Store $systemStore, array $data = [] - ) - { - $this->statusOptions = $statusOptions; - $this->_location = $location; - $this->_groupRepository = $groupRepository; + ) { + $this->statusOptions = $statusOptions; + $this->_location = $location; + $this->_groupRepository = $groupRepository; $this->_searchCriteriaBuilder = $searchCriteriaBuilder; - $this->_objectConverter = $objectConverter; - $this->_systemStore = $systemStore; + $this->_objectConverter = $objectConverter; + $this->_systemStore = $systemStore; parent::__construct($context, $registry, $formFactory, $data); } /** * @return Generic - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ protected function _prepareForm() { /** @var \Mageplaza\BannerSlider\Model\Slider $slider */ $slider = $this->_coreRegistry->registry('mpbannerslider_slider'); - $form = $this->_formFactory->create(); + $form = $this->_formFactory->create(); $form->setHtmlIdPrefix('slider_'); $form->setFieldNameSuffix('slider'); $fieldset = $form->addFieldset('base_fieldset', [ @@ -143,8 +146,8 @@ protected function _prepareForm() ]); if (!$this->_storeManager->isSingleStoreMode()) { - /** @var \Magento\Framework\Data\Form\Element\Renderer\RendererInterface $rendererBlock */ - $rendererBlock = $this->getLayout()->createBlock('Magento\Backend\Block\Store\Switcher\Form\Renderer\Fieldset\Element'); + /** @var RendererInterface $rendererBlock */ + $rendererBlock = $this->getLayout()->createBlock(Element::class); $fieldset->addField('store_ids', 'multiselect', [ 'name' => 'store_ids', 'label' => __('Store Views'), @@ -208,7 +211,7 @@ protected function _prepareForm() 'legend' => __('Another way to add sliders to your page'), 'class' => 'fieldset-wide' ]); - $subfieldset->addField('snippet', 'Mageplaza\BannerSlider\Block\Adminhtml\Slider\Edit\Tab\Renderer\Snippet', [ + $subfieldset->addField('snippet', Snippet::class, [ 'name' => 'snippet', 'label' => __('How to use'), 'title' => __('How to use'), diff --git a/Block/Adminhtml/Slider/Edit/Tabs.php b/Block/Adminhtml/Slider/Edit/Tabs.php index 93c8a69..e16da71 100644 --- a/Block/Adminhtml/Slider/Edit/Tabs.php +++ b/Block/Adminhtml/Slider/Edit/Tabs.php @@ -22,7 +22,7 @@ namespace Mageplaza\BannerSlider\Block\Adminhtml\Slider\Edit; /** - * @method Tabs setTitle(\string $title) + * @method Tabs setTitle(string $title) */ class Tabs extends \Magento\Backend\Block\Widget\Tabs { diff --git a/Block/Slider.php b/Block/Slider.php index 14f3b91..fee1c1b 100644 --- a/Block/Slider.php +++ b/Block/Slider.php @@ -21,10 +21,13 @@ namespace Mageplaza\BannerSlider\Block; +use Exception; use Magento\Cms\Model\Template\FilterProvider; use Magento\Customer\Api\CustomerRepositoryInterface; +use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; use Magento\Framework\Stdlib\DateTime\DateTime; use Magento\Framework\View\Element\Template; +use Magento\Store\Model\StoreManagerInterface; use Mageplaza\BannerSlider\Helper\Data as bannerHelper; /** @@ -34,22 +37,22 @@ class Slider extends Template { /** - * @type \Mageplaza\BannerSlider\Helper\Data + * @type bannerHelper */ public $helperData; /** - * @type \Magento\Store\Model\StoreManagerInterface + * @type StoreManagerInterface */ protected $store; /** - * @var \Magento\Customer\Api\CustomerRepositoryInterface + * @var CustomerRepositoryInterface */ protected $customerRepository; /** - * @var \Magento\Framework\Stdlib\DateTime\DateTime + * @var DateTime */ protected $_date; @@ -75,13 +78,12 @@ public function __construct( DateTime $dateTime, FilterProvider $filterProvider, array $data = [] - ) - { - $this->helperData = $helperData; + ) { + $this->helperData = $helperData; $this->customerRepository = $customerRepository; - $this->store = $context->getStoreManager(); - $this->_date = $dateTime; - $this->filterProvider = $filterProvider; + $this->store = $context->getStoreManager(); + $this->_date = $dateTime; + $this->filterProvider = $filterProvider; parent::__construct($context, $data); } @@ -113,7 +115,7 @@ public function getSliderId() * @param $content * * @return string - * @throws \Exception + * @throws Exception */ public function getPageFilter($content) { @@ -121,7 +123,7 @@ public function getPageFilter($content) } /** - * @return array|\Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection + * @return array|AbstractCollection */ public function getBannerCollection() { @@ -140,4 +142,4 @@ public function getBannerOptions() { return $this->helperData->getBannerOptions($this->getSlider()); } -} \ No newline at end of file +} diff --git a/Block/Widget.php b/Block/Widget.php index 9eec071..1b28f9a 100644 --- a/Block/Widget.php +++ b/Block/Widget.php @@ -21,6 +21,8 @@ namespace Mageplaza\BannerSlider\Block; +use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; + /** * Class Widget * @package Mageplaza\BannerSlider\Block @@ -28,19 +30,19 @@ class Widget extends Slider { /** - * @return array|bool|\Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection + * @return array|bool|AbstractCollection */ public function getBannerCollection() { $sliderId = $this->getData('slider_id'); - if (!$this->helperData->isEnabled() || !$sliderId) { + if (!$sliderId || !$this->helperData->isEnabled()) { return false; } $sliderCollection = $this->helperData->getActiveSliders(); - $slider = $sliderCollection->addFieldToFilter('slider_id', $sliderId)->getFirstItem(); + $slider = $sliderCollection->addFieldToFilter('slider_id', $sliderId)->getFirstItem(); $this->setSlider($slider); return parent::getBannerCollection(); } -} \ No newline at end of file +} diff --git a/Controller/Adminhtml/Banner.php b/Controller/Adminhtml/Banner.php index 4fe443d..9c1fc06 100644 --- a/Controller/Adminhtml/Banner.php +++ b/Controller/Adminhtml/Banner.php @@ -23,6 +23,7 @@ use Magento\Backend\App\Action; use Magento\Backend\App\Action\Context; +use Magento\Backend\Model\View\Result\RedirectFactory; use Magento\Framework\Registry; use Mageplaza\BannerSlider\Model\BannerFactory; @@ -49,7 +50,7 @@ abstract class Banner extends Action /** * Result redirect factory * - * @var \Magento\Backend\Model\View\Result\RedirectFactory + * @var RedirectFactory */ /** @@ -63,10 +64,9 @@ public function __construct( BannerFactory $bannerFactory, Registry $coreRegistry, Context $context - ) - { + ) { $this->bannerFactory = $bannerFactory; - $this->coreRegistry = $coreRegistry; + $this->coreRegistry = $coreRegistry; parent::__construct($context); } diff --git a/Controller/Adminhtml/Banner/Delete.php b/Controller/Adminhtml/Banner/Delete.php index a8f6098..b403ea2 100644 --- a/Controller/Adminhtml/Banner/Delete.php +++ b/Controller/Adminhtml/Banner/Delete.php @@ -21,6 +21,10 @@ namespace Mageplaza\BannerSlider\Controller\Adminhtml\Banner; +use Exception; +use Magento\Framework\App\ResponseInterface; +use Magento\Framework\Controller\Result\Redirect; +use Magento\Framework\Controller\ResultInterface; use Mageplaza\BannerSlider\Controller\Adminhtml\Banner; /** @@ -30,7 +34,7 @@ class Delete extends Banner { /** - * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Redirect|\Magento\Framework\Controller\ResultInterface + * @return ResponseInterface|Redirect|ResultInterface */ public function execute() { @@ -40,7 +44,7 @@ public function execute() ->load($this->getRequest()->getParam('banner_id')) ->delete(); $this->messageManager->addSuccess(__('The Banner has been deleted.')); - } catch (\Exception $e) { + } catch (Exception $e) { // display error message $this->messageManager->addErrorMessage($e->getMessage()); // go back to edit form diff --git a/Controller/Adminhtml/Banner/Edit.php b/Controller/Adminhtml/Banner/Edit.php index f736b24..8b014c0 100644 --- a/Controller/Adminhtml/Banner/Edit.php +++ b/Controller/Adminhtml/Banner/Edit.php @@ -22,7 +22,11 @@ namespace Mageplaza\BannerSlider\Controller\Adminhtml\Banner; use Magento\Backend\App\Action\Context; +use Magento\Framework\App\ResponseInterface; +use Magento\Framework\Controller\Result\Redirect; +use Magento\Framework\Controller\ResultInterface; use Magento\Framework\Registry; +use Magento\Framework\View\Result\Page; use Magento\Framework\View\Result\PageFactory; use Mageplaza\BannerSlider\Controller\Adminhtml\Banner; use Mageplaza\BannerSlider\Model\BannerFactory; @@ -38,31 +42,30 @@ class Edit extends Banner /** * Page factory * - * @var \Magento\Framework\View\Result\PageFactory + * @var PageFactory */ protected $resultPageFactory; /** * Edit constructor. * - * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Mageplaza\BannerSlider\Model\BannerFactory $bannerFactory - * @param \Magento\Framework\Registry $registry - * @param \Magento\Backend\App\Action\Context $context + * @param PageFactory $resultPageFactory + * @param BannerFactory $bannerFactory + * @param Registry $registry + * @param Context $context */ public function __construct( PageFactory $resultPageFactory, BannerFactory $bannerFactory, Registry $registry, Context $context - ) - { + ) { $this->resultPageFactory = $resultPageFactory; parent::__construct($bannerFactory, $registry, $context); } /** - * @return \Magento\Backend\Model\View\Result\Page|\Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Redirect|\Magento\Framework\Controller\ResultInterface|\Magento\Framework\View\Result\Page + * @return \Magento\Backend\Model\View\Result\Page|ResponseInterface|Redirect|ResultInterface|Page */ public function execute() { @@ -92,7 +95,7 @@ public function execute() $banner->setData($data); } - /** @var \Magento\Backend\Model\View\Result\Page|\Magento\Framework\View\Result\Page $resultPage */ + /** @var \Magento\Backend\Model\View\Result\Page|Page $resultPage */ $resultPage = $this->resultPageFactory->create(); $resultPage->setActiveMenu('Mageplaza_BannerSlider::banner'); $resultPage->getConfig()->getTitle() diff --git a/Controller/Adminhtml/Banner/Index.php b/Controller/Adminhtml/Banner/Index.php index d691268..f246cb7 100644 --- a/Controller/Adminhtml/Banner/Index.php +++ b/Controller/Adminhtml/Banner/Index.php @@ -23,6 +23,7 @@ use Magento\Backend\App\Action; use Magento\Backend\App\Action\Context; +use Magento\Framework\View\Result\Page; use Magento\Framework\View\Result\PageFactory; /** @@ -34,7 +35,7 @@ class Index extends Action /** * Page result factory * - * @var \Magento\Framework\View\Result\PageFactory + * @var PageFactory */ protected $resultPageFactory; @@ -54,8 +55,7 @@ class Index extends Action public function __construct( Context $context, PageFactory $resultPageFactory - ) - { + ) { $this->resultPageFactory = $resultPageFactory; parent::__construct($context); @@ -64,7 +64,7 @@ public function __construct( /** * execute the action * - * @return \Magento\Backend\Model\View\Result\Page|\Magento\Framework\View\Result\Page + * @return \Magento\Backend\Model\View\Result\Page|Page */ public function execute() { diff --git a/Controller/Adminhtml/Banner/InlineEdit.php b/Controller/Adminhtml/Banner/InlineEdit.php index 49c0055..bc15591 100644 --- a/Controller/Adminhtml/Banner/InlineEdit.php +++ b/Controller/Adminhtml/Banner/InlineEdit.php @@ -21,10 +21,16 @@ namespace Mageplaza\BannerSlider\Controller\Adminhtml\Banner; +use Exception; use Magento\Backend\App\Action; use Magento\Backend\App\Action\Context; +use Magento\Framework\Controller\Result\Json; use Magento\Framework\Controller\Result\JsonFactory; +use Magento\Framework\Controller\ResultInterface; +use Magento\Framework\Exception\LocalizedException; +use Mageplaza\BannerSlider\Model\Banner; use Mageplaza\BannerSlider\Model\BannerFactory; +use RuntimeException; /** * Class InlineEdit @@ -57,24 +63,23 @@ public function __construct( JsonFactory $jsonFactory, BannerFactory $bannerFactory, Context $context - ) - { - $this->jsonFactory = $jsonFactory; + ) { + $this->jsonFactory = $jsonFactory; $this->bannerFactory = $bannerFactory; parent::__construct($context); } /** - * @return \Magento\Framework\Controller\ResultInterface + * @return ResultInterface */ public function execute() { - /** @var \Magento\Framework\Controller\Result\Json $resultJson */ + /** @var Json $resultJson */ $resultJson = $this->jsonFactory->create(); - $error = false; - $messages = []; - $postItems = $this->getRequest()->getParam('items', []); + $error = false; + $messages = []; + $postItems = $this->getRequest()->getParam('items', []); if (!($this->getRequest()->getParam('isAjax') && count($postItems))) { return $resultJson->setData([ 'messages' => [__('Please correct the data sent.')], @@ -82,24 +87,24 @@ public function execute() ]); } foreach (array_keys($postItems) as $bannerId) { - /** @var \Mageplaza\BannerSlider\Model\Banner $banner */ + /** @var Banner $banner */ $banner = $this->bannerFactory->create()->load($bannerId); try { $bannerData = $postItems[$bannerId];//todo: handle dates $banner->addData($bannerData); $banner->save(); - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $messages[] = $this->getErrorWithBannerId($banner, $e->getMessage()); - $error = true; - } catch (\RuntimeException $e) { + $error = true; + } catch (RuntimeException $e) { $messages[] = $this->getErrorWithBannerId($banner, $e->getMessage()); - $error = true; - } catch (\Exception $e) { + $error = true; + } catch (Exception $e) { $messages[] = $this->getErrorWithBannerId( $banner, __('Something went wrong while saving the Banner.') ); - $error = true; + $error = true; } } @@ -112,12 +117,12 @@ public function execute() /** * Add Banner id to error message * - * @param \Mageplaza\BannerSlider\Model\Banner $banner + * @param Banner $banner * @param string $errorText * * @return string */ - protected function getErrorWithBannerId(\Mageplaza\BannerSlider\Model\Banner $banner, $errorText) + protected function getErrorWithBannerId(Banner $banner, $errorText) { return '[Banner ID: ' . $banner->getId() . '] ' . $errorText; } diff --git a/Controller/Adminhtml/Banner/MassDelete.php b/Controller/Adminhtml/Banner/MassDelete.php index 883efee..a016510 100644 --- a/Controller/Adminhtml/Banner/MassDelete.php +++ b/Controller/Adminhtml/Banner/MassDelete.php @@ -23,7 +23,13 @@ use Magento\Backend\App\Action; use Magento\Backend\App\Action\Context; +use Magento\Backend\Model\View\Result\Redirect; +use Magento\Framework\App\ResponseInterface; +use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\Controller\ResultInterface; +use Magento\Framework\Exception\LocalizedException; use Magento\Ui\Component\MassAction\Filter; +use Mageplaza\BannerSlider\Model\Banner; use Mageplaza\BannerSlider\Model\ResourceModel\Banner\CollectionFactory; /** @@ -57,17 +63,16 @@ public function __construct( Filter $filter, CollectionFactory $collectionFactory, Context $context - ) - { - $this->filter = $filter; + ) { + $this->filter = $filter; $this->collectionFactory = $collectionFactory; parent::__construct($context); } /** - * @return \Magento\Backend\Model\View\Result\Redirect|\Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface - * @throws \Magento\Framework\Exception\LocalizedException + * @return Redirect|ResponseInterface|ResultInterface + * @throws LocalizedException */ public function execute() { @@ -75,13 +80,13 @@ public function execute() $delete = 0; foreach ($collection as $item) { - /** @var \Mageplaza\BannerSlider\Model\Banner $item */ + /** @var Banner $item */ $item->delete(); $delete++; } $this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $delete)); - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ - $resultRedirect = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT); + /** @var Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); return $resultRedirect->setPath('*/*/'); } diff --git a/Controller/Adminhtml/Banner/MassStatus.php b/Controller/Adminhtml/Banner/MassStatus.php index 5819489..a7f1d16 100644 --- a/Controller/Adminhtml/Banner/MassStatus.php +++ b/Controller/Adminhtml/Banner/MassStatus.php @@ -21,9 +21,13 @@ namespace Mageplaza\BannerSlider\Controller\Adminhtml\Banner; +use Exception; use Magento\Backend\App\Action; use Magento\Backend\App\Action\Context; +use Magento\Backend\Model\View\Result\Redirect; +use Magento\Framework\App\ResponseInterface; use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\Controller\ResultInterface; use Magento\Framework\Exception\LocalizedException; use Magento\Ui\Component\MassAction\Filter; use Mageplaza\BannerSlider\Model\ResourceModel\Banner\CollectionFactory; @@ -37,14 +41,14 @@ class MassStatus extends Action /** * Mass Action Filter * - * @var \Magento\Ui\Component\MassAction\Filter + * @var Filter */ public $filter; /** * Collection Factory * - * @var \Mageplaza\BannerSlider\Model\ResourceModel\Banner\CollectionFactory + * @var CollectionFactory */ public $collectionFactory; @@ -59,22 +63,21 @@ public function __construct( Context $context, Filter $filter, CollectionFactory $collectionFactory - ) - { - $this->filter = $filter; + ) { + $this->filter = $filter; $this->collectionFactory = $collectionFactory; parent::__construct($context); } /** - * @return $this|\Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface + * @return $this|ResponseInterface|ResultInterface * @throws LocalizedException */ public function execute() { - $collection = $this->filter->getCollection($this->collectionFactory->create()); - $status = (int)$this->getRequest()->getParam('status'); + $collection = $this->filter->getCollection($this->collectionFactory->create()); + $status = (int)$this->getRequest()->getParam('status'); $bannerUpdated = 0; foreach ($collection as $banner) { try { @@ -84,7 +87,7 @@ public function execute() $bannerUpdated++; } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); - } catch (\Exception $e) { + } catch (Exception $e) { $this->messageManager->addErrorMessage(__('Something went wrong while updating status for %1.', $banner->getName())); } } @@ -93,7 +96,7 @@ public function execute() $this->messageManager->addSuccessMessage(__('A total of %1 record(s) have been updated.', $bannerUpdated)); } - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + /** @var Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); return $resultRedirect->setPath('*/*/'); diff --git a/Controller/Adminhtml/Banner/NewAction.php b/Controller/Adminhtml/Banner/NewAction.php index f0b11b8..a3dd271 100644 --- a/Controller/Adminhtml/Banner/NewAction.php +++ b/Controller/Adminhtml/Banner/NewAction.php @@ -22,6 +22,8 @@ namespace Mageplaza\BannerSlider\Controller\Adminhtml\Banner; use Magento\Backend\App\Action; +use Magento\Framework\App\ResponseInterface; +use Magento\Framework\Controller\ResultInterface; /** * Class NewAction @@ -30,7 +32,7 @@ class NewAction extends Action { /** - * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|void + * @return ResponseInterface|ResultInterface|void */ public function execute() { diff --git a/Controller/Adminhtml/Banner/Save.php b/Controller/Adminhtml/Banner/Save.php index 2ceab0e..71ab030 100644 --- a/Controller/Adminhtml/Banner/Save.php +++ b/Controller/Adminhtml/Banner/Save.php @@ -21,12 +21,19 @@ namespace Mageplaza\BannerSlider\Controller\Adminhtml\Banner; +use Exception; use Magento\Backend\App\Action\Context; use Magento\Backend\Helper\Js; +use Magento\Framework\App\ResponseInterface; +use Magento\Framework\Controller\Result\Redirect; +use Magento\Framework\Controller\ResultInterface; +use Magento\Framework\Exception\FileSystemException; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Registry; use Mageplaza\BannerSlider\Controller\Adminhtml\Banner; use Mageplaza\BannerSlider\Helper\Image; use Mageplaza\BannerSlider\Model\BannerFactory; +use RuntimeException; /** * Class Save @@ -37,14 +44,14 @@ class Save extends Banner /** * Image Helper * - * @var \Mageplaza\BannerSlider\Helper\Image + * @var Image */ protected $imageHelper; /** * JS helper * - * @var \Magento\Backend\Helper\Js + * @var Js */ public $jsHelper; @@ -62,17 +69,16 @@ public function __construct( Registry $registry, Js $jsHelper, Context $context - ) - { + ) { $this->imageHelper = $imageHelper; - $this->jsHelper = $jsHelper; + $this->jsHelper = $jsHelper; parent::__construct($bannerFactory, $registry, $context); } /** - * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Redirect|\Magento\Framework\Controller\ResultInterface - * @throws \Magento\Framework\Exception\FileSystemException + * @return ResponseInterface|Redirect|ResultInterface + * @throws FileSystemException */ public function execute() { @@ -116,11 +122,11 @@ public function execute() $resultRedirect->setPath('mpbannerslider/*/'); return $resultRedirect; - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $this->messageManager->addError($e->getMessage()); - } catch (\RuntimeException $e) { + } catch (RuntimeException $e) { $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { + } catch (Exception $e) { $this->messageManager->addException($e, __('Something went wrong while saving the Banner.')); } diff --git a/Controller/Adminhtml/Slider.php b/Controller/Adminhtml/Slider.php index c70619a..373897b 100644 --- a/Controller/Adminhtml/Slider.php +++ b/Controller/Adminhtml/Slider.php @@ -35,14 +35,14 @@ abstract class Slider extends Action /** * Slider Factory * - * @var \Mageplaza\BannerSlider\Model\SliderFactory + * @var SliderFactory */ protected $sliderFactory; /** * Core registry * - * @var \Magento\Framework\Registry + * @var Registry */ protected $coreRegistry; @@ -57,10 +57,9 @@ public function __construct( SliderFactory $sliderFactory, Registry $coreRegistry, Context $context - ) - { + ) { $this->sliderFactory = $sliderFactory; - $this->coreRegistry = $coreRegistry; + $this->coreRegistry = $coreRegistry; parent::__construct($context); } diff --git a/Controller/Adminhtml/Slider/Banners.php b/Controller/Adminhtml/Slider/Banners.php index 67a07e7..96a9a19 100644 --- a/Controller/Adminhtml/Slider/Banners.php +++ b/Controller/Adminhtml/Slider/Banners.php @@ -23,7 +23,9 @@ use Magento\Backend\App\Action\Context; use Magento\Framework\Registry; +use Magento\Framework\View\Result\Layout; use Magento\Framework\View\Result\LayoutFactory; +use Mageplaza\BannerSlider\Block\Adminhtml\Slider\Edit\Tab\Banner; use Mageplaza\BannerSlider\Controller\Adminhtml\Slider; use Mageplaza\BannerSlider\Model\SliderFactory; @@ -36,7 +38,7 @@ class Banners extends Slider /** * Result layout factory * - * @var \Magento\Framework\View\Result\LayoutFactory + * @var LayoutFactory */ protected $resultLayoutFactory; @@ -53,21 +55,20 @@ public function __construct( SliderFactory $bannerFactory, Registry $registry, Context $context - ) - { + ) { $this->resultLayoutFactory = $resultLayoutFactory; parent::__construct($bannerFactory, $registry, $context); } /** - * @return \Magento\Framework\View\Result\Layout + * @return Layout */ public function execute() { $this->initSlider(); $resultLayout = $this->resultLayoutFactory->create(); - /** @var \Mageplaza\BannerSlider\Block\Adminhtml\Slider\Edit\Tab\Banner $bannersBlock */ + /** @var Banner $bannersBlock */ $bannersBlock = $resultLayout->getLayout()->getBlock('slider.edit.tab.banner'); if ($bannersBlock) { $bannersBlock->setSliderBanners($this->getRequest()->getPost('slider_banners', null)); diff --git a/Controller/Adminhtml/Slider/Delete.php b/Controller/Adminhtml/Slider/Delete.php index 410caa1..f4c6355 100644 --- a/Controller/Adminhtml/Slider/Delete.php +++ b/Controller/Adminhtml/Slider/Delete.php @@ -21,7 +21,12 @@ namespace Mageplaza\BannerSlider\Controller\Adminhtml\Slider; +use Exception; +use Magento\Framework\App\ResponseInterface; +use Magento\Framework\Controller\Result\Redirect; +use Magento\Framework\Controller\ResultInterface; use Mageplaza\BannerSlider\Controller\Adminhtml\Slider; +use Mageplaza\BannerSlider\Model\Banner; /** * Class Delete @@ -30,18 +35,18 @@ class Delete extends Slider { /** - * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Redirect|\Magento\Framework\Controller\ResultInterface + * @return ResponseInterface|Redirect|ResultInterface */ public function execute() { $resultRedirect = $this->resultRedirectFactory->create(); try { - /** @var \Mageplaza\BannerSlider\Model\Banner $banner */ + /** @var Banner $banner */ $this->sliderFactory->create() ->load($this->getRequest()->getParam('slider_id')) ->delete(); $this->messageManager->addSuccess(__('The slider has been deleted.')); - } catch (\Exception $e) { + } catch (Exception $e) { // display error message $this->messageManager->addErrorMessage($e->getMessage()); // go back to edit form diff --git a/Controller/Adminhtml/Slider/Edit.php b/Controller/Adminhtml/Slider/Edit.php index 2cf00ad..7d41c75 100644 --- a/Controller/Adminhtml/Slider/Edit.php +++ b/Controller/Adminhtml/Slider/Edit.php @@ -22,7 +22,11 @@ namespace Mageplaza\BannerSlider\Controller\Adminhtml\Slider; use Magento\Backend\App\Action\Context; +use Magento\Framework\App\ResponseInterface; +use Magento\Framework\Controller\Result\Redirect; +use Magento\Framework\Controller\ResultInterface; use Magento\Framework\Registry; +use Magento\Framework\View\Result\Page; use Magento\Framework\View\Result\PageFactory; use Mageplaza\BannerSlider\Controller\Adminhtml\Slider; use Mageplaza\BannerSlider\Model\SliderFactory; @@ -38,7 +42,7 @@ class Edit extends Slider /** * Page factory * - * @var \Magento\Framework\View\Result\PageFactory + * @var PageFactory */ protected $resultPageFactory; @@ -55,15 +59,14 @@ public function __construct( SliderFactory $sliderFactory, Registry $registry, Context $context - ) - { + ) { $this->resultPageFactory = $resultPageFactory; parent::__construct($sliderFactory, $registry, $context); } /** - * @return \Magento\Backend\Model\View\Result\Page|\Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Redirect|\Magento\Framework\Controller\ResultInterface|\Magento\Framework\View\Result\Page + * @return \Magento\Backend\Model\View\Result\Page|ResponseInterface|Redirect|ResultInterface|Page */ public function execute() { @@ -93,7 +96,7 @@ public function execute() $slider->setData($data); } - /** @var \Magento\Backend\Model\View\Result\Page|\Magento\Framework\View\Result\Page $resultPage */ + /** @var \Magento\Backend\Model\View\Result\Page|Page $resultPage */ $resultPage = $this->resultPageFactory->create(); $resultPage->setActiveMenu('Mageplaza_BannerSlider::slider'); $resultPage->getConfig()->getTitle() diff --git a/Controller/Adminhtml/Slider/Index.php b/Controller/Adminhtml/Slider/Index.php index b707aed..6d02c85 100644 --- a/Controller/Adminhtml/Slider/Index.php +++ b/Controller/Adminhtml/Slider/Index.php @@ -23,6 +23,7 @@ use Magento\Backend\App\Action; use Magento\Backend\App\Action\Context; +use Magento\Framework\View\Result\Page; use Magento\Framework\View\Result\PageFactory; /** @@ -34,7 +35,7 @@ class Index extends Action /** * Page result factory * - * @var \Magento\Framework\View\Result\PageFactory + * @var PageFactory */ protected $resultPageFactory; @@ -48,14 +49,13 @@ class Index extends Action /** * constructor * - * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory - * @param \Magento\Backend\App\Action\Context $context + * @param PageFactory $resultPageFactory + * @param Context $context */ public function __construct( PageFactory $resultPageFactory, Context $context - ) - { + ) { $this->resultPageFactory = $resultPageFactory; parent::__construct($context); @@ -64,7 +64,7 @@ public function __construct( /** * execute the action * - * @return \Magento\Backend\Model\View\Result\Page|\Magento\Framework\View\Result\Page + * @return \Magento\Backend\Model\View\Result\Page|Page */ public function execute() { diff --git a/Controller/Adminhtml/Slider/InlineEdit.php b/Controller/Adminhtml/Slider/InlineEdit.php index f971336..e209a91 100644 --- a/Controller/Adminhtml/Slider/InlineEdit.php +++ b/Controller/Adminhtml/Slider/InlineEdit.php @@ -21,27 +21,34 @@ namespace Mageplaza\BannerSlider\Controller\Adminhtml\Slider; +use Exception; +use Magento\Backend\App\Action; use Magento\Backend\App\Action\Context; +use Magento\Framework\Controller\Result\Json; use Magento\Framework\Controller\Result\JsonFactory; +use Magento\Framework\Controller\ResultInterface; +use Magento\Framework\Exception\LocalizedException; +use Mageplaza\BannerSlider\Model\Slider; use Mageplaza\BannerSlider\Model\SliderFactory; +use RuntimeException; /** * Class InlineEdit * @package Mageplaza\BannerSlider\Controller\Adminhtml\Slider */ -class InlineEdit extends \Magento\Backend\App\Action +class InlineEdit extends Action { /** * JSON Factory * - * @var \Magento\Framework\Controller\Result\JsonFactory + * @var JsonFactory */ protected $jsonFactory; /** * Banner Factory * - * @var \Mageplaza\BannerSlider\Model\SliderFactory + * @var SliderFactory */ protected $sliderFactory; @@ -55,24 +62,23 @@ public function __construct( JsonFactory $jsonFactory, SliderFactory $sliderFactory, Context $context - ) - { - $this->jsonFactory = $jsonFactory; + ) { + $this->jsonFactory = $jsonFactory; $this->sliderFactory = $sliderFactory; parent::__construct($context); } /** - * @return \Magento\Framework\Controller\ResultInterface + * @return ResultInterface */ public function execute() { - /** @var \Magento\Framework\Controller\Result\Json $resultJson */ + /** @var Json $resultJson */ $resultJson = $this->jsonFactory->create(); - $error = false; - $messages = []; - $postItems = $this->getRequest()->getParam('items', []); + $error = false; + $messages = []; + $postItems = $this->getRequest()->getParam('items', []); if (!($this->getRequest()->getParam('isAjax') && count($postItems))) { return $resultJson->setData([ 'messages' => [__('Please correct the data sent.')], @@ -80,24 +86,24 @@ public function execute() ]); } foreach (array_keys($postItems) as $sliderId) { - /** @var \Mageplaza\BannerSlider\Model\Slider $slider */ + /** @var Slider $slider */ $slider = $this->sliderFactory->create()->load($sliderId); try { $sliderData = $postItems[$sliderId]; $slider->addData($sliderData); $slider->save(); - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $messages[] = $this->getErrorWithSliderId($slider, $e->getMessage()); - $error = true; - } catch (\RuntimeException $e) { + $error = true; + } catch (RuntimeException $e) { $messages[] = $this->getErrorWithSliderId($slider, $e->getMessage()); - $error = true; - } catch (\Exception $e) { + $error = true; + } catch (Exception $e) { $messages[] = $this->getErrorWithSliderId( $slider, __('Something went wrong while saving the Banner.') ); - $error = true; + $error = true; } } @@ -110,12 +116,12 @@ public function execute() /** * Add slider id to error message * - * @param \Mageplaza\BannerSlider\Model\Slider $slider + * @param Slider $slider * @param $errorText * * @return string */ - protected function getErrorWithSliderId(\Mageplaza\BannerSlider\Model\Slider $slider, $errorText) + protected function getErrorWithSliderId(Slider $slider, $errorText) { return '[Slider ID: ' . $slider->getId() . '] ' . $errorText; } diff --git a/Controller/Adminhtml/Slider/MassDelete.php b/Controller/Adminhtml/Slider/MassDelete.php index 00d4059..9003337 100644 --- a/Controller/Adminhtml/Slider/MassDelete.php +++ b/Controller/Adminhtml/Slider/MassDelete.php @@ -21,27 +21,34 @@ namespace Mageplaza\BannerSlider\Controller\Adminhtml\Slider; +use Magento\Backend\App\Action; use Magento\Backend\App\Action\Context; +use Magento\Backend\Model\View\Result\Redirect; +use Magento\Framework\App\ResponseInterface; +use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\Controller\ResultInterface; +use Magento\Framework\Exception\LocalizedException; use Magento\Ui\Component\MassAction\Filter; use Mageplaza\BannerSlider\Model\ResourceModel\Slider\CollectionFactory; +use Mageplaza\BannerSlider\Model\Slider; /** * Class MassDelete * @package Mageplaza\BannerSlider\Controller\Adminhtml\Slider */ -class MassDelete extends \Magento\Backend\App\Action +class MassDelete extends Action { /** * Mass Action Filter * - * @var \Magento\Ui\Component\MassAction\Filter + * @var Filter */ protected $filter; /** * Collection Factory * - * @var \Mageplaza\BannerSlider\Model\ResourceModel\Slider\CollectionFactory + * @var CollectionFactory */ protected $collectionFactory; @@ -56,17 +63,16 @@ public function __construct( Filter $filter, CollectionFactory $collectionFactory, Context $context - ) - { - $this->filter = $filter; + ) { + $this->filter = $filter; $this->collectionFactory = $collectionFactory; parent::__construct($context); } /** - * @return \Magento\Backend\Model\View\Result\Redirect|\Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface - * @throws \Magento\Framework\Exception\LocalizedException + * @return Redirect|ResponseInterface|ResultInterface + * @throws LocalizedException */ public function execute() { @@ -74,13 +80,13 @@ public function execute() $delete = 0; foreach ($collection as $item) { - /** @var \Mageplaza\BannerSlider\Model\Slider $item */ + /** @var Slider $item */ $item->delete(); $delete++; } $this->messageManager->addSuccess(__('A total of %1 record(s) have been deleted.', $delete)); - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ - $resultRedirect = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT); + /** @var Redirect $resultRedirect */ + $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); return $resultRedirect->setPath('*/*/'); } diff --git a/Controller/Adminhtml/Slider/MassStatus.php b/Controller/Adminhtml/Slider/MassStatus.php index 7201781..bf7306d 100644 --- a/Controller/Adminhtml/Slider/MassStatus.php +++ b/Controller/Adminhtml/Slider/MassStatus.php @@ -21,9 +21,13 @@ namespace Mageplaza\BannerSlider\Controller\Adminhtml\Slider; +use Exception; use Magento\Backend\App\Action; use Magento\Backend\App\Action\Context; +use Magento\Backend\Model\View\Result\Redirect; +use Magento\Framework\App\ResponseInterface; use Magento\Framework\Controller\ResultFactory; +use Magento\Framework\Controller\ResultInterface; use Magento\Framework\Exception\LocalizedException; use Magento\Ui\Component\MassAction\Filter; use Mageplaza\BannerSlider\Model\ResourceModel\Slider\CollectionFactory; @@ -37,14 +41,14 @@ class MassStatus extends Action /** * Mass Action Filter * - * @var \Magento\Ui\Component\MassAction\Filter + * @var Filter */ public $filter; /** * Collection Factory * - * @var \Mageplaza\BannerSlider\Model\ResourceModel\Slider\CollectionFactory + * @var CollectionFactory */ public $collectionFactory; @@ -59,22 +63,21 @@ public function __construct( Context $context, Filter $filter, CollectionFactory $collectionFactory - ) - { - $this->filter = $filter; + ) { + $this->filter = $filter; $this->collectionFactory = $collectionFactory; parent::__construct($context); } /** - * @return $this|\Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface + * @return $this|ResponseInterface|ResultInterface * @throws LocalizedException */ public function execute() { - $collection = $this->filter->getCollection($this->collectionFactory->create()); - $status = (int)$this->getRequest()->getParam('status'); + $collection = $this->filter->getCollection($this->collectionFactory->create()); + $status = (int)$this->getRequest()->getParam('status'); $sliderUpdated = 0; foreach ($collection as $slider) { try { @@ -84,7 +87,7 @@ public function execute() $sliderUpdated++; } catch (LocalizedException $e) { $this->messageManager->addErrorMessage($e->getMessage()); - } catch (\Exception $e) { + } catch (Exception $e) { $this->messageManager->addErrorMessage(__('Something went wrong while updating status for %1.', $slider->getName())); } } @@ -93,7 +96,7 @@ public function execute() $this->messageManager->addSuccessMessage(__('A total of %1 record(s) have been updated.', $sliderUpdated)); } - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ + /** @var Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); return $resultRedirect->setPath('*/*/'); diff --git a/Controller/Adminhtml/Slider/NewAction.php b/Controller/Adminhtml/Slider/NewAction.php index a988d0b..dcd669c 100644 --- a/Controller/Adminhtml/Slider/NewAction.php +++ b/Controller/Adminhtml/Slider/NewAction.php @@ -22,6 +22,8 @@ namespace Mageplaza\BannerSlider\Controller\Adminhtml\Slider; use Magento\Backend\App\Action; +use Magento\Framework\App\ResponseInterface; +use Magento\Framework\Controller\ResultInterface; /** * Class NewAction @@ -30,7 +32,7 @@ class NewAction extends Action { /** - * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|void + * @return ResponseInterface|ResultInterface|void */ public function execute() { diff --git a/Controller/Adminhtml/Slider/Save.php b/Controller/Adminhtml/Slider/Save.php index f71ea88..6026d0a 100644 --- a/Controller/Adminhtml/Slider/Save.php +++ b/Controller/Adminhtml/Slider/Save.php @@ -21,12 +21,19 @@ namespace Mageplaza\BannerSlider\Controller\Adminhtml\Slider; +use Exception; use Magento\Backend\App\Action\Context; use Magento\Backend\Helper\Js; +use Magento\Framework\App\ResponseInterface; +use Magento\Framework\Controller\Result\Redirect; +use Magento\Framework\Controller\ResultInterface; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Registry; use Magento\Framework\Stdlib\DateTime\Filter\Date; use Mageplaza\BannerSlider\Controller\Adminhtml\Slider; use Mageplaza\BannerSlider\Model\SliderFactory; +use RuntimeException; +use Zend_Filter_Input; /** * Class Save @@ -37,14 +44,14 @@ class Save extends Slider /** * JS helper * - * @var \Magento\Backend\Helper\Js + * @var Js */ protected $jsHelper; /** * Date filter * - * @var \Magento\Framework\Stdlib\DateTime\Filter\Date + * @var Date */ protected $_dateFilter; @@ -63,23 +70,22 @@ public function __construct( Registry $registry, Context $context, Date $dateFilter - ) - { - $this->jsHelper = $jsHelper; + ) { + $this->jsHelper = $jsHelper; $this->_dateFilter = $dateFilter; parent::__construct($sliderFactory, $registry, $context); } /** - * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Redirect|\Magento\Framework\Controller\ResultInterface + * @return ResponseInterface|Redirect|ResultInterface */ public function execute() { $resultRedirect = $this->resultRedirectFactory->create(); if ($data = $this->getRequest()->getPost('slider')) { - $data = $this->_filterData($data); + $data = $this->_filterData($data); $slider = $this->initSlider(); $banners = $this->getRequest()->getPost('banners', -1); @@ -114,11 +120,11 @@ public function execute() $resultRedirect->setPath('mpbannerslider/*/'); return $resultRedirect; - } catch (\Magento\Framework\Exception\LocalizedException $e) { + } catch (LocalizedException $e) { $this->messageManager->addError($e->getMessage()); - } catch (\RuntimeException $e) { + } catch (RuntimeException $e) { $this->messageManager->addError($e->getMessage()); - } catch (\Exception $e) { + } catch (Exception $e) { $this->messageManager->addException($e, __('Something went wrong while saving the Slider.')); } @@ -148,8 +154,8 @@ public function execute() */ protected function _filterData($data) { - $inputFilter = new \Zend_Filter_Input(['from_date' => $this->_dateFilter,], [], $data); - $data = $inputFilter->getUnescaped(); + $inputFilter = new Zend_Filter_Input(['from_date' => $this->_dateFilter,], [], $data); + $data = $inputFilter->getUnescaped(); if (isset($data['responsive_items'])) { unset($data['responsive_items']['__empty']); diff --git a/Helper/Data.php b/Helper/Data.php index 7b0fb01..0abfb34 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -21,12 +21,14 @@ namespace Mageplaza\BannerSlider\Helper; +use Exception; use Magento\Framework\App\Helper\Context; use Magento\Framework\App\Http\Context as HttpContext; use Magento\Framework\ObjectManagerInterface; use Magento\Framework\Stdlib\DateTime\DateTime; use Magento\Store\Model\StoreManagerInterface; use Mageplaza\BannerSlider\Model\BannerFactory; +use Mageplaza\BannerSlider\Model\ResourceModel\Banner\Collection; use Mageplaza\BannerSlider\Model\SliderFactory; use Mageplaza\Core\Helper\AbstractData; @@ -77,10 +79,9 @@ public function __construct( SliderFactory $sliderFactory, StoreManagerInterface $storeManager, ObjectManagerInterface $objectManager - ) - { - $this->date = $date; - $this->httpContext = $httpContext; + ) { + $this->date = $date; + $this->httpContext = $httpContext; $this->bannerFactory = $bannerFactory; $this->sliderFactory = $sliderFactory; @@ -100,9 +101,9 @@ public function getBannerOptions($slider = null) $config = $this->getModuleConfig('mpbannerslider_design'); } - $defaultOpt = $this->getDefaultConfig($config); + $defaultOpt = $this->getDefaultConfig($config); $responsiveOpt = $this->getResponsiveConfig($slider); - $effectOpt = $this->getEffectConfig($slider); + $effectOpt = $this->getEffectConfig($slider); $sliderOptions = array_merge($defaultOpt, $responsiveOpt, $effectOpt); @@ -137,27 +138,23 @@ public function getResponsiveConfig($slider = null) $sliderResponsive = $slider->getIsResponsive(); if (!$defaultResponsive && !$sliderResponsive) { - return ["items" => 1]; + return ['items' => 1]; } - if (!$slider->getDesign()) { - try { - $responsiveItems = $this->unserialize($this->getModuleConfig('mpbannerslider_design/item_slider')); - } catch (\Exception $e) { - $responsiveItems = []; - } - } else { - try { - $responsiveItems = $this->unserialize($slider->getResponsiveItems()); - } catch (\Exception $e) { - $responsiveItems = []; - } + $responsiveItemsValue = $slider->getDesign() + ? $slider->getResponsiveItems() + : $this->getModuleConfig('mpbannerslider_design/item_slider'); + + try { + $responsiveItems = $this->unserialize($responsiveItemsValue); + } catch (Exception $e) { + $responsiveItems = []; } $result = []; foreach ($responsiveItems as $config) { - $size = $config['size'] ?: 0; - $items = $config['items'] ?: 0; + $size = $config['size'] ?: 0; + $items = $config['items'] ?: 0; $result[$size] = ["items" => $items]; } @@ -181,7 +178,7 @@ public function getEffectConfig($slider) /** * @param null $id * - * @return \Mageplaza\BannerSlider\Model\ResourceModel\Banner\Collection + * @return Collection */ public function getBannerCollection($id = null) { @@ -200,13 +197,16 @@ public function getBannerCollection($id = null) /** * @return Collection + * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function getActiveSliders() { /** @var Collection $collection */ $collection = $this->sliderFactory->create() ->getCollection() - ->addFieldToFilter('customer_group_ids', ['finset' => $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_GROUP)]) + ->addFieldToFilter('customer_group_ids', [ + 'finset' => $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_GROUP) + ]) ->addFieldToFilter('status', 1) ->addOrder('priority'); diff --git a/Helper/Image.php b/Helper/Image.php index 053ffe9..eac1b61 100644 --- a/Helper/Image.php +++ b/Helper/Image.php @@ -29,7 +29,7 @@ */ class Image extends Media { - const TEMPLATE_MEDIA_PATH = 'mageplaza/bannerslider'; + const TEMPLATE_MEDIA_PATH = 'mageplaza/bannerslider'; const TEMPLATE_MEDIA_TYPE_BANNER = 'banner/image'; const TEMPLATE_MEDIA_TYPE_SLIDER = 'slider/image'; } diff --git a/Model/Banner.php b/Model/Banner.php index f4ed17e..ca986e7 100644 --- a/Model/Banner.php +++ b/Model/Banner.php @@ -27,6 +27,7 @@ use Magento\Framework\Model\ResourceModel\AbstractResource; use Magento\Framework\Registry; use Mageplaza\BannerSlider\Model\Config\Source\Image as configImage; +use Mageplaza\BannerSlider\Model\ResourceModel\Slider\Collection; use Mageplaza\BannerSlider\Model\ResourceModel\Slider\CollectionFactory as sliderCollectionFactory; /** @@ -40,15 +41,15 @@ * @method mixed getUrl() * @method mixed getType() * @method mixed getStatus() - * @method Banner setCreatedAt(\string $createdAt) + * @method Banner setCreatedAt(string $createdAt) * @method string getCreatedAt() - * @method Banner setUpdatedAt(\string $updatedAt) + * @method Banner setUpdatedAt(string $updatedAt) * @method string getUpdatedAt() * @method Banner setSlidersData(array $data) * @method array getSlidersData() * @method Banner setSlidersIds(array $sliderIds) * @method array getSlidersIds() - * @method Banner setIsChangedSliderList(\bool $flag) + * @method Banner setIsChangedSliderList(bool $flag) * @method bool getIsChangedSliderList() * @method Banner setAffectedSliderIds(array $ids) * @method bool getAffectedSliderIds() @@ -79,14 +80,14 @@ class Banner extends AbstractModel /** * Slider Collection * - * @var \Mageplaza\BannerSlider\Model\ResourceModel\Slider\Collection + * @var Collection */ protected $sliderCollection; /** * Slider Collection Factory * - * @var \Mageplaza\BannerSlider\Model\ResourceModel\Slider\CollectionFactory + * @var sliderCollectionFactory */ protected $sliderCollectionFactory; @@ -114,10 +115,9 @@ public function __construct( AbstractResource $resource = null, AbstractDb $resourceCollection = null, array $data = [] - ) - { + ) { $this->sliderCollectionFactory = $sliderCollectionFactory; - $this->imageModel = $configImage; + $this->imageModel = $configImage; parent::__construct($context, $registry, $resource, $resourceCollection, $data); } diff --git a/Model/Config/Source/Effect.php b/Model/Config/Source/Effect.php index f7b6821..21eac5a 100644 --- a/Model/Config/Source/Effect.php +++ b/Model/Config/Source/Effect.php @@ -29,15 +29,15 @@ */ class Effect implements ArrayInterface { - const SLIDER = 'slider'; - const FADE_OUT = 'fadeOut'; - const ROTATE_OUT = 'rotateOut'; - const FLIP_OUT = 'flipOutX'; - const ROLL_OUT = 'rollOut'; - const ZOOM_OUT = 'zoomOut'; - const SLIDER_OUT_LEFT = 'slideOutLeft'; + const SLIDER = 'slider'; + const FADE_OUT = 'fadeOut'; + const ROTATE_OUT = 'rotateOut'; + const FLIP_OUT = 'flipOutX'; + const ROLL_OUT = 'rollOut'; + const ZOOM_OUT = 'zoomOut'; + const SLIDER_OUT_LEFT = 'slideOutLeft'; const SLIDER_OUT_RIGHT = 'slideOutRight'; - const LIGHT_SPEED_OUT = 'lightSpeedOut'; + const LIGHT_SPEED_OUT = 'lightSpeedOut'; /** * to option array @@ -87,4 +87,4 @@ public function toOptionArray() return $options; } -} \ No newline at end of file +} diff --git a/Model/Config/Source/Image.php b/Model/Config/Source/Image.php index b8d914b..1506afe 100644 --- a/Model/Config/Source/Image.php +++ b/Model/Config/Source/Image.php @@ -21,6 +21,8 @@ namespace Mageplaza\BannerSlider\Model\Config\Source; +use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Filesystem; use Magento\Framework\UrlInterface; @@ -77,10 +79,10 @@ public function getBaseUrl() * get base image dir * * @return string - * @throws \Magento\Framework\Exception\FileSystemException + * @throws FileSystemException */ public function getBaseDir() { - return $this->fileSystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA)->getAbsolutePath($this->subDir . '/image/'); + return $this->fileSystem->getDirectoryWrite(DirectoryList::MEDIA)->getAbsolutePath($this->subDir . '/image/'); } } diff --git a/Model/Config/Source/Location.php b/Model/Config/Source/Location.php index 4bcaf0b..e7fdb2b 100644 --- a/Model/Config/Source/Location.php +++ b/Model/Config/Source/Location.php @@ -29,24 +29,24 @@ */ class Location implements ArrayInterface { - const ALLPAGE_CONTENT_TOP = 'allpage.content-top'; - const ALLPAGE_CONTENT_BOTTOM = 'allpage.content-bottom'; - const ALLPAGE_PAGE_TOP = 'allpage.page-top'; - const ALLPAGE_PAGE_BOTTOM = 'allpage.footer-container'; - const HOMEPAGE_CONTENT_TOP = 'cms_index_index.content-top'; + const ALLPAGE_CONTENT_TOP = 'allpage.content-top'; + const ALLPAGE_CONTENT_BOTTOM = 'allpage.content-bottom'; + const ALLPAGE_PAGE_TOP = 'allpage.page-top'; + const ALLPAGE_PAGE_BOTTOM = 'allpage.footer-container'; + const HOMEPAGE_CONTENT_TOP = 'cms_index_index.content-top'; const HOMEPAGE_CONTENT_BOTTOM = 'cms_index_index.content-bottom'; - const HOMEPAGE_PAGE_TOP = 'cms_index_index.page-top'; - const HOMEPAGE_PAGE_BOTTOM = 'cms_index_index.footer-container'; - const CATEGORY_CONTENT_TOP = 'catalog_category_view.content-top'; + const HOMEPAGE_PAGE_TOP = 'cms_index_index.page-top'; + const HOMEPAGE_PAGE_BOTTOM = 'cms_index_index.footer-container'; + const CATEGORY_CONTENT_TOP = 'catalog_category_view.content-top'; const CATEGORY_CONTENT_BOTTOM = 'catalog_category_view.content-bottom'; - const CATEGORY_PAGE_TOP = 'catalog_category_view.page-top'; - const CATEGORY_PAGE_BOTTOM = 'catalog_category_view.footer-container'; - const CATEGORY_SIDEBAR_TOP = 'catalog_category_view.sidebar-top'; + const CATEGORY_PAGE_TOP = 'catalog_category_view.page-top'; + const CATEGORY_PAGE_BOTTOM = 'catalog_category_view.footer-container'; + const CATEGORY_SIDEBAR_TOP = 'catalog_category_view.sidebar-top'; const CATEGORY_SIDEBAR_BOTTOM = 'catalog_category_view.sidebar-bottom'; - const PRODUCT_CONTENT_TOP = 'catalog_product_view.content-top'; - const PRODUCT_CONTENT_BOTTOM = 'catalog_product_view.content-bottom'; - const PRODUCT_PAGE_TOP = 'catalog_product_view.page-top'; - const PRODUCT_PAGE_BOTTOM = 'catalog_product_view.footer-container'; + const PRODUCT_CONTENT_TOP = 'catalog_product_view.content-top'; + const PRODUCT_CONTENT_BOTTOM = 'catalog_product_view.content-bottom'; + const PRODUCT_PAGE_TOP = 'catalog_product_view.page-top'; + const PRODUCT_PAGE_BOTTOM = 'catalog_product_view.footer-container'; /** * Return array of options as value-label pairs @@ -152,4 +152,4 @@ public function toOptionArray() return $options; } -} \ No newline at end of file +} diff --git a/Model/Config/Source/Sliders.php b/Model/Config/Source/Sliders.php index 6a344a2..1400efe 100644 --- a/Model/Config/Source/Sliders.php +++ b/Model/Config/Source/Sliders.php @@ -75,4 +75,4 @@ protected function toArray() return $options; } -} \ No newline at end of file +} diff --git a/Model/Config/Source/Template.php b/Model/Config/Source/Template.php index 57868fd..72a772e 100644 --- a/Model/Config/Source/Template.php +++ b/Model/Config/Source/Template.php @@ -89,7 +89,7 @@ public function toOptionArray() */ public function getTemplateHtml() { - $imgTmp = '
+ $imgTmp = '
{{imgName}}
diff --git a/Model/Config/Source/Type.php b/Model/Config/Source/Type.php index 8453b2b..5b6c3ca 100644 --- a/Model/Config/Source/Type.php +++ b/Model/Config/Source/Type.php @@ -29,7 +29,7 @@ */ class Type implements ArrayInterface { - const IMAGE = '0'; + const IMAGE = '0'; const CONTENT = '1'; /** diff --git a/Model/ResourceModel/Banner.php b/Model/ResourceModel/Banner.php index 2bec22a..9a9abc6 100644 --- a/Model/ResourceModel/Banner.php +++ b/Model/ResourceModel/Banner.php @@ -22,6 +22,7 @@ namespace Mageplaza\BannerSlider\Model\ResourceModel; use Magento\Framework\Event\ManagerInterface; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Model\AbstractModel; use Magento\Framework\Model\ResourceModel\Db\AbstractDb; use Magento\Framework\Model\ResourceModel\Db\Context; @@ -36,7 +37,7 @@ class Banner extends AbstractDb /** * Date model * - * @var \Magento\Framework\Stdlib\DateTime\DateTime + * @var DateTime */ protected $date; @@ -50,24 +51,23 @@ class Banner extends AbstractDb /** * Event Manager * - * @var \Magento\Framework\Event\ManagerInterface + * @var ManagerInterface */ protected $eventManager; /** * constructor * - * @param \Magento\Framework\Stdlib\DateTime\DateTime $date - * @param \Magento\Framework\Event\ManagerInterface $eventManager - * @param \Magento\Framework\Model\ResourceModel\Db\Context $context + * @param DateTime $date + * @param ManagerInterface $eventManager + * @param Context $context */ public function __construct( DateTime $date, ManagerInterface $eventManager, Context $context - ) - { - $this->date = $date; + ) { + $this->date = $date; $this->eventManager = $eventManager; parent::__construct($context); @@ -88,15 +88,15 @@ protected function _construct() * @param $id * * @return string - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ public function getBannerNameById($id) { $adapter = $this->getConnection(); - $select = $adapter->select() + $select = $adapter->select() ->from($this->getMainTable(), 'name') ->where('banner_id = :banner_id'); - $binds = ['banner_id' => (int)$id]; + $binds = ['banner_id' => (int)$id]; return $adapter->fetchOne($select, $binds); } @@ -137,15 +137,15 @@ protected function _afterSave(AbstractModel $object) protected function saveSliderRelation(\Mageplaza\BannerSlider\Model\Banner $banner) { $banner->setIsChangedSliderList(false); - $id = $banner->getId(); + $id = $banner->getId(); $sliders = $banner->getSlidersIds(); if ($sliders === null) { return $this; } $oldSliders = $banner->getSliderIds(); - $insert = array_diff($sliders, $oldSliders); - $delete = array_diff($oldSliders, $sliders); + $insert = array_diff($sliders, $oldSliders); + $delete = array_diff($oldSliders, $sliders); $adapter = $this->getConnection(); if (!empty($delete)) { @@ -167,7 +167,8 @@ protected function saveSliderRelation(\Mageplaza\BannerSlider\Model\Banner $bann $sliderIds = array_unique(array_merge(array_keys($insert), array_keys($delete))); $this->eventManager->dispatch( 'mageplaza_bannerslider_banner_after_save_sliders', - ['banner' => $banner, 'slider_ids' => $sliderIds]); + ['banner' => $banner, 'slider_ids' => $sliderIds] + ); $banner->setIsChangedSliderList(true); $sliderIds = array_keys($insert + $delete); @@ -185,7 +186,7 @@ protected function saveSliderRelation(\Mageplaza\BannerSlider\Model\Banner $bann public function getSliderIds(\Mageplaza\BannerSlider\Model\Banner $banner) { $adapter = $this->getConnection(); - $select = $adapter->select() + $select = $adapter->select() ->from($this->bannerSliderTable, 'slider_id') ->where('banner_id = ?', (int)$banner->getId()); diff --git a/Model/ResourceModel/Banner/Collection.php b/Model/ResourceModel/Banner/Collection.php index b86ef29..e481f74 100644 --- a/Model/ResourceModel/Banner/Collection.php +++ b/Model/ResourceModel/Banner/Collection.php @@ -21,7 +21,9 @@ namespace Mageplaza\BannerSlider\Model\ResourceModel\Banner; +use Magento\Framework\DB\Select; use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; +use Zend_Db_Select; /** * Class Collection @@ -64,12 +66,12 @@ protected function _construct() * Get SQL for get record count. * Extra GROUP BY strip added. * - * @return \Magento\Framework\DB\Select + * @return Select */ public function getSelectCountSql() { $countSelect = parent::getSelectCountSql(); - $countSelect->reset(\Zend_Db_Select::GROUP); + $countSelect->reset(Zend_Db_Select::GROUP); return $countSelect; } diff --git a/Model/ResourceModel/Slider.php b/Model/ResourceModel/Slider.php index 2379fcf..97390f4 100644 --- a/Model/ResourceModel/Slider.php +++ b/Model/ResourceModel/Slider.php @@ -22,21 +22,24 @@ namespace Mageplaza\BannerSlider\Model\ResourceModel; use Magento\Framework\Event\ManagerInterface; +use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Model\AbstractModel; +use Magento\Framework\Model\ResourceModel\Db\AbstractDb; use Magento\Framework\Model\ResourceModel\Db\Context; use Magento\Framework\Stdlib\DateTime\DateTime; use Mageplaza\BannerSlider\Helper\Data as bannerHelper; +use Zend_Serializer_Exception; /** * Class Slider * @package Mageplaza\BannerSlider\Model\ResourceModel */ -class Slider extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb +class Slider extends AbstractDb { /** * Date model * - * @var \Magento\Framework\Stdlib\DateTime\DateTime + * @var DateTime */ protected $date; @@ -50,7 +53,7 @@ class Slider extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb /** * Event Manager * - * @var \Magento\Framework\Event\ManagerInterface + * @var ManagerInterface */ protected $eventManager; @@ -72,9 +75,8 @@ public function __construct( ManagerInterface $eventManager, Context $context, bannerHelper $helperData - ) - { - $this->date = $date; + ) { + $this->date = $date; $this->eventManager = $eventManager; $this->bannerHelper = $helperData; @@ -98,15 +100,15 @@ protected function _construct() * @param $id * * @return string - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ public function getSliderNameById($id) { $adapter = $this->getConnection(); - $select = $adapter->select() + $select = $adapter->select() ->from($this->getMainTable(), 'name') ->where('slider_id = :slider_id'); - $binds = ['slider_id' => (int)$id]; + $binds = ['slider_id' => (int)$id]; return $adapter->fetchOne($select, $binds); } @@ -116,8 +118,8 @@ public function getSliderNameById($id) * * @param AbstractModel $object * - * @return \Magento\Framework\Model\ResourceModel\Db\AbstractDb - * @throws \Zend_Serializer_Exception + * @return AbstractDb + * @throws Zend_Serializer_Exception */ protected function _beforeSave(AbstractModel $object) { @@ -169,8 +171,8 @@ protected function _afterSave(AbstractModel $object) /** * @param AbstractModel $object * - * @return $this|\Magento\Framework\Model\ResourceModel\Db\AbstractDb - * @throws \Zend_Serializer_Exception + * @return $this|AbstractDb + * @throws Zend_Serializer_Exception */ protected function _afterLoad(AbstractModel $object) { @@ -199,7 +201,7 @@ public function getBannersPosition(\Mageplaza\BannerSlider\Model\Slider $slider) ->where( 'slider_id = :slider_id' ); - $bind = ['slider_id' => (int)$slider->getId()]; + $bind = ['slider_id' => (int)$slider->getId()]; return $this->getConnection()->fetchPairs($select, $bind); } @@ -212,22 +214,22 @@ public function getBannersPosition(\Mageplaza\BannerSlider\Model\Slider $slider) protected function saveBannerRelation(\Mageplaza\BannerSlider\Model\Slider $slider) { $slider->setIsChangedBannerList(false); - $id = $slider->getId(); + $id = $slider->getId(); $banners = $slider->getBannersData(); if ($banners === null) { return $this; } $oldBanners = $slider->getBannersPosition(); - $insert = array_diff_key($banners, $oldBanners); - $delete = array_diff_key($oldBanners, $banners); - $update = array_intersect_key($banners, $oldBanners); - $_update = []; + $insert = array_diff_key($banners, $oldBanners); + $delete = array_diff_key($oldBanners, $banners); + $update = array_intersect_key($banners, $oldBanners); + $_update = []; foreach ($update as $key => $settings) { if (isset($oldBanners[$key]) && $oldBanners[$key] != $settings['position']) { $_update[$key] = $settings; } } - $update = $_update; + $update = $_update; $adapter = $this->getConnection(); if (!empty($delete)) { $condition = ['banner_id IN(?)' => array_keys($delete), 'slider_id=?' => $id]; @@ -247,7 +249,7 @@ protected function saveBannerRelation(\Mageplaza\BannerSlider\Model\Slider $slid if (!empty($update)) { foreach ($update as $bannerId => $position) { $where = ['slider_id = ?' => (int)$id, 'banner_id = ?' => (int)$bannerId]; - $bind = ['position' => (int)$position['position']]; + $bind = ['position' => (int)$position['position']]; $adapter->update($this->sliderBannerTable, $bind, $where); } } diff --git a/Model/ResourceModel/Slider/Collection.php b/Model/ResourceModel/Slider/Collection.php index c58e466..1a09779 100644 --- a/Model/ResourceModel/Slider/Collection.php +++ b/Model/ResourceModel/Slider/Collection.php @@ -23,6 +23,7 @@ use Magento\Framework\DB\Select; use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; +use Zend_Db_Select; /** * Class Collection @@ -65,12 +66,12 @@ protected function _construct() * Get SQL for get record count. * Extra GROUP BY strip added. * - * @return \Magento\Framework\DB\Select + * @return Select */ public function getSelectCountSql() { $countSelect = parent::getSelectCountSql(); - $countSelect->reset(\Zend_Db_Select::GROUP); + $countSelect->reset(Zend_Db_Select::GROUP); return $countSelect; } @@ -102,9 +103,9 @@ public function addIdFilter($sliderIds) if (!empty($sliderIds)) { $condition = ['in' => $sliderIds]; } - } else if (is_numeric($sliderIds)) { + } elseif (is_numeric($sliderIds)) { $condition = $sliderIds; - } else if (is_string($sliderIds)) { + } elseif (is_string($sliderIds)) { $ids = explode(',', $sliderIds); if (empty($ids)) { $condition = $sliderIds; diff --git a/Model/Slider.php b/Model/Slider.php index 0c1323f..14a0494 100644 --- a/Model/Slider.php +++ b/Model/Slider.php @@ -22,9 +22,11 @@ namespace Mageplaza\BannerSlider\Model; use Magento\Framework\Data\Collection\AbstractDb; +use Magento\Framework\Model\AbstractModel; use Magento\Framework\Model\Context; use Magento\Framework\Model\ResourceModel\AbstractResource; use Magento\Framework\Registry; +use Mageplaza\BannerSlider\Model\ResourceModel\Banner\Collection; use Mageplaza\BannerSlider\Model\ResourceModel\Banner\CollectionFactory; /** @@ -36,18 +38,18 @@ * @method mixed getDescription() * @method mixed getStatus() * @method mixed getConfigSerialized() - * @method Slider setCreatedAt(\string $createdAt) + * @method Slider setCreatedAt(string $createdAt) * @method string getCreatedAt() - * @method Slider setUpdatedAt(\string $updatedAt) + * @method Slider setUpdatedAt(string $updatedAt) * @method string getUpdatedAt() * @method Slider setBannersData(array $data) * @method array getBannersData() - * @method Slider setIsChangedBannerList(\bool $flag) + * @method Slider setIsChangedBannerList(bool $flag) * @method bool getIsChangedBannerList() * @method Slider setAffectedBannerIds(array $ids) * @method bool getAffectedBannerIds() */ -class Slider extends \Magento\Framework\Model\AbstractModel +class Slider extends AbstractModel { /** * Cache tag @@ -73,25 +75,25 @@ class Slider extends \Magento\Framework\Model\AbstractModel /** * Banner Collection * - * @var \Mageplaza\BannerSlider\Model\ResourceModel\Banner\Collection + * @var Collection */ protected $bannerCollection; /** * Banner Collection Factory * - * @var \Mageplaza\BannerSlider\Model\ResourceModel\Banner\CollectionFactory + * @var CollectionFactory */ protected $bannerCollectionFactory; /** * constructor * - * @param \Mageplaza\BannerSlider\Model\ResourceModel\Banner\CollectionFactory $bannerCollectionFactory - * @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 CollectionFactory $bannerCollectionFactory + * @param Context $context + * @param Registry $registry + * @param AbstractResource $resource + * @param AbstractDb $resourceCollection * @param array $data */ public function __construct( @@ -101,8 +103,7 @@ public function __construct( AbstractResource $resource = null, AbstractDb $resourceCollection = null, array $data = [] - ) - { + ) { $this->bannerCollectionFactory = $bannerCollectionFactory; parent::__construct($context, $registry, $resource, $resourceCollection, $data); @@ -135,7 +136,7 @@ public function getIdentities() */ public function getDefaultValues() { - $values = []; + $values = []; $values['status'] = '1'; return $values; @@ -160,7 +161,7 @@ public function getBannersPosition() } /** - * @return \Mageplaza\BannerSlider\Model\ResourceModel\Banner\Collection + * @return Collection */ public function getSelectedBannersCollection() { diff --git a/Observer/AddBlock.php b/Observer/AddBlock.php index 8183d33..0cebd2b 100644 --- a/Observer/AddBlock.php +++ b/Observer/AddBlock.php @@ -24,6 +24,8 @@ use Magento\Framework\App\RequestInterface; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; +use Magento\Framework\View\Layout; +use Mageplaza\BannerSlider\Block\Slider; use Mageplaza\BannerSlider\Helper\Data; /** @@ -38,7 +40,7 @@ class AddBlock implements ObserverInterface protected $request; /** - * @var \Mageplaza\BannerSlider\Helper\Data + * @var Data */ protected $helperData; @@ -51,9 +53,8 @@ class AddBlock implements ObserverInterface public function __construct( RequestInterface $request, Data $helperData - ) - { - $this->request = $request; + ) { + $this->request = $request; $this->helperData = $helperData; } @@ -77,10 +78,10 @@ public function execute(Observer $observer) ]); if ($type !== false) { - /** @var \Magento\Framework\View\Layout $layout */ - $layout = $observer->getEvent()->getLayout(); + /** @var Layout $layout */ + $layout = $observer->getEvent()->getLayout(); $fullActionName = $this->request->getFullActionName(); - $output = $observer->getTransport()->getOutput(); + $output = $observer->getTransport()->getOutput(); foreach ($this->helperData->getActiveSliders() as $slider) { $locations = explode(",", $slider->getLocation()); @@ -89,7 +90,7 @@ public function execute(Observer $observer) if (($fullActionName == $pageType || $pageType == 'allpage') && strpos($location, $type) !== false ) { - $content = $layout->createBlock(\Mageplaza\BannerSlider\Block\Slider::class) + $content = $layout->createBlock(Slider::class) ->setSlider($slider) ->toHtml(); diff --git a/Setup/InstallSchema.php b/Setup/InstallSchema.php index 9ccdcb7..bb8d9b5 100644 --- a/Setup/InstallSchema.php +++ b/Setup/InstallSchema.php @@ -21,6 +21,7 @@ namespace Mageplaza\BannerSlider\Setup; +use Exception; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\DB\Ddl\Table; @@ -30,6 +31,7 @@ use Magento\Framework\Setup\SchemaSetupInterface; use Mageplaza\BannerSlider\Model\Config\Source\Template; use Psr\Log\LoggerInterface; +use Zend_Db_Exception; /** * Class InstallSchema @@ -63,10 +65,9 @@ public function __construct( Template $template, Filesystem $filesystem, LoggerInterface $logger - ) - { - $this->logger = $logger; - $this->template = $template; + ) { + $this->logger = $logger; + $this->template = $template; $this->fileSystem = $filesystem; } @@ -76,7 +77,7 @@ public function __construct( * @param SchemaSetupInterface $setup * @param ModuleContextInterface $context * - * @throws \Zend_Db_Exception + * @throws Zend_Db_Exception */ public function install(SchemaSetupInterface $setup, ModuleContextInterface $context) { @@ -85,13 +86,18 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con if (!$installer->tableExists('mageplaza_bannerslider_banner')) { $table = $installer->getConnection() ->newTable($installer->getTable('mageplaza_bannerslider_banner')) - ->addColumn('banner_id', Table::TYPE_INTEGER, null, + ->addColumn( + 'banner_id', + Table::TYPE_INTEGER, + null, [ 'identity' => true, 'nullable' => false, 'primary' => true, 'unsigned' => true - ], 'Banner ID') + ], + 'Banner ID' + ) ->addColumn('name', Table::TYPE_TEXT, 255, ['nullable => false'], 'Banner Name') ->addColumn('status', Table::TYPE_SMALLINT, null, ['nullable' => false, 'default' => '1'], 'Banner Status') ->addColumn('type', Table::TYPE_SMALLINT, null, ['nullable' => false, 'default' => '0'], 'Banner Type') @@ -119,13 +125,18 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con if (!$installer->tableExists('mageplaza_bannerslider_slider')) { $table = $installer->getConnection() ->newTable($installer->getTable('mageplaza_bannerslider_slider')) - ->addColumn('slider_id', Table::TYPE_INTEGER, null, + ->addColumn( + 'slider_id', + Table::TYPE_INTEGER, + null, [ 'identity' => true, 'nullable' => false, 'primary' => true, 'unsigned' => true - ], 'Slider ID') + ], + 'Slider ID' + ) ->addColumn('name', Table::TYPE_TEXT, 255, ['nullable => false'], 'Slider Name') ->addColumn('status', Table::TYPE_SMALLINT, null, ['nullable' => false, 'default' => '1'], 'Slider Status') ->addColumn('location', Table::TYPE_TEXT, 1000, [], 'Location') @@ -219,16 +230,16 @@ private function copyDemoImage() { try { $mediaDirectory = $this->fileSystem->getDirectoryWrite(DirectoryList::MEDIA); - $url = 'mageplaza/bannerslider/banner/demo/'; + $url = 'mageplaza/bannerslider/banner/demo/'; $mediaDirectory->create($url); $demos = $this->template->toOptionArray(); foreach ($demos as $demo) { $targetPath = $mediaDirectory->getAbsolutePath($url . $demo['value']); - $DS = DIRECTORY_SEPARATOR; - $oriPath = dirname(__DIR__) . $DS . 'view' . $DS . 'adminhtml' . $DS . 'web' . $DS . 'images' . $DS . $demo['value']; + $DS = DIRECTORY_SEPARATOR; + $oriPath = dirname(__DIR__) . $DS . 'view' . $DS . 'adminhtml' . $DS . 'web' . $DS . 'images' . $DS . $demo['value']; $mediaDirectory->getDriver()->copy($oriPath, $targetPath); } - } catch (\Exception $e) { + } catch (Exception $e) { $this->logger->critical($e->getMessage()); } } diff --git a/Ui/Component/Listing/Column/BannerActions.php b/Ui/Component/Listing/Column/BannerActions.php index cf1f83d..2d1e671 100644 --- a/Ui/Component/Listing/Column/BannerActions.php +++ b/Ui/Component/Listing/Column/BannerActions.php @@ -42,16 +42,16 @@ class BannerActions extends Column /** * URL builder * - * @var \Magento\Framework\UrlInterface + * @var UrlInterface */ protected $urlBuilder; /** * constructor * - * @param \Magento\Framework\UrlInterface $urlBuilder - * @param \Magento\Framework\View\Element\UiComponent\ContextInterface $context - * @param \Magento\Framework\View\Element\UiComponentFactory $uiComponentFactory + * @param UrlInterface $urlBuilder + * @param ContextInterface $context + * @param UiComponentFactory $uiComponentFactory * @param array $components * @param array $data */ @@ -61,8 +61,7 @@ public function __construct( UiComponentFactory $uiComponentFactory, array $components = [], array $data = [] - ) - { + ) { $this->urlBuilder = $urlBuilder; parent::__construct($context, $uiComponentFactory, $components, $data); diff --git a/Ui/Component/Listing/Column/Banners.php b/Ui/Component/Listing/Column/Banners.php index 5c53175..8adcbc4 100644 --- a/Ui/Component/Listing/Column/Banners.php +++ b/Ui/Component/Listing/Column/Banners.php @@ -51,8 +51,7 @@ public function __construct( bannerHelper $helperData, array $components = [], array $data = [] - ) - { + ) { $this->helperData = $helperData; parent::__construct($context, $uiComponentFactory, $components, $data); @@ -70,8 +69,8 @@ public function prepareDataSource(array $dataSource) if (isset($dataSource['data']['items'])) { foreach ($dataSource['data']['items'] as & $item) { if (isset($item['slider_id'])) { - $id = $item['slider_id']; - $data = $this->helperData->getBannerCollection($id)->getSize(); + $id = $item['slider_id']; + $data = $this->helperData->getBannerCollection($id)->getSize(); $item[$this->getData('name')] = ($data > 0) ? $data . ' banners ' : '' . __("No banner added") . ''; } } @@ -79,4 +78,4 @@ public function prepareDataSource(array $dataSource) return $dataSource; } -} \ No newline at end of file +} diff --git a/Ui/Component/Listing/Column/CustomerGroup.php b/Ui/Component/Listing/Column/CustomerGroup.php index 6d0d0be..98ba6ff 100644 --- a/Ui/Component/Listing/Column/CustomerGroup.php +++ b/Ui/Component/Listing/Column/CustomerGroup.php @@ -52,8 +52,7 @@ public function __construct( GroupCollection $GroupCollection, array $components = [], array $data = [] - ) - { + ) { $this->customerGroup = $GroupCollection; parent::__construct($context, $uiComponentFactory, $components, $data); @@ -87,7 +86,7 @@ public function prepareDataSource(array $dataSource) */ public function prepareItem(array $item) { - $content = []; + $content = []; $origGroup = $item['customer_group_ids']; if (!is_array($origGroup)) { @@ -101,4 +100,4 @@ public function prepareItem(array $item) return implode(", ", $content); } -} \ No newline at end of file +} diff --git a/Ui/Component/Listing/Column/SliderActions.php b/Ui/Component/Listing/Column/SliderActions.php index dbad7d1..c9358bc 100644 --- a/Ui/Component/Listing/Column/SliderActions.php +++ b/Ui/Component/Listing/Column/SliderActions.php @@ -42,16 +42,16 @@ class SliderActions extends Column /** * URL builder * - * @var \Magento\Framework\UrlInterface + * @var UrlInterface */ protected $urlBuilder; /** * constructor * - * @param \Magento\Framework\UrlInterface $urlBuilder - * @param \Magento\Framework\View\Element\UiComponent\ContextInterface $context - * @param \Magento\Framework\View\Element\UiComponentFactory $uiComponentFactory + * @param UrlInterface $urlBuilder + * @param ContextInterface $context + * @param UiComponentFactory $uiComponentFactory * @param array $components * @param array $data */ @@ -61,8 +61,7 @@ public function __construct( UiComponentFactory $uiComponentFactory, array $components = [], array $data = [] - ) - { + ) { $this->urlBuilder = $urlBuilder; parent::__construct($context, $uiComponentFactory, $components, $data); diff --git a/Ui/Component/Listing/Column/SliderLocation.php b/Ui/Component/Listing/Column/SliderLocation.php index b417ee1..14d0e28 100644 --- a/Ui/Component/Listing/Column/SliderLocation.php +++ b/Ui/Component/Listing/Column/SliderLocation.php @@ -42,8 +42,8 @@ public function prepareDataSource(array $dataSource) if (isset($dataSource['data']['items'])) { foreach ($dataSource['data']['items'] as & $item) { if (isset($item[$this->getData('name')])) { - $data = $this->getLocation($item[$this->getData('name')]); - $type = array_unique($data['type']); + $data = $this->getLocation($item[$this->getData('name')]); + $type = array_unique($data['type']); $item[$this->getData('name')] = '' . implode(', ', $type) . '
'; } } @@ -60,61 +60,61 @@ public function prepareDataSource(array $dataSource) public function getLocation($data) { $location = []; - $data = explode(',', $data); + $data = explode(',', $data); foreach ($data as $item) { switch ($item) { - case Location::ALLPAGE_CONTENT_TOP : + case Location::ALLPAGE_CONTENT_TOP: $location['type'][] = __('All Page'); break; - case Location::ALLPAGE_CONTENT_BOTTOM : + case Location::ALLPAGE_CONTENT_BOTTOM: $location['type'][] = __('All Page'); break; - case Location::ALLPAGE_PAGE_TOP : + case Location::ALLPAGE_PAGE_TOP: $location['type'][] = __('All Page'); break; - case Location::ALLPAGE_PAGE_BOTTOM : + case Location::ALLPAGE_PAGE_BOTTOM: $location['type'][] = __('All Page'); break; - case Location::HOMEPAGE_CONTENT_TOP : + case Location::HOMEPAGE_CONTENT_TOP: $location['type'][] = __('Home Page'); break; - case Location::HOMEPAGE_CONTENT_BOTTOM : + case Location::HOMEPAGE_CONTENT_BOTTOM: $location['type'][] = __('Home Page'); break; - case Location::HOMEPAGE_PAGE_TOP : + case Location::HOMEPAGE_PAGE_TOP: $location['type'][] = __('Home Page'); break; - case Location::HOMEPAGE_PAGE_BOTTOM : + case Location::HOMEPAGE_PAGE_BOTTOM: $location['type'][] = __('Home Page'); break; - case Location::CATEGORY_CONTENT_TOP : + case Location::CATEGORY_CONTENT_TOP: $location['type'][] = __('Category Page'); break; - case Location::CATEGORY_CONTENT_BOTTOM : + case Location::CATEGORY_CONTENT_BOTTOM: $location['type'][] = __('Category Page'); break; - case Location::CATEGORY_PAGE_TOP : + case Location::CATEGORY_PAGE_TOP: $location['type'][] = __('Category Page'); break; - case Location::CATEGORY_PAGE_BOTTOM : + case Location::CATEGORY_PAGE_BOTTOM: $location['type'][] = __('Category Page'); break; - case Location::CATEGORY_SIDEBAR_TOP : + case Location::CATEGORY_SIDEBAR_TOP: $location['type'][] = __('Category Page'); break; - case Location::CATEGORY_SIDEBAR_BOTTOM : + case Location::CATEGORY_SIDEBAR_BOTTOM: $location['type'][] = __('Category Page'); break; - case Location::PRODUCT_CONTENT_TOP : + case Location::PRODUCT_CONTENT_TOP: $location['type'][] = __('Product Page'); break; - case Location::PRODUCT_CONTENT_BOTTOM : + case Location::PRODUCT_CONTENT_BOTTOM: $location['type'][] = __('Product Page'); break; - case Location::PRODUCT_PAGE_TOP : + case Location::PRODUCT_PAGE_TOP: $location['type'][] = __('Product Page'); break; - case Location::PRODUCT_PAGE_BOTTOM : + case Location::PRODUCT_PAGE_BOTTOM: $location['type'][] = __('Product Page'); break; } diff --git a/Ui/Component/Listing/Column/Store.php b/Ui/Component/Listing/Column/Store.php index 5baa077..584e8fd 100644 --- a/Ui/Component/Listing/Column/Store.php +++ b/Ui/Component/Listing/Column/Store.php @@ -21,6 +21,7 @@ namespace Mageplaza\BannerSlider\Ui\Component\Listing\Column; +use Magento\Framework\App\ObjectManager; use Magento\Framework\Escaper; use Magento\Framework\View\Element\UiComponent\ContextInterface; use Magento\Framework\View\Element\UiComponentFactory; @@ -37,7 +38,7 @@ class Store extends Column /** * Escaper * - * @var \Magento\Framework\Escaper + * @var Escaper */ protected $escaper; @@ -77,11 +78,10 @@ public function __construct( array $components = [], array $data = [], $storeKey = 'store_ids' - ) - { + ) { $this->systemStore = $systemStore; - $this->escaper = $escaper; - $this->storeKey = $storeKey; + $this->escaper = $escaper; + $this->storeKey = $storeKey; parent::__construct($context, $uiComponentFactory, $components, $data); } @@ -114,7 +114,7 @@ public function prepareDataSource(array $dataSource) */ protected function prepareItem(array $item) { - $content = ''; + $content = ''; $origStores = $item[$this->storeKey]; if (!is_array($origStores)) { $origStores = [$origStores]; @@ -160,7 +160,7 @@ public function prepare() private function getStoreManager() { if ($this->storeManager === null) { - $this->storeManager = \Magento\Framework\App\ObjectManager::getInstance() + $this->storeManager = ObjectManager::getInstance() ->get('Magento\Store\Model\StoreManagerInterface'); } diff --git a/Ui/Component/Listing/Column/Thumbnail.php b/Ui/Component/Listing/Column/Thumbnail.php index d1f6006..b90d520 100644 --- a/Ui/Component/Listing/Column/Thumbnail.php +++ b/Ui/Component/Listing/Column/Thumbnail.php @@ -21,11 +21,13 @@ namespace Mageplaza\BannerSlider\Ui\Component\Listing\Column; +use Magento\Framework\DataObject; use Magento\Framework\UrlInterface; use Magento\Framework\View\Element\UiComponent\ContextInterface; use Magento\Framework\View\Element\UiComponentFactory; use Magento\Ui\Component\Listing\Columns\Column; use Mageplaza\BannerSlider\Model\Config\Source\Image; +use Mageplaza\BannerSlider\Model\Config\Source\Type; /** * Class Thumbnail @@ -60,8 +62,7 @@ public function __construct( UrlInterface $urlBuilder, array $components = [], array $data = [] - ) - { + ) { $this->imageModel = $imageModel; $this->urlBuilder = $urlBuilder; @@ -79,10 +80,10 @@ public function prepareDataSource(array $dataSource) { if (isset($dataSource['data']['items'])) { $fieldName = $this->getData('name'); - $path = $this->imageModel->getBaseUrl(); + $path = $this->imageModel->getBaseUrl(); foreach ($dataSource['data']['items'] as & $item) { - $banner = new \Magento\Framework\DataObject($item); - if ($item['type'] == \Mageplaza\BannerSlider\Model\Config\Source\Type::IMAGE && $item['image']) { + $banner = new DataObject($item); + if ($item['type'] == Type::IMAGE && $item['image']) { $item[$fieldName . '_src'] = $path . $item['image']; } diff --git a/composer.json b/composer.json index 10dc9aa..3cb6a1b 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "mageplaza/module-core": "^1.4.0" }, "type": "magento2-module", - "version": "2.0.1", + "version": "2.0.2", "license": "proprietary", "authors": [ { diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 146ed51..43d9c06 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -50,49 +50,49 @@ 1 - + Magento\Config\Model\Config\Source\Yesno validate-digits Select Yes to use auto-width - + Magento\Config\Model\Config\Source\Yesno validate-digits Select Yes to use auto-height - + Magento\Config\Model\Config\Source\Yesno validate-digits Select Yes to re-display the slider after it shows the last item - + Magento\Config\Model\Config\Source\Yesno validate-digits Select Yes to display the Next/Pre buttons in the slider - + Magento\Config\Model\Config\Source\Yesno validate-digits Select Yes to display dots navigation of the slider - + Magento\Config\Model\Config\Source\Yesno validate-digits Select Yes to lazy loading images - + Magento\Config\Model\Config\Source\Yesno validate-digits Select Yes to allow auto-displaying the next products - + Magento\Config\Model\Config\Source\Yesno validate-digits diff --git a/i18n/en_US.csv b/i18n/en_US.csv index fcc65a7..e291e8d 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -109,6 +109,14 @@ Enable,Enable "Select Yes to enable this module","Select Yes to enable this module" "Slider Design Configuration","Slider Design Configuration" Responsive,Responsive +"Select Yes to use auto-width","Select Yes to use auto-width" +"Select Yes to use auto-height","Select Yes to use auto-height" +"Select Yes to re-display the slider after it shows the last item","Select Yes to re-display the slider after it shows the last item" +"Select Yes to display the Next/Pre buttons in the slider","Select Yes to display the Next/Pre buttons in the slider" +"Select Yes to display dots navigation of the slider","Select Yes to display dots navigation of the slider" +"Select Yes to lazy loading images","Select Yes to lazy loading images" +"Select Yes to allow auto-displaying the next products","Select Yes to allow auto-displaying the next products" +"The time (ms) in which an item is auto-moved to the left","The time (ms) in which an item is auto-moved to the left" "Mageplaza Banner Slider","Mageplaza Banner Slider" "Banner Slider list","Banner Slider list" "Select Slider","Select Slider" diff --git a/registration.php b/registration.php index fd005b6..8f5a02a 100644 --- a/registration.php +++ b/registration.php @@ -19,8 +19,10 @@ * @license https://www.mageplaza.com/LICENSE.txt */ -\Magento\Framework\Component\ComponentRegistrar::register( - \Magento\Framework\Component\ComponentRegistrar::MODULE, +use Magento\Framework\Component\ComponentRegistrar; + +ComponentRegistrar::register( + ComponentRegistrar::MODULE, 'Mageplaza_BannerSlider', __DIR__ ); diff --git a/view/adminhtml/templates/widget/form.phtml b/view/adminhtml/templates/widget/form.phtml index ca6b779..3d484d6 100644 --- a/view/adminhtml/templates/widget/form.phtml +++ b/view/adminhtml/templates/widget/form.phtml @@ -22,17 +22,18 @@ /** @var $block \Mageplaza\BannerSlider\Block\Adminhtml\Banner\Edit\Form */ ?>
- getFormHtml(); ?> + getFormHtml(); ?>
-getChildHtml('form_after'); ?> +getChildHtml('form_after'); ?> diff --git a/view/frontend/templates/bannerslider.phtml b/view/frontend/templates/bannerslider.phtml index 6c4d453..be667fb 100644 --- a/view/frontend/templates/bannerslider.phtml +++ b/view/frontend/templates/bannerslider.phtml @@ -19,54 +19,56 @@ * @license https://www.mageplaza.com/LICENSE.txt */ -$banners = $block->getBannerCollection(); -$sliderId = $block->getSliderId() . '-' . uniqid(); +use Mageplaza\BannerSlider\Model\Config\Source\Type; + +$banners = $block->getBannerCollection(); +$sliderId = $block->getSliderId() . uniqid('-', false); $sliderOptions = $block->getBannerOptions(); -if (count($banners)): ?> +if (count($banners)) : ?>