first commit
This commit is contained in:
55
modules/ps_linklist/src/Cache/LegacyLinkBlockCache.php
Normal file
55
modules/ps_linklist/src/Cache/LegacyLinkBlockCache.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\LinkList\Cache;
|
||||
|
||||
use PrestaShop\PrestaShop\Core\Addon\Module\ModuleRepository;
|
||||
use Ps_Linklist;
|
||||
|
||||
/**
|
||||
* Class LegacyBlockCache.
|
||||
*/
|
||||
final class LegacyLinkBlockCache implements LinkBlockCacheInterface
|
||||
{
|
||||
/**
|
||||
* @var ModuleRepository
|
||||
*/
|
||||
private $moduleRepository;
|
||||
|
||||
/**
|
||||
* LegacyLinkBlockCache constructor.
|
||||
*
|
||||
* @param ModuleRepository $moduleRepository
|
||||
*/
|
||||
public function __construct(ModuleRepository $moduleRepository)
|
||||
{
|
||||
$this->moduleRepository = $moduleRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function clearModuleCache()
|
||||
{
|
||||
/** @var Ps_Linklist $module */
|
||||
$module = $this->moduleRepository->getInstanceByName(Ps_Linklist::MODULE_NAME);
|
||||
$module->_clearCache($module->templateFile);
|
||||
}
|
||||
}
|
||||
32
modules/ps_linklist/src/Cache/LinkBlockCacheInterface.php
Normal file
32
modules/ps_linklist/src/Cache/LinkBlockCacheInterface.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\LinkList\Cache;
|
||||
|
||||
/**
|
||||
* Interface LinkBlockCacheInterface.
|
||||
*/
|
||||
interface LinkBlockCacheInterface
|
||||
{
|
||||
/**
|
||||
* Clear module cache.
|
||||
*/
|
||||
public function clearModuleCache();
|
||||
}
|
||||
28
modules/ps_linklist/src/Cache/index.php
Normal file
28
modules/ps_linklist/src/Cache/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
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,309 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\LinkList\Controller\Admin\Improve\Design;
|
||||
|
||||
use PrestaShop\Module\LinkList\Core\Grid\LinkBlockGridFactory;
|
||||
use PrestaShop\Module\LinkList\Core\Search\Filters\LinkBlockFilters;
|
||||
use PrestaShop\Module\LinkList\Form\LinkBlockFormDataProvider;
|
||||
use PrestaShop\Module\LinkList\Repository\LinkBlockRepository;
|
||||
use PrestaShop\PrestaShop\Core\Exception\DatabaseException;
|
||||
use PrestaShop\PrestaShop\Core\Form\FormHandlerInterface;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Position\Exception\PositionDataException;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Position\Exception\PositionUpdateException;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Position\GridPositionUpdaterInterface;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Position\PositionUpdateFactory;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Position\PositionDefinition;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Position\PositionUpdate;
|
||||
use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController;
|
||||
use PrestaShopBundle\Security\Annotation\AdminSecurity;
|
||||
use PrestaShopBundle\Security\Annotation\ModuleActivated;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
/**
|
||||
* Class LinkBlockController.
|
||||
*
|
||||
* @ModuleActivated(moduleName="ps_linklist", redirectRoute="admin_module_manage")
|
||||
*/
|
||||
class LinkBlockController extends FrameworkBundleAdminController
|
||||
{
|
||||
/**
|
||||
* @AdminSecurity("is_granted('read', request.get('_legacy_controller'))", message="Access denied.")
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function listAction(Request $request)
|
||||
{
|
||||
//Get hook list, then loop through hooks setting it in in the filter
|
||||
/** @var LinkBlockRepository $repository */
|
||||
$repository = $this->get('prestashop.module.link_block.repository');
|
||||
$hooks = $repository->getHooksWithLinks();
|
||||
|
||||
$filtersParams = $this->buildFiltersParamsByRequest($request);
|
||||
|
||||
/** @var LinkBlockGridFactory $linkBlockGridFactory */
|
||||
$linkBlockGridFactory = $this->get('prestashop.module.link_block.grid.factory');
|
||||
$grids = $linkBlockGridFactory->getGrids($hooks, $filtersParams);
|
||||
|
||||
$presentedGrids = [];
|
||||
foreach ($grids as $grid) {
|
||||
$presentedGrids[] = $this->presentGrid($grid);
|
||||
}
|
||||
|
||||
return $this->render('@Modules/ps_linklist/views/templates/admin/link_block/list.html.twig', [
|
||||
'grids' => $presentedGrids,
|
||||
'enableSidebar' => true,
|
||||
'layoutHeaderToolbarBtn' => $this->getToolbarButtons(),
|
||||
'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @AdminSecurity("is_granted('create', request.get('_legacy_controller'))", message="Access denied.")
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createAction(Request $request)
|
||||
{
|
||||
$this->get('prestashop.module.link_block.form_provider')->setIdLinkBlock(null);
|
||||
$form = $this->get('prestashop.module.link_block.form_handler')->getForm();
|
||||
|
||||
return $this->render('@Modules/ps_linklist/views/templates/admin/link_block/form.html.twig', [
|
||||
'linkBlockForm' => $form->createView(),
|
||||
'enableSidebar' => true,
|
||||
'layoutHeaderToolbarBtn' => $this->getToolbarButtons(),
|
||||
'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @AdminSecurity("is_granted('update', request.get('_legacy_controller'))", message="Access denied.")
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $linkBlockId
|
||||
*
|
||||
* @return Response
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function editAction(Request $request, $linkBlockId)
|
||||
{
|
||||
$this->get('prestashop.module.link_block.form_provider')->setIdLinkBlock($linkBlockId);
|
||||
$form = $this->get('prestashop.module.link_block.form_handler')->getForm();
|
||||
|
||||
return $this->render('@Modules/ps_linklist/views/templates/admin/link_block/form.html.twig', [
|
||||
'linkBlockForm' => $form->createView(),
|
||||
'enableSidebar' => true,
|
||||
'layoutHeaderToolbarBtn' => $this->getToolbarButtons(),
|
||||
'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @AdminSecurity("is_granted('create', request.get('_legacy_controller'))", message="Access denied.")
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return RedirectResponse|Response
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createProcessAction(Request $request)
|
||||
{
|
||||
return $this->processForm($request, 'Successful creation.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @AdminSecurity("is_granted('update', request.get('_legacy_controller'))", message="Access denied.")
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $linkBlockId
|
||||
*
|
||||
* @return RedirectResponse|Response
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function editProcessAction(Request $request, $linkBlockId)
|
||||
{
|
||||
return $this->processForm($request, 'Successful update.', $linkBlockId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @AdminSecurity("is_granted('delete', request.get('_legacy_controller'))", message="Access denied.")
|
||||
*
|
||||
* @param int $linkBlockId
|
||||
*
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function deleteAction($linkBlockId)
|
||||
{
|
||||
$repository = $this->get('prestashop.module.link_block.repository');
|
||||
$errors = [];
|
||||
try {
|
||||
$repository->delete($linkBlockId);
|
||||
} catch (DatabaseException $e) {
|
||||
$errors[] = [
|
||||
'key' => 'Could not delete #%i',
|
||||
'domain' => 'Admin.Catalog.Notification',
|
||||
'parameters' => [$linkBlockId],
|
||||
];
|
||||
}
|
||||
|
||||
if (0 === count($errors)) {
|
||||
$this->clearModuleCache();
|
||||
$this->addFlash('success', $this->trans('Successful deletion.', 'Admin.Notifications.Success'));
|
||||
} else {
|
||||
$this->flashErrors($errors);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('admin_link_block_list');
|
||||
}
|
||||
|
||||
/**
|
||||
* @AdminSecurity("is_granted('update', request.get('_legacy_controller'))", message="Access denied.")
|
||||
*
|
||||
* @param Request $request
|
||||
* @param int $hookId
|
||||
*
|
||||
* @throws \Exception
|
||||
*
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
public function updatePositionsAction(Request $request, $hookId)
|
||||
{
|
||||
$positionsData = [
|
||||
'positions' => $request->request->get('positions', null),
|
||||
'parentId' => $hookId,
|
||||
];
|
||||
|
||||
/** @var PositionDefinition $positionDefinition */
|
||||
$positionDefinition = $this->get('prestashop.module.link_block.grid.position_definition');
|
||||
/** @var PositionUpdateFactory $positionUpdateFactory */
|
||||
$positionUpdateFactory = $this->get('prestashop.core.grid.position.position_update_factory');
|
||||
try {
|
||||
/** @var PositionUpdate $positionUpdate */
|
||||
$positionUpdate = $positionUpdateFactory->buildPositionUpdate($positionsData, $positionDefinition);
|
||||
} catch (PositionDataException $e) {
|
||||
$errors = [$e->toArray()];
|
||||
$this->flashErrors($errors);
|
||||
|
||||
return $this->redirectToRoute('admin_link_block_list');
|
||||
}
|
||||
|
||||
/** @var GridPositionUpdaterInterface $updater */
|
||||
$updater = $this->get('prestashop.core.grid.position.doctrine_grid_position_updater');
|
||||
try {
|
||||
$updater->update($positionUpdate);
|
||||
$this->clearModuleCache();
|
||||
$this->addFlash('success', $this->trans('Successful update.', 'Admin.Notifications.Success'));
|
||||
} catch (PositionUpdateException $e) {
|
||||
$errors = [$e->toArray()];
|
||||
$this->flashErrors($errors);
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('admin_link_block_list');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param string $successMessage
|
||||
* @param int|null $linkBlockId
|
||||
*
|
||||
* @return Response|RedirectResponse
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function processForm(Request $request, $successMessage, $linkBlockId = null)
|
||||
{
|
||||
/** @var LinkBlockFormDataProvider $formProvider */
|
||||
$formProvider = $this->get('prestashop.module.link_block.form_provider');
|
||||
$formProvider->setIdLinkBlock($linkBlockId);
|
||||
|
||||
/** @var FormHandlerInterface $formHandler */
|
||||
$formHandler = $this->get('prestashop.module.link_block.form_handler');
|
||||
$form = $formHandler->getForm();
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$data = $form->getData();
|
||||
$saveErrors = $formHandler->save($data);
|
||||
|
||||
if (0 === count($saveErrors)) {
|
||||
$this->addFlash('success', $this->trans($successMessage, 'Admin.Notifications.Success'));
|
||||
|
||||
return $this->redirectToRoute('admin_link_block_list');
|
||||
}
|
||||
|
||||
$this->flashErrors($saveErrors);
|
||||
}
|
||||
|
||||
return $this->render('@Modules/ps_linklist/views/templates/admin/link_block/form.html.twig', [
|
||||
'linkBlockForm' => $form->createView(),
|
||||
'enableSidebar' => true,
|
||||
'layoutHeaderToolbarBtn' => $this->getToolbarButtons(),
|
||||
'help_link' => $this->generateSidebarLink($request->attributes->get('_legacy_controller')),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function buildFiltersParamsByRequest(Request $request)
|
||||
{
|
||||
$filtersParams = array_merge(LinkBlockFilters::getDefaults(), $request->query->all());
|
||||
$filtersParams['filters']['id_lang'] = $this->getContext()->language->id;
|
||||
|
||||
return $filtersParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the header toolbar buttons.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getToolbarButtons()
|
||||
{
|
||||
return [
|
||||
'add' => [
|
||||
'href' => $this->generateUrl('admin_link_block_create'),
|
||||
'desc' => $this->trans('New block', 'Modules.Linklist.Admin'),
|
||||
'icon' => 'add_circle_outline',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear module cache.
|
||||
*/
|
||||
private function clearModuleCache()
|
||||
{
|
||||
$this->get('prestashop.module.link_block.cache')->clearModuleCache();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
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;
|
||||
28
modules/ps_linklist/src/Controller/Admin/Improve/index.php
Normal file
28
modules/ps_linklist/src/Controller/Admin/Improve/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
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;
|
||||
28
modules/ps_linklist/src/Controller/Admin/index.php
Normal file
28
modules/ps_linklist/src/Controller/Admin/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
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;
|
||||
28
modules/ps_linklist/src/Controller/index.php
Normal file
28
modules/ps_linklist/src/Controller/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
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,130 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\LinkList\Core\Grid\Definition\Factory;
|
||||
|
||||
use PrestaShop\PrestaShop\Core\Grid\Action\Row\RowActionCollection;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Action\Row\Type\LinkRowAction;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Action\Row\Type\SubmitRowAction;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Column\ColumnCollection;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\PositionColumn;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Column\Type\Common\ActionColumn;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Column\Type\DataColumn;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Definition\Factory\AbstractGridDefinitionFactory;
|
||||
|
||||
/**
|
||||
* Class LinkBlockDefinitionFactory.
|
||||
*/
|
||||
final class LinkBlockDefinitionFactory extends AbstractGridDefinitionFactory
|
||||
{
|
||||
const FACTORY_ID = 'link_widget_grid_';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $hook;
|
||||
|
||||
/**
|
||||
* LinkBlockDefinitionFactory constructor.
|
||||
*
|
||||
* @param array $hook
|
||||
*/
|
||||
public function __construct(array $hook)
|
||||
{
|
||||
$this->hook = $hook;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getId()
|
||||
{
|
||||
return self::FACTORY_ID . $this->hook['id_hook'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getName()
|
||||
{
|
||||
return $this->hook['name'] . ' ' . $this->hook['title'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getColumns()
|
||||
{
|
||||
return (new ColumnCollection())
|
||||
->add((new DataColumn('id_link_block'))
|
||||
->setName($this->trans('ID', [], 'Modules.Linklist.Admin'))
|
||||
->setOptions([
|
||||
'field' => 'id_link_block',
|
||||
])
|
||||
)
|
||||
->add((new DataColumn('block_name'))
|
||||
->setName($this->trans('Name of the block', [], 'Modules.Linklist.Admin'))
|
||||
->setOptions([
|
||||
'field' => 'block_name',
|
||||
])
|
||||
)
|
||||
->add((new PositionColumn('position'))
|
||||
->setName($this->trans('Position', [], 'Admin.Global'))
|
||||
->setOptions([
|
||||
'id_field' => 'id_link_block',
|
||||
'position_field' => 'position',
|
||||
'update_route' => 'admin_link_block_update_positions',
|
||||
'update_method' => 'POST',
|
||||
'record_route_params' => [
|
||||
'id_hook' => 'hookId',
|
||||
],
|
||||
])
|
||||
)
|
||||
->add((new ActionColumn('actions'))
|
||||
->setOptions([
|
||||
'actions' => (new RowActionCollection())
|
||||
->add((new LinkRowAction('edit'))
|
||||
->setIcon('edit')
|
||||
->setOptions([
|
||||
'route' => 'admin_link_block_edit',
|
||||
'route_param_name' => 'linkBlockId',
|
||||
'route_param_field' => 'id_link_block',
|
||||
])
|
||||
)
|
||||
->add((new SubmitRowAction('delete'))
|
||||
->setName($this->trans('Delete', [], 'Admin.Actions'))
|
||||
->setIcon('delete')
|
||||
->setOptions([
|
||||
'method' => 'POST',
|
||||
'route' => 'admin_link_block_delete',
|
||||
'route_param_name' => 'linkBlockId',
|
||||
'route_param_field' => 'id_link_block',
|
||||
'confirm_message' => $this->trans(
|
||||
'Delete selected item?',
|
||||
[],
|
||||
'Admin.Notifications.Warning'
|
||||
),
|
||||
])
|
||||
),
|
||||
])
|
||||
)
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
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;
|
||||
28
modules/ps_linklist/src/Core/Grid/Definition/index.php
Normal file
28
modules/ps_linklist/src/Core/Grid/Definition/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
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;
|
||||
119
modules/ps_linklist/src/Core/Grid/LinkBlockGridFactory.php
Normal file
119
modules/ps_linklist/src/Core/Grid/LinkBlockGridFactory.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\LinkList\Core\Grid;
|
||||
|
||||
use PrestaShop\Module\LinkList\Core\Grid\Definition\Factory\LinkBlockDefinitionFactory;
|
||||
use PrestaShop\Module\LinkList\Core\Search\Filters\LinkBlockFilters;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Data\Factory\GridDataFactoryInterface;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Filter\GridFilterFormFactoryInterface;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Grid;
|
||||
use PrestaShop\PrestaShop\Core\Grid\GridFactory;
|
||||
use PrestaShop\PrestaShop\Core\Hook\HookDispatcherInterface;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
* Class LinkBlockGridFactory.
|
||||
*/
|
||||
final class LinkBlockGridFactory
|
||||
{
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
/**
|
||||
* @var HookDispatcherInterface
|
||||
*/
|
||||
private $hookDispatcher;
|
||||
|
||||
/**
|
||||
* @var GridDataFactoryInterface
|
||||
*/
|
||||
private $dataFactory;
|
||||
|
||||
/**
|
||||
* @var GridFilterFormFactoryInterface
|
||||
*/
|
||||
private $filterFormFactory;
|
||||
|
||||
/**
|
||||
* HookGridFactory constructor.
|
||||
*
|
||||
* @param TranslatorInterface $translator
|
||||
* @param HookDispatcherInterface $hookDispatcher
|
||||
* @param GridDataFactoryInterface $dataFactory
|
||||
* @param GridFilterFormFactoryInterface $filterFormFactory
|
||||
*/
|
||||
public function __construct(
|
||||
TranslatorInterface $translator,
|
||||
GridDataFactoryInterface $dataFactory,
|
||||
HookDispatcherInterface $hookDispatcher,
|
||||
GridFilterFormFactoryInterface $filterFormFactory
|
||||
) {
|
||||
$this->translator = $translator;
|
||||
$this->hookDispatcher = $hookDispatcher;
|
||||
$this->dataFactory = $dataFactory;
|
||||
$this->filterFormFactory = $filterFormFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $hooks
|
||||
* @param array $filtersParams
|
||||
*
|
||||
* @return Grid[]
|
||||
*/
|
||||
public function getGrids(array $hooks, array $filtersParams)
|
||||
{
|
||||
$grids = [];
|
||||
foreach ($hooks as $hook) {
|
||||
$hookParams = $filtersParams;
|
||||
$hookParams['filters']['id_hook'] = $hook['id_hook'];
|
||||
|
||||
$filters = new LinkBlockFilters($hookParams);
|
||||
|
||||
$gridFactory = $this->buildGridFactoryByHook($hook);
|
||||
$grids[] = $gridFactory->getGrid($filters);
|
||||
}
|
||||
|
||||
return $grids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Each definition depends on the hook, therefore each factory also
|
||||
* depends on the hook.
|
||||
*
|
||||
* @param array $hook
|
||||
*
|
||||
* @return GridFactory
|
||||
*/
|
||||
private function buildGridFactoryByHook(array $hook)
|
||||
{
|
||||
$definitionFactory = new LinkBlockDefinitionFactory($hook);
|
||||
$definitionFactory->setTranslator($this->translator);
|
||||
$definitionFactory->setHookDispatcher($this->hookDispatcher);
|
||||
|
||||
return new GridFactory(
|
||||
$definitionFactory,
|
||||
$this->dataFactory,
|
||||
$this->filterFormFactory
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\LinkList\Core\Grid\Query;
|
||||
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Query\AbstractDoctrineQueryBuilder;
|
||||
use PrestaShop\PrestaShop\Core\Grid\Search\SearchCriteriaInterface;
|
||||
|
||||
/**
|
||||
* Class LinkBlockQueryBuilder.
|
||||
*/
|
||||
final class LinkBlockQueryBuilder extends AbstractDoctrineQueryBuilder
|
||||
{
|
||||
/**
|
||||
* @param null|SearchCriteriaInterface $searchCriteria
|
||||
*
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
public function getSearchQueryBuilder(SearchCriteriaInterface $searchCriteria = null)
|
||||
{
|
||||
$qb = $this->getQueryBuilder($searchCriteria->getFilters());
|
||||
$qb->select('
|
||||
lb.id_link_block,
|
||||
lbl.name AS block_name,
|
||||
lb.id_hook,
|
||||
h.name as hook_name,
|
||||
h.title as hook_title,
|
||||
h.description as hook_description,
|
||||
lb.position
|
||||
')
|
||||
->orderBy(
|
||||
$searchCriteria->getOrderBy(),
|
||||
$searchCriteria->getOrderWay()
|
||||
)
|
||||
;
|
||||
|
||||
if ($searchCriteria->getLimit() > 0) {
|
||||
$qb
|
||||
->setFirstResult($searchCriteria->getOffset())
|
||||
->setMaxResults($searchCriteria->getLimit())
|
||||
;
|
||||
}
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|SearchCriteriaInterface $searchCriteria
|
||||
*
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
public function getCountQueryBuilder(SearchCriteriaInterface $searchCriteria = null)
|
||||
{
|
||||
$qb = $this->getQueryBuilder($searchCriteria->getFilters());
|
||||
$qb->select('COUNT(lb.id_link_block)');
|
||||
|
||||
return $qb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get generic query builder.
|
||||
*
|
||||
* @param array $filters
|
||||
*
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
private function getQueryBuilder(array $filters)
|
||||
{
|
||||
$qb = $this->connection
|
||||
->createQueryBuilder()
|
||||
->from($this->dbPrefix . 'link_block', 'lb')
|
||||
->innerJoin('lb', $this->dbPrefix . 'link_block_lang', 'lbl', 'lb.id_link_block = lbl.id_link_block')
|
||||
->leftJoin('lb', $this->dbPrefix . 'hook', 'h', 'lb.id_hook = h.id_hook');
|
||||
|
||||
foreach ($filters as $name => $value) {
|
||||
if ('id_lang' === $name) {
|
||||
$qb
|
||||
->andWhere("lbl.id_lang = :$name")
|
||||
->setParameter($name, $value)
|
||||
;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ('id_hook' === $name) {
|
||||
$qb
|
||||
->andWhere("h.id_hook = :$name")
|
||||
->setParameter($name, $value)
|
||||
;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$qb
|
||||
->andWhere(sprintf('lbl.%s LIKE :%s', $name, $name))
|
||||
->setParameter($name, '%' . $value . '%')
|
||||
;
|
||||
}
|
||||
|
||||
return $qb;
|
||||
}
|
||||
}
|
||||
28
modules/ps_linklist/src/Core/Grid/Query/index.php
Normal file
28
modules/ps_linklist/src/Core/Grid/Query/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
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;
|
||||
28
modules/ps_linklist/src/Core/Grid/index.php
Normal file
28
modules/ps_linklist/src/Core/Grid/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
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,43 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\LinkList\Core\Search\Filters;
|
||||
|
||||
use PrestaShop\PrestaShop\Core\Search\Filters;
|
||||
|
||||
/**
|
||||
* Class LinkBlockFilters.
|
||||
*/
|
||||
final class LinkBlockFilters extends Filters
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getDefaults()
|
||||
{
|
||||
return [
|
||||
'limit' => 0,
|
||||
'offset' => 0,
|
||||
'orderBy' => 'position',
|
||||
'sortOrder' => 'asc',
|
||||
'filters' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
28
modules/ps_linklist/src/Core/Search/Filters/index.php
Normal file
28
modules/ps_linklist/src/Core/Search/Filters/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
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;
|
||||
28
modules/ps_linklist/src/Core/Search/index.php
Normal file
28
modules/ps_linklist/src/Core/Search/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
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;
|
||||
28
modules/ps_linklist/src/Core/index.php
Normal file
28
modules/ps_linklist/src/Core/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
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,71 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\LinkList\Form\ChoiceProvider;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use PrestaShop\PrestaShop\Core\Form\FormChoiceProviderInterface;
|
||||
|
||||
/**
|
||||
* Class AbstractDatabaseChoiceProvider.
|
||||
*/
|
||||
abstract class AbstractDatabaseChoiceProvider implements FormChoiceProviderInterface
|
||||
{
|
||||
/**
|
||||
* @var Connection
|
||||
*/
|
||||
protected $connection;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $dbPrefix;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $idLang;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $shopIds;
|
||||
|
||||
/**
|
||||
* AbstractDatabaseChoiceProvider constructor.
|
||||
*
|
||||
* @param Connection $connection
|
||||
* @param string $dbPrefix
|
||||
* @param int|null $idLang
|
||||
* @param array|null $shopIds
|
||||
*/
|
||||
public function __construct(Connection $connection, $dbPrefix, $idLang = null, array $shopIds = null)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
$this->dbPrefix = $dbPrefix;
|
||||
$this->idLang = $idLang;
|
||||
$this->shopIds = $shopIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
abstract public function getChoices();
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\LinkList\Form\ChoiceProvider;
|
||||
|
||||
/**
|
||||
* Class CMSCategoryChoiceProvider.
|
||||
*/
|
||||
final class CMSCategoryChoiceProvider extends AbstractDatabaseChoiceProvider
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getChoices()
|
||||
{
|
||||
$qb = $this->connection->createQueryBuilder();
|
||||
$qb
|
||||
->select('cc.id_cms_category, ccl.name')
|
||||
->from($this->dbPrefix . 'cms_category', 'cc')
|
||||
->innerJoin('cc', $this->dbPrefix . 'cms_category_lang', 'ccl', 'cc.id_cms_category = ccl.id_cms_category')
|
||||
->innerJoin('cc', $this->dbPrefix . 'cms_category_shop', 'ccs', 'cc.id_cms_category = ccs.id_cms_category')
|
||||
->andWhere('cc.active = 1')
|
||||
->andWhere('ccl.id_lang = :idLang')
|
||||
->andWhere('ccs.id_shop IN (:shopIds)')
|
||||
->setParameter('idLang', $this->idLang)
|
||||
->setParameter('shopIds', implode(',', $this->shopIds))
|
||||
->orderBy('ccl.name')
|
||||
;
|
||||
|
||||
$categories = $qb->execute()->fetchAll();
|
||||
$choices = [];
|
||||
foreach ($categories as $category) {
|
||||
$choices[$category['name']] = $category['id_cms_category'];
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\LinkList\Form\ChoiceProvider;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
|
||||
/**
|
||||
* Class CMSPageChoiceProvider.
|
||||
*/
|
||||
final class CMSPageChoiceProvider extends AbstractDatabaseChoiceProvider
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $categories;
|
||||
|
||||
/**
|
||||
* CMSPageChoiceProvider constructor.
|
||||
*
|
||||
* @param Connection $connection
|
||||
* @param string $dbPrefix
|
||||
* @param array $categories
|
||||
* @param int $idLang
|
||||
* @param array $shopIds
|
||||
*/
|
||||
public function __construct(
|
||||
Connection $connection,
|
||||
$dbPrefix,
|
||||
array $categories,
|
||||
$idLang,
|
||||
$shopIds
|
||||
) {
|
||||
parent::__construct($connection, $dbPrefix, $idLang, $shopIds);
|
||||
$this->categories = $categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getChoices()
|
||||
{
|
||||
$choices = [];
|
||||
|
||||
foreach ($this->categories as $categoryName => $categoryId) {
|
||||
$qb = $this->connection->createQueryBuilder();
|
||||
$qb
|
||||
->select('c.id_cms, cl.meta_title')
|
||||
->from($this->dbPrefix . 'cms', 'c')
|
||||
->innerJoin('c', $this->dbPrefix . 'cms_lang', 'cl', 'c.id_cms = cl.id_cms')
|
||||
->innerJoin('c', $this->dbPrefix . 'cms_shop', 'cs', 'c.id_cms = cs.id_cms')
|
||||
->andWhere('c.active = 1')
|
||||
->andWhere('cl.id_lang = :idLang')
|
||||
->andWhere('cs.id_shop IN (:shopIds)')
|
||||
->andWhere('c.id_cms_category = :idCmsCategory')
|
||||
->setParameter('idCmsCategory', $categoryId)
|
||||
->setParameter('idLang', $this->idLang)
|
||||
->setParameter('shopIds', implode(',', $this->shopIds))
|
||||
->orderBy('c.position')
|
||||
;
|
||||
$pages = $qb->execute()->fetchAll();
|
||||
foreach ($pages as $page) {
|
||||
$choices[$categoryName][$page['id_cms'] . ' ' . $page['meta_title']] = $page['id_cms'];
|
||||
}
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\LinkList\Form\ChoiceProvider;
|
||||
|
||||
/**
|
||||
* Class HookChoiceProvider.
|
||||
*/
|
||||
final class HookChoiceProvider extends AbstractDatabaseChoiceProvider
|
||||
{
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getChoices()
|
||||
{
|
||||
$qb = $this->connection->createQueryBuilder();
|
||||
$qb
|
||||
->select('h.id_hook, h.name')
|
||||
->from($this->dbPrefix . 'hook', 'h')
|
||||
->andWhere('h.name LIKE :displayHook')
|
||||
->setParameter('displayHook', 'display%')
|
||||
->orderBy('h.name')
|
||||
;
|
||||
|
||||
$hooks = $qb->execute()->fetchAll();
|
||||
$choices = [];
|
||||
foreach ($hooks as $hook) {
|
||||
$choices[$hook['name']] = $hook['id_hook'];
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\LinkList\Form\ChoiceProvider;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use PrestaShop\PrestaShop\Core\Foundation\Database\EntityNotFoundException;
|
||||
use Tools;
|
||||
|
||||
/**
|
||||
* Class PageChoiceProvider.
|
||||
*/
|
||||
final class PageChoiceProvider extends AbstractDatabaseChoiceProvider
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $pageNames;
|
||||
|
||||
/**
|
||||
* PageChoiceProvider constructor.
|
||||
*
|
||||
* @param Connection $connection
|
||||
* @param string $dbPrefix
|
||||
* @param int $idLang
|
||||
* @param array $shopIds
|
||||
* @param array $pageNames
|
||||
*/
|
||||
public function __construct(
|
||||
Connection $connection,
|
||||
$dbPrefix,
|
||||
$idLang,
|
||||
array $shopIds,
|
||||
array $pageNames
|
||||
) {
|
||||
parent::__construct($connection, $dbPrefix, $idLang, $shopIds);
|
||||
$this->pageNames = $pageNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*
|
||||
* @throws EntityNotFoundException
|
||||
*/
|
||||
public function getChoices()
|
||||
{
|
||||
$choices = [];
|
||||
foreach ($this->pageNames as $pageName) {
|
||||
$qb = $this->connection->createQueryBuilder();
|
||||
$qb
|
||||
->select('m.id_meta, ml.title')
|
||||
->from($this->dbPrefix . 'meta', 'm')
|
||||
->leftJoin('m', $this->dbPrefix . 'meta_lang', 'ml', 'm.id_meta = ml.id_meta')
|
||||
->andWhere($qb->expr()->orX('m.page = :page', 'm.page = :pageSlug'))
|
||||
->andWhere('ml.id_lang = :idLang')
|
||||
->andWhere('ml.id_shop IN (:shopIds)')
|
||||
->setParameter('idLang', $this->idLang)
|
||||
->setParameter('shopIds', implode(',', $this->shopIds))
|
||||
->setParameter('page', $pageName)
|
||||
->setParameter('pageSlug', str_replace('-', '', Tools::strtolower($pageName)))
|
||||
;
|
||||
$meta = $qb->execute()->fetchAll();
|
||||
if (!empty($meta)) {
|
||||
$choices[$meta[0]['title']] = $pageName;
|
||||
}
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
}
|
||||
28
modules/ps_linklist/src/Form/ChoiceProvider/index.php
Normal file
28
modules/ps_linklist/src/Form/ChoiceProvider/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
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;
|
||||
293
modules/ps_linklist/src/Form/LinkBlockFormDataProvider.php
Normal file
293
modules/ps_linklist/src/Form/LinkBlockFormDataProvider.php
Normal file
@@ -0,0 +1,293 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\LinkList\Form;
|
||||
|
||||
use PrestaShop\Module\LinkList\Cache\LinkBlockCacheInterface;
|
||||
use PrestaShop\Module\LinkList\Model\LinkBlock;
|
||||
use PrestaShop\Module\LinkList\Repository\LinkBlockRepository;
|
||||
use PrestaShop\PrestaShop\Core\Addon\Module\ModuleRepository;
|
||||
use PrestaShop\PrestaShop\Core\Form\FormDataProviderInterface;
|
||||
use Hook;
|
||||
use Ps_Linklist;
|
||||
|
||||
/**
|
||||
* Class LinkBlockFormDataProvider.
|
||||
*/
|
||||
class LinkBlockFormDataProvider implements FormDataProviderInterface
|
||||
{
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
private $idLinkBlock;
|
||||
|
||||
/**
|
||||
* @var LinkBlockRepository
|
||||
*/
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* @var LinkBlockCacheInterface
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
/**
|
||||
* @var ModuleRepository
|
||||
*/
|
||||
private $moduleRepository;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $languages;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $shopId;
|
||||
|
||||
/**
|
||||
* LinkBlockFormDataProvider constructor.
|
||||
*
|
||||
* @param LinkBlockRepository $repository
|
||||
* @param LinkBlockCacheInterface $cache
|
||||
* @param ModuleRepository $moduleRepository
|
||||
* @param array $languages
|
||||
* @param int $shopId
|
||||
*/
|
||||
public function __construct(
|
||||
LinkBlockRepository $repository,
|
||||
LinkBlockCacheInterface $cache,
|
||||
ModuleRepository $moduleRepository,
|
||||
array $languages,
|
||||
$shopId
|
||||
) {
|
||||
$this->repository = $repository;
|
||||
$this->cache = $cache;
|
||||
$this->moduleRepository = $moduleRepository;
|
||||
$this->languages = $languages;
|
||||
$this->shopId = $shopId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*
|
||||
* @throws \PrestaShopDatabaseException
|
||||
* @throws \PrestaShopException
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
if (null === $this->idLinkBlock) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$linkBlock = new LinkBlock($this->idLinkBlock);
|
||||
|
||||
$arrayLinkBlock = $linkBlock->toArray();
|
||||
|
||||
//The form and the database model don't have the same data hierarchy
|
||||
//Transform array $custom[en][1][name] to $custom[1][en][name]
|
||||
$arrayCustom = [];
|
||||
foreach ($arrayLinkBlock['custom_content'] as $idLang => $customs) {
|
||||
if (!is_array($customs)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($customs as $i => $custom) {
|
||||
$arrayCustom[$i][$idLang] = $custom;
|
||||
}
|
||||
}
|
||||
|
||||
return ['link_block' => [
|
||||
'id_link_block' => $arrayLinkBlock['id_link_block'],
|
||||
'block_name' => $arrayLinkBlock['name'],
|
||||
'id_hook' => $arrayLinkBlock['id_hook'],
|
||||
'cms' => $arrayLinkBlock['content']['cms'],
|
||||
'product' => $arrayLinkBlock['content']['product'],
|
||||
'static' => $arrayLinkBlock['content']['static'],
|
||||
'custom' => $arrayCustom,
|
||||
]];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \PrestaShop\PrestaShop\Adapter\Entity\PrestaShopDatabaseException
|
||||
*/
|
||||
public function setData(array $data)
|
||||
{
|
||||
$linkBlock = $data['link_block'];
|
||||
$errors = $this->validateLinkBlock($linkBlock);
|
||||
if (!empty($errors)) {
|
||||
return $errors;
|
||||
}
|
||||
|
||||
$customContent = [];
|
||||
if (!empty($linkBlock['custom'])) {
|
||||
foreach ($linkBlock['custom'] as $customLanguages) {
|
||||
if ($this->isEmptyCustom($customLanguages)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($customLanguages as $idLang => $custom) {
|
||||
$customContent[$idLang][] = $custom;
|
||||
}
|
||||
}
|
||||
}
|
||||
$linkBlock['custom_content'] = $customContent;
|
||||
|
||||
if (empty($linkBlock['id_link_block'])) {
|
||||
$linkBlockId = $this->repository->create($linkBlock);
|
||||
$this->setIdLinkBlock($linkBlockId);
|
||||
} else {
|
||||
$linkBlockId = $linkBlock['id_link_block'];
|
||||
$this->repository->update($linkBlockId, $linkBlock);
|
||||
}
|
||||
$this->updateHook($linkBlock['id_hook']);
|
||||
$this->cache->clearModuleCache();
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getIdLinkBlock()
|
||||
{
|
||||
return $this->idLinkBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $idLinkBlock
|
||||
*
|
||||
* @return LinkBlockFormDataProvider
|
||||
*/
|
||||
public function setIdLinkBlock($idLinkBlock)
|
||||
{
|
||||
$this->idLinkBlock = $idLinkBlock;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function validateLinkBlock(array $data)
|
||||
{
|
||||
$errors = [];
|
||||
if (!isset($data['id_hook'])) {
|
||||
$errors[] = [
|
||||
'key' => 'Missing id_hook',
|
||||
'domain' => 'Admin.Catalog.Notification',
|
||||
'parameters' => [],
|
||||
];
|
||||
}
|
||||
|
||||
if (!isset($data['block_name'])) {
|
||||
$errors[] = [
|
||||
'key' => 'Missing block_name',
|
||||
'domain' => 'Admin.Catalog.Notification',
|
||||
'parameters' => [],
|
||||
];
|
||||
} else {
|
||||
foreach ($this->languages as $language) {
|
||||
if (empty($data['block_name'][$language['id_lang']])) {
|
||||
$errors[] = [
|
||||
'key' => 'Missing block_name value for language %s',
|
||||
'domain' => 'Admin.Catalog.Notification',
|
||||
'parameters' => [$language['iso_code']],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($data['custom'])) {
|
||||
return $errors;
|
||||
}
|
||||
|
||||
foreach ($data['custom'] as $customIndex => $custom) {
|
||||
if ($this->isEmptyCustom($custom)) {
|
||||
continue;
|
||||
}
|
||||
foreach ($this->languages as $language) {
|
||||
if (!isset($custom[$language['id_lang']])) {
|
||||
$errors[] = [
|
||||
'key' => 'Missing block_name value for language %s',
|
||||
'domain' => 'Admin.Catalog.Notification',
|
||||
'parameters' => [$language['iso_code']],
|
||||
];
|
||||
} else {
|
||||
$langCustom = $custom[$language['id_lang']];
|
||||
$fields = ['title', 'url'];
|
||||
foreach ($fields as $field) {
|
||||
if (empty($langCustom[$field])) {
|
||||
$errors[] = [
|
||||
'key' => 'Missing %s value in custom[%s] for language %s',
|
||||
'domain' => 'Admin.Catalog.Notification',
|
||||
'parameters' => [$field, $customIndex, $language['iso_code']],
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $custom
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isEmptyCustom(array $custom)
|
||||
{
|
||||
$fields = ['title', 'url'];
|
||||
foreach ($custom as $langCustom) {
|
||||
foreach ($fields as $field) {
|
||||
if (!empty($langCustom[$field])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the selected hook to this module if it was not registered yet.
|
||||
*
|
||||
* @param int $hookId
|
||||
*
|
||||
* @throws \PrestaShopException
|
||||
*/
|
||||
private function updateHook($hookId)
|
||||
{
|
||||
$hookName = Hook::getNameById($hookId);
|
||||
$module = $this->moduleRepository->getInstanceByName(Ps_Linklist::MODULE_NAME);
|
||||
if (!Hook::isModuleRegisteredOnHook($module, $hookName, $this->shopId)) {
|
||||
Hook::registerHook($module, $hookName);
|
||||
}
|
||||
}
|
||||
}
|
||||
47
modules/ps_linklist/src/Form/Type/CustomUrlType.php
Normal file
47
modules/ps_linklist/src/Form/Type/CustomUrlType.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\LinkList\Form\Type;
|
||||
|
||||
use PrestaShopBundle\Form\Admin\Type\TranslatorAwareType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
class CustomUrlType extends TranslatorAwareType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('title', TextType::class, [
|
||||
'label' => $this->trans('Title', 'Modules.Linklist.Admin'),
|
||||
'required' => true,
|
||||
])
|
||||
->add('url', TextType::class, [
|
||||
'label' => $this->trans('URL', 'Modules.Linklist.Admin'),
|
||||
'required' => true,
|
||||
'constraints' => [new Assert\Url()],
|
||||
])
|
||||
;
|
||||
}
|
||||
}
|
||||
151
modules/ps_linklist/src/Form/Type/LinkBlockType.php
Normal file
151
modules/ps_linklist/src/Form/Type/LinkBlockType.php
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\LinkList\Form\Type;
|
||||
|
||||
use PrestaShopBundle\Form\Admin\Type\TranslateTextType;
|
||||
use PrestaShopBundle\Form\Admin\Type\TranslatorAwareType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
class LinkBlockType extends TranslatorAwareType
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $hookChoices;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $cmsPageChoices;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $productPageChoices;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $staticPageChoices;
|
||||
|
||||
/**
|
||||
* LinkBlockType constructor.
|
||||
*
|
||||
* @param TranslatorInterface $translator
|
||||
* @param array $locales
|
||||
* @param array $hookChoices
|
||||
* @param array $cmsPageChoices
|
||||
* @param array $productPageChoices
|
||||
* @param array $staticPageChoices
|
||||
*/
|
||||
public function __construct(
|
||||
TranslatorInterface $translator,
|
||||
array $locales,
|
||||
array $hookChoices,
|
||||
array $cmsPageChoices,
|
||||
array $productPageChoices,
|
||||
array $staticPageChoices
|
||||
) {
|
||||
parent::__construct($translator, $locales);
|
||||
$this->hookChoices = $hookChoices;
|
||||
$this->cmsPageChoices = $cmsPageChoices;
|
||||
$this->productPageChoices = $productPageChoices;
|
||||
$this->staticPageChoices = $staticPageChoices;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('id_link_block', HiddenType::class)
|
||||
->add('block_name', TranslateTextType::class, [
|
||||
'locales' => $this->locales,
|
||||
'required' => true,
|
||||
'label' => $this->trans('Name of the block', 'Modules.Linklist.Admin'),
|
||||
])
|
||||
->add('id_hook', ChoiceType::class, [
|
||||
'choices' => $this->hookChoices,
|
||||
'attr' => [
|
||||
'data-toggle' => 'select2',
|
||||
'data-minimumResultsForSearch' => '7',
|
||||
],
|
||||
'label' => $this->trans('Hook', 'Admin.Global'),
|
||||
])
|
||||
->add('cms', ChoiceType::class, [
|
||||
'choices' => $this->cmsPageChoices,
|
||||
'label' => $this->trans('Content pages', 'Modules.Linklist.Admin'),
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
])
|
||||
->add('product', ChoiceType::class, [
|
||||
'choices' => $this->productPageChoices,
|
||||
'label' => $this->trans('Product pages', 'Modules.Linklist.Admin'),
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
])
|
||||
->add('static', ChoiceType::class, [
|
||||
'choices' => $this->staticPageChoices,
|
||||
'label' => $this->trans('Static content', 'Modules.Linklist.Admin'),
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
])
|
||||
->add('custom', CollectionType::class, [
|
||||
'entry_type' => TranslateCustomUrlType::class,
|
||||
'entry_options' => [
|
||||
'locales' => $this->locales,
|
||||
'label' => false,
|
||||
],
|
||||
'attr' => [
|
||||
'class' => 'custom_collection',
|
||||
'data-delete-button-label' => $this->trans('Delete', 'Admin.Global'),
|
||||
],
|
||||
'allow_add' => true,
|
||||
'allow_delete' => true,
|
||||
'label' => $this->trans('Custom content', 'Modules.Linklist.Admin'),
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'label' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'module_link_block';
|
||||
}
|
||||
}
|
||||
47
modules/ps_linklist/src/Form/Type/TranslateCustomUrlType.php
Normal file
47
modules/ps_linklist/src/Form/Type/TranslateCustomUrlType.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\LinkList\Form\Type;
|
||||
|
||||
use PrestaShopBundle\Form\Admin\Type\TranslateTextType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
* Class TranslatableUrlType.
|
||||
*/
|
||||
class TranslateCustomUrlType extends TranslateTextType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
foreach ($options['locales'] as $locale) {
|
||||
$localeOptions = $options['options'];
|
||||
$localeOptions['label'] = $locale['iso_code'];
|
||||
|
||||
if (!isset($localeOptions['required'])) {
|
||||
$localeOptions['required'] = false;
|
||||
}
|
||||
|
||||
$builder->add($locale['id_lang'], CustomUrlType::class, $localeOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
28
modules/ps_linklist/src/Form/Type/index.php
Normal file
28
modules/ps_linklist/src/Form/Type/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
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;
|
||||
28
modules/ps_linklist/src/Form/index.php
Normal file
28
modules/ps_linklist/src/Form/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
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;
|
||||
151
modules/ps_linklist/src/LegacyLinkBlockRepository.php
Normal file
151
modules/ps_linklist/src/LegacyLinkBlockRepository.php
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\LinkList;
|
||||
|
||||
use PrestaShop\Module\LinkList\Model\LinkBlock;
|
||||
use Symfony\Component\Translation\TranslatorInterface as Translator;
|
||||
use Shop;
|
||||
use Hook;
|
||||
use DB;
|
||||
use Language;
|
||||
use Context;
|
||||
|
||||
/**
|
||||
* Class LegacyLinkBlockRepository.
|
||||
*/
|
||||
class LegacyLinkBlockRepository
|
||||
{
|
||||
private $db;
|
||||
private $shop;
|
||||
private $db_prefix;
|
||||
private $translator;
|
||||
|
||||
/**
|
||||
* @param DB $db
|
||||
* @param Shop $shop
|
||||
* @param Translator $translator
|
||||
*/
|
||||
public function __construct(Db $db, Shop $shop, Translator $translator)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->shop = $shop;
|
||||
$this->db_prefix = $db->getPrefix();
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $id_hook
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \PrestaShopDatabaseException
|
||||
* @throws \PrestaShopException
|
||||
*/
|
||||
public function getByIdHook($id_hook)
|
||||
{
|
||||
$id_hook = (int) $id_hook;
|
||||
|
||||
$sql = "SELECT cb.`id_link_block`
|
||||
FROM {$this->db_prefix}link_block cb
|
||||
WHERE `id_hook` = $id_hook
|
||||
ORDER by cb.`position`
|
||||
";
|
||||
$ids = $this->db->executeS($sql);
|
||||
|
||||
$cmsBlock = array();
|
||||
foreach ($ids as $id) {
|
||||
$cmsBlock[] = new LinkBlock((int) $id['id_link_block']);
|
||||
}
|
||||
|
||||
return $cmsBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function createTables()
|
||||
{
|
||||
$engine = _MYSQL_ENGINE_;
|
||||
$success = true;
|
||||
$this->dropTables();
|
||||
$queries = [
|
||||
"CREATE TABLE IF NOT EXISTS `{$this->db_prefix}link_block`(
|
||||
`id_link_block` int(10) unsigned NOT NULL auto_increment,
|
||||
`id_hook` int(1) unsigned DEFAULT NULL,
|
||||
`position` int(10) unsigned NOT NULL default '0',
|
||||
`content` text default NULL,
|
||||
PRIMARY KEY (`id_link_block`)
|
||||
) ENGINE=$engine DEFAULT CHARSET=utf8",
|
||||
"CREATE TABLE IF NOT EXISTS `{$this->db_prefix}link_block_lang`(
|
||||
`id_link_block` int(10) unsigned NOT NULL,
|
||||
`id_lang` int(10) unsigned NOT NULL,
|
||||
`name` varchar(40) NOT NULL default '',
|
||||
`custom_content` text default NULL,
|
||||
PRIMARY KEY (`id_link_block`, `id_lang`)
|
||||
) ENGINE=$engine DEFAULT CHARSET=utf8",
|
||||
"CREATE TABLE IF NOT EXISTS `{$this->db_prefix}link_block_shop` (
|
||||
`id_link_block` int(10) unsigned NOT NULL auto_increment,
|
||||
`id_shop` int(10) unsigned NOT NULL,
|
||||
PRIMARY KEY (`id_link_block`, `id_shop`)
|
||||
) ENGINE=$engine DEFAULT CHARSET=utf8",
|
||||
];
|
||||
foreach ($queries as $query) {
|
||||
$success &= $this->db->execute($query);
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
public function dropTables()
|
||||
{
|
||||
$sql = "DROP TABLE IF EXISTS
|
||||
`{$this->db_prefix}link_block`,
|
||||
`{$this->db_prefix}link_block_lang`,
|
||||
`{$this->db_prefix}link_block_shop`";
|
||||
|
||||
return $this->db->execute($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function installFixtures()
|
||||
{
|
||||
$success = true;
|
||||
$id_hook = (int) Hook::getIdByName('displayFooter');
|
||||
$queries = [
|
||||
'INSERT INTO `' . $this->db_prefix . 'link_block` (`id_link_block`, `id_hook`, `position`, `content`) VALUES
|
||||
(1, ' . $id_hook . ', 0, \'{"cms":[false],"product":["prices-drop","new-products","best-sales"],"static":[false]}\'),
|
||||
(2, ' . $id_hook . ', 1, \'{"cms":["1","2","3","4","5"],"product":[false],"static":["contact","sitemap","stores"]}\');',
|
||||
];
|
||||
foreach (Language::getLanguages(true, Context::getContext()->shop->id) as $lang) {
|
||||
$queries[] = 'INSERT INTO `' . $this->db_prefix . 'link_block_lang` (`id_link_block`, `id_lang`, `name`) VALUES
|
||||
(1, ' . (int) $lang['id_lang'] . ', "' . pSQL($this->translator->trans('Products', array(), 'Modules.Linklist.Shop', $lang['locale'])) . '"),
|
||||
(2, ' . (int) $lang['id_lang'] . ', "' . pSQL($this->translator->trans('Our company', array(), 'Modules.Linklist.Shop', $lang['locale'])) . '")'
|
||||
;
|
||||
}
|
||||
foreach ($queries as $query) {
|
||||
$success &= $this->db->execute($query);
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
}
|
||||
139
modules/ps_linklist/src/Model/LinkBlock.php
Normal file
139
modules/ps_linklist/src/Model/LinkBlock.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\LinkList\Model;
|
||||
|
||||
/**
|
||||
* Class LinkBlock.
|
||||
*/
|
||||
class LinkBlock extends \ObjectModel
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $id_link_block;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $id_hook;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $position;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $content;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $custom_content;
|
||||
|
||||
/**
|
||||
* @see ObjectModel::$definition
|
||||
*/
|
||||
public static $definition = array(
|
||||
'table' => 'link_block',
|
||||
'primary' => 'id_link_block',
|
||||
'multilang' => true,
|
||||
'fields' => array(
|
||||
'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'required' => true, 'size' => 128),
|
||||
'id_hook' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true),
|
||||
'position' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true),
|
||||
'content' => array('type' => self::TYPE_STRING, 'validate' => 'isJson'),
|
||||
'custom_content' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isJson'),
|
||||
),
|
||||
);
|
||||
|
||||
public function __construct($id = null, $id_lang = null, $id_shop = null)
|
||||
{
|
||||
parent::__construct($id, $id_lang, $id_shop);
|
||||
|
||||
if ($this->id) {
|
||||
$this->content = json_decode($this->content, true);
|
||||
if ($this->custom_content) {
|
||||
$this->custom_content = array_map(
|
||||
function ($el) {
|
||||
return json_decode($el, true);
|
||||
},
|
||||
$this->custom_content
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_null($this->content)) {
|
||||
$this->content = array(
|
||||
'cms' => array(),
|
||||
'product' => array(),
|
||||
'static' => array(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function add($auto_date = true, $null_values = false)
|
||||
{
|
||||
if (is_array($this->content)) {
|
||||
$this->content = json_encode($this->content);
|
||||
}
|
||||
|
||||
if (!$this->position) {
|
||||
$this->position = 1;
|
||||
}
|
||||
|
||||
$return = parent::add($auto_date, $null_values);
|
||||
$this->content = json_decode($this->content, true);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function update($auto_date = true, $null_values = false)
|
||||
{
|
||||
if (is_array($this->content)) {
|
||||
$this->content = json_encode($this->content);
|
||||
}
|
||||
|
||||
$return = parent::update($auto_date, $null_values);
|
||||
$this->content = json_decode($this->content, true);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function toArray()
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'id_link_block' => $this->id_link_block,
|
||||
'name' => $this->name,
|
||||
'id_hook' => $this->id_hook,
|
||||
'position' => $this->position,
|
||||
'content' => $this->content,
|
||||
'custom_content' => $this->custom_content,
|
||||
];
|
||||
}
|
||||
}
|
||||
46
modules/ps_linklist/src/Model/LinkBlockLang.php
Normal file
46
modules/ps_linklist/src/Model/LinkBlockLang.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\LinkList\Model;
|
||||
|
||||
use DataLangCore;
|
||||
|
||||
/**
|
||||
* Class LinkBlockLang.
|
||||
*/
|
||||
class LinkBlockLang extends DataLangCore
|
||||
{
|
||||
// Don't replace domain in init() with $this->domain for translation parsing
|
||||
protected $domain = 'Modules.Linklist.Shop';
|
||||
|
||||
protected $keys = array('id_link_block');
|
||||
|
||||
protected $fieldsToUpdate = array('name');
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$this->fieldNames = array(
|
||||
'name' => array(
|
||||
md5('Products') => $this->translator->trans('Products', array(), 'Modules.Linklist.Shop', $this->locale),
|
||||
md5('Our company') => $this->translator->trans('Our company', array(), 'Modules.Linklist.Shop', $this->locale),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
28
modules/ps_linklist/src/Model/index.php
Normal file
28
modules/ps_linklist/src/Model/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
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;
|
||||
218
modules/ps_linklist/src/Presenter/LinkBlockPresenter.php
Normal file
218
modules/ps_linklist/src/Presenter/LinkBlockPresenter.php
Normal file
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\LinkList\Presenter;
|
||||
|
||||
use PrestaShop\Module\LinkList\Model\LinkBlock;
|
||||
use Tools;
|
||||
|
||||
/**
|
||||
* Class LinkBlockPresenter.
|
||||
*/
|
||||
class LinkBlockPresenter
|
||||
{
|
||||
private $link;
|
||||
private $language;
|
||||
|
||||
/**
|
||||
* LinkBlockPresenter constructor.
|
||||
*
|
||||
* @param \Link $link
|
||||
* @param \Language $language
|
||||
*/
|
||||
public function __construct(\Link $link, \Language $language)
|
||||
{
|
||||
$this->link = $link;
|
||||
$this->language = $language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param LinkBlock $cmsBlock
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \PrestaShopDatabaseException
|
||||
* @throws \PrestaShopException
|
||||
*/
|
||||
public function present(LinkBlock $cmsBlock)
|
||||
{
|
||||
return array(
|
||||
'id' => (int) $cmsBlock->id,
|
||||
'title' => $cmsBlock->name[(int) $this->language->id],
|
||||
'hook' => (new \Hook((int) $cmsBlock->id_hook))->name,
|
||||
'position' => $cmsBlock->position,
|
||||
'links' => $this->makeLinks($cmsBlock->content, $cmsBlock->custom_content),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the url if is an external link.
|
||||
*
|
||||
* @param $url
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isExternalLink($url)
|
||||
{
|
||||
$baseLink = preg_replace('#^(http)s?://#', '', $this->link->getBaseLink());
|
||||
$url = Tools::strtolower($url);
|
||||
|
||||
if (preg_match('#^(http)s?://#', $url) && !preg_match('#^(http)s?://' . preg_quote(rtrim($baseLink, '/'), '/') . '#', $url)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $content
|
||||
* @param array $custom_content
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function makeLinks($content, $custom_content)
|
||||
{
|
||||
$cmsLinks = $productLinks = $staticsLinks = $customLinks = array();
|
||||
|
||||
if (isset($content['cms'])) {
|
||||
$cmsLinks = $this->makeCmsLinks($content['cms']);
|
||||
}
|
||||
|
||||
if (isset($content['product'])) {
|
||||
$productLinks = $this->makeProductLinks($content['product']);
|
||||
}
|
||||
|
||||
if (isset($content['static'])) {
|
||||
$staticsLinks = $this->makeStaticLinks($content['static']);
|
||||
}
|
||||
|
||||
$customLinks = $this->makeCustomLinks($custom_content);
|
||||
|
||||
return array_merge(
|
||||
$cmsLinks,
|
||||
$productLinks,
|
||||
$staticsLinks,
|
||||
$customLinks
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $cmsIds
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \PrestaShopDatabaseException
|
||||
* @throws \PrestaShopException
|
||||
*/
|
||||
private function makeCmsLinks($cmsIds)
|
||||
{
|
||||
$cmsLinks = array();
|
||||
foreach ($cmsIds as $cmsId) {
|
||||
$cms = new \CMS((int) $cmsId);
|
||||
if (null !== $cms->id && $cms->active) {
|
||||
$cmsLinks[] = array(
|
||||
'id' => 'link-cms-page-' . $cms->id,
|
||||
'class' => 'cms-page-link',
|
||||
'title' => $cms->meta_title[(int) $this->language->id],
|
||||
'description' => $cms->meta_description[(int) $this->language->id],
|
||||
'url' => $this->link->getCMSLink($cms),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $cmsLinks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $productIds
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function makeProductLinks($productIds)
|
||||
{
|
||||
$productLinks = array();
|
||||
foreach ($productIds as $productId) {
|
||||
if (false !== $productId) {
|
||||
$meta = \Meta::getMetaByPage($productId, (int) $this->language->id);
|
||||
$productLinks[] = array(
|
||||
'id' => 'link-product-page-' . $productId,
|
||||
'class' => 'cms-page-link',
|
||||
'title' => $meta['title'],
|
||||
'description' => $meta['description'],
|
||||
'url' => $this->link->getPageLink($productId, true),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $productLinks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $staticIds
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function makeStaticLinks($staticIds)
|
||||
{
|
||||
$staticLinks = array();
|
||||
foreach ($staticIds as $staticId) {
|
||||
if (false !== $staticId) {
|
||||
$meta = \Meta::getMetaByPage($staticId, (int) $this->language->id);
|
||||
$staticLinks[] = array(
|
||||
'id' => 'link-static-page-' . $staticId,
|
||||
'class' => 'cms-page-link',
|
||||
'title' => $meta['title'],
|
||||
'description' => $meta['description'],
|
||||
'url' => $this->link->getPageLink($staticId, true),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $staticLinks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $customContent
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function makeCustomLinks($customContent)
|
||||
{
|
||||
$customLinks = array();
|
||||
|
||||
if (isset($customContent[$this->language->id])) {
|
||||
$customLinks = $customContent[$this->language->id];
|
||||
|
||||
$self = $this;
|
||||
$customLinks = array_map(function ($el) use ($self) {
|
||||
return array(
|
||||
'id' => 'link-custom-page-' . Tools::link_rewrite($el['title']),
|
||||
'class' => 'custom-page-link',
|
||||
'title' => $el['title'],
|
||||
'description' => '',
|
||||
'url' => $el['url'],
|
||||
'target' => $self->isExternalLink($el['url']) ? '_blank' : '',
|
||||
);
|
||||
}, array_filter($customLinks));
|
||||
}
|
||||
|
||||
return $customLinks;
|
||||
}
|
||||
}
|
||||
28
modules/ps_linklist/src/Presenter/index.php
Normal file
28
modules/ps_linklist/src/Presenter/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
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;
|
||||
385
modules/ps_linklist/src/Repository/LinkBlockRepository.php
Normal file
385
modules/ps_linklist/src/Repository/LinkBlockRepository.php
Normal file
@@ -0,0 +1,385 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
namespace PrestaShop\Module\LinkList\Repository;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Driver\Statement;
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use PrestaShop\PrestaShop\Core\Exception\DatabaseException;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Hook;
|
||||
|
||||
/**
|
||||
* Class LinkBlockRepository.
|
||||
*/
|
||||
class LinkBlockRepository
|
||||
{
|
||||
/**
|
||||
* @var Connection
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $dbPrefix;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $languages;
|
||||
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
/**
|
||||
* LinkBlockRepository constructor.
|
||||
*
|
||||
* @param Connection $connection
|
||||
* @param string $dbPrefix
|
||||
* @param array $languages
|
||||
* @param TranslatorInterface $translator
|
||||
*/
|
||||
public function __construct(
|
||||
Connection $connection,
|
||||
$dbPrefix,
|
||||
array $languages,
|
||||
TranslatorInterface $translator
|
||||
) {
|
||||
$this->connection = $connection;
|
||||
$this->dbPrefix = $dbPrefix;
|
||||
$this->languages = $languages;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of hook with associated Link blocks.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHooksWithLinks()
|
||||
{
|
||||
$qb = $this->connection->createQueryBuilder();
|
||||
$qb
|
||||
->select('h.id_hook, h.name, h.title')
|
||||
->from($this->dbPrefix . 'link_block', 'lb')
|
||||
->leftJoin('lb', $this->dbPrefix . 'hook', 'h', 'lb.id_hook = h.id_hook')
|
||||
->groupBy('h.id_hook')
|
||||
->orderBy('h.name')
|
||||
;
|
||||
|
||||
return $qb->execute()->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws DatabaseException
|
||||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
$idHook = $data['id_hook'];
|
||||
$maxPosition = $this->getHookMaxPosition($idHook);
|
||||
|
||||
$qb = $this->connection->createQueryBuilder();
|
||||
$qb
|
||||
->insert($this->dbPrefix . 'link_block')
|
||||
->values([
|
||||
'id_hook' => ':idHook',
|
||||
'position' => ':position',
|
||||
'content' => ':content',
|
||||
])
|
||||
->setParameters([
|
||||
'idHook' => $idHook,
|
||||
'position' => null !== $maxPosition ? $maxPosition + 1 : 0,
|
||||
'content' => json_encode([
|
||||
'cms' => empty($data['cms']) ? [false] : $data['cms'],
|
||||
'static' => empty($data['static']) ? [false] : $data['static'],
|
||||
'product' => empty($data['product']) ? [false] : $data['product'],
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->executeQueryBuilder($qb, 'Link block error');
|
||||
$linkBlockId = $this->connection->lastInsertId();
|
||||
|
||||
$this->updateLanguages($linkBlockId, $data['block_name'], $data['custom_content']);
|
||||
|
||||
return $linkBlockId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $linkBlockId
|
||||
* @param array $data
|
||||
*
|
||||
* @throws DatabaseException
|
||||
*/
|
||||
public function update($linkBlockId, array $data)
|
||||
{
|
||||
$qb = $this->connection->createQueryBuilder();
|
||||
$qb
|
||||
->update($this->dbPrefix . 'link_block', 'lb')
|
||||
->andWhere('lb.id_link_block = :linkBlockId')
|
||||
->set('id_hook', ':idHook')
|
||||
->set('content', ':content')
|
||||
->setParameters([
|
||||
'linkBlockId' => $linkBlockId,
|
||||
'idHook' => $data['id_hook'],
|
||||
'content' => json_encode([
|
||||
'cms' => empty($data['cms']) ? [false] : $data['cms'],
|
||||
'static' => empty($data['static']) ? [false] : $data['static'],
|
||||
'product' => empty($data['product']) ? [false] : $data['product'],
|
||||
]),
|
||||
])
|
||||
;
|
||||
$this->executeQueryBuilder($qb, 'Link block error');
|
||||
|
||||
$this->updateLanguages($linkBlockId, $data['block_name'], $data['custom_content']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $idLinkBlock
|
||||
*
|
||||
* @throws DatabaseException
|
||||
*/
|
||||
public function delete($idLinkBlock)
|
||||
{
|
||||
$tableNames = [
|
||||
'link_block_shop',
|
||||
'link_block_lang',
|
||||
'link_block',
|
||||
];
|
||||
|
||||
foreach ($tableNames as $tableName) {
|
||||
$qb = $this->connection->createQueryBuilder();
|
||||
$qb
|
||||
->delete($this->dbPrefix . $tableName)
|
||||
->andWhere('id_link_block = :idLinkBlock')
|
||||
->setParameter('idLinkBlock', $idLinkBlock)
|
||||
;
|
||||
$this->executeQueryBuilder($qb, 'Delete error');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public function createTables()
|
||||
{
|
||||
$errors = [];
|
||||
$engine = _MYSQL_ENGINE_;
|
||||
$this->dropTables();
|
||||
|
||||
$queries = [
|
||||
"CREATE TABLE IF NOT EXISTS `{$this->dbPrefix}link_block`(
|
||||
`id_link_block` int(10) unsigned NOT NULL auto_increment,
|
||||
`id_hook` int(1) unsigned DEFAULT NULL,
|
||||
`position` int(10) unsigned NOT NULL default '0',
|
||||
`content` text default NULL,
|
||||
PRIMARY KEY (`id_link_block`)
|
||||
) ENGINE=$engine DEFAULT CHARSET=utf8",
|
||||
"CREATE TABLE IF NOT EXISTS `{$this->dbPrefix}link_block_lang`(
|
||||
`id_link_block` int(10) unsigned NOT NULL,
|
||||
`id_lang` int(10) unsigned NOT NULL,
|
||||
`name` varchar(40) NOT NULL default '',
|
||||
`custom_content` text default NULL,
|
||||
PRIMARY KEY (`id_link_block`, `id_lang`)
|
||||
) ENGINE=$engine DEFAULT CHARSET=utf8",
|
||||
"CREATE TABLE IF NOT EXISTS `{$this->dbPrefix}link_block_shop` (
|
||||
`id_link_block` int(10) unsigned NOT NULL auto_increment,
|
||||
`id_shop` int(10) unsigned NOT NULL,
|
||||
PRIMARY KEY (`id_link_block`, `id_shop`)
|
||||
) ENGINE=$engine DEFAULT CHARSET=utf8",
|
||||
];
|
||||
|
||||
foreach ($queries as $query) {
|
||||
$statement = $this->connection->executeQuery($query);
|
||||
if (0 != (int) $statement->errorCode()) {
|
||||
$errors[] = [
|
||||
'key' => json_encode($statement->errorInfo()),
|
||||
'parameters' => [],
|
||||
'domain' => 'Admin.Modules.Notification',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public function installFixtures()
|
||||
{
|
||||
$errors = [];
|
||||
$id_hook = (int) Hook::getIdByName('displayFooter');
|
||||
|
||||
$queries = [
|
||||
'INSERT INTO `' . $this->dbPrefix . 'link_block` (`id_link_block`, `id_hook`, `position`, `content`) VALUES
|
||||
(1, ' . $id_hook . ', 0, \'{"cms":[false],"product":["prices-drop","new-products","best-sales"],"static":[false]}\'),
|
||||
(2, ' . $id_hook . ', 1, \'{"cms":["1","2","3","4","5"],"product":[false],"static":["contact","sitemap","stores"]}\');',
|
||||
];
|
||||
|
||||
foreach ($this->languages as $lang) {
|
||||
$queries[] = 'INSERT INTO `' . $this->dbPrefix . 'link_block_lang` (`id_link_block`, `id_lang`, `name`) VALUES
|
||||
(1, ' . (int) $lang['id_lang'] . ', "' . pSQL($this->translator->trans('Products', array(), 'Modules.Linklist.Shop', $lang['locale'])) . '"),
|
||||
(2, ' . (int) $lang['id_lang'] . ', "' . pSQL($this->translator->trans('Our company', array(), 'Modules.Linklist.Shop', $lang['locale'])) . '")'
|
||||
;
|
||||
}
|
||||
|
||||
foreach ($queries as $query) {
|
||||
$statement = $this->connection->executeQuery($query);
|
||||
if (0 != (int) $statement->errorCode()) {
|
||||
$errors[] = [
|
||||
'key' => json_encode($statement->errorInfo()),
|
||||
'parameters' => [],
|
||||
'domain' => 'Admin.Modules.Notification',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*
|
||||
* @throws \Doctrine\DBAL\DBALException
|
||||
*/
|
||||
public function dropTables()
|
||||
{
|
||||
$errors = [];
|
||||
$tableNames = [
|
||||
'link_block_shop',
|
||||
'link_block_lang',
|
||||
'link_block',
|
||||
];
|
||||
foreach ($tableNames as $tableName) {
|
||||
$sql = 'DROP TABLE IF EXISTS ' . $this->dbPrefix . $tableName;
|
||||
$statement = $this->connection->executeQuery($sql);
|
||||
if ($statement instanceof Statement && 0 != (int) $statement->errorCode()) {
|
||||
$errors[] = [
|
||||
'key' => json_encode($statement->errorInfo()),
|
||||
'parameters' => [],
|
||||
'domain' => 'Admin.Modules.Notification',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $linkBlockId
|
||||
* @param array $blockName
|
||||
* @param array $custom
|
||||
*
|
||||
* @throws DatabaseException
|
||||
*/
|
||||
private function updateLanguages($linkBlockId, array $blockName, array $custom)
|
||||
{
|
||||
foreach ($this->languages as $language) {
|
||||
$qb = $this->connection->createQueryBuilder();
|
||||
$qb
|
||||
->select('lbl.id_link_block')
|
||||
->from($this->dbPrefix . 'link_block_lang', 'lbl')
|
||||
->andWhere('lbl.id_link_block = :linkBlockId')
|
||||
->andWhere('lbl.id_lang = :langId')
|
||||
->setParameter('linkBlockId', $linkBlockId)
|
||||
->setParameter('langId', $language['id_lang'])
|
||||
;
|
||||
$foundRows = $qb->execute()->rowCount();
|
||||
|
||||
$qb = $this->connection->createQueryBuilder();
|
||||
if (!$foundRows) {
|
||||
$qb
|
||||
->insert($this->dbPrefix . 'link_block_lang')
|
||||
->values([
|
||||
'id_link_block' => ':linkBlockId',
|
||||
'id_lang' => ':langId',
|
||||
'name' => ':name',
|
||||
'custom_content' => ':customContent',
|
||||
])
|
||||
;
|
||||
} else {
|
||||
$qb
|
||||
->update($this->dbPrefix . 'link_block_lang', 'lbl')
|
||||
->set('name', ':name')
|
||||
->set('custom_content', ':customContent')
|
||||
->andWhere('lbl.id_link_block = :linkBlockId')
|
||||
->andWhere('lbl.id_lang = :langId')
|
||||
;
|
||||
}
|
||||
|
||||
$qb
|
||||
->setParameters([
|
||||
'linkBlockId' => $linkBlockId,
|
||||
'langId' => $language['id_lang'],
|
||||
'name' => $blockName[$language['id_lang']],
|
||||
'customContent' => empty($custom) ? null : json_encode($custom[$language['id_lang']]),
|
||||
]);
|
||||
|
||||
$this->executeQueryBuilder($qb, 'Link block language error');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param QueryBuilder $qb
|
||||
* @param string $errorPrefix
|
||||
*
|
||||
* @return Statement|int
|
||||
*
|
||||
* @throws DatabaseException
|
||||
*/
|
||||
private function executeQueryBuilder(QueryBuilder $qb, $errorPrefix = 'SQL error')
|
||||
{
|
||||
$statement = $qb->execute();
|
||||
if ($statement instanceof Statement && !empty($statement->errorInfo())) {
|
||||
throw new DatabaseException($errorPrefix . ': ' . var_export($statement->errorInfo(), true));
|
||||
}
|
||||
|
||||
return $statement;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $idHook
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
private function getHookMaxPosition($idHook)
|
||||
{
|
||||
$qb = $this->connection->createQueryBuilder();
|
||||
$qb->select('MAX(lb.position)')
|
||||
->from($this->dbPrefix . 'link_block', 'lb')
|
||||
->andWhere('lb.id_hook = :idHook')
|
||||
->setParameter('idHook', $idHook)
|
||||
;
|
||||
|
||||
return $qb->execute()->fetchColumn(0);
|
||||
}
|
||||
}
|
||||
28
modules/ps_linklist/src/Repository/index.php
Normal file
28
modules/ps_linklist/src/Repository/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
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;
|
||||
28
modules/ps_linklist/src/index.php
Normal file
28
modules/ps_linklist/src/index.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
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