Initial commit: is_imageslider out of the box. v2.3.2
This commit is contained in:
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Oksydan\IsImageslider\Grid\Data\Factory;
|
||||
|
||||
use Oksydan\IsImageslider\Provider\ImageProviderInterface;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Data\Factory\GridDataFactoryInterface;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Data\GridData;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Record\RecordCollection;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Search\SearchCriteriaInterface;
|
||||
|
||||
final class ImageSliderGridDataFactory implements GridDataFactoryInterface
|
||||
{
|
||||
/**
|
||||
* @var GridDataFactoryInterface
|
||||
*/
|
||||
private $doctrineImageSliderDataFactory;
|
||||
|
||||
/**
|
||||
* @var ImageProviderInterface
|
||||
*/
|
||||
private $imagesliderImageThumbProvider;
|
||||
|
||||
/**
|
||||
* @param GridDataFactoryInterface $doctrineImageSliderDataFactory
|
||||
* @param ImageProviderInterface $imagesliderImageThumbProvider
|
||||
*/
|
||||
public function __construct(
|
||||
GridDataFactoryInterface $doctrineImageSliderDataFactory,
|
||||
ImageProviderInterface $imagesliderImageThumbProvider
|
||||
) {
|
||||
$this->doctrineImageSliderDataFactory = $doctrineImageSliderDataFactory;
|
||||
$this->imagesliderImageThumbProvider = $imagesliderImageThumbProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData(SearchCriteriaInterface $searchCriteria)
|
||||
{
|
||||
$languageData = $this->doctrineImageSliderDataFactory->getData($searchCriteria);
|
||||
|
||||
$modifiedRecords = $this->applyModification(
|
||||
$languageData->getRecords()->all()
|
||||
);
|
||||
|
||||
return new GridData(
|
||||
new RecordCollection($modifiedRecords),
|
||||
$languageData->getRecordsTotal(),
|
||||
$languageData->getQuery()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $sliders
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function applyModification(array $sliders)
|
||||
{
|
||||
foreach ($sliders as $i => $slider) {
|
||||
$sliders[$i]['image'] = $this->imagesliderImageThumbProvider->getPath($slider['image']);
|
||||
}
|
||||
|
||||
return $sliders;
|
||||
}
|
||||
}
|
||||
11
is_imageslider/src/Grid/Data/Factory/index.php
Normal file
11
is_imageslider/src/Grid/Data/Factory/index.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
11
is_imageslider/src/Grid/Data/index.php
Normal file
11
is_imageslider/src/Grid/Data/index.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Oksydan\IsImageslider\Grid\Definition\Factory;
|
||||
|
||||
use Oksydan\IsImageslider\Translations\TranslationDomains;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Action\Bulk\BulkActionCollection;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Action\GridActionCollection;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Action\Row\RowActionCollection;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Action\Row\Type\LinkRowAction;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Column\ColumnCollection;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\ActionColumn;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\ImageColumn;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\PositionColumn;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\ToggleColumn;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Column\Type\DataColumn;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Filter\FilterCollection;
|
||||
|
||||
class ImageSliderGridDefinitionFactory extends AbstractGridDefinitionFactory
|
||||
{
|
||||
public const GRID_ID = 'is_imageslider';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getId()
|
||||
{
|
||||
return self::GRID_ID;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getName()
|
||||
{
|
||||
return $this->trans('Image slider', [], TranslationDomains::TRANSLATION_DOMAIN_ADMIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getColumns()
|
||||
{
|
||||
return (new ColumnCollection())
|
||||
->add(
|
||||
(new PositionColumn('position'))
|
||||
->setName($this->trans('Position', [], 'Admin.Global'))
|
||||
->setOptions([
|
||||
'id_field' => 'id_slide',
|
||||
'position_field' => 'position',
|
||||
'update_route' => 'is_imageslider_controller_update_positions',
|
||||
'update_method' => 'POST',
|
||||
])
|
||||
)
|
||||
->add(
|
||||
(new ImageColumn('image'))
|
||||
->setName($this->trans('Image', [], 'Admin.Global'))
|
||||
->setOptions([
|
||||
'src_field' => 'image',
|
||||
])
|
||||
)
|
||||
->add(
|
||||
(new DataColumn('title'))
|
||||
->setName($this->trans('Title', [], 'Admin.Global'))
|
||||
->setOptions([
|
||||
'field' => 'title',
|
||||
])
|
||||
)
|
||||
->add(
|
||||
(new DataColumn('id_slide'))
|
||||
->setName($this->trans('ID', [], 'Admin.Global'))
|
||||
->setOptions([
|
||||
'field' => 'id_slide',
|
||||
])
|
||||
)
|
||||
->add(
|
||||
(new DataColumn('title'))
|
||||
->setName($this->trans('Title', [], 'Admin.Global'))
|
||||
->setOptions([
|
||||
'field' => 'title',
|
||||
])
|
||||
)
|
||||
->add(
|
||||
(new ToggleColumn('active'))
|
||||
->setName($this->trans('Displayed', [], 'Admin.Global'))
|
||||
->setOptions([
|
||||
'field' => 'active',
|
||||
'primary_field' => 'id_slide',
|
||||
'route' => 'is_imageslider_controller_toggle_status',
|
||||
'route_param_name' => 'slideId',
|
||||
])
|
||||
)
|
||||
->add(
|
||||
(new ActionColumn('actions'))
|
||||
->setOptions([
|
||||
'actions' => (new RowActionCollection())
|
||||
->add(
|
||||
(new LinkRowAction('edit'))
|
||||
->setIcon('edit')
|
||||
->setOptions([
|
||||
'route' => 'is_imageslider_controller_edit',
|
||||
'route_param_name' => 'slideId',
|
||||
'route_param_field' => 'id_slide',
|
||||
])
|
||||
)
|
||||
->add(
|
||||
(new LinkRowAction('delete'))
|
||||
->setName($this->trans('Delete', [], 'Admin.Actions'))
|
||||
->setIcon('delete')
|
||||
->setOptions([
|
||||
'route' => 'is_imageslider_controller_delete',
|
||||
'route_param_name' => 'slideId',
|
||||
'route_param_field' => 'id_slide',
|
||||
'confirm_message' => $this->trans(
|
||||
'Delete selected item?',
|
||||
[],
|
||||
'Admin.Notifications.Warning'
|
||||
),
|
||||
])
|
||||
),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getFilters()
|
||||
{
|
||||
return new FilterCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getGridActions()
|
||||
{
|
||||
return new GridActionCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getBulkActions()
|
||||
{
|
||||
return new BulkActionCollection();
|
||||
}
|
||||
}
|
||||
11
is_imageslider/src/Grid/Definition/Factory/index.php
Normal file
11
is_imageslider/src/Grid/Definition/Factory/index.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
11
is_imageslider/src/Grid/Definition/index.php
Normal file
11
is_imageslider/src/Grid/Definition/index.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
94
is_imageslider/src/Grid/Query/ImageSliderQueryBuilder.php
Normal file
94
is_imageslider/src/Grid/Query/ImageSliderQueryBuilder.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Oksydan\IsImageslider\Grid\Query;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use PrestaShop\PrestaShop\Adapter\Shop\Context;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Query\AbstractDoctrineQueryBuilder;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Search\SearchCriteriaInterface;
|
||||
|
||||
final class ImageSliderQueryBuilder extends AbstractDoctrineQueryBuilder
|
||||
{
|
||||
/**
|
||||
* @var Context
|
||||
*/
|
||||
private $shopContext;
|
||||
|
||||
private $contextLangId;
|
||||
|
||||
/**
|
||||
* ImageSliderQueryBuilder constructor.
|
||||
*
|
||||
* @param Connection $connection
|
||||
* @param $dbPrefix
|
||||
* @param Context $shopContext
|
||||
*/
|
||||
public function __construct(Connection $connection, $dbPrefix, Context $shopContext, $contextLangId)
|
||||
{
|
||||
parent::__construct($connection, $dbPrefix);
|
||||
|
||||
$this->shopContext = $shopContext;
|
||||
$this->contextLangId = $contextLangId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SearchCriteriaInterface $searchCriteria
|
||||
*
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
public function getSearchQueryBuilder(SearchCriteriaInterface $searchCriteria): QueryBuilder
|
||||
{
|
||||
$qb = $this->getBaseQuery($searchCriteria->getFilters());
|
||||
$qb->select('islide.id_slide, islidel.title, islidel.description, islidel.image, islide.active, islide.position')
|
||||
->join('islide', $this->dbPrefix . 'image_slider_lang', 'islidel', 'islidel.id_slide = islide.id_slide')
|
||||
->where('islidel.id_lang = :langId')
|
||||
->setParameter('langId', (int) $this->contextLangId);
|
||||
|
||||
if (!$this->shopContext->isAllShopContext()) {
|
||||
$qb->join('islide', $this->dbPrefix . 'image_slider_shop', 'islides', 'islides.id_slide = islide.id_slide')
|
||||
->where('islides.id_shop in (' . implode(', ', $this->shopContext->getContextListShopID()) . ')')
|
||||
->groupBy('islide.id_slide');
|
||||
}
|
||||
|
||||
$qb->orderBy(
|
||||
$searchCriteria->getOrderBy(),
|
||||
$searchCriteria->getOrderWay()
|
||||
)
|
||||
->setFirstResult($searchCriteria->getOffset())
|
||||
->setMaxResults($searchCriteria->getLimit());
|
||||
|
||||
$qb->orderBy('position');
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SearchCriteriaInterface $searchCriteria
|
||||
*
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
public function getCountQueryBuilder(SearchCriteriaInterface $searchCriteria): QueryBuilder
|
||||
{
|
||||
$qb = $this->getBaseQuery();
|
||||
$qb->select('COUNT(DISTINCT islide.id_slide)');
|
||||
if (!$this->shopContext->isAllShopContext()) {
|
||||
$qb->join('islide', $this->dbPrefix . 'image_slider_shop', 'islides', 'islides.id_slide = islide.id_slide')
|
||||
->where('islides.id_shop in (' . implode(', ', $this->shopContext->getContextListShopID()) . ')');
|
||||
}
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
private function getBaseQuery(): QueryBuilder
|
||||
{
|
||||
return $this->connection
|
||||
->createQueryBuilder()
|
||||
->from($this->dbPrefix . 'image_slider', 'islide');
|
||||
}
|
||||
}
|
||||
11
is_imageslider/src/Grid/Query/index.php
Normal file
11
is_imageslider/src/Grid/Query/index.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
Reference in New Issue
Block a user