Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401] [Versions 401 and 402] [Versions 401 and 403]

File containing the grade_report class

Copyright: 2007 Moodle Pty Ltd (http://moodle.com)
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 779 lines (32 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 1 class


Class: grade_report  - X-Ref

An abstract class containing variables and methods used by all or most reports.

__construct($courseid, $gpr, $context, $page=null)   X-Ref
Constructor. Sets local copies of user preferences and initialises grade_tree.

param: int $courseid
param: object $gpr grade plugin return tracking object
param: string $context
param: int $page The current page being viewed (when report is paged)

get_pref($pref, $objectid=null)   X-Ref
Given the name of a user preference (without grade_report_ prefix), locally saves then returns
the value of that preference. If the preference has already been fetched before,
the saved value is returned. If the preference is not set at the User level, the $CFG equivalent
is given (site default).
Can be called statically, but then doesn't benefit from caching

param: string $pref The name of the preference (do not include the grade_report_ prefix)
param: int $objectid An optional itemid or categoryid to check for a more fine-grained preference
return: mixed The value of the preference

set_pref($pref, $pref_value='default', $itemid=null)   X-Ref
Uses set_user_preferences() to update the value of a user preference. If 'default' is given as the value,
the preference will be removed in favour of a higher-level preference.

param: string $pref The name of the preference.
param: mixed $pref_value The value of the preference.
param: int $itemid An optional itemid to which the preference will be assigned
return: bool Success or failure.

get_lang_string($strcode, $section=null)   X-Ref
First checks the cached language strings, then returns match if found, or uses get_string()
to get it from the DB, caches it then returns it.

param: string $strcode
param: string $section Optional language section
return: string

get_numusers($groups = true, $users = false)   X-Ref
Fetches and returns a count of all the users that will be shown on this page.

param: boolean $groups include groups limit
param: boolean $users include users limit - default false, used for searching purposes
return: int Count of users

supports_mygrades()   X-Ref
Shows support for being used as a 'Grades' report.


setup_groups()   X-Ref
Sets up this object's group variables, mainly to restrict the selection of users to display.


setup_users()   X-Ref
Sets up this report's user criteria to restrict the selection of users to display.


get_sort_arrow($direction='move', $sortlink=null)   X-Ref
Returns an arrow icon inside an <a> tag, for the purpose of sorting a column.

param: string $direction
param: moodle_url $sortlink

blank_hidden_total_and_adjust_bounds($courseid, $course_item, $finalgrade)   X-Ref
Optionally blank out course/category totals if they contain any hidden items

param: string $courseid the course id
param: string $course_item an instance of grade_item
param: string $finalgrade the grade for the course_item
return: array[] containing values for 'grade', 'grademax', 'grademin', 'aggregationstatus' and 'aggregationweight'

blank_hidden_total($courseid, $course_item, $finalgrade)   X-Ref
Optionally blank out course/category totals if they contain any hidden items

param: string $courseid the course id
param: string $course_item an instance of grade_item
param: string $finalgrade the grade for the course_item
return: string The new final grade

calculate_average(grade_item $gradeitem, array $info)   X-Ref
Calculate average grade for a given grade item.
Based on calculate_averages function from grade/report/user/lib.php

param: grade_item $gradeitem Grade item
param: array $info Ungraded grade items counts and report preferences.
return: array Average grade and meancount.

ungraded_counts()   X-Ref
Get ungraded grade items info and sum of all grade items in a course.
Based on calculate_averages function from grade/report/user/lib.php

return: array Ungraded grade items counts with report preferences.

item_types()   X-Ref
Get grade item type names in a course to use in filter dropdown.

return: array Item types.

get_gradable_users(int $courseid, ?int $groupid = null)   X-Ref
Load a valid list of gradable users in a course.

param: int $courseid The course ID.
param: int|null $groupid The group ID (optional).
return: array A list of enrolled gradable users.