Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

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

Definition of grade scale class

Copyright: 2006 Nicolas Connault
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 392 lines (13 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 1 file
 lib/grade/grade_object.php

Defines 1 class

grade_scale:: (15 methods):
  fetch()
  fetch_all()
  insert()
  update()
  delete()
  get_name()
  load_items()
  compact_items()
  get_nearest_item()
  fetch_all_global()
  fetch_all_local()
  is_last_global_scale()
  can_delete()
  is_used()
  get_description()


Class: grade_scale  - X-Ref

Class representing a grade scale.

It is responsible for handling its DB representation, modifying and returning its metadata.

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

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

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

return: array array of grade_scale instances or false if none found.
param: array $params associative arrays varname=>value

insert($source = null, $isbulkupdate = false)   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.

return: int PK ID if successful, false otherwise
param: string $source from where was the object inserted (mod/forum, manual, etc.)
param: bool $isbulkupdate If bulk grade update is happening.

update($source = null, $isbulkupdate = false)   X-Ref
In addition to update() it also updates grade_outcomes_courses if needed

return: bool success
param: string $source from where was the object inserted
param: bool $isbulkupdate If bulk grade update is happening.

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

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

get_name()   X-Ref
Returns the most descriptive field for this object. This is a standard method used
when we do not know the exact type of an object.

return: string name

load_items($items=NULL)   X-Ref
Loads the scale's items into the $scale_items array.
There are three ways to achieve this:
1. No argument given: The $scale string is already loaded and exploded to an array of items.
2. A string is given: A comma-separated list of items is exploded into an array of items.
3. An array of items is given and saved directly as the array of items for this scale.

return: array The resulting array of scale items or null if the method failed to produce one.
param: mixed $items Could be null, a string or an array. The method behaves differently for each case.

compact_items($items=NULL)   X-Ref
Compacts (implodes) the array of items in $scale_items into a comma-separated string, $scale.
There are three ways to achieve this:
1. No argument given: The $scale_items array is already loaded and imploded to a string of items.
2. An array is given and is imploded into a string of items.
3. A string of items is given and saved directly as the $scale variable.
NOTE: This method is the exact reverse of load_items, and their input/output should be interchangeable. However,
because load_items() trims the whitespace around the items, when the string is reconstructed these whitespaces will
be missing. This is not an issue, but should be kept in mind when comparing the two strings.

return: array The resulting string of scale items or null if the method failed to produce one.
param: mixed $items Could be null, a string or an array. The method behaves differently for each case.

get_nearest_item($grade)   X-Ref
When called on a loaded scale object (with a valid id) and given a float grade between
the grademin and grademax, this method returns the scale item that falls closest to the
float given (which is usually an average of several grades on a scale). If the float falls
below 1 but above 0, it will be rounded up to 1.

return: string
param: float $grade

fetch_all_global()   X-Ref
Static function returning all global scales

return: object

fetch_all_local($courseid)   X-Ref
Static function returning all local course scales

return: array Returns an array of grade_scale instances
param: int $courseid The course ID

is_last_global_scale()   X-Ref
Checks if this is the last scale on the site.

return: bool

can_delete()   X-Ref
Checks if scale can be deleted.

return: bool

is_used()   X-Ref
Returns if scale used anywhere - activities, grade items, outcomes, etc.

return: bool

get_description()   X-Ref
Returns the formatted grade description with URLs converted

return: string