MDL-29108 Improved support for form definition status

Every grading form can be basically in either DRAFT state (currently
being edited) or READY state (available for usage). For shared
templates, the status is not relevant at the moment and they are
automatically in the READY state.
This commit is contained in:
David Mudrak 2011-11-01 12:32:06 +01:00
parent 20836db999
commit 7622ae95dc
7 changed files with 38 additions and 33 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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
*

View File

@ -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'))));
}
}

View File

@ -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)));
}
}

View File

@ -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;
}

View File

@ -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