diff --git a/classes/form/context/render_context.php b/classes/form/context/render_context.php index 7ca8a84d..a5bbf22a 100644 --- a/classes/form/context/render_context.php +++ b/classes/form/context/render_context.php @@ -146,7 +146,7 @@ abstract public function hide_if(string $dependant, string $dependency, string $ * @return string name of the element qualified by this context's prefix */ public function mangle_name(string $name): string { - if (utils::str_starts_with($name, $this->prefix)) { + if (str_starts_with($name, $this->prefix)) { // Already mangled, perhaps by an array_render_context. return $name; } diff --git a/classes/question_ui_renderer.php b/classes/question_ui_renderer.php index bddb7191..201c817f 100644 --- a/classes/question_ui_renderer.php +++ b/classes/question_ui_renderer.php @@ -249,7 +249,7 @@ private function mangle_ids_and_names(): void { ") as $attr ) { $original = $attr->value; - if ($attr->name === "usemap" && utils::str_starts_with($original, "#")) { + if ($attr->name === "usemap" && str_starts_with($original, "#")) { // See https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/useMap. $attr->value = "#" . $this->attempt->get_qt_field_name(substr($original, 1)); } else { diff --git a/classes/utils.php b/classes/utils.php index 2b40696a..39c7d85f 100644 --- a/classes/utils.php +++ b/classes/utils.php @@ -42,18 +42,6 @@ public static function &ensure_exists(array &$array, string $key): array { return $array[$key]; } - /** - * Determines whether a string starts with another. - * - * @param string $haystack - * @param string $needle - * @return bool - */ - public static function str_starts_with(string $haystack, string $needle): bool { - // From https://stackoverflow.com/a/10473026. - return substr_compare($haystack, $needle, 0, strlen($needle)) === 0; - } - /** * Given an array and a key such as `abc[def]`, returns `$array["abc"]["def"]`. * diff --git a/question.php b/question.php index f52fee36..5f2c0a1b 100644 --- a/question.php +++ b/question.php @@ -160,11 +160,7 @@ public function apply_attempt_state(question_attempt_step $step) { $this->scoringstate = $this->get_behaviour()->get_qa()->get_last_qt_var(constants::QT_VAR_SCORING_STATE); $lastqtdata = $this->get_behaviour()->get_qa()->get_last_qt_data(null); - $lastresponse = $lastqtdata === null ? null : array_filter( - $lastqtdata, - fn($key) => !utils::str_starts_with($key, "_"), - ARRAY_FILTER_USE_KEY - ); + $lastresponse = $lastqtdata === null ? null : utils::filter_for_response($lastqtdata); /* TODO: This method is also called from question_attempt->regrade and question_attempt->start_question_based_on, where we shouldn't need to get the UI. */