@@ -40,18 +40,26 @@ class question_ui_metadata_extractor {
4040 private DOMXPath $ xpath ;
4141
4242 /**
43- * @var array|false $correctresponse `false` if not yet extracted, empty array if not set in the XML.
43+ * @var array|null| false $correctresponse `false` if not yet extracted, null if not set in the XML.
4444 * @see \qtype_questionpy_question::get_correct_response()
4545 */
4646 private array |null |false $ correctresponse = false ;
4747
4848 /**
49- * @var string[] $requiredfields `false` if not yet extracted.
49+ * @var string[]|false $requiredfields `false` if not yet extracted.
5050 * @see \question_manually_gradable::is_complete_response()
5151 * @see \question_manually_gradable::is_gradable_response()
5252 */
5353 private array |false $ requiredfields = false ;
5454
55+ /**
56+ * @var string[]|false $requirededitors `false` if not yet extracted.
57+ * @see \question_manually_gradable::is_complete_response()
58+ * @see \question_manually_gradable::is_gradable_response()
59+ */
60+ private array |false $ requirededitors = false ;
61+
62+
5563 /**
5664 * Parses the given XML and initializes a new {@see question_ui_metadata_extractor} instance.
5765 *
@@ -67,11 +75,11 @@ public function __construct(string $xml) {
6775 }
6876
6977 /**
70- * Extracts the names of required fields from the question UI XML.
78+ * Extracts the names of required main response fields from the question UI XML.
7179 *
7280 * @return string[]
7381 */
74- public function get_required_fields (): array {
82+ public function get_required_response_fields (): array {
7583 if ($ this ->requiredfields !== false ) {
7684 return $ this ->requiredfields ;
7785 }
@@ -90,11 +98,29 @@ public function get_required_fields(): array {
9098 }
9199 }
92100
93- // TODO: Include required WYSIWYG editor fields.
94-
95101 return $ this ->requiredfields ;
96102 }
97103
104+ /**
105+ * Extracts the names of required rich text editors from the question UI XML.
106+ *
107+ * @return string[]
108+ */
109+ public function get_required_editors (): array {
110+ if ($ this ->requirededitors !== false ) {
111+ return $ this ->requirededitors ;
112+ }
113+
114+ $ this ->requirededitors = [];
115+ foreach (qpy_rich_text_editor::find_all_in ($ this ->xpath ) as $ editor ) {
116+ if ($ editor ->required ) {
117+ $ this ->requirededitors [] = $ editor ->name ;
118+ }
119+ }
120+
121+ return $ this ->requirededitors ;
122+ }
123+
98124 /**
99125 * Returns the correct response for any fields that use the `@qpy:correct-response` attribute, or null if none do.
100126 *
@@ -132,7 +158,6 @@ public function get_correct_response(): ?array {
132158 return $ this ->correctresponse ;
133159 }
134160
135-
136161 /**
137162 * Returns limits for all `<qpy:file-upload/>` and `<qpy:rich-text-editor/>` elements in the XML, indexed by their name.
138163 *
@@ -142,13 +167,11 @@ public function get_correct_response(): ?array {
142167 public function get_upload_limits (context $ attemptcontext ): array {
143168 $ uploadlimits = [];
144169
145- foreach ($ this ->xpath ->query ('//qpy:file-upload ' ) as $ element ) {
146- $ upload = qpy_file_upload::from_element ($ element );
170+ foreach (qpy_file_upload::find_all_in ($ this ->xpath ) as $ upload ) {
147171 $ uploadlimits [$ upload ->name ] = $ upload ->get_limits_in ($ attemptcontext );
148172 }
149173
150- foreach ($ this ->xpath ->query ('//qpy:rich-text-editor ' ) as $ element ) {
151- $ editor = qpy_rich_text_editor::from_element ($ element );
174+ foreach (qpy_rich_text_editor::find_all_in ($ this ->xpath ) as $ editor ) {
152175 $ uploadlimits [$ editor ->name ] = $ editor ->get_limits_in ($ attemptcontext );
153176 }
154177
0 commit comments