-
Notifications
You must be signed in to change notification settings - Fork 0
/
externallib.php
110 lines (92 loc) · 3.8 KB
/
externallib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?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/>.
/**
* Externallib.php file for cardbox plugin.
*
* @package mod_cardbox
* @copyright 2015 Caio Bressan Doneda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
/* require_once($CFG->libdir . '/externallib.php');
require_once($CFG->libdir . '/filelib.php');
require_once(dirname(__FILE__).'/classes/cardbox_webservices_handler.php'); */
require_once("$CFG->libdir/externallib.php");
require_once("$CFG->dirroot/user/externallib.php");
require_once("$CFG->dirroot/mod/cardbox/locallib.php");
/**
* Class mod_cardbox_external
* @copyright 2015 Caio Bressan Doneda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_cardbox_external extends external_api {
public static function deletetopic_parameters() {
return new external_function_parameters(
array(
"topicid" => new external_value(PARAM_INT, "topicid")
)
);
}
public static function deletetopic($topicid) {
global $DB;
$params = self::validate_parameters(
self::deletetopic_parameters(),
array('topicid' => $topicid)
);
$cmid = self::get_cmid($params['topicid']);
$context = context_module::instance($cmid);
require_capability('mod/cardbox:edittopics', $context);
$success = $DB->set_field_select('cardbox_cards', 'topic', null, 'topic = :id', ['id' => $params['topicid']]);
$DB->delete_records('cardbox_topics', ['id' => $params['topicid']]);
return $success;
}
public static function deletetopic_returns() {
return null;
}
public static function renametopic_parameters() {
return new external_function_parameters(
array(
"topicid" => new external_value(PARAM_INT, "topicid"),
"newtopicname" => new external_value(PARAM_TEXT, "newtopicname")
)
);
}
public static function renametopic($topicid, $newtopicname) {
global $DB;
$params = self::validate_parameters(
self::renametopic_parameters(),
array('topicid' => $topicid,
'newtopicname' => $newtopicname)
);
$cmid = self::get_cmid($params['topicid']);
$context = context_module::instance($cmid);
require_capability('mod/cardbox:edittopics', $context);
$success = $DB->set_field_select('cardbox_topics', 'topicname', $params['newtopicname'], 'id = :id', ['id' => $params['topicid']]);
return $success;
}
public static function renametopic_returns() {
return null;
}
public static function get_cmid($topicid) {
global $DB;
$sql = 'SELECT cardboxid FROM {cardbox_topics} WHERE id = :id';
$cardboxid = $DB->get_field_sql($sql, ['id' => $topicid]);
$sql = 'SELECT id FROM {modules} WHERE name = "cardbox"';
$module = $DB->get_field_sql($sql);
$sql = 'SELECT id FROM {course_modules} WHERE module = :module AND instance= :cardboxid';
return $DB->get_field_sql($sql, ['cardboxid' => $cardboxid, 'module' => $module]);
}
}