Skip to content

Commit

Permalink
MDL-30771: Enable students to view rubric definition prior to submission
Browse files Browse the repository at this point in the history
Also allow advanced grading plugin to extend course module navigation, it is not necessary only definition previewing
Added option to rubric whether to show it to the students before submission and option to view description
  • Loading branch information
marinaglancy committed Feb 10, 2012
1 parent 4d2f89f commit e8d5c5a
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 12 deletions.
13 changes: 13 additions & 0 deletions grade/grading/form/lib.php
Expand Up @@ -202,6 +202,19 @@ public function extend_settings_navigation(settings_navigation $settingsnav, nav
// do not extend by default
}

/**
* Extends the module navigation
*
* This function is called when the context for the page is an activity module with the
* FEATURE_ADVANCED_GRADING and there is an area with the active grading method set to the given plugin.
*
* @param global_navigation $navigation {@link global_navigation}
* @param navigation_node $node {@link navigation_node}
*/
public function extend_navigation(global_navigation $navigation, navigation_node $node=null) {
// do not extend by default
}

/**
* Returns the grading form definition structure
*
Expand Down
3 changes: 3 additions & 0 deletions grade/grading/form/rubric/lang/en/gradingform_rubric.php
Expand Up @@ -25,6 +25,7 @@
defined('MOODLE_INTERNAL') || die();

$string['addcriterion'] = 'Add criterion';
$string['alwaysshowdefinition'] = 'Allow users to preview rubric used in the module (otherwise rubric will only become visible after grading)';
$string['backtoediting'] = 'Back to editing';
$string['confirmdeletecriterion'] = 'Are you sure you want to delete this criterion?';
$string['confirmdeletelevel'] = 'Are you sure you want to delete this level?';
Expand All @@ -42,11 +43,13 @@
$string['err_nodescription'] = 'Criterion description 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['gradingof'] = '{$a} grading';
$string['leveldelete'] = 'Delete level';
$string['levelempty'] = 'Click to edit level';
$string['name'] = 'Name';
$string['needregrademessage'] = 'The rubric definition was changed after this student had been graded. The student can not see this rubric until you check the rubric and update the grade.';
$string['pluginname'] = 'Rubric';
$string['previewrubric'] = 'Preview rubric';
$string['regrademessage1'] = 'You are about to save changes to a rubric that has already been used for grading. Please indicate if existing grades need to be reviewed. If you set this then the rubric will be hidden from students until their item is regraded.';
$string['regrademessage5'] = 'You are about to save significant changes to a rubric that has already been used for grading. The gradebook value will be unchanged, but the rubric will be hidden from students until their item is regraded.';
$string['regradeoption0'] = 'Do not mark for regrade';
Expand Down
43 changes: 37 additions & 6 deletions grade/grading/form/rubric/lib.php
Expand Up @@ -37,8 +37,10 @@ class gradingform_rubric_controller extends gradingform_controller {
const DISPLAY_EDIT_FULL = 1;
/** Rubric display mode: Preview the rubric design with hidden fields */
const DISPLAY_EDIT_FROZEN = 2;
/** Rubric display mode: Preview the rubric design */
/** Rubric display mode: Preview the rubric design (for person with manage permission) */
const DISPLAY_PREVIEW = 3;
/** Rubric display mode: Preview the rubric (for people being graded) */
const DISPLAY_PREVIEW_GRADED= 8;
/** Rubric display mode: For evaluation, enabled (teacher grades a student) */
const DISPLAY_EVAL = 4;
/** Rubric display mode: For evaluation, with hidden fields */
Expand All @@ -64,6 +66,27 @@ public function extend_settings_navigation(settings_navigation $settingsnav, nav
null, null, new pix_icon('icon', '', 'gradingform_rubric'));
}

/**
* Extends the module navigation
*
* This function is called when the context for the page is an activity module with the
* FEATURE_ADVANCED_GRADING and there is an area with the active grading method set to the given plugin.
*
* @param global_navigation $navigation {@link global_navigation}
* @param navigation_node $node {@link navigation_node}
*/
public function extend_navigation(global_navigation $navigation, navigation_node $node=null) {
if (has_capability('moodle/grade:managegradingforms', $this->get_context())) {
// no need for preview if user can manage forms, he will have link to manage.php in settings instead
return;
}
if ($this->is_form_defined() && ($options = $this->get_options()) && !empty($options['alwaysshowdefinition'])) {
$node->add(get_string('gradingof', 'gradingform_rubric', get_grading_manager($this->get_areaid())->get_area_title()),
new moodle_url('/grade/grading/form/'.$this->get_method_name().'/preview.php', array('areaid' => $this->get_areaid())),
settings_navigation::TYPE_CUSTOM);
}
}

/**
* Saves the rubric definition into the database
*
Expand Down Expand Up @@ -330,14 +353,14 @@ protected function load_definition() {
public static function get_default_options() {
$options = array(
'sortlevelsasc' => 1,
//'showdescriptionteacher' => 1,
//'showdescriptionstudent' => 1,
'alwaysshowdefinition' => 1,
'showdescriptionteacher' => 1,
'showdescriptionstudent' => 1,
'showscoreteacher' => 1,
'showscorestudent' => 1,
'enableremarks' => 1,
'showremarksstudent' => 1
);
// TODO description options
return $options;
}

Expand Down Expand Up @@ -484,8 +507,13 @@ public function render_preview(moodle_page $page) {
$output = $this->get_renderer($page);
$criteria = $this->definition->rubric_criteria;
$options = $this->get_options();
$rubric = $output->display_rubric_mapping_explained($this->get_min_max_score());
$rubric .= $output->display_rubric($criteria, $options, self::DISPLAY_PREVIEW, 'rubric');
$rubric = '';
if (has_capability('moodle/grade:managegradingforms', $page->context)) {
$rubric .= $output->display_rubric_mapping_explained($this->get_min_max_score());
$rubric .= $output->display_rubric($criteria, $options, self::DISPLAY_PREVIEW, 'rubric');
} else {
$rubric .= $output->display_rubric($criteria, $options, self::DISPLAY_PREVIEW_GRADED, 'rubric');
}

return $rubric;
}
Expand Down Expand Up @@ -812,6 +840,9 @@ public function render_grading_element($page, $gradingformelement) {
if ($this->get_data('isrestored') && $haschanges) {
$html .= html_writer::tag('div', get_string('restoredfromdraft', 'gradingform_rubric'), array('class' => 'gradingform_rubric-restored'));
}
if (!empty($options['showdescriptionteacher'])) {
$html .= html_writer::tag('div', $this->get_controller()->get_formatted_description(), array('class' => 'gradingform_rubric-description'));
}
$html .= $this->get_controller()->get_renderer($page)->display_rubric($criteria, $options, $mode, $gradingformelement->getName(), $value);
return $html;
}
Expand Down
56 changes: 56 additions & 0 deletions grade/grading/form/rubric/preview.php
@@ -0,0 +1,56 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Preview rubric page
*
* @package gradingform_rubric
* @copyright 2011 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/config.php');
require_once(dirname(__FILE__).'/lib.php');
require_once(dirname(__FILE__).'/edit_form.php');
require_once($CFG->dirroot.'/grade/grading/lib.php');

$areaid = required_param('areaid', PARAM_INT);

$manager = get_grading_manager($areaid);

list($context, $course, $cm) = get_context_info_array($manager->get_context()->id);

require_login($course, true, $cm);

$controller = $manager->get_controller('rubric');
$options = $controller->get_options();

if (!$controller->is_form_defined() || empty($options['alwaysshowdefinition'])) {
throw new moodle_exception('nopermissions', 'error', '', get_string('previewrubric', 'gradingform_rubric'));
}

$title = get_string('gradingof', 'gradingform_rubric', $manager->get_area_title());
$PAGE->set_url(new moodle_url('/grade/grading/form/rubric/preview.php', array('areaid' => $areaid)));
$PAGE->set_title($title);
$PAGE->set_heading($title);

echo $OUTPUT->header();
echo $OUTPUT->heading($title);
if (!empty($options['showdescriptionstudent'])) {
echo $OUTPUT->box($controller->get_formatted_description(), 'gradingform_rubric-description');
}
echo $controller->render_preview($PAGE);
echo $OUTPUT->footer();
14 changes: 11 additions & 3 deletions grade/grading/form/rubric/renderer.php
Expand Up @@ -191,7 +191,7 @@ public function level_template($mode, $options, $elementname = '{NAME}', $criter
if (!$options['showscoreteacher'] && in_array($mode, array(gradingform_rubric_controller::DISPLAY_EVAL, gradingform_rubric_controller::DISPLAY_EVAL_FROZEN, gradingform_rubric_controller::DISPLAY_REVIEW))) {
$displayscore = false;
}
if (!$options['showscorestudent'] && $mode == gradingform_rubric_controller::DISPLAY_VIEW) {
if (!$options['showscorestudent'] && in_array($mode, array(gradingform_rubric_controller::DISPLAY_VIEW, gradingform_rubric_controller::DISPLAY_PREVIEW_GRADED))) {
$displayscore = false;
}
if ($displayscore) {
Expand Down Expand Up @@ -241,6 +241,7 @@ protected function rubric_template($mode, $options, $elementname, $criteriastr)
case gradingform_rubric_controller::DISPLAY_EDIT_FROZEN:
$classsuffix = ' editor frozen'; break;
case gradingform_rubric_controller::DISPLAY_PREVIEW:
case gradingform_rubric_controller::DISPLAY_PREVIEW_GRADED:
$classsuffix = ' editor preview'; break;
case gradingform_rubric_controller::DISPLAY_EVAL:
$classsuffix = ' evaluate editable'; break;
Expand Down Expand Up @@ -277,7 +278,7 @@ protected function rubric_edit_options($mode, $options) {
if ($mode != gradingform_rubric_controller::DISPLAY_EDIT_FULL
&& $mode != gradingform_rubric_controller::DISPLAY_EDIT_FROZEN
&& $mode != gradingform_rubric_controller::DISPLAY_PREVIEW) {
// Options are displayed only in edit mode
// Options are displayed only for people who can manage
return;
}
$html = html_writer::start_tag('div', array('class' => 'options'));
Expand Down Expand Up @@ -431,10 +432,17 @@ public function display_instance(gradingform_rubric_instance $instance, $idx, $c
$values = $instance->get_rubric_filling();
if ($cangrade) {
$mode = gradingform_rubric_controller::DISPLAY_REVIEW;
$showdescription = $options['showdescriptionteacher'];
} else {
$mode = gradingform_rubric_controller::DISPLAY_VIEW;
$showdescription = $options['showdescriptionstudent'];
}
return $this->display_rubric($criteria, $options, $mode, 'rubric'.$idx, $values);
$output = '';
if ($showdescription) {
$output .= $this->box($instance->get_controller()->get_formatted_description(), 'gradingform_rubric-description');
}
$output .= $this->display_rubric($criteria, $options, $mode, 'rubric'.$idx, $values);
return $output;
}

public function display_regrade_confirmation($elementname, $changelevel, $value) {
Expand Down
21 changes: 21 additions & 0 deletions grade/grading/lib.php
Expand Up @@ -454,6 +454,27 @@ public function extend_settings_navigation(settings_navigation $settingsnav, nav
}
}

/**
* Extends the module navigation with the advanced grading information
*
* This function is called when the context for the page is an activity module with the
* FEATURE_ADVANCED_GRADING.
*
* @param global_navigation $navigation
* @param navigation_node $modulenode
*/
public function extend_navigation(global_navigation $navigation, navigation_node $modulenode=null) {
$this->ensure_isset(array('context', 'component'));

$areas = $this->get_available_areas();
foreach ($areas as $areaname => $areatitle) {
$this->set_area($areaname);
if ($controller = $this->get_active_controller()) {
$controller->extend_navigation($navigation, $modulenode);
}
}
}

/**
* Returns the given method's controller in the gradable area
*
Expand Down
14 changes: 11 additions & 3 deletions lib/navigationlib.php
Expand Up @@ -1847,6 +1847,7 @@ protected function load_activity($cm, stdClass $course, navigation_node $activit
$cm = $modinfo->get_cm($cm->id);
}

$activity->nodetype = navigation_node::NODETYPE_LEAF;
$activity->make_active();
$file = $CFG->dirroot.'/mod/'.$cm->modname.'/lib.php';
$function = $cm->modname.'_extend_navigation';
Expand All @@ -1856,11 +1857,18 @@ protected function load_activity($cm, stdClass $course, navigation_node $activit
if (function_exists($function)) {
$activtyrecord = $DB->get_record($cm->modname, array('id' => $cm->instance), '*', MUST_EXIST);
$function($activity, $course, $activtyrecord, $cm);
return true;
}
}
$activity->nodetype = navigation_node::NODETYPE_LEAF;
return false;

// Allow the active advanced grading method plugin to append module navigation
$featuresfunc = $cm->modname.'_supports';
if (function_exists($featuresfunc) && $featuresfunc(FEATURE_ADVANCED_GRADING)) {
require_once($CFG->dirroot.'/grade/grading/lib.php');
$gradingman = get_grading_manager($cm->context, $cm->modname);
$gradingman->extend_navigation($this, $activity);
}

return $activity->has_children();
}
/**
* Loads user specific information into the navigation in the appropriate place.
Expand Down

0 comments on commit e8d5c5a

Please sign in to comment.