Skip to content

Commit

Permalink
GHI172 - Choice values can be the empty string if they are old questi…
Browse files Browse the repository at this point in the history
…onnaires.
  • Loading branch information
Mike Churchward committed Feb 7, 2019
1 parent d463b52 commit 6a4a531
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions backup/moodle2/restore_questionnaire_stepslib.php
Expand Up @@ -214,6 +214,11 @@ protected function process_questionnaire_quest_choice($data) {
// This fixes radio button options using old "value"="display" formats.
require_once($CFG->dirroot.'/mod/questionnaire/locallib.php');

// Some old systems had '' instead of NULL. Change it to NULL.
if ($data->value === '') {
$data->value = null;
}

if (($data->value == null || $data->value == 'NULL') && !preg_match("/^([0-9]{1,3}=.*|!other=.*)$/", $data->content)) {
$content = questionnaire_choice_values($data->content);
if (strpos($content->text, '=')) {
Expand Down
4 changes: 2 additions & 2 deletions classes/response/rank.php
Expand Up @@ -97,7 +97,7 @@ public function get_results($rids=false, $anonymous=false) {

if ($this->question->type_id == QUESRATE) {
// JR there can't be an !other field in rating questions ???
$rankvalue = array();
$rankvalue = [];
$select = 'question_id=' . $this->question->id . ' AND content NOT LIKE \'!other%\' ORDER BY id ASC';
if ($rows = $DB->get_records_select('questionnaire_quest_choice', $select)) {
foreach ($rows as $row) {
Expand All @@ -106,7 +106,7 @@ public function get_results($rids=false, $anonymous=false) {
'choice_id' => $row->id, 'rankvalue' => '-1'));
$this->counts[$row->content]->nbna = $nbna;
// The $row->value may be null (i.e. empty) or have a 'NULL' value.
if ($row->value !== null && $row->value !== 'NULL') {
if (($row->value !== null) && ($row->value !== 'NULL') && ($row->value !== '')) {
$rankvalue[] = $row->value;
}
}
Expand Down

0 comments on commit 6a4a531

Please sign in to comment.