Skip to content

Commit

Permalink
Merge pull request #93 from mageplaza/2.4-develop
Browse files Browse the repository at this point in the history
2.4 develop
  • Loading branch information
HuyPhuc98 committed May 31, 2023
2 parents 160753a + 7ee2dbc commit 21e1d42
Show file tree
Hide file tree
Showing 13 changed files with 380 additions and 192 deletions.
14 changes: 13 additions & 1 deletion Block/Adminhtml/Banner/Edit/Tab/Render/GridImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@

use Magento\Backend\Block\Context;
use Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer;
use Magento\Cms\Model\Template\FilterProvider;
use Magento\Framework\DataObject;
use Mageplaza\BannerSlider\Model\Config\Source\Image as ImageModel;
use Mageplaza\BannerSlider\Model\Config\Source\Type;

/**
* Class GridImage
Expand All @@ -37,19 +39,27 @@ class GridImage extends AbstractRenderer
*/
protected $imageModel;

/**
* @var FilterProvider
*/
protected $filterProvider;

/**
* GridImage constructor.
*
* @param Context $context
* @param ImageModel $imageModel
* @param FilterProvider $filterProvider
* @param array $data
*/
public function __construct(
Context $context,
ImageModel $imageModel,
FilterProvider $filterProvider,
array $data = []
) {
$this->imageModel = $imageModel;
$this->imageModel = $imageModel;
$this->filterProvider = $filterProvider;

parent::__construct($context, $data);
}
Expand All @@ -67,6 +77,8 @@ public function render(DataObject $row)
$imageUrl = $this->imageModel->getBaseUrl() . $row->getData($this->getColumn()->getIndex());

return '<img src="' . $imageUrl . '" width=\'150\' class="admin__control-thumbnail"/>';
} elseif ($row->getType() === Type::CONTENT) {
return $this->filterProvider->getPageFilter()->filter($row->getContent());
}

return '';
Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/Slider/Edit/Tab/Banner.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ protected function _prepareColumns()
'align' => 'center',
'index' => 'banner_id'
]);
$this->addColumn('banner_id', [
$this->addColumn('banner_ids', [
'header' => __('ID'),
'sortable' => true,
'index' => 'banner_id',
Expand Down
5 changes: 4 additions & 1 deletion Block/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
use Magento\Widget\Block\BlockInterface;
use Mageplaza\BannerSlider\Model\Config\Source\Location;

/**
* Class Widget
Expand All @@ -43,7 +44,9 @@ public function getBannerCollection()
}

$sliderCollection = $this->helperData->getActiveSliders();
$slider = $sliderCollection->addFieldToFilter('slider_id', $sliderId)->getFirstItem();
$slider = $sliderCollection->addFieldToFilter('slider_id', $sliderId)
->addFieldToFilter('location', ['finset' => Location::USING_SNIPPET_CODE])->getFirstItem();

$this->setSlider($slider);

return parent::getBannerCollection();
Expand Down
4 changes: 2 additions & 2 deletions Controller/Adminhtml/Slider/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
use Mageplaza\BannerSlider\Controller\Adminhtml\Slider;
use Mageplaza\BannerSlider\Model\SliderFactory;
use RuntimeException;
use Zend_Filter_Input;
use Magento\Framework\Filter\FilterInput;

/**
* Class Save
Expand Down Expand Up @@ -188,7 +188,7 @@ public function execute()
*/
protected function _filterData($data)
{
$inputFilter = new Zend_Filter_Input(['from_date' => $this->_dateFilter,], [], $data);
$inputFilter = new FilterInput(['from_date' => $this->_dateFilter,], [], $data);
$data = $inputFilter->getUnescaped();

if (isset($data['responsive_items'])) {
Expand Down
3 changes: 1 addition & 2 deletions Model/ResourceModel/Banner/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

use Magento\Framework\DB\Select;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
use Zend_Db_Select;

/**
* Class Collection
Expand Down Expand Up @@ -71,7 +70,7 @@ protected function _construct()
public function getSelectCountSql()
{
$countSelect = parent::getSelectCountSql();
$countSelect->reset(Zend_Db_Select::GROUP);
$countSelect->reset(Select::GROUP);

return $countSelect;
}
Expand Down
3 changes: 1 addition & 2 deletions Model/ResourceModel/Slider/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

use Magento\Framework\DB\Select;
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
use Zend_Db_Select;

/**
* Class Collection
Expand Down Expand Up @@ -71,7 +70,7 @@ protected function _construct()
public function getSelectCountSql()
{
$countSelect = parent::getSelectCountSql();
$countSelect->reset(Zend_Db_Select::GROUP);
$countSelect->reset(Select::GROUP);

return $countSelect;
}
Expand Down
101 changes: 101 additions & 0 deletions Model/ResourceModel/Slider/Grid/Collection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_BannerSlider
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\BannerSlider\Model\ResourceModel\Slider\Grid;

use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
use Magento\Framework\Data\Collection\EntityFactoryInterface;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult;
use Mageplaza\BannerSlider\Model\ResourceModel\Slider;
use Psr\Log\LoggerInterface;

/**
* Class Collection
* @package Mageplaza\BannerSlider\Model\ResourceModel\Slider\Grid
*/
class Collection extends SearchResult
{
/**
* ID Field Name
*
* @var string
*/
protected $_idFieldName = 'slider_id';

/**
* Event prefix
*
* @var string
*/
protected $_eventPrefix = 'mageplaza_bannerslider_slider_collection';

/**
* Event object
*
* @var string
*/
protected $_eventObject = 'slider_collection';

/**
* Collection constructor.
*
* @param EntityFactoryInterface $entityFactory
* @param LoggerInterface $logger
* @param FetchStrategyInterface $fetchStrategy
* @param ManagerInterface $eventManager
* @param string $mainTable
* @param string $resourceModel
*
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function __construct(
EntityFactoryInterface $entityFactory,
LoggerInterface $logger,
FetchStrategyInterface $fetchStrategy,
ManagerInterface $eventManager,
$mainTable = 'mageplaza_bannerslider_slider',
$resourceModel = Slider::class
) {
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $mainTable, $resourceModel);
}

/**
* @param array|string $field
* @param null $condition
*
* @return Collection
*/
public function addFieldToFilter($field, $condition = null)
{
switch ($field) {
case 'banners':
$field = 'main_table.name';
break;
case 'customer_group_ids':
return parent::addFieldToFilter('customer_group_ids', ['finset' => $condition['eq']]);
case 'store_ids':
return parent::addFieldToFilter('store_ids', [['finset' => $condition['eq']], ['finset' => 0]]);
}

return parent::addFieldToFilter($field, $condition);
}
}
2 changes: 1 addition & 1 deletion Observer/AddBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function execute(Observer $observer)
$output = $observer->getTransport()->getOutput();

foreach ($this->helperData->getActiveSliders() as $slider) {
$locations = array_filter(explode(',', $slider->getLocation()));
$locations = array_filter(explode(',', $slider->getLocation() ?: ''));
foreach ($locations as $value) {
if ($value === Location::USING_SNIPPET_CODE) {
continue;
Expand Down
80 changes: 80 additions & 0 deletions Ui/Component/Listing/Column/CustomerGroup/Options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_BannerSlider
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\BannerSlider\Ui\Component\Listing\Column\CustomerGroup;

use Magento\Customer\Model\ResourceModel\Group\Collection;
use Magento\Customer\Model\ResourceModel\Group\CollectionFactory;
use Magento\Framework\Data\OptionSourceInterface;

/**
* Class Options
* @package Mageplaza\BannerSlider\Ui\Component\Listing\Column\CustomerGroup
*/
class Options implements OptionSourceInterface
{
/**
* @var CollectionFactory
*/
protected $_customerGroupColFact;

/**
* Options constructor.
*
* @param CollectionFactory $customerGroupColFact
*/
public function __construct(CollectionFactory $customerGroupColFact)
{
$this->_customerGroupColFact = $customerGroupColFact;
}

/**
* Get options
*
* @return array
*/
public function toOptionArray()
{
return $this->_generateCustomerGroupOptions();
}

/**
* Get customer group options
*
* @return array
*/
protected function _generateCustomerGroupOptions()
{
$options = [];
$customerGroupCollection = $this->_customerGroupColFact->create();

if (count($customerGroupCollection)) {
foreach ($customerGroupCollection as $item) {
$options[] = [
'label' => $item->getCustomerGroupCode(),
'value' => $item->getCustomerGroupId(),
];
}
}

return $options;
}
}
36 changes: 4 additions & 32 deletions Ui/Component/Listing/Column/SliderLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')] = '<b>' . implode(', ', $type) . '</b></br>';
}
}
Expand All @@ -60,60 +60,32 @@ 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:
$location['type'][] = __('All Page');
break;
case Location::ALLPAGE_CONTENT_BOTTOM:
$location['type'][] = __('All Page');
break;
case Location::ALLPAGE_PAGE_TOP:
$location['type'][] = __('All Page');
break;
case Location::ALLPAGE_PAGE_BOTTOM:
case Location::ALLPAGE_CONTENT_TOP:
$location['type'][] = __('All Page');
break;
case Location::HOMEPAGE_CONTENT_TOP:
$location['type'][] = __('Home Page');
break;
case Location::HOMEPAGE_CONTENT_BOTTOM:
$location['type'][] = __('Home Page');
break;
case Location::HOMEPAGE_PAGE_TOP:
$location['type'][] = __('Home Page');
break;
case Location::HOMEPAGE_PAGE_BOTTOM:
$location['type'][] = __('Home Page');
break;
case Location::CATEGORY_CONTENT_TOP:
$location['type'][] = __('Category Page');
break;
case Location::CATEGORY_CONTENT_BOTTOM:
$location['type'][] = __('Category Page');
break;
case Location::CATEGORY_PAGE_TOP:
$location['type'][] = __('Category Page');
break;
case Location::CATEGORY_PAGE_BOTTOM:
$location['type'][] = __('Category Page');
break;
case Location::CATEGORY_SIDEBAR_TOP:
$location['type'][] = __('Category Page');
break;
case Location::CATEGORY_SIDEBAR_BOTTOM:
$location['type'][] = __('Category Page');
break;
case Location::PRODUCT_CONTENT_TOP:
$location['type'][] = __('Product Page');
break;
case Location::PRODUCT_CONTENT_BOTTOM:
$location['type'][] = __('Product Page');
break;
case Location::PRODUCT_PAGE_TOP:
$location['type'][] = __('Product Page');
break;
case Location::PRODUCT_PAGE_BOTTOM:
$location['type'][] = __('Product Page');
break;
Expand Down
Loading

0 comments on commit 21e1d42

Please sign in to comment.