Commit 3f4a6bd0 authored by Yassine Doghri's avatar Yassine Doghri
Browse files

feat: add episode_numbering() component helper to display episode and season numbers

parent e1f65cd3
Pipeline #374 passed with stage
in 4 minutes and 15 seconds
......@@ -118,8 +118,12 @@ class Episode extends BaseController
$this->request->getPost('parental_advisory') !== 'undefined'
? $this->request->getPost('parental_advisory')
: null,
'number' => $this->request->getPost('episode_number'),
'season_number' => $this->request->getPost('season_number'),
'number' => $this->request->getPost('episode_number')
? $this->request->getPost('episode_number')
: null,
'season_number' => $this->request->getPost('season_number')
? $this->request->getPost('season_number')
: null,
'type' => $this->request->getPost('type'),
'is_blocked' => $this->request->getPost('block') == 'yes',
'created_by' => user(),
......@@ -204,7 +208,9 @@ class Episode extends BaseController
$this->request->getPost('parental_advisory') !== 'undefined'
? $this->request->getPost('parental_advisory')
: null;
$this->episode->number = $this->request->getPost('episode_number');
$this->episode->number = $this->request->getPost('episode_number')
? $this->request->getPost('episode_number')
: null;
$this->episode->season_number = $this->request->getPost('season_number')
? $this->request->getPost('season_number')
: null;
......
......@@ -384,7 +384,9 @@ class Podcast extends BaseController
'number' =>
$this->request->getPost('force_renumber') === 'yes'
? $itemNumber
: $nsItunes->episode,
: (!empty($nsItunes->episode)
? $nsItunes->episode
: null),
'season_number' => empty(
$this->request->getPost('season_number')
)
......
......@@ -259,9 +259,9 @@ if (!function_exists('data_table')) {
if (!function_exists('publication_pill')) {
/**
* Data table component
* Publication pill component
*
* Creates a stylized table.
* Shows the stylized publication datetime in regards to current datetime.
*
* @param \CodeIgniter\I18n\Time $publicationDate publication datetime of the episode
* @param boolean $isPublished whether or not the episode has been published
......@@ -303,4 +303,66 @@ if (!function_exists('publication_pill')) {
'</span>';
}
}
// ------------------------------------------------------------------------
if (!function_exists('episode_numbering')) {
/**
* Returns relevant translated episode numbering.
*
* @param int|null $episodeNumber
* @param int|null $seasonNumber
* @param string $class styling classes
* @param string $is_abbr component will show abbreviated numbering if true
*
* @return string
*/
function episode_numbering(
$episodeNumber = null,
$seasonNumber = null,
$class = '',
$isAbbr = false
): string {
if (!$episodeNumber && !$seasonNumber) {
return '';
}
$transKey = '';
$args = [];
if ($episodeNumber && $seasonNumber) {
$transKey = 'Episode.season_episode';
$args = [
'seasonNumber' => $seasonNumber,
'episodeNumber' => $episodeNumber,
];
} elseif ($episodeNumber && !$seasonNumber) {
$transKey = 'Episode.number';
$args = [
'episodeNumber' => $episodeNumber,
];
} elseif (!$episodeNumber && $seasonNumber) {
$transKey = 'Episode.season';
$args = [
'seasonNumber' => $seasonNumber,
];
}
if ($isAbbr) {
return '<abbr class="' .
$class .
'" title="' .
lang($transKey, $args) .
'">' .
lang($transKey . '_abbr', $args) .
'</abbr>';
}
return '<span class="' .
$class .
'">' .
lang($transKey, $args) .
'</span>';
}
}
// ------------------------------------------------------------------------
......@@ -70,7 +70,7 @@ function write_enclosure_tags($episode)
$episode->published_at ? $episode->published_at->format('Y') : '',
],
'genre' => ['Podcast'],
'comment' => [$episode->description_html],
'comment' => [$episode->description],
'track_number' => [strval($episode->number)],
'copyright_message' => [$episode->podcast->copyright],
'publisher' => [
......
......@@ -142,7 +142,8 @@ function get_rss_feed($podcast, $serviceName = '')
$itunes_namespace
);
$item->addChild('episode', $episode->number, $itunes_namespace);
$episode->number &&
$item->addChild('episode', $episode->number, $itunes_namespace);
$episode->season_number &&
$item->addChild(
'season',
......
......@@ -12,6 +12,7 @@ return [
'next_episode' => 'Next episode',
'next_season' => 'Next season',
'season' => 'Season {seasonNumber}',
'season_abbr' => 'S{seasonNumber}',
'number' => 'Episode {episodeNumber}',
'number_abbr' => 'Ep. {episodeNumber}',
'season_episode' => 'Season {seasonNumber} episode {episodeNumber}',
......
......@@ -12,6 +12,7 @@ return [
'next_episode' => 'Épisode suivant',
'next_season' => 'Saison suivante',
'season' => 'Saison {seasonNumber}',
'season_abbr' => 'S{seasonNumber}',
'number' => 'Épisode {episodeNumber}',
'number_abbr' => 'Ep. {episodeNumber}',
'season_episode' => 'Saison {seasonNumber} épisode {episodeNumber}',
......
......@@ -104,7 +104,6 @@
'name' => 'episode_number',
'class' => 'form-input w-full',
'value' => old('episode_number'),
'required' => 'required',
'type' => 'number',
]) ?>
</div>
......
......@@ -108,7 +108,6 @@
'name' => 'episode_number',
'class' => 'form-input w-full',
'value' => old('episode_number', $episode->number),
'required' => 'required',
'type' => 'number',
]) ?>
</div>
......
......@@ -11,12 +11,10 @@
<?= $this->endSection() ?>
<?= $this->section('headerRight') ?>
<?= button(
lang('Episode.create'),
route_to('episode-create', $podcast->id),
['variant' => 'primary', 'iconLeft' => 'add']
) ?>
<?= button(lang('Episode.create'), route_to('episode-create', $podcast->id), [
'variant' => 'primary',
'iconLeft' => 'add',
]) ?>
<?= $this->endSection() ?>
......@@ -43,34 +41,12 @@
) ?>">
<h2 class="inline-flex justify-between w-full font-bold leading-none group">
<span class="mr-1 group-hover:underline"><?= $episode->title ?></span>
<?php if (
$episode->season_number &&
$episode->number
): ?>
<abbr class="text-xs font-bold text-gray-600" title="<?= lang(
'Episode.season_episode',
[
'seasonNumber' =>
$episode->season_number,
'episodeNumber' => $episode->number,
]
) ?>"><?= lang('Episode.season_episode_abbr', [
'seasonNumber' => $episode->season_number,
'episodeNumber' => $episode->number,
]) ?></abbr>
<?php elseif (
!$episode->season_number &&
$episode->number
): ?>
<abbr class="text-xs font-bold text-gray-600" title="<?= lang(
'Episode.number',
[
'episodeNumber' => $episode->number,
]
) ?>"><?= lang('Episode.number_abbr', [
'episodeNumber' => $episode->number,
]) ?></abbr>
<?php endif; ?>
<?= episode_numbering(
$episode->number,
$episode->season_number,
'text-xs font-bold text-gray-600',
true
) ?>
</h2>
</a>
<div class="relative" data-toggle="dropdown">
......
......@@ -27,37 +27,12 @@
><?= $episode->title ?>
</a>
<div class="text-xs">
<?php if (
$episode->season_number &&
$episode->number
): ?>
<abbr class="font-bold text-gray-600" title="<?= lang(
'Episode.season_episode',
[
'seasonNumber' =>
$episode->season_number,
'episodeNumber' => $episode->number,
]
) ?>"><?= lang(
'Episode.season_episode_abbr',
[
'seasonNumber' => $episode->season_number,
'episodeNumber' => $episode->number,
]
) ?></abbr>
<?php elseif (
!$episode->season_number &&
$episode->number
): ?>
<abbr class="font-bold text-gray-600" title="<?= lang(
'Episode.number',
[
'episodeNumber' => $episode->number,
]
) ?>"><?= lang('Episode.number_abbr', [
'episodeNumber' => $episode->number,
]) ?></abbr>
<?php endif; ?>
<?= episode_numbering(
$episode->number,
$episode->season_number,
'font-bold text-gray-600',
true
) ?>
<span class="mx-1"></span>
<time
pubdate
......
......@@ -63,24 +63,11 @@
alt="<?= $episode->title ?>" class="object-cover w-full max-w-xs mb-2 rounded-lg md:mb-0 md:mr-4" />
<div class="flex flex-col w-full max-w-sm">
<h1 class="text-lg font-semibold md:text-2xl"><?= $episode->title ?></h1>
<?php if ($episode->number): ?>
<p class="text-gray-600">
<?php if ($episode->season_number): ?>
<a class="mr-1 underline hover:no-underline" href="<?= route_to(
'podcast',
$podcast->name
) .
'?season=' .
$episode->season_number ?>">
<?= lang('Episode.season', [
'seasonNumber' => $episode->season_number,
]) ?></a>
<?php endif; ?>
<?= lang('Episode.number', [
'episodeNumber' => $episode->number,
]) ?>
</p>
<?php endif; ?>
<?= episode_numbering(
$episode->number,
$episode->season_number,
'text-gray-600'
) ?>
<div class="text-sm">
<time
pubdate
......
......@@ -117,7 +117,12 @@
<a class="text-sm hover:underline" href="<?= $episode->link ?>">
<h2 class="inline-flex justify-between w-full font-bold leading-none group">
<span class="mr-1 group-hover:underline"><?= $episode->title ?></span>
<span class="font-bold text-gray-600">#<?= $episode->number ?></span>
<?= episode_numbering(
$episode->number,
$episode->season_number,
'text-xs font-bold text-gray-600',
true
) ?>
</h2>
</a>
<div class="mb-2 text-xs">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment