Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
grade_tree Class Reference

This class represents a complete tree of categories, grade_items and final grades, organises as an array primarily, but which can also be converted to other formats. More...

Inheritance diagram for grade_tree:
grade_structure

Public Member Functions

 __construct ($courseid, $fillers=true, $category_grade_last=false, $collapsed=null, $nooutcomes=false)
 Constructor, retrieves and stores a hierarchical array of all grade_category and grade_item objects for the given courseid.
 
 category_collapse (&$element, $collapsed)
 Static recursive helper - removes items from collapsed categories.
 
 category_grade_last (&$element)
 Static recursive helper - makes the grade_item for category the last children.
 
 exporttojson ($root=null, $tabs="\t")
 Returns a JSON representation of the grade-tree using recursion.
 
 exporttoxml ($root=null, $tabs="\t")
 Returns a well-formed XML representation of the grade-tree using recursion.
 
 fill_levels (&$levels, &$element, $depth)
 Static recursive helper - fills the levels array, useful when accessing tree elements of one level.
 
 get_advanced_grading_link (array $element, object $gpr)
 Returns link to the advanced grading page.
 
 get_calculation_icon ($element, $gpr, $returnactionmenulink=false)
 Return calculation icon for given element.
 
 get_cell_action_menu (array $element, string $mode, grade_plugin_return $gpr, ?moodle_url $baseurl=null)
 Returns an action menu for the grade.
 
 get_delete_link (array $element, object $gpr)
 Returns a link to delete a given element.
 
 get_duplicate_link (array $element, object $gpr)
 Returns a link to duplicate a given element.
 
 get_edit_calculation_link (array $element, object $gpr)
 Returns link to edit calculation for a grade item.
 
 get_edit_icon ($element, $gpr, $returnactionmenulink=false)
 Return edit icon for give element.
 
 get_edit_link (array $element, object $gpr)
 Returns a link leading to the edit grade/grade item/category page.
 
 get_element_header (array &$element, bool $withlink=false, bool $icon=true, bool $spacerifnone=false, bool $withdescription=false, bool $fulltotal=false, ?moodle_url $sortlink=null)
 Returns name of element optionally with icon and link.
 
 get_element_icon (&$element, $spacerifnone=false)
 Returns icon of element.
 
 get_element_type_string (array $element)
 Returns the string that describes the type of the element.
 
 get_grade_action_menu (grade_grade $grade)
 Returns an action menu for the grade.
 
 get_grade_analysis_icon (grade_grade $grade)
 Returns an action icon leading to the grade analysis page.
 
 get_grade_analysis_link (grade_grade $grade)
 Returns a link leading to the grade analysis page.
 
 get_grade_analysis_url (grade_grade $grade)
 Returns URL of a page that is supposed to contain detailed grade analysis.
 
 get_grade_eid ($grade_grade)
 Returns the grade eid - the grade may not exist yet.
 
 get_hiding_icon ($element, $gpr, $returnactionmenulink=false)
 Return hiding icon for give element.
 
 get_hiding_link (array $element, object $gpr)
 Returns a link with url to hide/unhide grade/grade item/grade category.
 
 get_item ($itemid)
 Returns a specific Grade Item.
 
 get_item_eid ($grade_item)
 Returns the grade_item eid.
 
 get_items ()
 Returns the array of grade items.
 
 get_levels ()
 Returns the array of levels.
 
 get_locking_icon ($element, $gpr)
 Return locking icon for given element.
 
 get_locking_link (array $element, object $gpr)
 Returns link to lock/unlock grade/grade item/grade category.
 
 get_params_for_iconstr ($element)
 Given a grade_tree element, returns an array of parameters used to build an icon for that element.
 
 get_reset_icon ($element, $gpr, $returnactionmenulink=false)
 Return a reset icon for the given element.
 
 get_reset_weights_link (array $element, object $gpr)
 Returns a link to reset weights for the given element.
 
 get_sorting_link (moodle_url $sortlink, object $gpr, string $direction='asc')
 Returns link to sort grade item column.
 
 grade_tree ($courseid, $fillers=true, $category_grade_last=false, $collapsed=null, $nooutcomes=false)
 Old syntax of class constructor.
 
 inject_colspans (&$element)
 Static recursive helper - add colspan information into categories.
 
 inject_fillers (&$element, $depth)
 Static recursive helper - makes full tree (all leafes are at the same level)
 
 locate_element ($eid)
 Parses the array in search of a given eid and returns a element object with information about the element it has found.
 
 no_outcomes (&$element)
 Static recursive helper - removes all outcomes.
 
 set_grade_status_icons (array $element)
 Sets status icons for the grade.
 

Static Public Member Functions

static can_output_item ($element)
 Determines whether the grade tree item can be displayed.
 

Public Attributes

 $context
 
 $courseid
 
array $items
 Grade items $items.
 
array $levels
 2D array of grade items and categories $levels
 
course_modinfo $modinfo
 Reference to modinfo for current course (for performance, to save retrieving it from courseid every time).
 
object $top_element
 The basic representation of the tree as a hierarchical, 3-tiered array.
 

Detailed Description

This class represents a complete tree of categories, grade_items and final grades, organises as an array primarily, but which can also be converted to other formats.

It has simple method calls with complex implementations, allowing for easy insertion, deletion and moving of items and categories within the tree.

@uses grade_structure

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

grade_tree::__construct ( $courseid,
$fillers = true,
$category_grade_last = false,
$collapsed = null,
$nooutcomes = false )

Constructor, retrieves and stores a hierarchical array of all grade_category and grade_item objects for the given courseid.

Full objects are instantiated. Ordering sequence is fixed if needed.

Parameters
int$courseidThe Course ID
bool$fillersinclude fillers and colspans, make the levels var "rectangular"
bool$category_grade_lastcategory grade item is the last child
array$collapsedarray of collapsed categories
bool$nooutcomesWhether or not outcomes should be included

Member Function Documentation

◆ can_output_item()

static grade_tree::can_output_item ( $element)
static

Determines whether the grade tree item can be displayed.

This is particularly targeted for grade categories that have no total (None) when rendering the grade tree. It checks if the grade tree item is of type 'category', and makes sure that the category, or at least one of children, can be output.

Parameters
array$elementThe grade category element.
Return values
boolTrue if the grade tree item can be displayed. False, otherwise.

◆ category_collapse()

grade_tree::category_collapse ( & $element,
$collapsed )

Static recursive helper - removes items from collapsed categories.

Parameters
array&$elementThe seed of the recursion
array$collapsedarray of collapsed categories
Return values
void

◆ category_grade_last()

grade_tree::category_grade_last ( & $element)

Static recursive helper - makes the grade_item for category the last children.

Parameters
array&$elementThe seed of the recursion
Return values
void

◆ exporttojson()

grade_tree::exporttojson ( $root = null,
$tabs = "\t" )

Returns a JSON representation of the grade-tree using recursion.

Parameters
array$rootThe current element in the recursion. If null, starts at the top of the tree.
string$tabsTab characters used to indent the string nicely for humans to enjoy
Return values
string

◆ exporttoxml()

grade_tree::exporttoxml ( $root = null,
$tabs = "\t" )

Returns a well-formed XML representation of the grade-tree using recursion.

Parameters
array$rootThe current element in the recursion. If null, starts at the top of the tree.
string$tabsThe control character to use for tabs
Return values
string\$xml

◆ fill_levels()

grade_tree::fill_levels ( & $levels,
& $element,
$depth )

Static recursive helper - fills the levels array, useful when accessing tree elements of one level.

Parameters
array&$levelsThe levels of the grade tree through which to recurse
array&$elementThe seed of the recursion
int$depthHow deep are we?
Return values
void

◆ get_advanced_grading_link()

grade_structure::get_advanced_grading_link ( array $element,
object $gpr )
inherited

Returns link to the advanced grading page.

Parameters
array$elementAn array representing an element in the grade_tree
object$gprA grade_plugin_return object
Return values
string|null

◆ get_calculation_icon()

grade_structure::get_calculation_icon ( $element,
$gpr,
$returnactionmenulink = false )
inherited

Return calculation icon for given element.

Parameters
array$elementAn array representing an element in the grade_tree
object$gprA grade_plugin_return object
bool$returnactionmenulinkreturn the instance of action_menu_link instead of string
Return values
string|action_menu_link
Deprecated
since Moodle 4.2 - The row is not shown anymore - we have actions menu.
Todo
MDL-77307 This will be deleted in Moodle 4.6.

◆ get_cell_action_menu()

grade_structure::get_cell_action_menu ( array $element,
string $mode,
grade_plugin_return $gpr,
?moodle_url $baseurl = null )
inherited

Returns an action menu for the grade.

Parameters
array$elementArray with cell info.
string$modeMode - gradeitem or user
grade_plugin_return$gpr
moodle_url | null$baseurl
Return values
string

◆ get_delete_link()

grade_structure::get_delete_link ( array $element,
object $gpr )
inherited

Returns a link to delete a given element.

Parameters
array$elementAn array representing an element in the grade_tree
object$gprA grade_plugin_return object
Return values
string|null

◆ get_duplicate_link()

grade_structure::get_duplicate_link ( array $element,
object $gpr )
inherited

Returns a link to duplicate a given element.

Parameters
array$elementAn array representing an element in the grade_tree
object$gprA grade_plugin_return object
Return values
string|null

◆ get_edit_calculation_link()

grade_structure::get_edit_calculation_link ( array $element,
object $gpr )
inherited

Returns link to edit calculation for a grade item.

Parameters
array$elementAn array representing an element in the grade_tree
object$gprA grade_plugin_return object
Return values
string|null

◆ get_edit_icon()

grade_structure::get_edit_icon ( $element,
$gpr,
$returnactionmenulink = false )
inherited

Return edit icon for give element.

Parameters
array$elementAn array representing an element in the grade_tree
object$gprA grade_plugin_return object
bool$returnactionmenulinkreturn the instance of action_menu_link instead of string
Return values
string|action_menu_link
Deprecated
since Moodle 4.2 - The row is not shown anymore - we have actions menu.
Todo
MDL-77307 This will be deleted in Moodle 4.6.

◆ get_edit_link()

grade_structure::get_edit_link ( array $element,
object $gpr )
inherited

Returns a link leading to the edit grade/grade item/category page.

Parameters
array$elementAn array representing an element in the grade_tree
object$gprA grade_plugin_return object
Return values
string|null

◆ get_element_header()

grade_structure::get_element_header ( array & $element,
bool $withlink = false,
bool $icon = true,
bool $spacerifnone = false,
bool $withdescription = false,
bool $fulltotal = false,
?moodle_url $sortlink = null )
inherited

Returns name of element optionally with icon and link.

Parameters
array&$elementAn array representing an element in the grade_tree
bool$withlinkWhether or not this header has a link
bool$iconWhether or not to display an icon with this header
bool$spacerifnonereturn spacer if no icon found
bool$withdescriptionShow description if defined by this item.
bool$fulltotalIf the item is a category total, returns $categoryname."total" instead of "Category total" or "Course total"
moodle_url | null$sortlinkLink to sort column.
Return values
stringheader
Deprecated
since Moodle 4.4 - please use {
See also
grade_helper\get_element_header()}
Todo
MDL-79907 This will be deleted in Moodle 4.8.

◆ get_element_icon()

grade_structure::get_element_icon ( & $element,
$spacerifnone = false )
inherited

Returns icon of element.

Parameters
array&$elementAn array representing an element in the grade_tree
bool$spacerifnonereturn spacer if no icon found
Return values
stringicon or spacer
Deprecated
since Moodle 4.4 - please use {
See also
grade_helper\get_element_icon()}
Todo
MDL-79907 This will be deleted in Moodle 4.8.

◆ get_element_type_string()

grade_structure::get_element_type_string ( array $element)
inherited

Returns the string that describes the type of the element.

Parameters
array$elementAn array representing an element in the grade_tree
Return values
stringThe string that describes the type of the grade element
Deprecated
since Moodle 4.4 - please use {
See also
grade_helper\get_element_type_string()}
Todo
MDL-79907 This will be deleted in Moodle 4.8.

◆ get_grade_action_menu()

grade_structure::get_grade_action_menu ( grade_grade $grade)
inherited

Returns an action menu for the grade.

Parameters
grade_grade$gradeA grade_grade object
Return values
string

◆ get_grade_analysis_icon()

grade_structure::get_grade_analysis_icon ( grade_grade $grade)
inherited

Returns an action icon leading to the grade analysis page.

Parameters
grade_grade$grade
Return values
string
Deprecated
since Moodle 4.2 - The row is not shown anymore - we have actions menu.
Todo
MDL-77307 This will be deleted in Moodle 4.6.

◆ get_grade_analysis_link()

grade_structure::get_grade_analysis_link ( grade_grade $grade)
inherited

Returns a link leading to the grade analysis page.

Parameters
grade_grade$grade
Return values
string|null

◆ get_grade_analysis_url()

grade_structure::get_grade_analysis_url ( grade_grade $grade)
inherited

Returns URL of a page that is supposed to contain detailed grade analysis.

At the moment, only activity modules are supported. The method generates link to the module's file grade.php with the parameters id (cmid), itemid, itemnumber, gradeid and userid. If the grade.php does not exist, null is returned.

Return values
moodle_url|nullURL or null if unable to construct it

◆ get_grade_eid()

grade_structure::get_grade_eid ( $grade_grade)
inherited

Returns the grade eid - the grade may not exist yet.

Parameters
grade_grade$grade_gradeA grade_grade object
Return values
stringeid

◆ get_hiding_icon()

grade_structure::get_hiding_icon ( $element,
$gpr,
$returnactionmenulink = false )
inherited

Return hiding icon for give element.

Parameters
array$elementAn array representing an element in the grade_tree
object$gprA grade_plugin_return object
bool$returnactionmenulinkreturn the instance of action_menu_link instead of string
Return values
string|action_menu_link
Deprecated
since Moodle 4.2 - The row is not shown anymore - we have actions menu.
Todo
MDL-77307 This will be deleted in Moodle 4.6.

◆ get_hiding_link()

grade_structure::get_hiding_link ( array $element,
object $gpr )
inherited

Returns a link with url to hide/unhide grade/grade item/grade category.

Parameters
array$elementAn array representing an element in the grade_tree
object$gprA grade_plugin_return object
Return values
string|null

◆ get_item()

grade_tree::get_item ( $itemid)

Returns a specific Grade Item.

Parameters
int$itemidThe ID of the grade_item object
Return values
grade_item

◆ get_item_eid()

grade_structure::get_item_eid ( $grade_item)
inherited

Returns the grade_item eid.

Parameters
grade_item$grade_itemA grade_item object
Return values
stringeid

◆ get_items()

grade_tree::get_items ( )

Returns the array of grade items.

Return values
array

◆ get_levels()

grade_tree::get_levels ( )

Returns the array of levels.

Return values
array

◆ get_locking_icon()

grade_structure::get_locking_icon ( $element,
$gpr )
inherited

Return locking icon for given element.

Parameters
array$elementAn array representing an element in the grade_tree
object$gprA grade_plugin_return object
Return values
string
Deprecated
since Moodle 4.2 - The row is not shown anymore - we have actions menu.
Todo
MDL-77307 This will be deleted in Moodle 4.6.

◆ get_locking_link()

grade_structure::get_locking_link ( array $element,
object $gpr )
inherited

Returns link to lock/unlock grade/grade item/grade category.

Parameters
array$elementAn array representing an element in the grade_tree
object$gprA grade_plugin_return object
Return values
string|null

◆ get_params_for_iconstr()

grade_structure::get_params_for_iconstr ( $element)
inherited

Given a grade_tree element, returns an array of parameters used to build an icon for that element.

Parameters
array$elementAn array representing an element in the grade_tree
Return values
array

◆ get_reset_icon()

grade_structure::get_reset_icon ( $element,
$gpr,
$returnactionmenulink = false )
inherited

Return a reset icon for the given element.

Parameters
array$elementAn array representing an element in the grade_tree
object$gprA grade_plugin_return object
bool$returnactionmenulinkreturn the instance of action_menu_link instead of string
Return values
string|action_menu_link
Deprecated
since Moodle 4.2 - The row is not shown anymore - we have actions menu.
Todo
MDL-77307 This will be deleted in Moodle 4.6.

◆ get_reset_weights_link()

grade_structure::get_reset_weights_link ( array $element,
object $gpr )
inherited

Returns a link to reset weights for the given element.

Parameters
array$elementAn array representing an element in the grade_tree
object$gprA grade_plugin_return object
Return values
string|null

◆ get_sorting_link()

grade_structure::get_sorting_link ( moodle_url $sortlink,
object $gpr,
string $direction = 'asc' )
inherited

Returns link to sort grade item column.

Parameters
moodle_url$sortlinkA base link for sorting
object$gprA grade_plugin_return object
string$directionDirection od sorting
Return values
string

◆ grade_tree()

grade_tree::grade_tree ( $courseid,
$fillers = true,
$category_grade_last = false,
$collapsed = null,
$nooutcomes = false )

Old syntax of class constructor.

Deprecated in PHP7.

Deprecated
since Moodle 3.1

◆ inject_colspans()

grade_tree::inject_colspans ( & $element)

Static recursive helper - add colspan information into categories.

Parameters
array&$elementThe seed of the recursion
Return values
int

◆ inject_fillers()

grade_tree::inject_fillers ( & $element,
$depth )

Static recursive helper - makes full tree (all leafes are at the same level)

Parameters
array&$elementThe seed of the recursion
int$depthHow deep are we?
Return values
int

◆ locate_element()

grade_tree::locate_element ( $eid)

Parses the array in search of a given eid and returns a element object with information about the element it has found.

Parameters
int$eidGradetree Element ID
Return values
objectelement

◆ no_outcomes()

grade_tree::no_outcomes ( & $element)

Static recursive helper - removes all outcomes.

Parameters
array&$elementThe seed of the recursion
Return values
void

◆ set_grade_status_icons()

grade_structure::set_grade_status_icons ( array $element)
inherited

Sets status icons for the grade.

Parameters
array$elementarray with grade item info
Return values
string|nullstatus icons container HTML

Member Data Documentation

◆ $modinfo

course_modinfo grade_structure::$modinfo
inherited

Reference to modinfo for current course (for performance, to save retrieving it from courseid every time).

Not actually set except for the grade_tree type.

◆ $top_element

object grade_tree::$top_element

The basic representation of the tree as a hierarchical, 3-tiered array.

$top_element


The documentation for this class was generated from the following file: