Skip to content

Commit 45705b6

Browse files
author
Emanoil Manoylov
committed
Incomplete responses show -999 on downloaded report OU 980876
1 parent c2a4c6e commit 45705b6

File tree

7 files changed

+30
-23
lines changed

7 files changed

+30
-23
lines changed

classes/question/question.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
define('QUESFILE', 12);
4747
define('QUESPAGEBREAK', 99);
4848
define('QUESSECTIONTEXT', 100);
49+
define('QUESRATEUNANSWERED', -999);
4950

5051
global $idcounter, $CFG;
5152
$idcounter = 0;

classes/question/rate.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ protected function question_survey_display($response, $descendantsdata, $blankqu
315315

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

321322
$notcomplete = false;
@@ -361,13 +362,13 @@ protected function question_survey_display($response, $descendantsdata, $blankqu
361362
$title = '';
362363
if (
363364
$notcomplete && isset($response->answers[$this->id][$cid]) &&
364-
($response->answers[$this->id][$cid]->value == -999)
365+
$response->answers[$this->id][$cid]->value == QUESRATEUNANSWERED
365366
) {
366367
$completeclass = 'notcompleted';
367368
$title = get_string('pleasecomplete', 'questionnaire');
368369
}
369-
// Set value of notanswered button to -999 in order to eliminate it from form submit later on.
370-
$colinput = ['name' => $str, 'value' => -999];
370+
// Set value of notanswered button in order to eliminate it from form submit later on.
371+
$colinput = ['name' => $str, 'value' => QUESRATEUNANSWERED];
371372
if (!empty($checked)) {
372373
$colinput['checked'] = true;
373374
}
@@ -624,8 +625,8 @@ public function response_complete($responsedata) {
624625
if (isset($answers[$cid]) && !empty($answers[$cid]) && ($answers[$cid]->value == $na)) {
625626
$answers[$cid]->value = -1;
626627
}
627-
// If choice value == -999 this is a not yet answered choice.
628-
$num += (isset($answers[$cid]) && ($answers[$cid]->value != -999));
628+
// Ignore if value means this is a not yet answered choice.
629+
$num += (isset($answers[$cid]) && $answers[$cid]->value != QUESRATEUNANSWERED);
629630
}
630631
$nbchoices -= $nameddegrees;
631632
}
@@ -675,8 +676,8 @@ public function response_valid($responsedata) {
675676
if (isset($answers[$cid]) && ($answers[$cid]->value == $na)) {
676677
$answers[$cid]->value = -1;
677678
}
678-
// If choice value == -999 this is a not yet answered choice.
679-
$num += (isset($answers[$cid]) && ($answers[$cid]->value != -999));
679+
// Ignore if value means this is a not yet answered choice.
680+
$num += (isset($answers[$cid]) && $answers[$cid]->value != QUESRATEUNANSWERED);
680681
}
681682
$nbchoices -= $nameddegrees;
682683
}

questionnaire.class.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,7 +2450,8 @@ private function get_full_submission_for_export($rid) {
24502450
} else {
24512451
$rating = $this->responses[$rid]->answers[$question->id][$cid]->value;
24522452
}
2453-
$response->answers[] = $question->choices[$cid]->content . ' = ' . $rating;
2453+
$response->answers[] = $question->choices[$cid]->content . ' = ' .
2454+
($rating != QUESRATEUNANSWERED ? $rating : '');
24542455
}
24552456
}
24562457
}
@@ -3473,7 +3474,8 @@ protected function process_csv_row(
34733474

34743475
for ($c = $nbinfocols; $c < $numrespcols; $c++) {
34753476
if (isset($row[$c])) {
3476-
$positioned[] = $row[$c];
3477+
// Ignore if value means this is a not yet answered choice.
3478+
$positioned[] = $row[$c] != QUESRATEUNANSWERED ? $row[$c] : null;
34773479
} else if (isset($questionsbyposition[$c])) {
34783480
$question = $questionsbyposition[$c];
34793481
$qtype = intval($question->type_id);

tests/behat/behat_mod_questionnaire.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,11 +448,11 @@ private function add_response_data($qid, $sid) {
448448
["", "6", "13", "18", "-1"],
449449
["", "6", "13", "19", "1"],
450450
["", "6", "13", "20", "-1"],
451-
["", "7", "13", "16", "-999"],
452-
["", "7", "13", "17", "-999"],
453-
["", "7", "13", "18", "-999"],
454-
["", "7", "13", "19", "-999"],
455-
["", "7", "13", "20", "-999"],
451+
["", "7", "13", "16", QUESRATEUNANSWERED],
452+
["", "7", "13", "17", QUESRATEUNANSWERED],
453+
["", "7", "13", "18", QUESRATEUNANSWERED],
454+
["", "7", "13", "19", QUESRATEUNANSWERED],
455+
["", "7", "13", "20", QUESRATEUNANSWERED],
456456
];
457457
$this->add_data(
458458
$responserank,

tests/csvexport_test.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,19 @@ public function test_csvexport(): void {
7676
$questionnaireinst = new \questionnaire($course, $cm, 0, $questionnaire);
7777

7878
// Test for only complete responses.
79+
$expectedoutput = $this->expected_complete_output();
7980
$newoutput = $this->get_csv_text($questionnaireinst->generate_csv(0, '', '', 0, 0, 0));
80-
$this->assertEquals(count($newoutput), count($this->expected_complete_output()));
81+
$this->assertEquals(count($newoutput), count($expectedoutput));
8182
foreach ($newoutput as $key => $output) {
82-
$this->assertEquals($this->expected_complete_output()[$key], $output);
83+
$this->assertEquals($expectedoutput[$key], $output, "Output #$key");
8384
}
8485

8586
// Test for all responses.
87+
$expectedoutput = $this->expected_incomplete_output();
8688
$newoutput = $this->get_csv_text($questionnaireinst->generate_csv(0, '', '', 0, 0, 1));
87-
$this->assertEquals(count($newoutput), count($this->expected_incomplete_output()));
89+
$this->assertEquals(count($newoutput), count($expectedoutput));
8890
foreach ($newoutput as $key => $output) {
89-
$this->assertEquals($this->expected_incomplete_output()[$key], $output);
91+
$this->assertEquals($expectedoutput[$key], $output, "Output #$key");
9092
}
9193
}
9294
}
@@ -243,6 +245,6 @@ private function expected_incomplete_output() {
243245
" Test course 1 Testy Lastname4 username4 y Test answer Some header textSome paragraph text 83 " .
244246
"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",
245247
" Test course 1 Testy Lastname5 username5 n Test answer Some header textSome paragraph text 83 " .
246-
"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"];
248+
"27/12/2017 wind three 0 0 0 0 0 0 0 0 0 1 5"];
247249
}
248250
}

tests/generator/lib.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,8 @@ public function generate_response($questionnaire, $questions, $userid, $complete
661661
case QUESRATE:
662662
$answers = [];
663663
for ($a = 0; $a < count($choices) - 1; $a++) {
664-
$answers[] = new question_response_rank($choices[$a], (($a % 5) + 1));
664+
$rank = $complete ? (($a % 5) + 1) : QUESRATEUNANSWERED;
665+
$answers[] = new question_response_rank($choices[$a], $rank);
665666
}
666667
$responses[] = new question_response($question->id, $answers);
667668
break;

tests/privacy_provider_test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ public function test_export_user_data(): void {
138138
$this->assertEquals('7. Numeric 1004', $data->responses[0]['questions'][7]->questionname);
139139
$this->assertEquals(83, $data->responses[0]['questions'][7]->answers[0]);
140140
$this->assertEquals('22. Rate Scale 1014', $data->responses[0]['questions'][22]->questionname);
141-
$this->assertEquals('fourteen = 1', $data->responses[0]['questions'][22]->answers[0]);
142-
$this->assertEquals('happy = 3', $data->responses[0]['questions'][22]->answers[7]);
141+
$this->assertEquals('fourteen = ', $data->responses[0]['questions'][22]->answers[0]);
142+
$this->assertEquals('happy = ', $data->responses[0]['questions'][22]->answers[7]);
143143
}
144144

145145
/**

0 commit comments

Comments
 (0)