diff --git a/mod/forum/lang/en/forum.php b/mod/forum/lang/en/forum.php index 43680353211..35dfa960bb8 100644 --- a/mod/forum/lang/en/forum.php +++ b/mod/forum/lang/en/forum.php @@ -288,6 +288,10 @@ $string['mailnow'] = 'Send forum post notifications with no editing-time delay'; $string['manydiscussions'] = 'Discussions per page'; $string['markalldread'] = 'Mark all posts in this discussion read.'; $string['markallread'] = 'Mark all posts in this forum read.'; +$string['markasreadonnotification'] = 'When sending forum post notifications'; +$string['markasreadonnotificationno'] = 'Do not mark the post as read'; +$string['markasreadonnotificationyes'] = 'Mark the post as read'; +$string['markasreadonnotification_help'] = 'When you are notified of a forum post, you can choose whether this should mark the post as read for the purpose of forum tracking.'; $string['markread'] = 'Mark read'; $string['markreadbutton'] = 'Mark
read'; $string['markunread'] = 'Mark unread'; @@ -503,6 +507,7 @@ $string['timedposts'] = 'Timed posts'; $string['timedvisible'] = 'Timed status: Visible to all users'; $string['timestartenderror'] = 'Display end date cannot be earlier than the start date'; $string['trackforum'] = 'Track unread posts'; +$string['trackreadposts_header'] = 'Forum tracking'; $string['tracking'] = 'Track'; $string['trackingoff'] = 'Off'; $string['trackingon'] = 'Forced'; diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 31d95b9b2ea..621553e62a2 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -888,7 +888,10 @@ function forum_cron() { } // Mark processed posts as read. - forum_tp_mark_posts_read($userto, $userto->markposts); + if (get_user_preferences('forum_markasreadonnotification', 1, $userto->id) == 1) { + forum_tp_mark_posts_read($userto, $userto->markposts); + } + unset($userto); } } @@ -1202,7 +1205,9 @@ function forum_cron() { $usermailcount++; // Mark post as read if forum_usermarksread is set off - forum_tp_mark_posts_read($userto, $userto->markposts); + if (get_user_preferences('forum_markasreadonnotification', 1, $userto->id) == 1) { + forum_tp_mark_posts_read($userto, $userto->markposts); + } } } } diff --git a/user/forum.php b/user/forum.php index bd1052da433..03dc07ff417 100644 --- a/user/forum.php +++ b/user/forum.php @@ -38,6 +38,7 @@ list($user, $course) = useredit_setup_preference_page($userid, $courseid); // Create form. $forumform = new user_edit_forum_form(null, array('userid' => $user->id)); +$user->markasreadonnotification = get_user_preferences('forum_markasreadonnotification', 1, $user->id); $forumform->set_data($user); $redirect = new moodle_url("/user/preferences.php", array('userid' => $user->id)); @@ -49,8 +50,13 @@ if ($forumform->is_cancelled()) { $user->autosubscribe = $data->autosubscribe; if (!empty($CFG->forum_trackreadposts)) { $user->trackforums = $data->trackforums; + if (property_exists($data, 'markasreadonnotification')) { + $user->preference_forum_markasreadonnotification = $data->markasreadonnotification; + } } + unset($user->markasreadonnotification); + useredit_update_user_preference($user); user_update_user($user, false, false); // Trigger event. diff --git a/user/forum_form.php b/user/forum_form.php index 49fb5c5bed2..17037522389 100644 --- a/user/forum_form.php +++ b/user/forum_form.php @@ -62,11 +62,21 @@ class user_edit_forum_form extends moodleform { $mform->setDefault('autosubscribe', core_user::get_property_default('autosubscribe')); if (!empty($CFG->forum_trackreadposts)) { + $mform->addElement('header', 'trackreadposts', get_string('trackreadposts_header', 'mod_forum')); $choices = array(); $choices['0'] = get_string('trackforumsno'); $choices['1'] = get_string('trackforumsyes'); $mform->addElement('select', 'trackforums', get_string('trackforums'), $choices); $mform->setDefault('trackforums', core_user::get_property_default('trackforums')); + + $choices = [ + 1 => get_string('markasreadonnotificationyes', 'mod_forum'), + 0 => get_string('markasreadonnotificationno', 'mod_forum'), + ]; + $mform->addElement('select', 'markasreadonnotification', get_string('markasreadonnotification', 'mod_forum'), $choices); + $mform->addHelpButton('markasreadonnotification', 'markasreadonnotification', 'mod_forum'); + $mform->disabledIf('markasreadonnotification', 'trackforums', 'eq', "0"); + $mform->setDefault('markasreadonnotification', 1); } // Add some extra hidden fields.