Merge branch 'MDL-64646' of https://github.com/mkassaei/moodle
This commit is contained in:
@@ -905,6 +905,47 @@ abstract class question_utils {
|
||||
self::$tens[$number / 10 % 10] . self::$units[$number % 10];
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an integer to a letter of alphabet.
|
||||
* @param int $number an integer between 1 and 26 inclusive.
|
||||
* Anything else will throw an exception.
|
||||
* @return string the number converted to upper case letter of alphabet.
|
||||
*/
|
||||
public static function int_to_letter($number) {
|
||||
$alphabet = [
|
||||
'1' => 'A',
|
||||
'2' => 'B',
|
||||
'3' => 'C',
|
||||
'4' => 'D',
|
||||
'5' => 'E',
|
||||
'6' => 'F',
|
||||
'7' => 'G',
|
||||
'8' => 'H',
|
||||
'9' => 'I',
|
||||
'10' => 'J',
|
||||
'11' => 'K',
|
||||
'12' => 'L',
|
||||
'13' => 'M',
|
||||
'14' => 'N',
|
||||
'15' => 'O',
|
||||
'16' => 'P',
|
||||
'17' => 'Q',
|
||||
'18' => 'R',
|
||||
'19' => 'S',
|
||||
'20' => 'T',
|
||||
'21' => 'U',
|
||||
'22' => 'V',
|
||||
'23' => 'W',
|
||||
'24' => 'X',
|
||||
'25' => 'Y',
|
||||
'26' => 'Z'
|
||||
];
|
||||
if (!is_integer($number) || $number < 1 || $number > count($alphabet)) {
|
||||
throw new coding_exception('Only integers between 1 and 26 can be converted to letters.', $number);
|
||||
}
|
||||
return $alphabet[$number];
|
||||
}
|
||||
|
||||
/**
|
||||
* Typically, $mark will have come from optional_param($name, null, PARAM_RAW_TRIMMED).
|
||||
* This method copes with:
|
||||
|
||||
@@ -177,6 +177,35 @@ class question_utils_test extends advanced_testcase {
|
||||
$this->assertSame('mmmcmxcix', question_utils::int_to_roman(3999));
|
||||
}
|
||||
|
||||
public function test_int_to_letter() {
|
||||
$this->assertEquals('A', question_utils::int_to_letter(1));
|
||||
$this->assertEquals('B', question_utils::int_to_letter(2));
|
||||
$this->assertEquals('C', question_utils::int_to_letter(3));
|
||||
$this->assertEquals('D', question_utils::int_to_letter(4));
|
||||
$this->assertEquals('E', question_utils::int_to_letter(5));
|
||||
$this->assertEquals('F', question_utils::int_to_letter(6));
|
||||
$this->assertEquals('G', question_utils::int_to_letter(7));
|
||||
$this->assertEquals('H', question_utils::int_to_letter(8));
|
||||
$this->assertEquals('I', question_utils::int_to_letter(9));
|
||||
$this->assertEquals('J', question_utils::int_to_letter(10));
|
||||
$this->assertEquals('K', question_utils::int_to_letter(11));
|
||||
$this->assertEquals('L', question_utils::int_to_letter(12));
|
||||
$this->assertEquals('M', question_utils::int_to_letter(13));
|
||||
$this->assertEquals('N', question_utils::int_to_letter(14));
|
||||
$this->assertEquals('O', question_utils::int_to_letter(15));
|
||||
$this->assertEquals('P', question_utils::int_to_letter(16));
|
||||
$this->assertEquals('Q', question_utils::int_to_letter(17));
|
||||
$this->assertEquals('R', question_utils::int_to_letter(18));
|
||||
$this->assertEquals('S', question_utils::int_to_letter(19));
|
||||
$this->assertEquals('T', question_utils::int_to_letter(20));
|
||||
$this->assertEquals('U', question_utils::int_to_letter(21));
|
||||
$this->assertEquals('V', question_utils::int_to_letter(22));
|
||||
$this->assertEquals('W', question_utils::int_to_letter(23));
|
||||
$this->assertEquals('X', question_utils::int_to_letter(24));
|
||||
$this->assertEquals('Y', question_utils::int_to_letter(25));
|
||||
$this->assertEquals('Z', question_utils::int_to_letter(26));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException moodle_exception
|
||||
*/
|
||||
|
||||
@@ -147,7 +147,7 @@ class qtype_ddimageortext_edit_form extends qtype_ddtoimage_edit_form_base {
|
||||
array('class' => 'dragitemtype'));
|
||||
$options = array();
|
||||
for ($i = 1; $i <= self::MAX_GROUPS; $i += 1) {
|
||||
$options[$i] = $i;
|
||||
$options[$i] = question_utils::int_to_letter($i);
|
||||
}
|
||||
$grouparray[] = $mform->createElement('select', 'draggroup',
|
||||
get_string('group', 'qtype_gapselect'),
|
||||
|
||||
@@ -27,6 +27,9 @@ Feature: Test editing a drag and drop into text questions
|
||||
@javascript
|
||||
Scenario: Edit a drag and drop into text question
|
||||
When I click on "Edit" "link" in the "Drag to text" "table_row"
|
||||
Then I should see "Choice [[1]]"
|
||||
And I should see "Choice [[2]]"
|
||||
And I should see "Choice [[3]]"
|
||||
And I set the following fields to these values:
|
||||
| Question name | Edited question name |
|
||||
And I press "id_submitbutton"
|
||||
|
||||
@@ -182,7 +182,7 @@ class qtype_gapselect_edit_form_base extends question_edit_form {
|
||||
protected function choice_group($mform) {
|
||||
$options = array();
|
||||
for ($i = 1; $i <= $this->get_maximum_choice_group_number(); $i += 1) {
|
||||
$options[$i] = $i;
|
||||
$options[$i] = question_utils::int_to_letter($i);
|
||||
}
|
||||
$grouparray = array();
|
||||
$grouparray[] = $mform->createElement('text', 'answer',
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
$string['addmorechoiceblanks'] = 'Blanks for {no} more choices';
|
||||
$string['answer'] = 'Answer';
|
||||
$string['choices'] = 'Choices';
|
||||
$string['choicex'] = 'Choice {no}';
|
||||
$string['choicex'] = 'Choice [[{no}]]';
|
||||
$string['combinedcontrolnamegapselect'] = 'drop down box';
|
||||
$string['combinedcontrolnamegapselectplural'] = 'drop down boxes';
|
||||
$string['correctansweris'] = 'The correct answer is: {$a}';
|
||||
|
||||
Reference in New Issue
Block a user