Form definitions can be removed now

This commit is contained in:
David Mudrak
2011-10-19 13:25:47 +02:00
parent fde3380443
commit 671ec8f50e
5 changed files with 85 additions and 4 deletions
+31 -1
View File
@@ -368,8 +368,31 @@ abstract class gradingform_controller {
return $output->preview_definition_header($this);
}
////////////////////////////////////////////////////////////////////////////
/**
* Deletes the form definition and all the associated data
*
* @see delete_plugin_definition()
* @return void
*/
public function delete_definition() {
global $DB;
if (!$this->is_form_defined()) {
// nothing to do
return;
}
// firstly, let the plugin delete everything from their own tables
$this->delete_plugin_definition();
// then, delete all instances left
$DB->delete_records('grading_instances', array('formid' => $this->definition->id));
// finally, delete the main definition record
$DB->delete_records('grading_definitions', array('id' => $this->definition->id));
$this->definition = false;
}
////////////////////////////////////////////////////////////////////////////
/**
* Loads the form definition if it exists
@@ -385,6 +408,13 @@ abstract class gradingform_controller {
'method' => $this->get_method_name()), '*', IGNORE_MISSING);
}
/**
* Deletes all plugin data associated with the given form definiton
*
* @see delete_definition()
*/
abstract protected function delete_plugin_definition();
/**
* @return string the name of the grading method plugin, eg 'rubric'
* @see PARAM_PLUGIN
+20
View File
@@ -549,4 +549,24 @@ class gradingform_rubric_controller extends gradingform_controller {
return $header . $rubric;
}
/**
* Deletes the rubric definition and all the associated information
*/
protected function delete_plugin_definition() {
global $DB;
// get the list of instances
$instances = array_keys($DB->get_records('grading_instances', array('formid' => $this->definition->id), '', 'id'));
// delete all fillings
$DB->delete_records_list('gradingform_rubric_fillings', 'forminstanceid', $instances);
// delete instances
$DB->delete_records_list('grading_instances', 'id', $instances);
// get the list of criteria records
$criteria = array_keys($DB->get_records('gradingform_rubric_criteria', array('formid' => $this->definition->id), '', 'id'));
// delete levels
$DB->delete_records_list('gradingform_rubric_levels', 'criterionid', $criteria);
// delete critera
$DB->delete_records_list('gradingform_rubric_criteria', 'id', $criteria);
}
}
+24 -1
View File
@@ -37,6 +37,8 @@ $returnurl = optional_param('returnurl', null, PARAM_LOCALURL);
$setmethod = optional_param('setmethod', null, PARAM_PLUGIN);
// publish the given form definition as a new template in the forms bank
$shareform = optional_param('shareform', null, PARAM_INT);
// delete the given form definition
$deleteform = optional_param('deleteform', null, PARAM_INT);
// consider the required action as confirmed
$confirmed = optional_param('confirmed', false, PARAM_BOOL);
// a message to display, typically a previous action's result
@@ -121,6 +123,27 @@ if (!empty($shareform)) {
}
}
// delete the form definition
if (!empty($deleteform)) {
$controller = $manager->get_controller($method);
$definition = $controller->get_definition();
if (!$confirmed) {
// let the user confirm they understand the consequences (also known as WTF-effect)
echo $output->header();
echo $output->confirm(markdown_to_html(get_string('manageactiondeleteconfirm', 'core_grading', array(
'formname' => s($definition->name),
'component' => $manager->get_component_title(),
'area' => $manager->get_area_title()))),
new moodle_url($PAGE->url, array('deleteform' => $deleteform, 'confirmed' => 1)), $PAGE->url);
echo $output->footer();
die();
} else {
require_sesskey();
$controller->delete_definition();
redirect(new moodle_url($PAGE->url, array('message' => get_string('manageactiondeletedone', 'core_grading'))));
}
}
echo $output->header();
if (!empty($message)) {
@@ -142,7 +165,7 @@ if (!empty($method)) {
$definition = $controller->get_definition();
echo $output->management_action_icon($controller->get_editor_url($returnurl),
get_string('manageactionedit', 'core_grading'), 'b/document-edit');
echo $output->management_action_icon($PAGE->url,
echo $output->management_action_icon(new moodle_url($PAGE->url, array('deleteform' => $definition->id)),
get_string('manageactiondelete', 'core_grading'), 'b/edit-delete');
if (has_capability('moodle/grade:sharegradingforms', get_system_context())) {
echo $output->management_action_icon(new moodle_url($PAGE->url, array('shareform' => $definition->id)),
+2 -2
View File
@@ -23,8 +23,8 @@ YUI.add('moodle-core_grading-manage', function(Y) {
var box = e.currentTarget;
var anim = new Y.Anim({
node: box,
from: { opacity: 1 },
to: { opacity: 0 },
duration: 1,
to: { opacity: 0, height: 0 },
});
anim.run();
anim.on('end', function() {
+8
View File
@@ -42,6 +42,14 @@ $string['gradingmethodnone'] = 'Simple direct grading';
$string['gradingmethods'] = 'Grading methods';
$string['manageactionclone'] = 'Create new grading form from a template';
$string['manageactiondelete'] = 'Remove the currently defined form';
$string['manageactiondeleteconfirm'] = 'You are going to remove the grading form \'{$a->formname}\' and all the associated information from \'{$a->component} ({$a->area})\'. Please make sure you understand the following consequences:
* There is no way to undo this operation.
* You can switch to another grading method including the \'Simple direct grading\' without removing this form.
* All the information about how the grading forms are filled will be lost.
* The calculated result grades stored in the gradebook will not be affected. However the explanation of how they were calculated will not be available.
* This operation does not affect eventual copies of this form in other activities.';
$string['manageactiondeletedone'] = 'The form was successfully deleted';
$string['manageactionedit'] = 'Edit the current form definition';
$string['manageactionnew'] = 'Define new grading form from scratch';
$string['manageactionshare'] = 'Publish the form as a new template';