Moodle APIs
3.8
Moodle 3.8.6 (Build: 20201109)
|
Public Member Functions | |
aggregate_values ($grade_values, $items) | |
Internal function that calculates the aggregated grade for this grade category. More... | |
aggregate_values_and_adjust_bounds ($grade_values, $items, & $weights=null, $grademinoverrides=array(), $grademaxoverrides=array()) | |
Internal function that calculates the aggregated grade and new min/max for this grade category. More... | |
apply_default_settings () | |
Applies default settings on this category. More... | |
apply_forced_settings () | |
Applies forced settings on this category. More... | |
apply_limit_rules (&$grade_values, $items) | |
Given an array of grade values (numerical indices) applies droplow or keephigh rules to limit the final array. More... | |
can_apply_limit_rules () | |
Returns whether or not we can apply the limit rules. More... | |
can_control_visibility () | |
Returns whether the grade object can control the visibility of the grades. More... | |
delete ($source=null) | |
If parent::delete() is successful, send force_regrading message to parent category. More... | |
force_regrading () | |
Marks this grade categories' associated grade item as needing regrading. | |
generate_grades ($userid=null) | |
Generates and saves final grades in associated category grade item. More... | |
get_children ($include_category_items=false) | |
Fetches and returns all the children categories and/or grade_items belonging to this category. More... | |
get_coefstring ($first=true) | |
Recursive function to find which weight/extra credit field to use in the grade item form. More... | |
get_description () | |
Describe the aggregation settings for this category so the reports make more sense. More... | |
get_final ($userid=null) | |
Returns the final grade values for this grade category. More... | |
get_grade_item () | |
Retrieves this grade categories' associated grade_item from the database. More... | |
get_hidden () | |
Check a grade item hidden status. More... | |
get_idnumber () | |
Returns the idnumber of the grade categories' associated grade_item. More... | |
get_name () | |
Returns the most descriptive field for this grade category. More... | |
get_parent_category () | |
Uses $this->parent to instantiate and return a grade_category object. More... | |
get_record_data () | |
Returns object with fields and values that are defined in database. More... | |
get_sortorder () | |
Returns the sortorder of the grade categories' associated grade_item. More... | |
insert ($source=null) | |
In addition to the normal insert() defined in grade_object, this method sets the depth and path for this object, and update the record accordingly. More... | |
insert_course_category ($courseid) | |
Internal function - used only from fetch_course_category() Normal insert() can not be used for course category. More... | |
is_aggregationcoef_used () | |
Returns true if category uses special aggregation coefficient. More... | |
is_course_category () | |
Return true if this is the top most category that represents the total course grade. More... | |
is_editable () | |
Is grading object editable? More... | |
is_extracredit_used () | |
Returns true if category uses extra credit of any kind. More... | |
is_hidden () | |
Returns the current hidden state of this grade_item. More... | |
is_hiddenuntil () | |
Check grade object hidden status. More... | |
is_locked () | |
Returns the locked state/date of the grade categories' associated grade_item. More... | |
load_grade_item () | |
Uses get_grade_item() to load or create a grade_item, then saves it as $this->grade_item. More... | |
load_optional_fields () | |
Makes sure all the optional fields are loaded. More... | |
load_parent_category () | |
Uses $this->parent to instantiate $this->parent_category based on the referenced record in the DB. More... | |
move_after_sortorder ($sortorder) | |
Move this category after the given sortorder. More... | |
pre_regrade_final_grades () | |
Something that should be called before we start regrading the whole course. More... | |
qualifies_for_regrading () | |
Compares the values held by this object with those of the matching record in DB, and returns whether or not these differences are sufficient to justify an update of all parent objects. More... | |
set_hidden ($hidden, $cascade=false) | |
Sets the grade_item's hidden variable and updates the grade_item. More... | |
set_locked ($lockedstate, $cascade=false, $refresh=true) | |
Sets the grade_item's locked variable and updates the grade_item. More... | |
set_parent ($parentid, $source=null) | |
Sets this category's parent id. More... | |
set_sortorder ($sortorder) | |
Sets the sortorder variable for this category. More... | |
update ($source=null) | |
In addition to update() as defined in grade_object, call force_regrading of parent categories, if applicable. More... | |
update_from_db () | |
Using this object's id field, fetches the matching record in the DB, and looks at each variable in turn. More... | |
Static Public Member Functions | |
static | aggregation_uses_aggregationcoef ($aggregation) |
Returns true if aggregation uses aggregationcoef. More... | |
static | aggregation_uses_extracredit ($aggregation) |
Returns true if aggregation passed is using extracredit. More... | |
static | build_path ($grade_category) |
Builds this category's path string based on its parents (if any) and its own id number. More... | |
static | clean_record_set () |
Cleans the cache. More... | |
static | fetch ($params) |
Finds and returns a grade_category instance based on params. More... | |
static | fetch_all ($params) |
Finds and returns all grade_category instances based on params. More... | |
static | fetch_all_helper ($table, $classname, $params) |
Factory method which uses the parameters to retrieve all matching instances from the database. More... | |
static | fetch_course_category ($courseid) |
Return the course level grade_category object. More... | |
static | fetch_course_tree ($courseid, $include_category_items=false) |
Returns tree with all grade_items and categories as elements. More... | |
static | get_default_aggregation_coefficient_values ($aggregationmethod) |
Determine the default aggregation values for a given aggregation method. More... | |
static | set_properties (&$instance, $params) |
Overrides grade_object::set_properties() to add special handling for changes to category aggregation types. More... | |
static | updated_forced_settings () |
Notification of change in forced category settings. More... | |
Public Attributes | |
int | $aggregateonlygraded = 0 |
Aggregate only graded items $aggregateonlygraded. | |
int | $aggregateoutcomes = 0 |
Aggregate outcomes together with normal items $aggregateoutcomes. | |
int | $aggregation = GRADE_AGGREGATE_SUM |
A constant pointing to one of the predefined aggregation strategies (none, mean, median, sum etc) . More... | |
array | $all_children |
A hierarchical array of all children below this category. More... | |
array | $children |
Array of grade_items or grade_categories nested exactly 1 level below this category $children. | |
string | $coefstring = null |
String representing the aggregation coefficient. More... | |
int | $courseid |
The course this category belongs to. More... | |
int | $depth = 0 |
The number of parents this category has. More... | |
int | $droplow = 0 |
Drop the X lowest items. More... | |
array | $forceable = array('aggregation', 'keephigh', 'droplow', 'aggregateonlygraded', 'aggregateoutcomes') |
List of options which can be "forced" from site settings. More... | |
string | $fullname |
The name of this category. More... | |
grade_item | $grade_item |
An associated grade_item object, with itemtype=category, used to calculate and cache a set of grade values for this category. More... | |
int | $hidden = 0 |
0 if visible, 1 always hidden or date not visible until $hidden | |
int | $id |
The PK. More... | |
int | $keephigh = 0 |
Keep only the X highest items. More... | |
array | $optional_fields = array() |
Array of optional fields with default values - usually long text information that is not always needed. More... | |
int | $parent |
The category this category belongs to (optional). More... | |
grade_category | $parent_category |
The grade_category object referenced by $this->parent (PK). More... | |
string | $path |
Shows the hierarchical path for this category as /1/2/3/ (like course_categories), the last number being this category's autoincrement ID number. More... | |
array | $required_fields |
Array of required table fields, must start with 'id'. More... | |
int | $sortorder |
Temporary sortorder for speedup of children resorting $sortorder. | |
string | $table = 'grade_categories' |
The DB table. More... | |
int | $timecreated |
The first time this grade_object was created. More... | |
int | $timemodified |
The last time this grade_object was modified. More... | |
Protected Member Functions | |
add_feedback_files (int $historyid=null) | |
Handles adding feedback files in the gradebook. More... | |
delete_feedback_files () | |
Handles deleting feedback files in the gradebook. | |
notify_changed ($deleted) | |
Cleans the cache. More... | |
update_feedback_files (int $historyid=null) | |
Handles updating feedback files in the gradebook. More... | |
Static Protected Member Functions | |
static | fetch_helper ($table, $classname, $params) |
Factory method which uses the parameters to retrieve matching instances from the database. More... | |
static | generate_record_set_key ($params) |
Generates a unique key per query. More... | |
static | retrieve_record_set ($params) |
Tries to retrieve a record set from the cache. More... | |
static | set_record_set ($params, $records) |
Sets a result to the records cache, even if there were no results. More... | |
Protected Attributes | |
bool | $canapplylimitrules |
Static variable storing the result from self::can_apply_limit_rules. | |
|
protectedinherited |
Handles adding feedback files in the gradebook.
int | null | $historyid |
Reimplemented in grade_grade.
grade_category::aggregate_values | ( | $grade_values, | |
$items | |||
) |
Internal function that calculates the aggregated grade for this grade category.
Must be public as it is used by grade_grade::get_hiding_affected()
array | $grade_values | An array of values to be aggregated |
array | $items | The array of grade_items |
float | The aggregate grade for this grade category |
grade_category::aggregate_values_and_adjust_bounds | ( | $grade_values, | |
$items, | |||
& | $weights = null , |
||
$grademinoverrides = array() , |
|||
$grademaxoverrides = array() |
|||
) |
Internal function that calculates the aggregated grade and new min/max for this grade category.
Must be public as it is used by grade_grade::get_hiding_affected()
array | $grade_values | An array of values to be aggregated |
array | $items | The array of grade_items |
array | & $weights If provided, will be filled with the normalized weights for each grade_item as used in the aggregation. Some rules for the weights are:
| |
array | $grademinoverrides | User specific grademin values if different to the grade_item grademin (key is itemid) |
array | $grademaxoverrides | User specific grademax values if different to the grade_item grademax (key is itemid) |
array | containing values for: 'grade' => the new calculated grade 'grademin' => the new calculated min grade for the category 'grademax' => the new calculated max grade for the category |
|
static |
Returns true if aggregation uses aggregationcoef.
int | $aggregation | Aggregation const. |
bool | True if an aggregation coefficient is being used |
|
static |
Returns true if aggregation passed is using extracredit.
int | $aggregation | Aggregation const. |
bool | True if extra credit used |
grade_category::apply_default_settings | ( | ) |
Applies default settings on this category.
bool | True if anything changed |
grade_category::apply_forced_settings | ( | ) |
Applies forced settings on this category.
bool | True if anything changed |
grade_category::apply_limit_rules | ( | & | $grade_values, |
$items | |||
) |
Given an array of grade values (numerical indices) applies droplow or keephigh rules to limit the final array.
array | $grade_values | itemid=>$grade_value float |
array | $items | grade item objects |
array | Limited grades. |
|
static |
Builds this category's path string based on its parents (if any) and its own id number.
This is typically done just before inserting this object in the DB for the first time, or when a new parent is added or changed. It is a recursive function: once the calling object no longer has a parent, the path is complete.
grade_category | $grade_category | A Grade_Category object |
string | The category's path string |
grade_category::can_apply_limit_rules | ( | ) |
Returns whether or not we can apply the limit rules.
There are cases where drop lowest or keep highest should not be used at all. This method will determine whether or not this logic can be applied considering the current setup of the category.
bool |
|
inherited |
Returns whether the grade object can control the visibility of the grades.
bool |
Reimplemented in grade_item.
|
static |
Cleans the cache.
Aggressive deletion to be conservative given the gradebook design. The key is based on the requested params, not easy nor worth to purge selectively.
void |
grade_category::delete | ( | $source = null | ) |
If parent::delete() is successful, send force_regrading message to parent category.
string | $source | from where was the object deleted (mod/forum, manual, etc.) |
bool | success |
Reimplemented from grade_object.
|
static |
Finds and returns a grade_category instance based on params.
array | $params | associative arrays varname=>value |
grade_category | The retrieved grade_category instance or false if none found. |
Reimplemented from grade_object.
|
static |
Finds and returns all grade_category instances based on params.
array | $params | associative arrays varname=>value |
array | array of grade_category insatnces or false if none found. |
Reimplemented from grade_object.
|
staticinherited |
Factory method which uses the parameters to retrieve all matching instances from the database.
string | $table | The table to retrieve from |
string | $classname | The name of the class to instantiate |
array | $params | An array of conditions like $fieldname => $fieldvalue |
array|bool | Array of object instances or false if not found |
|
static |
Return the course level grade_category object.
int | $courseid | The Course ID |
grade_category | Returns the course level grade_category instance |
|
static |
Returns tree with all grade_items and categories as elements.
int | $courseid | The course ID |
bool | $include_category_items | as category children |
array |
|
staticprotectedinherited |
Factory method which uses the parameters to retrieve matching instances from the database.
string | $table | The table to retrieve from |
string | $classname | The name of the class to instantiate |
array | $params | An array of conditions like $fieldname => $fieldvalue |
mixed | An object instance or false if not found |
grade_category::generate_grades | ( | $userid = null | ) |
Generates and saves final grades in associated category grade item.
These immediate children must already have their own final grades. The category's aggregation method is used to generate final grades.
Please note that category grade is either calculated or aggregated, not both at the same time.
This method must be used ONLY from grade_item::regrade_final_grades(), because the calculation must be done in correct order!
Steps to follow:
int | $userid | The user ID if final grade generation should be limited to a single user |
bool |
|
staticprotected |
Generates a unique key per query.
Not unique between grade_object children. self::retrieve_record_set and self::set_record_set will be in charge of selecting the appropriate cache.
array | $params | An array of conditions like $fieldname => $fieldvalue |
string |
grade_category::get_children | ( | $include_category_items = false | ) |
Fetches and returns all the children categories and/or grade_items belonging to this category.
By default only returns the immediate children (depth=1), but deeper levels can be requested, as well as all levels (0). The elements are indexed by sort order.
bool | $include_category_items | Whether or not to include category grade_items in the children array |
array | Array of child objects (grade_category and grade_item). |
grade_category::get_coefstring | ( | $first = true | ) |
Recursive function to find which weight/extra credit field to use in the grade item form.
string | $first | Whether or not this is the first item in the recursion |
string |
|
static |
Determine the default aggregation values for a given aggregation method.
int | $aggregationmethod | The aggregation method constant value. |
array | Containing the keys 'aggregationcoef', 'aggregationcoef2' and 'weightoverride'. |
grade_category::get_description | ( | ) |
Describe the aggregation settings for this category so the reports make more sense.
string | description |
grade_category::get_final | ( | $userid = null | ) |
Returns the final grade values for this grade category.
int | $userid | Optional user ID to retrieve a single user's final grade |
mixed | An array of all final_grades (stdClass objects) for this grade_item, or a single final_grade. |
grade_category::get_grade_item | ( | ) |
Retrieves this grade categories' associated grade_item from the database.
If no grade_item exists yet, creates one.
grade_item |
|
inherited |
Check a grade item hidden status.
int | 0 means visible, 1 hidden always, a timestamp means "hidden until" |
Reimplemented in grade_grade.
grade_category::get_idnumber | ( | ) |
Returns the idnumber of the grade categories' associated grade_item.
This method is also available in grade_item for cases where the object type is not known.
string | idnumber |
grade_category::get_name | ( | ) |
Returns the most descriptive field for this grade category.
string | name |
grade_category::get_parent_category | ( | ) |
Uses $this->parent to instantiate and return a grade_category object.
grade_category | Returns the parent category or null if this category has no parent |
|
inherited |
Returns object with fields and values that are defined in database.
stdClass |
grade_category::get_sortorder | ( | ) |
Returns the sortorder of the grade categories' associated grade_item.
This method is also available in grade_item for cases where the object type is not known.
int | Sort order |
grade_category::insert | ( | $source = null | ) |
In addition to the normal insert() defined in grade_object, this method sets the depth and path for this object, and update the record accordingly.
We do this here instead of in the constructor as they both need to know the record's ID number, which only gets created at insertion time. This method also creates an associated grade_item if this wasn't done during construction.
string | $source | from where was the object inserted (mod/forum, manual, etc.) |
int | PK ID if successful, false otherwise |
Reimplemented from grade_object.
grade_category::insert_course_category | ( | $courseid | ) |
Internal function - used only from fetch_course_category() Normal insert() can not be used for course category.
int | $courseid | The course ID |
int | The ID of the new course category |
grade_category::is_aggregationcoef_used | ( | ) |
Returns true if category uses special aggregation coefficient.
bool | True if an aggregation coefficient is being used |
grade_category::is_course_category | ( | ) |
Return true if this is the top most category that represents the total course grade.
bool |
grade_category::is_editable | ( | ) |
Is grading object editable?
bool |
grade_category::is_extracredit_used | ( | ) |
Returns true if category uses extra credit of any kind.
bool | True if extra credit used |
|
inherited |
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
bool | Current hidden state |
Reimplemented in grade_grade.
|
inherited |
Check grade object hidden status.
bool | True if a "hidden until" timestamp is set, false if grade object is set to always visible or always hidden. |
Reimplemented in grade_grade.
grade_category::is_locked | ( | ) |
Returns the locked state/date of the grade categories' associated grade_item.
This method is also available in grade_item, for cases where the object type is not known.
bool |
grade_category::load_grade_item | ( | ) |
Uses get_grade_item() to load or create a grade_item, then saves it as $this->grade_item.
grade_item |
|
inherited |
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.
grade_category::load_parent_category | ( | ) |
Uses $this->parent to instantiate $this->parent_category based on the referenced record in the DB.
grade_category | The parent category |
grade_category::move_after_sortorder | ( | $sortorder | ) |
Move this category after the given sortorder.
Does not change the parent
int | $sortorder | to place after. |
void |
|
protected |
Cleans the cache.
We invalidate them all so it can be completely reloaded.
Being conservative here, if there is a new grade_category we purge them, the important part is that this is not purged when there are no changes in grade_categories.
bool | $deleted |
void |
Reimplemented from grade_object.
grade_category::pre_regrade_final_grades | ( | ) |
Something that should be called before we start regrading the whole course.
void |
grade_category::qualifies_for_regrading | ( | ) |
Compares the values held by this object with those of the matching record in DB, and returns whether or not these differences are sufficient to justify an update of all parent objects.
This assumes that this object has an ID number and a matching record in DB. If not, it will return false.
bool |
|
staticprotected |
Tries to retrieve a record set from the cache.
array | $params | The query params |
grade_object[]|bool | An array of grade_objects or false if not found. |
grade_category::set_hidden | ( | $hidden, | |
$cascade = false |
|||
) |
Sets the grade_item's hidden variable and updates the grade_item.
Overrides grade_item::set_hidden() to add cascading of the hidden value to grade items in this grade category
int | $hidden | 0 mean always visible, 1 means always hidden and a number > 1 is a timestamp to hide until |
bool | $cascade | apply to child objects too |
Reimplemented from grade_object.
grade_category::set_locked | ( | $lockedstate, | |
$cascade = false , |
|||
$refresh = true |
|||
) |
Sets the grade_item's locked variable and updates the grade_item.
Calls set_locked() on the categories' grade_item
int | $lockedstate | 0, 1 or a timestamp int(10) after which date the item will be locked. |
bool | $cascade | lock/unlock child objects too |
bool | $refresh | refresh grades when unlocking |
bool | success if category locked (not all children mayb be locked though) |
grade_category::set_parent | ( | $parentid, | |
$source = null |
|||
) |
Sets this category's parent id.
int | $parentid | The ID of the category that is the new parent to $this |
string | $source | From where was the object updated (mod/forum, manual, etc.) |
bool | success |
|
static |
Overrides grade_object::set_properties() to add special handling for changes to category aggregation types.
stdClass | $instance | the object to set the properties on |
array | stdClass | $params | Either an associative array or an object containing property name, property value pairs |
Reimplemented from grade_object.
|
staticprotected |
Sets a result to the records cache, even if there were no results.
string | $params | The query params |
grade_object[] | bool | $records | An array of grade_objects or false if there are no records matching the $key filters |
void |
grade_category::set_sortorder | ( | $sortorder | ) |
Sets the sortorder variable for this category.
This method is also available in grade_item, for cases where the object type is not know.
int | $sortorder | The sortorder to assign to this category |
grade_category::update | ( | $source = null | ) |
In addition to update() as defined in grade_object, call force_regrading of parent categories, if applicable.
string | $source | from where was the object updated (mod/forum, manual, etc.) |
bool | success |
Reimplemented from grade_object.
|
protectedinherited |
Handles updating feedback files in the gradebook.
int | null | $historyid |
Reimplemented in grade_grade.
|
inherited |
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.
bool | True if successful |
|
static |
Notification of change in forced category settings.
Causes all course and category grade items to be marked as needing to be updated
int grade_category::$aggregation = GRADE_AGGREGATE_SUM |
A constant pointing to one of the predefined aggregation strategies (none, mean, median, sum etc) .
$aggregation
array grade_category::$all_children |
A hierarchical array of all children below this category.
This is stored separately from $children because it is more memory-intensive and may not be used as often. $all_children
string grade_category::$coefstring = null |
String representing the aggregation coefficient.
Variable is used as cache. $coefstring
int grade_category::$courseid |
The course this category belongs to.
$courseid
int grade_category::$depth = 0 |
The number of parents this category has.
$depth
int grade_category::$droplow = 0 |
Drop the X lowest items.
$droplow
array grade_category::$forceable = array('aggregation', 'keephigh', 'droplow', 'aggregateonlygraded', 'aggregateoutcomes') |
List of options which can be "forced" from site settings.
$forceable
string grade_category::$fullname |
The name of this category.
$fullname
grade_item grade_category::$grade_item |
An associated grade_item object, with itemtype=category, used to calculate and cache a set of grade values for this category.
$grade_item
|
inherited |
The PK.
$id
int grade_category::$keephigh = 0 |
Keep only the X highest items.
$keephigh
|
inherited |
Array of optional fields with default values - usually long text information that is not always needed.
If you want to create an instance without optional fields use: new grade_object($only_required_fields, false); $optional_fields
int grade_category::$parent |
The category this category belongs to (optional).
$parent
grade_category grade_category::$parent_category |
The grade_category object referenced by $this->parent (PK).
$parent_category
string grade_category::$path |
Shows the hierarchical path for this category as /1/2/3/ (like course_categories), the last number being this category's autoincrement ID number.
$path
array grade_category::$required_fields |
Array of required table fields, must start with 'id'.
$required_fields
string grade_category::$table = 'grade_categories' |
The DB table.
$table
|
inherited |
The first time this grade_object was created.
$timecreated
|
inherited |
The last time this grade_object was modified.
$timemodified