Files
Plenario/src/Service/ReportService.php
T
gnilebeinandClaude Opus 5.5 ecb8f9d31c
CI / Deploy / test (push) Successful in 1m4s
CI / Deploy / deploy (push) Skipped
Make private slides start with hidden results instead of withholding them
Anonymous/internal feedback now only presets "hide results" on the stage:
presenter and embed get the full results flagged private and can show them
on demand. Participants still never get results of private slides, the
public PDF export strips them via ResultsService::withoutContents().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 19:33:52 +01:00

119 lines
4.0 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 poll, 1-based),
* '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
* @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
{
$sections = [];
foreach ($this->Slides->listForPoll($poll->id) 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 the poll has slides whose answers are not public.
*
* @param \App\Model\Entity\Poll $poll Poll
* @return bool
*/
public function hasInternalContent(Poll $poll): bool
{
foreach ($this->Slides->listForPoll($poll->id) as $slide) {
if ($slide->isInteractive() && $slide->isPrivate()) {
return true;
}
}
return false;
}
/**
* @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
{
$results = $this->results->forSlide($slide);
$mayRead = !$slide->isPrivate() || $includeInternal;
if (!$mayRead) {
return ResultsService::withoutContents($results);
}
if ($slide->type === Slide::TYPE_OPEN) {
$results['answers'] = $this->results->answers($slide);
}
if ($slide->type === Slide::TYPE_SCALE) {
// Ratings next to comments: complete version always, public one only with the setting.
$showRatings = $includeInternal || (bool)$slide->setting('comment_ratings');
$comments = [];
foreach ($slide->hasComments() ? $this->results->comments($slide) : [] as $comment) {
$comments[] = [
'id' => $comment['id'],
'text' => $comment['text'],
'value' => $showRatings ? $comment['value'] : null,
];
}
$results = $this->results->scaleResults($slide) + ['comments' => $comments] + $results;
}
return $results;
}
}