mirror of
https://code.castopod.org/adaures/castopod
synced 2025-06-06 18:31:05 +00:00
feat: add basic stats on podcast about page
number of seasons and episodes + publication date of the first episode
This commit is contained in:
parent
88fddc81d7
commit
1670558473
@ -125,9 +125,12 @@ class PodcastController extends BaseController
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (! ($cachedView = cache($cacheName))) {
|
if (! ($cachedView = cache($cacheName))) {
|
||||||
|
$stats = (new EpisodeModel())->getPodcastStats($this->podcast->id);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'metatags' => get_podcast_metatags($this->podcast, 'about'),
|
'metatags' => get_podcast_metatags($this->podcast, 'about'),
|
||||||
'podcast' => $this->podcast,
|
'podcast' => $this->podcast,
|
||||||
|
'stats' => $stats,
|
||||||
];
|
];
|
||||||
|
|
||||||
// // if user is logged in then send to the authenticated activity view
|
// // if user is logged in then send to the authenticated activity view
|
||||||
|
@ -28,12 +28,21 @@ return [
|
|||||||
other {<span class="font-semibold">#</span> posts}
|
other {<span class="font-semibold">#</span> posts}
|
||||||
}',
|
}',
|
||||||
'activity' => 'Activity',
|
'activity' => 'Activity',
|
||||||
'activity_title' => '{podcastTitle} news & activity',
|
|
||||||
'episodes' => 'Episodes',
|
'episodes' => 'Episodes',
|
||||||
'episodes_title' => 'Episodes of {podcastTitle}',
|
'episodes_title' => 'Episodes of {podcastTitle}',
|
||||||
'about' => 'About',
|
'about' => 'About',
|
||||||
'about_title' => 'About {podcastTitle}',
|
'stats' => [
|
||||||
'sponsor_title' => 'Enjoying the show?',
|
'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',
|
'sponsor' => 'Sponsor',
|
||||||
'funding_links' => 'Funding links for {podcastTitle}',
|
'funding_links' => 'Funding links for {podcastTitle}',
|
||||||
'find_on' => 'Find {podcastTitle} on',
|
'find_on' => 'Find {podcastTitle} on',
|
||||||
|
@ -9,7 +9,7 @@ declare(strict_types=1);
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'feed' => 'Podcast RSS feed',
|
'feed' => 'Flux RSS Podcast',
|
||||||
'season' => 'Saison {seasonNumber}',
|
'season' => 'Saison {seasonNumber}',
|
||||||
'list_of_episodes_year' => 'Épisodes de {year} ({episodeCount})',
|
'list_of_episodes_year' => 'Épisodes de {year} ({episodeCount})',
|
||||||
'list_of_episodes_season' =>
|
'list_of_episodes_season' =>
|
||||||
@ -29,8 +29,19 @@ return [
|
|||||||
}',
|
}',
|
||||||
'activity' => 'Activité',
|
'activity' => 'Activité',
|
||||||
'episodes' => 'Épisodes',
|
'episodes' => 'Épisodes',
|
||||||
'about' => 'About',
|
'about' => 'À propos',
|
||||||
'sponsor_title' => 'Vous aimez le podcast ?',
|
'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',
|
'sponsor' => 'Soutenez-nous',
|
||||||
'funding_links' => 'Liens de financement pour {podcastTitle}',
|
'funding_links' => 'Liens de financement pour {podcastTitle}',
|
||||||
'find_on' => 'Trouvez {podcastTitle} sur',
|
'find_on' => 'Trouvez {podcastTitle} sur',
|
||||||
|
@ -11,6 +11,7 @@ declare(strict_types=1);
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Entities\Episode;
|
use App\Entities\Episode;
|
||||||
|
use CodeIgniter\I18n\Time;
|
||||||
use CodeIgniter\Model;
|
use CodeIgniter\Model;
|
||||||
|
|
||||||
class EpisodeModel extends Model
|
class EpisodeModel extends Model
|
||||||
@ -294,6 +295,33 @@ class EpisodeModel extends Model
|
|||||||
return (int) $result[0]['next_episode_number'] + 1;
|
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
|
* @param mixed[] $data
|
||||||
*
|
*
|
||||||
|
@ -236,7 +236,6 @@ return [
|
|||||||
}',
|
}',
|
||||||
'activity' => 'Activity',
|
'activity' => 'Activity',
|
||||||
'episodes' => 'Episodes',
|
'episodes' => 'Episodes',
|
||||||
'sponsor_title' => 'Enjoying the show?',
|
|
||||||
'sponsor' => 'Sponsor',
|
'sponsor' => 'Sponsor',
|
||||||
'funding_links' => 'Funding links for {podcastTitle}',
|
'funding_links' => 'Funding links for {podcastTitle}',
|
||||||
'find_on' => 'Find {podcastTitle} on',
|
'find_on' => 'Find {podcastTitle} on',
|
||||||
|
@ -238,7 +238,6 @@ return [
|
|||||||
}',
|
}',
|
||||||
'activity' => 'Activité',
|
'activity' => 'Activité',
|
||||||
'episodes' => 'Épisodes',
|
'episodes' => 'Épisodes',
|
||||||
'sponsor_title' => 'Vous aimez le podcast ?',
|
|
||||||
'sponsor' => 'Soutenez-nous',
|
'sponsor' => 'Soutenez-nous',
|
||||||
'funding_links' => 'Liens de financement pour {podcastTitle}',
|
'funding_links' => 'Liens de financement pour {podcastTitle}',
|
||||||
'find_on' => 'Trouvez {podcastTitle} sur',
|
'find_on' => 'Trouvez {podcastTitle} sur',
|
||||||
|
@ -40,6 +40,16 @@
|
|||||||
<?= location_link($podcast->location, 'text-xs font-semibold p-2') ?>
|
<?= location_link($podcast->location, 'text-xs font-semibold p-2') ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user