feat: add basic stats on podcast about page

number of seasons and episodes + publication date of the first episode
This commit is contained in:
Yassine Doghri 2022-01-06 16:52:13 +00:00
parent 88fddc81d7
commit 1670558473
7 changed files with 67 additions and 8 deletions

View File

@ -125,9 +125,12 @@ class PodcastController extends BaseController
);
if (! ($cachedView = cache($cacheName))) {
$stats = (new EpisodeModel())->getPodcastStats($this->podcast->id);
$data = [
'metatags' => get_podcast_metatags($this->podcast, 'about'),
'podcast' => $this->podcast,
'stats' => $stats,
];
// // if user is logged in then send to the authenticated activity view

View File

@ -28,12 +28,21 @@ return [
other {<span class="font-semibold">#</span> posts}
}',
'activity' => 'Activity',
'activity_title' => '{podcastTitle} news & activity',
'episodes' => 'Episodes',
'episodes_title' => 'Episodes of {podcastTitle}',
'about' => 'About',
'about_title' => 'About {podcastTitle}',
'sponsor_title' => 'Enjoying the show?',
'stats' => [
'title' => 'Stats',
'number_of_seasons' => '{0, plural,
one {<span class="font-semibold">#</span> season}
other {<span class="font-semibold">#</span> seasons}
}',
'number_of_episodes' => '{0, plural,
one {<span class="font-semibold">#</span> episode}
other {<span class="font-semibold">#</span> episodes}
}',
'first_published_at' => 'First episode published on <span class="font-semibold">{0, date, medium}</span>',
],
'sponsor' => 'Sponsor',
'funding_links' => 'Funding links for {podcastTitle}',
'find_on' => 'Find {podcastTitle} on',

View File

@ -9,7 +9,7 @@ declare(strict_types=1);
*/
return [
'feed' => 'Podcast RSS feed',
'feed' => 'Flux RSS Podcast',
'season' => 'Saison {seasonNumber}',
'list_of_episodes_year' => 'Épisodes de {year} ({episodeCount})',
'list_of_episodes_season' =>
@ -29,8 +29,19 @@ return [
}',
'activity' => 'Activité',
'episodes' => 'Épisodes',
'about' => 'About',
'sponsor_title' => 'Vous aimez le podcast ?',
'about' => 'À propos',
'stats' => [
'title' => 'Statistiques',
'number_of_seasons' => '{0, plural,
one {<span class="font-semibold">#</span> saison}
other {<span class="font-semibold">#</span> saisons}
}',
'number_of_episodes' => '{0, plural,
one {<span class="font-semibold">#</span> épisode}
other {<span class="font-semibold">#</span> épisodes}
}',
'first_published_at' => 'Premier épisode publié le <span class="font-semibold">{0, date, medium}</span>',
],
'sponsor' => 'Soutenez-nous',
'funding_links' => 'Liens de financement pour {podcastTitle}',
'find_on' => 'Trouvez {podcastTitle} sur',

View File

@ -11,6 +11,7 @@ declare(strict_types=1);
namespace App\Models;
use App\Entities\Episode;
use CodeIgniter\I18n\Time;
use CodeIgniter\Model;
class EpisodeModel extends Model
@ -294,6 +295,33 @@ class EpisodeModel extends Model
return (int) $result[0]['next_episode_number'] + 1;
}
/**
* @return array<string, int|Time>
*/
public function getPodcastStats(int $podcastId): array
{
$result = $this->select(
'COUNT(DISTINCT season_number) as number_of_seasons, COUNT(*) as number_of_episodes, MIN(published_at) as first_published_at'
)
->where([
'podcast_id' => $podcastId,
'published_at IS NOT' => null,
$this->deletedField => null,
])->get()
->getResultArray();
$stats = [
'number_of_seasons' => (int) $result[0]['number_of_seasons'],
'number_of_episodes' => (int) $result[0]['number_of_episodes'],
];
if ($result[0]['first_published_at'] !== null) {
$stats['first_published_at'] = new Time($result[0]['first_published_at']);
}
return $stats;
}
/**
* @param mixed[] $data
*

View File

@ -236,7 +236,6 @@ return [
}',
'activity' => 'Activity',
'episodes' => 'Episodes',
'sponsor_title' => 'Enjoying the show?',
'sponsor' => 'Sponsor',
'funding_links' => 'Funding links for {podcastTitle}',
'find_on' => 'Find {podcastTitle} on',

View File

@ -238,7 +238,6 @@ return [
}',
'activity' => 'Activité',
'episodes' => 'Épisodes',
'sponsor_title' => 'Vous aimez le podcast ?',
'sponsor' => 'Soutenez-nous',
'funding_links' => 'Liens de financement pour {podcastTitle}',
'find_on' => 'Trouvez {podcastTitle} sur',

View File

@ -40,6 +40,16 @@
<?= location_link($podcast->location, 'text-xs font-semibold p-2') ?>
<?php endif; ?>
</div>
<div class="mt-4">
<h2 class="text-xs font-bold tracking-wider text-gray-600 uppercase border-b-2 border-subtle font-display"><?= lang('Podcast.stats.title') ?></h2>
<div class="flex flex-col text-sm">
<?php foreach ($stats as $key => $value): ?>
<span class="py-2 border-b border-subtle">
<?= lang('Podcast.about.stats.' . $key, [$value]) ?>
</span>
<?php endforeach; ?>
</div>
</div>
</div>