Skip to content

Commit dc546b5

Browse files
author
Emanoil Manoylov
committed
Questionnaire: Error when trying to delete a question
1 parent 27a0e45 commit dc546b5

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

locallib.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ function questionnaire_check_page_breaks($questionnaire) {
756756

757757
$dependencies = $DB->get_records('questionnaire_dependency', ['questionid' => $key , 'surveyid' => $sid],
758758
'id ASC', 'id, dependquestionid, dependchoiceid, dependlogic');
759-
$positions[$qu->position]['dependencies'] = $dependencies;
759+
$positions[$qu->position]['dependencies'] = $dependencies ?? [];
760760
}
761761
$count = count($positions);
762762

questions.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
}
7070

7171
$questionnairehasdependencies = $questionnaire->has_dependencies();
72-
$haschildren = [];
72+
$dependants = null;
7373
if (!isset($SESSION->questionnaire)) {
7474
$SESSION->questionnaire = new stdClass();
7575
}
@@ -182,17 +182,16 @@
182182
if ($qtype == QUESPAGEBREAK) {
183183
redirect($CFG->wwwroot.'/mod/questionnaire/questions.php?id='.$questionnaire->cm->id.'&delq='.$qid);
184184
}
185+
186+
$action = "confirmdelquestion";
185187
if ($questionnairehasdependencies) {
186188
// Important: due to possibly multiple parents per question
187189
// just remove the dependency and inform the user about it.
188-
$haschildren = $questionnaire->get_all_dependants($qid);
189-
}
190-
if (count($haschildren) != 0) {
191-
$action = "confirmdelquestionparent";
192-
} else {
193-
$action = "confirmdelquestion";
190+
$dependants = $questionnaire->get_all_dependants($qid);
191+
if (!(empty($dependants->directs) && empty($dependants->indirects))) {
192+
$action = "confirmdelquestionparent";
193+
}
194194
}
195-
196195
} else if (isset($qformdata->editbutton)) {
197196
// Switch to edit question screen.
198197
$action = 'question';
@@ -400,12 +399,14 @@
400399
if ($action == "confirmdelquestionparent") {
401400
$strnum = get_string('position', 'questionnaire');
402401
$qid = key($qformdata->removebutton);
403-
// Show the dependencies and inform about the dependencies to be removed.
404-
// Split dependencies in direct and indirect ones to separate for the confirm-dialogue. Only direct ones will be deleted.
405-
// List direct dependencies.
406-
$msg .= $questionnaire->renderer->dependency_warnings($haschildren->directs, 'directwarnings', $strnum);
407-
// List indirect dependencies.
408-
$msg .= $questionnaire->renderer->dependency_warnings($haschildren->indirects, 'indirectwarnings', $strnum);
402+
if ($dependants) {
403+
// Show the dependencies and inform about the dependencies to be removed.
404+
// Split dependencies in direct and indirect ones to separate for the confirm-dialogue. Only direct ones will be deleted.
405+
// List direct dependencies.
406+
$msg .= $questionnaire->renderer->dependency_warnings($dependants->directs, 'directwarnings', $strnum);
407+
// List indirect dependencies.
408+
$msg .= $questionnaire->renderer->dependency_warnings($dependants->indirects, 'indirectwarnings', $strnum);
409+
}
409410
}
410411
$questionnaire->page->add_to_page('formarea', $questionnaire->renderer->confirm($msg, $buttonyes, $buttonno));
411412

0 commit comments

Comments
 (0)