Skip to content

Commit

Permalink
MDL-60129 mod_book: added reset tags functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed Oct 3, 2017
1 parent 23ab0d7 commit 19f8efd
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion mod/book/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

/**
Expand Down

0 comments on commit 19f8efd

Please sign in to comment.