-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shuffleanswers
aus Quiz-Einstellungen berücksichtigen
#103
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,8 @@ class qtype_questionpy_question extends question_graded_automatically_with_count | |
private string $packagehash; | ||
/** @var string */ | ||
private string $questionstate; | ||
/** @var boolean Whether the questions answers should be shuffled. */ | ||
public bool $shuffleanswers; | ||
|
||
// Properties which do change between attempts (i.e. are modified by start_attempt and apply_attempt_state). | ||
/** @var string */ | ||
|
@@ -92,6 +94,7 @@ public function start_attempt(question_attempt_step $step, $variant): void { | |
$this->scoringstate = null; | ||
|
||
$this->ui = new question_ui_renderer($attempt->ui->content, $attempt->ui->placeholders); | ||
$this->ui->shuffleanswers = $this->shuffleanswers; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bitte im Konstruktor übergeben. |
||
} | ||
|
||
/** | ||
|
@@ -123,6 +126,7 @@ public function apply_attempt_state(question_attempt_step $step) { | |
$attempt = $this->api->view_attempt($this->packagehash, $this->questionstate, $this->attemptstate, | ||
$this->scoringstate); | ||
$this->ui = new question_ui_renderer($attempt->ui->content, $attempt->ui->placeholders); | ||
$this->ui->shuffleanswers = $this->shuffleanswers; | ||
} | ||
|
||
/** | ||
|
@@ -223,6 +227,7 @@ public function grade_response(array $response): array { | |
$response | ||
); | ||
$this->ui = new question_ui_renderer($attemptscored->ui->content, $attemptscored->ui->placeholders); | ||
$this->ui->shuffleanswers = $this->shuffleanswers; | ||
// TODO: Persist scoring state. We need to set a qtvar, but we don't have access to the pending step here. | ||
$this->scoringstate = $attemptscored->scoringstate; | ||
switch ($attemptscored->scoringcode) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,4 +145,14 @@ public function get_question_options($question): bool { | |
protected function make_question_instance($questiondata) { | ||
return new qtype_questionpy_question($questiondata->qpy_package_hash, $questiondata->qpy_state); | ||
} | ||
|
||
/** | ||
* Initialise the question_definition fields. | ||
* @param question_definition $question the question_definition we are creating. | ||
* @param object $questiondata the question data loaded from the database. | ||
*/ | ||
protected function initialise_question_instance(question_definition $question, $questiondata) { | ||
parent::initialise_question_instance($question, $questiondata); | ||
$question->shuffleanswers = $questiondata->shuffleanswers; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Greifst du hier auf das richtige Attribut zu? Moodle schreibt ja in |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,8 +53,19 @@ public function head_code(question_attempt $qa) { | |
* @throws coding_exception | ||
*/ | ||
public function formulation_and_controls(question_attempt $qa, question_display_options $options): string { | ||
global $DB; | ||
$question = $qa->get_question(); | ||
assert($question instanceof qtype_questionpy_question); | ||
|
||
// Check if we are in a quiz context. | ||
if ($this->page->context->contextlevel == CONTEXT_MODULE && $this->page->cm->modname == 'quiz') { | ||
$quiz = $DB->get_record('quiz', ['id' => $this->page->cm->instance]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Die Information steckt doch bereits in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wird das There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wenn ich mir https://github.com/moodle/moodle/blob/main/question/engine/bank.php#L278 ansehe, dann scheint das ja gemacht zu werden. Da der Wert aber nur im Falle von "kein shuffle" gesetzt/überschrieben wird, müsstest du vermutlich vorher mittels isset prüfen, ob das Attribut überhaupt existiert. |
||
if ($quiz) { | ||
// Access the shuffleanswers property of the quiz. | ||
$question->ui->shuffleanswers = $quiz->shuffleanswers; | ||
} | ||
} | ||
|
||
return $question->ui->render_formulation($qa, $options); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bitte keine neuen Einstellungen einführen. Ob so eine Einstellung für das jeweilige Paket sinnvoll ist, müssen die Pakete selber wissen und in ihren Options definieren.