Skip to content

Commit

Permalink
Try to fix a few issues in statistic-module
Browse files Browse the repository at this point in the history
  • Loading branch information
blackcoder87 committed May 7, 2017
1 parent d0dbd97 commit eaeb1db
Showing 1 changed file with 22 additions and 33 deletions.
55 changes: 22 additions & 33 deletions application/modules/statistic/mappers/Statistic.php
Expand Up @@ -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) {
Expand All @@ -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);

Expand Down Expand Up @@ -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)) {
Expand All @@ -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`';
Expand All @@ -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);
Expand All @@ -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)) {
Expand Down

0 comments on commit eaeb1db

Please sign in to comment.