public function reOrderPositions() { $id_banner = $this->id; $context = Context::getContext(); $id_shop = $context->shop->id; $max = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT MAX(hss.`position`) as position FROM `' . _DB_PREFIX_ . 'textbanners_banners` hss, `' . _DB_PREFIX_ . 'textbanners` hs WHERE hss.`id_textbanners_banners` = hs.`id_textbanners_banners` AND hs.`id_shop` = ' . (int) $id_shop); if ((int) $max == (int) $id_banner) { return true; } $rows = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT hss.`position` as position, hss.`id_textbanners_banners` as id_banner FROM `' . _DB_PREFIX_ . 'textbanners_banners` hss LEFT JOIN `' . _DB_PREFIX_ . 'textbanners` hs ON (hss.`id_textbanners_banners` = hs.`id_textbanners_banners`) WHERE hs.`id_shop` = ' . (int) $id_shop . ' AND hss.`position` > ' . (int) $this->position); foreach ($rows as $row) { $current_banner = new TextBanner($row['id_banner']); --$current_banner->position; $current_banner->update(); unset($current_banner); } return true; }
private function _postProcess() { $errors = array(); /* Processes bannerr */ if (Tools::isSubmit('submitbannerr')) { $res = Configuration::updateValue('textbanners_perline', (int) Tools::getValue('textbanners_perline')); $res &= Configuration::updateValue('textbanners_style', (int) Tools::getValue('textbanners_style')); $res &= Configuration::updateValue('textbanners_border', (int) Tools::getValue('textbanners_border')); $res &= Configuration::updateValue('textbanners_show', (int) Tools::getValue('textbanners_show')); $this->generateCss(); $this->clearCache(); if (!$res) { $errors[] = $this->displayError($this->l('The configuration could not be updated.')); } $this->_html .= $this->displayConfirmation($this->l('Configuration updated')); } elseif (Tools::isSubmit('changeStatus') && Tools::isSubmit('id_banner')) { $banner = new TextBanner((int) Tools::getValue('id_banner')); if ($banner->active == 0) { $banner->active = 1; } else { $banner->active = 0; } $res = $banner->update(); $this->generateCss(); $this->clearCache(); $this->_html .= $res ? $this->displayConfirmation($this->l('Configuration updated')) : $this->displayError($this->l('The configuration could not be updated.')); } elseif (Tools::isSubmit('submitbanner')) { /* Sets ID if needed */ if (Tools::getValue('id_banner')) { $banner = new TextBanner((int) Tools::getValue('id_banner')); if (!Validate::isLoadedObject($banner)) { $this->_html .= $this->displayError($this->l('Invalid id_banner')); return; } } else { $banner = new TextBanner(); } /* Sets position */ $banner->position = (int) Tools::getValue('position'); /* Sets active */ $banner->active = (int) Tools::getValue('active_banner'); $banner->icon = Tools::getValue('icon'); /* Sets colors */ $banner->icon_bg = Tools::getValue('icon_bg'); $banner->icon_c = Tools::getValue('icon_c'); $banner->title_c = Tools::getValue('title_c'); $banner->label_c = Tools::getValue('label_c'); /* Sets each langue fields */ $languages = Language::getLanguages(false); foreach ($languages as $language) { $banner->title[$language['id_lang']] = Tools::getValue('title_' . $language['id_lang']); $banner->url[$language['id_lang']] = Tools::getValue('url_' . $language['id_lang']); $banner->legend[$language['id_lang']] = Tools::getValue('legend_' . $language['id_lang']); } /* Processes if no errors */ if (!$errors) { /* Adds */ if (!Tools::getValue('id_banner')) { if (!$banner->add()) { $errors[] = $this->displayError($this->l('The banner could not be added.')); } } elseif (!$banner->update()) { $errors[] = $this->displayError($this->l('The banner could not be updated.')); } $this->generateCss(); $this->clearCache(); } } elseif (Tools::isSubmit('delete_id_banner')) { $banner = new TextBanner((int) Tools::getValue('delete_id_banner')); $res = $banner->delete(); $this->generateCss(); $this->clearCache(); if (!$res) { $this->_html .= $this->displayError('Could not delete'); } else { $this->_html .= $this->displayConfirmation($this->l('banner deleted')); } } /* Display errors if needed */ if (count($errors)) { $this->_html .= $this->displayError(implode('<br />', $errors)); } elseif (Tools::isSubmit('submitbanner') && Tools::getValue('id_banner')) { $this->_html .= $this->displayConfirmation($this->l('banner updated')); } elseif (Tools::isSubmit('submitbanner')) { $this->_html .= $this->displayConfirmation($this->l('banner added')); } }