Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

This file contains a class definition for the LTI Gradebook Services

Author: Dirk Singels, Diego del Blanco, Claude Vervoort
Copyright: 2017 Cengage Learning http://www.cengage.com
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 782 lines (32 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: gradebookservices  - X-Ref

A service implementing LTI Gradebook Services.

__construct()   X-Ref
Class constructor.


get_resources()   X-Ref
Get the resources for this service.

return: resource_base[]

get_permitted_scopes()   X-Ref
Get the scope(s) permitted for this service.

return: array

get_scopes()   X-Ref
Get the scopes defined by this service.

return: array

get_configuration_options(&$mform)   X-Ref
Adds form elements for gradebook sync add/edit page.

param: \MoodleQuickForm $mform Moodle quickform object definition

get_launch_parameters($messagetype, $courseid, $user, $typeid, $modlti = null)   X-Ref
Return an array of key/values to add to the launch parameters.

param: string $messagetype 'basic-lti-launch-request' or 'ContentItemSelectionRequest'.
param: string $courseid the course id.
param: object $user The user id.
param: string $typeid The tool lti type id.
param: string $modlti The id of the lti activity.
return: array of key/value pairs to add as launch parameters.

get_lineitems($courseid, $resourceid, $ltilinkid, $tag, $limitfrom, $limitnum, $typeid)   X-Ref
Fetch the lineitem instances.

param: string $courseid ID of course
param: string $resourceid Resource identifier used for filtering, may be null
param: string $ltilinkid Resource Link identifier used for filtering, may be null
param: string $tag
param: int $limitfrom Offset for the first line item to include in a paged set
param: int $limitnum Maximum number of line items to include in the paged set
param: string $typeid
return: array

get_lineitem($courseid, $itemid, $typeid)   X-Ref
Fetch a lineitem instance.

Returns the lineitem instance if found, otherwise false.

param: string $courseid ID of course
param: string $itemid ID of lineitem
param: string $typeid
return: \ltiservice_gradebookservices\local\resources\lineitem|bool

add_standalone_lineitem(string $courseid, string $label, float $maximumscore,string $baseurl, ?int $ltilinkid, ?string $resourceid, ?string $tag, int $typeid,int $toolproxyid = null)   X-Ref
Adds a decoupled (standalone) line item.
Decoupled line items are not directly attached to
an lti instance activity. They are recorded in
the gradebook as manual activities and the
gradebookservices is used to associate that manual column
with the tool in addition to storing the LTI related
metadata (resource id, tag).

param: string $courseid ID of course
param: string $label label of lineitem
param: float $maximumscore maximum score of lineitem
param: string $baseurl
param: int|null $ltilinkid id of lti instance this line item is associated with
param: string|null $resourceid resource id of lineitem
param: string|null $tag tag of lineitem
param: int $typeid lti type to which this line item is associated with
param: int|null $toolproxyid lti2 tool proxy to which this lineitem is associated to
return: int id of the created gradeitem

save_score($gradeitem, $score, $userid)   X-Ref
Set a grade item.

param: object $gradeitem Grade Item record
param: object $score Result object
param: int $userid User ID

save_grade_item($gradeitem, $score, $userid)   X-Ref
Saves a score received from the LTI tool.

param: object $gradeitem Grade Item record
param: object $score Result object
param: int $userid User ID

item_for_json($item, $endpoint, $typeid)   X-Ref
Get the json object representation of the grade item

param: object $item Grade Item record
param: string $endpoint Endpoint for lineitems container request
param: string $typeid
return: object

result_for_json($grade, $endpoint, $typeid)   X-Ref
Get the object matching the JSON representation of the result.

param: object  $grade              Grade record
param: string  $endpoint           Endpoint for lineitem
param: int  $typeid                The id of the type to include in the result url.
return: object

check_lti_id($linkid, $course, $toolproxy)   X-Ref
Check if an LTI id is valid.

param: string $linkid             The lti id
param: string  $course            The course
param: string  $toolproxy         The tool proxy id
return: boolean

check_lti_1x_id($linkid, $course, $typeid)   X-Ref
Check if an LTI id is valid when we are in a LTI 1.x case

param: string $linkid             The lti id
param: string  $course            The course
param: string  $typeid            The lti type id
return: boolean

update_coupled_gradebookservices(object $ltiinstance, ?string $resourceid, ?string $tag)   X-Ref
Updates the tag and resourceid values for a grade item coupled to an lti link instance.

param: object $ltiinstance The lti instance to which the grade item is coupled to
param: string|null $resourceid The resourceid to apply to the lineitem. If empty string which will be stored as null.
param: string|null $tag The tag to apply to the lineitem. If empty string which will be stored as null.

instance_added(object $lti)   X-Ref
Called when a new LTI Instance is added.

param: object $lti LTI Instance.

instance_updated(object $lti)   X-Ref
Called when a new LTI Instance is updated.

param: object $lti LTI Instance.

set_instance_form_values(object $defaultvalues)   X-Ref
Set the form data when displaying the LTI Instance form.

param: object $defaultvalues Default form values.

delete_orphans_ltiservice_gradebookservices_rows()   X-Ref
Deletes orphaned rows from the 'ltiservice_gradebookservices' table.

Sometimes, if a gradebook entry is deleted and it was a lineitem
the row in the table ltiservice_gradebookservices can become an orphan
This method will clean these orphans. It will happens based on a task
because it is not urgent and we don't want to slow the service

is_user_gradable_in_course($courseid, $userid)   X-Ref
Check if a user can be graded in a course

param: int $courseid The course
param: int $userid The user
return: bool

find_ltiservice_gradebookservice_for_lti($instanceid)   X-Ref
Find the right element in the ltiservice_gradebookservice table for an lti instance

param: string $instanceid The LTI module instance id
return: object gradebookservice for this line item

find_ltiservice_gradebookservice_for_lineitem($lineitemid)   X-Ref
Find the right element in the ltiservice_gradebookservice table for a lineitem

param: string $lineitemid The lineitem (gradeitem) id
return: object gradebookservice if it exists

validate_iso8601_date($date)   X-Ref
Validates specific ISO 8601 format of the timestamps.

param: string $date The timestamp to check.
return: boolean true or false if the date matches the format.