Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403]

Grading method controller for the guide plugin

Copyright: 2012 Dan Marsden <dan@danmarsden.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 1022 lines (45 kb)
Included or required: 2 times
Referenced: 3 times
Includes or requires: 0 files

Defines 2 classes


Class: gradingform_guide_controller  - X-Ref

This controller encapsulates the guide grading logic

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

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 'guide'.

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

extend_navigation(global_navigation $navigation, navigation_node $node=null)   X-Ref
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.

param: global_navigation $navigation {@link global_navigation}
param: navigation_node $node {@link navigation_node}
return: void

update_definition(stdClass $newdefinition, $usermodified = null)   X-Ref
Saves the guide definition into the database

param: stdClass $newdefinition guide definition data as coming from gradingform_guide_editguide::get_data()
param: int $usermodified optional userid of the author of the definition, defaults to the current user

update_or_check_guide(stdClass $newdefinition, $usermodified = null, $doupdate = false)   X-Ref
Either saves the guide definition into the database or check if it has been changed.

Returns the level of changes:
0 - no changes
1 - only texts or criteria sortorders are changed, students probably do not require re-grading
2 - added levels but maximum score on guide is the same, students still may not require re-grading
3 - removed criteria or changed number of points, students require re-grading but may be re-graded automatically
4 - removed levels - students require re-grading and not all students may be re-graded automatically
5 - added criteria - all students require manual re-grading

param: stdClass $newdefinition guide definition data as coming from gradingform_guide_editguide::get_data()
param: int|null $usermodified optional userid of the author of the definition, defaults to the current user
param: bool $doupdate if true actually updates DB, otherwise performs a check
return: int

mark_for_regrade()   X-Ref
Marks all instances filled with this guide with the status INSTANCE_STATUS_NEEDUPDATE


load_definition()   X-Ref
Loads the guide form definition if it exists

There is a new array called 'guide_criteria' appended to the list of parent's definition properties.

get_default_options()   X-Ref
Returns the default options for the guide display

return: array

get_options()   X-Ref
Gets the options of this guide definition, fills the missing options with default values

return: array

get_definition_for_editing($addemptycriterion = false)   X-Ref
Converts the current definition into an object suitable for the editor form's set_data()

param: bool $addemptycriterion whether to add an empty criterion if the guide is completely empty (just being created)
return: stdClass

get_definition_copy(gradingform_controller $target)   X-Ref
Returns the form definition suitable for cloning into another area

param: gradingform_controller $target the controller of the new copy
return: stdClass definition structure to pass to the target's {@link update_definition()}

description_form_field_options($context)   X-Ref
Options for displaying the guide description field in the form

param: context $context
return: array options for the form description field

get_formatted_description()   X-Ref
Formats the definition description for display on page

return: string

get_renderer(moodle_page $page)   X-Ref
Returns the guide plugin renderer

param: moodle_page $page the target page
return: gradingform_guide_renderer

render_preview(moodle_page $page)   X-Ref
Returns the HTML code displaying the preview of the grading form

param: moodle_page $page the target page
return: string

delete_plugin_definition()   X-Ref
Deletes the guide definition and all the associated information


get_or_create_instance($instanceid, $raterid, $itemid)   X-Ref
If instanceid is specified and grading instance exists and it is created by this rater for
this item, this instance is returned.
If there exists a draft for this raterid+itemid, take this draft (this is the change from parent)
Otherwise new instance is created for the specified rater and itemid

param: int $instanceid
param: int $raterid
param: int $itemid
return: gradingform_instance

render_grade($page, $itemid, $gradinginfo, $defaultcontent, $cangrade)   X-Ref
Returns html code to be included in student's feedback.

param: moodle_page $page
param: int $itemid
param: array $gradinginfo result of function grade_get_grades
param: string $defaultcontent default string to be returned if no active grading is found
param: bool $cangrade whether current user has capability to grade in this context
return: string

sql_search_from_tables($gdid)   X-Ref
Prepare the part of the search query to append to the FROM statement

param: string $gdid the alias of grading_definitions.id column used by the caller
return: string

sql_search_where($token)   X-Ref
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.

param: string $token token to search for
return: array An array containing two more arrays

get_min_max_score()   X-Ref
Calculates and returns the possible minimum and maximum score (in points) for this guide

return: array

get_external_definition_details()   X-Ref

return: array An array containing 2 key/value pairs which hold the external_multiple_structure

get_external_instance_filling_details()   X-Ref
Returns an array that defines the structure of the guide's filling. This function is used by
the web service function core_grading_external::get_gradingform_instances().

return: An array containing a single key/value pair with the 'criteria' external_multiple_structure

Class: gradingform_guide_instance  - X-Ref

Class to manage one guide grading instance. Stores information and performs actions like
update, copy, validate, submit, etc.

cancel()   X-Ref
Deletes this (INCOMPLETE) instance from database.


copy($raterid, $itemid)   X-Ref
Duplicates the instance before editing (optionally substitutes raterid and/or itemid with
the specified values)

param: int $raterid value for raterid in the duplicate
param: int $itemid value for itemid in the duplicate
return: int id of the new instance

is_empty_form($elementvalue)   X-Ref
Determines whether the submitted form was empty.

param: array $elementvalue value of element submitted from the form
return: boolean true if the form is empty

validate_grading_element($elementvalue)   X-Ref
Validates that guide is fully completed and contains valid grade on each criterion

param: array $elementvalue value of element as came in form submit
return: boolean true if the form data is validated and contains no errors

get_guide_filling($force = false)   X-Ref
Retrieves from DB and returns the data how this guide was filled

param: bool $force whether to force DB query even if the data is cached
return: array

update($data)   X-Ref
Updates the instance with the data received from grading form. This function may be
called via AJAX when grading is not yet completed, so it does not change the
status of the instance.

param: array $data

clear_attempt($data)   X-Ref
Removes the attempt from the gradingform_guide_fillings table

param: array $data the attempt data

get_grade()   X-Ref
Calculates the grade to be pushed to the gradebook

return: float|int the valid grade from $this->get_controller()->get_grade_range()

render_grading_element($page, $gradingformelement)   X-Ref
Returns html for form element of type 'grading'.

param: moodle_page $page
param: MoodleQuickForm_grading $gradingformelement
return: string

gradingform_guide_get_fontawesome_icon_map()   X-Ref
Get the icon mapping for font-awesome.

return: array