MDL-29108: added comments, declared functions visibility, renamed variables; also fixed MDL-30240

This commit is contained in:
Marina Glancy
2011-11-14 14:53:14 +08:00
parent b1add93e47
commit 3c2b3cb3ee
7 changed files with 208 additions and 107 deletions
+5 -2
View File
@@ -570,12 +570,12 @@ abstract class gradingform_controller {
*
* @param moodle_page $page
* @param int $itemid
* @param array $grading_info result of function grade_get_grades if plugin want to use some of their info
* @param array $gradinginfo 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, $cangrade) {
public function render_grade($page, $itemid, $gradinginfo, $defaultcontent, $cangrade) {
return $defaultcontent;
}
@@ -583,6 +583,8 @@ abstract class gradingform_controller {
* Sets the range of grades used in this area. This is usually either range like 0-100
* or the scale where keys start from 1. Typical use:
* $controller->set_grade_range(make_grades_menu($gradingtype));
*
* @param array $graderange
*/
public final function set_grade_range(array $graderange) {
$this->graderange = $graderange;
@@ -590,6 +592,7 @@ abstract class gradingform_controller {
/**
* Returns the range of grades used in this area
*
* @return array
*/
public final function get_grade_range() {
+4 -4
View File
@@ -90,7 +90,7 @@ class gradingform_rubric_editrubric extends moodleform {
* @return array of "element_name"=>"error_description" if there are errors,
* or an empty array if everything is OK (true allowed for backwards compatibility too).
*/
function validation($data, $files) {
public function validation($data, $files) {
$err = parent::validation($data, $files);
$err = array();
$form = $this->_form;
@@ -116,7 +116,7 @@ class gradingform_rubric_editrubric extends moodleform {
*
* @return object submitted data; NULL if not valid or not submitted or cancelled
*/
function get_data() {
public function get_data() {
$data = parent::get_data();
if (!empty($data->saverubric)) {
$data->status = gradingform_controller::DEFINITION_STATUS_READY;
@@ -133,7 +133,7 @@ class gradingform_rubric_editrubric extends moodleform {
*
* @param gradingform_rubric_controller $controller
*/
function need_confirm_regrading($controller) {
public function need_confirm_regrading($controller) {
$data = $this->get_data();
if (isset($data->rubric['regrade'])) {
// we have already displayed the confirmation on the previous step
@@ -180,7 +180,7 @@ class gradingform_rubric_editrubric extends moodleform {
* @param string $elementname
* @return HTML_QuickForm_element
*/
function &findButton($elementname) {
protected function &findButton($elementname) {
$form = $this->_form;
$buttonar =& $form->getElement('buttonar');
$elements =& $buttonar->getElements();
+35 -10
View File
@@ -33,13 +33,20 @@ require_once($CFG->dirroot.'/grade/grading/form/lib.php');
*/
class gradingform_rubric_controller extends gradingform_controller {
// Modes of displaying the rubric (used in gradingform_rubric_renderer)
const DISPLAY_EDIT_FULL = 1; // For editing (moderator or teacher creates a rubric)
const DISPLAY_EDIT_FROZEN = 2; // Preview the rubric design with hidden fields
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; // Teacher reviews filled rubric
const DISPLAY_VIEW = 7; // Dispaly filled rubric (i.e. students see their grades)
/** Rubric display mode: For editing (moderator or teacher creates a rubric) */
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 */
const DISPLAY_PREVIEW = 3;
/** Rubric display mode: For evaluation, enabled (teacher grades a student) */
const DISPLAY_EVAL = 4;
/** Rubric display mode: For evaluation, with hidden fields */
const DISPLAY_EVAL_FROZEN = 5;
/** Rubric display mode: Teacher reviews filled rubric */
const DISPLAY_REVIEW = 6;
/** Rubric display mode: Dispaly filled rubric (i.e. students see their grades) */
const DISPLAY_VIEW = 7;
/**
* Extends the module settings navigation with the rubric grading settings
@@ -247,6 +254,9 @@ class gradingform_rubric_controller extends gradingform_controller {
return array_pop($changelevels);
}
/**
* Marks all instances filled with this rubric with the status INSTANCE_STATUS_NEEDUPDATE
*/
public function mark_for_regrade() {
global $DB;
if ($this->has_active_instances()) {
@@ -312,6 +322,11 @@ class gradingform_rubric_controller extends gradingform_controller {
}
}
/**
* Returns the default options for the rubric display
*
* @return array
*/
public static function get_default_options() {
$options = array(
'sortlevelsasc' => 1,
@@ -326,6 +341,11 @@ class gradingform_rubric_controller extends gradingform_controller {
return $options;
}
/**
* Gets the options of this rubric definition, fills the missing options with default values
*
* @return array
*/
public function get_options() {
$options = self::get_default_options();
if (!empty($this->definition->options)) {
@@ -398,6 +418,9 @@ class gradingform_rubric_controller extends gradingform_controller {
}
/**
* Options for displaying the rubric description field in the form
*
* @param object $context
* @return array options for the form description field
*/
public static function description_form_field_options($context) {
@@ -437,7 +460,7 @@ class gradingform_rubric_controller extends gradingform_controller {
* Returns the rubric plugin renderer
*
* @param moodle_page $page the target page
* @return renderer_base
* @return gradingform_rubric_renderer
*/
public function get_renderer(moodle_page $page) {
return $page->get_renderer('gradingform_'. $this->get_method_name());
@@ -519,12 +542,12 @@ class gradingform_rubric_controller extends gradingform_controller {
*
* @param moodle_page $page
* @param int $itemid
* @param array $grading_info result of function grade_get_grades
* @param array $gradinginfo result of function grade_get_grades
* @param string $defaultcontent default string to be returned if no active grading is found
* @param boolean $cangrade whether current user has capability to grade in this context
* @return string
*/
public function render_grade($page, $itemid, $grading_info, $defaultcontent, $cangrade) {
public function render_grade($page, $itemid, $gradinginfo, $defaultcontent, $cangrade) {
return $this->get_renderer($page)->display_instances($this->get_active_instances($itemid), $defaultcontent, $cangrade);
}
@@ -610,6 +633,8 @@ class gradingform_rubric_instance extends gradingform_instance {
/**
* Validates that rubric is fully completed and contains valid grade on each criterion
*
* @param array $elementvalue value of element as came in form submit
* @return boolean true if the form data is validated and contains no errors
*/
public function validate_grading_element($elementvalue) {
+69 -61
View File
@@ -47,11 +47,11 @@ class gradingform_rubric_renderer extends plugin_renderer_base {
* @param int $mode rubric display mode @see gradingform_rubric_controller
* @param string $elementname the name of the form element (in editor mode) or the prefix for div ids (in view mode)
* @param array|null $criterion criterion data
* @param string $levels_str evaluated templates for this criterion levels
* @param string $levelsstr evaluated templates for this criterion levels
* @param array|null $value (only in view mode) teacher's feedback on this criterion
* @return string
*/
public function criterion_template($mode, $options, $elementname = '{NAME}', $criterion = null, $levels_str = '{LEVELS}', $value = null) {
public function criterion_template($mode, $options, $elementname = '{NAME}', $criterion = null, $levelsstr = '{LEVELS}', $value = null) {
// TODO description format, remark format
if ($criterion === null || !is_array($criterion) || !array_key_exists('id', $criterion)) {
$criterion = array('id' => '{CRITERION-id}', 'description' => '{CRITERION-description}', 'sortorder' => '{CRITERION-sortorder}', 'class' => '{CRITERION-class}');
@@ -63,22 +63,22 @@ class gradingform_rubric_renderer extends plugin_renderer_base {
}
}
}
$criterion_template = html_writer::start_tag('tr', array('class' => 'criterion'. $criterion['class'], 'id' => '{NAME}-criteria-{CRITERION-id}'));
$criteriontemplate = html_writer::start_tag('tr', array('class' => 'criterion'. $criterion['class'], 'id' => '{NAME}-criteria-{CRITERION-id}'));
if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FULL) {
$criterion_template .= html_writer::start_tag('td', array('class' => 'controls'));
$criteriontemplate .= html_writer::start_tag('td', array('class' => 'controls'));
foreach (array('moveup', 'delete', 'movedown') as $key) {
$value = get_string('criterion'.$key, 'gradingform_rubric');
$button = html_writer::empty_tag('input', array('type' => 'submit', 'name' => '{NAME}[criteria][{CRITERION-id}]['.$key.']',
'id' => '{NAME}-criteria-{CRITERION-id}-'.$key, 'value' => $value, 'title' => $value, 'tabindex' => -1));
$criterion_template .= html_writer::tag('div', $button, array('class' => $key));
$criteriontemplate .= html_writer::tag('div', $button, array('class' => $key));
}
$criterion_template .= html_writer::end_tag('td'); // .controls
$criterion_template .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][sortorder]', 'value' => $criterion['sortorder']));
$criteriontemplate .= html_writer::end_tag('td'); // .controls
$criteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][sortorder]', 'value' => $criterion['sortorder']));
$description = html_writer::tag('textarea', htmlspecialchars($criterion['description']), array('name' => '{NAME}[criteria][{CRITERION-id}][description]', 'cols' => '10', 'rows' => '5'));
} else {
if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FROZEN) {
$criterion_template .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][sortorder]', 'value' => $criterion['sortorder']));
$criterion_template .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][description]', 'value' => $criterion['description']));
$criteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][sortorder]', 'value' => $criterion['sortorder']));
$criteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][description]', 'value' => $criterion['description']));
}
$description = $criterion['description'];
}
@@ -86,18 +86,18 @@ class gradingform_rubric_renderer extends plugin_renderer_base {
if (isset($criterion['error_description'])) {
$descriptionclass .= ' error';
}
$criterion_template .= html_writer::tag('td', $description, array('class' => $descriptionclass, 'id' => '{NAME}-criteria-{CRITERION-id}-description'));
$levels_str_table = html_writer::tag('table', html_writer::tag('tr', $levels_str, array('id' => '{NAME}-criteria-{CRITERION-id}-levels')));
$criteriontemplate .= html_writer::tag('td', $description, array('class' => $descriptionclass, 'id' => '{NAME}-criteria-{CRITERION-id}-description'));
$levelsstrtable = html_writer::tag('table', html_writer::tag('tr', $levelsstr, array('id' => '{NAME}-criteria-{CRITERION-id}-levels')));
$levelsclass = 'levels';
if (isset($criterion['error_levels'])) {
$levelsclass .= ' error';
}
$criterion_template .= html_writer::tag('td', $levels_str_table, array('class' => $levelsclass));
$criteriontemplate .= html_writer::tag('td', $levelsstrtable, array('class' => $levelsclass));
if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FULL) {
$value = get_string('criterionaddlevel', 'gradingform_rubric');
$button = html_writer::empty_tag('input', array('type' => 'submit', 'name' => '{NAME}[criteria][{CRITERION-id}][levels][addlevel]',
'id' => '{NAME}-criteria-{CRITERION-id}-levels-addlevel', 'value' => $value, 'title' => $value));
$criterion_template .= html_writer::tag('td', $button, array('class' => 'addlevel'));
$criteriontemplate .= html_writer::tag('td', $button, array('class' => 'addlevel'));
}
$displayremark = ($options['enableremarks'] && ($mode != gradingform_rubric_controller::DISPLAY_VIEW || $options['showremarksstudent']));
if ($displayremark) {
@@ -107,18 +107,18 @@ class gradingform_rubric_renderer extends plugin_renderer_base {
}
if ($mode == gradingform_rubric_controller::DISPLAY_EVAL) {
$input = html_writer::tag('textarea', htmlspecialchars($currentremark), array('name' => '{NAME}[criteria][{CRITERION-id}][remark]', 'cols' => '10', 'rows' => '5'));
$criterion_template .= html_writer::tag('td', $input, array('class' => 'remark'));
$criteriontemplate .= html_writer::tag('td', $input, array('class' => 'remark'));
} else if ($mode == gradingform_rubric_controller::DISPLAY_EVAL_FROZEN) {
$criterion_template .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][remark]', 'value' => $currentremark));
$criteriontemplate .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][remark]', 'value' => $currentremark));
}else if ($mode == gradingform_rubric_controller::DISPLAY_REVIEW || $mode == gradingform_rubric_controller::DISPLAY_VIEW) {
$criterion_template .= html_writer::tag('td', $currentremark, array('class' => 'remark')); // TODO maybe some prefix here like 'Teacher remark:'
$criteriontemplate .= html_writer::tag('td', $currentremark, array('class' => 'remark')); // TODO maybe some prefix here like 'Teacher remark:'
}
}
$criterion_template .= html_writer::end_tag('tr'); // .criterion
$criteriontemplate .= html_writer::end_tag('tr'); // .criterion
$criterion_template = str_replace('{NAME}', $elementname, $criterion_template);
$criterion_template = str_replace('{CRITERION-id}', $criterion['id'], $criterion_template);
return $criterion_template;
$criteriontemplate = str_replace('{NAME}', $elementname, $criteriontemplate);
$criteriontemplate = str_replace('{CRITERION-id}', $criterion['id'], $criteriontemplate);
return $criteriontemplate;
}
/**
@@ -160,15 +160,15 @@ class gradingform_rubric_renderer extends plugin_renderer_base {
if (isset($level['tdwidth'])) {
$tdattributes['width'] = round($level['tdwidth']).'%';
}
$level_template = html_writer::start_tag('td', $tdattributes);
$level_template .= html_writer::start_tag('div', array('class' => 'level-wrapper'));
$leveltemplate = html_writer::start_tag('td', $tdattributes);
$leveltemplate .= html_writer::start_tag('div', array('class' => 'level-wrapper'));
if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FULL) {
$definition = html_writer::tag('textarea', htmlspecialchars($level['definition']), array('name' => '{NAME}[criteria][{CRITERION-id}][levels][{LEVEL-id}][definition]', 'cols' => '10', 'rows' => '4'));
$score = html_writer::empty_tag('input', array('type' => 'text', 'name' => '{NAME}[criteria][{CRITERION-id}][levels][{LEVEL-id}][score]', 'size' => '4', 'value' => $level['score']));
} else {
if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FROZEN) {
$level_template .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][levels][{LEVEL-id}][definition]', 'value' => $level['definition']));
$level_template .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][levels][{LEVEL-id}][score]', 'value' => $level['score']));
$leveltemplate .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][levels][{LEVEL-id}][definition]', 'value' => $level['definition']));
$leveltemplate .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][levels][{LEVEL-id}][score]', 'value' => $level['score']));
}
$definition = $level['definition'];
$score = $level['score'];
@@ -176,17 +176,17 @@ class gradingform_rubric_renderer extends plugin_renderer_base {
if ($mode == gradingform_rubric_controller::DISPLAY_EVAL) {
$input = html_writer::empty_tag('input', array('type' => 'radio', 'name' => '{NAME}[criteria][{CRITERION-id}][levelid]', 'value' => $level['id']) +
($level['checked'] ? array('checked' => 'checked') : array()));
$level_template .= html_writer::tag('div', $input, array('class' => 'radio'));
$leveltemplate .= html_writer::tag('div', $input, array('class' => 'radio'));
}
if ($mode == gradingform_rubric_controller::DISPLAY_EVAL_FROZEN && $level['checked']) {
$level_template .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][levelid]', 'value' => $level['id']));
$leveltemplate .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => '{NAME}[criteria][{CRITERION-id}][levelid]', 'value' => $level['id']));
}
$score = html_writer::tag('span', $score, array('id' => '{NAME}-criteria-{CRITERION-id}-levels-{LEVEL-id}-score'));
$definitionclass = 'definition';
if (isset($level['error_definition'])) {
$definitionclass .= ' error';
}
$level_template .= html_writer::tag('div', $definition, array('class' => $definitionclass, 'id' => '{NAME}-criteria-{CRITERION-id}-levels-{LEVEL-id}-definition'));
$leveltemplate .= html_writer::tag('div', $definition, array('class' => $definitionclass, 'id' => '{NAME}-criteria-{CRITERION-id}-levels-{LEVEL-id}-definition'));
$displayscore = true;
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;
@@ -199,20 +199,20 @@ class gradingform_rubric_renderer extends plugin_renderer_base {
if (isset($level['error_score'])) {
$scoreclass .= ' error';
}
$level_template .= html_writer::tag('div', get_string('scorepostfix', 'gradingform_rubric', $score), array('class' => $scoreclass));
$leveltemplate .= html_writer::tag('div', get_string('scorepostfix', 'gradingform_rubric', $score), array('class' => $scoreclass));
}
if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FULL) {
$value = get_string('leveldelete', 'gradingform_rubric');
$button = html_writer::empty_tag('input', array('type' => 'submit', 'name' => '{NAME}[criteria][{CRITERION-id}][levels][{LEVEL-id}][delete]', 'id' => '{NAME}-criteria-{CRITERION-id}-levels-{LEVEL-id}-delete', 'value' => $value, 'title' => $value, 'tabindex' => -1));
$level_template .= html_writer::tag('div', $button, array('class' => 'delete'));
$leveltemplate .= html_writer::tag('div', $button, array('class' => 'delete'));
}
$level_template .= html_writer::end_tag('div'); // .level-wrapper
$level_template .= html_writer::end_tag('td'); // .level
$leveltemplate .= html_writer::end_tag('div'); // .level-wrapper
$leveltemplate .= html_writer::end_tag('td'); // .level
$level_template = str_replace('{NAME}', $elementname, $level_template);
$level_template = str_replace('{CRITERION-id}', $criterionid, $level_template);
$level_template = str_replace('{LEVEL-id}', $level['id'], $level_template);
return $level_template;
$leveltemplate = str_replace('{NAME}', $elementname, $leveltemplate);
$leveltemplate = str_replace('{CRITERION-id}', $criterionid, $leveltemplate);
$leveltemplate = str_replace('{LEVEL-id}', $level['id'], $leveltemplate);
return $leveltemplate;
}
/**
@@ -230,10 +230,10 @@ class gradingform_rubric_renderer extends plugin_renderer_base {
*
* @param int $mode rubric display mode @see gradingform_rubric_controller
* @param string $elementname the name of the form element (in editor mode) or the prefix for div ids (in view mode)
* @param string $criteria_str evaluated templates for this rubric's criteria
* @param string $criteriastr evaluated templates for this rubric's criteria
* @return string
*/
protected function rubric_template($mode, $options, $elementname, $criteria_str) {
protected function rubric_template($mode, $options, $elementname, $criteriastr) {
$classsuffix = ''; // CSS suffix for class of the main div. Depends on the mode
switch ($mode) {
case gradingform_rubric_controller::DISPLAY_EDIT_FULL:
@@ -252,19 +252,27 @@ class gradingform_rubric_renderer extends plugin_renderer_base {
$classsuffix = ' view'; break;
}
$rubric_template = html_writer::start_tag('div', array('id' => 'rubric-{NAME}', 'class' => 'clearfix gradingform_rubric'.$classsuffix));
$rubric_template .= html_writer::tag('table', $criteria_str, array('class' => 'criteria', 'id' => '{NAME}-criteria'));
$rubrictemplate = html_writer::start_tag('div', array('id' => 'rubric-{NAME}', 'class' => 'clearfix gradingform_rubric'.$classsuffix));
$rubrictemplate .= html_writer::tag('table', $criteriastr, array('class' => 'criteria', 'id' => '{NAME}-criteria'));
if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FULL) {
$value = get_string('addcriterion', 'gradingform_rubric');
$input = html_writer::empty_tag('input', array('type' => 'submit', 'name' => '{NAME}[criteria][addcriterion]', 'id' => '{NAME}-criteria-addcriterion', 'value' => $value, 'title' => $value));
$rubric_template .= html_writer::tag('div', $input, array('class' => 'addcriterion'));
$rubrictemplate .= html_writer::tag('div', $input, array('class' => 'addcriterion'));
}
$rubric_template .= $this->rubric_edit_options($mode, $options);
$rubric_template .= html_writer::end_tag('div');
$rubrictemplate .= $this->rubric_edit_options($mode, $options);
$rubrictemplate .= html_writer::end_tag('div');
return str_replace('{NAME}', $elementname, $rubric_template);
return str_replace('{NAME}', $elementname, $rubrictemplate);
}
/**
* Generates html template to view/edit the rubric options. Expression {NAME} is used in
* template for the form element name
*
* @param int $mode
* @param array $options
* @return string
*/
protected function rubric_edit_options($mode, $options) {
if ($mode != gradingform_rubric_controller::DISPLAY_EDIT_FULL
&& $mode != gradingform_rubric_controller::DISPLAY_EDIT_FROZEN
@@ -285,8 +293,8 @@ class gradingform_rubric_renderer extends plugin_renderer_base {
$value = (int)(!!$value); // make sure $value is either 0 or 1
if ($mode == gradingform_rubric_controller::DISPLAY_EDIT_FULL) {
$selectoptions = array(0 => get_string($option.'0', 'gradingform_rubric'), 1 => get_string($option.'1', 'gradingform_rubric'));
$value_str = html_writer::select($selectoptions, $attrs['name'], $value, false, array('id' => $attrs['id']));
$html .= html_writer::tag('span', $value_str, array('class' => 'value'));
$valuestr = html_writer::select($selectoptions, $attrs['name'], $value, false, array('id' => $attrs['id']));
$html .= html_writer::tag('span', $valuestr, array('class' => 'value'));
// TODO add here button 'Sort levels'
} else {
$html .= html_writer::tag('span', get_string($option.$value, 'gradingform_rubric'), array('class' => 'value'));
@@ -335,12 +343,12 @@ class gradingform_rubric_renderer extends plugin_renderer_base {
* @return string
*/
public function display_rubric($criteria, $options, $mode, $elementname = null, $values = null) {
$criteria_str = '';
$criteriastr = '';
$cnt = 0;
foreach ($criteria as $id => $criterion) {
$criterion['class'] = $this->get_css_class_suffix($cnt++, sizeof($criteria) -1);
$criterion['id'] = $id;
$levels_str = '';
$levelsstr = '';
$levelcnt = 0;
if (isset($values['criteria'][$id])) {
$criterionvalue = $values['criteria'][$id];
@@ -359,29 +367,29 @@ class gradingform_rubric_renderer extends plugin_renderer_base {
$level['class'] .= ' currentchecked';
}
$level['tdwidth'] = 100/count($criterion['levels']);
$levels_str .= $this->level_template($mode, $options, $elementname, $id, $level);
$levelsstr .= $this->level_template($mode, $options, $elementname, $id, $level);
}
$criteria_str .= $this->criterion_template($mode, $options, $elementname, $criterion, $levels_str, $criterionvalue);
$criteriastr .= $this->criterion_template($mode, $options, $elementname, $criterion, $levelsstr, $criterionvalue);
}
return $this->rubric_template($mode, $options, $elementname, $criteria_str);
return $this->rubric_template($mode, $options, $elementname, $criteriastr);
}
/**
* Help function to return CSS class names for element (first/last/even/odd) with leading space
*
* @param int $cnt
* @param int $maxcnt
* @param int $idx index of this element in the row/column
* @param int $maxidx maximum index of the element in the row/column
* @return string
*/
protected function get_css_class_suffix($cnt, $maxcnt) {
protected function get_css_class_suffix($idx, $maxidx) {
$class = '';
if ($cnt == 0) {
if ($idx == 0) {
$class .= ' first';
}
if ($cnt == $maxcnt) {
if ($idx == $maxidx) {
$class .= ' last';
}
if ($cnt%2) {
if ($idx%2) {
$class .= ' odd';
} else {
$class .= ' even';
@@ -398,16 +406,16 @@ class gradingform_rubric_renderer extends plugin_renderer_base {
* @return string
*/
public function display_instances($instances, $defaultcontent, $cangrade) {
$rv = '';
$return = '';
if (sizeof($instances)) {
$rv .= html_writer::start_tag('div', array('class' => 'advancedgrade'));
$return .= html_writer::start_tag('div', array('class' => 'advancedgrade'));
$idx = 0;
foreach ($instances as $instance) {
$rv .= $this->display_instance($instance, $idx++, $cangrade);
$return .= $this->display_instance($instance, $idx++, $cangrade);
}
$rv .= html_writer::end_tag('div');
$return .= html_writer::end_tag('div');
}
return $rv. $defaultcontent;
return $return. $defaultcontent;
}
/**
+48 -15
View File
@@ -27,24 +27,51 @@ defined('MOODLE_INTERNAL') || die();
require_once("HTML/QuickForm/input.php");
class MoodleQuickForm_rubriceditor extends HTML_QuickForm_input {
/** help message */
public $_helpbutton = '';
protected $validationerrors = null; // null - undefined, false - no errors, string - error(s) text
protected $wasvalidated = false; // if element has already been validated
protected $nonjsbuttonpressed = false; // null - unknown, true/false - button was/wasn't pressed
/** stores the result of the last validation: null - undefined, false - no errors, string - error(s) text */
protected $validationerrors = null;
/** if element has already been validated **/
protected $wasvalidated = false;
/** If non-submit (JS) button was pressed: null - unknown, true/false - button was/wasn't pressed */
protected $nonjsbuttonpressed = false;
/** Message to display in front of the editor (that there exist grades on this rubric being edited) */
protected $regradeconfirmation = false;
function MoodleQuickForm_rubriceditor($elementName=null, $elementLabel=null, $attributes=null) {
parent::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
}
function getHelpButton() {
/**
* set html for help button
*
* @access public
* @param array $help array of arguments to make a help button
* @param string $function function name to call to get html
*/
public function setHelpButton($helpbuttonargs, $function='helpbutton'){
debugging('component setHelpButton() is not used any more, please use $mform->setHelpButton() instead');
}
/**
* get html for help button
*
* @access public
* @return string html for help button
*/
public function getHelpButton() {
return $this->_helpbutton;
}
function getElementTemplateType() {
/**
* The renderer will take care itself about different display in normal and frozen states
*
* @return string
*/
public function getElementTemplateType() {
return 'default';
}
protected $regradeconfirmation = false;
/**
* Specifies that confirmation about re-grading needs to be added to this rubric editor.
* $changelevel is saved in $this->regradeconfirmation and retrieved in toHtml()
@@ -52,7 +79,7 @@ class MoodleQuickForm_rubriceditor extends HTML_QuickForm_input {
* @see gradingform_rubric_controller::update_or_check_rubric()
* @param int $changelevel
*/
function add_regrade_confirmation($changelevel) {
public function add_regrade_confirmation($changelevel) {
$this->regradeconfirmation = $changelevel;
}
@@ -61,7 +88,7 @@ class MoodleQuickForm_rubriceditor extends HTML_QuickForm_input {
*
* @return string
*/
function toHtml() {
public function toHtml() {
global $PAGE;
$html = $this->_getTabs();
$renderer = $PAGE->get_renderer('gradingform_rubric');
@@ -112,7 +139,7 @@ class MoodleQuickForm_rubriceditor extends HTML_QuickForm_input {
* @param boolean $withvalidation whether to enable data validation
* @return array
*/
function prepare_data($value = null, $withvalidation = false) {
protected function prepare_data($value = null, $withvalidation = false) {
if (null === $value) {
$value = $this->getValue();
}
@@ -191,7 +218,7 @@ class MoodleQuickForm_rubriceditor extends HTML_QuickForm_input {
}
if (!array_key_exists('delete', $level)) {
if ($withvalidation) {
if (empty($level['definition'])) {
if (!strlen(trim($level['definition']))) {
$errors['err_nodefinition'] = 1;
$level['error_definition'] = true;
}
@@ -217,7 +244,7 @@ class MoodleQuickForm_rubriceditor extends HTML_QuickForm_input {
$errors['err_mintwolevels'] = 1;
$criterion['error_levels'] = true;
}
if (empty($criterion['description'])) {
if (!strlen(trim($criterion['description']))) {
$errors['err_nodescription'] = 1;
$criterion['error_description'] = true;
}
@@ -274,7 +301,13 @@ class MoodleQuickForm_rubriceditor extends HTML_QuickForm_input {
return $return;
}
function get_next_id($ids) {
/**
* Scans array $ids to find the biggest element ! NEWID*, increments it by 1 and returns
*
* @param array $ids
* @return string
*/
protected function get_next_id($ids) {
$maxid = 0;
foreach ($ids as $id) {
if (preg_match('/^NEWID(\d+)$/', $id, $matches) && ((int)$matches[1]) > $maxid) {
@@ -293,7 +326,7 @@ class MoodleQuickForm_rubriceditor extends HTML_QuickForm_input {
* @param array $value
* @return boolean true if non-submit button was pressed and not processed by JS
*/
function non_js_button_pressed($value) {
public function non_js_button_pressed($value) {
if ($this->nonjsbuttonpressed === null) {
$this->prepare_data($value);
}
@@ -308,7 +341,7 @@ class MoodleQuickForm_rubriceditor extends HTML_QuickForm_input {
* @param array $value
* @return string|false error text or false if no errors found
*/
function validate($value) {
public function validate($value) {
if (!$this->wasvalidated) {
$this->prepare_data($value, true);
}
@@ -323,7 +356,7 @@ class MoodleQuickForm_rubriceditor extends HTML_QuickForm_input {
* @param boolean $assoc
* @return array
*/
function exportValue(&$submitValues, $assoc = false) {
public function exportValue(&$submitValues, $assoc = false) {
$value = $this->prepare_data($this->_findValue($submitValues));
return $this->_prepareValue($value, $assoc);
}
+30 -8
View File
@@ -54,7 +54,15 @@ class MoodleQuickForm_grading extends HTML_QuickForm_input{
*/
private $gradingattributes;
function MoodleQuickForm_grading($elementName=null, $elementLabel=null, $attributes=null) {
/**
* Class constructor
*
* @param string $elementName Input field name attribute
* @param mixed $elementLabel Label(s) for the input field
* @param mixed $attributes Either a typical HTML attribute string or an associative array
* @return void
*/
public function MoodleQuickForm_grading($elementName=null, $elementLabel=null, $attributes=null) {
parent::HTML_QuickForm_input($elementName, $elementLabel, $attributes);
$this->gradingattributes = $attributes;
}
@@ -64,7 +72,7 @@ class MoodleQuickForm_grading extends HTML_QuickForm_input{
*
* @return gradingform_instance
*/
function get_gradinginstance() {
public function get_gradinginstance() {
if (is_array($this->gradingattributes) && array_key_exists('gradinginstance', $this->gradingattributes)) {
return $this->gradingattributes['gradinginstance'];
} else {
@@ -77,7 +85,7 @@ class MoodleQuickForm_grading extends HTML_QuickForm_input{
*
* @return string
*/
function toHtml(){
public function toHtml(){
global $PAGE;
return $this->get_gradinginstance()->render_grading_element($PAGE, $this);
}
@@ -89,7 +97,7 @@ class MoodleQuickForm_grading extends HTML_QuickForm_input{
* @param array $help array of arguments to make a help button
* @param string $function function name to call to get html
*/
function setHelpButton($helpbuttonargs, $function='helpbutton'){
public function setHelpButton($helpbuttonargs, $function='helpbutton'){
debugging('component setHelpButton() is not used any more, please use $mform->setHelpButton() instead');
}
@@ -99,21 +107,32 @@ class MoodleQuickForm_grading extends HTML_QuickForm_input{
* @access public
* @return string html for help button
*/
function getHelpButton(){
public function getHelpButton(){
return $this->_helpbutton;
}
/**
* The renderer of gradingform_instance will take care itself about different display
* in normal and frozen states
*
* @return string
*/
function getElementTemplateType(){
public function getElementTemplateType(){
return 'default';
}
/**
* Adds necessary rules to the element
* Called by HTML_QuickForm whenever form event is made on this element.
* Adds necessary rules to the element and checks that coorenct instance of gradingform_instance
* is passed in attributes
*
* @param string $event Name of event
* @param mixed $arg event arguments
* @param object $caller calling object
* @return void
* @throws moodle_exception
*/
function onQuickFormEvent($event, $arg, &$caller) {
public function onQuickFormEvent($event, $arg, &$caller) {
if ($event == 'createElement') {
$attributes = $arg[2];
if (!is_array($attributes) || !array_key_exists('gradinginstance', $attributes) || !($attributes['gradinginstance'] instanceof gradingform_instance)) {
@@ -131,6 +150,9 @@ class MoodleQuickForm_grading extends HTML_QuickForm_input{
/**
* Function registered as rule for this element and is called when this element is being validated.
* This is a wrapper to pass the validation to the method gradingform_instance::validate_grading_element
*
* @param mixed $elementValue
* @param array $attributes
*/
static function _validate($elementValue, $attributes = null) {
return $attributes['gradinginstance']->validate_grading_element($elementValue);
+17 -7
View File
@@ -332,12 +332,12 @@ class assignment_base {
echo '<tr>';
echo '<td class="left side">&nbsp;</td>';
echo '<td class="content">';
$grade_str = '<div class="grade">'. get_string("grade").': '.$grade->str_long_grade. '</div>';
$gradestr = '<div class="grade">'. get_string("grade").': '.$grade->str_long_grade. '</div>';
if (!empty($submission) && $controller = get_grading_manager($this->context, 'mod_assignment', 'submission')->get_active_controller()) {
$controller->set_grade_range(make_grades_menu($this->assignment->grade));
echo $controller->render_grade($PAGE, $submission->id, $item, $grade_str, has_capability('mod/assignment:grade', $this->context));
echo $controller->render_grade($PAGE, $submission->id, $item, $gradestr, has_capability('mod/assignment:grade', $this->context));
} else {
echo $grade_str;
echo $gradestr;
}
echo '<div class="clearer"></div>';
@@ -1607,8 +1607,17 @@ class assignment_base {
* from advanced grading (if applicable) and returns true
* If the form was submitted, validates it and returns false if validation did not pass.
* If validation passes, preprocess advanced grading (if applicable) and returns true.
*
* Note to the developers: This is NOT the correct way to implement advanced grading
* in grading form. The assignment grading was written long time ago and unfortunately
* does not fully use the mforms. Usually function is_validated() is called to
* validate the form and get_data() is called to get the data from the form.
*
* Here we have to push the calculated grade to $_POST['xgrade'] because further processing
* of the form gets the data not from form->get_data(), but from $_POST (using statement
* like $feedback = data_submitted() )
*/
function validate_and_preprocess_feedback() {
protected function validate_and_preprocess_feedback() {
global $USER, $CFG;
require_once($CFG->libdir.'/gradelib.php');
if (!($feedback = data_submitted()) || !isset($feedback->userid) || !isset($feedback->offset)) {
@@ -1616,8 +1625,8 @@ class assignment_base {
}
$userid = required_param('userid', PARAM_INT);
$offset = required_param('offset', PARAM_INT);
$grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array($userid));
$gradingdisabled = $grading_info->items[0]->grades[$userid]->locked || $grading_info->items[0]->grades[$userid]->overridden;
$gradinginfo = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, array($userid));
$gradingdisabled = $gradinginfo->items[0]->grades[$userid]->locked || $gradinginfo->items[0]->grades[$userid]->overridden;
if ($gradingdisabled) {
return true;
}
@@ -2322,6 +2331,8 @@ class assignment_base {
class mod_assignment_grading_form extends moodleform {
/** @var stores the advaned grading instance (if used in grading) */
private $advancegradinginstance;
function definition() {
global $OUTPUT;
@@ -2376,7 +2387,6 @@ class mod_assignment_grading_form extends moodleform {
}
private $advancegradinginstance;
/**
* Gets or sets the instance for advanced grading
*