From 0b9249e63ebae14d70511e68e113dc7570ac13b7 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 20 Sep 2017 19:03:19 +0800 Subject: [PATCH] MDL-60129 mod_forum: added reset tags functionality --- mod/forum/lib.php | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 03ecffd8c26..77085291517 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -7018,13 +7018,17 @@ function forum_reset_userdata($data) { $forumssql = $forums = $rm = null; - if( $removeposts || !empty($data->reset_forum_ratings) ) { - $forumssql = "$allforumssql $typesql"; - $forums = $forums = $DB->get_records_sql($forumssql, $params); + // Check if we need to get additional data. + if ($removeposts || !empty($data->reset_forum_ratings) || !empty($data->reset_forum_tags)) { + // Set this up if we have to remove ratings. $rm = new rating_manager(); $ratingdeloptions = new stdClass; $ratingdeloptions->component = 'mod_forum'; $ratingdeloptions->ratingarea = 'post'; + + // Get the forums for actions that require it. + $forumssql = "$allforumssql $typesql"; + $forums = $DB->get_records_sql($forumssql, $params); } if ($removeposts) { @@ -7045,6 +7049,8 @@ function forum_reset_userdata($data) { //remove ratings $ratingdeloptions->contextid = $context->id; $rm->delete_ratings($ratingdeloptions); + + core_tag_tag::delete_instances('mod_forum', null, $context->id); } } @@ -7099,6 +7105,22 @@ function forum_reset_userdata($data) { } } + // Remove all the tags. + if (!empty($data->reset_forum_tags)) { + if ($forums) { + foreach ($forums as $forumid => $unused) { + if (!$cm = get_coursemodule_from_instance('forum', $forumid)) { + continue; + } + + $context = context_module::instance($cm->id); + core_tag_tag::delete_instances('mod_forum', null, $context->id); + } + } + + $status[] = array('component' => $componentstr, 'item' => get_string('tagsdeleted', 'forum'), 'error' => false); + } + // remove all digest settings unconditionally - even for users still enrolled in course. if (!empty($data->reset_forum_digests)) { $DB->delete_records_select('forum_digests', "forum IN ($allforumssql)", $params); @@ -7155,6 +7177,9 @@ function forum_reset_course_form_definition(&$mform) { $mform->addElement('checkbox', 'reset_forum_ratings', get_string('deleteallratings')); $mform->disabledIf('reset_forum_ratings', 'reset_forum_all', 'checked'); + + $mform->addElement('checkbox', 'reset_forum_tags', get_string('removeallforumtags', 'forum')); + $mform->disabledIf('reset_forum_tags', 'reset_forum_all', 'checked'); } /**