Skip to content

Commit

Permalink
Register controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Hlavtox committed Sep 11, 2024
1 parent 7805343 commit 9c1d1e1
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 67 deletions.
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>ps_imageslider</name>
<displayName><![CDATA[Image slider]]></displayName>
<version><![CDATA[3.1.4]]></version>
<version><![CDATA[3.2.0]]></version>
<description><![CDATA[Adds an image slider to your site.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[front_office_features]]></tab>
Expand Down
40 changes: 19 additions & 21 deletions controllers/admin/AdminConfigureSlidesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,30 @@
*/
class AdminConfigureSlidesController extends ModuleAdminController
{
public $module;

/**
* This function allow to delete users
*/
public function ajaxProcessUpdateSlidesPosition()
{
$home_slider = $this->module;
$slides = [];

if (!Tools::isSubmit('secure_key') || Tools::getValue('secure_key') != $home_slider->secure_key || !Tools::getValue('action')) {
$this->ajaxDie(json_encode(['error' => true]));
}
if (empty(Tools::getValue('action')) || Tools::getValue('action') != 'updateSlidesPosition' || empty(Tools::getValue('slides'))) {
ob_end_clean();
header('Content-Type: application/json');
$this->ajaxRender(json_encode(['error' => true]));
exit;
}

if (Tools::getValue('action') == 'updateSlidesPosition' && Tools::getValue('slides')) {
$slides = Tools::getValue('slides');

foreach ($slides as $position => $id_slide) {
$res = Db::getInstance()->execute('
// Get slides and update their position
$slides = Tools::getValue('slides');
foreach ($slides as $position => $id_slide) {
Db::getInstance()->execute('
UPDATE `' . _DB_PREFIX_ . 'homeslider_slides` SET `position` = ' . (int) $position . '
WHERE `id_homeslider_slides` = ' . (int) $id_slide
);
}
);
}

// Wipe module cache
$this->module->clearCache();

$home_slider->clearCache();
}
$this->ajaxDie(json_encode(['success' => true]));
ob_end_clean();
header('Content-Type: application/json');
$this->ajaxRender(json_encode(['success' => true]));
exit;
}
}
28 changes: 0 additions & 28 deletions controllers/index.php

This file was deleted.

43 changes: 35 additions & 8 deletions ps_imageslider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,11 @@ class Ps_ImageSlider extends Module implements WidgetInterface
*/
public $secure_key;

public $adminControllers = [
'adminConfigureSlides' => 'AdminConfigureSlides',
];

public function __construct()
{
$this->name = 'ps_imageslider';
$this->tab = 'front_office_features';
$this->version = '3.1.4';
$this->version = '3.2.0';
$this->author = 'PrestaShop';
$this->need_instance = 0;
$this->secure_key = Tools::hash($this->name);
Expand All @@ -79,6 +75,7 @@ public function install()
/* Adds Module */
if (
parent::install() &&
$this->installTab() &&
$this->registerHook('displayHeader') &&
$this->registerHook('displayHome') &&
$this->registerHook('actionShopDataDuplication')
Expand Down Expand Up @@ -129,6 +126,21 @@ public function install()
return false;
}

public function installTab()
{
$tab = new Tab();
$tab->class_name = 'AdminConfigureSlides';
$tab->module = $this->name;
$tab->active = true;
$tab->id_parent = -1;
$tab->name = array_fill_keys(
Language::getIDs(false),
$this->displayName
);

return $tab->add();
}

/**
* Adds samples
*/
Expand Down Expand Up @@ -162,6 +174,9 @@ public function uninstall()
/* Deletes tables */
$res = $this->deleteTables();

/* Delete hidden tab */
$res &= $this->uninstallTab();

/* Unsets configuration */
$res &= Configuration::deleteByName('HOMESLIDER_SPEED');
$res &= Configuration::deleteByName('HOMESLIDER_PAUSE_ON_HOVER');
Expand All @@ -173,6 +188,18 @@ public function uninstall()
return false;
}

public function uninstallTab()
{
$result = true;
$id_tab = (int) Tab::getIdFromClassName('AdminConfigureSlides');
$tab = new Tab($id_tab);
if (Validate::isLoadedObject($tab)) {
$result = $tab->delete();
}

return $result;
}

/**
* Creates tables
*/
Expand Down Expand Up @@ -617,6 +644,7 @@ public function hookActionShopDataDuplication($params)

public function headerHTML()
{
// Run only on module configuration page
if ('AdminModules' !== Tools::getValue('controller') ||
Tools::getValue('configure') !== $this->name ||
Tools::getIsset('id_slide') ||
Expand All @@ -625,6 +653,7 @@ public function headerHTML()
}

$this->context->controller->addJS($this->_path . 'js/Sortable.min.js');

/* Style & js for fieldset 'slides configuration' */
$html = '<script type="text/javascript">
$(function() {
Expand All @@ -637,14 +666,12 @@ public function headerHTML()
var ajaxCallParameters = {
ajax: true,
action: "updateSlidesPosition",
secure_key: "'.$this->secure_key.'",
token: "'.Tools::getAdminTokenLite('AdminConfigureSlides') .'",
slides: sortableIdsAsData
};
$.ajax({
type: "POST",
cache: false,
url: "'.$this->context->link->getAdminLink('AdminConfigureSlides', false).'",
url: "' . $this->context->link->getAdminLink('AdminConfigureSlides') . '",
data: ajaxCallParameters
});
}
Expand Down
17 changes: 8 additions & 9 deletions controllers/admin/index.php → upgrade/upgrade-3.2.0.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
Expand All @@ -16,13 +15,13 @@
* @author PrestaShop SA <contact@prestashop.com>
* @copyright Since 2007 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');
if (!defined('_PS_VERSION_')) {
exit;
}

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;
function upgrade_module_3_2_0($object)
{
return $object->installTab();
}

0 comments on commit 9c1d1e1

Please sign in to comment.