Merge pull request 'Add a speaker view with a next-slide preview and keep the live slide in view' (#93) from feature/presenter-notes into main
Reviewed-on: #93
This commit was merged in pull request #93.
This commit is contained in:
commit
0c97f61763
11 files changed
+264
-5
No files matched your search
@@ -169,7 +169,16 @@ class AdminController extends AdminAppController
|
||||
*/
|
||||
public function present(): void
|
||||
{
|
||||
if ($this->poll->current_slide_id === null && !$this->poll->isPaused()) {
|
||||
$this->prepareStage(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $start Show the first slide if the presentation has not been started yet
|
||||
* @return void
|
||||
*/
|
||||
private function prepareStage(bool $start): void
|
||||
{
|
||||
if ($start && $this->poll->current_slide_id === null && !$this->poll->isPaused()) {
|
||||
$first = $this->Slides->find()
|
||||
->where(['poll_id' => $this->poll->id, 'is_hidden' => false])
|
||||
->orderBy(['position' => 'ASC', 'id' => 'ASC'])
|
||||
@@ -186,6 +195,19 @@ class AdminController extends AdminAppController
|
||||
$this->setPollInterval();
|
||||
}
|
||||
|
||||
/**
|
||||
* Speaker view for a second window or screen: current slide, preview of the next one and the
|
||||
* same controls as the presenter screen. Unlike present() it never starts the presentation.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function speaker(): void
|
||||
{
|
||||
$this->prepareStage(false);
|
||||
$this->set('speaker', true);
|
||||
$this->viewBuilder()->setTemplate('present');
|
||||
}
|
||||
|
||||
/**
|
||||
* JSON state for the presenter screen.
|
||||
*
|
||||
|
||||
@@ -131,12 +131,51 @@ class PollStateService
|
||||
], $slides),
|
||||
'index' => $index,
|
||||
'count' => count($slides),
|
||||
'next' => $this->nextPreview($poll, $slides, $index),
|
||||
'hiddenCount' => $this->Slides->find()->where(['poll_id' => $poll->id, 'is_hidden' => true])->count(),
|
||||
'slide' => $current ? $this->slidePayload($current, $poll) : null,
|
||||
'results' => $current ? $this->results->forSlide($current) : null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Preview of the slide that comes next for the speaker view: the one behind the live slide, the
|
||||
* paused one while paused (that is where "continue" goes), the first one before the start.
|
||||
* Labels only: never `is_correct` and never the options of an order slide (they are stored in the
|
||||
* correct order), so nothing leaks that is not allowed in the JSON before the slide is resolved.
|
||||
*
|
||||
* @param \App\Model\Entity\Poll $poll Poll
|
||||
* @param list<\App\Model\Entity\Slide> $slides Visible slides in presentation order
|
||||
* @param int|null $index Index of the live slide in `$slides`
|
||||
* @return array<string, mixed>|null Null after the last slide
|
||||
*/
|
||||
private function nextPreview(Poll $poll, array $slides, ?int $index): ?array
|
||||
{
|
||||
if ($index !== null) {
|
||||
$next = $slides[$index + 1] ?? null;
|
||||
} else {
|
||||
$next = $slides[0] ?? null;
|
||||
foreach ($slides as $slide) {
|
||||
if ($poll->paused_slide_id !== null && $slide->id === $poll->paused_slide_id) {
|
||||
$next = $slide;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($next === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $next->id,
|
||||
'type' => $next->type,
|
||||
'typeLabel' => $next->typeLabel(),
|
||||
'question' => $next->question,
|
||||
'description' => (string)$next->description,
|
||||
'options' => $next->isOrder() ? [] : array_map(fn($o) => $o->label, $next->slide_options ?? []),
|
||||
'hasImage' => $next->hasImage(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* State of one embedded slide (/e/{key}/{slide}/state). Same shape as forPresenter(),
|
||||
* but always for this slide, live or not, plus `isLive`. Never contains the slide list.
|
||||
|
||||
Reference in new issue
Block a user