Skip to content

Commit

Permalink
Merge pull request PrestaShop#3810 from gskema/psr2_13
Browse files Browse the repository at this point in the history
[PSR-2] Fix coding standards and indentation in Shop* class files
  • Loading branch information
julienbourdeau committed Aug 25, 2015
2 parents bc07147 + f1e83c0 commit f199cbf
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 95 deletions.
119 changes: 58 additions & 61 deletions classes/shop/Shop.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ public function setUrl()
$cache_id = 'Shop::setUrl_'.(int)$this->id;
if (!Cache::isStored($cache_id)) {
$row = Db::getInstance()->getRow('
SELECT su.physical_uri, su.virtual_uri, su.domain, su.domain_ssl, t.id_theme, t.name, t.directory
FROM '._DB_PREFIX_.'shop s
LEFT JOIN '._DB_PREFIX_.'shop_url su ON (s.id_shop = su.id_shop)
LEFT JOIN '._DB_PREFIX_.'theme t ON (t.id_theme = s.id_theme)
WHERE s.id_shop = '.(int)$this->id.'
AND s.active = 1 AND s.deleted = 0 AND su.main = 1');
SELECT su.physical_uri, su.virtual_uri, su.domain, su.domain_ssl, t.id_theme, t.name, t.directory
FROM '._DB_PREFIX_.'shop s
LEFT JOIN '._DB_PREFIX_.'shop_url su ON (s.id_shop = su.id_shop)
LEFT JOIN '._DB_PREFIX_.'theme t ON (t.id_theme = s.id_theme)
WHERE s.id_shop = '.(int)$this->id.'
AND s.active = 1 AND s.deleted = 0 AND su.main = 1');
Cache::store($cache_id, $row);
} else {
$row = Cache::retrieve($cache_id);
Expand Down Expand Up @@ -261,9 +261,9 @@ public function delete()
} else {
$table_name .= '_'.$row['type'];
}
$res &= Db::getInstance()->execute('
DELETE FROM `'.bqSQL(_DB_PREFIX_.$table_name).'`
WHERE `'.bqSQL($id).'`='.(int)$this->id
$res &= Db::getInstance()->execute(
'DELETE FROM `'.bqSQL(_DB_PREFIX_.$table_name).'`
WHERE `'.bqSQL($id).'`='.(int)$this->id
);
}

Expand All @@ -287,18 +287,18 @@ public function delete()
public static function hasDependency($id_shop)
{
$has_dependency = false;
$nbr_customer = (int)Db::getInstance()->getValue('
SELECT count(*)
FROM `'._DB_PREFIX_.'customer`
WHERE `id_shop`='.(int)$id_shop
$nbr_customer = (int)Db::getInstance()->getValue(
'SELECT count(*)
FROM `'._DB_PREFIX_.'customer`
WHERE `id_shop`='.(int)$id_shop
);
if ($nbr_customer) {
$has_dependency = true;
} else {
$nbr_order = (int)Db::getInstance()->getValue('
SELECT count(*)
FROM `'._DB_PREFIX_.'orders`
WHERE `id_shop`='.(int)$id_shop
$nbr_order = (int)Db::getInstance()->getValue(
'SELECT count(*)
FROM `'._DB_PREFIX_.'orders`
WHERE `id_shop`='.(int)$id_shop
);
if ($nbr_order) {
$has_dependency = true;
Expand All @@ -324,12 +324,12 @@ public static function initialize()
$request_uri = rawurldecode($_SERVER['REQUEST_URI']);

$sql = 'SELECT s.id_shop, CONCAT(su.physical_uri, su.virtual_uri) AS uri, su.domain, su.main
FROM '._DB_PREFIX_.'shop_url su
LEFT JOIN '._DB_PREFIX_.'shop s ON (s.id_shop = su.id_shop)
WHERE (su.domain = \''.pSQL($host).'\' OR su.domain_ssl = \''.pSQL($host).'\')
AND s.active = 1
AND s.deleted = 0
ORDER BY LENGTH(CONCAT(su.physical_uri, su.virtual_uri)) DESC';
FROM '._DB_PREFIX_.'shop_url su
LEFT JOIN '._DB_PREFIX_.'shop s ON (s.id_shop = su.id_shop)
WHERE (su.domain = \''.pSQL($host).'\' OR su.domain_ssl = \''.pSQL($host).'\')
AND s.active = 1
AND s.deleted = 0
ORDER BY LENGTH(CONCAT(su.physical_uri, su.virtual_uri)) DESC';

$result = Db::getInstance()->executeS($sql);

Expand Down Expand Up @@ -538,9 +538,9 @@ public function getCategory()
public function getUrls()
{
$sql = 'SELECT *
FROM '._DB_PREFIX_.'shop_url
WHERE active = 1
AND id_shop = '.(int)$this->id;
FROM '._DB_PREFIX_.'shop_url
WHERE active = 1
AND id_shop = '.(int)$this->id;
return Db::getInstance()->executeS($sql);
}

Expand Down Expand Up @@ -649,16 +649,16 @@ public static function cacheShops($refresh = false)
}

$sql = 'SELECT gs.*, s.*, gs.name AS group_name, s.name AS shop_name, s.active, su.domain, su.domain_ssl, su.physical_uri, su.virtual_uri
FROM '._DB_PREFIX_.'shop_group gs
LEFT JOIN '._DB_PREFIX_.'shop s
ON s.id_shop_group = gs.id_shop_group
LEFT JOIN '._DB_PREFIX_.'shop_url su
ON s.id_shop = su.id_shop AND su.main = 1
'.$from.'
WHERE s.deleted = 0
AND gs.deleted = 0
'.$where.'
ORDER BY gs.name, s.name';
FROM '._DB_PREFIX_.'shop_group gs
LEFT JOIN '._DB_PREFIX_.'shop s
ON s.id_shop_group = gs.id_shop_group
LEFT JOIN '._DB_PREFIX_.'shop_url su
ON s.id_shop = su.id_shop AND su.main = 1
'.$from.'
WHERE s.deleted = 0
AND gs.deleted = 0
'.$where.'
ORDER BY gs.name, s.name';

if ($results = Db::getInstance()->executeS($sql)) {
foreach ($results as $row) {
Expand Down Expand Up @@ -887,10 +887,10 @@ public static function getContextListShopID($share = false)
*/
public static function getShopById($id, $identifier, $table)
{
return Db::getInstance()->executeS('
SELECT `id_shop`, `'.bqSQL($identifier).'`
FROM `'._DB_PREFIX_.bqSQL($table).'_shop`
WHERE `'.bqSQL($identifier).'` = '.(int)$id
return Db::getInstance()->executeS(
'SELECT `id_shop`, `'.bqSQL($identifier).'`
FROM `'._DB_PREFIX_.bqSQL($table).'_shop`
WHERE `'.bqSQL($identifier).'` = '.(int)$id
);
}

Expand All @@ -903,22 +903,19 @@ public static function getShopById($id, $identifier, $table)
public static function setContext($type, $id = null)
{
switch ($type) {
case self::CONTEXT_ALL :
case self::CONTEXT_ALL:
self::$context_id_shop = null;
self::$context_id_shop_group = null;
break;

case self::CONTEXT_GROUP :
break;
case self::CONTEXT_GROUP:
self::$context_id_shop = null;
self::$context_id_shop_group = (int)$id;
break;

case self::CONTEXT_SHOP :
break;
case self::CONTEXT_SHOP:
self::$context_id_shop = (int)$id;
self::$context_id_shop_group = Shop::getGroupFromShop($id);
break;

default :
break;
default:
throw new PrestaShopException('Unknown context for shop');
}

Expand Down Expand Up @@ -1014,7 +1011,7 @@ public static function addSqlAssociation($table, $alias, $inner_join = true, $on
return;
}
$sql = (($inner_join) ? ' INNER' : ' LEFT').' JOIN '._DB_PREFIX_.$table.'_shop '.$table_alias.'
ON ('.$table_alias.'.id_'.$table.' = '.$alias.'.id_'.$table;
ON ('.$table_alias.'.id_'.$table.' = '.$alias.'.id_'.$table;
if ((int)self::$context_id_shop) {
$sql .= ' AND '.$table_alias.'.id_shop = '.(int)self::$context_id_shop;
} elseif (Shop::checkIdShopDefault($table) && !$force_not_default) {
Expand Down Expand Up @@ -1144,13 +1141,13 @@ public function copyShopData($old_id, $tables_import = false, $deleted = false)
unset($res['id_category_default']);
$keys = implode('`, `', array_keys($res));
$sql = 'INSERT IGNORE INTO `'._DB_PREFIX_.$table_name.'` (`'.$keys.'`, `id_category_default`, '.$id.')
(SELECT `'.$keys.'`, '.(int)$categories[0].', '.(int)$this->id.' FROM '._DB_PREFIX_.$table_name.'
WHERE `'.$id.'` = '.(int)$old_id.')';
(SELECT `'.$keys.'`, '.(int)$categories[0].', '.(int)$this->id.' FROM '._DB_PREFIX_.$table_name.'
WHERE `'.$id.'` = '.(int)$old_id.')';
} else {
$keys = implode('`, `', array_keys($res));
$sql = 'INSERT IGNORE INTO `'._DB_PREFIX_.$table_name.'` (`'.$keys.'`, '.$id.')
(SELECT `'.$keys.'`, '.(int)$this->id.' FROM '._DB_PREFIX_.$table_name.'
WHERE `'.$id.'` = '.(int)$old_id.')';
(SELECT `'.$keys.'`, '.(int)$this->id.' FROM '._DB_PREFIX_.$table_name.'
WHERE `'.$id.'` = '.(int)$old_id.')';
}
Db::getInstance()->execute($sql);
}
Expand Down Expand Up @@ -1213,12 +1210,12 @@ public static function getEntityIds($entity, $id_shop, $active = false, $delete
return false;
}

return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT entity.`id_'.pSQL($entity).'`
FROM `'._DB_PREFIX_.pSQL($entity).'_shop`es
LEFT JOIN '._DB_PREFIX_.pSQL($entity).' entity
ON (entity.`id_'.pSQL($entity).'` = es.`id_'.pSQL($entity).'`)
WHERE es.`id_shop` = '.(int)$id_shop.
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(
'SELECT entity.`id_'.pSQL($entity).'`
FROM `'._DB_PREFIX_.pSQL($entity).'_shop`es
LEFT JOIN '._DB_PREFIX_.pSQL($entity).' entity
ON (entity.`id_'.pSQL($entity).'` = es.`id_'.pSQL($entity).'`)
WHERE es.`id_shop` = '.(int)$id_shop.
($active ? ' AND entity.`active` = 1' : '').
($delete ? ' AND entity.deleted = 0' : '')
);
Expand Down
40 changes: 20 additions & 20 deletions classes/shop/ShopGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ public function haveShops()
public function getTotalShops()
{
$sql = 'SELECT COUNT(*)
FROM '._DB_PREFIX_.'shop s
WHERE id_shop_group='.(int)$this->id;
FROM '._DB_PREFIX_.'shop s
WHERE id_shop_group='.(int)$this->id;
return (int)Db::getInstance()->getValue($sql);
}

public static function getShopsFromGroup($id_group)
{
$sql = 'SELECT s.`id_shop`
FROM '._DB_PREFIX_.'shop s
WHERE id_shop_group='.(int)$id_group;
FROM '._DB_PREFIX_.'shop s
WHERE id_shop_group='.(int)$id_group;
return Db::getInstance()->executeS($sql);
}

Expand All @@ -113,8 +113,8 @@ public static function getShopsFromGroup($id_group)
public static function getIdByName($name)
{
$sql = 'SELECT id_shop_group
FROM '._DB_PREFIX_.'shop_group
WHERE name = \''.pSQL($name).'\'';
FROM '._DB_PREFIX_.'shop_group
WHERE name = \''.pSQL($name).'\'';
return (int)Db::getInstance()->getValue($sql);
}

Expand All @@ -133,21 +133,21 @@ public static function hasDependency($id_shop_group, $check = 'all')
}

if ($check == 'all' || $check == 'customer') {
$total_customer = (int)Db::getInstance()->getValue('
SELECT count(*)
FROM `'._DB_PREFIX_.'customer`
WHERE `id_shop` IN ('.implode(', ', $list_shops).')'
$total_customer = (int)Db::getInstance()->getValue(
'SELECT count(*)
FROM `'._DB_PREFIX_.'customer`
WHERE `id_shop` IN ('.implode(', ', $list_shops).')'
);
if ($total_customer) {
return true;
}
}

if ($check == 'all' || $check == 'order') {
$total_order = (int)Db::getInstance()->getValue('
SELECT count(*)
FROM `'._DB_PREFIX_.'orders`
WHERE `id_shop` IN ('.implode(', ', $list_shops).')'
$total_order = (int)Db::getInstance()->getValue(
'SELECT count(*)
FROM `'._DB_PREFIX_.'orders`
WHERE `id_shop` IN ('.implode(', ', $list_shops).')'
);
if ($total_order) {
return true;
Expand All @@ -159,12 +159,12 @@ public static function hasDependency($id_shop_group, $check = 'all')

public function shopNameExists($name, $id_shop = false)
{
return Db::getInstance()->getValue('
SELECT id_shop
FROM '._DB_PREFIX_.'shop
WHERE name = "'.pSQL($name).'"
AND id_shop_group = '.(int)$this->id.'
'.($id_shop ? 'AND id_shop != '.(int)$id_shop : '')
return Db::getInstance()->getValue(
'SELECT id_shop
FROM '._DB_PREFIX_.'shop
WHERE name = "'.pSQL($name).'"
AND id_shop_group = '.(int)$this->id.'
'.($id_shop ? 'AND id_shop != '.(int)$id_shop : '')
);
}
}
28 changes: 14 additions & 14 deletions classes/shop/ShopUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ public function setMain()

// Reset main URL for all shops to prevent problems
$sql = 'SELECT s1.id_shop_url FROM '._DB_PREFIX_.'shop_url s1
WHERE (
SELECT COUNT(*) FROM '._DB_PREFIX_.'shop_url s2
WHERE s2.main = 1
AND s2.id_shop = s1.id_shop
) = 0
GROUP BY s1.id_shop';
WHERE (
SELECT COUNT(*) FROM '._DB_PREFIX_.'shop_url s2
WHERE s2.main = 1
AND s2.id_shop = s1.id_shop
) = 0
GROUP BY s1.id_shop';
foreach (Db::getInstance()->executeS($sql) as $row) {
Db::getInstance()->update('shop_url', array('main' => 1), 'id_shop_url = '.$row['id_shop_url']);
}
Expand All @@ -151,10 +151,10 @@ public function canAddThisUrl($domain, $domain_ssl, $physical_uri, $virtual_uri)
}

$sql = 'SELECT id_shop_url
FROM '._DB_PREFIX_.'shop_url
WHERE physical_uri = \''.pSQL($physical_uri).'\'
AND virtual_uri = \''.pSQL($virtual_uri).'\'
AND (domain = \''.pSQL($domain).'\' '.(($domain_ssl) ? ' OR domain_ssl = \''.pSQL($domain_ssl).'\'' : '').')'
FROM '._DB_PREFIX_.'shop_url
WHERE physical_uri = \''.pSQL($physical_uri).'\'
AND virtual_uri = \''.pSQL($virtual_uri).'\'
AND (domain = \''.pSQL($domain).'\' '.(($domain_ssl) ? ' OR domain_ssl = \''.pSQL($domain_ssl).'\'' : '').')'
.($this->id ? ' AND id_shop_url != '.(int)$this->id : '');
return Db::getInstance()->getValue($sql);
}
Expand All @@ -163,10 +163,10 @@ public static function cacheMainDomainForShop($id_shop)
{
if (!isset(self::$main_domain_ssl[(int)$id_shop]) || !isset(self::$main_domain[(int)$id_shop])) {
$row = Db::getInstance()->getRow('
SELECT domain, domain_ssl
FROM '._DB_PREFIX_.'shop_url
WHERE main = 1
AND id_shop = '.($id_shop !== null ? (int)$id_shop : (int)Context::getContext()->shop->id));
SELECT domain, domain_ssl
FROM '._DB_PREFIX_.'shop_url
WHERE main = 1
AND id_shop = '.($id_shop !== null ? (int)$id_shop : (int)Context::getContext()->shop->id));
self::$main_domain[(int)$id_shop] = $row['domain'];
self::$main_domain_ssl[(int)$id_shop] = $row['domain_ssl'];
}
Expand Down

0 comments on commit f199cbf

Please sign in to comment.