2016-06-13 11:39:57 +00:00
|
|
|
<?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>
|
2016-06-13 11:39:57 +00:00
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
2021-11-24 07:29:43 +00:00
|
|
|
namespace mod_htmlcert;
|
2016-06-13 11:39:57 +00:00
|
|
|
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
|
|
|
|
*/
|
2016-06-13 11:39:57 +00:00
|
|
|
class external extends \external_api {
|
2018-05-23 06:35:23 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
2018-05-23 06:35:23 +00:00
|
|
|
*
|
|
|
|
* @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);
|
2018-05-23 06:35:23 +00:00
|
|
|
|
2021-11-24 07:29:43 +00:00
|
|
|
$cm = get_coursemodule_from_instance('htmlcert', $certificate->id, 0, false, MUST_EXIST);
|
2018-05-23 06:35:23 +00:00
|
|
|
|
|
|
|
// 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);
|
2018-05-23 06:35:23 +00:00
|
|
|
|
|
|
|
// Delete the issue.
|
2021-11-24 07:29:43 +00:00
|
|
|
return $DB->delete_records('htmlcert_issues', ['id' => $issue->id]);
|
2018-05-23 06:35:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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');
|
|
|
|
}
|
2016-06-13 11:39:57 +00:00
|
|
|
}
|