Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
|
grade_category is an object mapped to DB table {prefix}grade_categories More...
Public Member Functions | |
aggregate_values ($grade_values, $items) | |
Internal function that calculates the aggregated grade for this 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. | |
apply_default_settings () | |
Applies default settings on this category. | |
apply_forced_settings () | |
Applies forced settings on this 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. | |
can_apply_limit_rules () | |
Returns whether or not we can apply the limit rules. | |
can_control_visibility () | |
Returns whether the grade object can control the visibility of the grades. | |
delete ($source=null) | |
If parent\delete() is successful, send force_regrading message to parent category. | |
force_regrading () | |
Marks this grade categories' associated grade item as needing regrading. | |
generate_grades ($userid=null, ?\core\progress\base $progress=null) | |
Generates and saves final grades in associated category grade item. | |
get_children ($include_category_items=false) | |
Fetches and returns all the children categories and/or grade_items belonging to this category. | |
get_coefstring ($first=true) | |
Recursive function to find which weight/extra credit field to use in the grade item form. | |
get_description () | |
Describe the aggregation settings for this category so the reports make more sense. | |
get_final ($userid=null) | |
Returns the final grade values for this grade category. | |
get_grade_item () | |
Retrieves this grade categories' associated grade_item from the database. | |
get_hidden () | |
Check a grade item hidden status. | |
get_idnumber () | |
Returns the idnumber of the grade categories' associated grade_item. | |
get_name ($escape=true) | |
Returns the most descriptive field for this grade category. | |
get_parent_category () | |
Uses $this->parent to instantiate and return a grade_category object. | |
get_record_data () | |
Returns object with fields and values that are defined in database. | |
get_sortorder () | |
Returns the sortorder of the grade categories' associated grade_item. | |
insert ($source=null, $isbulkupdate=false) | |
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. | |
insert_course_category ($courseid) | |
Internal function - used only from fetch_course_category() Normal insert() can not be used for course category. | |
is_aggregationcoef_used () | |
Returns true if category uses special aggregation coefficient. | |
is_course_category () | |
Return true if this is the top most category that represents the total course grade. | |
is_editable () | |
Is grading object editable? | |
is_extracredit_used () | |
Returns true if category uses extra credit of any kind. | |
is_hidden () | |
Returns the current hidden state of this grade_item. | |
is_hiddenuntil () | |
Check grade object hidden status. | |
is_locked () | |
Returns the locked state/date of the grade categories' associated grade_item. | |
load_grade_item () | |
Uses get_grade_item() to load or create a grade_item, then saves it as $this->grade_item. | |
load_optional_fields () | |
Makes sure all the optional fields are loaded. | |
load_parent_category () | |
Uses $this->parent to instantiate $this->parent_category based on the referenced record in the DB. | |
move_after_sortorder ($sortorder) | |
Move this category after the given sortorder. | |
pre_regrade_final_grades () | |
Something that should be called before we start regrading the whole course. | |
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. | |
set_hidden ($hidden, $cascade=false) | |
Sets the grade_item's hidden variable and updates the grade_item. | |
set_locked ($lockedstate, $cascade=false, $refresh=true) | |
Sets the grade_item's locked variable and updates the grade_item. | |
set_parent ($parentid, $source=null) | |
Sets this category's parent id. | |
set_sortorder ($sortorder) | |
Sets the sortorder variable for this category. | |
update ($source=null, $isbulkupdate=false) | |
In addition to update() as defined in grade_object, call force_regrading of parent categories, if applicable. | |
update_from_db () | |
Using this object's id field, fetches the matching record in the DB, and looks at each variable in turn. | |
Static Public Member Functions | |
static | aggregation_uses_aggregationcoef ($aggregation) |
Returns true if aggregation uses aggregationcoef. | |
static | aggregation_uses_extracredit ($aggregation) |
Returns true if aggregation passed is using extracredit. | |
static | build_path ($grade_category) |
Builds this category's path string based on its parents (if any) and its own id number. | |
static | clean_record_set () |
Cleans the cache. | |
static | fetch ($params) |
Finds and returns a grade_category instance based on params. | |
static | fetch_all ($params) |
Finds and returns all grade_category instances based on params. | |
static | fetch_all_helper ($table, $classname, $params) |
Factory method which uses the parameters to retrieve all matching instances from the database. | |
static | fetch_course_category ($courseid) |
Return the course level grade_category object. | |
static | fetch_course_tree ($courseid, $include_category_items=false) |
Returns tree with all grade_items and categories as elements. | |
static | get_default_aggregation_coefficient_values ($aggregationmethod) |
Determine the default aggregation values for a given aggregation method. | |
static | set_properties (&$instance, $params) |
Overrides grade_object\set_properties() to add special handling for changes to category aggregation types. | |
static | updated_forced_settings () |
Notification of change in forced category settings. | |
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) . | |
array | $all_children |
A hierarchical array of all children below this category. | |
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. | |
int | $courseid |
The course this category belongs to. | |
int | $depth = 0 |
The number of parents this category has. | |
int | $droplow = 0 |
Drop the X lowest items. | |
array | $forceable = array('aggregation', 'keephigh', 'droplow', 'aggregateonlygraded', 'aggregateoutcomes') |
List of options which can be "forced" from site settings. | |
string | $fullname |
The name of this category. | |
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. | |
int | $hidden = 0 |
0 if visible, 1 always hidden or date not visible until $hidden | |
int | $id |
The PK. | |
string | $itemtype |
e.g. | |
int | $keephigh = 0 |
Keep only the X highest items. | |
array | $optional_fields = array() |
Array of optional fields with default values - usually long text information that is not always needed. | |
int | $parent |
The category this category belongs to (optional). | |
grade_category | $parent_category |
The grade_category object referenced by $this->parent (PK). | |
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. | |
array | $required_fields |
Array of required table fields, must start with 'id'. | |
int | $sortorder |
Temporary sortorder for speedup of children resorting $sortorder. | |
string | $table = 'grade_categories' |
The DB table. | |
int | $timecreated |
The first time this grade_object was created. | |
int | $timemodified |
The last time this grade_object was modified. | |
Protected Member Functions | |
add_feedback_files (int $historyid=null) | |
Handles adding feedback files in the gradebook. | |
delete_feedback_files () | |
Handles deleting feedback files in the gradebook. | |
notify_changed ($deleted) | |
Cleans the cache. | |
update_feedback_files (int $historyid=null) | |
Handles updating feedback files in the gradebook. | |
Static Protected Member Functions | |
static | fetch_helper ($table, $classname, $params) |
Factory method which uses the parameters to retrieve matching instances from the database. | |
static | generate_record_set_key ($params) |
Generates a unique key per query. | |
static | retrieve_record_set ($params) |
Tries to retrieve a record set from the cache. | |
static | set_record_set ($params, $records) |
Sets a result to the records cache, even if there were no results. | |
Protected Attributes | |
bool | $canapplylimitrules |
Static variable storing the result from self::can_apply_limit_rules. | |
grade_category is an object mapped to DB table {prefix}grade_categories
|
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.
|
protectedinherited |
Handles deleting feedback files in the gradebook.
Reimplemented in grade_grade.
|
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, | |
?\core\progress\base | $progress = 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 |
core\progress\base | null | $progress | Optional progress indicator |
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 | ( | $escape = true | ) |
Returns the most descriptive field for this grade category.
string | name |
bool | $escape | Whether the returned category name is to be HTML escaped or not. |
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, | |
$isbulkupdate = false ) |
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.) |
bool | $isbulkupdate | If bulk grade update is happening. |
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.
grade_category | $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, | |
$isbulkupdate = false ) |
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 | $isbulkupdate | If bulk grade update is happening. |
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
string grade_category::$itemtype |
e.g.
'category', 'course' and 'mod', 'blocks', 'import', etc... $itemtype
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