garancia/controllers/front/PresseController.php
2016-10-10 15:24:25 +02:00

180 lines
5.8 KiB
PHP
Executable File

<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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:
* http://opensource.org/licenses/osl-3.0.php
* 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.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class PresseControllerCore extends FrontController
{
public $php_self = 'presse';
/**
* Assign template vars related to page content
* @see FrontController::initContent()
*/
public function setMedia()
{
parent::setMedia();
$this->addCSS(_THEME_CSS_DIR_.'presse.css');
$this->addJS(_THEME_JS_DIR_.'presse.js');
}
public function getItemsProductsOLD()
{
if(Tools::getValue('id_product'))
$id_product=Tools::getValue('id_product');
$id_shop = $this->context->shop->id;
$id_lang = $this->context->language->id;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT distinct(hss.`id_product`), pl.name, pl.link_rewrite
FROM '._DB_PREFIX_.'devspepresse_items hss
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (hss.id_product = pl.id_product)
WHERE (id_shop = '.(int)$id_shop.')
AND pl.id_lang = '.(int)$id_lang.'
ORDER BY pl.name');
}
public function getItemsProducts($active = null)
{
if(Tools::getValue('id_product'))
$id_product=Tools::getValue('id_product');
$id_shop = $this->context->shop->id;
$id_lang = $this->context->language->id;
$products_selected=$this->getItemsProductsOLD();
$produits=array();
foreach($products_selected as $produit){
if(!in_array($produit['id_product'],$produits)){
$produits[]=$produit['id_product'];
}
}
// print_r($produits);
$produits_tries=Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT distinct(pl.id_product),cp.id_category,cl.name as category_name,pl.id_lang,cl.id_lang as category_lang,pl.name,cp.position
FROM '._DB_PREFIX_.'product_lang pl
left join '._DB_PREFIX_.'category_product cp on(cp.id_product=pl.id_product)
left join '._DB_PREFIX_.'category_lang cl on(cl.id_category=cp.id_category)
WHERE pl.id_lang = '.(int)$id_lang.'
and cl.id_lang='.(int)$id_lang.'
and (cl.id_category=3
or cl.id_category=4)
ORDER BY cp.id_category asc,cp.position asc');
// print_r($produits_tries);
$new_products=array();
foreach($produits_tries as &$produit){
if(in_array($produit['id_product'],$produits))
$new_products[]=$produit;
}
return $new_products;
// pl.id_product
}
public function getItemsPresse($max=6,$page=1)
{
if($page==0)$page=1;
$min=($page-1)*$max;
if(Tools::getValue('id_product'))
$id_product=Tools::getValue('id_product');
$id_shop = $this->context->shop->id;
$id_lang = $this->context->language->id;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT hs.`id_item`,
hss.`position`,
hss.`id_product`,
hss.`active`,
hssl.`title`,
hssl.`description`,
hssl.`url`,
hssl.`legend`,
hssl.`image`
FROM '._DB_PREFIX_.'devspepresse hs
LEFT JOIN '._DB_PREFIX_.'devspepresse_items hss ON (hs.id_item = hss.id_item)
LEFT JOIN '._DB_PREFIX_.'devspepresse_items_lang hssl ON (hss.id_item = hssl.id_item)
WHERE (id_shop = '.(int)$id_shop.')
AND hssl.id_lang = '.(int)$id_lang.'
AND hss.`active` = 1
'.(isset($id_product)?' AND hss.`id_product` = '.(int)$id_product : '').'
ORDER BY hss.position
limit '.$min.','.$max.'
');
}
public function getItemsPresseMax($nb=6)
{
if(Tools::getValue('id_product'))
$id_product=Tools::getValue('id_product');
$id_shop = $this->context->shop->id;
$id_lang = $this->context->language->id;
$max=count(Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT hs.`id_item`,
hss.`position`,
hss.`id_product`,
hss.`active`,
hssl.`title`,
hssl.`description`,
hssl.`url`,
hssl.`legend`,
hssl.`image`
FROM '._DB_PREFIX_.'devspepresse hs
LEFT JOIN '._DB_PREFIX_.'devspepresse_items hss ON (hs.id_item = hss.id_item)
LEFT JOIN '._DB_PREFIX_.'devspepresse_items_lang hssl ON (hss.id_item = hssl.id_item)
WHERE (id_shop = '.(int)$id_shop.')
AND hssl.id_lang = '.(int)$id_lang.'
AND hss.`active` = 1
'.(isset($id_product)?' AND hss.`id_product` = '.(int)$id_product : '').'
ORDER BY hss.position
'));
$nbitems=round($max/$nb);
if($nbitems==0)
$nbitems=1;
return $nbitems;
}
public function initContent()
{
// $this->context = Context::getContext();
$id_shop = $this->context->shop->id;
$id_lang = $this->context->language->id;
$this->context->smarty->assign('press',$this->getItemsPresse(6,Tools::getValue('page')));
$this->context->smarty->assign('nbPage',$this->getItemsPresseMax());
$this->context->smarty->assign('pressProducts',$this->getItemsProducts());
if(Tools::getValue('id_product'))
$this->context->smarty->assign('idProduct',Tools::getValue('id_product'));
else
$this->context->smarty->assign('idProduct',0);
if(Tools::getValue('page'))
$this->context->smarty->assign('page',Tools::getValue('page'));
else
$this->context->smarty->assign('page',1);
$this->setTemplate(_PS_THEME_DIR_.'presse.tpl');
parent::initContent();
}
}