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]

Advanced grading methods support

Copyright: 2011 David Mudrak <david@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 681 lines (24 kb)
Included or required: 2 times
Referenced: 10 times
Includes or requires: 0 files

Defines 1 class

Defines 24 functions


Class: grading_manager  - X-Ref

General class providing access to common grading features

Grading manager provides access to the particular grading method controller
in that area.

Fully initialized instance of the grading manager operates over a single
gradable area. It is possible to work with a partially initialized manager
that knows just context and component without known area, for example.
It is also possible to change context, component and area of an existing
manager. Such pattern is used when copying form definitions, for example.

get_context()   X-Ref
Returns grading manager context

return: stdClass grading manager context

set_context(stdClass $context)   X-Ref
Sets the context the manager operates on

param: stdClass $context

get_component()   X-Ref
Returns grading manager component

return: string grading manager component

set_component($component)   X-Ref
Sets the component the manager operates on

param: string $component the frankenstyle name of the component

get_area()   X-Ref
Returns grading manager area name

return: string grading manager area name

set_area($area)   X-Ref
Sets the area the manager operates on

param: string $area the name of the gradable area

get_component_title()   X-Ref
Returns a text describing the context and the component

At the moment this works for gradable areas in course modules. In the future, this
method should be improved so it works for other contexts (blocks, gradebook items etc)
or subplugins.

return: string

get_area_title()   X-Ref
Returns the localized title of the currently set area

return: string

load($areaid)   X-Ref
Loads the gradable area info from the database

param: int $areaid

available_methods($includenone = true)   X-Ref
Returns the list of installed grading plugins together, optionally extended
with a simple direct grading.

param: bool $includenone should the 'Simple direct grading' be included
return: array of the (string)name => (string)localized title of the method

get_available_methods($includenone = true)   X-Ref
Returns the list of available grading methods in the given context

Currently this is just a static list obtained from {@link self::available_methods()}.
In the future, the list of available methods may be controlled per-context.

Requires the context property to be set in advance.

param: bool $includenone should the 'Simple direct grading' be included
return: array of the (string)name => (string)localized title of the method

available_areas($component)   X-Ref
Returns the list of gradable areas provided by the given component

This performs a callback to the library of the relevant plugin to obtain
the list of supported areas.

param: string $component normalized component name
return: array of (string)areacode => (string)localized title of the area

get_available_areas()   X-Ref
Returns the list of gradable areas in the given context and component

This performs a callback to the library of the relevant plugin to obtain
the list of supported areas.
return: array of (string)areacode => (string)localized title of the area

get_active_method()   X-Ref
Returns the currently active grading method in the gradable area

return: string|null the name of the grading plugin of null if it has not been set

set_active_method($method)   X-Ref
Sets the currently active grading method in the gradable area

param: string $method the method name, eg 'rubric' (must be available)
return: bool true if the method changed or was just set, false otherwise

extend_settings_navigation(settings_navigation $settingsnav, navigation_node $modulenode=null)   X-Ref
Extends the settings navigation with the grading settings

This function is called when the context for the page is an activity module with the
FEATURE_ADVANCED_GRADING and the user has the permission moodle/grade:managegradingforms.

param: settings_navigation $settingsnav {@link settings_navigation}
param: navigation_node $modulenode {@link navigation_node}

extend_navigation(global_navigation $navigation, navigation_node $modulenode=null)   X-Ref
Extends the module navigation with the advanced grading information

This function is called when the context for the page is an activity module with the
FEATURE_ADVANCED_GRADING.

param: global_navigation $navigation
param: navigation_node $modulenode

get_controller($method)   X-Ref
Returns the given method's controller in the gradable area

param: string $method the method name, eg 'rubric' (must be available)
return: gradingform_controller

get_active_controller()   X-Ref
Returns the controller for the active method if it is available

return: null|gradingform_controller

get_management_url(moodle_url $returnurl = null)   X-Ref
Returns the URL of the grading area management page

param: moodle_url $returnurl optional URL of the page where the user should be sent back to
return: moodle_url

create_shared_area($method)   X-Ref
Creates a new shared area to hold a grading form template

Shared area are implemented as virtual gradable areas at the system level context
with the component set to core_grading and unique random area name.

param: string $method the name of the plugin we create the area for
return: int the new area id

delete_all_for_context($contextid)   X-Ref
Removes all data associated with the given context

This is called by {@link context::delete_content()}

param: int $contextid context id

tokenize($needle)   X-Ref
Helper method to tokenize the given string

Splits the given string into smaller strings. This is a helper method for
full text searching in grading forms. If the given string is surrounded with
double quotes, the resulting array consists of a single item containing the
quoted content.

Otherwise, string like 'grammar, english language' would be tokenized into
the three tokens 'grammar', 'english', 'language'.

One-letter tokens like are dropped in non-phrase mode. Repeated tokens are
returned just once.

param: string $needle
return: array

ensure_isset(array $properties)   X-Ref
Make sure that the given properties were set to some not-null value

param: array $properties the list of properties

Functions that are not part of a class:

get_grading_manager($context_or_areaid = null, $component = null, $area = null)   X-Ref
Factory method returning an instance of the grading manager

There are basically ways how to use this factory method. If the area record
id is known to the caller, get the manager for that area by providing just
the id. If the area record id is not know, the context, component and area name
can be provided. Note that null values are allowed in the second case as the context,
component and the area name can be set explicitly later.

param: stdClass|int|null $context_or_areaid if $areaid is passed, no other parameter is needed
param: string|null $component the frankenstyle name of the component
param: string|null $area the name of the gradable area
return: grading_manager