diff --git a/classes/output/mobile.php b/classes/output/mobile.php index 74d3f549..67bf9e64 100644 --- a/classes/output/mobile.php +++ b/classes/output/mobile.php @@ -162,7 +162,9 @@ public static function mobile_view_activity($args) { if ($question->supports_mobile()) { $pagequestions[] = $question->mobile_question_display($qnum, $questionnaire->autonum); $responses = array_merge($responses, $question->get_mobile_response_data($response)); - $qnum++; + if ($question->is_numbered()) { + $qnum++; + } } } $data['prevpage'] = 0; @@ -265,8 +267,10 @@ protected static function add_pagequestion_data($questionnaire, $pagenum, $respo if (($response !== null) && isset($response->answers[$questionid])) { $responses = array_merge($responses, $question->get_mobile_response_data($response)); } + if ($question->is_numbered()) { + $qnum++; + } } - $qnum++; } return ['pagequestions' => $pagequestions, 'responses' => $responses]; diff --git a/classes/question/pagebreak.php b/classes/question/pagebreak.php index c831641d..930639df 100644 --- a/classes/question/pagebreak.php +++ b/classes/question/pagebreak.php @@ -102,4 +102,12 @@ public function supports_mobile() { public function mobile_question_display($qnum, $autonum = false) { return false; } + + /** + * Override and return false if a number should not be rendered for this question in any context. + * @return bool + */ + public function is_numbered() { + return false; + } } diff --git a/classes/question/question.php b/classes/question/question.php index 5207a529..5f6c5616 100644 --- a/classes/question/question.php +++ b/classes/question/question.php @@ -497,6 +497,14 @@ public function supports_feedback_scores() { return $this->supports_feedback(); } + /** + * Override and return false if a number should not be rendered for this question in any context. + * @return bool + */ + public function is_numbered() { + return true; + } + /** * True if the question supports feedback and has valid settings for feedback. Override if the default logic is not enough. * @return bool diff --git a/classes/question/sectiontext.php b/classes/question/sectiontext.php index 6e75a8f5..107e6845 100644 --- a/classes/question/sectiontext.php +++ b/classes/question/sectiontext.php @@ -59,6 +59,44 @@ public function supports_feedback() { return false; } + /** + * True if question provides mobile support. + * @return bool + */ + public function supports_mobile() { + return true; + } + + /** + * Display on mobile. + * + * @param int $qnum + * @param bool $autonum + */ + public function mobile_question_display($qnum, $autonum = false) { + $options = ['noclean' => true, 'para' => false, 'filter' => true, + 'context' => $this->context, 'overflowdiv' => true]; + $mobiledata = (object)[ + 'id' => $this->id, + 'name' => $this->name, + 'type_id' => $this->type_id, + 'length' => $this->length, + 'content' => format_text(file_rewrite_pluginfile_urls($this->content, 'pluginfile.php', $this->context->id, + 'mod_questionnaire', 'question', $this->id), FORMAT_HTML, $options), + 'content_stripped' => strip_tags($this->content), + 'required' => false, + 'deleted' => $this->deleted, + 'response_table' => $this->responsetable, + 'fieldkey' => $this->mobile_fieldkey(), + 'precise' => $this->precise, + 'qnum' => '', + 'errormessage' => get_string('required') . ': ' . $this->name + ]; + + $mobiledata->issectiontext = true; + return $mobiledata; + } + /** * True if question type supports feedback scores and weights. Same as supports_feedback() by default. */ @@ -81,6 +119,14 @@ public function question_template() { return 'mod_questionnaire/question_sectionfb'; } + /** + * Override and return false if a number should not be rendered for this question in any context. + * @return bool + */ + public function is_numbered() { + return false; + } + /** * Return the context tags for the check question template. * @param \mod_questionnaire\responsetype\response\response $response diff --git a/classes/questions_form.php b/classes/questions_form.php index 769cbe86..c332ab5b 100644 --- a/classes/questions_form.php +++ b/classes/questions_form.php @@ -146,7 +146,7 @@ public function definition() { redirect($CFG->wwwroot.'/mod/questionnaire/questions.php?id='.$questionnaire->cm->id); } - if ($tid != QUESPAGEBREAK && $tid != QUESSECTIONTEXT) { + if ($question->is_numbered()) { $qnum++; } @@ -330,12 +330,10 @@ public function definition() { $mform->addElement('static', 'qdepend_' . $question->id, '', $dependencies); } - if ($tid != QUESPAGEBREAK) { - if ($tid != QUESSECTIONTEXT) { + if ($question->is_numbered()) { $qnumber = '

'.$qnum.'

'; - } else { + } else { $qnumber = ''; - } } if ($this->moveq && $pos < $moveqposition) { diff --git a/questionnaire.class.php b/questionnaire.class.php index 738c4c07..61cc562a 100644 --- a/questionnaire.class.php +++ b/questionnaire.class.php @@ -1323,7 +1323,7 @@ private function survey_render(&$formdata, $section = 1, $message = '') { $this->renderer->render_progress_bar($section, $this->questionsbysec)); } foreach ($this->questionsbysec[$section] as $questionid) { - if ($this->questions[$questionid]->type_id != QUESSECTIONTEXT) { + if ($this->questions[$questionid]->is_numbered()) { $i++; } // Need questionnaire id to get the questionnaire object in sectiontext (Label) question class. @@ -1615,7 +1615,7 @@ public function survey_print_render($courseid, $message = '', $referer='', $rid= $page++; } foreach ($section as $questionid) { - if ($this->questions[$questionid]->type_id == QUESSECTIONTEXT) { + if (!$this->questions[$questionid]->is_numbered()) { $i--; } if (isset($allqdependants[$questionid])) { @@ -1848,8 +1848,8 @@ private function response_check_format($section, $formdata, $checkmissing = true if (key_exists($section, $this->questionsbysec)) { foreach ($this->questionsbysec[$section] as $questionid) { - $tid = $this->questions[$questionid]->type_id; - if ($tid != QUESSECTIONTEXT) { + + if ($this->questions[$questionid]->is_numbered()) { $qnum++; } if (!$this->questions[$questionid]->response_complete($formdata)) { @@ -2910,13 +2910,13 @@ public function survey_results($rid = '', $uid=false, $pdf = false, $currentgrou if ($question->type_id == QUESPAGEBREAK) { continue; } - if ($question->type_id != QUESSECTIONTEXT) { + if ($question->is_numbered()) { $qnum++; } if (!$pdf) { $this->page->add_to_page('responses', $this->renderer->container_start('qn-container')); $this->page->add_to_page('responses', $this->renderer->container_start('qn-info')); - if ($question->type_id != QUESSECTIONTEXT) { + if ($question->is_numbered()) { $this->page->add_to_page('responses', $this->renderer->heading($qnum, 2, 'qn-number')); } $this->page->add_to_page('responses', $this->renderer->container_end()); // End qn-info. @@ -2928,7 +2928,7 @@ public function survey_results($rid = '', $uid=false, $pdf = false, $currentgrou } if ($pdf) { $response = new stdClass(); - if ($question->type_id != QUESSECTIONTEXT) { + if ($question->is_numbered()) { $response->qnum = $qnum; } $response->qcontent = format_text(file_rewrite_pluginfile_urls($question->content, 'pluginfile.php',