moodle-mod_htmlcert/classes/external.php

89 lines
3 KiB
PHP
Raw Normal View History

<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This is the external API for this tool.
*
2021-11-24 07:29:43 +00:00
* @package mod_htmlcert
* @copyright 2016 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
2021-11-24 07:29:43 +00:00
namespace mod_htmlcert;
defined('MOODLE_INTERNAL') || die();
require_once("$CFG->libdir/externallib.php");
/**
2017-02-16 12:12:19 +00:00
* This is the external API for this tool.
*
2021-11-24 07:29:43 +00:00
* @copyright 2016 Mark Nelson <markn@moodle.com>, 2021 Klaus-Uwe Mitterer <kumitterer@kumi.systems>
2017-02-16 12:12:19 +00:00
* @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'),
)
);
}
/**
2021-11-24 07:29:43 +00:00
* 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);
2021-11-24 07:29:43 +00:00
$certificate = $DB->get_record('htmlcert', ['id' => $certificateid], '*', MUST_EXIST);
$issue = $DB->get_record('htmlcert_issues', ['id' => $issueid, 'htmlcertid' => $certificateid], '*', MUST_EXIST);
2021-11-24 07:29:43 +00:00
$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);
2021-11-24 07:29:43 +00:00
require_capability('mod/htmlcert:manage', $context);
// Delete the issue.
2021-11-24 07:29:43 +00:00
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');
}
}