// fixed homeslider

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11534 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
bMancone
2011-12-21 17:46:31 +00:00
parent bc6b960a80
commit 2b9f2027f5
4 changed files with 37 additions and 35 deletions
+9 -9
View File
@@ -1663,27 +1663,27 @@ CREATE TABLE IF NOT EXISTS `PREFIX_newsletter` (
) ENGINE=ENGINE_TYPE default CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `PREFIX_homeslider` (
`id_slide` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_homeslider_slides` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_shop` int(10) unsigned NOT NULL,
PRIMARY KEY (`id_slide`, `id_shop`)
PRIMARY KEY (`id_homeslider_slides`, `id_shop`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=UTF8;
CREATE TABLE IF NOT EXISTS `PREFIX_homeslider_slides` (
`id_slide` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_homeslider_slides` int(10) unsigned NOT NULL AUTO_INCREMENT,
`position` int(10) unsigned NOT NULL DEFAULT '0',
`active` tinyint(1) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id_slide`)
PRIMARY KEY (`id_homeslider_slides`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=UTF8;
CREATE TABLE IF NOT EXISTS `PREFIX_homeslider_slides_lang` (
`id_slide` int(10) unsigned NOT NULL,
`id_homeslider_slides` int(10) unsigned NOT NULL,
`id_lang` int(10) unsigned NOT NULL,
`title` varchar(255) NOT NULL,
`description` text NOT NULL,
`legend` varchar(255) NOT NULL,
`url` varchar(255) NOT NULL,
`image` varchar(255) NOT NULL,
PRIMARY KEY (`id_slide`,`id_lang`)
PRIMARY KEY (`id_homeslider_slides`,`id_lang`)
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=UTF8;
INSERT INTO `PREFIX_configuration` (name, value)
@@ -1693,12 +1693,12 @@ VALUES
("HOMESLIDER_SPEED", "1300"),
("HOMESLIDER_PAUSE", "7700");
INSERT INTO `PREFIX_homeslider` (id_slide, id_shop) VALUES (1, 1),(2, 1), (3, 1), (4, 1), (5, 1);
INSERT INTO `PREFIX_homeslider` (id_homeslider_slides, id_shop) VALUES (1, 1),(2, 1), (3, 1), (4, 1), (5, 1);
INSERT INTO `PREFIX_homeslider_slides` (id_slide, position, active)
INSERT INTO `PREFIX_homeslider_slides` (id_homeslider_slides, position, active)
VALUES (1, 1, 1), (2, 2, 1), (3, 3, 1), (4, 4, 1), (5, 5, 1);
INSERT INTO `PREFIX_homeslider_slides_lang` (id_slide, id_lang, title, description, legend, url, image) VALUES
INSERT INTO `PREFIX_homeslider_slides_lang` (id_homeslider_slides, id_lang, title, description, legend, url, image) VALUES
(1, 1, "Add Ons", "improve your e-commerce site by adding new features", "addons", "http://addons.prestashop.com", "sample-1.jpg"),
(2, 1, "PrestaBox", "Your e-shop ready to use open in 10 minutes", "prestabox", "http://www.prestabox.com", "sample-2.jpg"),
(3, 1, "Support", "contact PrestaShop Support team to help you in installing or configuring your software", "support", "http://support.prestashop.com", "sample-3.jpg"),
+7 -7
View File
@@ -61,12 +61,12 @@ class HomeSlide extends ObjectModel
protected $tables = array('homeslider_slides, homeslider_slides_lang');
protected $table = 'homeslider_slides';
protected $identifier = 'id_slide';
protected $identifier = 'id_homeslider_slides';
public function getFields()
{
$this->validateFields();
$fields['id_slide'] = (int)$this->id;
$fields['id_homeslider_slides'] = (int)$this->id;
$fields['active'] = (int)$this->active;
$fields['position'] = (int)$this->position;
return $fields;
@@ -96,7 +96,7 @@ class HomeSlide extends ObjectModel
$res = parent::add($autodate, $null_values);
$res &= Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'homeslider` (`id_shop`, `id_slide`)
INSERT INTO `'._DB_PREFIX_.'homeslider` (`id_shop`, `id_homeslider_slides`)
VALUES('.(int)$id_shop.', '.(int)$this->id.')'
);
return $res;
@@ -115,7 +115,7 @@ class HomeSlide extends ObjectModel
$res &= $this->reOrderPositions();
$res &= Db::getInstance()->execute('
DELETE FROM `'._DB_PREFIX_.'homeslider`
WHERE `id_slide` = '.(int)$this->id
WHERE `id_homeslider_slides` = '.(int)$this->id
);
$res &= parent::delete();
@@ -131,16 +131,16 @@ class HomeSlide extends ObjectModel
$max = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT MAX(hss.`position`) as position
FROM `'._DB_PREFIX_.'homeslider_slides` hss, `'._DB_PREFIX_.'homeslider` hs
WHERE hss.`id_slide` = hs.`id_slide` AND hs.`id_shop` = '.(int)$id_shop
WHERE hss.`id_homeslider_slides` = hs.`id_homeslider_slides` AND hs.`id_shop` = '.(int)$id_shop
);
if ((int)$max == (int)$id_slide)
return true;
$rows = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT hss.`position` as position, hss.`id_slide` as id_slide
SELECT hss.`position` as position, hss.`id_homeslider_slides` as id_slide
FROM `'._DB_PREFIX_.'homeslider_slides` hss, `'._DB_PREFIX_.'homeslider` hs
WHERE hss.`id_slide` = hs.`id_slide` AND hs.`id_shop` = '.(int)$id_shop.' AND hss.`position` > '.(int)$this->position
WHERE hss.`id_homeslider_slides` = hs.`id_homeslider_slides` AND hs.`id_shop` = '.(int)$id_shop.' AND hss.`position` > '.(int)$this->position
);
if (!$rows)
+3 -3
View File
@@ -32,7 +32,7 @@ $context = Context::getContext();
$homeSlider = new HomeSlider();
$slides = array();
if (!Tools::isSubmit('secure_key') OR Tools::getValue('secure_key') != $homeSlider->secure_key OR !Tools::getValue('action'))
if (!Tools::isSubmit('secure_key') || Tools::getValue('secure_key') != $homeSlider->secure_key || !Tools::getValue('action'))
die(1);
if (Tools::getValue('action') == 'updateSlidesPosition' && Tools::getValue('slides'))
@@ -43,8 +43,8 @@ if (Tools::getValue('action') == 'updateSlidesPosition' && Tools::getValue('slid
foreach ($slides as $position => $id_slide)
{
$res = Db::getInstance()->execute('
UPDATE `'._DB_PREFIX_.'homeslider_slides` SET `position` = '.(int)($position).'
WHERE `id_slide` = '.(int)($id_slide)
UPDATE `'._DB_PREFIX_.'homeslider_slides` SET `position` = '.(int)$position.'
WHERE `id_slide` = '.(int)$id_slide
);
}
+18 -16
View File
@@ -57,7 +57,7 @@ class HomeSlider extends Module
public function install()
{
/* Adds Module */
if (parent::install() && $this->registerHook('displayHome') && $this->registerHook('backOfficeTop') && $this->registerHook('displayHeader'))
if (parent::install() && $this->registerHook('displayHome') && $this->registerHook('displayHeader'))
{
/* Sets up configuration */
$res = Configuration::updateValue('HOMESLIDER_WIDTH', '535');
@@ -73,7 +73,7 @@ class HomeSlider extends Module
public function uninstall()
{
/* Deletes Module */
if (parent::uninstall() && $this->unregisterHook('home') && $this->unregisterHook('backOfficeTop') && $this->unregisterHook('header'))
if (parent::uninstall() && $this->unregisterHook('home') && $this->unregisterHook('header'))
{
/* Deletes tables */
$res = $this->deleteTables();
@@ -92,33 +92,33 @@ class HomeSlider extends Module
/* Slides */
$res = (bool)Db::getInstance()->execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'homeslider` (
`id_slide` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_homeslider_slides` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_shop` int(10) unsigned NOT NULL,
PRIMARY KEY (`id_slide`, `id_shop`)
PRIMARY KEY (`id_homeslider_slides`, `id_shop`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
');
/* Slides configuration */
$res &= Db::getInstance()->execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'homeslider_slides` (
`id_slide` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_homeslider_slides` int(10) unsigned NOT NULL AUTO_INCREMENT,
`position` int(10) unsigned NOT NULL DEFAULT \'0\',
`active` tinyint(1) unsigned NOT NULL DEFAULT \'0\',
PRIMARY KEY (`id_slide`)
PRIMARY KEY (`id_homeslider_slides`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
');
/* Slides lang configuration */
$res &= Db::getInstance()->execute('
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'homeslider_slides_lang` (
`id_slide` int(10) unsigned NOT NULL,
`id_homeslider_slides` int(10) unsigned NOT NULL,
`id_lang` int(10) unsigned NOT NULL,
`title` varchar(255) NOT NULL,
`description` text NOT NULL,
`legend` varchar(255) NOT NULL,
`url` varchar(255) NOT NULL,
`image` varchar(255) NOT NULL,
PRIMARY KEY (`id_slide`,`id_lang`)
PRIMARY KEY (`id_homeslider_slides`,`id_lang`)
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=UTF8;
');
@@ -140,6 +140,7 @@ class HomeSlider extends Module
public function getContent()
{
$this->_html .= $this->headerHTML();
$this->_html .= '<h2>'.$this->displayName.'.</h2>';
/* Validate & process */
@@ -579,17 +580,18 @@ class HomeSlider extends Module
{
if (!$this->getSlides(true))
return;
$this->context->controller->addJqueryUI('ui.sortable');
$this->context->controller->addJS($this->_path.'js/jquery.bxSlider.min.js');
$this->context->controller->addCSS($this->_path.'bx_styles.css');
$this->context->controller->addJS($this->_path.'js/homeslider.js');
}
public function hookBackOfficeTop()
public function headerHTML()
{
if (Tools::getValue('controller') != 'AdminModules' && Tools::getValue('configure') != $this->name)
return;
$this->context->controller->addJqueryUI('ui.sortable');
/* Style & js for fieldset 'slides configuration' */
$html = '
<style>
@@ -631,7 +633,7 @@ class HomeSlider extends Module
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT MAX(hss.`position`) AS `next_position`
FROM `'._DB_PREFIX_.'homeslider_slides` hss, `'._DB_PREFIX_.'homeslider` hs
WHERE hss.`id_slide` = hs.`id_slide` AND hs.`id_shop` = '.(int)$this->context->shop->getId()
WHERE hss.`id_homeslider_slides` = hs.`id_homeslider_slides` AND hs.`id_shop` = '.(int)$this->context->shop->getId()
);
return (++$row['next_position']);
@@ -644,7 +646,7 @@ class HomeSlider extends Module
$id_lang = $this->context->language->id;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT hs.`id_slide`,
SELECT hs.`id_homeslider_slides` as id_slide,
hssl.`image`,
hss.`position`,
hss.`active`,
@@ -653,8 +655,8 @@ class HomeSlider extends Module
hssl.`legend`,
hssl.`description`
FROM '._DB_PREFIX_.'homeslider hs
LEFT JOIN '._DB_PREFIX_.'homeslider_slides hss ON (hs.id_slide = hss.id_slide)
LEFT JOIN '._DB_PREFIX_.'homeslider_slides_lang hssl ON (hssl.id_slide = hs.id_slide)
LEFT JOIN '._DB_PREFIX_.'homeslider_slides hss ON (hs.id_homeslider_slides = hss.id_homeslider_slides)
LEFT JOIN '._DB_PREFIX_.'homeslider_slides_lang hssl ON (hss.id_homeslider_slides = hssl.id_homeslider_slides)
WHERE (id_shop = '.(int)$id_shop.' OR id_shop = 1)
AND hssl.id_lang = '.(int)$id_lang.
($active ? ' AND hss.`active` = 1' : ' ').'
@@ -674,9 +676,9 @@ class HomeSlider extends Module
public function slideExists($id_slide)
{
$req = 'SELECT hs.`id_slide`
$req = 'SELECT hs.`id_homeslider_slides` as id_slide
FROM `'._DB_PREFIX_.'homeslider` hs
WHERE hs.`id_slide` = '.(int)$id_slide;
WHERE hs.`id_homeslider_slides` = '.(int)$id_slide;
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($req);
return ($row);
}