Permalink
Browse files

Merge pull request #21 from marinaglancy/wip-nov03-rubric

Display warnings if used rubric is being updated and mark instances for regrade
  • Loading branch information...
2 parents dd736a8 + 0136124 commit e14e78abbfcc0c938237d0b3ceb4a6ef4da43668 @mudrd8mz mudrd8mz committed Nov 3, 2011
View
@@ -56,6 +56,9 @@
/** @var array graderange array of valid grades for this area. Use set_grade_range and get_grade_range to access this */
private $graderange = null;
+ /** @var boolean|null cached result of function has_active_instances() */
+ protected $hasactiveinstances = null;
+
/**
* Do not instantinate this directly, use {@link grading_manager::get_controller()}
*
@@ -334,8 +337,8 @@ public function get_formatted_description() {
}
/**
- * Returns the ACTIVE instance for this definition for the specified $raterid and $itemid
- * (if multiple raters are allowed, or only for $itemid otherwise).
+ * Returns the current instance (either with status ACTIVE or NEEDUPDATE) for this definition for the
+ * specified $raterid and $itemid (if multiple raters are allowed, or only for $itemid otherwise).
*
* @param int $raterid
* @param int $itemid
@@ -344,32 +347,36 @@ public function get_formatted_description() {
*/
public function get_current_instance($raterid, $itemid, $idonly = false) {
global $DB;
- $select = array(
+ $params = array(
'formid' => $this->definition->id,
'itemid' => $itemid,
- 'status' => gradingform_instance::INSTANCE_STATUS_ACTIVE);
+ 'status1' => gradingform_instance::INSTANCE_STATUS_ACTIVE,
+ 'status2' => gradingform_instance::INSTANCE_STATUS_NEEDUPDATE);
+ $select = 'formid=:formid and itemid=:itemid and (status=:status1 or status=:status2)';
if (false /* TODO $manager->allow_multiple_raters() */) {
- $select['raterid'] = $raterid;
+ $select .= ' and raterid=:raterid';
+ $params['raterid'] = $raterid;
}
if ($idonly) {
- if ($current = $DB->get_record('grading_instances', $select, 'id', IGNORE_MISSING)) {
+ if ($current = $DB->get_record_select('grading_instances', $select, $params, 'id', IGNORE_MISSING)) {
return $current->id;
}
} else {
- if ($current = $DB->get_record('grading_instances', $select, '*', IGNORE_MISSING)) {
+ if ($current = $DB->get_record_select('grading_instances', $select, $params, '*', IGNORE_MISSING)) {
return $this->get_instance($current);
}
}
return null;
}
/**
- * Returns list of active instances for the specified $itemid
+ * Returns list of ACTIVE instances for the specified $itemid
+ * (intentionally does not return instances with status NEEDUPDATE)
*
* @param int $itemid
* @return array of gradingform_instance objects
*/
- public function get_current_instances($itemid) {
+ public function get_active_instances($itemid) {
global $DB;
$conditions = array('formid' => $this->definition->id,
'itemid' => $itemid,
@@ -382,6 +389,22 @@ public function get_current_instances($itemid) {
return $rv;
}
+ /**
+ * Returns true if there are already people who has been graded on this definition.
+ * In this case plugins may restrict changes of the grading definition
+ *
+ * @return boolean
+ */
+ public function has_active_instances() {
+ global $DB;
+ if ($this->hasactiveinstances === null) {
+ $conditions = array('formid' => $this->definition->id,
+ 'status' => gradingform_instance::INSTANCE_STATUS_ACTIVE);
+ $this->hasactiveinstances = $DB->record_exists('grading_instances', $conditions);
+ }
+ return $this->hasactiveinstances;
+ }
+
/**
* Returns the object of type gradingform_XXX_instance (where XXX is the plugin method name)
*
@@ -528,9 +551,10 @@ protected function get_method_name() {
* @param int $itemid
* @param array $grading_info result of function grade_get_grades if plugin want to use some of their info
* @param string $defaultcontent default string to be returned if no active grading is found or for some reason can not be shown to a user
+ * @param boolean $cangrade whether current user has capability to grade in this context
* @return string
*/
- public function render_grade($page, $itemid, $grading_info, $defaultcontent) {
+ public function render_grade($page, $itemid, $grading_info, $defaultcontent, $cangrade) {
return $defaultcontent;
}
@@ -563,6 +587,7 @@ public function render_grade($page, $itemid, $grading_info, $defaultcontent) {
*/
abstract class gradingform_instance {
const INSTANCE_STATUS_ACTIVE = 1;
+ const INSTANCE_STATUS_NEEDUPDATE = 2;
const INSTANCE_STATUS_INCOMPLETE = 0;
const INSTANCE_STATUS_ARCHIVE = 3;
@@ -624,6 +649,19 @@ public function copy($raterid, $itemid) {
return $instanceid;
}
+ /**
+ * Returns the current (active or needupdate) instance for the same raterid and itemid as this
+ * instance. This function is useful to find the status of the currently modified instance
+ *
+ * @return gradingform_instance
+ */
+ public function get_current_instance() {
+ if ($this->get_status() == self::INSTANCE_STATUS_ACTIVE || $this->get_status() == self::INSTANCE_STATUS_NEEDUPDATE) {
+ return $this;
+ }
+ return $this->get_controller()->get_current_instance($this->data->raterid, $this->data->itemid);
+ }
+
/**
* Returns the controller
*
@@ -642,6 +680,15 @@ public function get_id() {
return $this->data->id;
}
+ /**
+ * Returns instance status
+ *
+ * @return int
+ */
+ public function get_status() {
+ return $this->data->status;
+ }
+
/**
* Marks the instance as ACTIVE and current active instance (if exists) as ARCHIVE
*/
@@ -655,14 +702,10 @@ protected function make_active() {
throw new coding_exception('You cannot mark active the grading instance without itemid');
}
$currentid = $this->get_controller()->get_current_instance($this->data->raterid, $this->data->itemid, true);
- if ($currentid) {
- if ($currentid != $this->get_id()) {
- $DB->update_record('grading_instances', array('id' => $currentid, 'status' => self::INSTANCE_STATUS_ARCHIVE));
- $DB->update_record('grading_instances', array('id' => $this->get_id(), 'status' => self::INSTANCE_STATUS_ACTIVE));
- }
- } else {
- $DB->update_record('grading_instances', array('id' => $this->get_id(), 'status' => self::INSTANCE_STATUS_ACTIVE));
+ if ($currentid && $currentid != $this->get_id()) {
+ $DB->update_record('grading_instances', array('id' => $currentid, 'status' => self::INSTANCE_STATUS_ARCHIVE));
}
+ $DB->update_record('grading_instances', array('id' => $this->get_id(), 'status' => self::INSTANCE_STATUS_ACTIVE));
$this->data->status = self::INSTANCE_STATUS_ACTIVE;
}
@@ -44,16 +44,16 @@
$PAGE->set_title(get_string('definerubric', 'gradingform_rubric'));
$PAGE->set_heading(get_string('definerubric', 'gradingform_rubric'));
-$mform = new gradingform_rubric_editrubric(null, array('areaid' => $areaid, 'context' => $context));
+$mform = new gradingform_rubric_editrubric(null, array('areaid' => $areaid, 'context' => $context, 'allowdraft' => !$controller->has_active_instances()));
$data = $controller->get_definition_for_editing();
$returnurl = optional_param('returnurl', $manager->get_management_url(), PARAM_LOCALURL);
$data->returnurl = $returnurl;
$mform->set_data($data);
if ($mform->is_cancelled()) {
redirect($returnurl);
-} else if ($mform->is_submitted() && $mform->is_validated()) {
- $data = $mform->get_data();
- $controller->update_definition($data);
+} else if ($mform->is_submitted() && $mform->is_validated() && !$mform->need_confirm_regrading($controller)) {
+ // everything ok, validated, re-grading confirmed if needed. Make changes to the rubric
+ $controller->update_definition($mform->get_data());
redirect($returnurl);
}
@@ -69,7 +69,12 @@ public function definition() {
$buttonarray = array();
$buttonarray[] = &$form->createElement('submit', 'saverubric', get_string('saverubric', 'gradingform_rubric'));
- $buttonarray[] = &$form->createElement('submit', 'saverubricdraft', get_string('saverubricdraft', 'gradingform_rubric'));
+ if ($this->_customdata['allowdraft']) {
+ $buttonarray[] = &$form->createElement('submit', 'saverubricdraft', get_string('saverubricdraft', 'gradingform_rubric'));
+ }
+ $editbutton = &$form->createElement('submit', 'editrubric', ' ');
+ $editbutton->freeze();
+ $buttonarray[] = &$editbutton;
$buttonarray[] = &$form->createElement('cancel');
$form->addGroup($buttonarray, 'buttonar', '', array(' '), false);
$form->closeHeaderBefore('buttonar');
@@ -93,6 +98,9 @@ function validation($data, $files) {
if ($rubricel->non_js_button_pressed($data['rubric'])) {
// if JS is disabled and button such as 'Add criterion' is pressed - prevent from submit
$err['rubricdummy'] = 1;
+ } else if (isset($data['editrubric'])) {
+ // continue editing
+ $err['rubricdummy'] = 1;
} else if (isset($data['saverubric']) && $data['saverubric']) {
// If user attempts to make rubric active - it needs to be validated
if ($rubricel->validate($data['rubric']) !== false) {
@@ -117,4 +125,70 @@ function get_data() {
}
return $data;
}
+
+ /**
+ * Check if there are changes in the rubric and it is needed to ask user whether to
+ * mark the current grades for re-grading. User may confirm re-grading and continue,
+ * return to editing or cancel the changes
+ *
+ * @param gradingform_rubric_controller $controller
+ */
+ function need_confirm_regrading($controller) {
+ $data = $this->get_data();
+ if (isset($data->rubric['regrade'])) {
+ // we have already displayed the confirmation on the previous step
+ return false;
+ }
+ if (!isset($data->saverubric) || !$data->saverubric) {
+ // we only need confirmation when button 'Save rubric' is pressed
+ return false;
+ }
+ if (!$controller->has_active_instances()) {
+ // nothing to re-grade, confirmation not needed
+ return false;
+ }
+ $changelevel = $controller->update_or_check_rubric($data);
+ if ($changelevel == 0) {
+ // no changes in the rubric, no confirmation needed
+ return false;
+ }
+
+ // freeze form elements and pass the values in hidden fields
+ // TODO description_editor does not freeze the normal way!
+ $form = $this->_form;
+ foreach (array('rubric', 'name'/*, 'description_editor'*/) as $fieldname) {
+ $el =& $form->getElement($fieldname);
+ $el->freeze();
+ $el->setPersistantFreeze(true);
+ if ($fieldname == 'rubric') {
+ $el->add_regrade_confirmation($changelevel);
+ }
+ }
+
+ // replace button text 'saverubric' and unfreeze 'Back to edit' button
+ $this->findButton('saverubric')->setValue(get_string('continue'));
+ $el =& $this->findButton('editrubric');
+ $el->setValue(get_string('backtoediting', 'gradingform_rubric'));
+ $el->unfreeze();
+
+ return true;
+ }
+
+ /**
+ * Returns a form element (submit button) with the name $elementname
+ *
+ * @param string $elementname
+ * @return HTML_QuickForm_element
+ */
+ function &findButton($elementname) {
+ $form = $this->_form;
+ $buttonar =& $form->getElement('buttonar');
+ $elements =& $buttonar->getElements();
+ foreach ($elements as $el) {
+ if ($el->getName() == $elementname) {
+ return $el;
+ }
+ }
+ return null;
+ }
}
@@ -69,3 +69,18 @@
$string['err_nodefinition'] = 'Level definition can not be empty';
$string['err_scoreformat'] = 'Number of points for each level must be a valid non-negative number';
$string['err_totalscore'] = 'Maximum number of points possible when graded by the rubric must be more than zero';
+
+$string['regrademessage1'] = 'You are about to save changes to the rubric that has already been used for grading. Please indicate whether your changes
+ are significant and students grades need to be reviewed.
+ If students already graded are marked for re-grading their
+ current grades remain in gradebook but the students will not see the rubric grading before teacher updates it.';
+$string['regrademessage5'] = 'You are about to save significant changes to the rubric that has already been used for grading. Please note that all students already graded will be marked for re-grading.
+ The
+ current grades remain in gradebook but the students will not see the rubric grading before teacher updates it.';
+$string['regradeoption0'] = 'Do not mark for regrade';
+$string['regradeoption1'] = 'Mark for regrade';
+
+$string['needregrademessage'] = 'Rubric definition was changed after this student had been graded. You must update the grade otherwise it will not be shown to student.';
+$string['rubricnotcompleted'] = 'You have to select a feedback on each rubric criterion';
+
+$string['backtoediting'] = 'Back to editing';
Oops, something went wrong.

0 comments on commit e14e78a

Please sign in to comment.