Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 39 and 402] [Versions 39 and 403]

Grading method controller for the Rubric plugin

Copyright: 2011 David Mudrak <david@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 985 lines (44 kb)
Included or required: 2 times
Referenced: 0 times
Includes or requires: 0 files

Defines 2 classes


Class: gradingform_rubric_controller  - X-Ref

This controller encapsulates the rubric grading logic

extend_settings_navigation(settings_navigation $settingsnav, navigation_node $node=null)   X-Ref
Extends the module settings navigation with the rubric grading settings

This function is called when the context for the page is an activity module with the
FEATURE_ADVANCED_GRADING, the user has the permission moodle/grade:managegradingforms
and there is an area with the active grading method set to 'rubric'.

param: settings_navigation $settingsnav {@link settings_navigation}
param: navigation_node $node {@link navigation_node}

extend_navigation(global_navigation $navigation, navigation_node $node=null)   X-Ref
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}

update_definition(stdClass $newdefinition, $usermodified = null)   X-Ref
Saves the rubric definition into the database

param: stdClass $newdefinition rubric definition data as coming from gradingform_rubric_editrubric::get_data()
param: int|null $usermodified optional userid of the author of the definition, defaults to the current user

update_or_check_rubric(stdClass $newdefinition, $usermodified = null, $doupdate = false)   X-Ref
Either saves the rubric definition into the database or check if it has been changed.
Returns the level of changes:
0 - no changes
1 - only texts or criteria sortorders are changed, students probably do not require re-grading
2 - added levels but maximum score on rubric is the same, students still may not require re-grading
3 - removed criteria or added levels or changed number of points, students require re-grading but may be re-graded automatically
4 - removed levels - students require re-grading and not all students may be re-graded automatically
5 - added criteria - all students require manual re-grading

param: stdClass $newdefinition rubric definition data as coming from gradingform_rubric_editrubric::get_data()
param: int|null $usermodified optional userid of the author of the definition, defaults to the current user
param: boolean $doupdate if true actually updates DB, otherwise performs a check

mark_for_regrade()   X-Ref
Marks all instances filled with this rubric with the status INSTANCE_STATUS_NEEDUPDATE


load_definition()   X-Ref
Loads the rubric form definition if it exists

There is a new array called 'rubric_criteria' appended to the list of parent's definition properties.

get_default_options()   X-Ref
Returns the default options for the rubric display

return: array

get_options()   X-Ref
Gets the options of this rubric definition, fills the missing options with default values

The only exception is 'lockzeropoints' - if other options are present in the json string but this
one is absent, this means that the rubric was created before Moodle 3.2 and the 0 value should be used.

return: array

get_definition_for_editing($addemptycriterion = false)   X-Ref
Converts the current definition into an object suitable for the editor form's set_data()

param: boolean $addemptycriterion whether to add an empty criterion if the rubric is completely empty (just being created)
return: stdClass

get_definition_copy(gradingform_controller $target)   X-Ref
Returns the form definition suitable for cloning into another area

param: gradingform_controller $target the controller of the new copy
return: stdClass definition structure to pass to the target's {@link update_definition()}

description_form_field_options($context)   X-Ref
Options for displaying the rubric description field in the form

param: object $context
return: array options for the form description field

get_formatted_description()   X-Ref
Formats the definition description for display on page

return: string

get_renderer(moodle_page $page)   X-Ref
Returns the rubric plugin renderer

param: moodle_page $page the target page
return: gradingform_rubric_renderer

render_preview(moodle_page $page)   X-Ref
Returns the HTML code displaying the preview of the grading form

param: moodle_page $page the target page
return: string

delete_plugin_definition()   X-Ref
Deletes the rubric definition and all the associated information


get_or_create_instance($instanceid, $raterid, $itemid)   X-Ref
If instanceid is specified and grading instance exists and it is created by this rater for
this item, this instance is returned.
If there exists a draft for this raterid+itemid, take this draft (this is the change from parent)
Otherwise new instance is created for the specified rater and itemid

param: int $instanceid
param: int $raterid
param: int $itemid
return: gradingform_instance

render_grade($page, $itemid, $gradinginfo, $defaultcontent, $cangrade)   X-Ref
Returns html code to be included in student's feedback.

param: moodle_page $page
param: int $itemid
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

sql_search_from_tables($gdid)   X-Ref
Prepare the part of the search query to append to the FROM statement

param: string $gdid the alias of grading_definitions.id column used by the caller
return: string

sql_search_where($token)   X-Ref
Prepare the parts of the SQL WHERE statement to search for the given token

The returned array cosists of the list of SQL comparions and the list of
respective parameters for the comparisons. The returned chunks will be joined
with other conditions using the OR operator.

param: string $token token to search for
return: array

get_min_max_score()   X-Ref
Calculates and returns the possible minimum and maximum score (in points) for this rubric

return: array

get_external_definition_details()   X-Ref

return: array An array containing a single key/value pair with the 'rubric_criteria' external_multiple_structure.

get_external_instance_filling_details()   X-Ref
Returns an array that defines the structure of the rubric's filling. This function is used by
the web service function core_grading_external::get_gradingform_instances().

return: An array containing a single key/value pair with the 'criteria' external_multiple_structure

Class: gradingform_rubric_instance  - X-Ref

Class to manage one rubric grading instance.

Stores information and performs actions like update, copy, validate, submit, etc.

cancel()   X-Ref
Deletes this (INCOMPLETE) instance from database.


copy($raterid, $itemid)   X-Ref
Duplicates the instance before editing (optionally substitutes raterid and/or itemid with
the specified values)

param: int $raterid value for raterid in the duplicate
param: int $itemid value for itemid in the duplicate
return: int id of the new instance

is_empty_form($elementvalue)   X-Ref
Determines whether the submitted form was empty.

param: array $elementvalue value of element submitted from the form
return: boolean true if the form is empty

clear_attempt($data)   X-Ref
Removes the attempt from the gradingform_guide_fillings table

param: array $data the attempt data

validate_grading_element($elementvalue)   X-Ref
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

get_rubric_filling($force = false)   X-Ref
Retrieves from DB and returns the data how this rubric was filled

param: boolean $force whether to force DB query even if the data is cached
return: array

update($data)   X-Ref
Updates the instance with the data received from grading form. This function may be
called via AJAX when grading is not yet completed, so it does not change the
status of the instance.

param: array $data

get_grade()   X-Ref
Calculates the grade to be pushed to the gradebook

return: float|int the valid grade from $this->get_controller()->get_grade_range()

render_grading_element($page, $gradingformelement)   X-Ref
Returns html for form element of type 'grading'.

param: moodle_page $page
param: MoodleQuickForm_grading $gradingformelement
return: string