Skip to content

Commit c8a218f

Browse files
committed
docs: add missing PHPdocs
1 parent f878b34 commit c8a218f

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed

classes/attempt_ui/invalid_option_warning.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,43 @@
1919
use coding_exception;
2020
use html_writer;
2121

22+
/**
23+
* The last response has fields set to values which don't seem to be available anymore.
24+
*
25+
* @package qtype_questionpy
26+
* @author Maximilian Haye
27+
* @copyright 2024 TU Berlin, innoCampus {@link https://www.questionpy.org}
28+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29+
*/
2230
class invalid_option_warning {
31+
/**
32+
* Trivial constructor.
33+
*
34+
* @param string $name name of the input field in question
35+
* @param string $value value from the last response, for which no option was found in the UI
36+
* @param array $availablevalues the available options present in the UI
37+
*/
2338
public function __construct(
39+
/** @var string $name name of the input field in question */
2440
public string $name,
41+
/** @var string $value value from the last response, for which no option was found in the UI */
2542
public string $value,
43+
/** @var array $availablevalues the available options present in the UI */
2644
public array $availablevalues
2745
) {
2846
}
2947

3048
/**
49+
* Return a localized string describing this warning to humans. Name and values are escaped.
50+
*
51+
* @return string
3152
* @throws coding_exception
3253
*/
3354
public function localize(): string {
34-
$availablevaluesstr = implode(', ', array_map(fn($value) => html_writer::tag('code', format_string($value)), $this->availablevalues));
55+
$availablevaluesstr = implode(', ', array_map(
56+
fn($value) => html_writer::tag('code', format_string($value)),
57+
$this->availablevalues
58+
));
3559

3660
return get_string('render_warning_invalid_value', 'qtype_questionpy', [
3761
'name' => html_writer::tag('code', format_string($this->name)),

classes/attempt_ui/question_ui_renderer.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,22 @@ function (array $match) use ($question) {
588588
);
589589
}
590590

591+
/**
592+
* For all selects, checkboxes and radios in the UI, collects the available option values.
593+
*
594+
* This can be opted-out of by setting `qpy:warn-on-unknown-option` on the input element. In the case of checkboxes
595+
* and radios, any element having the attribute will exclude all inputs with the same name.
596+
*
597+
* At first glance, this function seems to be more suited to be placed in
598+
* {@see question_ui_metadata_extractor}. It is here for two reasons:
599+
* - The {@see \qtype_questionpy_renderer} uses the render warnings when it also renders the UI. The metadata
600+
* extractor is used in other methods.
601+
* - While we should discourage it, it is possible for inputs to be inside `qpy:if-role` or `qpy:feedback`
602+
* elements. {@see question_ui_metadata_extractor} doesn't resolve those.
603+
*
604+
* @return array
605+
* @see check_for_unknown_options
606+
*/
591607
private function extract_available_options(): array {
592608
$optionsbyname = [];
593609

@@ -642,6 +658,13 @@ private function extract_available_options(): array {
642658
return $optionsbyname;
643659
}
644660

661+
/**
662+
* Checks if the last response contains values which are invalid.
663+
*
664+
* @param array $availableoptionsbyname
665+
* @return array
666+
* @see extract_available_options
667+
*/
645668
private function check_for_unknown_options(array $availableoptionsbyname): array {
646669
$response = utils::get_last_response($this->attempt);
647670

classes/attempt_ui/render_result.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,21 @@
1616

1717
namespace qtype_questionpy\attempt_ui;
1818

19+
/**
20+
* Result from {@see question_ui_renderer::render()}: The HTML and possibly warnings.
21+
*
22+
* @package qtype_questionpy
23+
* @author Maximilian Haye
24+
* @copyright 2024 TU Berlin, innoCampus {@link https://www.questionpy.org}
25+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26+
*/
1927
class render_result {
28+
/**
29+
* Initialize a new render result.
30+
*
31+
* @param string $html
32+
* @param array $warnings
33+
*/
2034
public function __construct(
2135
/** @var string $html */
2236
public string $html,

classes/utils.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ public static function filter_for_response(array $qtvars): array {
132132
);
133133
}
134134

135+
/**
136+
* Gets the last response submitted in the given attempt, or an empty array if no response has been submitted yet.
137+
*
138+
* The last response is the qt data of the last step which has {@see constants::QT_VAR_RESPONSE_MARKER} set, to
139+
* which {@see utils::filter_for_response} is applied.
140+
*
141+
* @param question_attempt $qa
142+
* @return array
143+
*/
135144
public static function get_last_response(question_attempt $qa): array {
136145
$step = $qa->get_last_step_with_qt_var(constants::QT_VAR_RESPONSE_MARKER);
137146
return self::filter_for_response($step->get_qt_data());

0 commit comments

Comments
 (0)