Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions classes/question/question.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
define('QUESFILE', 12);
define('QUESPAGEBREAK', 99);
define('QUESSECTIONTEXT', 100);
define('QUESRATEUNANSWERED', -999);

global $idcounter, $CFG;
$idcounter = 0;
Expand Down
17 changes: 9 additions & 8 deletions classes/question/rate.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ protected function question_survey_display($response, $descendantsdata, $blankqu

$num = 0;
foreach ($this->choices as $cid => $choice) {
$num += (isset($response->answers[$this->id][$cid]) && ($response->answers[$this->id][$cid]->value != -999));
$num += (isset($response->answers[$this->id][$cid]) &&
$response->answers[$this->id][$cid]->value != QUESRATEUNANSWERED);
}

$notcomplete = false;
Expand Down Expand Up @@ -361,13 +362,13 @@ protected function question_survey_display($response, $descendantsdata, $blankqu
$title = '';
if (
$notcomplete && isset($response->answers[$this->id][$cid]) &&
($response->answers[$this->id][$cid]->value == -999)
$response->answers[$this->id][$cid]->value == QUESRATEUNANSWERED
) {
$completeclass = 'notcompleted';
$title = get_string('pleasecomplete', 'questionnaire');
}
// Set value of notanswered button to -999 in order to eliminate it from form submit later on.
$colinput = ['name' => $str, 'value' => -999];
// Set value of notanswered button in order to eliminate it from form submit later on.
$colinput = ['name' => $str, 'value' => QUESRATEUNANSWERED];
if (!empty($checked)) {
$colinput['checked'] = true;
}
Expand Down Expand Up @@ -624,8 +625,8 @@ public function response_complete($responsedata) {
if (isset($answers[$cid]) && !empty($answers[$cid]) && ($answers[$cid]->value == $na)) {
$answers[$cid]->value = -1;
}
// If choice value == -999 this is a not yet answered choice.
$num += (isset($answers[$cid]) && ($answers[$cid]->value != -999));
// Ignore if value means this is a not yet answered choice.
$num += (isset($answers[$cid]) && $answers[$cid]->value != QUESRATEUNANSWERED);
}
$nbchoices -= $nameddegrees;
}
Expand Down Expand Up @@ -675,8 +676,8 @@ public function response_valid($responsedata) {
if (isset($answers[$cid]) && ($answers[$cid]->value == $na)) {
$answers[$cid]->value = -1;
}
// If choice value == -999 this is a not yet answered choice.
$num += (isset($answers[$cid]) && ($answers[$cid]->value != -999));
// Ignore if value means this is a not yet answered choice.
$num += (isset($answers[$cid]) && $answers[$cid]->value != QUESRATEUNANSWERED);
}
$nbchoices -= $nameddegrees;
}
Expand Down
6 changes: 4 additions & 2 deletions questionnaire.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2450,7 +2450,8 @@ private function get_full_submission_for_export($rid) {
} else {
$rating = $this->responses[$rid]->answers[$question->id][$cid]->value;
}
$response->answers[] = $question->choices[$cid]->content . ' = ' . $rating;
$response->answers[] = $question->choices[$cid]->content . ' = ' .
($rating != QUESRATEUNANSWERED ? $rating : '');
}
}
}
Expand Down Expand Up @@ -3473,7 +3474,8 @@ protected function process_csv_row(

for ($c = $nbinfocols; $c < $numrespcols; $c++) {
if (isset($row[$c])) {
$positioned[] = $row[$c];
// Ignore if value means this is a not yet answered choice.
$positioned[] = $row[$c] != QUESRATEUNANSWERED ? $row[$c] : null;
} else if (isset($questionsbyposition[$c])) {
$question = $questionsbyposition[$c];
$qtype = intval($question->type_id);
Expand Down
10 changes: 5 additions & 5 deletions tests/behat/behat_mod_questionnaire.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,11 @@ private function add_response_data($qid, $sid) {
["", "6", "13", "18", "-1"],
["", "6", "13", "19", "1"],
["", "6", "13", "20", "-1"],
["", "7", "13", "16", "-999"],
["", "7", "13", "17", "-999"],
["", "7", "13", "18", "-999"],
["", "7", "13", "19", "-999"],
["", "7", "13", "20", "-999"],
["", "7", "13", "16", QUESRATEUNANSWERED],
["", "7", "13", "17", QUESRATEUNANSWERED],
["", "7", "13", "18", QUESRATEUNANSWERED],
["", "7", "13", "19", QUESRATEUNANSWERED],
["", "7", "13", "20", QUESRATEUNANSWERED],
];
$this->add_data(
$responserank,
Expand Down
12 changes: 7 additions & 5 deletions tests/csvexport_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,19 @@ public function test_csvexport(): void {
$questionnaireinst = new \questionnaire($course, $cm, 0, $questionnaire);

// Test for only complete responses.
$expectedoutput = $this->expected_complete_output();
$newoutput = $this->get_csv_text($questionnaireinst->generate_csv(0, '', '', 0, 0, 0));
$this->assertEquals(count($newoutput), count($this->expected_complete_output()));
$this->assertEquals(count($newoutput), count($expectedoutput));
foreach ($newoutput as $key => $output) {
$this->assertEquals($this->expected_complete_output()[$key], $output);
$this->assertEquals($expectedoutput[$key], $output, "Output #$key");
}

// Test for all responses.
$expectedoutput = $this->expected_incomplete_output();
$newoutput = $this->get_csv_text($questionnaireinst->generate_csv(0, '', '', 0, 0, 1));
$this->assertEquals(count($newoutput), count($this->expected_incomplete_output()));
$this->assertEquals(count($newoutput), count($expectedoutput));
foreach ($newoutput as $key => $output) {
$this->assertEquals($this->expected_incomplete_output()[$key], $output);
$this->assertEquals($expectedoutput[$key], $output, "Output #$key");
}
}
}
Expand Down Expand Up @@ -243,6 +245,6 @@ private function expected_incomplete_output() {
" Test course 1 Testy Lastname4 username4 y Test answer Some header textSome paragraph text 83 " .
"27/12/2017 wind three 0 0 0 0 0 0 0 0 0 1 1 2 3 4 5 1 2 3 4 5",
" Test course 1 Testy Lastname5 username5 n Test answer Some header textSome paragraph text 83 " .
"27/12/2017 wind three 0 0 0 0 0 0 0 0 0 1 1 2 3 4 5 1 2 3 4 5"];
"27/12/2017 wind three 0 0 0 0 0 0 0 0 0 1 5"];
}
}
3 changes: 2 additions & 1 deletion tests/generator/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,8 @@ public function generate_response($questionnaire, $questions, $userid, $complete
case QUESRATE:
$answers = [];
for ($a = 0; $a < count($choices) - 1; $a++) {
$answers[] = new question_response_rank($choices[$a], (($a % 5) + 1));
$rank = $complete ? (($a % 5) + 1) : QUESRATEUNANSWERED;
$answers[] = new question_response_rank($choices[$a], $rank);
}
$responses[] = new question_response($question->id, $answers);
break;
Expand Down
4 changes: 2 additions & 2 deletions tests/privacy_provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ public function test_export_user_data(): void {
$this->assertEquals('7. Numeric 1004', $data->responses[0]['questions'][7]->questionname);
$this->assertEquals(83, $data->responses[0]['questions'][7]->answers[0]);
$this->assertEquals('22. Rate Scale 1014', $data->responses[0]['questions'][22]->questionname);
$this->assertEquals('fourteen = 1', $data->responses[0]['questions'][22]->answers[0]);
$this->assertEquals('happy = 3', $data->responses[0]['questions'][22]->answers[7]);
$this->assertEquals('fourteen = ', $data->responses[0]['questions'][22]->answers[0]);
$this->assertEquals('happy = ', $data->responses[0]['questions'][22]->answers[7]);
}

/**
Expand Down