MDL-29108 Remove all associated grading areas when the context is being deleted

This commit is contained in:
David Mudrak 2011-11-13 13:50:00 +01:00
parent c15b933c69
commit 9e32368b29
2 changed files with 28 additions and 0 deletions

View file

@ -564,6 +564,30 @@ class grading_manager {
return $DB->insert_record('grading_areas', $area);
}
/**
* Removes all data associated with the given context
*
* This is called by {@link context::delete_content()}
*
* @param int $contextid context id
*/
public static function delete_all_for_context($contextid) {
global $DB;
$areaids = $DB->get_fieldset_select('grading_areas', 'id', 'contextid = ?', array($contextid));
$methods = array_keys(self::available_methods(false));
foreach($areaids as $areaid) {
$manager = get_grading_manager($areaid);
foreach ($methods as $method) {
$controller = $manager->get_controller($method);
$controller->delete_definition();
}
}
$DB->delete_records_list('grading_areas', 'id', $areaids);
}
/**
* Helper method to tokenize the given string
*