Add Q&A slide type
Participants submit questions, upvote them and the presenter discusses them one by one, most upvoted first. - Stages collect -> vote -> discuss, switched manually by the presenter (V key or stepper, going back is possible) - Configurable upvote budget per participant, freely distributable (several upvotes on one question are allowed), votes can be withdrawn - Participants see all questions while collecting to avoid duplicates; no counts before the discussion - While discussing, next/prev step through the questions before moving to the next slide - Migration: slides.stage, slides.focus_response_id, responses.parent_id Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ea944b080f
commit
f0c6687100
21 files changed
+1327
-27
No files matched your search
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
namespace App\Model\Table;
|
||||
|
||||
use App\Service\VoteService;
|
||||
use Cake\ORM\Query\SelectQuery;
|
||||
use Cake\ORM\Table;
|
||||
|
||||
/**
|
||||
@@ -32,6 +33,67 @@ class ResponsesTable extends Table
|
||||
$this->belongsTo('SlideOptions', ['foreignKey' => 'slide_option_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Q&A questions of a slide (rows with text, without parent).
|
||||
*
|
||||
* @param int $slideId Slide id
|
||||
* @return \Cake\ORM\Query\SelectQuery
|
||||
*/
|
||||
public function questionsOf(int $slideId): SelectQuery
|
||||
{
|
||||
return $this->find()->where([
|
||||
'Responses.slide_id' => $slideId,
|
||||
'Responses.parent_id IS' => null,
|
||||
'Responses.text_value IS NOT' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Q&A progress of one participant on a slide.
|
||||
*
|
||||
* @param int $slideId Slide id
|
||||
* @param string $participantHash Participant hash
|
||||
* @return array{questions: list<int>, upvotes: list<int>} ids of own questions / question id of each own upvote (repeated per upvote)
|
||||
*/
|
||||
public function qaVotesOf(int $slideId, string $participantHash): array
|
||||
{
|
||||
$rows = $this->find()
|
||||
->select(['id', 'parent_id'])
|
||||
->where(['slide_id' => $slideId, 'participant_hash' => $participantHash])
|
||||
->orderBy(['id' => 'ASC'])
|
||||
->disableHydration()
|
||||
->all();
|
||||
|
||||
$result = ['questions' => [], 'upvotes' => []];
|
||||
foreach ($rows as $row) {
|
||||
if ($row['parent_id'] === null) {
|
||||
$result['questions'][] = (int)$row['id'];
|
||||
} else {
|
||||
$result['upvotes'][] = (int)$row['parent_id'];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upvotes per Q&A question of a slide.
|
||||
*
|
||||
* @param int $slideId Slide id
|
||||
* @return array<int, int> question id => upvotes
|
||||
*/
|
||||
public function upvotesPerQuestion(int $slideId): array
|
||||
{
|
||||
return $this->find()
|
||||
->select(['parent_id', 'n' => $this->find()->func()->count('*')])
|
||||
->where(['slide_id' => $slideId, 'parent_id IS NOT' => null])
|
||||
->groupBy(['parent_id'])
|
||||
->disableHydration()
|
||||
->all()
|
||||
->combine(fn($row) => (int)$row['parent_id'], fn($row) => (int)$row['n'])
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $slideId Slide id
|
||||
* @param string $participantHash Participant hash
|
||||
|
||||
@@ -159,6 +159,10 @@ class SlidesTable extends Table
|
||||
$settings['time_limit'] = $limit;
|
||||
}
|
||||
break;
|
||||
case Slide::TYPE_QA:
|
||||
$max = (int)($input['max_upvotes'] ?? $settings['max_upvotes']);
|
||||
$settings['max_upvotes'] = max(1, min(Slide::QA_MAX_UPVOTES, $max));
|
||||
break;
|
||||
case Slide::TYPE_YOUTUBE:
|
||||
$url = mb_substr(trim((string)($input['url'] ?? '')), 0, 500);
|
||||
$parsed = YouTubeService::parseUrl($url);
|
||||
|
||||
Reference in new issue
Block a user