weekly release 2.5dev
[moodle.git] / calendar / externallib.php
CommitLineData
01bea07d
AA
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
18/**
19 * External calendar API
20 *
21 * @package core_calendar
22 * @category external
23 * @copyright 2012 Ankit Agarwal
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 * @since Moodle 2.5
26 */
27
28defined('MOODLE_INTERNAL') || die;
29
30require_once("$CFG->libdir/externallib.php");
31
32/**
33 * Calendar external functions
34 *
35 * @package core_calendar
36 * @category external
37 * @copyright 2012 Ankit Agarwal
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 * @since Moodle 2.5
40 */
41class core_calendar_external extends external_api {
42
43
44 /**
45 * Returns description of method parameters
46 *
47 * @return external_function_parameters
48 * @since Moodle 2.5
49 */
50 public static function delete_calendar_events_parameters() {
51 return new external_function_parameters(
52 array('events' => new external_multiple_structure(
53 new external_single_structure(
54 array(
55 'eventid' => new external_value(PARAM_INT, 'Event ID', VALUE_REQUIRED, '', NULL_NOT_ALLOWED),
56 'repeat' => new external_value(PARAM_BOOL, 'Delete comeplete series if repeated event')
57 ), 'List of events to delete'
58 )
59 )
60 )
61 );
62 }
63
64 /**
65 * Delete Calendar events
66 *
67 * @param array $eventids A list of event ids with repeat flag to delete
68 * @return null
69 * @since Moodle 2.5
70 */
71 public static function delete_calendar_events($events) {
72 global $CFG, $DB;
73 require_once($CFG->dirroot."/calendar/lib.php");
74
75 // Parameter validation.
76 $params = self::validate_parameters(self:: delete_calendar_events_parameters(), array('events' => $events));
77
78 $transaction = $DB->start_delegated_transaction();
79
80 foreach ($params['events'] as $event) {
81 $eventobj = calendar_event::load($event['eventid']);
82
83 // Let's check if the user is allowed to delete an event.
84 if (!calendar_edit_event_allowed($eventobj)) {
85 throw new moodle_exception("nopermissions");
86 }
87 // Time to do the magic.
88 $eventobj->delete($event['repeat']);
89 }
90
91 // Everything done smoothly, let's commit.
92 $transaction->allow_commit();
93
94 return null;
95 }
96
97 /**
98 * Returns description of method result value
99 *
100 * @return external_description
101 * @since Moodle 2.5
102 */
103 public static function delete_calendar_events_returns() {
104 return null;
105 }
106}