// Context part 5

This commit is contained in:
tDidierjean
2011-07-13 15:24:38 +00:00
parent cb3f2f7b52
commit b09c76f5b4
89 changed files with 417 additions and 441 deletions
+12 -6
View File
@@ -37,7 +37,7 @@ abstract class AdminTabCore
protected $identifier = false;
/** @var string Tab name */
public $name;
public $className;
/** @var string Security token */
public $token;
@@ -141,7 +141,7 @@ abstract class AdminTabCore
/** @var string specificConfirmDelete */
public $specificConfirmDelete = NULL;
public $currentIndex = '';
public static $currentIndex;
protected $identifiersDnd = array('id_product' => 'id_product', 'id_category' => 'id_category_to_move','id_cms_category' => 'id_cms_category_to_move', 'id_cms' => 'id_cms');
@@ -171,9 +171,15 @@ abstract class AdminTabCore
public function __construct()
{
global $cookie;
global $cookie, $currentIndex;
$context = Context::getContext();
$context->tab = $this;
/*$currentIndex = $_SERVER['SCRIPT_NAME'].($tab ? '?tab='.$tab : '');
if ($back = Tools::getValue('back'))
$currentIndex .= '&back='.urlencode($back);
$this->currentIndex = $currentIndex;*/
$this->id = Tab::getCurrentTabId();
$this->_conf = array(
1 => $this->l('Deletion successful'), 2 => $this->l('Selection successfully deleted'),
@@ -1709,7 +1715,7 @@ abstract class AdminTabCore
<script type="text/javascript">
id_language = Number('.$defaultLanguage.');
</script>
<form action="'.$this->currentIndex.'" id="'.$tab['name'].'" name="'.$tab['name'].'" method="post">
<form action="'.self::$currentIndex.'" id="'.$tab['name'].'" name="'.$tab['name'].'" method="post">
<fieldset>';
echo (isset($this->optionTitle) ? '<legend>
<img src="'.(!empty($tab['module']) && file_exists($_SERVER['DOCUMENT_ROOT']._MODULE_DIR_.$tab['module'].'/'.$tab['class_name'].'.gif') ? _MODULE_DIR_.$tab['module'].'/' : '../img/t/').$tab['class_name'].'.gif" />'
@@ -2033,7 +2039,7 @@ abstract class AdminTabCore
{
$html = '
<table cellpadding="0" cellspacing="0" class="table">
<form name="updateAssoShop" action="'.$this->currentIndex.'&submitFields'.$this->table.'=1&token='.$this->token.'" method="post">
<form name="updateAssoShop" action="'.self::$currentIndex.'&submitFields'.$this->table.'=1&token='.$this->token.'" method="post">
<input type="hidden" name="assoShopClass" value="'.$this->className.'" />
<tr>
<th style="width: 200px">'.$this->l('Shop association').'</th>';
@@ -2091,7 +2097,7 @@ abstract class AdminTabCore
$assos[$row['id_group_shop']][] = $row[$this->identifier];
if (!$this->_object)
{
$html = '<form name="updateAssoGroupShop" action="'.$this->currentIndex.'&submitFields'.$this->table.'=1&token='.$this->token.'" method="post">
$html = '<form name="updateAssoGroupShop" action="'.self::$currentIndex.'&submitFields'.$this->table.'=1&token='.$this->token.'" method="post">
<input type="hidden" name="assoGroupShopClass" value="'.$this->className.'" />
<table cellpadding="0" cellspacing="0" class="table">
<tr>
+10 -16
View File
@@ -176,11 +176,13 @@ class CMSCategoryCore extends ObjectModel
);
}
static public function getRecurseCategory($id_lang = _USER_ID_LANG_, $current = 1, $active = 1, $links = 0, $id_shop = false, $context = null)
static public function getRecurseCategory($id_lang = null, $current = 1, $active = 1, $links = 0, $id_shop = false, $context = null)
{
if (!$context)
$context = Context::getContext();
$id_lang = is_null($id_lang) ? $context->language->id : $id_lang;
$category = Db::getInstance()->getRow('
SELECT c.`id_cms_category`, c.`id_parent`, c.`level_depth`, cl.`name`, cl.`link_rewrite`
FROM `'._DB_PREFIX_.'cms_category` c
@@ -399,16 +401,6 @@ class CMSCategoryCore extends ObjectModel
{
return self::getChildren(1, $id_lang, $active);
}
/**
* @deprecated
**/
static public function getRootCMSCategory($id_lang = NULL)
{
Tools::displayAsDeprecated();
//get idLang
$id_lang = is_null($id_lang) ? _USER_ID_LANG_ : (int)($id_lang);
return new CMSCategory (1, $id_lang);
}
static public function getChildren($id_parent, $id_lang, $active = true)
{
@@ -544,20 +536,22 @@ class CMSCategoryCore extends ObjectModel
* @param integer $id_lang Language ID
* @return array Corresponding categories
*/
public function getParentsCategories($idLang = null)
public function getParentsCategories($idLang = null, $context = null)
{
if (!$context)
$context = Context::getContext();
//get idLang
$idLang = is_null($idLang) ? _USER_ID_LANG_ : (int)($idLang);
$idLang = is_null($idLang) ? $context->language->id : $idLang;
$categories = null;
$idCurrent = (int)($this->id);
$idCurrent = $this->id;
while (true)
{
$query = '
SELECT c.*, cl.*
FROM `'._DB_PREFIX_.'cms_category` c
LEFT JOIN `'._DB_PREFIX_.'cms_category_lang` cl ON (c.`id_cms_category` = cl.`id_cms_category` AND `id_lang` = '.(int)($idLang).')
WHERE c.`id_cms_category` = '.$idCurrent.' AND c.`id_parent` != 0
LEFT JOIN `'._DB_PREFIX_.'cms_category_lang` cl ON (c.`id_cms_category` = cl.`id_cms_category` AND `id_lang` = '.(int)$idLang.')
WHERE c.`id_cms_category` = '.(int)$idCurrent.' AND c.`id_parent` != 0
';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($query);
+11 -11
View File
@@ -193,18 +193,18 @@ class CategoryCore extends ObjectModel
{
if (!$context)
$context = Context::getContext();
$idLang = is_null($idLang) ? _USER_ID_LANG_ : (int)($idLang);
$idLang = is_null($idLang) ? $context->language->id : (int)$idLang;
$children = array();
if (($maxDepth == 0 OR $currentDepth < $maxDepth) AND $subcats = $this->getSubCategories((int)$idLang, true) AND sizeof($subcats))
if (($maxDepth == 0 OR $currentDepth < $maxDepth) AND $subcats = $this->getSubCategories($idLang, true) AND sizeof($subcats))
foreach ($subcats AS &$subcat)
{
if (!$subcat['id_category'])
break;
elseif (!is_array($excludedIdsArray) || !in_array($subcat['id_category'], $excludedIdsArray))
{
$categ = new Category((int)$subcat['id_category'], (int)$idLang);
$children[] = $categ->recurseLiteCategTree($maxDepth, $currentDepth + 1, (int)$idLang, $excludedIdsArray);
$categ = new Category((int)$subcat['id_category'], $idLang);
$children[] = $categ->recurseLiteCategTree($maxDepth, $currentDepth + 1, $idLang, $excludedIdsArray);
}
}
@@ -574,13 +574,13 @@ class CategoryCore extends ObjectModel
return self::getChildren(1, $id_lang, $active);
}
static public function getRootCategory($id_lang = NULL, $id_shop = false)
static public function getRootCategory($id_lang = NULL, $id_shop = false, $context = null)
{
if (!$id_shop)
$id_shop = Configuration::get('PS_SHOP_DEFAULT');
$shop = new Shop((int)$id_shop);
$shop = new Shop($id_shop);
return new Category ((int)$shop->id_category, is_null($id_lang) ? (int)_USER_ID_LANG_ : (int)($id_lang));
return new Category ($shop->id_category, is_null($id_lang) ? $context->language->id : $id_lang);
}
/**
@@ -790,19 +790,19 @@ class CategoryCore extends ObjectModel
* @param integer $id_lang Language ID
* @return array Corresponding categories
*/
public function getParentsCategories($idLang = null)
public function getParentsCategories($idLang = null, $context = null)
{
//get idLang
$idLang = is_null($idLang) ? _USER_ID_LANG_ : (int)($idLang);
$idLang = is_null($idLang) ? $context->language->id : $idLang;
$categories = null;
$idCurrent = (int)($this->id);
$idCurrent = $this->id;
while (true)
{
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT c.*, cl.*
FROM `'._DB_PREFIX_.'category` c
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.(int)($idLang).')
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.(int)$idLang.')
WHERE c.`id_category` = '.(int)$idCurrent.' AND c.`id_parent` != 0
');
+11 -13
View File
@@ -122,10 +122,6 @@ class FrontControllerCore
Tools::switchLanguage();
Tools::setCookieLanguage($cookie);
/* attribute id_lang is often needed, so we create a constant for performance reasons */
if (!defined('_USER_ID_LANG_'))
define('_USER_ID_LANG_', (int)$cookie->id_lang);
if (isset($_GET['logout']) OR ($cookie->logged AND Customer::isBanned((int)$cookie->id_customer)))
{
$cookie->logout();
@@ -153,12 +149,13 @@ class FrontControllerCore
$cart->nbProducts() AND intval(Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR')) != -1 AND
!self::isInWhitelistForGeolocation())
unset($cookie->id_cart, $cart);
elseif ($cookie->id_customer != $cart->id_customer OR $cookie->id_lang != $cart->id_lang OR $cookie->id_currency != $cart->id_currency)
// update cart values
elseif ($cookie->id_customer != $cart->id_customer OR $cookie->id_lang != $cart->id_lang OR $currency->id != $cart->id_currency)
{
if ($cookie->id_customer)
$cart->id_customer = (int)($cookie->id_customer);
$cart->id_lang = (int)($cookie->id_lang);
$cart->id_currency = (int)($cookie->id_currency);
$cart->id_currency = (int)$currency->id;
$cart->update();
}
/* Select an address if not set */
@@ -212,14 +209,16 @@ class FrontControllerCore
if (Validate::isLoadedObject($currency))
$smarty->ps_currency = $currency;
if (Validate::isLoadedObject($ps_language = new Language((int)$cookie->id_lang)))
$smarty->ps_language = $ps_language;
if (!Validate::isLoadedObject($language = new Language($cookie->id_lang)))
$language = new Language(Configuration::get('PS_LANG_DEFAULT'));
$smarty->ps_language = $language;
$context->language = $language;
/* get page name to display it in body id */
$pathinfo = pathinfo(__FILE__);
$page_name = Dispatcher::$controller;
$page_name = (preg_match('/^[0-9]/', $page_name)) ? 'page_'.$page_name : $page_name;
$smarty->assign(Tools::getMetaTags($cookie->id_lang, $page_name));
$smarty->assign(Tools::getMetaTags($language->id, $page_name));
$smarty->assign('request_uri', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
/* Breadcrumb */
@@ -228,15 +227,14 @@ class FrontControllerCore
$protocol_link = (Configuration::get('PS_SSL_ENABLED') OR (!empty($_SERVER['HTTPS']) AND strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://';
$protocol_content = ((isset($useSSL) AND $useSSL AND Configuration::get('PS_SSL_ENABLED')) OR (!empty($_SERVER['HTTPS']) AND strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://';
$link = new Link($protocol_link, $protocol_content);
$context->link = $link;
if (!defined('_PS_BASE_URL_'))
define('_PS_BASE_URL_', Tools::getShopDomain(true));
if (!defined('_PS_BASE_URL_SSL_'))
define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true));
$link = new Link($protocol_link, $protocol_content);
$context->link = $link;
$context->language = $ps_language;
$link->preloadPageLinks();
$this->canonicalRedirection();
@@ -262,7 +260,7 @@ class FrontControllerCore
'tpl_dir' => _PS_THEME_DIR_,
'modules_dir' => _MODULE_DIR_,
'mail_dir' => _MAIL_DIR_,
'lang_iso' => $ps_language->iso_code,
'lang_iso' => $language->iso_code,
'come_from' => Tools::getHttpHost(true, true).Tools::htmlentitiesUTF8(str_replace('\'', '', urldecode($_SERVER['REQUEST_URI']))),
'cart_qties' => (int)$cart->nbProducts(),
'currencies' => Currency::getCurrencies(),
+2 -2
View File
@@ -489,7 +489,7 @@ abstract class ModuleCore
if (substr(realpath($filePath), 0, strlen($realpathModuleDir)) == $realpathModuleDir)
{
self::$classInModule[$currentClass] = substr(dirname($filePath), strlen($realpathModuleDir)+1);
$file = _PS_MODULE_DIR_.self::$classInModule[$currentClass].'/'.$context->getContext()->language->iso_code.'.php';
$file = _PS_MODULE_DIR_.self::$classInModule[$currentClass].'/'.Context::getContext()->language->iso_code.'.php';
if (Tools::file_exists_cache($file) AND include_once($file))
$_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE;
}
@@ -578,7 +578,7 @@ abstract class ModuleCore
if (!count($errors) AND (int)$xml_module->need_instance == 0 AND !$needNewConfigFile)
{
$file = _PS_MODULE_DIR_.$module.'/'.$context->getContext()->language->iso_code.'.php';
$file = _PS_MODULE_DIR_.$module.'/'.Context::getContext()->language->iso_code.'.php';
if (Tools::file_exists_cache($file) AND include_once($file))
if(isset($_MODULE) AND is_array($_MODULE))
$_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE;
+3 -1
View File
@@ -286,8 +286,10 @@ abstract class ModuleGraphCore extends Module
return call_user_func(array($render, 'hookGraphEngine'), $params, $drawer);
}
protected static function getEmployee($employee = null)
protected static function getEmployee($employee = null, $context = null)
{
if (!$context)
$context = Context::getContext();
if (!$employee)
$employee = $context->employee;
-28
View File
@@ -829,33 +829,6 @@ class ProductCore extends ObjectModel
ORDER BY pl.`name`');
}
/**
* Return the products in the same category than the default category of the instancied product
*
* @param integer $id_lang Language ID
* @return array Products
* @deprecated
*/
public function getDefaultCategoryProducts($idLang = NULL, $limit = NULL)
{
Tools::displayAsDeprecated();
//get idLang
$idLang = is_null($idLang) ? _USER_ID_LANG_ : (int)($idLang);
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT p.`id_product`, pl.`description_short`set, pl.`link_rewrite`, pl.`name`, i.`id_image`
FROM `'._DB_PREFIX_.'category_product` cp
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product = cp.id_product)
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)
WHERE cp.id_category = ' . (int)($this->id_category_default) . '
AND id_lang = ' . (int)($idLang) . '
AND p.`active` = 1
AND i.`cover` = 1
'. (is_null($limit) ? '' : ' LIMIT 0 , ' . (int)($limit)));
return $result;
}
public function isNew()
{
$result = Db::getInstance()->ExecuteS('
@@ -867,7 +840,6 @@ class ProductCore extends ObjectModel
return sizeof($result) > 0;
}
public function productAttributeExists($attributesList, $currentProductAttribute = false)
{
$result = Db::getInstance()->ExecuteS('SELECT pac.`id_attribute`, pac.`id_product_attribute`
+14 -12
View File
@@ -181,21 +181,23 @@ class SceneCore extends ObjectModel
*
* @return array Products
*/
static public function getScenes($id_category, $id_lang = NULL, $onlyActive = true, $liteResult = true, $hideScenePosition = true)
static public function getScenes($id_category, $id_lang = NULL, $onlyActive = true, $liteResult = true, $hideScenePosition = true, $context = null)
{
$id_lang = is_null($id_lang) ? _USER_ID_LANG_ : (int)($id_lang);
if (!$context)
$context = Context::getContext();
$id_lang = is_null($id_lang) ? $context->language->id : $id_lang;
$scenes = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT s.*
FROM `'._DB_PREFIX_.'scene_category` sc
LEFT JOIN `'._DB_PREFIX_.'scene` s ON (sc.id_scene = s.id_scene)
LEFT JOIN `'._DB_PREFIX_.'scene_lang` sl ON (sl.id_scene = s.id_scene)
WHERE sc.id_category = '.(int)($id_category).' AND sl.id_lang = '.(int)($id_lang).($onlyActive ? ' AND s.active = 1' : '').'
WHERE sc.id_category = '.(int)$id_category.' AND sl.id_lang = '.(int)$id_lang.($onlyActive ? ' AND s.active = 1' : '').'
ORDER BY sl.name ASC');
if (!$liteResult AND $scenes)
foreach($scenes AS &$scene)
$scene = new Scene((int)($scene['id_scene']), (int)($id_lang), false, $hideScenePosition);
$scene = new Scene($scene['id_scene'], $id_lang, false, $hideScenePosition);
return $scenes;
}
@@ -204,28 +206,28 @@ class SceneCore extends ObjectModel
*
* @return array Products
*/
public function getProducts($onlyActive = true, $id_lang = NULL, $liteResult = true)
public function getProducts($onlyActive = true, $id_lang = NULL, $liteResult = true, $context = null)
{
global $link;
$id_lang = is_null($id_lang) ? _USER_ID_LANG_ : (int)($id_lang);
if (!$context)
$context = Context::getContext();
$id_lang = is_null($id_lang) ? $context->language->id : $id_lang;
$products = Db::getInstance()->ExecuteS('
SELECT s.*
FROM `'._DB_PREFIX_.'scene_products` s
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.id_product = s.id_product)
WHERE s.id_scene = '.(int)($this->id).($onlyActive ? ' AND p.active = 1' : ''));
WHERE s.id_scene = '.(int)$this->id.($onlyActive ? ' AND p.active = 1' : ''));
if (!$liteResult AND $products)
foreach ($products AS &$product)
{
$product['details'] = new Product((int)($product['id_product']), !$liteResult, (int)($id_lang));
$product['link'] = $link->getProductLink((int)($product['details']->id), $product['details']->link_rewrite, $product['details']->category, $product['details']->ean13);
$cover = Product::getCover((int)($product['details']->id));
$product['details'] = new Product($product['id_product'], !$liteResult, $id_lang);
$product['link'] = $link->getProductLink($product['details']->id, $product['details']->link_rewrite, $product['details']->category, $product['details']->ean13);
$cover = Product::getCover($product['details']->id);
if(is_array($cover))
$product = array_merge($cover, $product);
}
return $products;
}