Skip to content

Commit

Permalink
Merge pull request #17 from marinaglancy/wip-rubricrenderer-rubric
Browse files Browse the repository at this point in the history
Better rendering of the rubrics, rubric display options
  • Loading branch information
mudrd8mz committed Oct 27, 2011
2 parents 01609c9 + 39c6f4b commit 72e48ad
Show file tree
Hide file tree
Showing 7 changed files with 418 additions and 176 deletions.
6 changes: 3 additions & 3 deletions grade/grading/form/rubric/edit_form.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public function definition() {
$form->setType('description_editor', PARAM_RAW); $form->setType('description_editor', PARAM_RAW);


// rubric editor // rubric editor
$element = $form->addElement('rubriceditor', 'rubric_criteria', 'Rubric 1'); // todo label $element = $form->addElement('rubriceditor', 'rubric', get_string('rubric', 'gradingform_rubric'));
$form->setType('rubric_criteria', PARAM_RAW); $form->setType('rubric', PARAM_RAW);
$form->addRule('rubric_criteria', '', 'rubriceditorcompleted'); //TODO how to add this rule automatically????? $form->addRule('rubric', '', 'rubriceditorcompleted'); //TODO how to add this rule automatically?????
if (array_key_exists('freezerubric', $this->_customdata) && $this->_customdata['freezerubric']) { if (array_key_exists('freezerubric', $this->_customdata) && $this->_customdata['freezerubric']) {
$element->freeze(); $element->freeze();
} }
Expand Down
38 changes: 22 additions & 16 deletions grade/grading/form/rubric/js/rubriceditor.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ M.gradingform_rubriceditor.buttonclick = function(e, Y, name, confirmed) {
if (e.target.get('type') != 'submit') return; if (e.target.get('type') != 'submit') return;
var chunks = e.target.get('id').split('-'), var chunks = e.target.get('id').split('-'),
action = chunks[chunks.length-1] action = chunks[chunks.length-1]
if (chunks[0] != name) return; if (chunks[0] != name || chunks[1] != 'criteria') return;
var elements_str var elements_str
if (chunks.length>3 || action == 'addlevel') { if (chunks.length>4 || action == 'addlevel') {
elements_str = '#rubric-'+name+' #'+name+'-'+chunks[1]+'-levels .level' elements_str = '#rubric-'+name+' #'+name+'-criteria-'+chunks[2]+'-levels .level'
} else { } else {
elements_str = '#rubric-'+name+' .criterion' elements_str = '#rubric-'+name+' .criterion'
} }
Expand All @@ -112,38 +112,44 @@ M.gradingform_rubriceditor.buttonclick = function(e, Y, name, confirmed) {
'callbackargs' : [e, Y, name, true], 'callbackargs' : [e, Y, name, true],
'callback' : M.gradingform_rubriceditor.buttonclick 'callback' : M.gradingform_rubriceditor.buttonclick
}; };
if (chunks.length == 2 && action == 'addcriterion') { if (chunks.length == 3 && action == 'addcriterion') {
// ADD NEW CRITERION // ADD NEW CRITERION
var newcriterion = M.gradingform_rubriceditor.templates[name]['criterion']. var newcriterion = M.gradingform_rubriceditor.templates[name]['criterion'].
replace(/\{CRITERION-id\}/g, 'NEWID'+newid).replace(/\{.+?\}/g, '') 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); M.gradingform_rubriceditor.addhandlers(Y, name);
} else if (chunks.length == 4 && action == 'addlevel') { } else if (chunks.length == 5 && action == 'addlevel') {
// ADD NEW LEVEL // ADD NEW LEVEL
var newlevel = M.gradingform_rubriceditor.templates[name]['level']. var newlevel = M.gradingform_rubriceditor.templates[name]['level'].
replace(/\{CRITERION-id\}/g, chunks[1]).replace(/\{LEVEL-id\}/g, 'NEWID'+newid).replace(/\{.+?\}/g, '') replace(/\{CRITERION-id\}/g, chunks[2]).replace(/\{LEVEL-id\}/g, 'NEWID'+newid).replace(/\{.+?\}/g, '')
Y.one('#'+name+'-'+chunks[1]+'-levels').append(newlevel) 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); M.gradingform_rubriceditor.addhandlers(Y, name);
} else if (chunks.length == 3 && action == 'moveup') { } else if (chunks.length == 4 && action == 'moveup') {
// MOVE CRITERION UP // 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()) 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 // 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) 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 // DELETE CRITERION
if (confirmed) { if (confirmed) {
Y.one('#'+name+'-'+chunks[1]).remove() Y.one('#'+name+'-criteria-'+chunks[2]).remove()
} else { } else {
dialog_options['message'] = M.str.gradingform_rubric.confirmdeletecriterion dialog_options['message'] = M.str.gradingform_rubric.confirmdeletecriterion
M.util.show_confirm_dialog(e, dialog_options); M.util.show_confirm_dialog(e, dialog_options);
} }
} else if (chunks.length == 5 && action == 'delete') { } else if (chunks.length == 6 && action == 'delete') {
// DELETE LEVEL // DELETE LEVEL
if (confirmed) { 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 { } else {
dialog_options['message'] = M.str.gradingform_rubric.confirmdeletelevel dialog_options['message'] = M.str.gradingform_rubric.confirmdeletelevel
M.util.show_confirm_dialog(e, dialog_options); M.util.show_confirm_dialog(e, dialog_options);
Expand Down
15 changes: 14 additions & 1 deletion grade/grading/form/rubric/lang/en/gradingform_rubric.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -37,8 +37,21 @@
$string['criteriondelete'] = 'Delete criterion'; $string['criteriondelete'] = 'Delete criterion';
$string['criterionmovedown'] = 'Move down'; $string['criterionmovedown'] = 'Move down';
$string['criterionaddlevel'] = 'Add level'; $string['criterionaddlevel'] = 'Add level';
$string['scorepostfix'] = ' pts'; $string['scorepostfix'] = ' points';
$string['leveldelete'] = 'Delete level'; $string['leveldelete'] = 'Delete level';


$string['criterionempty'] = 'Click to edit criterion'; $string['criterionempty'] = 'Click to edit criterion';
$string['levelempty'] = 'Click to edit level'; $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';
69 changes: 53 additions & 16 deletions grade/grading/form/rubric/lib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class gradingform_rubric_controller extends gradingform_controller {
const DISPLAY_PREVIEW = 3; // Preview the rubric design const DISPLAY_PREVIEW = 3; // Preview the rubric design
const DISPLAY_EVAL = 4; // For evaluation, enabled (teacher grades a student) const DISPLAY_EVAL = 4; // For evaluation, enabled (teacher grades a student)
const DISPLAY_EVAL_FROZEN = 5; // For evaluation, with hidden fields 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 * Extends the module settings navigation with the rubric grading settings
Expand Down Expand Up @@ -73,8 +74,12 @@ public function update_definition(stdClass $newdefinition, $usermodified = null)
parent::update_definition((object)array('descriptionformat' => FORMAT_MOODLE), $usermodified); parent::update_definition((object)array('descriptionformat' => FORMAT_MOODLE), $usermodified);
parent::load_definition(); parent::load_definition();
} }
$options = self::description_form_field_options($this->get_context()); if (!isset($newdefinition->rubric['options'])) {
$newdefinition = file_postupdate_standard_editor($newdefinition, 'description', $options, $this->get_context(), $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); 'gradingform_rubric', 'definition_description', $this->definition->id);
parent::update_definition($newdefinition, $usermodified); parent::update_definition($newdefinition, $usermodified);


Expand All @@ -83,10 +88,10 @@ public function update_definition(stdClass $newdefinition, $usermodified = null)


// update rubric data // update rubric data
$haschanges = false; $haschanges = false;
if (empty($newdefinition->rubric_criteria)) { if (empty($newdefinition->rubric['criteria'])) {
$newcriteria = array(); $newcriteria = array();
} else { } else {
$newcriteria = $newdefinition->rubric_criteria; // new ones to be saved $newcriteria = $newdefinition->rubric['criteria']; // new ones to be saved
} }
$currentcriteria = $currentdefinition->rubric_criteria; $currentcriteria = $currentdefinition->rubric_criteria;
$criteriafields = array('sortorder', 'description', 'descriptionformat'); $criteriafields = array('sortorder', 'description', 'descriptionformat');
Expand Down Expand Up @@ -175,7 +180,6 @@ public function update_definition(stdClass $newdefinition, $usermodified = null)
*/ */
protected function load_definition() { protected function load_definition() {
global $DB; global $DB;

$sql = "SELECT gd.*, $sql = "SELECT gd.*,
rc.id AS rcid, rc.sortorder AS rcsortorder, rc.description AS rcdescription, rc.descriptionformat AS rcdescriptionformat, 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 rl.id AS rlid, rl.score AS rlscore, rl.definition AS rldefinition, rl.definitionformat AS rldefinitionformat
Expand Down Expand Up @@ -213,6 +217,37 @@ protected function load_definition() {
} }
} }
$rs->close(); $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;
} }


/** /**
Expand All @@ -226,17 +261,16 @@ public function get_definition_for_editing() {
$properties = new stdClass(); $properties = new stdClass();
$properties->areaid = $this->areaid; $properties->areaid = $this->areaid;
if ($definition) { 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; $properties->$key = $definition->$key;
} }
$options = self::description_form_field_options($this->get_context()); $options = self::description_form_field_options($this->get_context());
$properties = file_prepare_standard_editor($properties, 'description', $options, $this->get_context(), $properties = file_prepare_standard_editor($properties, 'description', $options, $this->get_context(),
'gradingform_rubric', 'definition_description', $definition->id); 'gradingform_rubric', 'definition_description', $definition->id);
} }
$properties->rubric = array('criteria' => array(), 'options' => $this->get_options());
if (!empty($definition->rubric_criteria)) { if (!empty($definition->rubric_criteria)) {
$properties->rubric_criteria = $definition->rubric_criteria; $properties->rubric['criteria'] = $definition->rubric_criteria;
} else {
$properties->rubric_criteria = array();
} }


return $properties; return $properties;
Expand All @@ -252,11 +286,12 @@ public function get_definition_for_editing() {
public function get_definition_copy(gradingform_controller $target) { public function get_definition_copy(gradingform_controller $target) {


$new = parent::get_definition_copy($target); $new = parent::get_definition_copy($target);
$old = $this->get_definition(); $old = $this->get_definition_for_editing();
$new->rubric_criteria = array(); $new->description_editor = $old->description_editor;
$new->rubric = array('criteria' => array(), 'options' => $old->rubric['options']);
$newcritid = 1; $newcritid = 1;
$newlevid = 1; $newlevid = 1;
foreach ($old->rubric_criteria as $oldcritid => $oldcrit) { foreach ($old->rubric['criteria'] as $oldcritid => $oldcrit) {
unset($oldcrit['id']); unset($oldcrit['id']);
if (isset($oldcrit['levels'])) { if (isset($oldcrit['levels'])) {
foreach ($oldcrit['levels'] as $oldlevid => $oldlev) { foreach ($oldcrit['levels'] as $oldlevid => $oldlev) {
Expand All @@ -268,7 +303,7 @@ public function get_definition_copy(gradingform_controller $target) {
} else { } else {
$oldcrit['levels'] = array(); $oldcrit['levels'] = array();
} }
$new->rubric_criteria['NEWID'.$newcritid] = $oldcrit; $new->rubric['criteria']['NEWID'.$newcritid] = $oldcrit;
$newcritid++; $newcritid++;
} }


Expand Down Expand Up @@ -337,7 +372,8 @@ public function render_preview(moodle_page $page) {
// append the rubric itself, using own renderer // append the rubric itself, using own renderer
$output = $this->get_renderer($page); $output = $this->get_renderer($page);
$criteria = $this->definition->rubric_criteria; $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; return $header . $rubric;
} }
Expand Down Expand Up @@ -556,10 +592,11 @@ public function render_grading_element($page, $gradingformelement) {
} }
} }
$criteria = $this->get_controller()->get_definition()->rubric_criteria; $criteria = $this->get_controller()->get_definition()->rubric_criteria;
$options = $this->get_controller()->get_options();
$value = $gradingformelement->getValue(); $value = $gradingformelement->getValue();
if ($value === null) { if ($value === null) {
$value = $this->get_rubric_filling(); $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);
} }
} }
Loading

0 comments on commit 72e48ad

Please sign in to comment.