2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * External tool module external API
22 * @copyright 2015 Juan Leyva <juan@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') || die;
29 require_once($CFG->libdir . '/externallib.php');
30 require_once($CFG->dirroot . '/mod/lti/lib.php');
31 require_once($CFG->dirroot . '/mod/lti/locallib.php');
34 * External tool module external functions
38 * @copyright 2015 Juan Leyva <juan@moodle.com>
39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42 class mod_lti_external extends external_api {
45 * Returns structure be used for returning a tool type from a web service.
47 * @return external_function_parameters
50 private static function tool_type_return_structure() {
51 return new external_single_structure(
53 'id' => new external_value(PARAM_INT, 'Tool type id'),
54 'name' => new external_value(PARAM_NOTAGS, 'Tool type name'),
55 'description' => new external_value(PARAM_NOTAGS, 'Tool type description'),
56 'urls' => new external_single_structure(
58 'icon' => new external_value(PARAM_URL, 'Tool type icon URL'),
59 'edit' => new external_value(PARAM_URL, 'Tool type edit URL'),
60 'course' => new external_value(PARAM_URL, 'Tool type edit URL', VALUE_OPTIONAL),
63 'state' => new external_single_structure(
65 'text' => new external_value(PARAM_TEXT, 'Tool type state name string'),
66 'pending' => new external_value(PARAM_BOOL, 'Is the state pending'),
67 'configured' => new external_value(PARAM_BOOL, 'Is the state configured'),
68 'rejected' => new external_value(PARAM_BOOL, 'Is the state rejected'),
69 'unknown' => new external_value(PARAM_BOOL, 'Is the state unknown'),
72 'hascapabilitygroups' => new external_value(PARAM_BOOL, 'Indicate if capabilitygroups is populated'),
73 'capabilitygroups' => new external_multiple_structure(
74 new external_value(PARAM_TEXT, 'Tool type capability groups enabled'),
75 'Array of capability groups', VALUE_DEFAULT, array()
77 'courseid' => new external_value(PARAM_INT, 'Tool type course', VALUE_DEFAULT, 0),
78 'instanceids' => new external_multiple_structure(
79 new external_value(PARAM_INT, 'LTI instance ID'),
80 'IDs for the LTI instances using this type', VALUE_DEFAULT, array()
82 'instancecount' => new external_value(PARAM_INT, 'The number of times this tool is being used')
88 * Returns description of a tool proxy
90 * @return external_function_parameters
93 private static function tool_proxy_return_structure() {
94 return new external_function_parameters(
96 'id' => new external_value(PARAM_INT, 'Tool proxy id'),
97 'name' => new external_value(PARAM_TEXT, 'Tool proxy name'),
98 'regurl' => new external_value(PARAM_URL, 'Tool proxy registration URL'),
99 'state' => new external_value(PARAM_INT, 'Tool proxy state'),
100 'guid' => new external_value(PARAM_TEXT, 'Tool proxy globally unique identifier'),
101 'secret' => new external_value(PARAM_TEXT, 'Tool proxy shared secret'),
102 'vendorcode' => new external_value(PARAM_TEXT, 'Tool proxy consumer code'),
103 'capabilityoffered' => new external_value(PARAM_TEXT, 'Tool proxy capabilities offered'),
104 'serviceoffered' => new external_value(PARAM_TEXT, 'Tool proxy services offered'),
105 'toolproxy' => new external_value(PARAM_TEXT, 'Tool proxy'),
106 'timecreated' => new external_value(PARAM_INT, 'Tool proxy time created'),
107 'timemodified' => new external_value(PARAM_INT, 'Tool proxy modified'),
113 * Returns description of method parameters
115 * @return external_function_parameters
118 public static function get_tool_proxies_parameters() {
119 return new external_function_parameters(
121 'orphanedonly' => new external_value(PARAM_BOOL, 'Orphaned tool types only', VALUE_DEFAULT, 0)
127 * Returns the tool types.
129 * @param bool $orphanedonly Retrieve only tool proxies that do not have a corresponding tool type
130 * @return array of tool types
132 * @throws moodle_exception
134 public static function get_tool_proxies($orphanedonly) {
136 $params = self::validate_parameters(self::get_tool_proxies_parameters(),
138 'orphanedonly' => $orphanedonly
140 $orphanedonly = $params['orphanedonly'];
143 $context = context_system::instance();
145 self::validate_context($context);
146 require_capability('moodle/site:config', $context);
148 $proxies = lti_get_tool_proxies($orphanedonly);
150 return array_map('serialise_tool_proxy', $proxies);
154 * Returns description of method result value.
156 * @return external_description
159 public static function get_tool_proxies_returns() {
160 return new external_multiple_structure(
161 self::tool_type_return_structure()
166 * Returns description of method parameters.
168 * @return external_function_parameters
171 public static function get_tool_launch_data_parameters() {
172 return new external_function_parameters(
174 'toolid' => new external_value(PARAM_INT, 'external tool instance id')
180 * Return the launch data for a given external tool.
182 * @param int $toolid the external tool instance id
183 * @return array of warnings and launch data
185 * @throws moodle_exception
187 public static function get_tool_launch_data($toolid) {
189 require_once($CFG->dirroot . '/mod/lti/lib.php');
191 $params = self::validate_parameters(self::get_tool_launch_data_parameters(),
197 // Request and permission validation.
198 $lti = $DB->get_record('lti', array('id' => $params['toolid']), '*', MUST_EXIST);
199 list($course, $cm) = get_course_and_cm_from_instance($lti, 'lti');
201 $context = context_module::instance($cm->id);
202 self::validate_context($context);
204 require_capability('mod/lti:view', $context);
206 $lti->cmid = $cm->id;
207 list($endpoint, $parms) = lti_get_launch_data($lti);
209 $parameters = array();
210 foreach ($parms as $name => $value) {
211 $parameters[] = array(
218 $result['endpoint'] = $endpoint;
219 $result['parameters'] = $parameters;
220 $result['warnings'] = $warnings;
225 * Returns description of method result value
227 * @return external_description
230 public static function get_tool_launch_data_returns() {
231 return new external_single_structure(
233 'endpoint' => new external_value(PARAM_RAW, 'Endpoint URL'), // Using PARAM_RAW as is defined in the module.
234 'parameters' => new external_multiple_structure(
235 new external_single_structure(
237 'name' => new external_value(PARAM_NOTAGS, 'Parameter name'),
238 'value' => new external_value(PARAM_RAW, 'Parameter value')
242 'warnings' => new external_warnings()
248 * Describes the parameters for get_ltis_by_courses.
250 * @return external_function_parameters
253 public static function get_ltis_by_courses_parameters() {
254 return new external_function_parameters (
256 'courseids' => new external_multiple_structure(
257 new external_value(PARAM_INT, 'course id'), 'Array of course ids', VALUE_DEFAULT, array()
264 * Returns a list of external tools in a provided list of courses,
265 * if no list is provided all external tools that the user can view will be returned.
267 * @param array $courseids the course ids
268 * @return array the lti details
271 public static function get_ltis_by_courses($courseids = array()) {
274 $returnedltis = array();
277 $params = self::validate_parameters(self::get_ltis_by_courses_parameters(), array('courseids' => $courseids));
279 $mycourses = array();
280 if (empty($params['courseids'])) {
281 $mycourses = enrol_get_my_courses();
282 $params['courseids'] = array_keys($mycourses);
285 // Ensure there are courseids to loop through.
286 if (!empty($params['courseids'])) {
288 list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
290 // Get the ltis in this course, this function checks users visibility permissions.
291 // We can avoid then additional validate_context calls.
292 $ltis = get_all_instances_in_courses("lti", $courses);
294 foreach ($ltis as $lti) {
296 $context = context_module::instance($lti->coursemodule);
301 // First, we return information that any user can see in (or can deduce from) the web interface.
302 $module['id'] = $lti->id;
303 $module['coursemodule'] = $lti->coursemodule;
304 $module['course'] = $lti->course;
305 $module['name'] = external_format_string($lti->name, $context->id);
307 $viewablefields = [];
308 if (has_capability('mod/lti:view', $context)) {
309 list($module['intro'], $module['introformat']) =
310 external_format_text($lti->intro, $lti->introformat, $context->id, 'mod_lti', 'intro', $lti->id);
312 $module['introfiles'] = external_util::get_area_files($context->id, 'mod_lti', 'intro', false, false);
313 $viewablefields = array('launchcontainer', 'showtitlelaunch', 'showdescriptionlaunch', 'icon', 'secureicon');
316 // Check additional permissions for returning optional private settings.
317 if (has_capability('moodle/course:manageactivities', $context)) {
319 $additionalfields = array('timecreated', 'timemodified', 'typeid', 'toolurl', 'securetoolurl',
320 'instructorchoicesendname', 'instructorchoicesendemailaddr', 'instructorchoiceallowroster',
321 'instructorchoiceallowsetting', 'instructorcustomparameters', 'instructorchoiceacceptgrades', 'grade',
322 'resourcekey', 'password', 'debuglaunch', 'servicesalt', 'visible', 'groupmode', 'groupingid');
323 $viewablefields = array_merge($viewablefields, $additionalfields);
327 foreach ($viewablefields as $field) {
328 $module[$field] = $lti->{$field};
331 $returnedltis[] = $module;
336 $result['ltis'] = $returnedltis;
337 $result['warnings'] = $warnings;
342 * Describes the get_ltis_by_courses return value.
344 * @return external_single_structure
347 public static function get_ltis_by_courses_returns() {
349 return new external_single_structure(
351 'ltis' => new external_multiple_structure(
352 new external_single_structure(
354 'id' => new external_value(PARAM_INT, 'External tool id'),
355 'coursemodule' => new external_value(PARAM_INT, 'Course module id'),
356 'course' => new external_value(PARAM_INT, 'Course id'),
357 'name' => new external_value(PARAM_RAW, 'LTI name'),
358 'intro' => new external_value(PARAM_RAW, 'The LTI intro', VALUE_OPTIONAL),
359 'introformat' => new external_format_value('intro', VALUE_OPTIONAL),
360 'introfiles' => new external_files('Files in the introduction text', VALUE_OPTIONAL),
361 'timecreated' => new external_value(PARAM_INT, 'Time of creation', VALUE_OPTIONAL),
362 'timemodified' => new external_value(PARAM_INT, 'Time of last modification', VALUE_OPTIONAL),
363 'typeid' => new external_value(PARAM_INT, 'Type id', VALUE_OPTIONAL),
364 'toolurl' => new external_value(PARAM_URL, 'Tool url', VALUE_OPTIONAL),
365 'securetoolurl' => new external_value(PARAM_RAW, 'Secure tool url', VALUE_OPTIONAL),
366 'instructorchoicesendname' => new external_value(PARAM_TEXT, 'Instructor choice send name',
368 'instructorchoicesendemailaddr' => new external_value(PARAM_INT, 'instructor choice send mail address',
370 'instructorchoiceallowroster' => new external_value(PARAM_INT, 'Instructor choice allow roster',
372 'instructorchoiceallowsetting' => new external_value(PARAM_INT, 'Instructor choice allow setting',
374 'instructorcustomparameters' => new external_value(PARAM_RAW, 'instructor custom parameters',
376 'instructorchoiceacceptgrades' => new external_value(PARAM_INT, 'instructor choice accept grades',
378 'grade' => new external_value(PARAM_INT, 'Enable grades', VALUE_OPTIONAL),
379 'launchcontainer' => new external_value(PARAM_INT, 'Launch container mode', VALUE_OPTIONAL),
380 'resourcekey' => new external_value(PARAM_RAW, 'Resource key', VALUE_OPTIONAL),
381 'password' => new external_value(PARAM_RAW, 'Shared secret', VALUE_OPTIONAL),
382 'debuglaunch' => new external_value(PARAM_INT, 'Debug launch', VALUE_OPTIONAL),
383 'showtitlelaunch' => new external_value(PARAM_INT, 'Show title launch', VALUE_OPTIONAL),
384 'showdescriptionlaunch' => new external_value(PARAM_INT, 'Show description launch', VALUE_OPTIONAL),
385 'servicesalt' => new external_value(PARAM_RAW, 'Service salt', VALUE_OPTIONAL),
386 'icon' => new external_value(PARAM_URL, 'Alternative icon URL', VALUE_OPTIONAL),
387 'secureicon' => new external_value(PARAM_URL, 'Secure icon URL', VALUE_OPTIONAL),
388 'section' => new external_value(PARAM_INT, 'course section id', VALUE_OPTIONAL),
389 'visible' => new external_value(PARAM_INT, 'visible', VALUE_OPTIONAL),
390 'groupmode' => new external_value(PARAM_INT, 'group mode', VALUE_OPTIONAL),
391 'groupingid' => new external_value(PARAM_INT, 'group id', VALUE_OPTIONAL),
395 'warnings' => new external_warnings(),
401 * Returns description of method parameters
403 * @return external_function_parameters
406 public static function view_lti_parameters() {
407 return new external_function_parameters(
409 'ltiid' => new external_value(PARAM_INT, 'lti instance id')
415 * Trigger the course module viewed event and update the module completion status.
417 * @param int $ltiid the lti instance id
418 * @return array of warnings and status result
420 * @throws moodle_exception
422 public static function view_lti($ltiid) {
425 $params = self::validate_parameters(self::view_lti_parameters(),
431 // Request and permission validation.
432 $lti = $DB->get_record('lti', array('id' => $params['ltiid']), '*', MUST_EXIST);
433 list($course, $cm) = get_course_and_cm_from_instance($lti, 'lti');
435 $context = context_module::instance($cm->id);
436 self::validate_context($context);
437 require_capability('mod/lti:view', $context);
439 // Trigger course_module_viewed event and completion.
440 lti_view($lti, $course, $cm, $context);
443 $result['status'] = true;
444 $result['warnings'] = $warnings;
449 * Returns description of method result value
451 * @return external_description
454 public static function view_lti_returns() {
455 return new external_single_structure(
457 'status' => new external_value(PARAM_BOOL, 'status: true if success'),
458 'warnings' => new external_warnings()
464 * Returns description of method parameters
466 * @return external_function_parameters
469 public static function create_tool_proxy_parameters() {
470 return new external_function_parameters(
472 'name' => new external_value(PARAM_TEXT, 'Tool proxy name', VALUE_DEFAULT, ''),
473 'regurl' => new external_value(PARAM_URL, 'Tool proxy registration URL'),
474 'capabilityoffered' => new external_multiple_structure(
475 new external_value(PARAM_TEXT, 'Tool proxy capabilities offered'),
476 'Array of capabilities', VALUE_DEFAULT, array()
478 'serviceoffered' => new external_multiple_structure(
479 new external_value(PARAM_TEXT, 'Tool proxy services offered'),
480 'Array of services', VALUE_DEFAULT, array()
487 * Creates a new tool proxy
489 * @param string $name Tool proxy name
490 * @param string $registrationurl Registration url
491 * @param string[] $capabilityoffered List of capabilities this tool proxy should be offered
492 * @param string[] $serviceoffered List of services this tool proxy should be offered
493 * @return object The new tool proxy
495 * @throws moodle_exception
497 public static function create_tool_proxy($name, $registrationurl, $capabilityoffered, $serviceoffered) {
498 $params = self::validate_parameters(self::create_tool_proxy_parameters(),
501 'regurl' => $registrationurl,
502 'capabilityoffered' => $capabilityoffered,
503 'serviceoffered' => $serviceoffered
505 $name = $params['name'];
506 $regurl = $params['regurl'];
507 $capabilityoffered = $params['capabilityoffered'];
508 $serviceoffered = $params['serviceoffered'];
510 $context = context_system::instance();
511 self::validate_context($context);
512 require_capability('moodle/site:config', $context);
514 // Can't create duplicate proxies with the same URL.
515 $duplicates = lti_get_tool_proxies_from_registration_url($registrationurl);
516 if (!empty($duplicates)) {
517 throw new moodle_exception('duplicateregurl', 'mod_lti');
520 $config = new stdClass();
521 $config->lti_registrationurl = $registrationurl;
524 $config->lti_registrationname = $name;
527 if (!empty($capabilityoffered)) {
528 $config->lti_capabilities = $capabilityoffered;
531 if (!empty($serviceoffered)) {
532 $config->lti_services = $serviceoffered;
535 $id = lti_add_tool_proxy($config);
536 $toolproxy = lti_get_tool_proxy($id);
538 // Pending makes more sense than configured as the first state, since
539 // the next step is to register, which requires the state be pending.
540 $toolproxy->state = LTI_TOOL_PROXY_STATE_PENDING;
541 lti_update_tool_proxy($toolproxy);
547 * Returns description of method result value
549 * @return external_description
552 public static function create_tool_proxy_returns() {
553 return self::tool_proxy_return_structure();
557 * Returns description of method parameters
559 * @return external_function_parameters
562 public static function delete_tool_proxy_parameters() {
563 return new external_function_parameters(
565 'id' => new external_value(PARAM_INT, 'Tool proxy id'),
571 * Trigger the course module viewed event and update the module completion status.
573 * @param int $id the lti instance id
574 * @return object The tool proxy
576 * @throws moodle_exception
578 public static function delete_tool_proxy($id) {
579 $params = self::validate_parameters(self::delete_tool_proxy_parameters(),
585 $context = context_system::instance();
586 self::validate_context($context);
587 require_capability('moodle/site:config', $context);
589 $toolproxy = lti_get_tool_proxy($id);
591 lti_delete_tool_proxy($id);
597 * Returns description of method result value
599 * @return external_description
602 public static function delete_tool_proxy_returns() {
603 return self::tool_proxy_return_structure();
607 * Returns description of method parameters
609 * @return external_function_parameters
612 public static function get_tool_proxy_registration_request_parameters() {
613 return new external_function_parameters(
615 'id' => new external_value(PARAM_INT, 'Tool proxy id'),
621 * Returns the registration request for a tool proxy.
623 * @param int $id the lti instance id
624 * @return array of registration parameters
626 * @throws moodle_exception
628 public static function get_tool_proxy_registration_request($id) {
629 $params = self::validate_parameters(self::get_tool_proxy_registration_request_parameters(),
635 $context = context_system::instance();
636 self::validate_context($context);
637 require_capability('moodle/site:config', $context);
639 $toolproxy = lti_get_tool_proxy($id);
640 return lti_build_registration_request($toolproxy);
644 * Returns description of method result value
646 * @return external_description
649 public static function get_tool_proxy_registration_request_returns() {
650 return new external_function_parameters(
652 'lti_message_type' => new external_value(PARAM_ALPHANUMEXT, 'LTI message type'),
653 'lti_version' => new external_value(PARAM_ALPHANUMEXT, 'LTI version'),
654 'reg_key' => new external_value(PARAM_TEXT, 'Tool proxy registration key'),
655 'reg_password' => new external_value(PARAM_TEXT, 'Tool proxy registration password'),
656 'reg_url' => new external_value(PARAM_TEXT, 'Tool proxy registration url'),
657 'tc_profile_url' => new external_value(PARAM_URL, 'Tool consumers profile URL'),
658 'launch_presentation_return_url' => new external_value(PARAM_URL, 'URL to redirect on registration completion'),
664 * Returns description of method parameters
666 * @return external_function_parameters
669 public static function get_tool_types_parameters() {
670 return new external_function_parameters(
672 'toolproxyid' => new external_value(PARAM_INT, 'Tool proxy id', VALUE_DEFAULT, 0)
678 * Returns the tool types.
680 * @param int $toolproxyid The tool proxy id
681 * @return array of tool types
683 * @throws moodle_exception
685 public static function get_tool_types($toolproxyid) {
687 $params = self::validate_parameters(self::get_tool_types_parameters(),
689 'toolproxyid' => $toolproxyid
691 $toolproxyid = $params['toolproxyid'];
694 $context = context_system::instance();
696 self::validate_context($context);
697 require_capability('moodle/site:config', $context);
699 if (!empty($toolproxyid)) {
700 $types = lti_get_lti_types_from_proxy_id($toolproxyid);
702 $types = lti_get_lti_types();
705 return array_map("serialise_tool_type", array_values($types));
709 * Returns description of method result value
711 * @return external_description
714 public static function get_tool_types_returns() {
715 return new external_multiple_structure(
716 self::tool_type_return_structure()
721 * Returns description of method parameters
723 * @return external_function_parameters
726 public static function create_tool_type_parameters() {
727 return new external_function_parameters(
729 'cartridgeurl' => new external_value(PARAM_URL, 'URL to cardridge to load tool information', VALUE_DEFAULT, ''),
730 'key' => new external_value(PARAM_TEXT, 'Consumer key', VALUE_DEFAULT, ''),
731 'secret' => new external_value(PARAM_TEXT, 'Shared secret', VALUE_DEFAULT, ''),
737 * Creates a tool type.
739 * @param string $cartridgeurl Url of the xml cartridge representing the LTI tool
740 * @param string $key The consumer key to identify this consumer
741 * @param string $secret The secret
742 * @return array created tool type
744 * @throws moodle_exception If the tool type could not be created
746 public static function create_tool_type($cartridgeurl, $key, $secret) {
747 $params = self::validate_parameters(self::create_tool_type_parameters(),
749 'cartridgeurl' => $cartridgeurl,
753 $cartridgeurl = $params['cartridgeurl'];
754 $key = $params['key'];
755 $secret = $params['secret'];
757 $context = context_system::instance();
758 self::validate_context($context);
759 require_capability('moodle/site:config', $context);
763 if (!empty($cartridgeurl)) {
764 $type = new stdClass();
765 $data = new stdClass();
766 $type->state = LTI_TOOL_STATE_CONFIGURED;
767 $data->lti_coursevisible = 1;
768 $data->lti_sendname = LTI_SETTING_DELEGATE;
769 $data->lti_sendemailaddr = LTI_SETTING_DELEGATE;
770 $data->lti_acceptgrades = LTI_SETTING_DELEGATE;
771 $data->lti_forcessl = 0;
774 $data->lti_resourcekey = $key;
777 if (!empty($secret)) {
778 $data->lti_password = $secret;
781 lti_load_type_from_cartridge($cartridgeurl, $data);
782 if (empty($data->lti_toolurl)) {
783 throw new moodle_exception('unabletocreatetooltype', 'mod_lti');
785 $id = lti_add_type($type, $data);
790 $type = lti_get_type($id);
791 return serialise_tool_type($type);
793 throw new moodle_exception('unabletocreatetooltype', 'mod_lti');
798 * Returns description of method result value
800 * @return external_description
803 public static function create_tool_type_returns() {
804 return self::tool_type_return_structure();
808 * Returns description of method parameters
810 * @return external_function_parameters
813 public static function update_tool_type_parameters() {
814 return new external_function_parameters(
816 'id' => new external_value(PARAM_INT, 'Tool type id'),
817 'name' => new external_value(PARAM_RAW, 'Tool type name', VALUE_DEFAULT, null),
818 'description' => new external_value(PARAM_RAW, 'Tool type description', VALUE_DEFAULT, null),
819 'state' => new external_value(PARAM_INT, 'Tool type state', VALUE_DEFAULT, null)
825 * Update a tool type.
827 * @param int $id The id of the tool type to update
828 * @param string $name The name of the tool type
829 * @param string $description The name of the tool type
830 * @param int $state The state of the tool type
831 * @return array updated tool type
833 * @throws moodle_exception
835 public static function update_tool_type($id, $name, $description, $state) {
836 $params = self::validate_parameters(self::update_tool_type_parameters(),
840 'description' => $description,
844 $name = $params['name'];
845 $description = $params['description'];
846 $state = $params['state'];
848 $context = context_system::instance();
849 self::validate_context($context);
850 require_capability('moodle/site:config', $context);
852 $type = lti_get_type($id);
855 throw new moodle_exception('unabletofindtooltype', 'mod_lti', '', array('id' => $id));
862 if (!empty($description)) {
863 $type->description = $description;
866 if (!empty($state)) {
867 // Valid state range.
868 if (in_array($state, array(1, 2, 3))) {
869 $type->state = $state;
871 throw new moodle_exception("Invalid state: $state - must be 1, 2, or 3");
875 lti_update_type($type, new stdClass());
877 return serialise_tool_type($type);
881 * Returns description of method result value
883 * @return external_description
886 public static function update_tool_type_returns() {
887 return self::tool_type_return_structure();
891 * Returns description of method parameters
893 * @return external_function_parameters
896 public static function delete_tool_type_parameters() {
897 return new external_function_parameters(
899 'id' => new external_value(PARAM_INT, 'Tool type id'),
905 * Delete a tool type.
907 * @param int $id The id of the tool type to be deleted
908 * @return array deleted tool type
910 * @throws moodle_exception
912 public static function delete_tool_type($id) {
913 $params = self::validate_parameters(self::delete_tool_type_parameters(),
919 $context = context_system::instance();
920 self::validate_context($context);
921 require_capability('moodle/site:config', $context);
923 $type = lti_get_type($id);
926 lti_delete_type($id);
928 // If this is the last type for this proxy then remove the proxy
929 // as well so that it isn't orphaned.
930 $types = lti_get_lti_types_from_proxy_id($type->toolproxyid);
932 lti_delete_tool_proxy($type->toolproxyid);
936 return array('id' => $id);
940 * Returns description of method result value
942 * @return external_description
945 public static function delete_tool_type_returns() {
946 return new external_function_parameters(
948 'id' => new external_value(PARAM_INT, 'Tool type id'),
954 * Returns description of method parameters
956 * @return external_function_parameters
959 public static function is_cartridge_parameters() {
960 return new external_function_parameters(
962 'url' => new external_value(PARAM_URL, 'Tool url'),
968 * Determine if the url to a tool is for a cartridge.
970 * @param string $url Url that may or may not be an xml cartridge
971 * @return bool True if the url is for a cartridge.
973 * @throws moodle_exception
975 public static function is_cartridge($url) {
976 $params = self::validate_parameters(self::is_cartridge_parameters(),
980 $url = $params['url'];
982 $context = context_system::instance();
983 self::validate_context($context);
984 require_capability('moodle/site:config', $context);
986 $iscartridge = lti_is_cartridge($url);
988 return array('iscartridge' => $iscartridge);
992 * Returns description of method result value
994 * @return external_description
997 public static function is_cartridge_returns() {
998 return new external_function_parameters(
1000 'iscartridge' => new external_value(PARAM_BOOL, 'True if the URL is a cartridge'),