1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 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. 8 // 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. 13 // 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/>. 16 17 namespace mod_lti\external; 18 19 use core_external\external_api; 20 use core_external\external_function_parameters; 21 use core_external\external_value; 22 23 defined('MOODLE_INTERNAL') || die(); 24 25 global $CFG; 26 require_once($CFG->dirroot . '/mod/lti/locallib.php'); 27 28 /** 29 * External function to delete a course tool type. 30 * 31 * @package mod_lti 32 * @copyright 2023 Jake Dallimore <jrhdallimore@gmail.com> 33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 34 */ 35 class delete_course_tool_type extends external_api { 36 37 /** 38 * Get parameter definition. 39 * 40 * @return external_function_parameters 41 */ 42 public static function execute_parameters(): external_function_parameters { 43 return new external_function_parameters([ 44 'tooltypeid' => new external_value(PARAM_INT, 'Tool type ID'), 45 ]); 46 } 47 48 /** 49 * Delete a course tool type. 50 * 51 * @param int $tooltypeid the id of the course external tool type. 52 * @return bool true 53 * @throws \invalid_parameter_exception if the provided id refers to a site level tool which cannot be deleted. 54 */ 55 public static function execute(int $tooltypeid): bool { 56 57 ['tooltypeid' => $tooltypeid] = self::validate_parameters(self::execute_parameters(), ['tooltypeid' => $tooltypeid]); 58 59 global $DB; 60 $course = (int) $DB->get_field('lti_types', 'course', ['id' => $tooltypeid]); 61 if ($course == get_site()->id) { 62 throw new \invalid_parameter_exception('This is a site-level tool and cannot be deleted via this service'); 63 } 64 65 $context = \context_course::instance($course); 66 self::validate_context($context); 67 require_capability('mod/lti:addcoursetool', $context); 68 69 \lti_delete_type($tooltypeid); 70 return true; 71 } 72 73 /** 74 * Get service returns definition. 75 * 76 * @return external_value 77 */ 78 public static function execute_returns(): external_value { 79 return new external_value(PARAM_BOOL, 'Success'); 80 } 81 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body