diff --git a/grade/grading/form/lib.php b/grade/grading/form/lib.php index 11d95dae710..64744ed404d 100644 --- a/grade/grading/form/lib.php +++ b/grade/grading/form/lib.php @@ -31,9 +31,12 @@ defined('MOODLE_INTERNAL') || die(); */ abstract class gradingform_controller { - const DEFINITION_STATUS_WORKINPROGRESS = 0; - const DEFINITION_STATUS_PRIVATE = 1; - const DEFINITION_STATUS_PUBLIC = 2; + /** undefined definition status */ + const DEFINITION_STATUS_NULL = 0; + /** the form is currently being edited and is not ready for usage yet */ + const DEFINITION_STATUS_DRAFT = 10; + /** the for was marked as ready for actual usage */ + const DEFINITION_STATUS_READY = 20; /** @var stdClass the context */ protected $context; @@ -114,32 +117,20 @@ abstract class gradingform_controller { } /** - * Is the grading form defined and released for usage by the given user? + * Is the grading form defined and ready for usage? * - * @param int $foruserid the id of the user who attempts to work with the form * @return boolean */ - public function is_form_available($foruserid = null) { - global $USER; - - if (is_null($foruserid)) { - $foruserid = $USER->id; - } + public function is_form_available() { if (!$this->is_form_defined()) { return false; } - if ($this->definition->status == self::DEFINITION_STATUS_PUBLIC) { + if ($this->definition->status == self::DEFINITION_STATUS_READY) { return true; } - if ($this->definition->status == self::DEFINITION_STATUS_PRIVATE) { - if ($this->definition->usercreated == $foruserid) { - return true; - } - } - return false; } @@ -225,9 +216,10 @@ abstract class gradingform_controller { * and save their data into own tables, too. * * @param stdClass $definition data containing values for the {grading_definition} table + * @param int|null $status optionally overwrite the status field with this value * @param int|null $usermodified optional userid of the author of the definition, defaults to the current user */ - public function update_definition(stdClass $definition, $usermodified = null) { + public function update_definition(stdClass $definition, $status = null, $usermodified = null) { global $DB, $USER; if (is_null($usermodified)) { @@ -256,6 +248,10 @@ abstract class gradingform_controller { // set the modification flags $record->timemodified = time(); $record->usermodified = $usermodified; + // overwrite the status if required + if (!is_null($status)) { + $record->status = $status; + } $DB->update_record('grading_definitions', $record); @@ -281,7 +277,11 @@ abstract class gradingform_controller { $record->usercreated = $usermodified; $record->timemodified = $record->timecreated; $record->usermodified = $record->usercreated; - $record->status = self::DEFINITION_STATUS_WORKINPROGRESS; + if (!is_null($status)) { + $record->status = $status; + } else { + $record->status = self::DEFINITION_STATUS_DRAFT; + } $DB->insert_record('grading_definitions', $record); diff --git a/grade/grading/form/rubric/edit.php b/grade/grading/form/rubric/edit.php index a4ac7845880..cff0092f8de 100644 --- a/grade/grading/form/rubric/edit.php +++ b/grade/grading/form/rubric/edit.php @@ -56,7 +56,7 @@ if ($mform->is_cancelled()) { redirect($returnurl); } else if ($mform->is_submitted() && $mform->is_validated()) { $data = $mform->get_data(); - $controller->update_definition($data); + $controller->update_definition($data); // todo set status redirect($returnurl); } diff --git a/grade/grading/form/rubric/lib.php b/grade/grading/form/rubric/lib.php index 2075039081b..085ee0afb8d 100644 --- a/grade/grading/form/rubric/lib.php +++ b/grade/grading/form/rubric/lib.php @@ -62,16 +62,17 @@ class gradingform_rubric_controller extends gradingform_controller { * * @see parent::update_definition() * @param stdClass $newdefinition rubric definition data as coming from gradingform_rubric_editrubric::get_data() + * @param int|null $status optionally overwrite the status field with this value * @param int|null $usermodified optional userid of the author of the definition, defaults to the current user */ - public function update_definition(stdClass $newdefinition, $usermodified = null) { + public function update_definition(stdClass $newdefinition, $status = null, $usermodified = null) { global $DB; // firstly update the common definition data in the {grading_definition} table if ($this->definition === false) { - // if definition does not exist yet, create a blank one with only required fields set + // if definition does not exist yet, create a blank one // (we need id to save files embedded in description) - parent::update_definition((object)array('descriptionformat' => FORMAT_MOODLE), $usermodified); + parent::update_definition((object)array(), $status, $usermodified); parent::load_definition(); } if (!isset($newdefinition->rubric['options'])) { @@ -81,7 +82,7 @@ class gradingform_rubric_controller extends gradingform_controller { $editoroptions = self::description_form_field_options($this->get_context()); $newdefinition = file_postupdate_standard_editor($newdefinition, 'description', $editoroptions, $this->get_context(), 'gradingform_rubric', 'definition_description', $this->definition->id); - parent::update_definition($newdefinition, $usermodified); + parent::update_definition($newdefinition, $status, $usermodified); // reload the definition from the database $currentdefinition = $this->get_definition(true); @@ -343,11 +344,6 @@ class gradingform_rubric_controller extends gradingform_controller { return format_text($description, $this->definition->descriptionformat, $formatoptions); } - public function is_form_available($foruserid = null) { - return true; - // TODO this is temporary for testing! - } - /** * Returns the rubric plugin renderer * diff --git a/grade/grading/manage.php b/grade/grading/manage.php index 5e80dcfddd6..9bdabdd19cc 100644 --- a/grade/grading/manage.php +++ b/grade/grading/manage.php @@ -115,7 +115,8 @@ if (!empty($shareform)) { $newareaid = $manager->create_shared_area($method); $targetarea = get_grading_manager($newareaid); $targetcontroller = $targetarea->get_controller($method); - $targetcontroller->update_definition($controller->get_definition_copy($targetcontroller)); + $targetcontroller->update_definition($controller->get_definition_copy($targetcontroller), + gradingform_controller::DEFINITION_STATUS_READY); redirect(new moodle_url($PAGE->url, array('message' => get_string('manageactionsharedone', 'core_grading')))); } } diff --git a/grade/grading/templates.php b/grade/grading/templates.php index 8a0ba15c2eb..5e63035350e 100644 --- a/grade/grading/templates.php +++ b/grade/grading/templates.php @@ -82,7 +82,8 @@ if ($pick) { die(); } else { require_sesskey(); - $targetcontroller->update_definition($sourcecontroller->get_definition_copy($targetcontroller)); + $targetcontroller->update_definition($sourcecontroller->get_definition_copy($targetcontroller), + gradingform_controller::DEFINITION_STATUS_READY); redirect(new moodle_url('/grade/grading/manage.php', array('areaid' => $targetid))); } } diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 6aa33d1d57a..602cbc902c1 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -6878,6 +6878,13 @@ FROM upgrade_main_savepoint(true, 2011101900.02); } + // TODO squash this before merging into the master - MDL-29798 + if ($oldversion < 2011102700.03) { + // set the reasonable status to all definitions we have in our databases so far + $DB->set_field('grading_definitions', 'status', 20); + upgrade_main_savepoint(true, 2011102700.03); + } + return true; } diff --git a/version.php b/version.php index 6bcc026af5b..32e81a507b4 100644 --- a/version.php +++ b/version.php @@ -31,7 +31,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2011102700.00; // YYYYMMDD = weekly release date of this DEV branch +$version = 2011102700.03; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes