From 7c5ff8073f16611cb63ea7e0a9fd62551f152b35 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Wed, 16 Oct 2013 11:47:47 +0200 Subject: [PATCH] // Code cleaning --- modules/dashproducts/dashproducts.php | 40 +++++++++---------- .../templates/hook/dashboard_zone_two.tpl | 29 +++++++++----- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/modules/dashproducts/dashproducts.php b/modules/dashproducts/dashproducts.php index aa434b6f7..3ccb8a294 100644 --- a/modules/dashproducts/dashproducts.php +++ b/modules/dashproducts/dashproducts.php @@ -406,6 +406,7 @@ class Dashproducts extends Module if (Validate::isLoadedObject($gapi) && $gapi->isConfigured()) { $products = array(); + // Only works with the default product URL pattern at this time if ($result = $gapi->requestReportData('ga:pagePath', 'ga:visits', $date_from, $date_to, '-ga:visits', 'ga:pagePath=~/([a-z]{2}/)?([a-z]+/)?[0-9][0-9]*\-.*\.html$', 1, 10)) foreach ($result as $row) { @@ -416,30 +417,27 @@ class Dashproducts extends Module return $products; } else - { - $sql = 'SELECT p.id_object, pv.counter - FROM `'._DB_PREFIX_.'page_viewed` pv - LEFT JOIN `'._DB_PREFIX_.'date_range` dr ON pv.`id_date_range` = dr.`id_date_range` - LEFT JOIN `'._DB_PREFIX_.'page` p ON pv.`id_page` = p.`id_page` - LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON pt.`id_page_type` = p.`id_page_type` - WHERE pt.`name` = \'product\' - '.Shop::addSqlRestriction(false, 'pv').' - AND dr.`time_start` BETWEEN "'.pSQL($date_from).'" AND "'.pSQL($date_to).'" - AND dr.`time_end` BETWEEN "'.pSQL($date_from).'" AND "'.pSQL($date_to).'"'; - - return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); - } + return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' + SELECT p.id_object, pv.counter + FROM `'._DB_PREFIX_.'page_viewed` pv + LEFT JOIN `'._DB_PREFIX_.'date_range` dr ON pv.`id_date_range` = dr.`id_date_range` + LEFT JOIN `'._DB_PREFIX_.'page` p ON pv.`id_page` = p.`id_page` + LEFT JOIN `'._DB_PREFIX_.'page_type` pt ON pt.`id_page_type` = p.`id_page_type` + WHERE pt.`name` = \'product\' + '.Shop::addSqlRestriction(false, 'pv').' + AND dr.`time_start` BETWEEN "'.pSQL($date_from).'" AND "'.pSQL($date_to).'" + AND dr.`time_end` BETWEEN "'.pSQL($date_from).'" AND "'.pSQL($date_to).'"'); } public function getMostSearchTerms($date_from, $date_to, $limit = 10) { - $sql = 'SELECT `keywords`, count(`id_statssearch`) as count_keywords, `results` - FROM `'._DB_PREFIX_.'statssearch` ss - WHERE ss.`date_add` BETWEEN "'.pSQL($date_from).'" AND "'.pSQL($date_to).'" - '.Shop::addSqlRestriction(false, 'ss').' - GROUP BY ss.`keywords` - ORDER BY `count_keywords` DESC - LIMIT 0, '.(int)$limit; - return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); + return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' + SELECT `keywords`, count(`id_statssearch`) as count_keywords, `results` + FROM `'._DB_PREFIX_.'statssearch` ss + WHERE ss.`date_add` BETWEEN "'.pSQL($date_from).'" AND "'.pSQL($date_to).'" + '.Shop::addSqlRestriction(false, 'ss').' + GROUP BY ss.`keywords` + ORDER BY `count_keywords` DESC + LIMIT '.(int)$limit); } } \ No newline at end of file diff --git a/modules/dashproducts/views/templates/hook/dashboard_zone_two.tpl b/modules/dashproducts/views/templates/hook/dashboard_zone_two.tpl index 7fb7afe5d..d78e3b5ce 100644 --- a/modules/dashproducts/views/templates/hook/dashboard_zone_two.tpl +++ b/modules/dashproducts/views/templates/hook/dashboard_zone_two.tpl @@ -39,17 +39,26 @@