Commit 16705584 authored by Yassine Doghri's avatar Yassine Doghri
Browse files

feat: add basic stats on podcast about page

number of seasons and episodes + publication date of the first episode
parent 88fddc81
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -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
+12 −3
Original line number Diff line number Diff line
@@ -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',
+14 −3
Original line number Diff line number Diff line
@@ -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',
+28 −0
Original line number Diff line number Diff line
@@ -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
     *
+0 −1
Original line number Diff line number Diff line
@@ -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',
Loading