MDL-60129 mod_book: added reset tags functionality

This commit is contained in:
Mark Nelson 2017-09-20 19:03:09 +08:00
parent 23ab0d7788
commit 19f8efd3be

View file

@ -164,10 +164,44 @@ function book_print_recent_activity($course, $viewfullnames, $timestart) {
* @return array status array
*/
function book_reset_userdata($data) {
global $DB;
// Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
// See MDL-9367.
return array();
$status = [];
if (!empty($data->reset_book_tags)) {
// Loop through the books and remove the tags from the chapters.
if ($books = $DB->get_records('book', array('course' => $data->courseid))) {
foreach ($books as $book) {
if (!$cm = get_coursemodule_from_instance('book', $book->id)) {
continue;
}
$context = context_module::instance($cm->id);
core_tag_tag::delete_instances('mod_book', null, $context->id);
}
}
$status[] = [
'component' => get_string('modulenameplural', 'book'),
'item' => get_string('tagsdeleted', 'book'),
'error' => false
];
}
return $status;
}
/**
* The elements to add the course reset form.
*
* @param moodleform $mform
*/
function book_reset_course_form_definition(&$mform) {
$mform->addElement('header', 'bookheader', get_string('modulenameplural', 'book'));
$mform->addElement('checkbox', 'reset_book_tags', get_string('removeallbooktags', 'book'));
}
/**