From eaeb1dbcfc3f3e3416730faae48a8750a41603a7 Mon Sep 17 00:00:00 2001 From: blackcoder87 Date: Sun, 7 May 2017 18:22:34 +0200 Subject: [PATCH] Try to fix a few issues in statistic-module --- .../modules/statistic/mappers/Statistic.php | 55 ++++++++----------- 1 file changed, 22 insertions(+), 33 deletions(-) diff --git a/application/modules/statistic/mappers/Statistic.php b/application/modules/statistic/mappers/Statistic.php index 110f283af..df45cac65 100644 --- a/application/modules/statistic/mappers/Statistic.php +++ b/application/modules/statistic/mappers/Statistic.php @@ -113,8 +113,8 @@ public function getVisitsHour($year = null, $month = null) public function getVisitsDay($year = null, $month = null) { $sql = 'SELECT - DATE (`date`) `date_full`, - WEEKDAY(`date`) `date_week`, + MAX(DATE (`date`)) AS `date_full`, + WEEKDAY(`date`) AS `date_week`, COUNT(`id`) AS `visits` FROM `[prefix]_visits_stats`'; if ($month != null AND $year != null) { @@ -124,8 +124,8 @@ public function getVisitsDay($year = null, $month = null) $date = $year.'-01-01'; $sql .= ' WHERE YEAR(`date`) = YEAR("'.$date.'")'; } - $sql .= ' GROUP BY WEEKDAY(`date`), `date_full` - ORDER BY `date` DESC'; + $sql .= ' GROUP BY `date_week` + ORDER BY `date_week` ASC'; $entryArray = $this->db()->queryArray($sql); @@ -242,26 +242,21 @@ public function getVisitsBrowser($year = null, $month = null, $browser = null) FROM `[prefix]_visits_stats`'; if ($month != null AND $year != null AND $browser != null) { $date = $year.'-'.$month.'-01'; - $sql .= ' WHERE YEAR(`date`) = YEAR("'.$date.'") AND MONTH(`date`) = MONTH("'.$date.'") AND browser = "'.$browser.'" - GROUP BY `browser` - ORDER BY `visits` DESC'; + $sql .= ' WHERE YEAR(`date`) = YEAR("'.$date.'") AND MONTH(`date`) = MONTH("'.$date.'") AND browser = "'.$browser.'"'; } elseif ($month == null AND $year != null AND $browser != null) { $date = $year.'-01-01'; - $sql .= ' WHERE YEAR(`date`) = YEAR("'.$date.'") AND browser = "'.$browser.'" - GROUP BY `browser` - ORDER BY `visits` DESC'; + $sql .= ' WHERE YEAR(`date`) = YEAR("'.$date.'") AND browser = "'.$browser.'"'; } elseif ($month != null AND $year != null) { $date = $year.'-'.$month.'-01'; - $sql .= ' WHERE YEAR(`date`) = YEAR("'.$date.'") AND MONTH(`date`) = MONTH("'.$date.'") - GROUP BY `browser` - ORDER BY `visits` DESC'; + $sql .= ' WHERE YEAR(`date`) = YEAR("'.$date.'") AND MONTH(`date`) = MONTH("'.$date.'")'; } elseif ($month == null AND $year != null) { $date = $year.'-01-01'; - $sql .= ' WHERE YEAR(`date`) = YEAR("'.$date.'") - GROUP BY `browser` - ORDER BY `visits` DESC'; + $sql .= ' WHERE YEAR(`date`) = YEAR("'.$date.'")'; } + $sql .= ' GROUP BY `browser` + ORDER BY `visits` DESC'; + $entryArray = $this->db()->queryArray($sql); if (empty($entryArray)) { @@ -282,8 +277,7 @@ public function getVisitsBrowser($year = null, $month = null, $browser = null) public function getVisitsLanguage($year = null, $month = null) { $sql = 'SELECT - YEAR(`date`) `date_year`, - MONTH(`date`) `date_month`, + MAX(`date`), `lang`, COUNT(`id`) AS `visits` FROM `[prefix]_visits_stats`'; @@ -294,7 +288,8 @@ public function getVisitsLanguage($year = null, $month = null) $date = $year.'-01-01'; $sql .= ' WHERE YEAR(`date`) = YEAR("'.$date.'")'; } - $sql .= ' GROUP BY `lang`, `date_year`, `date_month` + + $sql .= ' GROUP BY `lang` ORDER BY `visits` DESC'; $entryArray = $this->db()->queryArray($sql); @@ -317,34 +312,28 @@ public function getVisitsLanguage($year = null, $month = null) public function getVisitsOS($year = null, $month = null, $os = null) { $sql = 'SELECT - YEAR(`date`) `date_year`, - MONTH(`date`) `date_month`, + MAX(`date`), `os_version`, `os`, COUNT(`id`) AS `visits` FROM `[prefix]_visits_stats`'; if ($month != null AND $year != null AND $os != null) { $date = $year.'-'.$month.'-01'; - $sql .= ' WHERE YEAR(`date`) = YEAR("'.$date.'") AND MONTH(`date`) = MONTH("'.$date.'") AND os = "'.$os.'" - GROUP BY `os_version`, `date_year`, `date_month`, `os` - ORDER BY `visits` DESC'; + $sql .= ' WHERE YEAR(`date`) = YEAR("'.$date.'") AND MONTH(`date`) = MONTH("'.$date.'") AND os = "'.$os.'"'; } elseif ($month == null AND $year != null AND $os != null) { $date = $year.'-01-01'; - $sql .= ' WHERE YEAR(`date`) = YEAR("'.$date.'") AND os = "'.$os.'" - GROUP BY `os_version`, `date_year`, `date_month`, `os` - ORDER BY `visits` DESC'; + $sql .= ' WHERE YEAR(`date`) = YEAR("'.$date.'") AND os = "'.$os.'"'; } elseif ($month != null AND $year != null) { $date = $year.'-'.$month.'-01'; - $sql .= ' WHERE YEAR(`date`) = YEAR("'.$date.'") AND MONTH(`date`) = MONTH("'.$date.'") - GROUP BY `os`, `date_year`, `date_month`, `os_version` - ORDER BY `visits` DESC'; + $sql .= ' WHERE YEAR(`date`) = YEAR("'.$date.'") AND MONTH(`date`) = MONTH("'.$date.'")'; } elseif ($month == null AND $year != null) { $date = $year.'-01-01'; - $sql .= ' WHERE YEAR(`date`) = YEAR("'.$date.'") - GROUP BY `os`, `date_year`, `date_month`, `os_version` - ORDER BY `visits` DESC'; + $sql .= ' WHERE YEAR(`date`) = YEAR("'.$date.'")'; } + $sql .= ' GROUP BY `os`,`os_version` + ORDER BY `visits` DESC'; + $entryArray = $this->db()->queryArray($sql); if (empty($entryArray)) {