From 455f2ad01f59e9d8a2b61496fffeef6b10a00e94 Mon Sep 17 00:00:00 2001 From: Hans Georg Schaathun Date: Mon, 5 Sep 2022 15:39:23 +0200 Subject: [PATCH 1/5] Fixed a deprecated function call. Removes error message but not the bug --- classes/improviser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/improviser.php b/classes/improviser.php index 962097b..4a36c5f 100755 --- a/classes/improviser.php +++ b/classes/improviser.php @@ -120,7 +120,7 @@ private function get_default_question_category() { $context = \context_module::instance($this->jazzquiz->cm->id); $category = question_get_default_category($context->id); if (!$category) { - $contexts = new \question_edit_contexts($context); + $contexts = new \core_question\local\bank\question_edit_contexts($context); $category = question_make_default_categories($contexts->all()); } return $category; From 959a26f5fb3e88ae312c711e62f9540220127495 Mon Sep 17 00:00:00 2001 From: Hans Georg Schaathun Date: Tue, 6 Sep 2022 08:30:18 +0200 Subject: [PATCH 2/5] Added new functions to create question bank entry and question version for the IMPROV questions. They are now correctly created, but they do not appear in the Improvise drop down menu during the session. --- classes/improviser.php | 67 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 60 insertions(+), 7 deletions(-) diff --git a/classes/improviser.php b/classes/improviser.php index 4a36c5f..1221852 100755 --- a/classes/improviser.php +++ b/classes/improviser.php @@ -126,6 +126,24 @@ private function get_default_question_category() { return $category; } + /** + * Create a question bank entry for the database. + * @return \stdClass | null + */ + private function make_generic_question_bank_entry() { + $category = $this->get_default_question_category(); + if (!$category) { + return null; + } + + /* debugging( "Making generic question bank entry." ) ; */ + $question = new \stdClass(); + $question->questioncategoryid = $category->id; + $question->ownerid = null; + $question->idnumber = null; + return $question; + } + /** * Create a question database object. * @param string $qtype What question type to create @@ -134,18 +152,15 @@ private function get_default_question_category() { */ private function make_generic_question_definition(string $qtype, string $name) { if (!$this->question_type_exists($qtype)) { + /* debugging( "make_generic_question_definition: question type does not exist" ) ; */ return null; } $existing = $this->get_improvised_question_definition($name); if ($existing !== false) { - return null; - } - $category = $this->get_default_question_category(); - if (!$category) { + /* debugging( "make_generic_question_definition: existing: ".$name ) ; */ return null; } $question = new \stdClass(); - $question->category = $category->id; $question->parent = 0; $question->name = '{IMPROV}' . $name; $question->questiontext = ' '; @@ -157,8 +172,6 @@ private function make_generic_question_definition(string $qtype, string $name) { $question->qtype = $qtype; $question->length = 1; $question->stamp = ''; - $question->version = ''; - $question->hidden = 0; $question->timecreated = time(); $question->timemodified = $question->timecreated; $question->createdby = null; @@ -225,11 +238,19 @@ private function make_generic_question_answer($questionid, string $format, strin */ private function insert_multichoice_question_definition(string $name, array $answers) { global $DB; + /* debugging("insert_multichoice_question_definition: ".$name ) ; */ $question = $this->make_generic_question_definition('multichoice', $name); if (!$question) { return; } + /* debugging("insert_multichoice_question_definition 2") ; */ + $qbankentry = $this->make_generic_question_bank_entry(); + if (!$qbankentry) { + return; + } $question->id = $DB->insert_record('question', $question); + $qbankentry->id = $DB->insert_record('question_bank_entries', $qbankentry); + $this->insert_question_version( $qbankentry->id, $question->id ) ; // Add options. $options = $this->make_multichoice_options($question->id); $DB->insert_record('qtype_multichoice_options', $options); @@ -238,6 +259,23 @@ private function insert_multichoice_question_definition(string $name, array $ans $qanswer = $this->make_generic_question_answer($question->id, 1, $answer); $DB->insert_record('question_answers', $qanswer); } + /* debugging( "Question ID ".$question->id ); */ + } + + /* Create a question version database object, linking the given question + * and question bank entry. + * @param int $qbankid The ID of the question banke entry + * @param int $qid The ID of the question + * @return \stdClass + */ + private function insert_question_version(int $qbankid, int $qid) { + global $DB; + $qv = new \stdClass(); + $qv->questionbankentryid = $qbankid ; + $qv->version = 1 ; + $qv->questionid = $qid ; + $qv->id = $DB->insert_record('question_versions', $qv); + return $qv; } /** @@ -246,11 +284,19 @@ private function insert_multichoice_question_definition(string $name, array $ans */ private function insert_shortanswer_question_definition(string $name) { global $DB; + /* debugging("insert_shortanswer_question_definition: ".$name ) ; */ $question = $this->make_generic_question_definition('shortanswer', $name); if (!$question) { return; } + $qbankentry = $this->make_generic_question_bank_entry(); + if (!$qbankentry) { + return; + } $question->id = $DB->insert_record('question', $question); + $qbankentry->id = $DB->insert_record('question_bank_entries', $qbankentry); + $this->insert_question_version( $qbankentry->id, $question->id ) ; + // Add options. $options = $this->make_shortanswer_options($question->id); $DB->insert_record('qtype_shortanswer_options', $options); @@ -261,11 +307,18 @@ private function insert_shortanswer_question_definition(string $name) { private function insert_shortmath_question_definition(string $name) { global $DB; + /* debugging("insert_shortmath_question_definition: ".$name ) ; */ $question = $this->make_generic_question_definition('shortmath', $name); if (!$question) { return; } + $qbankentry = $this->make_generic_question_bank_entry(); + if (!$qbankentry) { + return; + } $question->id = $DB->insert_record('question', $question); + $qbankentry->id = $DB->insert_record('question_bank_entries', $qbankentry); + $this->insert_question_version( $qbankentry->id, $question->id ) ; // Add options. Important: If shortmath changes options table in the future, this must be changed too. $options = $this->make_shortanswer_options($question->id); $DB->insert_record('qtype_shortmath_options', $options); From 382dfe5d4431b6b8630031ad762e6f0ed9bb4972 Mon Sep 17 00:00:00 2001 From: Hans Georg Schaathun Date: Tue, 6 Sep 2022 14:19:06 +0200 Subject: [PATCH 3/5] Changed the SQL query to find IMPROV questions to match new schema. It seems to work. Not thoroughly tested though. --- ajax.php | 2 ++ classes/improviser.php | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ajax.php b/ajax.php index 15319e9..416a4c5 100755 --- a/ajax.php +++ b/ajax.php @@ -45,7 +45,9 @@ function show_all_improvise_questions(jazzquiz $jazzquiz) { $improviser = new improviser($jazzquiz); $questionrecords = $improviser->get_all_improvised_question_definitions(); + debugging( 'show'.$questionrecords ); if (!$questionrecords) { + debugging( 'No improvisation questions' ); return [ 'status' => 'error', 'message' => 'No improvisation questions' diff --git a/classes/improviser.php b/classes/improviser.php index 1221852..cab8960 100755 --- a/classes/improviser.php +++ b/classes/improviser.php @@ -60,13 +60,19 @@ public function get_all_improvised_question_definitions() { $questions = []; $context = \context_module::instance($this->jazzquiz->cm->id); $parts = explode('/', $context->path); + debugging( "get_all_improvised: ".$parts ) ; foreach ($parts as $part) { // Selecting name first, to prevent duplicate improvise questions. + debugging( "get_all_improvised: ".$part ) ; $sql = "SELECT q.name, q.id FROM {question} q + JOIN {question_versions} qv + ON q.id = qv.questionid + JOIN {question_bank_entries} qbe + ON qbe.id = qv.questionbankentryid JOIN {question_categories} qc - ON qc.id = q.category + ON qc.id = qbe.questioncategoryid JOIN {context} ctx ON ctx.id = qc.contextid AND ctx.path LIKE :path From 7ff471201222f3741db2a8e131d125dde737826d Mon Sep 17 00:00:00 2001 From: Hans Georg Schaathun Date: Tue, 6 Sep 2022 14:25:55 +0200 Subject: [PATCH 4/5] Converted tab character --- reports.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reports.php b/reports.php index 6c76726..79e25a2 100755 --- a/reports.php +++ b/reports.php @@ -136,7 +136,7 @@ function jazzquiz_reports() { if (!$isdownload) { $jazzquiz->renderer->header($jazzquiz, 'reports'); } - $sessionid = optional_param('sessionid', 0, PARAM_INT); + $sessionid = optional_param('sessionid', 0, PARAM_INT); switch ($action) { case 'view': jazzquiz_view_session_report($jazzquiz, $url, $sessionid); From deb37583e0b58f704db367f81e5391978b9459e8 Mon Sep 17 00:00:00 2001 From: Hans Georg Schaathun Date: Tue, 6 Sep 2022 14:31:49 +0200 Subject: [PATCH 5/5] Moved static declaration after visibility --- backup/moodle2/backup_jazzquiz_activity_task.class.php | 2 +- backup/moodle2/restore_jazzquiz_activity_task.class.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backup/moodle2/backup_jazzquiz_activity_task.class.php b/backup/moodle2/backup_jazzquiz_activity_task.class.php index f3846df..11107dd 100644 --- a/backup/moodle2/backup_jazzquiz_activity_task.class.php +++ b/backup/moodle2/backup_jazzquiz_activity_task.class.php @@ -45,7 +45,7 @@ protected function define_my_steps() { * @param string $content * @return string of content with the URLs encoded */ - static public function encode_content_links($content) { + public static function encode_content_links($content) { global $CFG; $base = preg_quote($CFG->wwwroot, '/'); // Link to the list of JazzQuizes. diff --git a/backup/moodle2/restore_jazzquiz_activity_task.class.php b/backup/moodle2/restore_jazzquiz_activity_task.class.php index 9d57a39..1d82d86 100644 --- a/backup/moodle2/restore_jazzquiz_activity_task.class.php +++ b/backup/moodle2/restore_jazzquiz_activity_task.class.php @@ -41,7 +41,7 @@ protected function define_my_steps() { /** * @return restore_decode_content[] */ - static public function define_decode_contents() { + public static function define_decode_contents() { return [ new restore_decode_content('jazzquiz', ['intro']) ]; @@ -50,7 +50,7 @@ static public function define_decode_contents() { /** * @return restore_decode_rule[] */ - static public function define_decode_rules() { + public static function define_decode_rules() { return [ new restore_decode_rule('JAZZQUIZVIEWBYID', '/mod/jazzquiz/view.php?id=$1', 'course_module'), new restore_decode_rule('JAZZQUIZINDEX', '/mod/jazzquiz/index.php?id=$1', 'course') @@ -60,14 +60,14 @@ static public function define_decode_rules() { /** * @return restore_log_rule[] */ - static public function define_restore_log_rules() { + public static function define_restore_log_rules() { return []; } /** * @return restore_log_rule[] */ - static public function define_restore_log_rules_for_course() { + public static function define_restore_log_rules_for_course() { return []; }