fetchTable('Slides'); $this->Slides = $slides; /** @var \App\Model\Table\ResponsesTable $responses */ $responses = $this->fetchTable('Responses'); $this->Responses = $responses; } /** * Deletes all responses of a slide. A quiz goes back to "not started" * (so it can be played again), a Q&A slide back to collecting questions. * * @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; } if ($slide->isQuiz()) { $slide->is_voting_open = false; $slide->voting_started_at = null; $slide->voting_ends_at = null; $this->Slides->saveOrFail($slide); } }); } /** * Deletes the responses of all slides of the poll (see slide()). * The presentation stays where it is. * * @param \App\Model\Entity\Poll $poll Poll * @return void */ public function poll(Poll $poll): void { $this->Slides->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); } }); } }