feat: add map analytics, add episodes analytics, clean analytics page layout, translate countries

This commit is contained in:
Benjamin Bellamy 2020-10-14 10:38:48 +00:00 committed by Yassine Doghri
commit 07eae83a00
27 changed files with 705 additions and 192 deletions

View file

@ -37,12 +37,12 @@ class AnalyticsPodcastByEpisodeModel extends Model
))
) {
$lastEpisodes = (new EpisodeModel())
->select('id, season_number, number, title')
->orderBy('id', 'DESC')
->where(['podcast_id' => $podcastId])
->select('`id`, `season_number`, `number`, `title`')
->orderBy('`id`', 'DESC')
->where(['`podcast_id`' => $podcastId])
->findAll(5);
$found = $this->select('age AS X');
$found = $this->select('`age` AS `X`');
$letter = 97;
foreach ($lastEpisodes as $episode) {
@ -51,7 +51,7 @@ class AnalyticsPodcastByEpisodeModel extends Model
'(CASE WHEN `episode_id`=' .
$episode->id .
' THEN `hits` END)',
chr($letter) . 'Y'
'`' . chr($letter) . 'Y`'
)
->select(
'"' .
@ -62,20 +62,20 @@ class AnalyticsPodcastByEpisodeModel extends Model
? ''
: '-' . $episode->number . '/ ') .
$episode->title .
'" AS ' .
'" AS `' .
chr($letter) .
'Value'
'Value`'
);
$letter++;
}
$found = $found
->where([
'podcast_id' => $podcastId,
'age <' => 60,
'`podcast_id`' => $podcastId,
'`age` <' => 60,
])
->groupBy('X')
->orderBy('X', 'ASC')
->groupBy('`X`')
->orderBy('`X`', 'ASC')
->findAll();
cache()->save(
@ -91,14 +91,15 @@ class AnalyticsPodcastByEpisodeModel extends Model
"{$podcastId}_{$episodeId}_analytics_podcast_by_episode_by_day"
))
) {
$found = $this->select('date as labels')
->selectSum('hits', 'values')
$found = $this->select('`date as `labels`')
->selectSum('`hits`', '`values`')
->where([
'episode_id' => $episodeId,
'podcast_id' => $podcastId,
'`episode_id`' => $episodeId,
'`podcast_id`' => $podcastId,
'`age` <' => 60,
])
->groupBy('labels')
->orderBy('labels', 'ASC')
->groupBy('`labels`')
->orderBy('`labels`', 'ASC')
->findAll();
cache()->save(
@ -110,4 +111,35 @@ class AnalyticsPodcastByEpisodeModel extends Model
return $found;
}
}
/**
* @param int $podcastId, $episodeId
*
* @return array
*/
public function getDataByMonth(int $podcastId, int $episodeId = null): array
{
if (
!($found = cache(
"{$podcastId}_{$episodeId}_analytics_podcast_by_episode_by_month"
))
) {
$found = $this->select('DATE_FORMAT(`date`,"%Y-%m-01") as `labels`')
->selectSum('`hits`', '`values`')
->where([
'episode_id' => $episodeId,
'podcast_id' => $podcastId,
])
->groupBy('`labels`')
->orderBy('`labels`', 'ASC')
->findAll();
cache()->save(
"{$podcastId}_{$episodeId}_analytics_podcast_by_episode_by_month",
$found,
600
);
}
return $found;
}
}