MDL-29794 Do not offer re-sharing of unmodified forms
The patch introduces a new field 'timecopied' that holds the timestamp of when the given form was cloned last time. Using this field, we can decide whether the form can be actually re-shared or not. Note that the logic just hides the icon. It is meant as a usability feature, not any real protection from sharing.
This commit is contained in:
@@ -198,7 +198,7 @@ class gradingform_rubric_controller extends gradingform_controller {
|
||||
if ($this->definition === false) {
|
||||
$this->definition = new stdClass();
|
||||
foreach (array('id', 'name', 'description', 'descriptionformat', 'status', 'copiedfromid',
|
||||
'timecreated', 'usercreated', 'timemodified', 'usermodified', 'options') as $fieldname) {
|
||||
'timecreated', 'usercreated', 'timemodified', 'usermodified', 'timecopied', 'options') as $fieldname) {
|
||||
$this->definition->$fieldname = $record->$fieldname;
|
||||
}
|
||||
$this->definition->rubric_criteria = array();
|
||||
|
||||
@@ -117,6 +117,7 @@ if (!empty($shareform)) {
|
||||
$targetcontroller = $targetarea->get_controller($method);
|
||||
$targetcontroller->update_definition($controller->get_definition_copy($targetcontroller),
|
||||
gradingform_controller::DEFINITION_STATUS_READY);
|
||||
$DB->set_field('grading_definitions', 'timecopied', time(), array('id' => $definition->id));
|
||||
redirect(new moodle_url($PAGE->url, array('message' => get_string('manageactionsharedone', 'core_grading'))));
|
||||
}
|
||||
}
|
||||
@@ -161,13 +162,51 @@ if (!empty($method)) {
|
||||
echo $output->container_start('actions');
|
||||
if ($controller->is_form_defined()) {
|
||||
$definition = $controller->get_definition();
|
||||
// icon to edit the form definition
|
||||
echo $output->management_action_icon($controller->get_editor_url($returnurl),
|
||||
get_string('manageactionedit', 'core_grading'), 'b/document-edit');
|
||||
// icon to delete the current form definition
|
||||
echo $output->management_action_icon(new moodle_url($PAGE->url, array('deleteform' => $definition->id)),
|
||||
get_string('manageactiondelete', 'core_grading'), 'b/edit-delete');
|
||||
// icon to save the form as a new template
|
||||
if (has_capability('moodle/grade:sharegradingforms', get_system_context())) {
|
||||
echo $output->management_action_icon(new moodle_url($PAGE->url, array('shareform' => $definition->id)),
|
||||
get_string('manageactionshare', 'core_grading'), 'b/bookmark-new');
|
||||
if (empty($definition->copiedfromid)) {
|
||||
$hasoriginal = false;
|
||||
} else {
|
||||
$hasoriginal = $DB->record_exists('grading_definitions', array('id' => $definition->copiedfromid));
|
||||
}
|
||||
if (!$hasoriginal) {
|
||||
// was created from scratch or is orphaned
|
||||
if (empty($definition->timecopied)) {
|
||||
// was never shared before
|
||||
$allowshare = true;
|
||||
} else if ($definition->timemodified > $definition->timecopied) {
|
||||
// was modified since last time shared
|
||||
$allowshare = true;
|
||||
} else {
|
||||
// was not modified since last time shared
|
||||
$allowshare = false;
|
||||
}
|
||||
} else {
|
||||
// was created from a template and the template still exists
|
||||
if ($definition->timecreated == $definition->timemodified) {
|
||||
// was not modified since created
|
||||
$allowshare = false;
|
||||
} else if (empty($definition->timecopied)) {
|
||||
// was modified but was not re-shared yet
|
||||
$allowshare = true;
|
||||
} else if ($definition->timemodified > $definition->timecopied) {
|
||||
// was modified since last time re-shared
|
||||
$allowshare = true;
|
||||
} else {
|
||||
// was not modified since last time re-shared
|
||||
$allowshare = false;
|
||||
}
|
||||
}
|
||||
if ($allowshare) {
|
||||
echo $output->management_action_icon(new moodle_url($PAGE->url, array('shareform' => $definition->id)),
|
||||
get_string('manageactionshare', 'core_grading'), 'b/bookmark-new');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo $output->management_action_icon($controller->get_editor_url($returnurl),
|
||||
|
||||
@@ -90,6 +90,7 @@ if ($pick) {
|
||||
require_sesskey();
|
||||
$targetcontroller->update_definition($sourcecontroller->get_definition_copy($targetcontroller),
|
||||
gradingform_controller::DEFINITION_STATUS_READY);
|
||||
$DB->set_field('grading_definitions', 'timecopied', time(), array('id' => $definition->id));
|
||||
redirect(new moodle_url('/grade/grading/manage.php', array('areaid' => $targetid)));
|
||||
}
|
||||
}
|
||||
@@ -209,7 +210,10 @@ foreach ($rs as $template) {
|
||||
$rs->close();
|
||||
|
||||
if (!$found) {
|
||||
echo $output->heading(get_string('nothingtodisplay'));
|
||||
echo $output->heading(get_string('nosharedformfound', 'core_grading'));
|
||||
echo $output->single_button(
|
||||
new moodle_url('/grade/grading/manage.php', array('areaid' => $targetid)),
|
||||
get_string('back'), 'get');
|
||||
}
|
||||
|
||||
echo $output->footer();
|
||||
|
||||
+2
-1
@@ -53,9 +53,10 @@ $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';
|
||||
$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['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.';
|
||||
$string['manageactionsharedone'] = 'The form was successfully saved as a template';
|
||||
$string['noitemid'] = 'Grading not possible. The graded item does not exist.';
|
||||
$string['nosharedformfound'] = 'No template found';
|
||||
$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';
|
||||
|
||||
+4
-3
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="lib/db" VERSION="20111014" COMMENT="XMLDB file for core Moodle tables"
|
||||
<XMLDB PATH="lib/db" VERSION="20111101" COMMENT="XMLDB file for core Moodle tables"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
@@ -2813,8 +2813,9 @@
|
||||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="The timestamp of when the form definition was created initially" PREVIOUS="copiedfromid" NEXT="usercreated"/>
|
||||
<FIELD NAME="usercreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="The ID of the user who created this definition and is considered as its owner for access control purposes" PREVIOUS="timecreated" NEXT="timemodified"/>
|
||||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="The time stamp of when the form definition was modified recently" PREVIOUS="usercreated" NEXT="usermodified"/>
|
||||
<FIELD NAME="usermodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="The ID of the user who did the most recent modification" PREVIOUS="timemodified" NEXT="options"/>
|
||||
<FIELD NAME="options" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" COMMENT="General field to be used by plugins as a general storage place for their own settings" PREVIOUS="usermodified"/>
|
||||
<FIELD NAME="usermodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="The ID of the user who did the most recent modification" PREVIOUS="timemodified" NEXT="timecopied"/>
|
||||
<FIELD NAME="timecopied" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="The timestamp of when this form was most recently copied into another area" PREVIOUS="usermodified" NEXT="options"/>
|
||||
<FIELD NAME="options" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" COMMENT="General field to be used by plugins as a general storage place for their own settings" PREVIOUS="timecopied"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="fk_areaid"/>
|
||||
|
||||
@@ -6885,6 +6885,16 @@ FROM
|
||||
upgrade_main_savepoint(true, 2011102700.03);
|
||||
}
|
||||
|
||||
// TODO squash this before merging into the master - MDL-29798
|
||||
if ($oldversion < 2011102700.05) {
|
||||
$table = new xmldb_table('grading_definitions');
|
||||
$field = new xmldb_field('timecopied', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, '0', 'usermodified');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
upgrade_main_savepoint(true, 2011102700.05);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
|
||||
$version = 2011102700.04; // YYYYMMDD = weekly release date of this DEV branch
|
||||
$version = 2011102700.05; // YYYYMMDD = weekly release date of this DEV branch
|
||||
// RR = release increments - 00 in DEV branches
|
||||
// .XX = incremental changes
|
||||
|
||||
|
||||
Reference in New Issue
Block a user