. /** * This is the external API for this tool. * * @package mod_htmlcert * @copyright 2016 Mark Nelson , 2021 Klaus-Uwe Mitterer * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace mod_htmlcert; defined('MOODLE_INTERNAL') || die(); require_once("$CFG->libdir/externallib.php"); /** * This is the external API for this tool. * * @copyright 2016 Mark Nelson , 2021 Klaus-Uwe Mitterer * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class external extends \external_api { /** * Returns the delete_issue() parameters. * * @return \external_function_parameters */ public static function delete_issue_parameters() { return new \external_function_parameters( array( 'certificateid' => new \external_value(PARAM_INT, 'The certificate id'), 'issueid' => new \external_value(PARAM_INT, 'The issue id'), ) ); } /** * Handles deleting a htmlcert issue. * * @param int $certificateid The certificate id. * @param int $issueid The issue id. * @return bool */ public static function delete_issue($certificateid, $issueid) { global $DB; $params = [ 'certificateid' => $certificateid, 'issueid' => $issueid ]; self::validate_parameters(self::delete_issue_parameters(), $params); $certificate = $DB->get_record('htmlcert', ['id' => $certificateid], '*', MUST_EXIST); $issue = $DB->get_record('htmlcert_issues', ['id' => $issueid, 'htmlcertid' => $certificateid], '*', MUST_EXIST); $cm = get_coursemodule_from_instance('htmlcert', $certificate->id, 0, false, MUST_EXIST); // Make sure the user has the required capabilities. $context = \context_module::instance($cm->id); self::validate_context($context); require_capability('mod/htmlcert:manage', $context); // Delete the issue. return $DB->delete_records('htmlcert_issues', ['id' => $issue->id]); } /** * Returns the delete_issue result value. * * @return \external_value */ public static function delete_issue_returns() { return new \external_value(PARAM_BOOL, 'True if successful, false otherwise'); } }