// Norm
This commit is contained in:
+8
-8
@@ -60,7 +60,7 @@ class ShopCore extends ObjectModel
|
|||||||
/** @var array List of shops cached */
|
/** @var array List of shops cached */
|
||||||
protected static $shops = array();
|
protected static $shops = array();
|
||||||
|
|
||||||
private static $assoTables = array(
|
private static $asso_tables = array(
|
||||||
'carrier' => array('type' => 'shop'),
|
'carrier' => array('type' => 'shop'),
|
||||||
'carrier_lang' => array('type' => 'fk_shop'),
|
'carrier_lang' => array('type' => 'fk_shop'),
|
||||||
'category_lang' => array('type' => 'fk_shop'),
|
'category_lang' => array('type' => 'fk_shop'),
|
||||||
@@ -87,7 +87,7 @@ class ShopCore extends ObjectModel
|
|||||||
'webservice_account' => array('type' => 'shop'),
|
'webservice_account' => array('type' => 'shop'),
|
||||||
);
|
);
|
||||||
|
|
||||||
protected $webserviceParameters = array(
|
protected $webserviceParameters = array(
|
||||||
'fields' => array(
|
'fields' => array(
|
||||||
'id_group_shop' => array('xlink_resource' => 'shop_groups'),
|
'id_group_shop' => array('xlink_resource' => 'shop_groups'),
|
||||||
'id_category' => array(),
|
'id_category' => array(),
|
||||||
@@ -137,7 +137,7 @@ class ShopCore extends ObjectModel
|
|||||||
AND s.deleted = 0
|
AND s.deleted = 0
|
||||||
AND su.main = 1';
|
AND su.main = 1';
|
||||||
if (!$row = Db::getInstance()->getRow($sql))
|
if (!$row = Db::getInstance()->getRow($sql))
|
||||||
return ;
|
return;
|
||||||
|
|
||||||
$this->theme_name = $row['name'];
|
$this->theme_name = $row['name'];
|
||||||
$this->physical_uri = $row['physical_uri'];
|
$this->physical_uri = $row['physical_uri'];
|
||||||
@@ -147,9 +147,9 @@ class ShopCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add($autodate = true, $nullValues = false)
|
public function add($autodate = true, $null_values = false)
|
||||||
{
|
{
|
||||||
$res = parent::add($autodate, $nullValues);
|
$res = parent::add($autodate, $null_values);
|
||||||
Shop::cacheShops(true);
|
Shop::cacheShops(true);
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
@@ -359,7 +359,7 @@ class ShopCore extends ObjectModel
|
|||||||
*/
|
*/
|
||||||
public static function getAssoTables()
|
public static function getAssoTables()
|
||||||
{
|
{
|
||||||
return self::$assoTables;
|
return self::$asso_tables;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -683,8 +683,8 @@ class ShopCore extends ObjectModel
|
|||||||
if (strpos($table, '.') !== false)
|
if (strpos($table, '.') !== false)
|
||||||
list($tableAlias, $table) = explode('.', $table);
|
list($tableAlias, $table) = explode('.', $table);
|
||||||
|
|
||||||
$assoTables = Shop::getAssoTables();
|
$asso_tables = Shop::getAssoTables();
|
||||||
if (!isset($assoTables[$table]) || $assoTables[$table]['type'] != 'shop')
|
if (!isset($asso_tables[$table]) || $asso_tables[$table]['type'] != 'shop')
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
$sql = (($innerJoin) ? ' INNER' : ' LEFT').' JOIN '._DB_PREFIX_.$table.'_shop '.$tableAlias.'
|
$sql = (($innerJoin) ? ' INNER' : ' LEFT').' JOIN '._DB_PREFIX_.$table.'_shop '.$tableAlias.'
|
||||||
|
|||||||
+41
-39
@@ -28,39 +28,39 @@
|
|||||||
class TabCore extends ObjectModel
|
class TabCore extends ObjectModel
|
||||||
{
|
{
|
||||||
/** @var string Displayed name*/
|
/** @var string Displayed name*/
|
||||||
public $name;
|
public $name;
|
||||||
|
|
||||||
/** @var string Class and file name*/
|
/** @var string Class and file name*/
|
||||||
public $class_name;
|
public $class_name;
|
||||||
|
|
||||||
public $module;
|
public $module;
|
||||||
|
|
||||||
/** @var integer parent ID */
|
/** @var integer parent ID */
|
||||||
public $id_parent;
|
public $id_parent;
|
||||||
|
|
||||||
/** @var integer position */
|
/** @var integer position */
|
||||||
public $position;
|
public $position;
|
||||||
|
|
||||||
protected $fieldsRequired = array('class_name', 'position');
|
protected $fieldsRequired = array('class_name', 'position');
|
||||||
protected $fieldsSize = array('class_name' => 64, 'module' => 64);
|
protected $fieldsSize = array('class_name' => 64, 'module' => 64);
|
||||||
protected $fieldsValidate = array('id_parent' => 'isInt', 'position' => 'isUnsignedInt', 'module' => 'isTabName');
|
protected $fieldsValidate = array('id_parent' => 'isInt', 'position' => 'isUnsignedInt', 'module' => 'isTabName');
|
||||||
|
|
||||||
protected $fieldsRequiredLang = array('name');
|
protected $fieldsRequiredLang = array('name');
|
||||||
protected $fieldsSizeLang = array('name' => 32);
|
protected $fieldsSizeLang = array('name' => 32);
|
||||||
protected $fieldsValidateLang = array('name' => 'isGenericName');
|
protected $fieldsValidateLang = array('name' => 'isGenericName');
|
||||||
|
|
||||||
protected $table = 'tab';
|
protected $table = 'tab';
|
||||||
protected $identifier = 'id_tab';
|
protected $identifier = 'id_tab';
|
||||||
|
|
||||||
protected static $_getIdFromClassName = null;
|
protected static $_getIdFromClassName = null;
|
||||||
|
|
||||||
public function getFields()
|
public function getFields()
|
||||||
{
|
{
|
||||||
$this->validateFields();
|
$this->validateFields();
|
||||||
$fields['id_parent'] = (int)($this->id_parent);
|
$fields['id_parent'] = (int)$this->id_parent;
|
||||||
$fields['class_name'] = pSQL($this->class_name);
|
$fields['class_name'] = pSQL($this->class_name);
|
||||||
$fields['module'] = pSQL($this->module);
|
$fields['module'] = pSQL($this->module);
|
||||||
$fields['position'] = (int)($this->position);
|
$fields['position'] = (int)$this->position;
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,10 +70,10 @@ class TabCore extends ObjectModel
|
|||||||
return $this->getTranslationsFields(array('name'));
|
return $this->getTranslationsFields(array('name'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function add($autodate = true, $nullValues = false)
|
public function add($autodate = true, $null_values = false)
|
||||||
{
|
{
|
||||||
$this->position = self::getNbTabs($this->id_parent) + 1;
|
$this->position = self::getNbTabs($this->id_parent) + 1;
|
||||||
if (parent::add($autodate, $nullValues))
|
if (parent::add($autodate, $null_values))
|
||||||
{
|
{
|
||||||
// refresh cache when adding new tab
|
// refresh cache when adding new tab
|
||||||
self::$_getIdFromClassName[$this->class_name] = $this->id;
|
self::$_getIdFromClassName[$this->class_name] = $this->id;
|
||||||
@@ -82,7 +82,7 @@ class TabCore extends ObjectModel
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function initAccess($id_tab, Context $context = null)
|
public static function initAccess($id_tab, Context $context = null)
|
||||||
{
|
{
|
||||||
if (!$context)
|
if (!$context)
|
||||||
$context = Context::getContext();
|
$context = Context::getContext();
|
||||||
@@ -90,21 +90,21 @@ class TabCore extends ObjectModel
|
|||||||
return false;
|
return false;
|
||||||
/* Profile selection */
|
/* Profile selection */
|
||||||
$profiles = Db::getInstance()->ExecuteS('SELECT `id_profile` FROM '._DB_PREFIX_.'profile');
|
$profiles = Db::getInstance()->ExecuteS('SELECT `id_profile` FROM '._DB_PREFIX_.'profile');
|
||||||
if (!$profiles OR empty($profiles))
|
if (!$profiles || empty($profiles))
|
||||||
return false;
|
return false;
|
||||||
/* Query definition */
|
/* Query definition */
|
||||||
$query = 'INSERT INTO `'._DB_PREFIX_.'access` VALUES ';
|
$query = 'INSERT INTO `'._DB_PREFIX_.'access` VALUES ';
|
||||||
foreach ($profiles AS $profile)
|
foreach ($profiles as $profile)
|
||||||
{
|
{
|
||||||
$rights = (((int)($profile['id_profile']) == 1 OR (int)($profile['id_profile']) == $context->employee->id_profile) ? 1 : 0);
|
$rights = (((int)$profile['id_profile'] == 1 || (int)$profile['id_profile'] == $context->employee->id_profile) ? 1 : 0);
|
||||||
$query .= ($profile === $profiles[0] ? '' : ', ').'('.(int)($profile['id_profile']).', '.(int)($id_tab).', '.$rights.', '.$rights.', '.$rights.', '.$rights.')';
|
$query .= ($profile === $profiles[0] ? '' : ', ').'('.(int)$profile['id_profile'].', '.(int)($id_tab).', '.$rights.', '.$rights.', '.$rights.', '.$rights.')';
|
||||||
}
|
}
|
||||||
return Db::getInstance()->Execute($query);
|
return Db::getInstance()->Execute($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete()
|
public function delete()
|
||||||
{
|
{
|
||||||
if (Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'access WHERE `id_tab` = '.(int)($this->id)) AND parent::delete())
|
if (Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'access WHERE `id_tab` = '.(int)$this->id) && parent::delete())
|
||||||
return $this->cleanPositions($this->id_parent);
|
return $this->cleanPositions($this->id_parent);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -142,8 +142,8 @@ class TabCore extends ObjectModel
|
|||||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM `'._DB_PREFIX_.'tab` t
|
FROM `'._DB_PREFIX_.'tab` t
|
||||||
LEFT JOIN `'._DB_PREFIX_.'tab_lang` tl ON (t.`id_tab` = tl.`id_tab` AND tl.`id_lang` = '.(int)($id_lang).')
|
LEFT JOIN `'._DB_PREFIX_.'tab_lang` tl ON (t.`id_tab` = tl.`id_tab` AND tl.`id_lang` = '.(int)$id_lang.')
|
||||||
WHERE t.`id_tab` = '.(int)($id_tab));
|
WHERE t.`id_tab` = '.(int)$id_tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -152,7 +152,7 @@ class TabCore extends ObjectModel
|
|||||||
* @return array tabs
|
* @return array tabs
|
||||||
*/
|
*/
|
||||||
static $_cache_tabs = array();
|
static $_cache_tabs = array();
|
||||||
public static function getTabs($id_lang, $id_parent = NULL)
|
public static function getTabs($id_lang, $id_parent = null)
|
||||||
{
|
{
|
||||||
if (!isset(self::$_cache_tabs[$id_lang]))
|
if (!isset(self::$_cache_tabs[$id_lang]))
|
||||||
{
|
{
|
||||||
@@ -197,29 +197,31 @@ class TabCore extends ObjectModel
|
|||||||
return (isset(self::$_getIdFromClassName[$class_name]) ? (int)self::$_getIdFromClassName[$class_name] : false);
|
return (isset(self::$_getIdFromClassName[$class_name]) ? (int)self::$_getIdFromClassName[$class_name] : false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getNbTabs($id_parent = NULL)
|
public static function getNbTabs($id_parent = null)
|
||||||
{
|
{
|
||||||
return (int)Db::getInstance()->getValue('
|
return (int)Db::getInstance()->getValue('
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM `'._DB_PREFIX_.'tab` t
|
FROM `'._DB_PREFIX_.'tab` t
|
||||||
'.($id_parent !== NULL ? 'WHERE t.`id_parent` = '.(int)$id_parent : ''));
|
'.(!is_null($id_parent) ? 'WHERE t.`id_parent` = '.(int)$id_parent : ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function move($direction)
|
public function move($direction)
|
||||||
{
|
{
|
||||||
$nbTabs = self::getNbTabs($this->id_parent);
|
$nb_tabs = self::getNbTabs($this->id_parent);
|
||||||
if ($direction != 'l' AND $direction != 'r')
|
if ($direction != 'l' && $direction != 'r')
|
||||||
return false;
|
return false;
|
||||||
if ($nbTabs <= 1)
|
if ($nb_tabs <= 1)
|
||||||
return false;
|
return false;
|
||||||
if ($direction == 'l' AND $this->position <= 1)
|
if ($direction == 'l' && $this->position <= 1)
|
||||||
return false;
|
return false;
|
||||||
if ($direction == 'r' AND $this->position >= $nbTabs)
|
if ($direction == 'r' && $this->position >= $nb_tabs)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$newPosition = ($direction == 'l') ? $this->position - 1 : $this->position + 1;
|
$new_position = ($direction == 'l') ? $this->position - 1 : $this->position + 1;
|
||||||
Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'tab` t SET position = '.(int)($this->position).' WHERE id_parent = '.(int)($this->id_parent).' AND position = '.(int)($newPosition));
|
Db::getInstance()->Execute('UPDATE `'._DB_PREFIX_.'tab` t
|
||||||
$this->position = $newPosition;
|
SET position = '.(int)$this->position.'
|
||||||
|
WHERE id_parent = '.(int)$this->id_parent.' AND position = '.(int)$new_position);
|
||||||
|
$this->position = $new_position;
|
||||||
return $this->update();
|
return $this->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -228,14 +230,14 @@ class TabCore extends ObjectModel
|
|||||||
$result = Db::getInstance()->ExecuteS('
|
$result = Db::getInstance()->ExecuteS('
|
||||||
SELECT `id_tab`
|
SELECT `id_tab`
|
||||||
FROM `'._DB_PREFIX_.'tab`
|
FROM `'._DB_PREFIX_.'tab`
|
||||||
WHERE `id_parent` = '.(int)($id_parent).'
|
WHERE `id_parent` = '.(int)$id_parent.'
|
||||||
ORDER BY `position`');
|
ORDER BY `position`');
|
||||||
$sizeof = sizeof($result);
|
$sizeof = count($result);
|
||||||
for ($i = 0; $i < $sizeof; ++$i)
|
for ($i = 0; $i < $sizeof; ++$i)
|
||||||
Db::getInstance()->Execute('
|
Db::getInstance()->Execute('
|
||||||
UPDATE `'._DB_PREFIX_.'tab`
|
UPDATE `'._DB_PREFIX_.'tab`
|
||||||
SET `position` = '.($i + 1).'
|
SET `position` = '.($i + 1).'
|
||||||
WHERE `id_tab` = '.(int)($result[$i]['id_tab']));
|
WHERE `id_tab` = '.(int)$result[$i]['id_tab']);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -170,13 +170,14 @@ class TagCore extends ObjectModel
|
|||||||
if (!$this->id && $associated)
|
if (!$this->id && $associated)
|
||||||
return array();
|
return array();
|
||||||
|
|
||||||
|
$in = $associated ? 'IN' : 'NOT IN';
|
||||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||||
SELECT pl.name, pl.id_product
|
SELECT pl.name, pl.id_product
|
||||||
FROM `'._DB_PREFIX_.'product` p
|
FROM `'._DB_PREFIX_.'product` p
|
||||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON p.id_product = pl.id_product'.$context->shop->sqlLang('pl').'
|
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON p.id_product = pl.id_product'.$context->shop->sqlLang('pl').'
|
||||||
WHERE pl.id_lang = '.(int)$id_lang.'
|
WHERE pl.id_lang = '.(int)$id_lang.'
|
||||||
AND p.active = 1
|
AND p.active = 1
|
||||||
'.($this->id ? ('AND p.id_product '.($associated ? 'IN' : 'NOT IN').' (SELECT pt.id_product FROM `'._DB_PREFIX_.'product_tag` pt WHERE pt.id_tag = '.(int)$this->id.')') : '').'
|
'.($this->id ? ('AND p.id_product '.$in.' (SELECT pt.id_product FROM `'._DB_PREFIX_.'product_tag` pt WHERE pt.id_tag = '.(int)$this->id.')') : '').'
|
||||||
ORDER BY pl.name');
|
ORDER BY pl.name');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user