Gradebook API: Difference between revisions
Andrew Davis (talk | contribs) |
Andrew Davis (talk | contribs) No edit summary |
||
Line 17: | Line 17: | ||
grade_get_grades() is used to retrieve grade information about a given activity. Optionally you can retrieve student grades for that activity. | grade_get_grades() is used to retrieve grade information about a given activity. Optionally you can retrieve student grades for that activity. | ||
==Infrastructure Required From | ==Infrastructure Required From a Custom Activity Module== | ||
===/mod/ | ===/mod/$modname/grade.php=== | ||
A teacher or student clicking on the activity name in the gradebook is sent to grade.php within the activities directory. It should redirect the user to the appropriate page. For example, sending students to the activity itself while sending teachers to a list of students who have completed the activity. | A teacher or student clicking on the activity name in the gradebook is sent to grade.php within the activities directory. It should redirect the user to the appropriate page. For example, sending students to the activity itself while sending teachers to a list of students who have completed the activity. | ||
Line 33: | Line 33: | ||
Typically you will use has_capability() to determine where to send the user then call redirect(). | Typically you will use has_capability() to determine where to send the user then call redirect(). | ||
== | ===Callbacks=== | ||
Gradebook callbacks should available in /mod/$modname/lib.php There are two required callbacks. | |||
$modname.'_update_grades' | |||
Get module to update all grade items | |||
$modname.'_grade_item_update' | |||
Create/update grade item for given activity module instance | |||
==Examples== | |||
What is the difference between these methods exactly? Both are required by lib/gradelib.php grade_update_mod_grades() which calls both of them but all our implementations of %modname%_update_grades() just seem to call %modname%_grade_item_update(). Are we updating the grade twice for every call to grade_update_mod_grades()? | What is the difference between these methods exactly? Both are required by lib/gradelib.php grade_update_mod_grades() which calls both of them but all our implementations of %modname%_update_grades() just seem to call %modname%_grade_item_update(). Are we updating the grade twice for every call to grade_update_mod_grades()? |
Revision as of 08:09, 17 January 2012
Overview
This document explains how custom Moodle activity modules may use the Gradebook API to read and write student grades.
The Gradebook API allows you to read and write from the gradebook. It also allows you to provide an interface for detailed grading information.
File Locations
The main file of interest for the gradebook API is /lib/gradelib.php
Functions
grade_update() is used to submit new or updated grades.
grade_update_outcomes() is used to submit new or updated outcomes.
grade_get_grades() is used to retrieve grade information about a given activity. Optionally you can retrieve student grades for that activity.
Infrastructure Required From a Custom Activity Module
/mod/$modname/grade.php
A teacher or student clicking on the activity name in the gradebook is sent to grade.php within the activities directory. It should redirect the user to the appropriate page. For example, sending students to the activity itself while sending teachers to a list of students who have completed the activity.
grade.php is supplied with the following parameters.
$id = required_param('id', PARAM_INT); // Course module ID
$itemnumber = optional_param('itemnumber', 0, PARAM_INT); // Item number, may be != 0 for activities that allow more than one grade per user
$userid = optional_param('userid', 0, PARAM_INT); // Graded user ID (optional)
Typically you will use has_capability() to determine where to send the user then call redirect().
Callbacks
Gradebook callbacks should available in /mod/$modname/lib.php There are two required callbacks.
$modname.'_update_grades' Get module to update all grade items
$modname.'_grade_item_update' Create/update grade item for given activity module instance
Examples
What is the difference between these methods exactly? Both are required by lib/gradelib.php grade_update_mod_grades() which calls both of them but all our implementations of %modname%_update_grades() just seem to call %modname%_grade_item_update(). Are we updating the grade twice for every call to grade_update_mod_grades()?