19declare(strict_types=1);
51 private readonly UIFactory $ui_factory,
53 private readonly QuestionRepository $question_repository,
54 private readonly AttemptRepository $attempt_repository,
55 private readonly CapabilitiesFactory $capabilities_factory,
56 array $capability_identifiers,
57 private readonly
int $owner_object_id
59 $this->required_capabilities = $this->capabilities_factory->get(
60 $capability_identifiers
66 return $this->presentation_identifier;
82 bool $show_best_response,
84 ): QuestionParticipantView {
85 $question = $this->question_repository->getForQuestionId(
89 $marking_required = $this->required_capabilities->isMarkingRequired();
91 if ($attempt_id ===
null
92 || !isset($this->attempt_cache[$attempt_id->
toString()][$question_id->
toString()])) {
93 $attempt = $this->attempt_repository->getAttemptFor(
97 $attempt_id = $attempt->getId();
98 $this->attempt_cache[$attempt_id->
toString()][$question_id->
toString()] = $attempt;
101 return $question->getParticipantView(
105 $this->required_capabilities,
108 $show_marks && $marking_required,
109 $show_best_response && $marking_required,
110 $show_feedback && $this->required_capabilities->isCapabilityRequired(
111 TextFeedback::getIdentifier()
120 $question = $this->question_repository->getForQuestionId(
124 $attempt_data = $this->attempt_repository->getAttemptFor(
129 if ($attempt_data ===
null) {
130 throw new \UnexpectedValueException(
131 'The provided attempt identifier is invalid. Response cannot be persisted.'
135 $response = $this->attempt_repository->getNewResponseFor(
140 $response_with_values_from_post = array_reduce(
141 $question->retrieveAnswerFormResponsesFromPost(
142 $this->required_capabilities,
143 $this->http->wrapper()->post(),
147 =>
$c->withAnswerFormResponse($v),
151 if ($this->required_capabilities->isMarkingRequired()) {
152 $response_with_values_from_post = $question->addAwardedPointsToResponse(
153 $response_with_values_from_post
157 $this->attempt_repository->storeResponse(
158 $response_with_values_from_post
166 $this->attempt_repository->deleteResponsesFor(
168 $this->question_repository->getForQuestionId(
Builds a Color from either hex- or rgb values.
deleteResponsesFor(Uuid $attempt_id, Uuid $question_id)
getPresentationIdentifier()
withShuffleQuestionOrder(bool $shuffle_question_order)
bool $shuffle_question_order
readonly RequiredCapabilities $required_capabilities
__construct(private readonly Language $lng, private readonly Refinery $refinery, private readonly UIFactory $ui_factory, private readonly HTTP $http, private readonly QuestionRepository $question_repository, private readonly AttemptRepository $attempt_repository, private readonly CapabilitiesFactory $capabilities_factory, array $capability_identifiers, private readonly int $owner_object_id)
getQuestionView(Uuid $question_id, ?Uuid $attempt_id, bool $interactive, bool $show_marks, bool $show_best_response, bool $show_feedback)
persistResponse(Uuid $question_id, Uuid $attempt_id)
toString()
Converts this UUID into a string representation.
readonly HttpService $http