Add anonymous feedback option for open questions
Open questions can be marked private: the presenter screen and embeds only show the number of answers, participants never see results, and the texts are readable on a new admin answers page and in the CSV. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
07a292d109
commit
367ff8548d
14 files changed
+310
-12
No files matched your search
@@ -6,6 +6,7 @@ namespace App\Controller;
|
||||
use App\Model\Entity\Slide;
|
||||
use App\Model\Table\SlidesTable;
|
||||
use App\Service\QaService;
|
||||
use App\Service\ResultsService;
|
||||
use App\Service\YouTubeService;
|
||||
use Cake\Http\Exception\NotFoundException;
|
||||
use Cake\Http\Response;
|
||||
@@ -158,6 +159,22 @@ class SlidesController extends AdminAppController
|
||||
return $this->redirect($this->adminUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* All answers of an open question (also anonymous feedback, which is never shown on the stage).
|
||||
*
|
||||
* @param string $id Slide id
|
||||
* @return void
|
||||
*/
|
||||
public function answers(string $id): void
|
||||
{
|
||||
$slide = $this->loadSlide($id);
|
||||
if ($slide->type !== Slide::TYPE_OPEN) {
|
||||
throw new NotFoundException(__('Folie nicht gefunden.'));
|
||||
}
|
||||
$this->set('slide', $slide);
|
||||
$this->set('answers', (new ResultsService())->answers($slide));
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a slide that belongs to the current poll (404 otherwise).
|
||||
*
|
||||
|
||||
@@ -81,7 +81,8 @@ class Slide extends Entity
|
||||
self::TYPE_CHOICE => ['multiple' => false],
|
||||
// allow_downvotes only takes effect together with allow_upvotes
|
||||
self::TYPE_WORDCLOUD => ['allow_upvotes' => true, 'allow_downvotes' => true],
|
||||
self::TYPE_OPEN => [],
|
||||
// private: anonymous feedback, answers only visible in the admin area (never on the stage)
|
||||
self::TYPE_OPEN => ['private' => false],
|
||||
self::TYPE_SCALE => ['scale_min' => 1, 'scale_max' => 5, 'min_label' => '', 'max_label' => ''],
|
||||
self::TYPE_CONTENT => [],
|
||||
// time_limit in seconds, 0 = no limit (presenter ends the quiz)
|
||||
@@ -327,4 +328,15 @@ class Slide extends Entity
|
||||
{
|
||||
return $this->getSettings()[$key] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open question collecting anonymous feedback: answers are never shown on the
|
||||
* presenter screen or to participants, only in the admin area and the CSV export.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isPrivate(): bool
|
||||
{
|
||||
return $this->type === self::TYPE_OPEN && (bool)$this->setting('private');
|
||||
}
|
||||
}
|
||||
@@ -145,6 +145,9 @@ class SlidesTable extends Table
|
||||
$settings['allow_upvotes'] = filter_var($input['allow_upvotes'] ?? true, FILTER_VALIDATE_BOOLEAN);
|
||||
$settings['allow_downvotes'] = filter_var($input['allow_downvotes'] ?? true, FILTER_VALIDATE_BOOLEAN);
|
||||
break;
|
||||
case Slide::TYPE_OPEN:
|
||||
$settings['private'] = filter_var($input['private'] ?? false, FILTER_VALIDATE_BOOLEAN);
|
||||
break;
|
||||
case Slide::TYPE_SCALE:
|
||||
$min = max(0, min(1, (int)($input['scale_min'] ?? 1)));
|
||||
$max = max(2, min(10, (int)($input['scale_max'] ?? 5)));
|
||||
|
||||
@@ -25,6 +25,7 @@ use Cake\ORM\Locator\LocatorAwareTrait;
|
||||
* when their deadline has passed.
|
||||
*
|
||||
* Q&A slides have their own participant view (`qa`, see qaState()), never `results`.
|
||||
* Private open questions (anonymous feedback) never show results to participants.
|
||||
*/
|
||||
class PollStateService
|
||||
{
|
||||
@@ -162,6 +163,7 @@ class PollStateService
|
||||
$showResults = $slide !== null
|
||||
&& $slide->isInteractive()
|
||||
&& $qa === null
|
||||
&& !$slide->isPrivate()
|
||||
&& ($quiz !== null
|
||||
? $quiz['phase'] === Slide::QUIZ_FINISHED
|
||||
: ($poll->show_results_to_participants && ($hasResponded || !$isVotingOpen))
|
||||
|
||||
@@ -16,7 +16,8 @@ use Cake\ORM\Locator\LocatorAwareTrait;
|
||||
* - wordcloud: 'words' => [['key' (lower case), 'text', 'count', 'down', 'weight' (0..1)]]
|
||||
* (count = participants who named or upvoted the word, down = downvotes,
|
||||
* weight follows count)
|
||||
* - open: 'answers' => [['text', 'created']] newest first
|
||||
* - open: 'answers' => [['text', 'created']] newest first, 'private' (bool);
|
||||
* private (anonymous feedback): 'answers' is always empty, texts only via answers()
|
||||
* - scale: 'buckets' => [['value', 'count', 'percent']], 'average' => float|null,
|
||||
* 'min', 'max', 'minLabel', 'maxLabel'
|
||||
* - quiz: 'phase' (ready|running|finished), 'timeLimit' (s, 0 = manual), 'remaining' (s|null),
|
||||
@@ -213,19 +214,36 @@ class ResultsService
|
||||
*/
|
||||
protected function open(Slide $slide): array
|
||||
{
|
||||
$rows = $this->Responses->find()
|
||||
return [
|
||||
'private' => $slide->isPrivate(),
|
||||
'answers' => $slide->isPrivate() ? [] : $this->answers($slide, self::MAX_ANSWERS),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Texts of an open question, newest first – also of private slides,
|
||||
* so only for the admin area (never for the presenter screen or participants).
|
||||
*
|
||||
* @param \App\Model\Entity\Slide $slide Open question
|
||||
* @param int|null $limit Max. answers, null = all
|
||||
* @return list<array{text: string, created: string}>
|
||||
*/
|
||||
public function answers(Slide $slide, ?int $limit = null): array
|
||||
{
|
||||
$query = $this->Responses->find()
|
||||
->select(['text_value', 'created'])
|
||||
->where(['slide_id' => $slide->id, 'text_value IS NOT' => null])
|
||||
->orderBy(['id' => 'DESC'])
|
||||
->limit(self::MAX_ANSWERS)
|
||||
->all();
|
||||
|
||||
$answers = [];
|
||||
foreach ($rows as $row) {
|
||||
$answers[] = ['text' => $row->text_value, 'created' => $row->created->toIso8601String()];
|
||||
->orderBy(['id' => 'DESC']);
|
||||
if ($limit !== null) {
|
||||
$query->limit($limit);
|
||||
}
|
||||
|
||||
return ['answers' => $answers];
|
||||
$answers = [];
|
||||
foreach ($query->all() as $row) {
|
||||
$answers[] = ['text' => (string)$row->text_value, 'created' => $row->created->toIso8601String()];
|
||||
}
|
||||
|
||||
return $answers;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user