diff --git a/classes/Shop.php b/classes/Shop.php index 61068e5cf..ff2730f3b 100644 --- a/classes/Shop.php +++ b/classes/Shop.php @@ -60,7 +60,7 @@ class ShopCore extends ObjectModel /** @var array List of shops cached */ protected static $shops = array(); - private static $assoTables = array( + private static $asso_tables = array( 'carrier' => array('type' => 'shop'), 'carrier_lang' => array('type' => 'fk_shop'), 'category_lang' => array('type' => 'fk_shop'), @@ -87,7 +87,7 @@ class ShopCore extends ObjectModel 'webservice_account' => array('type' => 'shop'), ); - protected $webserviceParameters = array( + protected $webserviceParameters = array( 'fields' => array( 'id_group_shop' => array('xlink_resource' => 'shop_groups'), 'id_category' => array(), @@ -121,7 +121,7 @@ class ShopCore extends ObjectModel $fields['deleted'] = (int)$this->deleted; return $fields; } - + public function __construct($id = null, $id_lang = null, $id_shop = null) { parent::__construct($id, $id_lang, $id_shop); @@ -137,7 +137,7 @@ class ShopCore extends ObjectModel AND s.deleted = 0 AND su.main = 1'; if (!$row = Db::getInstance()->getRow($sql)) - return ; + return; $this->theme_name = $row['name']; $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); return $res; } @@ -271,7 +271,7 @@ class ShopCore extends ObjectModel { return $this->physical_uri; } - + /** * Get shop URL * @@ -359,7 +359,7 @@ class ShopCore extends ObjectModel */ public static function getAssoTables() { - return self::$assoTables; + return self::$asso_tables; } /** @@ -545,7 +545,7 @@ class ShopCore extends ObjectModel { if (!isset($context->cookie) || !$context->cookie->shopContext) return ($type == 'shop' || $type == 'group') ? '' : array('', ''); - + // Parse shopContext cookie value (E.g. s-2, g-4) $split = explode('-', $context->cookie->shopContext); if (count($split) == 2 && $split[0] == 'g') @@ -582,7 +582,7 @@ class ShopCore extends ObjectModel } else { - + $shopID = (int)$context->shop->getID(); $shopGroupID = (int)$context->shop->id_group_shop; } @@ -683,8 +683,8 @@ class ShopCore extends ObjectModel if (strpos($table, '.') !== false) list($tableAlias, $table) = explode('.', $table); - $assoTables = Shop::getAssoTables(); - if (!isset($assoTables[$table]) || $assoTables[$table]['type'] != 'shop') + $asso_tables = Shop::getAssoTables(); + if (!isset($asso_tables[$table]) || $asso_tables[$table]['type'] != 'shop') return ; $sql = (($innerJoin) ? ' INNER' : ' LEFT').' JOIN '._DB_PREFIX_.$table.'_shop '.$tableAlias.' diff --git a/classes/Tab.php b/classes/Tab.php index c0488db75..754f8cc2e 100644 --- a/classes/Tab.php +++ b/classes/Tab.php @@ -1,6 +1,6 @@ 64, 'module' => 64); - protected $fieldsValidate = array('id_parent' => 'isInt', 'position' => 'isUnsignedInt', 'module' => 'isTabName'); + protected $fieldsRequired = array('class_name', 'position'); + protected $fieldsSize = array('class_name' => 64, 'module' => 64); + protected $fieldsValidate = array('id_parent' => 'isInt', 'position' => 'isUnsignedInt', 'module' => 'isTabName'); - protected $fieldsRequiredLang = array('name'); - protected $fieldsSizeLang = array('name' => 32); - protected $fieldsValidateLang = array('name' => 'isGenericName'); + protected $fieldsRequiredLang = array('name'); + protected $fieldsSizeLang = array('name' => 32); + protected $fieldsValidateLang = array('name' => 'isGenericName'); + + protected $table = 'tab'; + protected $identifier = 'id_tab'; - protected $table = 'tab'; - protected $identifier = 'id_tab'; - protected static $_getIdFromClassName = null; - + public function getFields() { $this->validateFields(); - $fields['id_parent'] = (int)($this->id_parent); + $fields['id_parent'] = (int)$this->id_parent; $fields['class_name'] = pSQL($this->class_name); $fields['module'] = pSQL($this->module); - $fields['position'] = (int)($this->position); + $fields['position'] = (int)$this->position; return $fields; } @@ -70,10 +70,10 @@ class TabCore extends ObjectModel 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; - if (parent::add($autodate, $nullValues)) + if (parent::add($autodate, $null_values)) { // refresh cache when adding new tab self::$_getIdFromClassName[$this->class_name] = $this->id; @@ -82,7 +82,7 @@ class TabCore extends ObjectModel return false; } - static public function initAccess($id_tab, Context $context = null) + public static function initAccess($id_tab, Context $context = null) { if (!$context) $context = Context::getContext(); @@ -90,21 +90,21 @@ class TabCore extends ObjectModel return false; /* Profile selection */ $profiles = Db::getInstance()->ExecuteS('SELECT `id_profile` FROM '._DB_PREFIX_.'profile'); - if (!$profiles OR empty($profiles)) + if (!$profiles || empty($profiles)) return false; /* Query definition */ $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); - $query .= ($profile === $profiles[0] ? '' : ', ').'('.(int)($profile['id_profile']).', '.(int)($id_tab).', '.$rights.', '.$rights.', '.$rights.', '.$rights.')'; + $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.')'; } return Db::getInstance()->Execute($query); } 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 false; } @@ -142,8 +142,8 @@ class TabCore extends ObjectModel return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' SELECT * 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).') - WHERE t.`id_tab` = '.(int)($id_tab)); + 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); } /** @@ -152,7 +152,7 @@ class TabCore extends ObjectModel * @return array tabs */ 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])) { @@ -197,29 +197,31 @@ class TabCore extends ObjectModel 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(' SELECT COUNT(*) 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) { - $nbTabs = self::getNbTabs($this->id_parent); - if ($direction != 'l' AND $direction != 'r') + $nb_tabs = self::getNbTabs($this->id_parent); + if ($direction != 'l' && $direction != 'r') return false; - if ($nbTabs <= 1) + if ($nb_tabs <= 1) return false; - if ($direction == 'l' AND $this->position <= 1) + if ($direction == 'l' && $this->position <= 1) return false; - if ($direction == 'r' AND $this->position >= $nbTabs) + if ($direction == 'r' && $this->position >= $nb_tabs) return false; - $newPosition = ($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)); - $this->position = $newPosition; + $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)$new_position); + $this->position = $new_position; return $this->update(); } @@ -228,14 +230,14 @@ class TabCore extends ObjectModel $result = Db::getInstance()->ExecuteS(' SELECT `id_tab` FROM `'._DB_PREFIX_.'tab` - WHERE `id_parent` = '.(int)($id_parent).' + WHERE `id_parent` = '.(int)$id_parent.' ORDER BY `position`'); - $sizeof = sizeof($result); + $sizeof = count($result); for ($i = 0; $i < $sizeof; ++$i) Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'tab` SET `position` = '.($i + 1).' - WHERE `id_tab` = '.(int)($result[$i]['id_tab'])); + WHERE `id_tab` = '.(int)$result[$i]['id_tab']); return true; } } diff --git a/classes/Tag.php b/classes/Tag.php index 12c89d59b..38ff57864 100644 --- a/classes/Tag.php +++ b/classes/Tag.php @@ -170,13 +170,14 @@ class TagCore extends ObjectModel if (!$this->id && $associated) return array(); + $in = $associated ? 'IN' : 'NOT IN'; return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT pl.name, pl.id_product FROM `'._DB_PREFIX_.'product` p 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.' 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'); }