Add initial Plenario live polling app
CakePHP 5.4 app for live polls: create via email without login, manage via secret admin link, join via code. Includes slide types (choice, wordcloud, open, scale, content), presenter mode, CSV export, captcha, throttling, tests and Gitea CI/deploy workflow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
eb319f8c1e
120 files changed
+15572
No files matched your search
Whitespace-only changes.
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model\Entity;
|
||||
|
||||
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 int|null $current_slide_id
|
||||
* @property bool $is_active
|
||||
* @property bool $show_results_to_participants
|
||||
* @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,
|
||||
'show_results_to_participants' => 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',
|
||||
];
|
||||
|
||||
/**
|
||||
* "K7P2QX" -> "K7P 2QX" for nicer display.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function formattedJoinCode(): string
|
||||
{
|
||||
return trim(chunk_split($this->join_code, 3, ' '));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model\Entity;
|
||||
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
* One answer row of a participant. A multi-select vote or a word cloud entry
|
||||
* with several words results in several rows with the same participant_hash.
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $slide_id
|
||||
* @property string $participant_hash
|
||||
* @property int|null $slide_option_id
|
||||
* @property string|null $text_value
|
||||
* @property int|null $numeric_value
|
||||
* @property \Cake\I18n\DateTime $created
|
||||
*/
|
||||
class Response extends Entity
|
||||
{
|
||||
/**
|
||||
* Responses are only created by VoteService, never mass assigned from requests.
|
||||
*
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'slide_id' => true,
|
||||
'participant_hash' => true,
|
||||
'slide_option_id' => true,
|
||||
'text_value' => true,
|
||||
'numeric_value' => true,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
protected array $_hidden = ['participant_hash'];
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model\Entity;
|
||||
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
* A slide of a poll. `type` decides how participants answer and how results
|
||||
* are aggregated (see \App\Service\ResultsService and \App\Service\VoteService).
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $poll_id
|
||||
* @property string $type
|
||||
* @property string $question
|
||||
* @property string|null $description
|
||||
* @property int $position
|
||||
* @property array<string, mixed>|null $settings
|
||||
* @property bool $is_voting_open
|
||||
* @property \Cake\I18n\DateTime $created
|
||||
* @property \Cake\I18n\DateTime $modified
|
||||
* @property \App\Model\Entity\Poll $poll
|
||||
* @property array<\App\Model\Entity\SlideOption> $slide_options
|
||||
* @property array<\App\Model\Entity\Response> $responses
|
||||
*/
|
||||
class Slide extends Entity
|
||||
{
|
||||
public const TYPE_CHOICE = 'choice';
|
||||
public const TYPE_WORDCLOUD = 'wordcloud';
|
||||
public const TYPE_OPEN = 'open';
|
||||
public const TYPE_SCALE = 'scale';
|
||||
public const TYPE_CONTENT = 'content';
|
||||
|
||||
/**
|
||||
* Default settings per type. Unknown keys are dropped on save.
|
||||
*
|
||||
* @var array<string, array<string, mixed>>
|
||||
*/
|
||||
public const DEFAULT_SETTINGS = [
|
||||
self::TYPE_CHOICE => ['multiple' => false],
|
||||
// max_words: words per participant incl. upvotes (not downvotes), 0 = unlimited;
|
||||
// allow_downvotes only takes effect together with allow_upvotes
|
||||
self::TYPE_WORDCLOUD => ['max_words' => 0, 'allow_upvotes' => true, 'allow_downvotes' => true],
|
||||
self::TYPE_OPEN => [],
|
||||
self::TYPE_SCALE => ['scale_min' => 1, 'scale_max' => 5, 'min_label' => '', 'max_label' => ''],
|
||||
self::TYPE_CONTENT => [],
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'type' => true,
|
||||
'question' => true,
|
||||
'description' => true,
|
||||
'settings' => true,
|
||||
'is_voting_open' => true,
|
||||
];
|
||||
|
||||
/**
|
||||
* @return array<string, string> type => human readable label
|
||||
*/
|
||||
public static function typeLabels(): array
|
||||
{
|
||||
return [
|
||||
self::TYPE_CHOICE => __('Multiple Choice'),
|
||||
self::TYPE_WORDCLOUD => __('Wortwolke'),
|
||||
self::TYPE_OPEN => __('Offene Frage'),
|
||||
self::TYPE_SCALE => __('Skala'),
|
||||
self::TYPE_CONTENT => __('Inhaltsfolie'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string> type => short description
|
||||
*/
|
||||
public static function typeDescriptions(): array
|
||||
{
|
||||
return [
|
||||
self::TYPE_CHOICE => __('Antwortoptionen vorgeben, Ergebnis als Balkendiagramm.'),
|
||||
self::TYPE_WORDCLOUD => __('Teilnehmende geben Begriffe ein oder unterstützen vorhandene, häufige werden größer.'),
|
||||
self::TYPE_OPEN => __('Freitext-Antworten, live als Liste.'),
|
||||
self::TYPE_SCALE => __('Bewertung auf einer Skala, z. B. 1 bis 5.'),
|
||||
self::TYPE_CONTENT => __('Nur Text anzeigen, ohne Abstimmung.'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function typeLabel(): string
|
||||
{
|
||||
return static::typeLabels()[$this->type] ?? $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether participants can answer this slide at all.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isInteractive(): bool
|
||||
{
|
||||
return $this->type !== self::TYPE_CONTENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings merged with the type defaults.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function getSettings(): array
|
||||
{
|
||||
$defaults = self::DEFAULT_SETTINGS[$this->type] ?? [];
|
||||
|
||||
return array_intersect_key(array_merge($defaults, (array)($this->settings ?? [])), $defaults);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key Setting name
|
||||
* @return mixed
|
||||
*/
|
||||
public function setting(string $key): mixed
|
||||
{
|
||||
return $this->getSettings()[$key] ?? null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Model\Entity;
|
||||
|
||||
use Cake\ORM\Entity;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $slide_id
|
||||
* @property string $label
|
||||
* @property int $position
|
||||
*/
|
||||
class SlideOption extends Entity
|
||||
{
|
||||
/**
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
protected array $_accessible = [
|
||||
'label' => true,
|
||||
'position' => true,
|
||||
];
|
||||
}
|
||||
Reference in new issue
Block a user