Add YouTube video slide type
Admins paste a YouTube link (watch, youtu.be, shorts, live, embed). The link is checked via oEmbed on save and with a "check link" button (not found / not embeddable is rejected, unreachable saves with a warning). Start time can be entered or is taken from the link's timecode; autoplay is optional. The presenter embeds the video via youtube-nocookie.com; participants get the link plus a share button (Web Share API, falls back to copying). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
93aeae1884
commit
1c509e31c2
14 files changed
+972
-24
No files matched your search
@@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Model\Entity;
|
||||
|
||||
use App\Service\YouTubeService;
|
||||
use Cake\I18n\DateTime;
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
@@ -34,6 +35,7 @@ class Slide extends Entity
|
||||
public const TYPE_SCALE = 'scale';
|
||||
public const TYPE_CONTENT = 'content';
|
||||
public const TYPE_QUIZ = 'quiz';
|
||||
public const TYPE_YOUTUBE = 'youtube';
|
||||
|
||||
/**
|
||||
* Quiz phases, see quizPhase().
|
||||
@@ -63,6 +65,8 @@ class Slide extends Entity
|
||||
self::TYPE_CONTENT => [],
|
||||
// time_limit in seconds, 0 = no limit (presenter ends the quiz)
|
||||
self::TYPE_QUIZ => ['time_limit' => 30],
|
||||
// url as entered, video_id parsed from it, start in seconds
|
||||
self::TYPE_YOUTUBE => ['url' => '', 'video_id' => '', 'start' => 0, 'autoplay' => false],
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -88,6 +92,7 @@ class Slide extends Entity
|
||||
self::TYPE_SCALE => __('Skala'),
|
||||
self::TYPE_QUIZ => __('Quiz'),
|
||||
self::TYPE_CONTENT => __('Inhaltsfolie'),
|
||||
self::TYPE_YOUTUBE => __('YouTube-Video'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -103,6 +108,7 @@ class Slide extends Entity
|
||||
self::TYPE_SCALE => __('Bewertung auf einer Skala, z. B. 1 bis 5.'),
|
||||
self::TYPE_QUIZ => __('Frage mit richtiger Antwort und Zeitlimit, aufgelöst wird erst am Ende.'),
|
||||
self::TYPE_CONTENT => __('Nur Text anzeigen, ohne Abstimmung.'),
|
||||
self::TYPE_YOUTUBE => __('Video in der Präsentation abspielen, Teilnehmende bekommen den Link zum Teilen.'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -121,7 +127,41 @@ class Slide extends Entity
|
||||
*/
|
||||
public function isInteractive(): bool
|
||||
{
|
||||
return $this->type !== self::TYPE_CONTENT;
|
||||
return !in_array($this->type, [self::TYPE_CONTENT, self::TYPE_YOUTUBE], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isYouTube(): bool
|
||||
{
|
||||
return $this->type === self::TYPE_YOUTUBE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to the video on YouTube incl. start time, null without valid video.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function youtubeWatchUrl(): ?string
|
||||
{
|
||||
$id = (string)$this->setting('video_id');
|
||||
|
||||
return $this->isYouTube() && $id !== '' ? YouTubeService::watchUrl($id, (int)$this->setting('start')) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Player URL for the presenter screen, null without valid video.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function youtubeEmbedUrl(): ?string
|
||||
{
|
||||
$id = (string)$this->setting('video_id');
|
||||
|
||||
return $this->isYouTube() && $id !== ''
|
||||
? YouTubeService::embedUrl($id, (int)$this->setting('start'), (bool)$this->setting('autoplay'))
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace App\Model\Table;
|
||||
|
||||
use App\Model\Entity\Slide;
|
||||
use App\Service\YouTubeService;
|
||||
use ArrayObject;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
use Cake\Event\EventInterface;
|
||||
@@ -158,6 +159,19 @@ class SlidesTable extends Table
|
||||
$settings['time_limit'] = $limit;
|
||||
}
|
||||
break;
|
||||
case Slide::TYPE_YOUTUBE:
|
||||
$url = mb_substr(trim((string)($input['url'] ?? '')), 0, 500);
|
||||
$parsed = YouTubeService::parseUrl($url);
|
||||
$settings['url'] = $url;
|
||||
$settings['video_id'] = $parsed['videoId'] ?? '';
|
||||
// Form input "1:30" / "2" (minutes); an int is already seconds. Empty = timecode of the link.
|
||||
$start = $input['start'] ?? '';
|
||||
if (!is_int($start)) {
|
||||
$start = trim((string)$start) === '' ? null : YouTubeService::parseStartInput((string)$start);
|
||||
}
|
||||
$settings['start'] = max(0, min($start ?? $parsed['start'] ?? 0, YouTubeService::MAX_START));
|
||||
$settings['autoplay'] = filter_var($input['autoplay'] ?? false, FILTER_VALIDATE_BOOLEAN);
|
||||
break;
|
||||
}
|
||||
|
||||
return $settings;
|
||||
|
||||
Reference in new issue
Block a user