MDL-65069 mod_forum: Remove unused code and additional dev docs.
[moodle.git] / mod / forum / post.php
index fdea9c0..d01153a 100644 (file)
@@ -720,26 +720,8 @@ $postid = empty($post->id) ? null : $post->id;
 $draftideditor = file_get_submitted_draft_itemid('message');
 $editoropts = mod_forum_post_form::editor_options($modcontext, $postid);
 $currenttext = file_prepare_draft_area($draftideditor, $modcontext->id, 'mod_forum', 'post', $postid, $editoropts, $post->message);
-
-$manageactivities = has_capability('moodle/course:manageactivities', $coursecontext);
-if (\mod_forum\subscriptions::subscription_disabled($forum) && !$manageactivities) {
-    // User does not have permission to subscribe to this discussion at all.
-    $discussionsubscribe = false;
-} else if (\mod_forum\subscriptions::is_forcesubscribed($forum)) {
-    // User does not have permission to unsubscribe from this discussion at all.
-    $discussionsubscribe = true;
-} else {
-    if (isset($discussion) && \mod_forum\subscriptions::is_subscribed($USER->id, $forum, $discussion->id, $cm)) {
-        // User is subscribed to the discussion - continue the subscription.
-        $discussionsubscribe = true;
-    } else if (!isset($discussion) && \mod_forum\subscriptions::is_subscribed($USER->id, $forum, null, $cm)) {
-        // Starting a new discussion, and the user is subscribed to the forum - subscribe to the discussion.
-        $discussionsubscribe = true;
-    } else {
-        // User is not subscribed to either forum or discussion. Follow user preference.
-        $discussionsubscribe = $USER->autosubscribe;
-    }
-}
+$discussionid = isset($discussion) ? $discussion->id : null;
+$discussionsubscribe = \mod_forum\subscriptions::get_user_default_subscription($forum, $coursecontext, $cm, $discussionid);
 
 $mformpost->set_data(
     array(