Add countdown audio per presentation
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:
1 parent
cad09163d9
commit
2f7a401522
16 files changed
+648
-11
No files matched your search
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace App\Model\Table;
|
||||
|
||||
use App\Model\Entity\Poll;
|
||||
use App\Service\AudioService;
|
||||
use App\Service\ImageService;
|
||||
use ArrayObject;
|
||||
use Cake\Core\Configure;
|
||||
@@ -16,6 +17,7 @@ use Cake\ORM\Table;
|
||||
use Cake\Utility\Security;
|
||||
use Cake\Validation\Validator;
|
||||
use RuntimeException;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Polls ("presentations"). Access control works exclusively via the secret
|
||||
@@ -277,13 +279,27 @@ class PollsTable extends Table
|
||||
$copy->set('comment_speed', $poll->comment_speed);
|
||||
|
||||
$token = null;
|
||||
$this->getConnection()->transactional(function () use ($copy, $slides, &$token): void {
|
||||
[, $token] = $this->insertPoll($copy);
|
||||
if ($token === null) {
|
||||
throw new RuntimeException('Poll could not be saved');
|
||||
}
|
||||
$this->Slides->copyAllToPoll($slides, $copy->id);
|
||||
});
|
||||
$audio = new AudioService();
|
||||
$audioCopy = null;
|
||||
try {
|
||||
$this->getConnection()->transactional(function () use ($poll, $copy, $slides, $audio, &$token, &$audioCopy): void {
|
||||
[, $token] = $this->insertPoll($copy);
|
||||
if ($token === null) {
|
||||
throw new RuntimeException('Poll could not be saved');
|
||||
}
|
||||
$this->Slides->copyAllToPoll($slides, $copy->id);
|
||||
// The copy gets its own audio file: deleting one poll never takes the music of the other.
|
||||
$audioCopy = $poll->hasAudio() ? $audio->copy($copy->id, (string)$poll->audio, $poll->id) : null;
|
||||
if ($audioCopy !== null) {
|
||||
$copy->set('audio', $audioCopy);
|
||||
$this->saveOrFail($copy);
|
||||
}
|
||||
});
|
||||
} catch (Throwable $e) {
|
||||
$audio->delete((int)$copy->id, $audioCopy);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return [$copy, $token];
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user