From a04b2af73b37c193ebed61f854c48aaa8182d007 Mon Sep 17 00:00:00 2001 From: rMalie Date: Mon, 23 Jan 2012 15:25:43 +0000 Subject: [PATCH] // Normalize some classes git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@12612 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/Product.php | 10 ++-- classes/ProductDownload.php | 78 +++++++++++++----------- classes/ProductSale.php | 93 ++++++++++++++++------------ classes/Profile.php | 44 ++++++++------ classes/QuickAccess.php | 2 +- classes/RangePrice.php | 25 ++++---- classes/RangeWeight.php | 23 ++++--- classes/Referrer.php | 42 ++++++------- classes/Rijndael.php | 26 +++++--- classes/Scene.php | 105 +++++++++++++++++--------------- classes/SearchEngine.php | 24 ++++---- classes/SpecificPrice.php | 16 ++--- classes/SpecificPriceRule.php | 37 ++++++++---- classes/State.php | 110 ++++++++++++++++++---------------- classes/Store.php | 66 ++++++++++---------- classes/SubDomain.php | 10 ++-- classes/Tab.php | 15 +++-- classes/Tag.php | 7 ++- classes/Theme.php | 15 ++--- 19 files changed, 414 insertions(+), 334 deletions(-) diff --git a/classes/Product.php b/classes/Product.php index 2a7008ce3..ddcda3377 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -377,8 +377,9 @@ class ProductCore extends ObjectModel const CUSTOMIZE_FILE = 0; const CUSTOMIZE_TEXTFIELD = 1; - - // Note: prefix is "PTYPE" because TYPE_ is used in ObjectModel (definition) + /** + * Note: prefix is "PTYPE" because TYPE_ is used in ObjectModel (definition) + */ const PTYPE_SIMPLE = 0; const PTYPE_PACK = 1; const PTYPE_VIRTUAL = 2; @@ -1245,7 +1246,6 @@ class ProductCore extends ObjectModel public function updateAttribute($id_product_attribute, $wholesale_price, $price, $weight, $unit, $ecotax, $id_images, $reference, $ean13, $default, $location = null, $upc = null, $minimal_quantity, $available_date) { - $price = str_replace(',', '.', $price); $weight = str_replace(',', '.', $weight); @@ -2369,7 +2369,7 @@ class ProductCore extends ObjectModel } $result = self::$_pricesLevel2[$cache_id_2]; - if (!$specific_price || $specific_price['price'] ==0) + if (!$specific_price || $specific_price['price'] == 0) $price = (float)$result['price']; else $price = (float)$specific_price['price']; @@ -3386,7 +3386,7 @@ class ProductCore extends ObjectModel $row['attribute_price'] = 0; if (isset($row['id_product_attribute']) && $row['id_product_attribute']) - $row['attribute_price'] = (float)Product::getProductAttributePrice($row['id_product_attribute']); + $row['attribute_price'] = (float)Product::getProductAttributePrice($row['id_product_attribute']); $row['price_tax_exc'] = Product::getPriceStatic( (int)$row['id_product'], diff --git a/classes/ProductDownload.php b/classes/ProductDownload.php index a24767372..b98e186b6 100644 --- a/classes/ProductDownload.php +++ b/classes/ProductDownload.php @@ -103,9 +103,9 @@ class ProductDownloadCore extends ObjectModel return $fields; } - public function add($autodate = true, $nullValues = false) + public function add($autodate = true, $null_values = false) { - if (parent::add($autodate, $nullValues)) + if (parent::add($autodate, $null_values)) { // Set cache of feature detachable to true if ($this->active) @@ -115,9 +115,9 @@ class ProductDownloadCore extends ObjectModel return false; } - public function update($nullValues = false) + public function update($null_values = false) { - if (parent::update($nullValues)) + if (parent::update($null_values)) { // Refresh cache of feature detachable because the row can be deactive Configuration::updateGlobalValue('PS_VIRTUAL_PROD_FEATURE_ACTIVE', ProductDownload::isCurrentlyUsed($this->def['table'], true)); @@ -126,9 +126,9 @@ class ProductDownloadCore extends ObjectModel return false; } - public function delete($deleteFile = false) + public function delete($delete = false) { - if ($deleteFile) + if ($delete) return $this->deleteFile(); return true; } @@ -139,14 +139,13 @@ class ProductDownloadCore extends ObjectModel * * @return boolean */ - public function deleteFile($id_product_download = NULL) + public function deleteFile($id_product_download = null) { if (!$this->checkFile()) return false; - - return unlink(_PS_DOWNLOAD_DIR_.$this->filename) && Db::getInstance()->Execute('DELETE - FROM `'._DB_PREFIX_.'product_download` - WHERE `id_product_download` = '.(int)$id_product_download); + + return unlink(_PS_DOWNLOAD_DIR_.$this->filename) + && Db::getInstance()->delete(_DB_PREFIX_.'product_download', 'id_product_download = '.(int)$id_product_download); } /** @@ -202,13 +201,17 @@ class ProductDownloadCore extends ObjectModel { if (!ProductDownload::isFeatureActive()) return false; + if (array_key_exists($id_product_attribute, self::$_productIds)) - return self::$_productIds[$id_product]; + return self::$_productIds[$id_product]; + self::$_productIds[$id_product_attribute] = (int)Db::getInstance()->getValue(' - SELECT `id_product_download` - FROM `'._DB_PREFIX_.'product_download` - WHERE `id_product` = '.(int)$id_product.' - AND `id_product_attribute` = '.(int)$id_product_attribute.' AND `active` = 1'); + SELECT `id_product_download` + FROM `'._DB_PREFIX_.'product_download` + WHERE `id_product` = '.(int)$id_product.' + AND `id_product_attribute` = '.(int)$id_product_attribute.' + AND `active` = 1' + ); return self::$_productIds[$id_product_attribute]; } @@ -228,7 +231,7 @@ class ProductDownloadCore extends ObjectModel FROM `'._DB_PREFIX_.'product_download` WHERE `id_product` = '.(int)$id_product.' AND `active` = 1'); } - + /** * Return the result from an id_product_attribute * @@ -272,12 +275,13 @@ class ProductDownloadCore extends ObjectModel public static function getFilenameFromIdProduct($id_product) { return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' - SELECT `filename` - FROM `'._DB_PREFIX_.'product_download` - WHERE `id_product` = '.(int)$id_product.' - AND `active` = 1'); + SELECT `filename` + FROM `'._DB_PREFIX_.'product_download` + WHERE `id_product` = '.(int)$id_product.' + AND `active` = 1 + '); } - + /** * Return the filename from an id_product_attribute * @@ -288,11 +292,12 @@ class ProductDownloadCore extends ObjectModel public static function getFilenameFromIdAttribute($id_product, $id_product_attribute) { return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' - SELECT `filename` - FROM `'._DB_PREFIX_.'product_download` - WHERE `id_product` = '.(int)$id_product.' - AND `id_product_attribute` = '.(int)$id_product_attribute.' - AND `active` = 1'); + SELECT `filename` + FROM `'._DB_PREFIX_.'product_download` + WHERE `id_product` = '.(int)$id_product.' + AND `id_product_attribute` = '.(int)$id_product_attribute.' + AND `active` = 1 + '); } /** @@ -319,7 +324,7 @@ class ProductDownloadCore extends ObjectModel */ public function getTextLink($admin = true, $hash = false) { - $key = $this->filename . '-' . ($hash ? $hash : 'orderdetail'); + $key = $this->filename.'-'.($hash ? $hash : 'orderdetail'); $link = ($admin) ? 'get-file-admin.php?' : _PS_BASE_URL_.__PS_BASE_URI__.'index.php?controller=get-file&'; $link .= ($admin) ? 'file='.$this->filename : 'key='.$key; return $link; @@ -328,17 +333,18 @@ class ProductDownloadCore extends ObjectModel /** * Return html link * - * @param string $class CSS selector (optionnal) - * @param bool $admin specific to backend (optionnal) - * @param string $hash hash code in table order detail (optionnal) + * @param string $class CSS selector + * @param bool $admin specific to backend + * @param bool $hash hash code in table order detail * @return string Html all the code for print a link to the file */ - public function getHtmlLink($class=false, $admin=true, $hash=false) + public function getHtmlLink($class = false, $admin = true, $hash = false) { $link = $this->getTextLink($admin, $hash); $html = 'display_filename.''; + if ($class) + $html .= ' class="'.$class.'"'; + $html .= '>'.$this->display_filename.''; return $html; } @@ -349,9 +355,9 @@ class ProductDownloadCore extends ObjectModel */ public function getDeadline() { - if (!(int)($this->nb_days_accessible)) + if (!(int)$this->nb_days_accessible) return '0000-00-00 00:00:00'; - $timestamp = strtotime('+'.(int)($this->nb_days_accessible).' day'); + $timestamp = strtotime('+'.(int)$this->nb_days_accessible.' day'); return date('Y-m-d H:i:s', $timestamp); } diff --git a/classes/ProductSale.php b/classes/ProductSale.php index c30e4eb3f..a27bd696d 100644 --- a/classes/ProductSale.php +++ b/classes/ProductSale.php @@ -44,7 +44,7 @@ class ProductSaleCore ** Get number of actives products sold ** @return int number of actives products listed in product_sales */ - static public function getNbSales(Context $context = null) + public static function getNbSales(Context $context = null) { if (!$context) $context = Context::getContext(); @@ -61,32 +61,38 @@ class ProductSaleCore ** Get required informations on best sales products ** ** @param integer $id_lang Language id - ** @param integer $pageNumber Start from (optional) - ** @param integer $nbProducts Number of products to return (optional) + ** @param integer $page_number Start from (optional) + ** @param integer $nb_products Number of products to return (optional) ** @return array from Product::getProductProperties */ - static public function getBestSales($id_lang, $pageNumber = 0, $nbProducts = 10, $orderBy = NULL, $orderWay = NULL, Context $context = null) + public static function getBestSales($id_lang, $page_number = 0, $nb_products = 10, $order_by = null, $order_way = null, Context $context = null) { if (!$context) $context = Context::getContext(); - if ($pageNumber < 0) $pageNumber = 0; - if ($nbProducts < 1) $nbProducts = 10; - if (empty($orderBy) || $orderBy == 'position') $orderBy = 'sales'; - if (empty($orderWay)) $orderWay = 'DESC'; + if ($page_number < 0) $page_number = 0; + if ($nb_products < 1) $nb_products = 10; + if (empty($order_by) || $order_by == 'position') $order_by = 'sales'; + if (empty($order_way)) $order_way = 'DESC'; $groups = FrontController::getCurrentCustomerGroups(); - $sqlGroups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); + $sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); + $interval = Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20; $sql = 'SELECT p.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, - pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, m.`name` AS manufacturer_name, p.`id_manufacturer` as id_manufacturer, + pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, + pl.`meta_keywords`, pl.`meta_title`, pl.`name`, + m.`name` AS manufacturer_name, p.`id_manufacturer` as id_manufacturer, i.`id_image`, il.`legend`, ps.`quantity` AS sales, t.`rate`, pl.`meta_keywords`, pl.`meta_title`, pl.`meta_description`, - DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 AS new + DATEDIFF(p.`date_add`, DATE_SUB(NOW(), + INTERVAL '.$interval.' DAY)) > 0 AS new FROM `'._DB_PREFIX_.'product_sale` ps LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product` '.$context->shop->addSqlAssociation('product', 'p', false).' - LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.$context->shop->addSqlRestrictionOnLang('pl').') + LEFT JOIN `'._DB_PREFIX_.'product_lang` pl + ON p.`id_product` = pl.`id_product` + AND pl.`id_lang` = '.(int)$id_lang.$context->shop->addSqlRestrictionOnLang('pl').' LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) @@ -100,15 +106,15 @@ class ProductSaleCore SELECT cp.`id_product` FROM `'._DB_PREFIX_.'category_group` cg LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) - WHERE cg.`id_group` '.$sqlGroups.' + WHERE cg.`id_group` '.$sql_groups.' ) - ORDER BY `'.pSQL($orderBy).'` '.pSQL($orderWay).' - LIMIT '.(int)($pageNumber * $nbProducts).', '.(int)$nbProducts; + ORDER BY `'.pSQL($order_by).'` '.pSQL($order_way).' + LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products; $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); - if ($orderBy == 'price') - Tools::orderbyPrice($result,$orderWay); + if ($order_by == 'price') + Tools::orderbyPrice($result, $order_way); if (!$result) return false; return Product::getProductsProperties($id_lang, $result); @@ -118,41 +124,46 @@ class ProductSaleCore ** Get required informations on best sales products ** ** @param integer $id_lang Language id - ** @param integer $pageNumber Start from (optional) - ** @param integer $nbProducts Number of products to return (optional) + ** @param integer $page_number Start from (optional) + ** @param integer $nb_products Number of products to return (optional) ** @return array keys : id_product, link_rewrite, name, id_image, legend, sales, ean13, upc, link */ - static public function getBestSalesLight($id_lang, $pageNumber = 0, $nbProducts = 10, Context $context = null) + public static function getBestSalesLight($id_lang, $page_number = 0, $nb_products = 10, Context $context = null) { if (!$context) $context = Context::getContext(); - if ($pageNumber < 0) $pageNumber = 0; - if ($nbProducts < 1) $nbProducts = 10; + if ($page_number < 0) $page_number = 0; + if ($nb_products < 1) $nb_products = 10; $groups = FrontController::getCurrentCustomerGroups(); - $sqlGroups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); + $sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1'); - $sql = 'SELECT p.id_product, pl.`link_rewrite`, pl.`name`, pl.`description_short`, i.`id_image`, il.`legend`, ps.`quantity` AS sales, p.`ean13`, p.`upc`, cl.`link_rewrite` AS category + $sql = 'SELECT p.id_product, pl.`link_rewrite`, pl.`name`, pl.`description_short`, i.`id_image`, il.`legend`, + ps.`quantity` AS sales, p.`ean13`, p.`upc`, cl.`link_rewrite` AS category FROM `'._DB_PREFIX_.'product_sale` ps LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product` '.$context->shop->addSqlAssociation('product', 'p').' - LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.$context->shop->addSqlRestrictionOnLang('pl').') + LEFT JOIN `'._DB_PREFIX_.'product_lang` pl + ON p.`id_product` = pl.`id_product` + AND pl.`id_lang` = '.(int)$id_lang.$context->shop->addSqlRestrictionOnLang('pl').' LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') - LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (cl.`id_category` = p.`id_category_default` AND cl.`id_lang` = '.(int)$id_lang.$context->shop->addSqlRestrictionOnLang('cl').') + LEFT JOIN `'._DB_PREFIX_.'category_lang` cl + ON cl.`id_category` = p.`id_category_default` + AND cl.`id_lang` = '.(int)$id_lang.$context->shop->addSqlRestrictionOnLang('cl').' WHERE p.`active` = 1 AND p.`id_product` IN ( SELECT cp.`id_product` FROM `'._DB_PREFIX_.'category_group` cg LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) - WHERE cg.`id_group` '.$sqlGroups.' + WHERE cg.`id_group` '.$sql_groups.' ) ORDER BY sales DESC - LIMIT '.(int)($pageNumber * $nbProducts).', '.(int)$nbProducts; + LIMIT '.(int)($page_number * $nb_products).', '.(int)$nb_products; if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql)) return false; - foreach ($result AS &$row) + foreach ($result as &$row) { $row['link'] = $context->link->getProductLink($row['id_product'], $row['link_rewrite'], $row['category'], $row['ean13']); $row['id_image'] = Product::defineProductImage($row, $id_lang); @@ -165,25 +176,29 @@ class ProductSaleCore return Db::getInstance()->execute(' INSERT INTO '._DB_PREFIX_.'product_sale (`id_product`, `quantity`, `sale_nbr`, `date_upd`) - VALUES ('.(int)($product_id).', '.(int)($qty).', 1, NOW()) - ON DUPLICATE KEY UPDATE `quantity` = `quantity` + '.(int)($qty).', `sale_nbr` = `sale_nbr` + 1, `date_upd` = NOW()'); + VALUES ('.(int)$product_id.', '.(int)$qty.', 1, NOW()) + ON DUPLICATE KEY UPDATE `quantity` = `quantity` + '.(int)$qty.', `sale_nbr` = `sale_nbr` + 1, `date_upd` = NOW()'); } public static function getNbrSales($id_product) { - $result = Db::getInstance()->getRow('SELECT `sale_nbr` FROM '._DB_PREFIX_.'product_sale WHERE `id_product` = '.(int)($id_product)); - if (!$result OR empty($result) OR !key_exists('sale_nbr', $result)) + $result = Db::getInstance()->getRow('SELECT `sale_nbr` FROM '._DB_PREFIX_.'product_sale WHERE `id_product` = '.(int)$id_product); + if (!$result || empty($result) || !key_exists('sale_nbr', $result)) return -1; - return (int)($result['sale_nbr']); + return (int)$result['sale_nbr']; } public static function removeProductSale($id_product, $qty = 1) { - $nbrSales = ProductSale::getNbrSales($id_product); - if ($nbrSales > 1) - return Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'product_sale SET `quantity` = `quantity` - '.(int)($qty).', `sale_nbr` = `sale_nbr` - 1, `date_upd` = NOW() WHERE `id_product` = '.(int)($id_product)); - elseif ($nbrSales == 1) - return Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'product_sale WHERE `id_product` = '.(int)($id_product)); + $total_sales = ProductSale::getNbrSales($id_product); + if ($total_sales > 1) + return Db::getInstance()->execute(' + UPDATE '._DB_PREFIX_.'product_sale + SET `quantity` = `quantity` - '.(int)$qty.', `sale_nbr` = `sale_nbr` - 1, `date_upd` = NOW() + WHERE `id_product` = '.(int)$id_product + ); + elseif ($total_sales == 1) + return Db::getInstance()->delete(_DB_PREFIX_.'product_sale', 'id_product = '.(int)$id_product); return true; } } diff --git a/classes/Profile.php b/classes/Profile.php index dc5841e25..14301b1af 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -1,6 +1,6 @@ executeS(' SELECT p.`id_profile`, `name` FROM `'._DB_PREFIX_.'profile` p - LEFT JOIN `'._DB_PREFIX_.'profile_lang` pl ON (p.`id_profile` = pl.`id_profile` AND `id_lang` = '.(int)($id_lang).') + LEFT JOIN `'._DB_PREFIX_.'profile_lang` pl ON (p.`id_profile` = pl.`id_profile` AND `id_lang` = '.(int)$id_lang.') ORDER BY `id_profile` ASC'); } @@ -64,29 +64,35 @@ class ProfileCore extends ObjectModel * * @return string Profile */ - public static function getProfile($id_profile, $id_lang = NULL) + public static function getProfile($id_profile, $id_lang = null) { - if ($id_lang == NULL) + if (!$id_lang) $id_lang = Configuration::get('PS_LANG_DEFAULT'); + return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' - SELECT `name` - FROM `'._DB_PREFIX_.'profile` p - LEFT JOIN `'._DB_PREFIX_.'profile_lang` pl ON (p.`id_profile` = pl.`id_profile`) - WHERE p.`id_profile` = '.(int)$id_profile.' - AND pl.`id_lang` = '.(int)$id_lang); + SELECT `name` + FROM `'._DB_PREFIX_.'profile` p + LEFT JOIN `'._DB_PREFIX_.'profile_lang` pl ON (p.`id_profile` = pl.`id_profile`) + WHERE p.`id_profile` = '.(int)$id_profile.' + AND pl.`id_lang` = '.(int)$id_lang + ); } - - public function add($autodate = true, $nullValues = false) + public function add($autodate = true, $null_values = false) { - if (parent::add($autodate, true)) - return ( - Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'access (SELECT '.(int)$this->id.', id_tab, 0, 0, 0, 0 FROM '._DB_PREFIX_.'tab)') - && Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'module_access (`id_profile`, `id_module`, `configure`, `view`) (SELECT '.(int)$this->id.', id_module, 0, 1 FROM '._DB_PREFIX_.'module)') - ); + if (parent::add($autodate, true)) + { + $result = Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'access (SELECT '.(int)$this->id.', id_tab, 0, 0, 0, 0 FROM '._DB_PREFIX_.'tab)'); + $result &= Db::getInstance()->execute(' + INSERT INTO '._DB_PREFIX_.'module_access + (`id_profile`, `id_module`, `configure`, `view`) + (SELECT '.(int)$this->id.', id_module, 0, 1 FROM '._DB_PREFIX_.'module) + '); + return $result; + } return false; } - + public function delete() { if (parent::delete()) @@ -114,7 +120,7 @@ class ProfileCore extends ObjectModel WHERE `id_profile` = '.(int)$id_profile); self::$_cache_accesses[$id_profile] = array(); - foreach ($result AS $row) + foreach ($result as $row) { if (!isset(self::$_cache_accesses[$id_profile][$row['id_tab']])) self::$_cache_accesses[$id_profile][$row['id_tab']] = array(); diff --git a/classes/QuickAccess.php b/classes/QuickAccess.php index e8e27e546..7d6103513 100644 --- a/classes/QuickAccess.php +++ b/classes/QuickAccess.php @@ -1,6 +1,6 @@ executeS(' SELECT * FROM `'._DB_PREFIX_.'range_price` - WHERE `id_carrier` = '.(int)($id_carrier).' + WHERE `id_carrier` = '.(int)$id_carrier.' ORDER BY `delimiter1` ASC'); } - + /** * Override add to create delivery value for all zones * @see classes/ObjectModelCore::add() @@ -78,20 +78,19 @@ class RangePriceCore extends ObjectModel { if (!parent::add($autodate, $null_values) || !Validate::isLoadedObject($this)) return false; - + $carrier = new Carrier((int)$this->id_carrier); - $priceList = array(); + $price_list = array(); foreach ($carrier->getZones() as $zone) - $priceList[] = array( + $price_list[] = array( 'id_range_price' => (int)$this->id, 'id_range_weight' => 0, 'id_carrier' => (int)$this->id_carrier, 'id_zone' => (int)$zone['id_zone'], 'price' => 0, ); - $carrier->addDeliveryPrice($priceList); - + $carrier->addDeliveryPrice($price_list); + return true; } -} - +} \ No newline at end of file diff --git a/classes/RangeWeight.php b/classes/RangeWeight.php index 6e4002358..c2aa7a078 100644 --- a/classes/RangeWeight.php +++ b/classes/RangeWeight.php @@ -1,6 +1,6 @@ executeS(' SELECT * FROM `'._DB_PREFIX_.'range_weight` - WHERE `id_carrier` = '.(int)($id_carrier).' + WHERE `id_carrier` = '.(int)$id_carrier.' ORDER BY `delimiter1` ASC'); } - + /** * Override add to create delivery value for all zones * @see classes/ObjectModelCore::add() @@ -78,20 +78,19 @@ class RangeWeightCore extends ObjectModel { if (!parent::add($autodate, $null_values) || !Validate::isLoadedObject($this)) return false; - + $carrier = new Carrier((int)$this->id_carrier); - $priceList = array(); + $price_list = array(); foreach ($carrier->getZones() as $zone) - $priceList[] = array( + $price_list[] = array( 'id_range_price' => 0, 'id_range_weight' => (int)$this->id, 'id_carrier' => (int)$this->id_carrier, 'id_zone' => (int)$zone['id_zone'], 'price' => 0, ); - $carrier->addDeliveryPrice($priceList); - + $carrier->addDeliveryPrice($price_list); + return true; } } - diff --git a/classes/Referrer.php b/classes/Referrer.php index 0c8391f24..b9cad8f8b 100644 --- a/classes/Referrer.php +++ b/classes/Referrer.php @@ -1,6 +1,6 @@ $this->id))); Referrer::refreshIndex(array(array('id_referrer' => $this->id))); @@ -334,22 +334,24 @@ class ReferrerCore extends ObjectModel if ((int)$id_product && !$stats_visits['visits'] && !$stats_sales['orders']) exit; - $json_array = array(); - $json_array[] = '"id_product":"'.(int)$product->id.'"'; - $json_array[] = '"product_name":"'.addslashes($product->name).'"'; - $json_array[] = '"uniqs":"'.(int)$stats_visits['uniqs'].'"'; - $json_array[] = '"visitors":"'.(int)$stats_visits['visitors'].'"'; - $json_array[] = '"visits":"'.(int)$stats_visits['visits'].'"'; - $json_array[] = '"pages":"'.(int)$stats_visits['pages'].'"'; - $json_array[] = '"registrations":"'.(int)$registrations.'"'; - $json_array[] = '"orders":"'.(int)$stats_sales['orders'].'"'; - $json_array[] = '"sales":"'.Tools::displayPrice($stats_sales['sales'], $currency).'"'; - $json_array[] = '"cart":"'.Tools::displayPrice(((int)$stats_sales['orders'] ? $stats_sales['sales'] / (int)$stats_sales['orders'] : 0), $currency).'"'; - $json_array[] = '"reg_rate":"'.number_format((int)$stats_visits['uniqs'] ? (int)$registrations / (int)$stats_visits['uniqs'] : 0, 4, '.', '').'"'; - $json_array[] = '"order_rate":"'.number_format((int)$stats_visits['uniqs'] ? (int)$stats_sales['orders'] / (int)$stats_visits['uniqs'] : 0, 4, '.', '').'"'; - $json_array[] = '"click_fee":"'.Tools::displayPrice((int)$stats_visits['visits'] * $referrer->click_fee, $currency).'"'; - $json_array[] = '"base_fee":"'.Tools::displayPrice($stats_sales['orders'] * $referrer->base_fee, $currency).'"'; - $json_array[] = '"percent_fee":"'.Tools::displayPrice($stats_sales['sales'] * $referrer->percent_fee / 100, $currency).'"'; - die ('[{'.implode(',', $json_array).'}]'); + $json_array = array( + 'id_product' => (int)$product->id, + 'product_name' => addslashes($product->name), + 'uniqs' => (int)$stats_visits['uniqs'], + 'visitors' => (int)$stats_visits['visitors'], + 'visits' => (int)$stats_visits['visits'], + 'pages' => (int)$stats_visits['pages'], + 'registrations' => (int)$registrations, + 'orders' => (int)$stats_sales['orders'], + 'sales' => Tools::displayPrice($stats_sales['sales'], $currency), + 'cart' => Tools::displayPrice(((int)$stats_sales['orders'] ? $stats_sales['sales'] / (int)$stats_sales['orders'] : 0), $currency), + 'reg_rate' => number_format((int)$stats_visits['uniqs'] ? (int)$registrations / (int)$stats_visits['uniqs'] : 0, 4, '.', ''), + 'order_rate' => number_format((int)$stats_visits['uniqs'] ? (int)$stats_sales['orders'] / (int)$stats_visits['uniqs'] : 0, 4, '.', ''), + 'click_fee' => Tools::displayPrice((int)$stats_visits['visits'] * $referrer->click_fee, $currency), + 'base_fee' => Tools::displayPrice($stats_sales['orders'] * $referrer->base_fee, $currency), + 'percent_fee' => Tools::displayPrice($stats_sales['sales'] * $referrer->percent_fee / 100, $currency), + ); + + die ('['.Tools::jsonEncode($json_array).']'); } } \ No newline at end of file diff --git a/classes/Rijndael.php b/classes/Rijndael.php index 404b4371a..724a10e31 100644 --- a/classes/Rijndael.php +++ b/classes/Rijndael.php @@ -1,6 +1,6 @@ _key = $key; $this->_iv = base64_decode($iv); } - - // Base64 is not required, but it is be more compact than urlencode + + /** + * Base64 is not required, but it is be more compact than urlencode + * + * @param string $plaintext + * @return bool|string + */ public function encrypt($plaintext) { $length = (ini_get('mbstring.func_overload') & 2) ? mb_strlen($plaintext, ini_get('default_charset')) : strlen($plaintext); @@ -50,15 +55,20 @@ class RijndaelCore { if (ini_get('mbstring.func_overload') & 2) { - $plainTextLength = intval(mb_substr($ciphertext, -6, 6, ini_get('default_charset'))); + $length = intval(mb_substr($ciphertext, -6, 6, ini_get('default_charset'))); $ciphertext = mb_substr($ciphertext, 0, -6, ini_get('default_charset')); - return mb_substr(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->_key, base64_decode($ciphertext), MCRYPT_MODE_ECB, $this->_iv), 0, $plainTextLength, ini_get('default_charset')); + return mb_substr( + mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->_key, base64_decode($ciphertext), MCRYPT_MODE_ECB, $this->_iv), + 0, + $length, + ini_get('default_charset') + ); } else { - $plainTextLength = intval(substr($ciphertext, -6)); + $length = intval(substr($ciphertext, -6)); $ciphertext = substr($ciphertext, 0, -6); - return substr(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->_key, base64_decode($ciphertext), MCRYPT_MODE_ECB, $this->_iv), 0, $plainTextLength); + return substr(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->_key, base64_decode($ciphertext), MCRYPT_MODE_ECB, $this->_iv), 0, $length); } } } diff --git a/classes/Scene.php b/classes/Scene.php index 2464d8962..1ba68c4cf 100644 --- a/classes/Scene.php +++ b/classes/Scene.php @@ -28,19 +28,19 @@ class SceneCore extends ObjectModel { /** @var string Name */ - public $name; + public $name; /** @var boolean Active Scene */ - public $active = true; + public $active = true; /** @var array Zone for image map */ - public $zones = array(); + public $zones = array(); /** @var array list of category where this scene is available */ - public $categories = array(); + public $categories = array(); /** @var array Products */ - public $products; + public $products; /** * @see ObjectModel::$definition @@ -59,25 +59,25 @@ class SceneCore extends ObjectModel protected static $feature_active = null; - public function __construct($id = NULL, $id_lang = NULL, $liteResult = true, $hideScenePosition = false) + public function __construct($id = null, $id_lang = null, $lite_result = true, $hide_scene_position = false) { parent::__construct($id, $id_lang); - if (!$liteResult) - $this->products = $this->getProducts(true, (int)($id_lang), false); - if ($hideScenePosition) + if (!$lite_result) + $this->products = $this->getProducts(true, (int)$id_lang, false); + if ($hide_scene_position) $this->name = Scene::hideScenePosition($this->name); $this->image_dir = _PS_SCENE_IMG_DIR_; } - public function update($nullValues = false) + public function update($null_values = false) { if (!$this->updateZoneProducts()) return false; if (!$this->updateCategories()) return false; - if (parent::update($nullValues)) + if (parent::update($null_values)) { // Refresh cache of feature detachable Configuration::updateGlobalValue('PS_SCENE_FEATURE_ACTIVE', Scene::isCurrentlyUsed($this->def['table'], true)); @@ -87,14 +87,14 @@ class SceneCore extends ObjectModel } - public function add($autodate = true, $nullValues = false) + public function add($autodate = true, $null_values = false) { if (!empty($this->zones)) $this->addZoneProducts($this->zones); if (!empty($this->categories)) $this->addCategories($this->categories); - if (parent::add($autodate, $nullValues)) + if (parent::add($autodate, $null_values)) { // Put cache of feature detachable only if this new scene is active else we keep the old value if ($this->active) @@ -131,67 +131,73 @@ class SceneCore extends ObjectModel public function addCategories($categories) { - $result = true; - foreach ($categories AS $category) + $data = array(); + foreach ($categories as $category) { - if (!Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'scene_category` ( `id_scene` , `id_category`) VALUES ('.(int)($this->id).', '.(int)($category).')')) - $result = false; + $data[] = array( + 'id_scene' => (int)$this->id, + 'id_category' => (int)$category, + ); } - return $result; + return Db::getInstance()->autoExecute(_DB_PREFIX_.'scene_category', $data, 'INSERT'); } public function deleteCategories() { return Db::getInstance()->execute(' DELETE FROM `'._DB_PREFIX_.'scene_category` - WHERE `id_scene` = '.(int)($this->id)); + WHERE `id_scene` = '.(int)$this->id); } public function updateCategories() { if (!$this->deleteCategories()) return false; - if (!empty($this->categories) AND !$this->addCategories($this->categories)) + if (!empty($this->categories) && !$this->addCategories($this->categories)) return false; return true; } public function addZoneProducts($zones) { - $result = true; - foreach ($zones AS $zone) + $data = array(); + foreach ($zones as $zone) { - // @todo use multiple insert - $sql = 'INSERT INTO `'._DB_PREFIX_.'scene_products` ( `id_scene` , `id_product` , `x_axis` , `y_axis` , `zone_width` , `zone_height`) VALUES - ('.(int)($this->id).', '.(int)($zone['id_product']).', '.(int)($zone['x1']).', '.(int)($zone['y1']).', '.(int)($zone['width']).', '.(int)($zone['height']).')'; - if (!Db::getInstance()->execute($sql)) - $result = false; + $data[] = array( + 'id_scene' => (int)$this->id, + 'id_product' => (int)$zone['id_product'], + 'x_axis' => (int)$zone['x1'], + 'y_axis' => (int)$zone['y1'], + 'zone_width' => (int)$zone['width'], + 'zone_height' => (int)$zone['height'], + ); } - return $result; + + return Db::getInstance()->autoExecute(_DB_PREFIX_.'scene_products', $data, 'INSERT'); } public function deleteZoneProducts() { return Db::getInstance()->execute(' DELETE FROM `'._DB_PREFIX_.'scene_products` - WHERE `id_scene` = '.(int)($this->id)); + WHERE `id_scene` = '.(int)$this->id); } public function updateZoneProducts() { if (!$this->deleteZoneProducts()) return false; - if ($this->zones AND !$this->addZoneProducts($this->zones)) + if ($this->zones && !$this->addZoneProducts($this->zones)) return false; return true; } /** - * Get all scenes of a category - * - * @return array Products - */ - public static function getScenes($id_category, $id_lang = NULL, $onlyActive = true, $liteResult = true, $hideScenePosition = true, Context $context = null) + * Get all scenes of a category + * + * @return array Products + */ + public static function getScenes($id_category, $id_lang = null, $only_active = true, $lite_result = true, $hide_scene_position = true, Context $context = null) { if (!Scene::isFeatureActive()) return array(); @@ -207,13 +213,13 @@ class SceneCore extends ObjectModel 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' : '').' + .($only_active ? ' AND s.active = 1' : '').' ORDER BY sl.name ASC'; $scenes = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); - if (!$liteResult AND $scenes) - foreach($scenes AS &$scene) - $scene = new Scene($scene['id_scene'], $id_lang, false, $hideScenePosition); + if (!$lite_result && $scenes) + foreach ($scenes as &$scene) + $scene = new Scene($scene['id_scene'], $id_lang, false, $hide_scene_position); return $scenes; } @@ -222,7 +228,7 @@ class SceneCore extends ObjectModel * * @return array Products */ - public function getProducts($onlyActive = true, $id_lang = NULL, $liteResult = true, Context $context = null) + public function getProducts($only_active = true, $id_lang = null, $lite_result = true, Context $context = null) { if (!Scene::isFeatureActive()) return array(); @@ -235,15 +241,20 @@ class SceneCore extends ObjectModel 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.($only_active ? ' AND p.active = 1' : '')); - if (!$liteResult AND $products) - foreach ($products AS &$product) + if (!$lite_result && $products) + foreach ($products as &$product) { - $product['details'] = new Product($product['id_product'], !$liteResult, $id_lang); - $product['link'] = $context->link->getProductLink($product['details']->id, $product['details']->link_rewrite, $product['details']->category, $product['details']->ean13); + $product['details'] = new Product($product['id_product'], !$lite_result, $id_lang); + $product['link'] = $context->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)) + if (is_array($cover)) $product = array_merge($cover, $product); } return $products; @@ -260,7 +271,7 @@ class SceneCore extends ObjectModel return Db::getInstance()->executeS(' SELECT `id_category` FROM `'._DB_PREFIX_.'scene_category` - WHERE `id_scene` = '.(int)($id_scene)); + WHERE `id_scene` = '.(int)$id_scene); } /** diff --git a/classes/SearchEngine.php b/classes/SearchEngine.php index a12bbc1be..cf824722a 100644 --- a/classes/SearchEngine.php +++ b/classes/SearchEngine.php @@ -1,6 +1,6 @@ executeS('SELECT `server`, `getvar` FROM `'._DB_PREFIX_.'search_engine`'); foreach ($result as $row) { $host =& $row['server']; $varname =& $row['getvar']; - if (strstr($parsedUrl['host'], $host)) + if (strstr($parsed_url['host'], $host)) { - $kArray = array(); - preg_match('/[^a-z]'.$varname.'=.+\&'.'/U', $parsedUrl['query'], $kArray); - if (empty($kArray[0])) - preg_match('/[^a-z]'.$varname.'=.+$'.'/', $parsedUrl['query'], $kArray); - if (empty($kArray[0])) + $array = array(); + preg_match('/[^a-z]'.$varname.'=.+\&/U', $parsed_url['query'], $array); + if (empty($array[0])) + preg_match('/[^a-z]'.$varname.'=.+$/', $parsed_url['query'], $array); + if (empty($array[0])) return false; - $kString = urldecode(str_replace('+', ' ', ltrim(substr(rtrim($kArray[0], '&'), strlen($varname) + 1), '='))); - return $kString; + $str = urldecode(str_replace('+', ' ', ltrim(substr(rtrim($array[0], '&'), strlen($varname) + 1), '='))); + return $str; } } } diff --git a/classes/SpecificPrice.php b/classes/SpecificPrice.php index 6647dfe8d..5dd7ee718 100644 --- a/classes/SpecificPrice.php +++ b/classes/SpecificPrice.php @@ -120,7 +120,7 @@ class SpecificPriceCore extends ObjectModel AND id_product_attribute='.(int)$id_product_attribute.' AND id_cart='.(int)$id_cart); } - + public static function deleteByIdCart($id_cart, $id_product = false, $id_product_attribute = false) { return Db::getInstance()->Execute(' @@ -139,7 +139,9 @@ class SpecificPriceCore extends ObjectModel AND id_cart='.(int)$id_cart); } - // score generation for quantity discount + /** + * score generation for quantity discount + */ protected static function _getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group, $id_customer) { $select = '('; @@ -149,7 +151,7 @@ class SpecificPriceCore extends ObjectModel $priority = SpecificPrice::getPriority($id_product); foreach (array_reverse($priority) as $k => $field) - $select .= ' IF (`'.bqSQL($field).'` = '.(int)(${$field}).', '.pow(2, $k + 1).', 0) + '; + $select .= ' IF (`'.bqSQL($field).'` = '.(int)$$field.', '.pow(2, $k + 1).', 0) + '; return rtrim($select, ' +').') AS `score`'; } @@ -159,8 +161,8 @@ class SpecificPriceCore extends ObjectModel if (!SpecificPrice::isFeatureActive()) return explode(';', Configuration::get('PS_SPECIFIC_PRICE_PRIORITIES')); - if (!isset(self::$_cache_priorities[(int)$id_product])) - { + if (!isset(self::$_cache_priorities[(int)$id_product])) + { self::$_cache_priorities[(int)$id_product] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT `priority`, `id_specific_price_priority` FROM `'._DB_PREFIX_.'specific_price_priority` @@ -251,7 +253,7 @@ class SpecificPriceCore extends ObjectModel return array(); $now = date('Y-m-d H:i:s'); - $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' + $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT *, '.SpecificPrice::_getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group, $id_customer).' FROM `'._DB_PREFIX_.'specific_price` @@ -275,7 +277,7 @@ class SpecificPriceCore extends ObjectModel $targeted_prices = array(); $last_quantity = null; - foreach($res as $specific_price) + foreach ($res as $specific_price) { if (!isset($last_quantity)) $last_quantity = $specific_price['from_quantity']; diff --git a/classes/SpecificPriceRule.php b/classes/SpecificPriceRule.php index 526b7e038..91dcd3c31 100755 --- a/classes/SpecificPriceRule.php +++ b/classes/SpecificPriceRule.php @@ -80,14 +80,25 @@ class SpecificPriceRuleCore extends ObjectModel { if (!is_array($conditions)) return; - if (!Db::getInstance()->Execute('INSERT INTO `'._DB_PREFIX_.'specific_price_rule_condition_group` (`id_specific_price_rule_condition_group`, `id_specific_price_rule`) - VALUES(\'\', '.(int)$this->id.')')) + + $result = Db::getInstance()->autoExecute(_DB_PREFIX_.'specific_price_rule_condition_group', array( + 'id_specific_price_rule_condition_group' => '', + 'id_specific_price_rule' => (int)$this->id + ), 'INSERT'); + if (!$result) return false; $id_specific_price_rule_condition_group = (int)Db::getInstance()->Insert_ID(); foreach ($conditions as $condition) - if (!Db::getInstance()->Execute('INSERT INTO '._DB_PREFIX_.'specific_price_rule_condition (id_specific_price_rule_condition, id_specific_price_rule_condition_group, type, value) - VALUES(\'\', '.(int)$id_specific_price_rule_condition_group.', \''.pSQL($condition['type']).'\', \''.pSQL($condition['value']).'\')')) + { + $result = Db::getInstance()->autoExecute(_DB_PREFIX_.'specific_price_rule_condition', array( + 'id_specific_price_rule_condition' => '', + 'id_specific_price_rule_condition_group' => (int)$id_specific_price_rule_condition_group, + 'type' => $condition['type'], + 'value' => $condition['value'], + ), 'INSERT'); + if (!$result) return false; + } return true; } @@ -113,14 +124,18 @@ class SpecificPriceRuleCore extends ObjectModel public function getConditions() { - $conditions = Db::getInstance()->executeS('SELECT sprd.* - FROM '._DB_PREFIX_.'specific_price_rule_condition_group sprdg - LEFT JOIN '._DB_PREFIX_.'specific_price_rule_condition sprd ON (sprd.id_specific_price_rule_condition_group = sprdg.id_specific_price_rule_condition_group) - WHERE sprdg.id_specific_price_rule='.(int)$this->id); + $conditions = Db::getInstance()->executeS(' + SELECT g.* + FROM '._DB_PREFIX_.'specific_price_rule_condition_group g + LEFT JOIN '._DB_PREFIX_.'specific_price_rule_condition c + ON (c.id_specific_price_rule_condition_group = g.id_specific_price_rule_condition_group) + WHERE g.id_specific_price_rule='.(int)$this->id + ); + $conditions_group = array(); if ($conditions) { - foreach ($conditions AS &$condition) + foreach ($conditions as &$condition) { if ($condition['type'] == 'attribute') $condition['id_attribute_group'] = Db::getInstance()->getValue('SELECT id_attribute_group @@ -225,8 +240,8 @@ class SpecificPriceRuleCore extends ObjectModel $specific_price->id_group = (int)$rule->id_group; $specific_price->from_quantity = (int)$rule->from_quantity; $specific_price->price = (int)$rule->price; - $specific_price->reduction_type = pSQL($rule->reduction_type); - $specific_price->reduction = ($rule->reduction_type == 'percentage' ? (float)($rule->reduction / 100) : (float)$rule->reduction); + $specific_price->reduction_type = $rule->reduction_type; + $specific_price->reduction = ($rule->reduction_type == 'percentage' ? $rule->reduction / 100 : (float)$rule->reduction); $specific_price->from = $rule->from; $specific_price->to = $rule->to; diff --git a/classes/State.php b/classes/State.php index 637c88bb3..02dae4177 100644 --- a/classes/State.php +++ b/classes/State.php @@ -28,19 +28,19 @@ class StateCore extends ObjectModel { /** @var integer Country id which state belongs */ - public $id_country; + public $id_country; /** @var integer Zone id which state belongs */ - public $id_zone; + public $id_zone; /** @var string 2 letters iso code */ - public $iso_code; + public $iso_code; /** @var string Name */ - public $name; + public $name; /** @var boolean Status for delivery */ - public $active = true; + public $active = true; /** * @see ObjectModel::$definition @@ -74,36 +74,38 @@ class StateCore extends ObjectModel } /** - * Get a state name with its ID - * - * @param integer $id_state Country ID - * @return string State name - */ + * Get a state name with its ID + * + * @param integer $id_state Country ID + * @return string State name + */ public static function getNameById($id_state) { $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' - SELECT `name` - FROM `'._DB_PREFIX_.'state` - WHERE `id_state` = '.(int)($id_state)); + SELECT `name` + FROM `'._DB_PREFIX_.'state` + WHERE `id_state` = '.(int)$id_state + ); - return $result['name']; - } + return $result['name']; + } /** - * Get a state id with its name - * - * @param string $id_state Country ID - * @return integer state id - */ + * Get a state id with its name + * + * @param string $id_state Country ID + * @return integer state id + */ public static function getIdByName($state) - { - $result = Db::getInstance()->getRow(' - SELECT `id_state` - FROM `'._DB_PREFIX_.'state` - WHERE `name` LIKE \''.pSQL($state).'\''); + { + $result = Db::getInstance()->getValue(' + SELECT `id_state` + FROM `'._DB_PREFIX_.'state` + WHERE `name` LIKE \''.pSQL($state).'\' + '); - return ((int)($result['id_state'])); - } + return (int)$result; + } /** * Get a state id with its iso code @@ -112,13 +114,13 @@ class StateCore extends ObjectModel * @return integer state id */ public static function getIdByIso($iso_code) - { + { return Db::getInstance()->getValue(' SELECT `id_state` FROM `'._DB_PREFIX_.'state` WHERE `iso_code` = \''.pSQL($iso_code).'\'' ); - } + } /** * Delete a state only if is not in use @@ -130,7 +132,7 @@ class StateCore extends ObjectModel if (!$this->isUsed()) { /* Database deletion */ - $result = Db::getInstance()->execute('DELETE FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'` WHERE `'.$this->def['primary'] .'` = '.(int)$this->id); + $result = Db::getInstance()->delete(_DB_PREFIX_.$this->def['table'], '`'.$this->def['primary'].'` = '.(int)$this->id); if (!$result) return false; @@ -160,11 +162,12 @@ class StateCore extends ObjectModel */ public function countUsed() { - $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' - SELECT COUNT(*) AS nb_used - FROM `'._DB_PREFIX_.'address` - WHERE `'.$this->def['primary'].'` = '.(int)($this->id)); - return $row['nb_used']; + $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' + SELECT COUNT(*) + FROM `'._DB_PREFIX_.'address` + WHERE `'.$this->def['primary'].'` = '.(int)$this->id + ); + return $result; } public static function getStatesByIdCountry($id_country) @@ -181,32 +184,33 @@ class StateCore extends ObjectModel public static function hasCounties($id_state) { - return sizeof(County::getCounties((int)$id_state)); + return count(County::getCounties((int)$id_state)); } - + public static function getIdZone($id_state) { if (!Validate::isUnsignedId($id_state)) die(Tools::displayError()); return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' - SELECT `id_zone` - FROM `'._DB_PREFIX_.'state` - WHERE `id_state` = '.(int)($id_state)); + SELECT `id_zone` + FROM `'._DB_PREFIX_.'state` + WHERE `id_state` = '.(int)$id_state + ); } - /** - * @param $ids_states - * @param $id_zone - * @return bool - */ - public function affectZoneToSelection($ids_states, $id_zone) - { - // cast every array values to int (security) - $ids_states = array_map('intval', $ids_states); - return Db::getInstance()->execute(' - UPDATE `'._DB_PREFIX_.'state` SET `id_zone` = '.(int)$id_zone.' WHERE `id_state` IN ('.implode(',', $ids_states).') - '); - } + /** + * @param $ids_states + * @param $id_zone + * @return bool + */ + public function affectZoneToSelection($ids_states, $id_zone) + { + // cast every array values to int (security) + $ids_states = array_map('intval', $ids_states); + return Db::getInstance()->execute(' + UPDATE `'._DB_PREFIX_.'state` SET `id_zone` = '.(int)$id_zone.' WHERE `id_state` IN ('.implode(',', $ids_states).') + '); + } } diff --git a/classes/Store.php b/classes/Store.php index 229960b37..eb28d0a84 100644 --- a/classes/Store.php +++ b/classes/Store.php @@ -1,6 +1,6 @@ id_image = ($this->id AND file_exists(_PS_STORE_IMG_DIR_.(int)$this->id.'.jpg')) ? (int)$this->id : false; + $this->id_image = ($this->id && file_exists(_PS_STORE_IMG_DIR_.(int)$this->id.'.jpg')) ? (int)$this->id : false; $this->image_dir = _PS_STORE_IMG_DIR_; } - + public function getWsHours() { return implode(';', unserialize($this->hours)); } - + public function setWsHours($hours) { $this->hours = serialize(explode(';', $hours)); diff --git a/classes/SubDomain.php b/classes/SubDomain.php index 80b7f664b..8636f3d51 100644 --- a/classes/SubDomain.php +++ b/classes/SubDomain.php @@ -1,6 +1,6 @@ executeS('SELECT `name` FROM `'._DB_PREFIX_.'subdomain`')) return false; - $subDomains = array(); - foreach ($result AS $row) - $subDomains[] = $row['name']; - return $subDomains; + $domains = array(); + foreach ($result as $row) + $domains[] = $row['name']; + return $domains; } } diff --git a/classes/Tab.php b/classes/Tab.php index cdfc3bda0..9003e0f91 100644 --- a/classes/Tab.php +++ b/classes/Tab.php @@ -71,7 +71,7 @@ class TabCore extends ObjectModel * - add access for admin profile * * @param boolean $autodate - * @param boolean $nullValues + * @param boolean $null_values * @return int id_tab */ public function add($autodate = true, $null_values = false) @@ -90,6 +90,7 @@ class TabCore extends ObjectModel * * @todo this should not be public static but protected * @param int $id_tab + * @param Context $context * @return boolean true if succeed */ public static function initAccess($id_tab, Context $context = null) @@ -275,8 +276,10 @@ class TabCore extends ObjectModel public static function enablingForModule($module) { $tabs = Tab::getCollectionFromModule($module); - if (!empty($tabs)) { - foreach ($tabs as $tab) { + if (!empty($tabs)) + { + foreach ($tabs as $tab) + { $tab->active = 1; $tab->save(); } @@ -294,8 +297,10 @@ class TabCore extends ObjectModel public static function disablingForModule($module) { $tabs = Tab::getCollectionFromModule($module); - if (!empty($tabs)) { - foreach ($tabs as $tab) { + if (!empty($tabs)) + { + foreach ($tabs as $tab) + { $tab->active = 0; $tab->save(); } diff --git a/classes/Tag.php b/classes/Tag.php index 0a871fe92..1311cfa4b 100644 --- a/classes/Tag.php +++ b/classes/Tag.php @@ -195,7 +195,12 @@ class TagCore extends ObjectModel $ids = array(); foreach ($array as $id_product) $ids[] = '('.(int)$id_product.','.(int)$this->id.')'; - return ($result && Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'product_tag (id_product, id_tag) VALUES '.implode(',', $ids)) && Search::indexation(false)); + + if ($result) + { + $result &= Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'product_tag (id_product, id_tag) VALUES '.implode(',', $ids)); + $result &= Search::indexation(false); + } } return $result; } diff --git a/classes/Theme.php b/classes/Theme.php index 06cb80317..88abdb0e4 100644 --- a/classes/Theme.php +++ b/classes/Theme.php @@ -54,27 +54,28 @@ class ThemeCore extends ObjectModel /** * return an array of all available theme (installed or not) * - * @param boolean $installed + * @param boolean $installed_only * @return array string (directory) */ - public static function getAvailable($installed_only = true){ + public static function getAvailable($installed_only = true) + { static $dirlist = array(); $available_theme = array(); - + if (empty($dirlist)) { $themes = scandir(_PS_ALL_THEMES_DIR_); - foreach ($themes AS $theme) + foreach ($themes as $theme) if (is_dir(_PS_ALL_THEMES_DIR_.DIRECTORY_SEPARATOR.$theme) && $theme[0] != '.') $dirlist[] = $theme; } - + if ($installed_only) { $themes = Theme::getThemes(); - foreach($themes as $theme_obj) + foreach ($themes as $theme_obj) $themes_dir[] = $theme_obj->directory; - foreach( $dirlist as $theme) + foreach ($dirlist as $theme) if (false !== array_search($theme, $themes_dir)) $available_theme[] = $theme; }