fetchTable('Polls'); $this->Polls = $polls; /** @var \App\Model\Table\SlidesTable $slides */ $slides = $this->fetchTable('Slides'); $this->Slides = $slides; /** @var \App\Model\Table\ResponsesTable $responses */ $responses = $this->fetchTable('Responses'); $this->Responses = $responses; } /** * Deletes all responses of a slide and restores the state of a new slide: * quiz not started, Q&A collecting, everything else open for voting * (so orderings are no longer revealed). * * @param \App\Model\Entity\Slide $slide Slide * @return void */ public function slide(Slide $slide): void { $this->Slides->getConnection()->transactional(function () use ($slide): void { $this->Responses->deleteAll(['slide_id' => $slide->id]); if ($slide->isQa()) { (new QaService())->reset($slide); return; } $slide->is_voting_open = !$slide->isQuiz(); $slide->voting_started_at = null; $slide->voting_ends_at = null; $this->Slides->saveOrFail($slide); }); } /** * Resets every slide of the poll and the presentation itself (not started, * no pause, no live embed), so participants see the waiting page. * * @param \App\Model\Entity\Poll $poll Poll * @return void */ public function poll(Poll $poll): void { $this->Polls->getConnection()->transactional(function () use ($poll): void { foreach ($this->Slides->find()->where(['poll_id' => $poll->id])->all() as $slide) { /** @var \App\Model\Entity\Slide $slide */ $this->slide($slide); } $poll->restart(); $this->Polls->saveOrFail($poll); }); } }