Results belong on the stage. Participants only get results where they interact with them (word cloud with upvotes) and, once resolved, the solution of quiz and ordering slides with their own verdict, without counts or distribution. Removes the per-poll setting show_results_to_participants (column stays unused). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
110 lines
2.8 KiB
PHP
110 lines
2.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Model\Entity;
|
|
|
|
use Cake\I18n\DateTime;
|
|
use Cake\ORM\Entity;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property string $title
|
|
* @property string $email
|
|
* @property string $admin_token_hash
|
|
* @property string $admin_token_encrypted
|
|
* @property string $join_code
|
|
* @property string|null $embed_key
|
|
* @property int|null $current_slide_id
|
|
* @property \Cake\I18n\DateTime|null $embed_seen_at
|
|
* @property int|null $paused_slide_id
|
|
* @property bool $is_active
|
|
* @property \Cake\I18n\DateTime|null $last_admin_access
|
|
* @property \Cake\I18n\DateTime $created
|
|
* @property \Cake\I18n\DateTime $modified
|
|
* @property array<\App\Model\Entity\Slide> $slides
|
|
*/
|
|
class Poll extends Entity
|
|
{
|
|
/**
|
|
* Only harmless fields are mass assignable. Tokens, join code and the
|
|
* current slide are always set explicitly in code.
|
|
*
|
|
* @var array<string, bool>
|
|
*/
|
|
protected array $_accessible = [
|
|
'title' => true,
|
|
'email' => true,
|
|
'is_active' => true,
|
|
];
|
|
|
|
/**
|
|
* Never leak secrets when an entity is serialised (JSON, debug output).
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected array $_hidden = [
|
|
'admin_token_hash',
|
|
'admin_token_encrypted',
|
|
'email',
|
|
'embed_key',
|
|
];
|
|
|
|
/**
|
|
* "K7P2QX" -> "K7P 2QX" for nicer display.
|
|
*
|
|
* @return string
|
|
*/
|
|
public function formattedJoinCode(): string
|
|
{
|
|
return trim(chunk_split($this->join_code, 3, ' '));
|
|
}
|
|
|
|
/**
|
|
* Shows a slide to the participants (from PlenarIO itself: no embed timeout).
|
|
*
|
|
* @param int $slideId Slide id (must belong to this poll, checked by the caller)
|
|
* @return void
|
|
*/
|
|
public function showSlide(int $slideId): void
|
|
{
|
|
$this->current_slide_id = $slideId;
|
|
$this->paused_slide_id = null;
|
|
$this->embed_seen_at = null;
|
|
}
|
|
|
|
/**
|
|
* Shows a slide because its embedded page (e.g. in Canva) became visible.
|
|
* It stays live only as long as the page keeps sending heartbeats.
|
|
*
|
|
* @param int $slideId Slide id
|
|
* @return void
|
|
*/
|
|
public function showEmbeddedSlide(int $slideId): void
|
|
{
|
|
$this->showSlide($slideId);
|
|
$this->embed_seen_at = DateTime::now();
|
|
}
|
|
|
|
/**
|
|
* No slide live: participants see the pause page. Idempotent.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function pause(): void
|
|
{
|
|
if ($this->current_slide_id !== null) {
|
|
$this->paused_slide_id = $this->current_slide_id;
|
|
}
|
|
$this->current_slide_id = null;
|
|
$this->embed_seen_at = null;
|
|
}
|
|
|
|
/**
|
|
* @return bool Paused after a slide had been live (not: not started yet)
|
|
*/
|
|
public function isPaused(): bool
|
|
{
|
|
return $this->current_slide_id === null && $this->paused_slide_id !== null;
|
|
}
|
|
}
|