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 401 and 402] [Versions 401 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.

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

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

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

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.

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

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

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

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

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

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.

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

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.

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

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.

param: float $grade
return: string

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

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

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