Where is the code for question_utils located

Where is the code for question_utils located

de AL Rachels -
Número de respuestas: 6
Imagen de Core developers Imagen de Particularly helpful Moodlers Imagen de Plugin developers Imagen de Testers

I have been trying to follow the code logic in the Essay (autograde) question type. In it's file, question.php, down around line 536, it has the following line of code:

$plaintext = question_utils::to_plain_text($text, $format, array('para' => false));

For more time than I care to admit, I have been trying to track down the location of, question_utils? Can anyone tell me where I might find it?

Promedio de valoraciones: -
En respuesta a AL Rachels

Re: Where is the code for question_utils located

de Dominique Bauer -
Imagen de Documentation writers Imagen de Particularly helpful Moodlers Imagen de Plugin developers
Search "question_utils" (123 hits in 24 files)
  C:\moodle310\server\moodle\mod\quiz\locallib.php (1 hit)
	Line 2090:         $questiontext = question_utils::to_plain_text($question->questiontext,
  C:\moodle310\server\moodle\question\behaviour\behaviourbase.php (5 hits)
	Line 413:         $newmark = question_utils::clean_param_mark($pendingstep->get_behaviour_var('mark'));
	Line 502:             $mark = question_utils::clean_param_mark($pendingstep->get_behaviour_var('mark'));
	Line 558:             $comment = question_utils::to_plain_text($step->get_behaviour_var('comment'),
	Line 565:         $mark = question_utils::clean_param_mark($step->get_behaviour_var('mark'));
	Line 787:         if ($fraction <= question_utils::MARK_TOLERANCE) {
  C:\moodle310\server\moodle\question\behaviour\rendererbase.php (2 hits)
	Line 100:         $editor->use_editor($id, question_utils::get_editor_options($options->context),
	Line 101:                 question_utils::get_filepicker_options($options->context, $draftitemid));
  C:\moodle310\server\moodle\question\engine\lib.php (2 hits)
	Line 142:         $mark = question_utils::optional_param_mark($prefix . '-mark');
	Line 792: abstract class question_utils {
  C:\moodle310\server\moodle\question\engine\questionattempt.php (4 hits)
	Line 698:         return $this->maxmark >= question_utils::MARK_TOLERANCE;
	Line 1155:         $mark = question_utils::clean_param_mark($currentmark);
	Line 1161:         if ($mark > $maxmark * $this->get_max_fraction() + question_utils::MARK_TOLERANCE ||
	Line 1162:                 $mark < $maxmark * $this->get_min_fraction() - question_utils::MARK_TOLERANCE) {
  C:\moodle310\server\moodle\question\engine\tests\questionutils_test.php (81 hits)
	Line 18:  * This file contains tests for the {@link question_utils} class.
	Line 34:  * Unit tests for the {@link question_utils} class.
	Line 39: class question_utils_test extends advanced_testcase {
	Line 41:         $this->assertTrue(question_utils::arrays_have_same_keys_and_values(
	Line 44:         $this->assertTrue(question_utils::arrays_have_same_keys_and_values(
	Line 47:         $this->assertFalse(question_utils::arrays_have_same_keys_and_values(
	Line 50:         $this->assertFalse(question_utils::arrays_have_same_keys_and_values(
	Line 53:         $this->assertFalse(question_utils::arrays_have_same_keys_and_values(
	Line 56:         $this->assertFalse(question_utils::arrays_have_same_keys_and_values(
	Line 62:         $this->assertTrue(question_utils::arrays_same_at_key(
	Line 66:         $this->assertFalse(question_utils::arrays_same_at_key(
	Line 70:         $this->assertFalse(question_utils::arrays_same_at_key(
	Line 74:         $this->assertTrue(question_utils::arrays_same_at_key(
	Line 78:         $this->assertFalse(question_utils::arrays_same_at_key(
	Line 82:         $this->assertTrue(question_utils::arrays_same_at_key(
	Line 86:         $this->assertFalse(question_utils::arrays_same_at_key(
	Line 90:         $this->assertFalse(question_utils::arrays_same_at_key(
	Line 97:         $this->assertTrue(question_utils::arrays_same_at_key_missing_is_blank(
	Line 101:         $this->assertFalse(question_utils::arrays_same_at_key_missing_is_blank(
	Line 105:         $this->assertFalse(question_utils::arrays_same_at_key_missing_is_blank(
	Line 109:         $this->assertTrue(question_utils::arrays_same_at_key_missing_is_blank(
	Line 113:         $this->assertFalse(question_utils::arrays_same_at_key_missing_is_blank(
	Line 117:         $this->assertTrue(question_utils::arrays_same_at_key_missing_is_blank(
	Line 121:         $this->assertFalse(question_utils::arrays_same_at_key_missing_is_blank(
	Line 125:         $this->assertTrue(question_utils::arrays_same_at_key_missing_is_blank(
	Line 132:         $this->assertTrue(question_utils::arrays_same_at_key_integer(
	Line 136:         $this->assertFalse(question_utils::arrays_same_at_key_integer(
	Line 140:         $this->assertFalse(question_utils::arrays_same_at_key_integer(
	Line 144:         $this->assertTrue(question_utils::arrays_same_at_key_integer(
	Line 148:         $this->assertFalse(question_utils::arrays_same_at_key_integer(
	Line 152:         $this->assertTrue(question_utils::arrays_same_at_key_integer(
	Line 156:         $this->assertTrue(question_utils::arrays_same_at_key_integer(
	Line 160:         $this->assertTrue(question_utils::arrays_same_at_key_integer(
	Line 167:         $this->assertSame('i', question_utils::int_to_roman(1));
	Line 168:         $this->assertSame('iv', question_utils::int_to_roman(4));
	Line 169:         $this->assertSame('v', question_utils::int_to_roman(5));
	Line 170:         $this->assertSame('vi', question_utils::int_to_roman(6));
	Line 171:         $this->assertSame('ix', question_utils::int_to_roman(9));
	Line 172:         $this->assertSame('xi', question_utils::int_to_roman(11));
	Line 173:         $this->assertSame('xlviii', question_utils::int_to_roman(48));
	Line 174:         $this->assertSame('lxxxvii', question_utils::int_to_roman(87));
	Line 175:         $this->assertSame('c', question_utils::int_to_roman(100));
	Line 176:         $this->assertSame('mccxxxiv', question_utils::int_to_roman(1234));
	Line 177:         $this->assertSame('mmmcmxcix', question_utils::int_to_roman(3999));
	Line 181:         $this->assertEquals('A', question_utils::int_to_letter(1));
	Line 182:         $this->assertEquals('B', question_utils::int_to_letter(2));
	Line 183:         $this->assertEquals('C', question_utils::int_to_letter(3));
	Line 184:         $this->assertEquals('D', question_utils::int_to_letter(4));
	Line 185:         $this->assertEquals('E', question_utils::int_to_letter(5));
	Line 186:         $this->assertEquals('F', question_utils::int_to_letter(6));
	Line 187:         $this->assertEquals('G', question_utils::int_to_letter(7));
	Line 188:         $this->assertEquals('H', question_utils::int_to_letter(8));
	Line 189:         $this->assertEquals('I', question_utils::int_to_letter(9));
	Line 190:         $this->assertEquals('J', question_utils::int_to_letter(10));
	Line 191:         $this->assertEquals('K', question_utils::int_to_letter(11));
	Line 192:         $this->assertEquals('L', question_utils::int_to_letter(12));
	Line 193:         $this->assertEquals('M', question_utils::int_to_letter(13));
	Line 194:         $this->assertEquals('N', question_utils::int_to_letter(14));
	Line 195:         $this->assertEquals('O', question_utils::int_to_letter(15));
	Line 196:         $this->assertEquals('P', question_utils::int_to_letter(16));
	Line 197:         $this->assertEquals('Q', question_utils::int_to_letter(17));
	Line 198:         $this->assertEquals('R', question_utils::int_to_letter(18));
	Line 199:         $this->assertEquals('S', question_utils::int_to_letter(19));
	Line 200:         $this->assertEquals('T', question_utils::int_to_letter(20));
	Line 201:         $this->assertEquals('U', question_utils::int_to_letter(21));
	Line 202:         $this->assertEquals('V', question_utils::int_to_letter(22));
	Line 203:         $this->assertEquals('W', question_utils::int_to_letter(23));
	Line 204:         $this->assertEquals('X', question_utils::int_to_letter(24));
	Line 205:         $this->assertEquals('Y', question_utils::int_to_letter(25));
	Line 206:         $this->assertEquals('Z', question_utils::int_to_letter(26));
	Line 211:         question_utils::int_to_roman(0);
	Line 216:         question_utils::int_to_roman(4000);
	Line 221:         question_utils::int_to_roman(1.5);
	Line 225:         $this->assertNull(question_utils::clean_param_mark(null));
	Line 226:         $this->assertNull(question_utils::clean_param_mark('frog'));
	Line 227:         $this->assertSame('', question_utils::clean_param_mark(''));
	Line 228:         $this->assertSame(0.0, question_utils::clean_param_mark('0'));
	Line 229:         $this->assertSame(1.5, question_utils::clean_param_mark('1.5'));
	Line 230:         $this->assertSame(1.5, question_utils::clean_param_mark('1,5'));
	Line 231:         $this->assertSame(-1.5, question_utils::clean_param_mark('-1.5'));
	Line 232:         $this->assertSame(-1.5, question_utils::clean_param_mark('-1,5'));
  C:\moodle310\server\moodle\question\format\aiken\format.php (2 hits)
	Line 184:         $expout = str_replace("\n", '', question_utils::to_plain_text($question->questiontext,
	Line 189:             $expout .= $number . ') ' . str_replace("\n", '', question_utils::to_plain_text($answer->answer,
  C:\moodle310\server\moodle\question\format.php (1 hit)
	Line 1108:         return s(question_utils::to_plain_text($question->questiontext,
  C:\moodle310\server\moodle\question\type\ddimageortext\edit_ddimageortext_form.php (1 hit)
	Line 140:             $options[$i] = question_utils::int_to_letter($i);
  C:\moodle310\server\moodle\question\type\essay\question.php (2 hits)
	Line 88:             return question_utils::to_plain_text($response['answer'],
	Line 167:                 question_utils::arrays_same_at_key_missing_is_blank(
  C:\moodle310\server\moodle\question\type\essay\renderer.php (3 hits)
	Line 386:         return question_utils::get_editor_options($context);
	Line 400:             'use question_utils::specific_filepicker_options() instead.', DEBUG_DEVELOPER);
	Line 423:         return question_utils::get_filepicker_options($context, $draftitemid);
  C:\moodle310\server\moodle\question\type\formulas\question.php (2 hits)
	Line 324:             if (!question_utils::arrays_same_at_key_missing_is_blank(
	Line 922:             if (!question_utils::arrays_same_at_key_missing_is_blank($prevresponse, $newresponse, $name)) {
  C:\moodle310\server\moodle\question\type\formulas\renderer.php (2 hits)
	Line 186:                 $number = question_utils::int_to_roman($num + 1);
	Line 189:                 $number = strtoupper(question_utils::int_to_roman($num + 1));
  C:\moodle310\server\moodle\question\type\gapselect\edit_form_base.php (1 hit)
	Line 185:             $options[$i] = question_utils::int_to_letter($i);
  C:\moodle310\server\moodle\question\type\gapselect\questionbase.php (1 hit)
	Line 256:             if (!question_utils::arrays_same_at_key_integer(
  C:\moodle310\server\moodle\question\type\match\question.php (1 hit)
	Line 293:             if (!question_utils::arrays_same_at_key_integer(
  C:\moodle310\server\moodle\question\type\multichoice\question.php (2 hits)
	Line 261:         return question_utils::arrays_same_at_key($prevresponse, $newresponse, 'answer');
	Line 431:             if (!question_utils::arrays_same_at_key_integer($prevresponse, $newresponse, $fieldname)) {
  C:\moodle310\server\moodle\question\type\multichoice\questiontype.php (2 hits)
	Line 253:                         question_utils::to_plain_text($answer->answer, $answer->answerformat),
	Line 264:                         question_utils::to_plain_text($answer->answer, $answer->answerformat),
  C:\moodle310\server\moodle\question\type\multichoice\renderer.php (2 hits)
	Line 194:                 $number = question_utils::int_to_roman($num + 1);
	Line 197:                 $number = strtoupper(question_utils::int_to_roman($num + 1));
  C:\moodle310\server\moodle\question\type\numerical\question.php (2 hits)
	Line 160:         if (!question_utils::arrays_same_at_key_missing_is_blank(
	Line 166:             return question_utils::arrays_same_at_key_missing_is_blank(
  C:\moodle310\server\moodle\question\type\pmatch\question.php (1 hit)
	Line 130:         return question_utils::arrays_same_at_key_missing_is_blank(
  C:\moodle310\server\moodle\question\type\questionbase.php (1 hit)
	Line 378:         return question_utils::to_plain_text($text, $format);
  C:\moodle310\server\moodle\question\type\shortanswer\question.php (1 hit)
	Line 81:         return question_utils::arrays_same_at_key_missing_is_blank(
  C:\moodle310\server\moodle\question\type\truefalse\question.php (1 hit)
	Line 98:         return question_utils::arrays_same_at_key_missing_is_blank(
En respuesta a Dominique Bauer

Re: Where is the code for question_utils located

de AL Rachels -
Imagen de Core developers Imagen de Particularly helpful Moodlers Imagen de Plugin developers Imagen de Testers
Thanks Dominique,
I looked at your reply on my phone three times last night and could not find what I was looking. Big screens make a huge difference to my tired, old eyes. I kept looking for a "file" when the whole time it was inside a file as an abstract, whatever that is.

One thing that hurts me when it comes to maintaining Moodle plugins using PHP, is that PHP had not been invented yet, the last time I took a programming course. I had never come across classes as an abstract and was used to looking for them as separate files.

Now to figure out how to use it since I now know where it is. Everything I tried before I started looking for the code, did not seem to work and kept giving a debug message saying, "question_utils", did not exist.
En respuesta a AL Rachels

Re: Where is the code for question_utils located

de Tim Hunt -
Imagen de Core developers Imagen de Documentation writers Imagen de Particularly helpful Moodlers Imagen de Peer reviewers Imagen de Plugin developers

If you are working with Moodle code, then you need to be able to answer questions like this all the time.

The slickest answer is to use an IDE like VSCode or PHPStorm. Then, when I am looking at the code, I can just hold down CTRL and click on the function or class name to jump straight to where it is defined. PHPStorm's full-text search is also unbelievable fast.

If you don't want to install an IDE (but, really you do) then you need some other way to search all the files. https://git-scm.com/docs/git-grep is very fast. Other solutions exist.

Also, the search at github is good. E.g. try searching for question_utils at https://github.com/moodle/moodle/. Or, at https://github.com/moodle/moodle/blob/511a87f5fc357f18a4c53911f6e6c7f7b526246e/question/type/essay/question.php#L97, try clicking on the function name to_plain_text sonrisa

En respuesta a Tim Hunt

Re: Where is the code for question_utils located

de AL Rachels -
Imagen de Core developers Imagen de Particularly helpful Moodlers Imagen de Plugin developers Imagen de Testers
Thanks for the info Tim. I have tried to use IDE's in the past, but due to limited knowledge and guidance on how to set them up, they made more work for me in the long run. VSCode is a new one I have not heard about so I guess I will try once again.
En respuesta a AL Rachels

Re: Where is the code for question_utils located

de Dominique Bauer -
Imagen de Documentation writers Imagen de Particularly helpful Moodlers Imagen de Plugin developers

Notepad++ ↗ can be used to edit plugin code. It is sometimes recommended as your first Integrated Development Environment (IDE), although it does not really qualify as such given its simplicity. It's a good choice if you don't want to invest the time to get familiar with a full-fledged IDE.  

NetBeans is often mentioned for writing PHP programs, but there are plenty more. See for example Best PHP IDE ↗ or any other simliar review.

To find out what an "abstrat class" is, I would consult two references: W3Schools ↗ and Stack Overflow ↗.

En respuesta a Dominique Bauer

Re: Where is the code for question_utils located

de AL Rachels -
Imagen de Core developers Imagen de Particularly helpful Moodlers Imagen de Plugin developers Imagen de Testers
My normal work setup is git, WinSCP, PuTTY, and Notepad++. Just recently added GitHub Desktop. I have used Eclipse in the past and do have it currently set up on my main development desktop computer, but due to having to monitor my wife all the time now, I have to use my living room computer where I currently only have WinSCP, PuTTY, and Notepad++. Never tried PHPStorm due to recurring annual cost. My reluctance to regularly use Eclipse is due to the docs in Moodle do not seem to be up to date with the latest version/s. The templates in it have really cost me a lot of extra work where it's coding style does not match that required by Moodle. I have tried on numerous occasions to fix the templates but with not enough success to rely on it.