Moodle  2.2.1
http://www.collinsharper.com
grade_item Class Reference
Inheritance diagram for grade_item:
Collaboration diagram for grade_item:

Public Member Functions

 update ($source=null)
 qualifies_for_regrading ()
 delete ($source=null)
 delete_all_grades ($source=null)
 insert ($source=null)
 add_idnumber ($idnumber)
 is_locked ($userid=NULL)
 set_locked ($lockedstate, $cascade=false, $refresh=true)
 check_locktime ()
 set_locktime ($locktime)
 get_locktime ()
 set_hidden ($hidden, $cascade=false)
 has_hidden_grades ($groupsql="", array $params=null, $groupwheresql="")
 regrading_finished ()
 regrade_final_grades ($userid=null)
 adjust_raw_grade ($rawgrade, $rawmin, $rawmax)
 force_regrading ()
 load_scale ()
 load_outcome ()
 get_parent_category ()
 load_parent_category ()
 get_item_category ()
 load_item_category ()
 is_category_item ()
 is_course_item ()
 is_manual_item ()
 is_outcome_item ()
 is_external_item ()
 is_overridable_item ()
 is_overridable_item_feedback ()
 is_raw_used ()
 is_editable ()
 is_calculated ()
 get_calculation ()
 set_calculation ($formula)
 get_final ($userid=NULL)
 get_grade ($userid, $create=true)
 get_sortorder ()
 get_idnumber ()
 get_grade_item ()
 set_sortorder ($sortorder)
 move_after_sortorder ($sortorder)
 get_name ($fulltotal=false)
 set_parent ($parentid)
 bounded_grade ($gradevalue)
 depends_on ($reset_cache=false)
 refresh_grades ($userid=0)
 update_final_grade ($userid, $finalgrade=false, $source=NULL, $feedback=false, $feedbackformat=FORMAT_MOODLE, $usermodified=null)
 update_raw_grade ($userid, $rawgrade=false, $source=NULL, $feedback=false, $feedbackformat=FORMAT_MOODLE, $usermodified=null, $dategraded=null, $datesubmitted=null, $grade=null)
 compute ($userid=null)
 use_formula ($userid, $params, $useditems, $oldgrade)
 validate_formula ($formulastr)
 get_displaytype ()
 get_decimals ()
 get_formatted_range ($rangesdisplaytype=null, $rangesdecimalpoints=null)
 get_coefstring ()

Static Public Member Functions

static fetch ($params)
static fetch_all ($params)
static fetch_course_item ($courseid)
static denormalize_formula ($formula, $courseid)
static normalize_formula ($formula, $courseid)

Data Fields

 $table = 'grade_items'
 $required_fields
 $courseid
 $categoryid
 $item_category
 $parent_category
 $itemname
 $itemtype
 $itemmodule
 $iteminstance
 $itemnumber
 $iteminfo
 $idnumber
 $calculation
 $calculation_normalized
 $formula
 $gradetype = GRADE_TYPE_VALUE
 $grademax = 100
 $grademin = 0
 $scaleid
 $scale
 $outcomeid
 $outcome
 $gradepass = 0
 $multfactor = 1.0
 $plusfactor = 0
 $aggregationcoef = 0
 $sortorder = 0
 $display = GRADE_DISPLAY_TYPE_DEFAULT
 $decimals = null
 $locked = 0
 $locktime = 0
 $needsupdate = 1
 $dependson_cache = null

Detailed Description

Class representing a grade item. It is responsible for handling its DB representation, modifying and returning its metadata.

Definition at line 33 of file grade_item.php.


Member Function Documentation

add_idnumber ( idnumber)

Set idnumber of grade item, updates also course_modules table

Parameters:
string$idnumber(without magic quotes)
Returns:
boolean success

Definition at line 419 of file grade_item.php.

Here is the call graph for this function:

adjust_raw_grade ( rawgrade,
rawmin,
rawmax 
)

Given a float grade value or integer grade scale, applies a number of adjustment based on grade_item variables and returns the result.

Parameters:
float$rawgradeThe raw grade value.
float$rawminoriginal rawmin
float$rawmaxoriginal rawmax
Returns:
mixed

Definition at line 708 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

bounded_grade ( gradevalue)

Makes sure value is a valid grade value.

Parameters:
float$gradevalue
Returns:
mixed float or int fixed grade value

Definition at line 1231 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Lock the grade if needed - make sure this is called only when final grades are valid

Definition at line 530 of file grade_item.php.

Here is the call graph for this function:

compute ( userid = null)

Calculates final grade values using the formula in calculation property. The parameters are taken from final grades of grade items in current course only.

Returns:
boolean false if error

Definition at line 1660 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

delete ( source = null)

Delete all grades and force_regrading of parent category.

Parameters:
string$sourcefrom where was the object deleted (mod/forum, manual, etc.)
Returns:
boolean success

Reimplemented from grade_object.

Definition at line 335 of file grade_item.php.

Here is the call graph for this function:

delete_all_grades ( source = null)

Delete all grades

Parameters:
string$sourcefrom where was the object deleted (mod/forum, manual, etc.)
Returns:
boolean success

Definition at line 345 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static denormalize_formula ( formula,
courseid 
) [static]

Denormalizes the calculation formula to [idnumber] form

Parameters:
string$formula
Returns:
string denormalized string

Definition at line 1019 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

depends_on ( reset_cache = false)

Finds out on which other items does this depend directly when doing calculation or category aggregation

Parameters:
bool$reset_cache
Returns:
array of grade_item ids this one depends on

Definition at line 1268 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static fetch ( params) [static]

Finds and returns a grade_item instance based on params.

Parameters:
array$paramsassociative arrays varname=>value
Returns:
object grade_item instance or false if none found.

Reimplemented from grade_object.

Definition at line 315 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static fetch_all ( params) [static]

Finds and returns all grade_item instances based on params.

Parameters:
array$paramsassociative arrays varname=>value
Returns:
array array of grade_item instances or false if none found.

Reimplemented from grade_object.

Definition at line 326 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static fetch_course_item ( courseid) [static]

Returns grade item associated with the course

Parameters:
int$courseid
Returns:
course item object

Definition at line 946 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Sets this grade_item's needsupdate to true. Also marks the course item as needing update.

Returns:
void

Definition at line 771 of file grade_item.php.

Here is the caller graph for this function:

Returns calculation string if grade calculated.

Returns:
mixed string if calculation used, null if not

Definition at line 991 of file grade_item.php.

Here is the call graph for this function:

Queries parent categories recursively to find the aggregationcoef type that applies to this grade item.

Definition at line 1987 of file grade_item.php.

Here is the call graph for this function:

Returns the value of the decimals field. It can be set at 3 levels: grade_item, course setting and site. The lowest level overrides the higher ones.

Returns:
int Decimals (0 - 5)

Definition at line 1931 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Returns the value of the display type. It can be set at 3 levels: grade_item, course setting and site. The lowest level overrides the higher ones.

Returns:
int Display type

Definition at line 1916 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_final ( userid = NULL)

Returns the final values for this grade item (as imported by module or other source).

Parameters:
int$useridOptional: to retrieve a single final grade
Returns:
mixed An array of all final_grades (stdClass objects) for this grade_item, or a single final_grade.

Definition at line 1068 of file grade_item.php.

Here is the caller graph for this function:

get_formatted_range ( rangesdisplaytype = null,
rangesdecimalpoints = null 
)

Returns a string representing the range of grademin - grademax for this grade item.

Parameters:
int$rangesdisplaytype
int$rangesdecimalpoints
Returns:
string

Definition at line 1948 of file grade_item.php.

Here is the call graph for this function:

get_grade ( userid,
create = true 
)

Get (or create if not exist yet) grade for this user

Parameters:
int$userid
Returns:
object grade_grade object instance

Definition at line 1094 of file grade_item.php.

Here is the call graph for this function:

Returns this grade_item. This method is also available in grade_category, for cases where the object type is not know.

Returns:
string idnumber

Definition at line 1131 of file grade_item.php.

Returns the idnumber of this grade_item. This method is also available in grade_category, for cases where the object type is not know.

Returns:
string idnumber

Definition at line 1122 of file grade_item.php.

Here is the caller graph for this function:

Returns the grade_category for category item

Returns:
mixed grade_category object if applicable, false otherwise

Definition at line 858 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Set the locktime for this grade item.

Returns:
int $locktime timestamp for lock to activate

Definition at line 557 of file grade_item.php.

Here is the caller graph for this function:

get_name ( fulltotal = false)

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.

Parameters:
boolean$fulltotal,:if the item is a category total, returns $categoryname."total" instead of "Category total" or "Course total"
Returns:
string name

Definition at line 1168 of file grade_item.php.

Here is the call graph for this function:

Returns the grade_category object this grade_item belongs to (referenced by categoryid) or category attached to category item.

Returns:
mixed grade_category object if applicable, false if course item

Definition at line 832 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Returns the sortorder of this grade_item. This method is also available in grade_category, for cases where the object type is not know.

Returns:
int Sort order

Definition at line 1113 of file grade_item.php.

Here is the caller graph for this function:

has_hidden_grades ( groupsql = "",
array params = null,
groupwheresql = "" 
)

Returns the number of grades that are hidden.

Parameters:
string$groupsql
array$paramssql params in $groupsql
string$groupsqlwhere
Returns:
int Number of hidden grades

Definition at line 599 of file grade_item.php.

insert ( source = null)

In addition to perform parent::insert(), calls force_regrading() method too.

Parameters:
string$sourcefrom where was the object inserted (mod/forum, manual, etc.)
Returns:
int PK ID if successful, false otherwise

Reimplemented from grade_object.

Definition at line 364 of file grade_item.php.

Here is the call graph for this function:

Checks if grade calculated. Returns this object's calculation.

Returns:
boolean true if grade item calculated.

Definition at line 968 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Is the grade item associated with category?

Returns:
boolean

Definition at line 881 of file grade_item.php.

Here is the caller graph for this function:

Is the grade item associated with course?

Returns:
boolean

Definition at line 889 of file grade_item.php.

Here is the caller graph for this function:

Is grading object editable?

Returns:
boolean

Definition at line 960 of file grade_item.php.

Is the grade item external - associated with module, plugin or something else?

Returns:
boolean

Definition at line 913 of file grade_item.php.

Here is the caller graph for this function:

is_locked ( userid = NULL)

Returns the locked state of this grade_item (if the grade_item is locked OR no specific $userid is given) or the locked state of a specific grade within this item if a specific $userid is given and the grade_item is unlocked.

Parameters:
int$userid
Returns:
boolean Locked state

Definition at line 456 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Is this a manually graded item?

Returns:
boolean

Definition at line 897 of file grade_item.php.

Here is the caller graph for this function:

Is this an outcome item?

Returns:
boolean

Definition at line 905 of file grade_item.php.

Here is the caller graph for this function:

Is the grade item overridable

Returns:
boolean

Definition at line 921 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Is the grade item feedback overridable

Returns:
boolean

Definition at line 929 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Returns true if grade items uses raw grades

Returns:
boolean

Definition at line 937 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Calls upon the get_item_category method to retrieve the grade_category object from the DB and assigns it to $this->item_category. It also returns the object.

Returns:
object Grade_category

Definition at line 870 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Instantiates a grade_outcome object whose data is retrieved from the DB, if this item's outcomeid variable is set.

Returns:
object grade_outcome

Definition at line 819 of file grade_item.php.

Here is the call graph for this function:

Calls upon the get_parent_category method to retrieve the grade_category object from the DB and assigns it to $this->parent_category. It also returns the object.

Returns:
object Grade_category

Definition at line 846 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Instantiates a grade_scale object whose data is retrieved from the DB, if this item's scaleid variable is set.

Returns:
object grade_scale or null if no scale used

Definition at line 785 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

move_after_sortorder ( sortorder)

Definition at line 1149 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static normalize_formula ( formula,
courseid 
) [static]

Normalizes the calculation formula to [#giXX#] form

Parameters:
string$formula
Returns:
string normalized string

Definition at line 1045 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Returns:
boolean

Definition at line 281 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

refresh_grades ( userid = 0)

Refetch grades from modules, plugins.

Parameters:
int$useridoptional, one user only

Definition at line 1371 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

regrade_final_grades ( userid = null)

Performs the necessary calculations on the grades_final referenced by this grade_item. Also resets the needsupdate flag once successfully performed.

This function must be used ONLY from lib/gradeslib.php/grade_regrade_final_grades(), because the regrading must be done in correct order!!

Returns:
boolean true if ok, error string otherwise

Definition at line 627 of file grade_item.php.

Here is the call graph for this function:

Mark regrading as finished successfully.

Definition at line 611 of file grade_item.php.

set_calculation ( formula)

Sets this item's calculation (creates it) if not yet set, or updates it if already set (in the DB). If no calculation is given, the calculation is removed.

Parameters:
string$formulastring representation of formula used for calculation
Returns:
boolean success

Definition at line 1007 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

set_hidden ( hidden,
cascade = false 
)

Set the hidden status of grade_item and all grades, 0 mean visible, 1 always hidden, number means date to hide until.

Parameters:
int$hiddennew hidden status
boolean$cascadeapply to child objects too
Returns:
void

Reimplemented from grade_object.

Definition at line 567 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

set_locked ( lockedstate,
cascade = false,
refresh = true 
)

Locks or unlocks this grade_item and (optionally) all its associated final grades.

Parameters:
int$locked0, 1 or a timestamp int(10) after which date the item will be locked.
boolean$cascadelock/unlock child objects too
boolean$refreshrefresh grades when unlocking
Returns:
boolean true if grade_item all grades updated, false if at least one update fails

setting lock

removing lock

Definition at line 478 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

set_locktime ( locktime)

Set the locktime for this grade item.

Parameters:
int$locktimetimestamp for lock to activate
Returns:
void

Definition at line 547 of file grade_item.php.

Here is the call graph for this function:

set_parent ( parentid)

Sets this item's categoryid. A generic method shared by objects that have a parent id of some kind.

Parameters:
int$parentid
Returns:
boolean success;

Definition at line 1196 of file grade_item.php.

Here is the call graph for this function:

set_sortorder ( sortorder)

Sets the sortorder of this grade_item. This method is also available in grade_category, for cases where the object type is not know.

Parameters:
int$sortorder
Returns:
void

Definition at line 1141 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

update ( source = null)

In addition to update() as defined in grade_object, handle the grade_outcome and grade_scale objects. Force regrading if necessary, rounds the float numbers using php function, the reason is we need to compare the db value with computed number to skip regrading if possible.

Parameters:
string$sourcefrom where was the object inserted (mod/forum, manual, etc.)
Returns:
boolean success

Reimplemented from grade_object.

Definition at line 248 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

update_final_grade ( userid,
finalgrade = false,
source = NULL,
feedback = false,
feedbackformat = FORMAT_MOODLE,
usermodified = null 
)

Updates final grade value for given user, this is a only way to update final grades from gradebook and import because it logs the change in history table and deals with overridden flag. This flag is set to prevent later overriding from raw grades submitted from modules.

Parameters:
int$useridthe graded user
mixed$finalgradefloat value of final grade - false means do not change
string$howmodifiedmodification source
string$noteoptional note
mixed$feedbackteachers feedback as string - false means do not change
int$feedbackformat
Returns:
boolean success

Definition at line 1410 of file grade_item.php.

Here is the call graph for this function:

update_raw_grade ( userid,
rawgrade = false,
source = NULL,
feedback = false,
feedbackformat = FORMAT_MOODLE,
usermodified = null,
dategraded = null,
datesubmitted = null,
grade = null 
)

Updates raw grade value for given user, this is a only way to update raw grades from external source (modules, etc.), because it logs the change in history table and deals with final grade recalculation.

Parameters:
int$useridthe graded user
mixed$rawgradefloat value of raw grade - false means do not change
string$howmodifiedmodification source
string$noteoptional note
mixed$feedbackteachers feedback as string - false means do not change
int$feedbackformat
int$usermodified- user which did the grading
int$dategraded
int$datesubmitted
object$gradeobject - useful for bulk upgrades
Returns:
boolean success

Definition at line 1524 of file grade_item.php.

Here is the call graph for this function:

use_formula ( userid,
params,
useditems,
oldgrade 
)

internal function - does the final grade calculation

Definition at line 1756 of file grade_item.php.

Here is the call graph for this function:

Here is the caller graph for this function:

validate_formula ( formulastr)

Validate the formula.

Parameters:
string$formula
Returns:
boolean true if calculation possible, false otherwise

Definition at line 1839 of file grade_item.php.

Here is the call graph for this function:


Field Documentation

float $aggregationcoef = 0

Aggregation coeficient used for weighted averages

Definition at line 198 of file grade_item.php.

string $calculation

Calculation string used for this item.

Definition at line 121 of file grade_item.php.

$calculation_normalized

Definition at line 128 of file grade_item.php.

int $categoryid

The category this grade_item belongs to (optional).

Definition at line 60 of file grade_item.php.

int $courseid

The course this grade_item belongs to.

Definition at line 54 of file grade_item.php.

int $decimals = null

The number of digits after the decimal point symbol. Applies only to REAL and PERCENTAGE grade display types.

Definition at line 216 of file grade_item.php.

$dependson_cache = null

Cached dependson array

Definition at line 239 of file grade_item.php.

Display type of the grades (Real, Percentage, Letter, or default).

Definition at line 210 of file grade_item.php.

$formula

Math evaluation object

Definition at line 132 of file grade_item.php.

float $grademax = 100

Maximum allowable grade.

Definition at line 144 of file grade_item.php.

float $grademin = 0

Minimum allowable grade.

Definition at line 150 of file grade_item.php.

float $gradepass = 0

grade required to pass. (grademin <= gradepass <= grademax)

Definition at line 180 of file grade_item.php.

int $gradetype = GRADE_TYPE_VALUE

The type of grade (0 = none, 1 = value, 2 = scale, 3 = text)

Definition at line 138 of file grade_item.php.

string $idnumber

Arbitrary idnumber provided by the module responsible.

Definition at line 115 of file grade_item.php.

object $item_category

The grade_category object referenced $this->iteminstance (itemtype must be == 'category' or == 'course' in that case).

Definition at line 66 of file grade_item.php.

string $iteminfo

Info and notes about this item.

Definition at line 109 of file grade_item.php.

int $iteminstance

ID of the item module

Definition at line 97 of file grade_item.php.

string $itemmodule

The module pushing this grade (e.g. 'forum', 'quiz', 'assignment' etc).

Definition at line 91 of file grade_item.php.

string $itemname

The name of this grade_item (pushed by the module).

Definition at line 79 of file grade_item.php.

int $itemnumber

Number of the item in a series of multiple grades pushed by an activity.

Definition at line 103 of file grade_item.php.

string $itemtype

e.g. 'category', 'course' and 'mod', 'blocks', 'import', etc...

Definition at line 85 of file grade_item.php.

int $locked = 0

Grade item lock flag. Empty if not locked, locked if any value present, usually date when item was locked. Locking prevents updating.

Definition at line 222 of file grade_item.php.

int $locktime = 0

Date after which the grade will be locked. Empty means no automatic locking.

Definition at line 228 of file grade_item.php.

float $multfactor = 1.0

Multiply all grades by this number.

Definition at line 186 of file grade_item.php.

boolean $needsupdate = 1

If set, the whole column will be recalculated, then this flag will be switched off.

Definition at line 234 of file grade_item.php.

object $outcome

The grade_outcome this grade is associated with, if applicable.

Definition at line 174 of file grade_item.php.

int $outcomeid

The id of the optional grade_outcome associated with this grade_item.

Definition at line 168 of file grade_item.php.

object $parent_category

The grade_category object referenced by $this->categoryid.

Definition at line 72 of file grade_item.php.

float $plusfactor = 0

Add this to all grades.

Definition at line 192 of file grade_item.php.

array $required_fields
Initial value:
 array('id', 'courseid', 'categoryid', 'itemname', 'itemtype', 'itemmodule', 'iteminstance',
                                 'itemnumber', 'iteminfo', 'idnumber', 'calculation', 'gradetype', 'grademax', 'grademin',
                                 'scaleid', 'outcomeid', 'gradepass', 'multfactor', 'plusfactor', 'aggregationcoef',
                                 'sortorder', 'display', 'decimals', 'hidden', 'locked', 'locktime', 'needsupdate', 'timecreated',
                                 'timemodified')

Array of required table fields, must start with 'id'.

Reimplemented from grade_object.

Definition at line 44 of file grade_item.php.

object $scale

A grade_scale object (referenced by $this->scaleid).

Definition at line 162 of file grade_item.php.

int $scaleid

id of the scale, if this grade is based on a scale.

Definition at line 156 of file grade_item.php.

int $sortorder = 0

Sorting order of the columns.

Definition at line 204 of file grade_item.php.

string $table = 'grade_items'

DB Table (used by grade_object).

Reimplemented from grade_object.

Definition at line 38 of file grade_item.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations