mirror of
https://github.com/moodle/moodle.git
synced 2025-04-15 21:45:37 +02:00
MDL-79863 qtype_ordering: qtype_ordering fix small typo in language file and optimize logic in form validation
This commit is contained in:
parent
9d3998ecf5
commit
4a70e6211f
@ -362,26 +362,26 @@ class qtype_ordering_edit_form extends question_edit_form {
|
||||
$errors = array();
|
||||
$plugin = 'qtype_ordering';
|
||||
|
||||
// Identify duplicates and report as an error.
|
||||
$answers = [];
|
||||
$answercount = 0;
|
||||
$list = [];
|
||||
foreach ($data['answer'] as $answer) {
|
||||
if (is_array($answer)) {
|
||||
$answer = trim($answer['text']);
|
||||
$answer = $answer['text'];
|
||||
}
|
||||
if (trim($answer) == '') {
|
||||
continue; // Skip empty answer.
|
||||
if ($answer = trim($answer)) {
|
||||
if (in_array($answer, $answers)) {
|
||||
$i = array_search($answer, $answers);
|
||||
$item = get_string('answerheader', $plugin);
|
||||
$item = str_replace('{no}', $i + 1, $item);
|
||||
$item = html_writer::link("#id_answerheader_$i", $item);
|
||||
$a = (object)array('text' => $answer, 'item' => $item);
|
||||
$errors["answer[$answercount]"] = get_string('duplicatesnotallowed', $plugin, $a);
|
||||
} else {
|
||||
$answers[] = $answer;
|
||||
}
|
||||
$answercount++;
|
||||
}
|
||||
// Check on duplicates.
|
||||
if ($answer && in_array($answer, $list)) {
|
||||
$draggableitem = new stdClass();
|
||||
$draggableitem->number = array_search($answer, $list) + 1;
|
||||
$draggableitem->text = $answer;
|
||||
|
||||
$errors["answer[$answercount]"] = get_string('err_draggableitemsduplication', 'qtype_ordering', $draggableitem);
|
||||
} else {
|
||||
$list[] = trim($answer);
|
||||
}
|
||||
$answercount++;
|
||||
}
|
||||
|
||||
switch ($answercount) {
|
||||
|
@ -34,8 +34,8 @@ $string['correctorder'] = 'The correct order for these items is as follows:';
|
||||
$string['defaultanswerformat'] = 'Default answer format';
|
||||
$string['defaultquestionname'] = 'Drag the following items into the correct order.';
|
||||
|
||||
$string['duplicatesnotallowed'] = 'Duplication of draggable items is not allowed. The string "{$a->text}" is already used in {$a->item}.';
|
||||
$string['editingordering'] = 'Editing ordering question';
|
||||
$string['err_draggableitemsduplication'] = 'Dupplication of draggable items are not allowed. The string "{$a->text}" is already used in Draggable item {$a->number}.';
|
||||
|
||||
$string['gradedetails'] = 'Grade details';
|
||||
$string['gradingtype'] = 'Grading type';
|
||||
|
@ -29,5 +29,5 @@ $plugin->cron = 0;
|
||||
$plugin->component = 'qtype_ordering';
|
||||
$plugin->maturity = MATURITY_STABLE;
|
||||
$plugin->requires = 2015051100; // Moodle 2.9.
|
||||
$plugin->version = 2019021986;
|
||||
$plugin->release = '2019-02-19 (86)';
|
||||
$plugin->version = 2019030688;
|
||||
$plugin->release = '2019-03-06 (88)';
|
||||
|
Loading…
x
Reference in New Issue
Block a user