MDL-30811 forum: Update use of redirect to include message and type

This commit is contained in:
Andrew Nicols 2016-02-16 09:22:17 +08:00
parent 3ad964190c
commit d954b54f9e
7 changed files with 127 additions and 73 deletions

View File

@ -174,8 +174,13 @@ foreach ($modinfo->get_instances_of('forum') as $forumid=>$cm) {
// Do course wide subscribe/unsubscribe if requested
if (!is_null($subscribe)) {
if (isguestuser() or !$can_subscribe) {
// there should not be any links leading to this place, just redirect
redirect(new moodle_url('/mod/forum/index.php', array('id' => $id)), get_string('subscribeenrolledonly', 'forum'));
// There should not be any links leading to this place, just redirect.
redirect(
new moodle_url('/mod/forum/index.php', array('id' => $id)),
get_string('subscribeenrolledonly', 'forum'),
null,
\core\output\notification::NOTIFY_ERROR
);
}
// Can proceed now, the user is not guest and is enrolled
foreach ($modinfo->get_instances_of('forum') as $forumid=>$cm) {
@ -204,9 +209,19 @@ if (!is_null($subscribe)) {
$returnto = forum_go_back_to(new moodle_url('/mod/forum/index.php', array('id' => $course->id)));
$shortname = format_string($course->shortname, true, array('context' => context_course::instance($course->id)));
if ($subscribe) {
redirect($returnto, get_string('nowallsubscribed', 'forum', $shortname), 1);
redirect(
$returnto,
get_string('nowallsubscribed', 'forum', $shortname),
null,
\core\output\notification::NOTIFY_SUCCESS
);
} else {
redirect($returnto, get_string('nowallunsubscribed', 'forum', $shortname), 1);
redirect(
$returnto,
get_string('nowallunsubscribed', 'forum', $shortname),
null,
\core\output\notification::NOTIFY_SUCCESS
);
}
}

View File

@ -75,4 +75,4 @@ if ($backtoindex) {
$returnto = "view.php?f={$id}";
}
redirect($returnto, $updatemessage, 1);
redirect($returnto, $updatemessage, null, \core\output\notification::NOTIFY_SUCCESS);

View File

@ -740,11 +740,6 @@ if ($mform_post->is_cancelled()) {
$DB->update_record("forum", $forum);
}
$timemessage = 2;
if (!empty($message)) { // if we're printing stuff about the file upload
$timemessage = 4;
}
if ($realpost->userid == $USER->id) {
$message .= '<br />'.get_string("postupdated", "forum");
} else {
@ -752,9 +747,7 @@ if ($mform_post->is_cancelled()) {
$message .= '<br />'.get_string("editedpostupdated", "forum", fullname($realuser));
}
if ($subscribemessage = forum_post_subscription($fromform, $forum, $discussion)) {
$timemessage = 4;
}
$subscribemessage = forum_post_subscription($fromform, $forum, $discussion);
if ($forum->type == 'single') {
// Single discussion forums are an exception. We show
// the forum itself since it only has one discussion
@ -782,10 +775,12 @@ if ($mform_post->is_cancelled()) {
$event->add_record_snapshot('forum_discussions', $discussion);
$event->trigger();
redirect(forum_go_back_to($discussionurl), $message.$subscribemessage, $timemessage);
exit;
redirect(
forum_go_back_to($discussionurl),
$message . $subscribemessage,
null,
\core\output\notification::NOTIFY_SUCCESS
);
} else if ($fromform->discussion) { // Adding a new post to an existing discussion
// Before we add this we must check that the user will not exceed the blocking threshold.
@ -796,18 +791,10 @@ if ($mform_post->is_cancelled()) {
$addpost = $fromform;
$addpost->forum=$forum->id;
if ($fromform->id = forum_add_new_post($addpost, $mform_post, $message)) {
$timemessage = 2;
if (!empty($message)) { // if we're printing stuff about the file upload
$timemessage = 4;
}
if ($subscribemessage = forum_post_subscription($fromform, $forum, $discussion)) {
$timemessage = 4;
}
$subscribemessage = forum_post_subscription($fromform, $forum, $discussion);
if (!empty($fromform->mailnow)) {
$message .= get_string("postmailnow", "forum");
$timemessage = 4;
} else {
$message .= '<p>'.get_string("postaddedsuccess", "forum") . '</p>';
$message .= '<p>'.get_string("postaddedtimeleft", "forum", format_time($CFG->maxeditingtime)) . '</p>';
@ -843,7 +830,12 @@ if ($mform_post->is_cancelled()) {
$completion->update_state($cm,COMPLETION_COMPLETE);
}
redirect(forum_go_back_to($discussionurl), $message.$subscribemessage, $timemessage);
redirect(
forum_go_back_to($discussionurl),
$message . $subscribemessage,
null,
\core\output\notification::NOTIFY_SUCCESS
);
} else {
print_error("couldnotadd", "forum", $errordestination);
@ -924,22 +916,14 @@ if ($mform_post->is_cancelled()) {
$event->add_record_snapshot('forum_discussions', $discussion);
$event->trigger();
$timemessage = 2;
if (!empty($message)) { // If we're printing stuff about the file upload.
$timemessage = 4;
}
if ($fromform->mailnow) {
$message .= get_string("postmailnow", "forum");
$timemessage = 4;
} else {
$message .= '<p>'.get_string("postaddedsuccess", "forum") . '</p>';
$message .= '<p>'.get_string("postaddedtimeleft", "forum", format_time($CFG->maxeditingtime)) . '</p>';
}
if ($subscribemessage = forum_post_subscription($fromform, $forum, $discussion)) {
$timemessage = 6;
}
$subscribemessage = forum_post_subscription($fromform, $forum, $discussion);
} else {
print_error("couldnotadd", "forum", $errordestination);
}
@ -953,7 +937,12 @@ if ($mform_post->is_cancelled()) {
}
// Redirect back to the discussion.
redirect(forum_go_back_to($redirectto->out()), $message . $subscribemessage, $timemessage);
redirect(
forum_go_back_to($redirectto->out()),
$message . $subscribemessage,
null,
\core\output\notification::NOTIFY_SUCCESS
);
}
}

View File

@ -99,8 +99,13 @@ if (is_null($mode) and !is_enrolled($context, $USER, '', true)) { // Guests an
echo $OUTPUT->footer();
exit;
} else {
// there should not be any links leading to this place, just redirect
redirect(new moodle_url('/mod/forum/view.php', array('f'=>$id)), get_string('subscribeenrolledonly', 'forum'));
// There should not be any links leading to this place, just redirect.
redirect(
new moodle_url('/mod/forum/view.php', array('f'=>$id)),
get_string('subscribeenrolledonly', 'forum'),
null,
\core\output\notification::NOTIFY_ERROR
);
}
}
@ -117,11 +122,21 @@ if (!is_null($mode) and has_capability('mod/forum:managesubscriptions', $context
switch ($mode) {
case FORUM_CHOOSESUBSCRIBE : // 0
\mod_forum\subscriptions::set_subscription_mode($forum->id, FORUM_CHOOSESUBSCRIBE);
redirect($returnto, get_string("everyonecannowchoose", "forum"), 1);
redirect(
$returnto,
get_string('everyonecannowchoose', 'forum'),
null,
\core\output\notification::NOTIFY_SUCCESS
);
break;
case FORUM_FORCESUBSCRIBE : // 1
\mod_forum\subscriptions::set_subscription_mode($forum->id, FORUM_FORCESUBSCRIBE);
redirect($returnto, get_string("everyoneisnowsubscribed", "forum"), 1);
redirect(
$returnto,
get_string('everyoneisnowsubscribed', 'forum'),
null,
\core\output\notification::NOTIFY_SUCCESS
);
break;
case FORUM_INITIALSUBSCRIBE : // 2
if ($forum->forcesubscribe <> FORUM_INITIALSUBSCRIBE) {
@ -131,11 +146,21 @@ if (!is_null($mode) and has_capability('mod/forum:managesubscriptions', $context
}
}
\mod_forum\subscriptions::set_subscription_mode($forum->id, FORUM_INITIALSUBSCRIBE);
redirect($returnto, get_string("everyoneisnowsubscribed", "forum"), 1);
redirect(
$returnto,
get_string('everyoneisnowsubscribed', 'forum'),
null,
\core\output\notification::NOTIFY_SUCCESS
);
break;
case FORUM_DISALLOWSUBSCRIBE : // 3
\mod_forum\subscriptions::set_subscription_mode($forum->id, FORUM_DISALLOWSUBSCRIBE);
redirect($returnto, get_string("noonecansubscribenow", "forum"), 1);
redirect(
$returnto,
get_string('noonecansubscribenow', 'forum'),
null,
\core\output\notification::NOTIFY_SUCCESS
);
break;
default:
print_error(get_string('invalidforcesubscribe', 'forum'));
@ -143,7 +168,12 @@ if (!is_null($mode) and has_capability('mod/forum:managesubscriptions', $context
}
if (\mod_forum\subscriptions::is_forcesubscribed($forum)) {
redirect($returnto, get_string("everyoneisnowsubscribed", "forum"), 1);
redirect(
$returnto,
get_string('everyoneisnowsubscribed', 'forum'),
null,
\core\output\notification::NOTIFY_SUCCESS
);
}
$info = new stdClass();
@ -174,14 +204,24 @@ if ($issubscribed) {
require_sesskey();
if ($discussionid === null) {
if (\mod_forum\subscriptions::unsubscribe_user($user->id, $forum, $context, true)) {
redirect($returnto, get_string("nownotsubscribed", "forum", $info), 1);
redirect(
$returnto,
get_string('nownotsubscribed', 'forum', $info),
null,
\core\output\notification::NOTIFY_SUCCESS
);
} else {
print_error('cannotunsubscribe', 'forum', get_local_referer(false));
}
} else {
if (\mod_forum\subscriptions::unsubscribe_user_from_discussion($user->id, $discussion, $context)) {
$info->discussion = $discussion->name;
redirect($returnto, get_string("discussionnownotsubscribed", "forum", $info), 1);
redirect(
$returnto,
get_string('discussionnownotsubscribed', 'forum', $info),
null,
\core\output\notification::NOTIFY_SUCCESS
);
} else {
print_error('cannotunsubscribe', 'forum', get_local_referer(false));
}
@ -217,10 +257,20 @@ if ($issubscribed) {
require_sesskey();
if ($discussionid == null) {
\mod_forum\subscriptions::subscribe_user($user->id, $forum, $context, true);
redirect($returnto, get_string("nowsubscribed", "forum", $info), 1);
redirect(
$returnto,
get_string('nowsubscribed', 'forum', $info),
null,
\core\output\notification::NOTIFY_SUCCESS
);
} else {
$info->discussion = $discussion->name;
\mod_forum\subscriptions::subscribe_user_to_discussion($user->id, $discussion, $context);
redirect($returnto, get_string("discussionnowsubscribed", "forum", $info), 1);
redirect(
$returnto,
get_string('discussionnowsubscribed', 'forum', $info),
null,
\core\output\notification::NOTIFY_SUCCESS
);
}
}

View File

@ -39,27 +39,27 @@ Feature: A user can control their own subscription preferences for a discussion
And "You are not subscribed to this discussion. Click to subscribe." "link" should exist in the "Test post subject one" "table_row"
And "You are not subscribed to this discussion. Click to subscribe." "link" should exist in the "Test post subject two" "table_row"
And I click on "You are not subscribed to this discussion. Click to subscribe." "link" in the "Test post subject one" "table_row"
And I follow "Continue"
And I should see "Student One will be notified of new posts in 'Test post subject one' of 'Test forum name'"
And I should see "Subscribe to this forum"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject one" "table_row"
And "You are not subscribed to this discussion. Click to subscribe." "link" should exist in the "Test post subject two" "table_row"
And I click on "You are subscribed to this discussion. Click to unsubscribe." "link" in the "Test post subject one" "table_row"
And I follow "Continue"
And I should see "Student One will NOT be notified of new posts in 'Test post subject one' of 'Test forum name'"
And I should see "Subscribe to this forum"
And "You are not subscribed to this discussion. Click to subscribe." "link" should exist in the "Test post subject one" "table_row"
And "You are not subscribed to this discussion. Click to subscribe." "link" should exist in the "Test post subject two" "table_row"
And I click on "You are not subscribed to this discussion. Click to subscribe." "link" in the "Test post subject one" "table_row"
And I follow "Continue"
And I should see "Student One will be notified of new posts in 'Test post subject one' of 'Test forum name'"
And I should see "Subscribe to this forum"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject one" "table_row"
And "You are not subscribed to this discussion. Click to subscribe." "link" should exist in the "Test post subject two" "table_row"
And I follow "Subscribe to this forum"
And I follow "Continue"
And I should see "Student One will be notified of new posts in 'Test forum name'"
And I should see "Unsubscribe from this forum"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject one" "table_row"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject two" "table_row"
And I follow "Unsubscribe from this forum"
And I follow "Continue"
And I should see "Student One will NOT be notified of new posts in 'Test forum name'"
And I should see "Subscribe to this forum"
And "You are not subscribed to this discussion. Click to subscribe." "link" should exist in the "Test post subject one" "table_row"
And "You are not subscribed to this discussion. Click to subscribe." "link" should exist in the "Test post subject two" "table_row"
@ -84,27 +84,27 @@ Feature: A user can control their own subscription preferences for a discussion
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject one" "table_row"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject two" "table_row"
And I click on "You are subscribed to this discussion. Click to unsubscribe." "link" in the "Test post subject one" "table_row"
And I follow "Continue"
And I should see "Student One will NOT be notified of new posts in 'Test post subject one' of 'Test forum name'"
And I should see "Unsubscribe from this forum"
And "You are not subscribed to this discussion. Click to subscribe." "link" should exist in the "Test post subject one" "table_row"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject two" "table_row"
And I click on "You are not subscribed to this discussion. Click to subscribe." "link" in the "Test post subject one" "table_row"
And I follow "Continue"
And I should see "Student One will be notified of new posts in 'Test post subject one' of 'Test forum name'"
And I should see "Unsubscribe from this forum"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject one" "table_row"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject two" "table_row"
And I click on "You are subscribed to this discussion. Click to unsubscribe." "link" in the "Test post subject one" "table_row"
And I follow "Continue"
And I should see "Student One will NOT be notified of new posts in 'Test post subject one' of 'Test forum name'"
And I should see "Unsubscribe from this forum"
And "You are not subscribed to this discussion. Click to subscribe." "link" should exist in the "Test post subject one" "table_row"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject two" "table_row"
And I follow "Unsubscribe from this forum"
And I follow "Continue"
And I should see "Student One will NOT be notified of new posts in 'Test forum name'"
And I should see "Subscribe to this forum"
And "You are not subscribed to this discussion. Click to subscribe." "link" should exist in the "Test post subject one" "table_row"
And "You are not subscribed to this discussion. Click to subscribe." "link" should exist in the "Test post subject two" "table_row"
And I follow "Subscribe to this forum"
And I follow "Continue"
And I should see "Student One will be notified of new posts in 'Test forum name'"
And I should see "Unsubscribe from this forum"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject one" "table_row"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject two" "table_row"
@ -129,7 +129,7 @@ Feature: A user can control their own subscription preferences for a discussion
And "You are not subscribed to this discussion. Click to subscribe." "link" should exist in the "Test post subject one" "table_row"
And "You are not subscribed to this discussion. Click to subscribe." "link" should exist in the "Test post subject two" "table_row"
And I click on "You are not subscribed to this discussion. Click to subscribe." "link" in the "Test post subject one" "table_row"
And I follow "Continue"
And I should see "Student One will be notified of new posts in 'Test post subject one' of 'Test forum name'"
And I should see "Subscribe to this forum"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject one" "table_row"
And "You are not subscribed to this discussion. Click to subscribe." "link" should exist in the "Test post subject two" "table_row"
@ -150,8 +150,8 @@ Feature: A user can control their own subscription preferences for a discussion
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject one" "table_row"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject two" "table_row"
When I follow "Unsubscribe from this forum"
And I follow "Continue"
Then I should see "Subscribe to this forum"
Then I should see "Student One will NOT be notified of new posts in 'Test forum name'"
And I should see "Subscribe to this forum"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject one" "table_row"
And "You are not subscribed to this discussion. Click to subscribe." "link" should exist in the "Test post subject two" "table_row"
@ -175,7 +175,7 @@ Feature: A user can control their own subscription preferences for a discussion
And "You are not subscribed to this discussion. Click to subscribe." "link" should exist in the "Test post subject one" "table_row"
And "You are not subscribed to this discussion. Click to subscribe." "link" should exist in the "Test post subject two" "table_row"
And I click on "You are not subscribed to this discussion. Click to subscribe." "link" in the "Test post subject one" "table_row"
And I follow "Continue"
And I should see "Student One will be notified of new posts in 'Test post subject one' of 'Test forum name'"
And I should see "Subscribe to this forum"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject one" "table_row"
And "You are not subscribed to this discussion. Click to subscribe." "link" should exist in the "Test post subject two" "table_row"
@ -196,7 +196,7 @@ Feature: A user can control their own subscription preferences for a discussion
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject one" "table_row"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject two" "table_row"
When I follow "Unsubscribe from this forum"
And I follow "Continue"
And I should see "Student One will NOT be notified of new posts in 'Test forum name'"
Then I should see "Subscribe to this forum"
And "You are subscribed to this discussion. Click to unsubscribe." "link" should exist in the "Test post subject one" "table_row"
And "You are not subscribed to this discussion. Click to subscribe." "link" should exist in the "Test post subject two" "table_row"
@ -325,31 +325,31 @@ Feature: A user can control their own subscription preferences for a discussion
Then I should see "Subscribe to this forum"
And I should see "Subscribe to this discussion"
And I follow "Subscribe to this forum"
And I follow "Continue"
And I should see "Student One will be notified of new posts in 'Test forum name'"
And I follow "Test post subject one"
And I should see "Unsubscribe from this forum"
And I should see "Unsubscribe from this discussion"
And I follow "Unsubscribe from this discussion"
And I follow "Continue"
And I should see "Student One will NOT be notified of new posts in 'Test post subject one' of 'Test forum name'"
And I follow "Test post subject one"
And I should see "Unsubscribe from this forum"
And I should see "Subscribe to this discussion"
And I follow "Unsubscribe from this forum"
And I follow "Continue"
And I should see "Student One will NOT be notified of new posts in 'Test forum name'"
And I follow "Test post subject one"
And I should see "Subscribe to this forum"
And I should see "Subscribe to this discussion"
And I follow "Subscribe to this discussion"
And I follow "Continue"
And I should see "Student One will be notified of new posts in 'Test post subject one' of 'Test forum name'"
And I should see "Subscribe to this forum"
And I should see "Unsubscribe from this discussion"
And I follow "Subscribe to this forum"
And I follow "Continue"
And I should see "Student One will be notified of new posts in 'Test forum name'"
And I follow "Test post subject one"
And I should see "Unsubscribe from this forum"
And I should see "Unsubscribe from this discussion"
And I follow "Unsubscribe from this forum"
And I follow "Continue"
And I should see "Student One will NOT be notified of new posts in 'Test forum name'"
And I follow "Test post subject one"
And I should see "Subscribe to this forum"
And I should see "Subscribe to this discussion"

View File

@ -71,7 +71,7 @@ Feature: A user can control their own subscription preferences for a forum
Then I should see "Subscribe to this forum"
And I should not see "Unsubscribe from this forum"
And I follow "Subscribe to this forum"
And I follow "Continue"
And I should see "Student One will be notified of new posts in 'Test forum name'"
And I should see "Unsubscribe from this forum"
And I should not see "Subscribe to this forum"
@ -91,6 +91,6 @@ Feature: A user can control their own subscription preferences for a forum
Then I should see "Unsubscribe from this forum"
And I should not see "Subscribe to this forum"
And I follow "Unsubscribe from this forum"
And I follow "Continue"
And I should see "Student One will NOT be notified of new posts in 'Test forum name'"
And I should see "Subscribe to this forum"
And I should not see "Unsubscribe from this forum"

View File

@ -121,7 +121,7 @@ Feature: A user can control their default discussion subscription settings
And I follow "Course 1"
And I follow "Test forum name"
And I click on "You are subscribed to this discussion. Click to unsubscribe." "link" in the "Test post subject" "table_row"
And I follow "Continue"
And I should see "Student One will NOT be notified of new posts in 'Test post subject' of 'Test forum name'"
And I follow "Test post subject"
When I follow "Reply"
And "input[name=discussionsubscribe][checked=checked]" "css_element" should exist
@ -130,7 +130,7 @@ Feature: A user can control their default discussion subscription settings
And I follow "Course 1"
And I follow "Test forum name"
And I click on "You are subscribed to this discussion. Click to unsubscribe." "link" in the "Test post subject" "table_row"
And I follow "Continue"
And I should see "Student Two will NOT be notified of new posts in 'Test post subject' of 'Test forum name'"
And I follow "Test post subject"
And I follow "Reply"
And "input[name=discussionsubscribe]:not([checked=checked])" "css_element" should exist