Skip to content

Commit

Permalink
course MDL-24162 added wiki_reset_userdata() to delete tag instances …
Browse files Browse the repository at this point in the history
…during course reset.
  • Loading branch information
nebgor committed Sep 20, 2010
1 parent 32368e9 commit 0cdbbc1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mod/wiki/lang/en/wiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
$string['reparsetimeout'] = 'Reparsing default timeout';
$string['repeatedsection'] = 'Wiki error: Section name cannot be repeated \'{$a}\'';
$string['restore'] = 'Restore';
$string['removeallwikitags'] = 'Remove all wiki tags';
$string['restoreconfirm'] = 'Are you sure you want to restore version #{$a}?';
$string['restoreerror'] = 'Version #{$a} could not be restored';
$string['restorethis'] = 'Restore this version';
Expand All @@ -148,6 +149,7 @@
$string['searchresult'] = 'Search results:';
$string['searchwikis'] = 'Search wikis';
$string['special'] = 'Special';
$string['tagsdeleted'] = 'Wiki tags have been deleted';
$string['teacherrating'] = 'Teacher rating';
$string['timesrating']='This page has been rated {$a->c} times with an average of: {$a->s}';
$string['updatedpages'] = "Updated pages";
Expand Down
39 changes: 39 additions & 0 deletions mod/wiki/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,45 @@ function wiki_delete_instance($id) {
return $result;
}

function wiki_reset_userdata($data) {
global $CFG,$DB;
require_once($CFG->dirroot . '/mod/wiki/pagelib.php');
require_once($CFG->dirroot . '/tag/lib.php');

$componentstr = get_string('modulenameplural', 'wiki');
$status = array();

//get the wiki(s) in this course.
if (!$wikis = $DB->get_records('wiki', array('course' => $data->courseid))) {
return false;
}
$errors = false;
foreach ($wikis as $wiki) {
# Get subwiki information #
$subwikis = $DB->get_records('wiki_subwikis', array('wikiid' => $wiki->id));

foreach ($subwikis as $subwiki) {
if ($pages = $DB->get_records('wiki_pages', array('subwikiid' => $subwiki->id))) {
foreach ($pages as $page) {
$tags = tag_get_tags_array('wiki_page', $page->id);
foreach ($tags as $tagid => $tagname) {
// Delete the related tag_instances related to the wiki page.
$errors = tag_delete_instance('wiki_page', $page->id, $tagid);
$status[] = array('component' => $componentstr, 'item' => get_string('tagsdeleted', 'wiki'), 'error' => $errors);
}
}
}
}
}
return $status;
}


function wiki_reset_course_form_definition(&$mform) {
$mform->addElement('header', 'wikiheader', get_string('modulenameplural', 'wiki'));
$mform->addElement('advcheckbox', 'reset_wiki_tags', get_string('removeallwikitags','wiki'));
}

/**
* Return a small object with summary information about what a
* user has done with a given particular instance of this module
Expand Down

0 comments on commit 0cdbbc1

Please sign in to comment.