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}> */ 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 $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 */ 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); } }