MDL-30811 forum: Update use of redirect to include message and type
[moodle.git] / mod / forum / subscribe.php
index 7bd8414..ab209b0 100644 (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
+            );
     }
 }