Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

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

Definition of a grade object class for grade item, grade category etc to inherit from

Copyright: 2006 Nicolas Connault
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 495 lines (16 kb)
Included or required: 5 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: grade_object  - X-Ref

An abstract object that holds methods and attributes common to all grade_* objects defined here.

__construct($params=NULL, $fetch=true)   X-Ref
Constructor. Optionally (and by default) attempts to fetch corresponding row from the database

param: array $params An array with required parameters for this grade object.
param: bool $fetch Whether to fetch corresponding row from the database or not,

load_optional_fields()   X-Ref
Makes sure all the optional fields are loaded.

If id present, meaning the instance exists in the database, then data will be fetched from the database.
Defaults are used for new instances.

fetch($params)   X-Ref
Finds and returns a grade_object instance based on params.

param: array $params associative arrays varname=>value
return: object grade_object instance or false if none found.

fetch_all($params)   X-Ref
Finds and returns all grade_object instances based on $params.

param: array $params Associative arrays varname=>value
return: array|bool Array of grade_object instances or false if none found.

fetch_helper($table, $classname, $params)   X-Ref
Factory method which uses the parameters to retrieve matching instances from the database

param: string $table The table to retrieve from
param: string $classname The name of the class to instantiate
param: array $params An array of conditions like $fieldname => $fieldvalue
return: mixed An object instance or false if not found

fetch_all_helper($table, $classname, $params)   X-Ref
Factory method which uses the parameters to retrieve all matching instances from the database

param: string $table The table to retrieve from
param: string $classname The name of the class to instantiate
param: array $params An array of conditions like $fieldname => $fieldvalue
return: array|bool Array of object instances or false if not found

update($source=null)   X-Ref
Updates this object in the Database, based on its object variables. ID must be set.

param: string $source from where was the object updated (mod/forum, manual, etc.)
return: bool success

delete($source=null)   X-Ref
Deletes this object from the database.

param: string $source From where was the object deleted (mod/forum, manual, etc.)
return: bool success

get_record_data()   X-Ref
Returns object with fields and values that are defined in database

return: stdClass

insert($source=null)   X-Ref
Records this object in the Database, sets its id to the returned value, and returns that value.
If successful this function also fetches the new object data from database and stores it
in object properties.

param: string $source From where was the object inserted (mod/forum, manual, etc.)
return: int The new grade object ID if successful, false otherwise

update_from_db()   X-Ref
Using this object's id field, fetches the matching record in the DB, and looks at
each variable in turn. If the DB has different data, the db's data is used to update
the object. This is different from the update() function, which acts on the DB record
based on the object.

return: bool True if successful

set_properties(&$instance, $params)   X-Ref
Given an associated array or object, cycles through each key/variable
and assigns the value to the corresponding variable in this object.

param: stdClass $instance The object to set the properties on
param: array $params An array of properties to set like $propertyname => $propertyvalue
return: array|stdClass Either an associative array or an object containing property name, property value pairs

notify_changed($deleted)   X-Ref
Called immediately after the object data has been inserted, updated, or
deleted in the database. Default does nothing, can be overridden to
hook in special behaviour.

param: bool $deleted

add_feedback_files(int $historyid = null)   X-Ref
Handles adding feedback files in the gradebook.

param: int|null $historyid

update_feedback_files(int $historyid = null)   X-Ref
Handles updating feedback files in the gradebook.

param: int|null $historyid

delete_feedback_files()   X-Ref
Handles deleting feedback files in the gradebook.


is_hidden()   X-Ref
Returns the current hidden state of this grade_item

This depends on the grade object hidden setting and the current time if hidden is set to a "hidden until" timestamp

return: bool Current hidden state

is_hiddenuntil()   X-Ref
Check grade object hidden status

return: bool True if a "hidden until" timestamp is set, false if grade object is set to always visible or always hidden.

get_hidden()   X-Ref
Check a grade item hidden status.

return: int 0 means visible, 1 hidden always, a timestamp means "hidden until"

set_hidden($hidden, $cascade=false)   X-Ref
Set a grade object hidden status

param: int $hidden 0 means visiable, 1 means hidden always, a timestamp means "hidden until"
param: bool $cascade Ignored

can_control_visibility()   X-Ref
Returns whether the grade object can control the visibility of the grades.

return: bool