Note:

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

Grade settings modules: Difference between revisions

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


# '''Allow centralized grading''' - Shifting all grade related settings into the grade tables makes it easier to provide a centralized marking UI.
# '''Allow centralized grading''' - Shifting all grade related settings into the grade tables makes it easier to provide a centralized marking UI.
Note that this document only deals with centralizing grade settings. The centralization of grades themselves is at https://docs.moodle.org/en/Development:Grading_interface_2.0


==Interface==
==Interface==
Line 17: Line 19:
== Database structures ==
== Database structures ==


New tables to be created
===Altered tables===
=== grade_modules_settings ===
====Assignment====
 
The field assignment.grade need to be migrated to use grade_items.grade then be removed.
Holds the grade related settings for all modules. Additional columns, course id etc, may be required/desirable to make getting and setting of the settings easier.
 
{| class="nicetable"
|-
! Field
! Type
! Default
! Info
|-
| id
| int(10)
| auto-incrementing
| The unique ID for this setting.
|-
| coursemoduleid
| int(10)
|
| The PK of the associated record in course_modules - identifies the instance of module associated with the settings.
|-
| grade
| int(10)
|
| The grade
|-
| grademethod
| int(4)
|
| The grading method the module instance uses
|}
 
 
The following columns need to be migrated to the new system then removed.
 
# '''assignment''' - grade
# '''quiz''' - grade, grademethod


== Code Alterations ==
== Code Alterations ==


===Class moodleform_mod()===
===Class moodleform_mod()===
in course/moodleform_mod.php
course/moodleform_mod.php contains the definition of the class moodleform_mod. Modules extend this class to create their configuration form.


the following new method will be added
the following new method will be added
====coursemodule_grading_elements()====
====moodleform_mod::standard_grading_coursemodule_elements()====
Similar to standard_coursemodule_elements(). Adds elements to a private instance of moodle form. A new method is being added rather than adding grading elements to those already output by standard_coursemodule_elements() to allow the grading elements to appear near the top of page, just below the General section. Standard elements are usually added at the bottom of the settings. The assignment and quiz modules in 1.9 have their grade settings at the top and shifting them to the bottom would be unexpected.
Similar to standard_coursemodule_elements(). Adds elements to an instance of moodle form. A new method is being added rather than adding grading elements to those already output by standard_coursemodule_elements() to allow the grading elements to appear near the top of page, just below the General section. Standard elements are usually added at the bottom of the settings. The assignment and quiz modules in 1.9 have their grade settings at the top and shifting them to the bottom would be unexpected.


It will determine whether to include a grade and grading method element by calling plugin_supports() found in lib/moodlelib.php like this...
It will determine whether to include a grade, grading method etc element by calling plugin_supports() found in lib/moodlelib.php like this...
<code php>
<syntaxhighlight lang="php">
if (plugin_supports('mod', $mod, FEATURE_GRADE_HAS_GRADE, false)) {
if (plugin_supports('mod', $mod, FEATURE_GRADE_HAS_GRADE, false)) {
     //include grade element
     //include grade element
}
}
</code>
</syntaxhighlight>
 
mod/%modulename%/lib.php defines a function called %modulename%_supports() that lists the elements that the module supports.


===Module Enhancements===
===Module Enhancements===


Each module's mod_form.php definition() method, for example in mod/assignment/mod_form.php, will then call $this->coursemodule_grading_elements() to insert the grading elements.
====Specifying required form elements====
 
Each module's %modname%_supports() method, for example assignment_supports() in the assignment modules, will need to be checked and possibly altered to specify the modules support for a grade.
 
====Adding grading elements to module forms====
Each module's mod_form.php definition() method, for example in mod/assignment/mod_form.php, will call $this->coursemodule_grading_elements() to insert the grading elements.


Another constant like FEATURE_GRADE_HAS_GRADE called FEATURE_GRADE_HAS_GRADING_METHOD will be needed for modules like quiz that have a variable grading method.
====General module refactoring====
Affected modules will need to be refactored to reference the relocated settings like 'grade'. For example the class assignment_base has a member variable 'assignment' that consists of a row from the assignment table. This previously included the column 'grade' accessed at $this->assignment->grade. See line 121 of mod/assignment/lib.php for where it is loaded.


Each module's %modname%_supports() method, for example assignment_supports() in the assignment modules, will need to be checked and possibly altered to specify the modules support for a grade and grading method.
In addition to loading a row from the table application it will be necessary to load a row from table grade_items. Retrieve the correct row from grade_item as follow:
<syntaxhighlight lang="php">
$grade_item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>'assignment', 'iteminstance'=>1))
</syntaxhighlight>
or by joining on those columns (itemtype, itemmodule and iteminstance).


== Outstanding Issues ==
The result of the call to $DB->get_record should be assigned to $this->grade_item. The references to 'grade' ($this->assignment->grade) such as at line 823 of mod/assignment/lib.php will need to be updated to instead access grade at $this->grade_item->grade.
Where is the code that actually makes use of the module instance grade setting?

Latest revision as of 13:38, 14 July 2021

Note: This page is a work-in-progress. Feedback and suggested improvements are welcome. Please join the discussion on moodle.org or use the page comments.


Moodle 2.0


Executive Summary

Module grade settings should be provided and stored in a central location rather than being handled by each individual module. In the UI, grade settings should appear in their own section provided by grade library.

  1. Reduce duplicate code - Requiring each module to be aware of grading settings leads to unnecessary duplication of grading code.
  1. Allow centralized grading - Shifting all grade related settings into the grade tables makes it easier to provide a centralized marking UI.

Note that this document only deals with centralizing grade settings. The centralization of grades themselves is at https://docs.moodle.org/en/Development:Grading_interface_2.0

Interface

UpdatingAssignmentUI.gif

Database structures

Altered tables

Assignment

The field assignment.grade need to be migrated to use grade_items.grade then be removed.

Code Alterations

Class moodleform_mod()

course/moodleform_mod.php contains the definition of the class moodleform_mod. Modules extend this class to create their configuration form.

the following new method will be added

moodleform_mod::standard_grading_coursemodule_elements()

Similar to standard_coursemodule_elements(). Adds elements to an instance of moodle form. A new method is being added rather than adding grading elements to those already output by standard_coursemodule_elements() to allow the grading elements to appear near the top of page, just below the General section. Standard elements are usually added at the bottom of the settings. The assignment and quiz modules in 1.9 have their grade settings at the top and shifting them to the bottom would be unexpected.

It will determine whether to include a grade, grading method etc element by calling plugin_supports() found in lib/moodlelib.php like this...

if (plugin_supports('mod', $mod, FEATURE_GRADE_HAS_GRADE, false)) {
    //include grade element
}

mod/%modulename%/lib.php defines a function called %modulename%_supports() that lists the elements that the module supports.

Module Enhancements

Specifying required form elements

Each module's %modname%_supports() method, for example assignment_supports() in the assignment modules, will need to be checked and possibly altered to specify the modules support for a grade.

Adding grading elements to module forms

Each module's mod_form.php definition() method, for example in mod/assignment/mod_form.php, will call $this->coursemodule_grading_elements() to insert the grading elements.

General module refactoring

Affected modules will need to be refactored to reference the relocated settings like 'grade'. For example the class assignment_base has a member variable 'assignment' that consists of a row from the assignment table. This previously included the column 'grade' accessed at $this->assignment->grade. See line 121 of mod/assignment/lib.php for where it is loaded.

In addition to loading a row from the table application it will be necessary to load a row from table grade_items. Retrieve the correct row from grade_item as follow:

$grade_item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>'assignment', 'iteminstance'=>1))

or by joining on those columns (itemtype, itemmodule and iteminstance).

The result of the call to $DB->get_record should be assigned to $this->grade_item. The references to 'grade' ($this->assignment->grade) such as at line 823 of mod/assignment/lib.php will need to be updated to instead access grade at $this->grade_item->grade.