Files
Plenario/src/Service/ReportService.php
T
gnilebeinandClaude Opus 5.5 3c978e6f22
CI / Deploy / test (push) Successful in 57s
CI / Deploy / deploy (push) Skipped
Add hiding slides from the presentation
Hidden slides stay prepared in the dashboard but are skipped when
presenting (start, next/prev, goto), can not go live via embed and are
left out of the PDF export. Hiding the live or paused slide pauses the
poll like deleting it and resumes with the next visible slide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 15:25:41 +01:00

101 lines
3.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace App\Service;
use App\Model\Entity\Poll;
use App\Model\Entity\Slide;
use App\Model\Table\SlidesTable;
use Cake\ORM\Locator\LocatorAwareTrait;
/**
* Collects the results of all interactive slides of a poll for the PDF export.
*
* Without $includeInternal the report shows exactly what may be shown publicly: private slides
* (anonymous feedback, internal scales) only with their number of participants, like the presenter
* screen. With $includeInternal it also contains their answers, distribution and comments –
* that version is meant for the poll owner only.
*
* Per slide: ['slide' => Slide, 'number' => int (position in the presentation, 1-based; hidden slides are left out),
* 'internal' => bool (private slide), 'withheld' => bool (private and left out),
* 'results' => ResultsService::forSlide() shape, where
* open: 'answers' contains all texts (not only the newest ones), and
* scale: 'comments' contains all comments, 'value' only in the complete version or with comment_ratings].
*/
class ReportService
{
use LocatorAwareTrait;
protected SlidesTable $Slides;
protected ResultsService $results;
/**
* Constructor
*/
public function __construct()
{
/** @var \App\Model\Table\SlidesTable $slides */
$slides = $this->fetchTable('Slides');
$this->Slides = $slides;
$this->results = new ResultsService();
}
/**
* @param \App\Model\Entity\Poll $poll Poll
* @param bool $includeInternal Include answers of private slides (ignored without private slides,
* so the public and the complete version are identical then)
* @return list<array{slide: \App\Model\Entity\Slide, number: int, internal: bool, withheld: bool, results: array<string, mixed>}>
*/
public function build(Poll $poll, bool $includeInternal): array
{
$slides = $this->Slides->listForPoll($poll->id, true);
$includeInternal = $includeInternal
&& array_filter($slides, fn(Slide $slide) => $slide->isInteractive() && $slide->isPrivate()) !== [];
$sections = [];
foreach ($slides as $index => $slide) {
if (!$slide->isInteractive()) {
continue;
}
$internal = $slide->isPrivate();
$sections[] = [
'slide' => $slide,
'number' => $index + 1,
'internal' => $internal,
'withheld' => $internal && !$includeInternal,
'results' => $this->resultsFor($slide, $includeInternal),
];
}
return $sections;
}
/**
* Whether a report built by build() contains slides whose answers are not public
* (i.e. whether a complete, internal version exists at all).
*
* @param list<array{internal: bool}> $sections Result of build()
* @return bool
*/
public static function hasInternal(array $sections): bool
{
return in_array(true, array_column($sections, 'internal'), true);
}
/**
* @param \App\Model\Entity\Slide $slide Slide incl. slide_options
* @param bool $includeInternal Include answers of private slides
* @return array<string, mixed>
*/
protected function resultsFor(Slide $slide, bool $includeInternal): array
{
if ($slide->isPrivate() && !$includeInternal) {
return ResultsService::withoutContents($this->results->forSlide($slide));
}
// All answers and comments. Ratings next to comments: complete version always,
// public one only with the setting comment_ratings.
return $this->results->forSlide($slide, null, $includeInternal);
}
}