Skip to content

Commit

Permalink
Merge branch 'MOODLE_401_STABLE' into MOODLE_403_STABLE
Browse files Browse the repository at this point in the history
  • Loading branch information
mchurchward authored Feb 23, 2024
2 parents a3069f0 + 4564790 commit 4bf5aec
Show file tree
Hide file tree
Showing 27 changed files with 532 additions and 85 deletions.
8 changes: 6 additions & 2 deletions classes/output/mobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion classes/question/numerical.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function question_survey_display($response, $descendantsdata, $blankqu
// Numeric.
$questiontags = new \stdClass();
$precision = $this->precise;
$a = '';
$a = new \StdClass();
if (isset($response->answers[$this->id][0])) {
$mynumber = $response->answers[$this->id][0]->value;
if ($mynumber != '') {
Expand Down
8 changes: 8 additions & 0 deletions classes/question/pagebreak.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
8 changes: 8 additions & 0 deletions classes/question/question.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions classes/question/radio.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ protected function question_survey_display($response, $dependants=[], $blankques
}
$contents = questionnaire_choice_values($choice->content);
$radio->label = $value.format_text($contents->text, FORMAT_HTML, ['noclean' => true]).$contents->image;
if (!empty($this->qlegend)) {
$radio->alabel = strip_tags("{$this->qlegend} {$radio->label}");
}
} else { // Radio button with associated !other text field.
$othertext = $choice->other_choice_display();
$cname = choice::id_other_choice_name($id);
Expand All @@ -143,6 +146,10 @@ protected function question_survey_display($response, $dependants=[], $blankques
$radio->ovalue = format_string(stripslashes($odata));
}
$radio->olabel = 'Text for '.format_text($othertext, FORMAT_HTML, ['noclean' => true]);
if (!empty($this->qlegend)) {
$radio->alabel = strip_tags("{$this->qlegend} {$radio->label}");
$radio->aolabel = strip_tags("{$this->qlegend} {$radio->olabel}");
}
}
$choicetags->qelements[] = (object)['choice' => $radio];
}
Expand All @@ -164,6 +171,9 @@ protected function question_survey_display($response, $dependants=[], $blankques
}
$content = get_string('noanswer', 'questionnaire');
$radio->label = format_text($content, FORMAT_HTML, ['noclean' => true]);
if (!empty($this->qlegend)) {
$radio->alabel = strip_tags("{$this->qlegend} {$radio->label}");
}

$choicetags->qelements[] = (object)['choice' => $radio];
}
Expand Down Expand Up @@ -213,6 +223,9 @@ protected function response_survey_display($response) {
} else {
$chobj->content = ($choice->content === '' ? $id : format_text($choice->content, FORMAT_HTML, ['noclean' => true]));
}
if (!empty($this->qlegend)) {
$chobj->alabel = strip_tags("{$this->qlegend} {$chobj->content}");
}
$resptags->choices[] = $chobj;
}

Expand Down
48 changes: 47 additions & 1 deletion classes/question/sectiontext.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,47 @@ public function required() {
* True if question type supports feedback options. False by default.
*/
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.
*/
Expand All @@ -70,7 +108,7 @@ public function supports_feedback_scores() {
* True if the question supports feedback and has valid settings for feedback. Override if the default logic is not enough.
*/
public function valid_feedback() {
return true;
return false;
}

/**
Expand All @@ -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
Expand Down
33 changes: 33 additions & 0 deletions classes/question/slider.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,39 @@ public function response_template() {
return 'mod_questionnaire/response_slider';
}

/**
* True if question type supports feedback options. False by default.
* @return bool
*/
public function supports_feedback() {
return true;
}

/**
* True if the question supports feedback and has valid settings for feedback. Override if the default logic is not enough.
* @return bool
*/
public function valid_feedback() {
$extradata = json_decode($this->extradata);
$minrange = $extradata->minrange;
// Negative scores are not accepted in Feedback.
return $this->supports_feedback() && !empty($this->name) && $minrange >= 0;
}

/**
* Get the maximum score possible for feedback if appropriate. Override if default behaviour is not correct.
* @return int | boolean
*/
public function get_feedback_maxscore() {
if ($this->valid_feedback()) {
$extradata = json_decode($this->extradata);
$maxscore = $extradata->maxrange;
} else {
$maxscore = false;
}
return $maxscore;
}

/**
* Return the context tags for the check question template.
*
Expand Down
10 changes: 10 additions & 0 deletions classes/question/yesno.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ protected function question_survey_display($response, $dependants=[], $blankques
if ($blankquestionnaire) {
$option->disabled = true;
}
if (!empty($this->qlegend)) {
$option->alabel = strip_tags("{$this->qlegend} {$option->label}");
}
$choicetags->qelements->choice[] = $option;
}
// CONTRIB-846.
Expand All @@ -169,6 +172,9 @@ protected function question_survey_display($response, $dependants=[], $blankques
if (!$ischecked && !$blankquestionnaire) {
$option->checked = true;
}
if (!empty($this->qlegend)) {
$option->alabel = strip_tags("{$this->qlegend} {$option->label}");
}
$choicetags->qelements->choice[] = $option;
}
// End CONTRIB-846.
Expand Down Expand Up @@ -201,6 +207,10 @@ protected function response_survey_display($response) {
if ($answer->value == 'n') {
$resptags->noselected = 1;
}
if (!empty($this->qlegend)) {
$resptags->alabelyes = strip_tags("{$this->qlegend} {$resptags->stryes}");
$resptags->alabelno = strip_tags("{$this->qlegend} {$resptags->strno}");
}

return $resptags;
}
Expand Down
8 changes: 3 additions & 5 deletions classes/questions_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,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++;
}

Expand Down Expand Up @@ -331,12 +331,10 @@ public function definition() {
$mform->addElement('static', 'qdepend_' . $question->id, '', $dependencies);
}

if ($tid != QUESPAGEBREAK) {
if ($tid != QUESSECTIONTEXT) {
if ($question->is_numbered()) {
$qnumber = '<div class="qn-info"><h2 class="qn-number">'.$qnum.'</h2></div>';
} else {
} else {
$qnumber = '';
}
}

if ($this->moveq && $pos < $moveqposition) {
Expand Down
22 changes: 22 additions & 0 deletions classes/responsetype/slider.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,26 @@ public static function response_answers_by_question($rid) {
}
return $answers;
}

/**
* Provide the feedback scores for all requested response id's. This should be provided only by questions that provide feedback.
* @param array $rids
* @return array | boolean
*/
public function get_feedback_scores(array $rids) {
global $DB;
$rsql = '';
$params = [$this->question->id];
if (!empty($rids)) {
list($rsql, $rparams) = $DB->get_in_or_equal($rids);
$params = array_merge($params, $rparams);
$rsql = ' AND response_id ' . $rsql;
}
$sql = 'SELECT response_id as rid, response AS score ' .
'FROM {'.$this->response_table().'} r ' .
'WHERE r.question_id= ? ' . $rsql . ' ' .
'ORDER BY response_id ASC';
return $DB->get_records_sql($sql, $params);
}

}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "PoetOS/moodle-mod_questionnaire",
"name": "poetos/moodle-mod_questionnaire",
"type": "moodle-mod",
"require": {
"composer/installers": "~1.0"
Expand Down
2 changes: 1 addition & 1 deletion db/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

$functions = [
'mod_questionnaire_submit_questionnaire_response' => [
'classname' => 'mod_questionnaire_external',
'classname' => 'mod_questionnaire\external',
'methodname' => 'submit_questionnaire_response',
'classpath' => 'mod/questionnaire/externallib.php',
'description' => 'Questionnaire submit',
Expand Down
5 changes: 5 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,11 @@ function xmldb_questionnaire_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2022092200, 'questionnaire');
}

if ($oldversion < 2022121600.02) {
// Upgrade for downloadoptions - useridentityfields setting.
upgrade_mod_savepoint(true, 2022121600.02, 'questionnaire');
}

return true;
}

Expand Down
18 changes: 10 additions & 8 deletions externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@
* @since Moodle 3.0
*/

use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
namespace mod_questionnaire;


defined('MOODLE_INTERNAL') || die;
require_once($CFG->libdir . '/externallib.php');

use external_api;
use external_function_parameters;
use external_single_structure;
use external_multiple_structure;
use external_value;
use external_warnings;

require_once($CFG->dirroot . '/mod/questionnaire/lib.php');
require_once($CFG->dirroot . '/mod/questionnaire/questionnaire.class.php');

Expand All @@ -45,7 +47,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.0
*/
class mod_questionnaire_external extends external_api {
class external extends external_api {

/**
* Describes the parameters for submit_questionnaire_response.
Expand Down
3 changes: 2 additions & 1 deletion lang/en/questionnaire.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@
$string['feedbacknotes_help'] = 'Text entered here will be displayed to the respondents at the end of their Feedback Report';
$string['feedbackoptions'] = 'Feedback options';
$string['feedbackoptions_help'] = 'Feedback options are available if your questionnaire contains the following question types and question settings:
Radio buttons; Dropdown box; Yes/No; or Rate (normal or Osgood scale). Those questions must be set as Required, their Question Name field must NOT be empty and the Possible answers choices must contain a value.';
Radio buttons; Dropdown box; Yes/No; Rate (normal or Osgood scale) or Slider. Those questions must be set as Required, their Question Name field must NOT be empty and the Possible answers choices must contain a value.
Slider questions must NOT use a negative value for the Minimum slider range.';
$string['feedbackoptions_link'] = 'mod/questionnaire/personality_test';
$string['feedbackremovequestionfromsection'] = 'This question is part of feedback section [{$a}]';
$string['feedbackremovesection'] = 'Removing this question will completely remove feedback section [{$a}]';
Expand Down
7 changes: 7 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@ function questionnaire_get_coursemodule_info($coursemodule) {

$info = new cached_cm_info();
$info->customdata = (object)[];

if ($coursemodule->showdescription) {
// Convert intro to html. Do not filter cached version, filters run at display time.
// Based on the function quiz_get_coursemodule_info() in the quiz module.
$info->content = format_module_intro('questionnaire', $questionnaire, $coursemodule->id, false);
}

// Populate the custom completion rules as key => value pairs, but only if the completion mode is 'automatic'.
if ($coursemodule->completion == COMPLETION_TRACKING_AUTOMATIC) {
$info->customdata->customcompletionrules['completionsubmit'] = $questionnaire->completionsubmit;
Expand Down
Loading

0 comments on commit 4bf5aec

Please sign in to comment.