Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MDL-29794 Shared grading form templates can be deleted now
There is a new capability to manage all shared templates. Without this
capability, the user is allowed to delete just templates they previously
shared.

In the future, an option to edit the template directly might be added.
At the moment, the workaround is to pick the template into a temporary
assignment, edit it there and re-save it as a new template.
  • Loading branch information
mudrd8mz committed Nov 1, 2011
1 parent 7622ae9 commit 86e9ccf
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 19 deletions.
60 changes: 48 additions & 12 deletions grade/grading/templates.php
Expand Up @@ -29,7 +29,8 @@
require_once($CFG->dirroot.'/grade/grading/templates_form.php');

$targetid = required_param('targetid', PARAM_INT); // area we are coming from
$pick = optional_param('pick', null, PARAM_INT); // use this form
$pick = optional_param('pick', null, PARAM_INT); // create new form from this template
$remove = optional_param('remove', null, PARAM_INT); // remove this template
$confirmed = optional_param('confirmed', false, PARAM_BOOL); // is the action confirmed

// the manager of the target area
Expand All @@ -54,13 +55,18 @@
require_login($course, true, $cm);
require_capability('moodle/grade:managegradingforms', $context);

// user's capability in the templates bank
$canshare = has_capability('moodle/grade:sharegradingforms', get_system_context());
$canmanage = has_capability('moodle/grade:managesharedforms', get_system_context());

// setup the page
$PAGE->set_url(new moodle_url('/grade/grading/templates.php', array('targetid' => $targetid)));
navigation_node::override_active_url($targetmanager->get_management_url());
$PAGE->set_title(get_string('gradingmanagement', 'core_grading'));
$PAGE->set_heading(get_string('gradingmanagement', 'core_grading'));
$output = $PAGE->get_renderer('core_grading');

// process template actions
// process picking a template
if ($pick) {
$sourceid = $DB->get_field('grading_definitions', 'areaid', array('id' => $pick), MUST_EXIST);
$sourcemanager = get_grading_manager($sourceid);
Expand Down Expand Up @@ -88,6 +94,35 @@
}
}

// process removing a template
if ($remove) {
$sourceid = $DB->get_field('grading_definitions', 'areaid', array('id' => $remove), MUST_EXIST);
$sourcemanager = get_grading_manager($sourceid);
$sourcecontroller = $sourcemanager->get_controller($method);
if (!$sourcecontroller->is_form_defined()) {
throw new moodle_exception('form_definition_mismatch', 'core_grading');
}
$definition = $sourcecontroller->get_definition();
if ($canmanage or ($canshare and ($definition->usercreated == $USER->id))) {
// ok, this user can drop the template
} else {
throw new moodle_exception('no_permission_to_remove_template', 'core_grading');
}
if (!$confirmed) {
echo $output->header();
echo $output->confirm(get_string('templatedeleteconfirm', 'core_grading', s($definition->name)),
new moodle_url($PAGE->url, array('remove' => $remove, 'confirmed' => 1)),
$PAGE->url);
echo $output->box($sourcecontroller->render_preview($PAGE), 'template-preview-confirm');
echo $output->footer();
die();
} else {
require_sesskey();
$sourcecontroller->delete_definition();
redirect($PAGE->url);
}
}

$searchform = new grading_search_template_form($PAGE->url, null, 'GET', '', array('class' => 'templatesearchform'));

if ($searchdata = $searchform->get_data()) {
Expand All @@ -100,7 +135,8 @@
}

// construct the SQL to find all matching templates
$sql = "SELECT DISTINCT gd.id, gd.areaid, gd.name, gd.description, gd.descriptionformat, gd.timecreated
$sql = "SELECT DISTINCT gd.id, gd.areaid, gd.name, gd.description, gd.descriptionformat, gd.timecreated,
gd.usercreated, gd.timemodified, gd.usermodified
FROM {grading_definitions} gd
JOIN {grading_areas} ga ON (gd.areaid = ga.id)";
// join method-specific tables from the plugin scope
Expand Down Expand Up @@ -143,7 +179,6 @@
$rs = $DB->get_recordset_sql($sql, $params);

echo $output->header();

$searchform->display();

$found = 0;
Expand All @@ -154,14 +189,15 @@
$manager = get_grading_manager($template->areaid);
$controller = $manager->get_controller($method);
$out .= $output->box($controller->render_preview($PAGE), 'template-preview');
$out .= $output->box(join(' ', array(
$output->pick_action_icon(new moodle_url($PAGE->url, array('pick' => $template->id)),
get_string('templatepick', 'core_grading'), 'i/tick_green_big', 'pick'),
//$output->pick_action_icon(new moodle_url($PAGE->url, array('edit' => $template->id)),
// get_string('templateedit', 'core_grading'), 'i/edit', 'edit'),
//$output->pick_action_icon(new moodle_url($PAGE->url, array('remove' => $template->id)),
// get_string('templatedelete', 'core_grading'), 't/delete', 'edit'),
)), 'template-actions');
$actions = array($output->pick_action_icon(new moodle_url($PAGE->url, array('pick' => $template->id)),
get_string('templatepick', 'core_grading'), 'i/tick_green_big', 'pick'));
if ($canmanage or ($canshare and ($template->usercreated == $USER->id))) {
//$actions[] = $output->pick_action_icon(new moodle_url($PAGE->url, array('edit' => $template->id)),
// get_string('templateedit', 'core_grading'), 'i/edit', 'edit');
$actions[] = $output->pick_action_icon(new moodle_url($PAGE->url, array('remove' => $template->id)),
get_string('templatedelete', 'core_grading'), 't/delete', 'remove');
}
$out .= $output->box(join(' ', $actions), 'template-actions');
$out .= $output->box(format_text($template->description, $template->descriptionformat), 'template-description');

// ideally we should highlight just the name, description and the fields
Expand Down
9 changes: 5 additions & 4 deletions lang/en/grading.php
Expand Up @@ -41,11 +41,11 @@
$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:
$string['manageactiondelete'] = 'Delete the currently defined form';
$string['manageactiondeleteconfirm'] = 'You are going to delete 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.
* You can switch to another grading method including the \'Simple direct grading\' without deleting 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.';
Expand All @@ -56,7 +56,8 @@
$string['manageactionshareconfirm'] = 'You are going to save a copy of the grading form \'{$a}\' as a new public template. Other users at your site will be able to create new grading forms in their activities from that template. Note that users are able to reuse their own grading forms in other activities even if the forms were not saved as template.';
$string['manageactionsharedone'] = 'The form was successfully saved as a template';
$string['noitemid'] = 'Grading not possible. The graded item does not exist.';
$string['templatedelete'] = 'Remove';
$string['templatedelete'] = 'Delete';
$string['templatedeleteconfirm'] = 'You are going to delete the shared template \'{$a}\'. Deleting a template does not affect existing forms that were created from it.';
$string['templateedit'] = 'Edit';
$string['templatepick'] = 'Use this template';
$string['templatepickconfirm'] = 'Do you want to use the grading form \'{$a->formname}\' as a template for the new grading form in \'{$a->component} ({$a->area})\'?';
3 changes: 2 additions & 1 deletion lang/en/role.php
Expand Up @@ -181,7 +181,8 @@
$string['grade:lock'] = 'Lock grades or items';
$string['grade:manage'] = 'Manage grade items';
$string['grade:managegradingforms'] = 'Manage advanced grading methods';
$string['grade:sharegradingforms'] = 'Share advanced grading forms';
$string['grade:managesharedforms'] = 'Manage advanced grading form templates';
$string['grade:sharegradingforms'] = 'Share advanced grading form as a template';
$string['grade:manageletters'] = 'Manage letter grades';
$string['grade:manageoutcomes'] = 'Manage grade outcomes';
$string['grade:override'] = 'Override grades';
Expand Down
17 changes: 16 additions & 1 deletion lib/db/access.php
Expand Up @@ -1487,6 +1487,8 @@
'clonepermissionsfrom' => 'moodle/course:managegrades'
),

// ability to define advanced grading forms in activities either from scratch
// or from a shared template
'moodle/grade:managegradingforms' => array(
'riskbitmask' => RISK_PERSONAL | RISK_XSS,
'captype' => 'write',
Expand All @@ -1498,8 +1500,21 @@
'clonepermissionsfrom' => 'moodle/course:managegrades'
),

// ability to save a grading form as a new shared template and eventually edit
// and remove own templates (templates originally shared by that user)
'moodle/grade:sharegradingforms' => array(
'riskbitmask' => RISK_SPAM,
'riskbitmask' => RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'manager' => CAP_ALLOW
),
),

// ability to edit and remove any shared template, even those originally shared
// by other users
'moodle/grade:managesharedforms' => array(
'riskbitmask' => RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
Expand Down
2 changes: 1 addition & 1 deletion version.php
Expand Up @@ -31,7 +31,7 @@



$version = 2011102700.03; // YYYYMMDD = weekly release date of this DEV branch
$version = 2011102700.04; // YYYYMMDD = weekly release date of this DEV branch
// RR = release increments - 00 in DEV branches
// .XX = incremental changes

Expand Down

0 comments on commit 86e9ccf

Please sign in to comment.