Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
gradingform_controller Class Reference

Class represents a grading form definition used in a particular area. More...

Inheritance diagram for gradingform_controller:
gradingform_guide_controller gradingform_rubric_controller

Public Member Functions

 __construct (stdClass $context, $component, $area, $areaid)
 Do not instantinate this directly, use grading_manager::get_controller().
 
 create_instance ($raterid, $itemid=null)
 This function is invoked when user (teacher) starts grading.
 
 delete_definition ()
 Deletes the form definition and all the associated data.
 
 extend_navigation (global_navigation $navigation, navigation_node $node=null)
 Extends the module navigation.
 
 extend_settings_navigation (settings_navigation $settingsnav, navigation_node $node=null)
 Extends the module settings navigation.
 
 fetch_instance (int $raterid, int $itemid, ?int $instanceid)
 If an instanceid is specified and grading instance exists and it is created by this rater for this item, then the instance is returned.
 
 form_unavailable_notification ()
 Returns a message why this form is unavailable.
 
 get_active_instances ($itemid)
 Returns list of ACTIVE instances for the specified $itemid (intentionally does not return instances with status NEEDUPDATE)
 
 get_all_active_instances ($since=0)
 Returns an array of all active instances for this definition.
 
 get_allow_grade_decimals ()
 Returns if decimal values are allowed as grades.
 
 get_area ()
 Returns gradable area name.
 
 get_areaid ()
 Returns gradable area id.
 
 get_component ()
 Returns gradable component name.
 
 get_context ()
 Returns controller context.
 
 get_current_instance ($raterid, $itemid, $idonly=false)
 Returns the current instance (either with status ACTIVE or NEEDUPDATE) for this definition for the specified $raterid and $itemid (if multiple raters are allowed, or only for $itemid otherwise).
 
 get_definition ($force=false)
 Returns the grading form definition structure.
 
 get_definition_copy (gradingform_controller $target)
 Returns the form definition suitable for cloning into another area.
 
 get_editor_url (moodle_url $returnurl=null)
 Returns URL of a page where the grading form can be defined and edited.
 
 get_formatted_description ()
 Formats the definition description for display on page.
 
 get_grade_range ()
 Returns the range of grades used in this area.
 
 get_or_create_instance ($instanceid, $raterid, $itemid)
 If instanceid is specified and grading instance exists and it is created by this rater for this item, this instance is returned.
 
 has_active_instances ()
 Returns true if there are already people who has been graded on this definition.
 
 is_form_available ()
 Is the grading form defined and ready for usage?
 
 is_form_defined ()
 Is the form definition record available?
 
 is_own_form ($userid=null)
 Is the grading form owned by the given user?
 
 is_shared_template ()
 Is the grading form saved as a shared public template?
 
 render_grade ($page, $itemid, $gradinginfo, $defaultcontent, $cangrade)
 Returns html code to be included in student's feedback.
 
 render_preview (moodle_page $page)
 Returns the HTML code displaying the preview of the grading form.
 
 set_grade_range (array $graderange, $allowgradedecimals=false)
 Sets the range of grades used in this area.
 
 update_definition (stdClass $definition, $usermodified=null)
 Saves the defintion data into the database.
 

Static Public Member Functions

static get_external_definition_details ()
 Overridden by sub classes that wish to make definition details available to web services.
 
static get_external_instance_filling_details ()
 Overridden by sub classes that wish to make instance filling details available to web services.
 
static sql_search_from_tables ($gdid)
 Prepare the part of the search query to append to the FROM statement.
 
static sql_search_where ($token)
 Prepare the parts of the SQL WHERE statement to search for the given token.
 

Public Attributes

const DEFINITION_STATUS_DRAFT = 10
 the form is currently being edited and is not ready for usage yet
 
const DEFINITION_STATUS_NULL = 0
 undefined definition status
 
const DEFINITION_STATUS_READY = 20
 the form was marked as ready for actual usage
 

Protected Member Functions

 delete_plugin_definition ()
 Deletes all plugin data associated with the given form definiton.
 
 get_instance ($instance)
 Returns the object of type gradingform_XXX_instance (where XXX is the plugin method name)
 
 get_method_name ()
 Returns the name of the grading method plugin, eg 'rubric'.
 
 load_definition ()
 Loads the form definition if it exists.
 

Protected Attributes

string $area
 the name of the gradable area
 
int $areaid
 the id of the gradable area record
 
string $component
 the frankenstyle name of the component
 
stdClass $context
 the context
 
stdClass false $definition = false
 the definition structure
 
boolean null $hasactiveinstances = null
 cached result of function has_active_instances()
 

Detailed Description

Class represents a grading form definition used in a particular area.

General data about definition is stored in the standard DB table grading_definitions. A separate entry is created for each grading area (i.e. for each module). Plugins may define and use additional tables to store additional data about definitions.

Advanced grading plugins must declare a class gradingform_xxxx_controller extending this class and put it in lib.php in the plugin folder.

See gradingform_rubric_controller as an example

Except for overwriting abstract functions, plugin developers may want to overwrite functions responsible for loading and saving of the definition to include additional data stored.

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

Constructor & Destructor Documentation

◆ __construct()

gradingform_controller::__construct ( stdClass $context,
$component,
$area,
$areaid )

Do not instantinate this directly, use grading_manager::get_controller().

Parameters
stdClass$contextthe context of the form
string$componentthe frankenstyle name of the component
string$areathe name of the gradable area
int$areaidthe id of the gradable area record

Member Function Documentation

◆ create_instance()

gradingform_controller::create_instance ( $raterid,
$itemid = null )

This function is invoked when user (teacher) starts grading.

It creates and returns copy of the current ACTIVE instance if it exists. If this is the first grading attempt, a new instance is created. The status of the returned instance is INCOMPLETE

Parameters
int$raterid
int$itemid
Return values
gradingform_instance

◆ delete_definition()

gradingform_controller::delete_definition ( )

Deletes the form definition and all the associated data.

See also
delete_plugin_definition()
Return values
void

◆ delete_plugin_definition()

gradingform_controller::delete_plugin_definition ( )
abstractprotected

Deletes all plugin data associated with the given form definiton.

See also
delete_definition()

Reimplemented in gradingform_guide_controller, and gradingform_rubric_controller.

◆ extend_navigation()

gradingform_controller::extend_navigation ( global_navigation $navigation,
navigation_node $node = null )

Extends the module navigation.

This function is called when the context for the page is an activity module with the FEATURE_ADVANCED_GRADING and there is an area with the active grading method set to the given plugin.

Parameters
global_navigation$navigationglobal_navigation
navigation_node$nodenavigation_node

Reimplemented in gradingform_guide_controller, and gradingform_rubric_controller.

◆ extend_settings_navigation()

gradingform_controller::extend_settings_navigation ( settings_navigation $settingsnav,
navigation_node $node = null )

Extends the module settings navigation.

This function is called when the context for the page is an activity module with the FEATURE_ADVANCED_GRADING, the user has the permission moodle/grade:managegradingforms and there is an area with the active grading method set to the given plugin.

Parameters
settings_navigation$settingsnavsettings_navigation
navigation_node$nodenavigation_node

Reimplemented in gradingform_guide_controller, and gradingform_rubric_controller.

◆ fetch_instance()

gradingform_controller::fetch_instance ( int $raterid,
int $itemid,
?int $instanceid )

If an instanceid is specified and grading instance exists and it is created by this rater for this item, then the instance is returned.

If instanceid is not known, then null can be passed to fetch the current instance matchign the specified raterid and itemid.

If the instanceid is falsey, or no instance was found, then create a new instance for the specified rater and item.

Parameters
int$raterid
int$itemid
int$instanceid
Return values
gradingform_instance
Exceptions
dml_exception

◆ form_unavailable_notification()

gradingform_controller::form_unavailable_notification ( )

Returns a message why this form is unavailable.

Maybe overriden by plugins to give more details.

See also
is_form_available()
Return values
string

◆ get_active_instances()

gradingform_controller::get_active_instances ( $itemid)

Returns list of ACTIVE instances for the specified $itemid (intentionally does not return instances with status NEEDUPDATE)

Parameters
int$itemid
Return values
arrayof gradingform_instance objects

◆ get_all_active_instances()

gradingform_controller::get_all_active_instances ( $since = 0)

Returns an array of all active instances for this definition.

(intentionally does not return instances with status NEEDUPDATE)

Parameters
intsince only return instances with timemodified >= since
Return values
arrayof gradingform_instance objects

◆ get_allow_grade_decimals()

gradingform_controller::get_allow_grade_decimals ( )
final

Returns if decimal values are allowed as grades.

Return values
bool

◆ get_area()

gradingform_controller::get_area ( )

Returns gradable area name.

Return values
stringgradable area name

◆ get_areaid()

gradingform_controller::get_areaid ( )

Returns gradable area id.

Return values
intgradable area id

◆ get_component()

gradingform_controller::get_component ( )

Returns gradable component name.

Return values
stringgradable component name

◆ get_context()

gradingform_controller::get_context ( )

Returns controller context.

Return values
stdClasscontroller context

◆ get_current_instance()

gradingform_controller::get_current_instance ( $raterid,
$itemid,
$idonly = false )

Returns the current instance (either with status ACTIVE or NEEDUPDATE) for this definition for the specified $raterid and $itemid (if multiple raters are allowed, or only for $itemid otherwise).

Parameters
int$raterid
int$itemid
boolean$idonly
Return values
mixedif $idonly=true returns id of the found instance, otherwise returns the instance object

◆ get_definition()

gradingform_controller::get_definition ( $force = false)

Returns the grading form definition structure.

Parameters
boolean$forcewhether to force loading from DB even if it was already loaded
Return values
stdClass|falsedefinition data or false if the form is not defined yet

◆ get_definition_copy()

gradingform_controller::get_definition_copy ( gradingform_controller $target)

Returns the form definition suitable for cloning into another area.

Parameters
gradingform_controller$targetthe controller of the new copy
Return values
stdClassdefinition structure to pass to the target's update_definition()

Reimplemented in gradingform_guide_controller, and gradingform_rubric_controller.

◆ get_editor_url()

gradingform_controller::get_editor_url ( moodle_url $returnurl = null)

Returns URL of a page where the grading form can be defined and edited.

Parameters
moodle_url$returnurloptional URL of a page where the user should be sent once they are finished with editing
Return values
moodle_url

◆ get_external_definition_details()

static gradingform_controller::get_external_definition_details ( )
static

Overridden by sub classes that wish to make definition details available to web services.

When not overridden, only definition data common to all grading methods is made available. When overriding, the return value should be an array containing one or more key/value pairs. These key/value pairs should match the definition returned by the get_definition() function. For examples, look at: $gradingform_rubric_controller->get_external_definition_details() $gradingform_guide_controller->get_external_definition_details()

Return values
arrayAn array of one or more key/value pairs containing the external_multiple_structure/s corresponding to the definition returned by $controller->get_definition()
Since
Moodle 2.5

Reimplemented in gradingform_guide_controller, and gradingform_rubric_controller.

◆ get_external_instance_filling_details()

static gradingform_controller::get_external_instance_filling_details ( )
static

Overridden by sub classes that wish to make instance filling details available to web services.

When not overridden, only instance filling data common to all grading methods is made available. When overriding, the return value should be an array containing one or more key/value pairs. These key/value pairs should match the filling data returned by the get_<method>_filling() function in the gradingform_instance subclass. For examples, look at: $gradingform_rubric_controller->get_external_instance_filling_details() $gradingform_guide_controller->get_external_instance_filling_details()

Return values
arrayAn array of one or more key/value pairs containing the external_multiple_structure/s corresponding to the definition returned by $gradingform_<method>instance->get<method>_filling()
Since
Moodle 2.6

Reimplemented in gradingform_guide_controller, and gradingform_rubric_controller.

◆ get_formatted_description()

gradingform_controller::get_formatted_description ( )

Formats the definition description for display on page.

Return values
string

Reimplemented in gradingform_guide_controller, and gradingform_rubric_controller.

◆ get_grade_range()

gradingform_controller::get_grade_range ( )
final

Returns the range of grades used in this area.

Return values
array

◆ get_instance()

gradingform_controller::get_instance ( $instance)
protected

Returns the object of type gradingform_XXX_instance (where XXX is the plugin method name)

Parameters
mixed$instanceid or row from grading_isntances table
Return values
gradingform_instance

◆ get_method_name()

gradingform_controller::get_method_name ( )
protected

Returns the name of the grading method plugin, eg 'rubric'.

Return values
stringthe name of the grading method plugin, eg 'rubric'
See also
PARAM_PLUGIN

◆ get_or_create_instance()

gradingform_controller::get_or_create_instance ( $instanceid,
$raterid,
$itemid )

If instanceid is specified and grading instance exists and it is created by this rater for this item, this instance is returned.

Otherwise new instance is created for the specified rater and itemid

Parameters
int$instanceid
int$raterid
int$itemid
Return values
gradingform_instance
Exceptions
dml_exception

Reimplemented in gradingform_guide_controller, and gradingform_rubric_controller.

◆ has_active_instances()

gradingform_controller::has_active_instances ( )

Returns true if there are already people who has been graded on this definition.

In this case plugins may restrict changes of the grading definition

Return values
boolean

◆ is_form_available()

gradingform_controller::is_form_available ( )

Is the grading form defined and ready for usage?

Return values
boolean

◆ is_form_defined()

gradingform_controller::is_form_defined ( )

Is the form definition record available?

Note that this actually checks whether the process of defining the form ever started and not whether the form definition should be considered as final.

Return values
boolean

◆ is_own_form()

gradingform_controller::is_own_form ( $userid = null)

Is the grading form owned by the given user?

The form owner is the user who created this instance of the form.

Parameters
int$useridthe user id to check, defaults to the current user
Return values
boolean|nullnull if the form not defined yet, boolean otherwise

◆ is_shared_template()

gradingform_controller::is_shared_template ( )

Is the grading form saved as a shared public template?

Return values
boolean

◆ load_definition()

gradingform_controller::load_definition ( )
protected

Loads the form definition if it exists.

The default implementation just tries to load the record from the {grading_definitions} table. The plugins are likely to override this with a more complex query that loads all required data at once.

Reimplemented in gradingform_guide_controller, and gradingform_rubric_controller.

◆ render_grade()

gradingform_controller::render_grade ( $page,
$itemid,
$gradinginfo,
$defaultcontent,
$cangrade )

Returns html code to be included in student's feedback.

Parameters
moodle_page$page
int$itemid
array$gradinginforesult of function grade_get_grades if plugin want to use some of their info
string$defaultcontentdefault string to be returned if no active grading is found or for some reason can not be shown to a user
boolean$cangradewhether current user has capability to grade in this context
Return values
string

Reimplemented in gradingform_guide_controller, and gradingform_rubric_controller.

◆ render_preview()

gradingform_controller::render_preview ( moodle_page $page)
abstract

Returns the HTML code displaying the preview of the grading form.

Plugins are forced to override this. Ideally they should delegate the task to their own renderer.

Parameters
moodle_page$pagethe target page
Return values
string

Reimplemented in gradingform_guide_controller, and gradingform_rubric_controller.

◆ set_grade_range()

gradingform_controller::set_grade_range ( array $graderange,
$allowgradedecimals = false )
final

Sets the range of grades used in this area.

This is usually either range like 0-100 or the scale where keys start from 1.

Typically modules will call it: $controller->set_grade_range(make_grades_menu($gradingtype), $gradingtype > 0); Negative $gradingtype means that scale is used and the grade must be rounded to the nearest int. Positive $gradingtype means that range 0..$gradingtype is used for the grades and in this case grade does not have to be rounded.

Sometimes modules always expect grade to be rounded (like mod_assign does).

Parameters
array$graderangearray where first key is the minimum grade and the last key is the maximum grade.
bool$allowgradedecimalsif decimal values are allowed as grades.

◆ sql_search_from_tables()

static gradingform_controller::sql_search_from_tables ( $gdid)
static

Prepare the part of the search query to append to the FROM statement.

Parameters
string$gdidthe alias of grading_definitions.id column used by the caller
Return values
string

Reimplemented in gradingform_guide_controller, and gradingform_rubric_controller.

◆ sql_search_where()

static gradingform_controller::sql_search_where ( $token)
static

Prepare the parts of the SQL WHERE statement to search for the given token.

The returned array cosists of the list of SQL comparions and the list of respective parameters for the comparisons. The returned chunks will be joined with other conditions using the OR operator.

Parameters
string$tokentoken to search for
Return values
array

Reimplemented in gradingform_guide_controller, and gradingform_rubric_controller.

◆ update_definition()

gradingform_controller::update_definition ( stdClass $definition,
$usermodified = null )

Saves the defintion data into the database.

The implementation in this base class stores the common data into the record into the {grading_definition} table. The plugins are likely to extend this and save their data into own tables, too.

Parameters
stdClass$definitiondata containing values for the {grading_definition} table
int | null$usermodifiedoptional userid of the author of the definition, defaults to the current user

Reimplemented in gradingform_guide_controller, and gradingform_rubric_controller.


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