Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Advanced grading API: Difference between revisions

From MoodleDocs
m (Text replacement - "<code php>" to "<syntaxhighlight lang="php">")
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
== Overview ==
== Overview ==


Advanced grading is introduced in Moodle 2.2 for grading of assignments. It is intended to be used for grading of other types of activities in the later versions. Moodle will try to minimize the future API changes but still they are possible.
Advanced grading was introduced in Moodle 2.2 for grading of assignments. It is intended to be used for grading of other types of activities in the later versions. Moodle will try to minimise future API changes, but as this API is relatively new, changes are possible.


== Glossary ==
== Glossary ==


In advanced grading we operate with three main entities: grading area, grading form definition and grading form instance.  
In advanced grading we operate with three main entities: a grading area, a grading form definition and a grading form instance.  


=== Grading area ===
=== Grading area ===
Grading area is basically the area that can be graded. At the moment it is a submission in an assignment module. Each grading area may have several grading definitions but only one for each grading method. In assignment edit form (or on Advanced grading page) the teacher may set one of the advanced grading methods as current. Class grading_manager is responsible for operations with grading methods in one area.
The grading area is basically the area that can be graded, for example, a submission in an assignment module. Each grading area may have several grading definitions but only one for each grading method. In an assignment's edit form (or its Advanced grading page) the teacher may set one of the advanced grading methods as current. The class called '''grading_manager''' is responsible for grading method operations in the specified area.


=== Grading form definition ===
=== Grading form definition ===
Grading form definitions is the set of rules on how the grading is performed. For example in rubrics this is the set of criteria and levels and their display options. The basic information about definition is stored in the standard DB table grading_definitions. A separate entry is created for each grading area (i.e. for each module). Users with permission moodle/grade:managegradingforms are able to edit the definitions and mark them as Ready.
Grading form definitions are the set of rules defining how the grading is performed. For example, in rubrics this is the set of criteria and levels and their display options. The basic information about definition is stored in the DB table grading_definitions. A separate entry is created for each grading area (i.e. for each module). Users with permission moodle/grade:managegradingforms are able to edit the definitions and mark them as "Ready".


=== Grading form instance ===
=== Grading form instance ===
Grading form instance is created for each evaluation of student using advanced grading. One instance (usually the latest) has the status INSTANCE_STATUS_ACTIVE. Sometimes it may happen that teacher wants to change the definition when some students have already been graded. In this case their instances change status to INSTANCE_STATUS_NEEDUPDATE. The grade pushed to the gradebook remains unchanged but students will not see the grade in advanced grading format unless teacher updates them. Plugins are also welcome to use the statuses
A grading form instance is created for each evaluation of a submission, using advanced grading. One instance (usually the latest) has the status INSTANCE_STATUS_ACTIVE. Sometimes it may be the case that a teacher wants to change the definition after some students have already been graded. In this case their instances change status to INSTANCE_STATUS_NEEDUPDATE. The grade pushed to the gradebook remains unchanged but students will not see the grade in advanced grading format until teacher updates them. Plugins are also welcome to use these status levels.


== Functions ==
== Functions ==
Line 22: Line 22:
=== Using advanced grading in grade-able modules ===
=== Using advanced grading in grade-able modules ===


see mod/assignment/lib.php for example
The following example is drawn from '''/mod/assignment/lib.php'''.


1. function MODNAME_supports(FEATURE_ADVANCED_GRADING) must return true
# In order for module to support advanced grading, its function '''MODNAME_supports(FEATURE_ADVANCED_GRADING)''' must return true.
 
# The module should define a function called '''MODNAME_grading_areas_list()'''.
2. module should define function MODNAME_grading_areas_list()
# There needs to be a check to see if there is an advanced grading method for this area and it is available. If it is, retrieve it and set the grade range used in this module.<syntaxhighlight lang="php">
 
if ($controller = get_grading_manager(...)->get_active_controller()) {
3. Check if there is set advanced grading method for this area and it is available. If yes, retrieve it and set the grade range used in this module.
    $controller->set_grade_range(...);
        if ($controller = get_grading_manager(...)->get_active_controller()) {
    ...
            $controller->set_grade_range(...);
}
            ...
</syntaxhighlight>
        }
# There are two ways to create an grading object instance. Choose one of the following.<syntaxhighlight lang="php">
 
$gradinginstance = $controller->get_current_instance(...);
There are two ways to create an instance object:
$gradinginstance = $controller->get_or_create_instance(...);
        $gradinginstance = $controller->get_current_instance(...);
</syntaxhighlight>
        $gradinginstance = $controller->get_or_create_instance(...);
# During population of the grading form, simple grading elements can now be substituted with advanced grading element.<syntaxhighlight lang="php">
 
$mform->addElement('grading', 'ELEMENTNAME', '...', array('gradinginstance' => $gradinginstance));
- during population of grading form the simple grading element should be substituted with advanced grading element
</syntaxhighlight>
        $mform->addElement('grading', 'ELEMENTNAME', '...', array('gradinginstance' => $gradinginstance));
#On submittion of a grading form, the advanced grading information shall be also submitted. The grade for the gradebook retrieved from plugin and saved to the gradebook.<syntaxhighlight lang="php">
 
$grade = $gradinginstance->submit_and_get_grade($data->ELEMENTNAME, ...)
- on submit of grading form the advanced grading shall be also submitted and the grade for the gradebook retrieved from plugin and saved to gradebook.
</syntaxhighlight>
        $grade = $gradinginstance->submit_and_get_grade($data->ELEMENTNAME, ...)
# When the grade is displayed to the student it is displayed using the grading objects renderer.<syntaxhighlight lang="php">
 
$output .= $controller->render_grade(...);
- when the grade is displayed to the student it is displayed as:
</syntaxhighlight>
        $output .= $controller->render_grade(...);
# To show the grading method to students before they are actually graded:<syntaxhighlight lang="php">
 
$output .= $controller->render_preview($PAGE);
=== Developing advanced grading plugins ===
</syntaxhighlight>
 
see Rubrics in grade/grading/form/rubric as an example
 
Frankenstyle prefix for advanced grading plugins is gradingform. The directory to land the plugins is grade/grading/form.
 
The required files in the advanced grading plugin are:
* version.php
* lib.php
* edit.php (or other path if gradingform_controller::get_editor_url is overriden)
* lang/en/gradingform_PLUGINNAME.php
 
If plugin defines it’s own database tables and/or can be backed up and restored, the following files need to be present:
* db/install.xml
* backup/moodle2/backup_gradingform_PLUGINNAME_plugin.class.php
* backup/moodle2/restore_gradingform_PLUGINNAME_plugin.class.php
 
It also can be also very useful to have files
* renderer.php
* styles.css
 
Please refer to other parts of dev docs on how to write language file, version.php, backup/*, renderer.php and db/*.


[[Category:Plugins]]
[[Category:Plugins]]

Revision as of 13:30, 14 July 2021

Overview

Advanced grading was introduced in Moodle 2.2 for grading of assignments. It is intended to be used for grading of other types of activities in the later versions. Moodle will try to minimise future API changes, but as this API is relatively new, changes are possible.

Glossary

In advanced grading we operate with three main entities: a grading area, a grading form definition and a grading form instance.

Grading area

The grading area is basically the area that can be graded, for example, a submission in an assignment module. Each grading area may have several grading definitions but only one for each grading method. In an assignment's edit form (or its Advanced grading page) the teacher may set one of the advanced grading methods as current. The class called grading_manager is responsible for grading method operations in the specified area.

Grading form definition

Grading form definitions are the set of rules defining how the grading is performed. For example, in rubrics this is the set of criteria and levels and their display options. The basic information about definition is stored in the DB table grading_definitions. A separate entry is created for each grading area (i.e. for each module). Users with permission moodle/grade:managegradingforms are able to edit the definitions and mark them as "Ready".

Grading form instance

A grading form instance is created for each evaluation of a submission, using advanced grading. One instance (usually the latest) has the status INSTANCE_STATUS_ACTIVE. Sometimes it may be the case that a teacher wants to change the definition after some students have already been graded. In this case their instances change status to INSTANCE_STATUS_NEEDUPDATE. The grade pushed to the gradebook remains unchanged but students will not see the grade in advanced grading format until teacher updates them. Plugins are also welcome to use these status levels.

Functions

Examples

Using advanced grading in grade-able modules

The following example is drawn from /mod/assignment/lib.php.

  1. In order for module to support advanced grading, its function MODNAME_supports(FEATURE_ADVANCED_GRADING) must return true.
  2. The module should define a function called MODNAME_grading_areas_list().
  3. There needs to be a check to see if there is an advanced grading method for this area and it is available. If it is, retrieve it and set the grade range used in this module.
    if ($controller = get_grading_manager(...)->get_active_controller()) {
        $controller->set_grade_range(...);
        ...
    }
    
  4. There are two ways to create an grading object instance. Choose one of the following.
    $gradinginstance = $controller->get_current_instance(...);
    $gradinginstance = $controller->get_or_create_instance(...);
    
  5. During population of the grading form, simple grading elements can now be substituted with advanced grading element.
    $mform->addElement('grading', 'ELEMENTNAME', '...', array('gradinginstance' => $gradinginstance));
    
  6. On submittion of a grading form, the advanced grading information shall be also submitted. The grade for the gradebook retrieved from plugin and saved to the gradebook.
    $grade = $gradinginstance->submit_and_get_grade($data->ELEMENTNAME, ...)
    
  7. When the grade is displayed to the student it is displayed using the grading objects renderer.
    $output .= $controller->render_grade(...);
    
  8. To show the grading method to students before they are actually graded:
    $output .= $controller->render_preview($PAGE);