Skip to content

Commit d466bf3

Browse files
GHI622 Replace deprecated error functions (#660)
Co-authored-by: Mike Churchward <mike.churchward@poetopensource.org>
1 parent 309fa6f commit d466bf3

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

classes/question/question.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ protected function form_preprocess_data($formdata) {
16731673
*/
16741674
protected function form_preprocess_choicedata($formdata) {
16751675
if (empty($formdata->allchoices)) {
1676-
error(get_string('enterpossibleanswers', 'questionnaire'));
1676+
throw new \moodle_exception('enterpossibleanswers', 'mod_questionnaire');
16771677
}
16781678
return false;
16791679
}

lang/en/questionnaire.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
$string['contentoptions'] = 'Content options';
124124
$string['couldnotcreatenewsurvey'] = 'Could not create a new survey!';
125125
$string['couldnotdelresp'] = 'Could not delete response ';
126+
$string['couldnotdelrespby'] = 'Could not delete response {$a->rid} by {$a->user}';
126127
$string['createcontent'] = 'Define New Content';
127128
$string['createcontent_help'] = 'Select one of the radio button options. \'Create new\' is the default.';
128129
$string['createcontent_link'] = 'mod/questionnaire/mod#Content_Options';
@@ -182,6 +183,7 @@
182183
$string['emailsnotspecified'] = 'No email(s) were specified.';
183184
$string['emailssent'] = 'Downloads sent to specified email(s).';
184185
$string['enabled'] = 'Enabled';
186+
$string['enterpossibleanswers'] = 'Enter possible answers';
185187
$string['errnewname'] = 'Sorry, name already in use. Pick a new name.';
186188
$string['erroropening'] = 'Error opening questionnaire.';
187189
$string['errortable'] = 'Error system table corrupt.';

report.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@
220220
require_capability('mod/questionnaire:deleteresponses', $context);
221221

222222
if (empty($questionnaire->survey)) {
223-
$id = $questionnaire->survey;
224-
notify("questionnaire->survey = /$id/");
225223
throw new \moodle_exception('surveynotexists', 'mod_questionnaire');
226224
} else if ($questionnaire->survey->courseid != $course->id) {
227225
throw new \moodle_exception('surveyowner', 'mod_questionnaire');
@@ -366,11 +364,17 @@
366364
} else {
367365
$ruser = $response->userid;
368366
}
369-
error(
370-
get_string('couldnotdelresp', 'questionnaire') .
371-
$rid . get_string('by', 'questionnaire') . $ruser . '?',
372-
$CFG->wwwroot . '/mod/questionnaire/report.php?action=vresp&amp;sid=' . $sid . '&amp;&amp;instance=' .
373-
$instance . 'byresponse=1'
367+
$link = new \moodle_url('/mod/questionnaire/report.php', [
368+
'action' => 'vresp',
369+
'sid' => $sid,
370+
'instance' => $instance,
371+
'byresponse' => '1',
372+
]);
373+
throw new \moodle_exception(
374+
'couldnotdelrespby',
375+
'mod_questionnaire',
376+
$link,
377+
['rid' => $rid, 'user' => $ruser]
374378
);
375379
}
376380
break;
@@ -442,10 +446,12 @@
442446

443447
redirect($redirection);
444448
} else {
445-
error(
446-
get_string('couldnotdelresp', 'questionnaire'),
447-
$CFG->wwwroot . '/mod/questionnaire/report.php?action=vall&amp;sid=' . $sid . '&amp;instance=' . $instance
448-
);
449+
$link = new \moodle_url('/mod/questionnaire/report.php', [
450+
'action' => 'vall',
451+
'sid' => $sid,
452+
'instance' => $instance,
453+
]);
454+
throw new \moodle_exception('couldnotdelresp', 'mod_questionnaire', $link);
449455
}
450456
break;
451457

0 commit comments

Comments
 (0)