Skip to content
Snippets Groups Projects
Commit a67ebcff authored by Friederike Schwager's avatar Friederike Schwager Committed by Friederike Schwager
Browse files

forward: error if there are no recipients

parent 685d0e1c
Branches
No related tags found
No related merge requests found
......@@ -41,6 +41,7 @@ if ($action === 'forwardquestion') {
global $USER;
$commentid = required_param('commentid', PARAM_INT);
$fromoverview = optional_param('fromoverview', 0, PARAM_INT);
$cminfo = pdfannotator_instance::get_cm_info($cm->course);
// Make sure user is allowed to see cm with the question. (Might happen if user changes commentid in url).
list($insql, $inparams) = $DB->get_in_or_equal(array_keys($cminfo));
......@@ -62,18 +63,34 @@ if ($action === 'forwardquestion') {
}
}
if ($error) { // An error occured e.g. comment doesn't exist.
$info = get_string('error:forwardquestion', 'pdfannotator'); // Display error notification.
echo "<span id='subscriptionPanel' class='usernotifications'><div class='alert alert-success alert-block fade in' role='alert'>$info</div></span>";
$action = 'overviewquestions'; // And go back to overview.
} else {
$possiblerecipients = get_enrolled_users($context, 'mod/pdfannotator:getforwardedquestions');
$recipientslist = [];
foreach ($possiblerecipients as $recipient) {
if ($recipient->id === $USER->id) {
continue;
}
$recipientslist[$recipient->id] = $recipient->firstname . ' ' . $recipient->lastname;
}
if (count($recipientslist) === 0) {
$error = true;
$errorinfo = get_string('error:forwardquestionnorecipient', 'pdfannotator');
}
if ($error) { // An error occured e.g. comment doesn't exist.
if (!isset($errorinfo)) {
$errorinfo = get_string('error:forwardquestion', 'pdfannotator'); // Display error notification.
}
echo "<span id='subscriptionPanel' class='usernotifications'><div class='alert alert-success alert-block fade in' role='alert'>$errorinfo</div></span>";
if ($fromoverview) {
// If user forwarded question from overview go back to overview.
$action = 'overviewquestions';
} else {
// Else go to document.
$action = 'view';
}
} else {
$data = new stdClass();
$data->course = $cm->course;
$data->pdfannotatorid = $cm->instance;
......@@ -107,7 +124,6 @@ if ($action === 'forwardquestion') {
if (isset($data->recipients)) {
send_forward_message($data->recipients, $params, $course, $cm, $context);
}
$fromoverview = optional_param('fromoverview', 0, PARAM_INT);
if ($fromoverview) {
// If user forwarded question from overview go back to overview.
$action = 'overviewquestions';
......@@ -115,7 +131,6 @@ if ($action === 'forwardquestion') {
// Else go to document.
$action = 'view';
}
} else { // Executed if the form is submitted but the data doesn't validate and the form should be redisplayed
// or on the first display of the form.
$PAGE->set_title("forward_form");
......@@ -184,7 +199,6 @@ if ($action === 'subscribeQuestion') {
}
$action = 'overviewanswers';
}
/*
* This section unsubscribes the user from a particular question and then rerenders the overview table of
......@@ -217,7 +231,6 @@ if ($action === 'unsubscribeQuestion') {
echo "<span id='pdfannotator_notificationpanel' class='usernotifications'><div class='alert alert-success alert-block fade in' role='alert'>$info</div></span>";
$action = 'overviewanswers';
}
/*
* This section prints a subpage of overview called 'answers'. It lists all answers to questions the current
......@@ -293,7 +306,6 @@ if ($action === 'overviewownposts') {
* (either unread reports (reportfiler == 0) or all reports (reportfilter == 2)).
*/
if ($action === 'markreportasread') { // XXX Rename key and move it into $action === 'overviewreports'
require_capability('mod/pdfannotator:viewreports', $context);
global $DB;
......@@ -317,21 +329,18 @@ if ($action === 'markreportasread') { // XXX Rename key and move it into $action
$info = get_string('successfullymarkedasread', 'pdfannotator');
}
echo "<span id='pdfannotator_notificationpanel' class='usernotifications'><div class='alert alert-success alert-block fade in' role='alert'>$info</div></span>";
} else {
$info = get_string('error:markasread', 'pdfannotator');
echo "<span id='pdfannotator_notificationpanel' class='usernotifications'><div class='alert alert-error alert-block fade in' role='alert'>$info</div></span>";
}
$action = 'overviewreports'; // This will do the actual rerendering of the page (see below).
}
/*
* This section marks a report as read and then rerenders the overview table of reports
* (either unread reports (reportfiler == 0) or all reports (reportfilter == 2)).
*/
if ($action === 'markreportasunread') { // XXX Rename key and move it into $action === 'overviewreports'
require_capability('mod/pdfannotator:viewreports', $context);
global $DB;
......@@ -355,14 +364,12 @@ if ($action === 'markreportasunread') { // XXX Rename key and move it into $acti
$info = get_string('successfullymarkedasunread', 'pdfannotator');
}
echo "<span id='pdfannotator_notificationpanel' class='usernotifications'><div class='alert alert-success alert-block fade in' role='alert'>$info</div></span>";
} else {
$info = get_string('error:markasunread', 'pdfannotator');
echo "<span id='pdfannotator_notificationpanel' class='usernotifications'><div class='alert alert-error alert-block fade in' role='alert'>$info</div></span>";
}
$action = 'overviewreports'; // This will do the actual rerendering of the page (see below).
}
/*
* This section prints a subpage of overview called "Reports" were comments that were reported as inappropriate are listed.
......@@ -400,7 +407,6 @@ if ($action === 'overviewreports') {
break;
}
echo "<span class='notification'><div class='alert alert-info alert-block fade in' role='alert'>$info</div></span>";
} else {
$urlparams = array('action' => 'overviewreports', 'id' => $cmid, 'page' => $currentpage, 'itemsperpage' => $itemsperpage, 'reportfilter' => $reportfilter);
$url = new moodle_url($CFG->wwwroot . '/mod/pdfannotator/view.php', $urlparams);
......
......@@ -271,6 +271,7 @@ $string['error:putinrecyclebin'] = 'Das Element konnte nicht in den Papierkorb v
$string['error:markasread'] = 'Das Element konnte nicht als gelesen markiert werden.';
$string['error:markasunread'] = 'Das Element konnte nicht als ungelesen markiert werden.';
$string['error:forwardquestion'] = 'Beim Weiterleiten der Frage ist ein Fehler aufgetreten.';
$string['error:forwardquestionnorecipient'] = 'Beim Weiterleiten der Frage ist ein Fehler aufgetreten: In diesem Kurs gibt es keine Person mit dem Recht, weitergeleitete Fragen zu erhalten.';
$string['document'] = 'Dokument';
......
......@@ -351,6 +351,8 @@ $string['error:putinrecyclebin'] = 'The item could not be placed in the recycle
$string['error:markasread'] = 'The item could not be marked as read.';
$string['error:markasunread'] = 'The item could not be marked as unread.';
$string['error:forwardquestion'] = 'An error has occured while forwarding the question.';
$string['error:forwardquestionnorecipient'] = 'An error has occured while forwarding the question.: No person in this course has the capability to receive forwarded questions.';
$string['document'] = 'Document';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment