Add countdown audio per presentation
CI / Deploy / PHP 8.4 (push) Failing after 1m18s
CI / Deploy / PHP 8.5 (push) Failing after 2m4s
CI / Deploy / test (push) Failing after 1s
CI / Deploy / deploy (push) Skipped

One audio file per poll (MP3, M4A, OGG, WAV) is uploaded in the admin
settings and looped in the presenter view while a quiz runs. Format is
detected by magic bytes, files are served with a fixed content type,
copied with the poll and swept by images_cleanup.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Sonnet 5.5 committed 2026-11-21 11:36:01 +01:00
1 parent cad09163d9
commit 2f7a401522
16 files changed
+648 -11

No files matched your search

+50
View File
@@ -7,6 +7,8 @@ use App\Mailer\PollMailer;
use App\Model\Entity\Slide;
use App\Model\Table\ResponsesTable;
use App\Model\Table\SlidesTable;
use App\Service\AudioService;
use App\Service\ImageException;
use App\Service\PollStateService;
use App\Service\QaService;
use App\Service\ReportService;
@@ -17,6 +19,7 @@ use Cake\Http\Exception\BadRequestException;
use Cake\Http\Response;
use Cake\I18n\DateTime;
use Cake\Routing\Router;
use Psr\Http\Message\UploadedFileInterface;
use chillerlan\QRCode\Output\QRMarkupSVG;
use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\QROptions;
@@ -89,6 +92,53 @@ class AdminController extends AdminAppController
return $this->redirect($this->adminUrl());
}
/**
* Countdown music of the presentation: uploads a new file (replaces the old one) or, with
* `remove` = 1, deletes it. Old files are deleted after saving, never before.
*
* @return \Cake\Http\Response|null
*/
public function audio(): ?Response
{
$this->request->allowMethod(['post']);
$service = new AudioService();
$old = $this->poll->audio;
$upload = $this->request->getUploadedFile('audio');
$hasUpload = $upload instanceof UploadedFileInterface && $upload->getError() !== UPLOAD_ERR_NO_FILE;
$back = $this->adminUrl() + ['#' => 'audio'];
if ($hasUpload) {
try {
$new = $service->store($upload, $this->poll->id);
} catch (ImageException $e) {
$this->Flash->error($e->getMessage());
return $this->redirect($back);
}
} elseif (filter_var($this->request->getData('remove'), FILTER_VALIDATE_BOOLEAN)) {
$new = null;
} else {
$this->Flash->error(__('Bitte wähle eine Audiodatei aus.'));
return $this->redirect($back);
}
$this->poll->set('audio', $new);
try {
$this->Polls->saveOrFail($this->poll);
} catch (Throwable $e) {
$service->delete($this->poll->id, $new);
throw $e;
}
if ($old !== null && $old !== $new) {
$service->delete($this->poll->id, $old);
}
$this->Flash->success($new === null ? __('Audiodatei entfernt.') : __('Audiodatei gespeichert.'));
return $this->redirect($back);
}
/**
* Invalidates the current admin link and mails a new one.
*