Permalink
Browse files

Merge pull request #17 from marinaglancy/wip-rubricrenderer-rubric

Better rendering of the rubrics, rubric display options
  • Loading branch information...
mudrd8mz committed Oct 27, 2011
2 parents 01609c9 + 39c6f4b commit 72e48ad28f53f486c76d6e4406a9830037efb426
@@ -57,9 +57,9 @@ public function definition() {
$form->setType('description_editor', PARAM_RAW);
// rubric editor
- $element = $form->addElement('rubriceditor', 'rubric_criteria', 'Rubric 1'); // todo label
- $form->setType('rubric_criteria', PARAM_RAW);
- $form->addRule('rubric_criteria', '', 'rubriceditorcompleted'); //TODO how to add this rule automatically?????
+ $element = $form->addElement('rubriceditor', 'rubric', get_string('rubric', 'gradingform_rubric'));
+ $form->setType('rubric', PARAM_RAW);
+ $form->addRule('rubric', '', 'rubriceditorcompleted'); //TODO how to add this rule automatically?????
if (array_key_exists('freezerubric', $this->_customdata) && $this->_customdata['freezerubric']) {
$element->freeze();
}
@@ -92,10 +92,10 @@ M.gradingform_rubriceditor.buttonclick = function(e, Y, name, confirmed) {
if (e.target.get('type') != 'submit') return;
var chunks = e.target.get('id').split('-'),
action = chunks[chunks.length-1]
- if (chunks[0] != name) return;
+ if (chunks[0] != name || chunks[1] != 'criteria') return;
var elements_str
- if (chunks.length>3 || action == 'addlevel') {
- elements_str = '#rubric-'+name+' #'+name+'-'+chunks[1]+'-levels .level'
+ if (chunks.length>4 || action == 'addlevel') {
+ elements_str = '#rubric-'+name+' #'+name+'-criteria-'+chunks[2]+'-levels .level'
} else {
elements_str = '#rubric-'+name+' .criterion'
}
@@ -112,38 +112,44 @@ M.gradingform_rubriceditor.buttonclick = function(e, Y, name, confirmed) {
'callbackargs' : [e, Y, name, true],
'callback' : M.gradingform_rubriceditor.buttonclick
};
- if (chunks.length == 2 && action == 'addcriterion') {
+ if (chunks.length == 3 && action == 'addcriterion') {
// ADD NEW CRITERION
var newcriterion = M.gradingform_rubriceditor.templates[name]['criterion'].
replace(/\{CRITERION-id\}/g, 'NEWID'+newid).replace(/\{.+?\}/g, '')
- Y.one('#'+name+'-criteria').append(newcriterion)
+ var parentel = Y.one('#'+name+'-criteria')
+ if (parentel.one('>tbody')) parentel = parentel.one('>tbody')
+ parentel.append(newcriterion)
M.gradingform_rubriceditor.addhandlers(Y, name);
- } else if (chunks.length == 4 && action == 'addlevel') {
+ } else if (chunks.length == 5 && action == 'addlevel') {
// ADD NEW LEVEL
var newlevel = M.gradingform_rubriceditor.templates[name]['level'].
- replace(/\{CRITERION-id\}/g, chunks[1]).replace(/\{LEVEL-id\}/g, 'NEWID'+newid).replace(/\{.+?\}/g, '')
- Y.one('#'+name+'-'+chunks[1]+'-levels').append(newlevel)
+ replace(/\{CRITERION-id\}/g, chunks[2]).replace(/\{LEVEL-id\}/g, 'NEWID'+newid).replace(/\{.+?\}/g, '')
+ Y.one('#'+name+'-criteria-'+chunks[2]+'-levels').append(newlevel)
+ var levels = Y.all('#'+name+'-criteria-'+chunks[2]+'-levels .level')
+ if (levels.size()) levels.set('width', Math.round(100/levels.size())+'%')
M.gradingform_rubriceditor.addhandlers(Y, name);
- } else if (chunks.length == 3 && action == 'moveup') {
+ } else if (chunks.length == 4 && action == 'moveup') {
// MOVE CRITERION UP
- el = Y.one('#'+name+'-'+chunks[1])
+ el = Y.one('#'+name+'-criteria-'+chunks[2])
if (el.previous()) el.get('parentNode').insertBefore(el, el.previous())
- } else if (chunks.length == 3 && action == 'movedown') {
+ } else if (chunks.length == 4 && action == 'movedown') {
// MOVE CRITERION DOWN
- el = Y.one('#'+name+'-'+chunks[1])
+ el = Y.one('#'+name+'-criteria-'+chunks[2])
if (el.next()) el.get('parentNode').insertBefore(el.next(), el)
- } else if (chunks.length == 3 && action == 'delete') {
+ } else if (chunks.length == 4 && action == 'delete') {
// DELETE CRITERION
if (confirmed) {
- Y.one('#'+name+'-'+chunks[1]).remove()
+ Y.one('#'+name+'-criteria-'+chunks[2]).remove()
} else {
dialog_options['message'] = M.str.gradingform_rubric.confirmdeletecriterion
M.util.show_confirm_dialog(e, dialog_options);
}
- } else if (chunks.length == 5 && action == 'delete') {
+ } else if (chunks.length == 6 && action == 'delete') {
// DELETE LEVEL
if (confirmed) {
- Y.one('#'+name+'-'+chunks[1]+'-'+chunks[2]+'-'+chunks[3]).remove()
+ Y.one('#'+name+'-criteria-'+chunks[2]+'-'+chunks[3]+'-'+chunks[4]).remove()
+ levels = Y.all('#'+name+'-criteria-'+chunks[2]+'-levels .level')
+ if (levels.size()) levels.set('width', Math.round(100/levels.size())+'%')
} else {
dialog_options['message'] = M.str.gradingform_rubric.confirmdeletelevel
M.util.show_confirm_dialog(e, dialog_options);
@@ -37,8 +37,21 @@
$string['criteriondelete'] = 'Delete criterion';
$string['criterionmovedown'] = 'Move down';
$string['criterionaddlevel'] = 'Add level';
-$string['scorepostfix'] = ' pts';
+$string['scorepostfix'] = ' points';
$string['leveldelete'] = 'Delete level';
$string['criterionempty'] = 'Click to edit criterion';
$string['levelempty'] = 'Click to edit level';
+
+$string['rubric'] = 'Rubric';
+$string['rubricoptions'] = 'Rubric options';
+
+$string['sortlevelsasc'] = 'Sort order for levels:';
+$string['sortlevelsasc1'] = 'Ascending by number of points';
+$string['sortlevelsasc0'] = 'Descending by number of points';
+$string['showdescriptionteacher'] = 'Display rubric description during evaluation';
+$string['showdescriptionstudent'] = 'Display rubric description to those being graded';
+$string['showscoreteacher'] = 'Display points for each level during evaluation';
+$string['showscorestudent'] = 'Display points for each level to those being graded';
+$string['enableremarks'] = 'Allow grader to add text remarks for each criteria';
+$string['showremarksstudent'] = 'Show remarks to those being graded';
@@ -38,7 +38,8 @@ class gradingform_rubric_controller extends gradingform_controller {
const DISPLAY_PREVIEW = 3; // Preview the rubric design
const DISPLAY_EVAL = 4; // For evaluation, enabled (teacher grades a student)
const DISPLAY_EVAL_FROZEN = 5; // For evaluation, with hidden fields
- const DISPLAY_REVIEW = 6; // Dispaly filled rubric (i.e. students see their grades)
+ const DISPLAY_REVIEW = 6; // Teacher reviews filled rubric
+ const DISPLAY_VIEW = 7; // Dispaly filled rubric (i.e. students see their grades)
/**
* Extends the module settings navigation with the rubric grading settings
@@ -73,8 +74,12 @@ public function update_definition(stdClass $newdefinition, $usermodified = null)
parent::update_definition((object)array('descriptionformat' => FORMAT_MOODLE), $usermodified);
parent::load_definition();
}
- $options = self::description_form_field_options($this->get_context());
- $newdefinition = file_postupdate_standard_editor($newdefinition, 'description', $options, $this->get_context(),
+ if (!isset($newdefinition->rubric['options'])) {
+ $newdefinition->rubric['options'] = self::get_default_options();
+ }
+ $newdefinition->options = json_encode($newdefinition->rubric['options']);
+ $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);
@@ -83,10 +88,10 @@ public function update_definition(stdClass $newdefinition, $usermodified = null)
// update rubric data
$haschanges = false;
- if (empty($newdefinition->rubric_criteria)) {
+ if (empty($newdefinition->rubric['criteria'])) {
$newcriteria = array();
} else {
- $newcriteria = $newdefinition->rubric_criteria; // new ones to be saved
+ $newcriteria = $newdefinition->rubric['criteria']; // new ones to be saved
}
$currentcriteria = $currentdefinition->rubric_criteria;
$criteriafields = array('sortorder', 'description', 'descriptionformat');
@@ -175,7 +180,6 @@ public function update_definition(stdClass $newdefinition, $usermodified = null)
*/
protected function load_definition() {
global $DB;
-
$sql = "SELECT gd.*,
rc.id AS rcid, rc.sortorder AS rcsortorder, rc.description AS rcdescription, rc.descriptionformat AS rcdescriptionformat,
rl.id AS rlid, rl.score AS rlscore, rl.definition AS rldefinition, rl.definitionformat AS rldefinitionformat
@@ -213,6 +217,37 @@ protected function load_definition() {
}
}
$rs->close();
+ $options = $this->get_options();
+ if (!$options['sortlevelsasc']) {
+ foreach (array_keys($this->definition->rubric_criteria) as $rcid) {
+ $this->definition->rubric_criteria[$rcid]['levels'] = array_reverse($this->definition->rubric_criteria[$rcid]['levels'], true);
+ }
+ }
+ }
+
+ public static function get_default_options() {
+ $options = array(
+ 'sortlevelsasc' => 1,
+ //'showdescriptionteacher' => 1,
+ //'showdescriptionstudent' => 1,
+ 'showscoreteacher' => 1,
+ 'showscorestudent' => 1,
+ 'enableremarks' => 1,
+ 'showremarksstudent' => 1
+ );
+ // TODO description options
+ return $options;
+ }
+
+ public function get_options() {
+ $options = self::get_default_options();
+ if (!empty($this->definition->options)) {
+ $thisoptions = json_decode($this->definition->options);
+ foreach ($thisoptions as $option => $value) {
+ $options[$option] = $value;
+ }
+ }
+ return $options;
}
/**
@@ -226,17 +261,16 @@ public function get_definition_for_editing() {
$properties = new stdClass();
$properties->areaid = $this->areaid;
if ($definition) {
- foreach (array('id', 'name', 'description', 'descriptionformat', 'options', 'status') as $key) {
+ foreach (array('id', 'name', 'description', 'descriptionformat', 'status') as $key) {
$properties->$key = $definition->$key;
}
$options = self::description_form_field_options($this->get_context());
$properties = file_prepare_standard_editor($properties, 'description', $options, $this->get_context(),
'gradingform_rubric', 'definition_description', $definition->id);
}
+ $properties->rubric = array('criteria' => array(), 'options' => $this->get_options());
if (!empty($definition->rubric_criteria)) {
- $properties->rubric_criteria = $definition->rubric_criteria;
- } else {
- $properties->rubric_criteria = array();
+ $properties->rubric['criteria'] = $definition->rubric_criteria;
}
return $properties;
@@ -252,11 +286,12 @@ public function get_definition_for_editing() {
public function get_definition_copy(gradingform_controller $target) {
$new = parent::get_definition_copy($target);
- $old = $this->get_definition();
- $new->rubric_criteria = array();
+ $old = $this->get_definition_for_editing();
+ $new->description_editor = $old->description_editor;
+ $new->rubric = array('criteria' => array(), 'options' => $old->rubric['options']);
$newcritid = 1;
$newlevid = 1;
- foreach ($old->rubric_criteria as $oldcritid => $oldcrit) {
+ foreach ($old->rubric['criteria'] as $oldcritid => $oldcrit) {
unset($oldcrit['id']);
if (isset($oldcrit['levels'])) {
foreach ($oldcrit['levels'] as $oldlevid => $oldlev) {
@@ -268,7 +303,7 @@ public function get_definition_copy(gradingform_controller $target) {
} else {
$oldcrit['levels'] = array();
}
- $new->rubric_criteria['NEWID'.$newcritid] = $oldcrit;
+ $new->rubric['criteria']['NEWID'.$newcritid] = $oldcrit;
$newcritid++;
}
@@ -337,7 +372,8 @@ public function render_preview(moodle_page $page) {
// append the rubric itself, using own renderer
$output = $this->get_renderer($page);
$criteria = $this->definition->rubric_criteria;
- $rubric = $output->display_rubric($criteria, self::DISPLAY_PREVIEW, 'rubric');
+ $options = $this->get_options();
+ $rubric = $output->display_rubric($criteria, $options, self::DISPLAY_PREVIEW, 'rubric');
return $header . $rubric;
}
@@ -556,10 +592,11 @@ public function render_grading_element($page, $gradingformelement) {
}
}
$criteria = $this->get_controller()->get_definition()->rubric_criteria;
+ $options = $this->get_controller()->get_options();
$value = $gradingformelement->getValue();
if ($value === null) {
$value = $this->get_rubric_filling();
}
- return $this->get_controller()->get_renderer($page)->display_rubric($criteria, $mode, $gradingformelement->getName(), $value);
+ return $this->get_controller()->get_renderer($page)->display_rubric($criteria, $options, $mode, $gradingformelement->getName(), $value);
}
}
Oops, something went wrong.

0 comments on commit 72e48ad

Please sign in to comment.