Merge branch 'w18_MDL-30686_m23_guessurl' of git://github.com/skodak/moodle
[moodle.git] / course / externallib.php
CommitLineData
8e7d3fe4 1<?php
8e7d3fe4
PS
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
4615817d 17
8e7d3fe4 18/**
6bb31e40 19 * External course API
8e7d3fe4 20 *
4615817d
JM
21 * @package core_course
22 * @category external
23 * @copyright 2009 Petr Skodak
8e7d3fe4
PS
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
26
df997f84
PS
27defined('MOODLE_INTERNAL') || die;
28
8e7d3fe4
PS
29require_once("$CFG->libdir/externallib.php");
30
5d1017e1 31/**
4615817d
JM
32 * Course external functions
33 *
34 * @package core_course
35 * @category external
36 * @copyright 2011 Jerome Mouneyrac
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 * @since Moodle 2.2
5d1017e1
JM
39 */
40class core_course_external extends external_api {
8e7d3fe4 41
ec0d6ea2
DC
42 /**
43 * Returns description of method parameters
4615817d 44 *
ec0d6ea2 45 * @return external_function_parameters
4615817d 46 * @since Moodle 2.2
ec0d6ea2
DC
47 */
48 public static function get_course_contents_parameters() {
49 return new external_function_parameters(
50 array('courseid' => new external_value(PARAM_INT, 'course id'),
51 'options' => new external_multiple_structure (
52 new external_single_structure(
53 array('name' => new external_value(PARAM_ALPHANUM, 'option name'),
54 'value' => new external_value(PARAM_RAW, 'the value of the option, this param is personaly validated in the external function.')
55 )
56 ), 'Options, not used yet, might be used in later version', VALUE_DEFAULT, array())
57 )
58 );
59 }
60
61 /**
62 * Get course contents
4615817d
JM
63 *
64 * @param int $courseid course id
65 * @param array $options These options are not used yet, might be used in later version
ec0d6ea2 66 * @return array
4615817d 67 * @since Moodle 2.2
ec0d6ea2
DC
68 */
69 public static function get_course_contents($courseid, $options) {
70 global $CFG, $DB;
71 require_once($CFG->dirroot . "/course/lib.php");
72
73 //validate parameter
74 $params = self::validate_parameters(self::get_course_contents_parameters(),
75 array('courseid' => $courseid, 'options' => $options));
76
77 //retrieve the course
78 $course = $DB->get_record('course', array('id' => $params['courseid']), '*', MUST_EXIST);
79
80 //check course format exist
81 if (!file_exists($CFG->dirroot . '/course/format/' . $course->format . '/lib.php')) {
82 throw new moodle_exception('cannotgetcoursecontents', 'webservice', '', null, get_string('courseformatnotfound', 'error', '', $course->format));
83 } else {
84 require_once($CFG->dirroot . '/course/format/' . $course->format . '/lib.php');
85 }
86
87 // now security checks
88 $context = get_context_instance(CONTEXT_COURSE, $course->id);
89 try {
90 self::validate_context($context);
91 } catch (Exception $e) {
92 $exceptionparam = new stdClass();
93 $exceptionparam->message = $e->getMessage();
94 $exceptionparam->courseid = $course->id;
95 throw new moodle_exception('errorcoursecontextnotvalid', 'webservice', '', $exceptionparam);
96 }
97
98 $canupdatecourse = has_capability('moodle/course:update', $context);
99
100 //create return value
101 $coursecontents = array();
102
103 if ($canupdatecourse or $course->visible
104 or has_capability('moodle/course:viewhiddencourses', $context)) {
105
106 //retrieve sections
107 $modinfo = get_fast_modinfo($course);
108 $sections = get_all_sections($course->id);
109
110 //for each sections (first displayed to last displayed)
111 foreach ($sections as $key => $section) {
112
113 $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $section->visible or !$course->hiddensections);
114 if (!$showsection) {
115 continue;
116 }
117
118 // reset $sectioncontents
119 $sectionvalues = array();
120 $sectionvalues['id'] = $section->id;
121 $sectionvalues['name'] = get_section_name($course, $section);
122 $summary = file_rewrite_pluginfile_urls($section->summary, 'webservice/pluginfile.php', $context->id, 'course', 'section', $section->id);
123 $sectionvalues['visible'] = $section->visible;
124 $sectionvalues['summary'] = format_text($summary, $section->summaryformat);
125 $sectioncontents = array();
126
127 //for each module of the section
128 foreach ($modinfo->sections[$section->section] as $cmid) { //matching /course/lib.php:print_section() logic
129 $cm = $modinfo->cms[$cmid];
130
131 // stop here if the module is not visible to the user
132 if (!$cm->uservisible) {
133 continue;
134 }
135
136 $module = array();
137
138 //common info (for people being able to see the module or availability dates)
139 $module['id'] = $cm->id;
140 $module['name'] = format_string($cm->name, true);
141 $module['modname'] = $cm->modname;
142 $module['modplural'] = $cm->modplural;
143 $module['modicon'] = $cm->get_icon_url()->out(false);
144 $module['indent'] = $cm->indent;
145
146 $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
147
148 if (!empty($cm->showdescription)) {
149 $module['description'] = $cm->get_content();
150 }
151
152 //url of the module
153 $url = $cm->get_url();
154 if ($url) { //labels don't have url
155 $module['url'] = $cm->get_url()->out();
156 }
157
158 $canviewhidden = has_capability('moodle/course:viewhiddenactivities',
159 get_context_instance(CONTEXT_MODULE, $cm->id));
160 //user that can view hidden module should know about the visibility
161 $module['visible'] = $cm->visible;
162
163 //availability date (also send to user who can see hidden module when the showavailabilyt is ON)
164 if ($canupdatecourse or ($CFG->enableavailability && $canviewhidden && $cm->showavailability)) {
165 $module['availablefrom'] = $cm->availablefrom;
166 $module['availableuntil'] = $cm->availableuntil;
167 }
168
169 $baseurl = 'webservice/pluginfile.php';
170
171 //call $modulename_export_contents
172 //(each module callback take care about checking the capabilities)
173 require_once($CFG->dirroot . '/mod/' . $cm->modname . '/lib.php');
174 $getcontentfunction = $cm->modname.'_export_contents';
175 if (function_exists($getcontentfunction)) {
176 if ($contents = $getcontentfunction($cm, $baseurl)) {
177 $module['contents'] = $contents;
178 }
179 }
180
181 //assign result to $sectioncontents
182 $sectioncontents[] = $module;
183
184 }
185 $sectionvalues['modules'] = $sectioncontents;
186
187 // assign result to $coursecontents
188 $coursecontents[] = $sectionvalues;
189 }
190 }
191 return $coursecontents;
192 }
193
194 /**
195 * Returns description of method result value
4615817d 196 *
ec0d6ea2 197 * @return external_description
4615817d 198 * @since Moodle 2.2
ec0d6ea2
DC
199 */
200 public static function get_course_contents_returns() {
201 return new external_multiple_structure(
202 new external_single_structure(
203 array(
204 'id' => new external_value(PARAM_INT, 'Section ID'),
205 'name' => new external_value(PARAM_TEXT, 'Section name'),
206 'visible' => new external_value(PARAM_INT, 'is the section visible', VALUE_OPTIONAL),
207 'summary' => new external_value(PARAM_RAW, 'Section description'),
208 'modules' => new external_multiple_structure(
209 new external_single_structure(
210 array(
211 'id' => new external_value(PARAM_INT, 'activity id'),
212 'url' => new external_value(PARAM_URL, 'activity url', VALUE_OPTIONAL),
213 'name' => new external_value(PARAM_TEXT, 'activity module name'),
214 'description' => new external_value(PARAM_RAW, 'activity description', VALUE_OPTIONAL),
215 'visible' => new external_value(PARAM_INT, 'is the module visible', VALUE_OPTIONAL),
216 'modicon' => new external_value(PARAM_URL, 'activity icon url'),
217 'modname' => new external_value(PARAM_PLUGIN, 'activity module type'),
218 'modplural' => new external_value(PARAM_TEXT, 'activity module plural name'),
219 'availablefrom' => new external_value(PARAM_INT, 'module availability start date', VALUE_OPTIONAL),
220 'availableuntil' => new external_value(PARAM_INT, 'module availability en date', VALUE_OPTIONAL),
221 'indent' => new external_value(PARAM_INT, 'number of identation in the site'),
222 'contents' => new external_multiple_structure(
223 new external_single_structure(
224 array(
225 // content info
226 'type'=> new external_value(PARAM_TEXT, 'a file or a folder or external link'),
227 'filename'=> new external_value(PARAM_FILE, 'filename'),
228 'filepath'=> new external_value(PARAM_PATH, 'filepath'),
229 'filesize'=> new external_value(PARAM_INT, 'filesize'),
230 'fileurl' => new external_value(PARAM_URL, 'downloadable file url', VALUE_OPTIONAL),
231 'content' => new external_value(PARAM_RAW, 'Raw content, will be used when type is content', VALUE_OPTIONAL),
232 'timecreated' => new external_value(PARAM_INT, 'Time created'),
233 'timemodified' => new external_value(PARAM_INT, 'Time modified'),
234 'sortorder' => new external_value(PARAM_INT, 'Content sort order'),
235
236 // copyright related info
237 'userid' => new external_value(PARAM_INT, 'User who added this content to moodle'),
238 'author' => new external_value(PARAM_TEXT, 'Content owner'),
239 'license' => new external_value(PARAM_TEXT, 'Content license'),
240 )
241 ), VALUE_DEFAULT, array()
242 )
243 )
244 ), 'list of module'
245 )
246 )
247 )
248 );
249 }
250
6bb31e40 251 /**
252 * Returns description of method parameters
4615817d 253 *
6bb31e40 254 * @return external_function_parameters
4615817d 255 * @since Moodle 2.2
6bb31e40 256 */
257 public static function get_courses_parameters() {
258 return new external_function_parameters(
259 array('options' => new external_single_structure(
260 array('ids' => new external_multiple_structure(
261 new external_value(PARAM_INT, 'Course id')
262 , 'List of course id. If empty return all courses
263 except front page course.',
264 VALUE_OPTIONAL)
265 ), 'options - operator OR is used', VALUE_DEFAULT, array())
266 )
267 );
268 }
269
270 /**
271 * Get courses
4615817d
JM
272 *
273 * @param array $options It contains an array (list of ids)
6bb31e40 274 * @return array
4615817d 275 * @since Moodle 2.2
6bb31e40 276 */
277 public static function get_courses($options) {
278 global $CFG, $DB;
279 require_once($CFG->dirroot . "/course/lib.php");
280
281 //validate parameter
282 $params = self::validate_parameters(self::get_courses_parameters(),
283 array('options' => $options));
284
285 //retrieve courses
286 if (!key_exists('ids', $params['options'])
287 or empty($params['options']['ids'])) {
288 $courses = $DB->get_records('course');
289 } else {
290 $courses = $DB->get_records_list('course', 'id', $params['options']['ids']);
291 }
292
293 //create return value
294 $coursesinfo = array();
295 foreach ($courses as $course) {
296
297 // now security checks
298 $context = get_context_instance(CONTEXT_COURSE, $course->id);
299 try {
300 self::validate_context($context);
301 } catch (Exception $e) {
302 $exceptionparam = new stdClass();
303 $exceptionparam->message = $e->getMessage();
304 $exceptionparam->courseid = $course->id;
305 throw new moodle_exception(
306 get_string('errorcoursecontextnotvalid', 'webservice', $exceptionparam));
307 }
308 require_capability('moodle/course:view', $context);
309
310 $courseinfo = array();
311 $courseinfo['id'] = $course->id;
312 $courseinfo['fullname'] = $course->fullname;
313 $courseinfo['shortname'] = $course->shortname;
314 $courseinfo['categoryid'] = $course->category;
315 $courseinfo['summary'] = $course->summary;
316 $courseinfo['summaryformat'] = $course->summaryformat;
317 $courseinfo['format'] = $course->format;
318 $courseinfo['startdate'] = $course->startdate;
319 $courseinfo['numsections'] = $course->numsections;
320
321 //some field should be returned only if the user has update permission
322 $courseadmin = has_capability('moodle/course:update', $context);
323 if ($courseadmin) {
324 $courseinfo['categorysortorder'] = $course->sortorder;
325 $courseinfo['idnumber'] = $course->idnumber;
326 $courseinfo['showgrades'] = $course->showgrades;
327 $courseinfo['showreports'] = $course->showreports;
328 $courseinfo['newsitems'] = $course->newsitems;
329 $courseinfo['visible'] = $course->visible;
330 $courseinfo['maxbytes'] = $course->maxbytes;
331 $courseinfo['hiddensections'] = $course->hiddensections;
332 $courseinfo['groupmode'] = $course->groupmode;
333 $courseinfo['groupmodeforce'] = $course->groupmodeforce;
334 $courseinfo['defaultgroupingid'] = $course->defaultgroupingid;
335 $courseinfo['lang'] = $course->lang;
336 $courseinfo['timecreated'] = $course->timecreated;
337 $courseinfo['timemodified'] = $course->timemodified;
338 $courseinfo['forcetheme'] = $course->theme;
339 $courseinfo['enablecompletion'] = $course->enablecompletion;
340 $courseinfo['completionstartonenrol'] = $course->completionstartonenrol;
341 $courseinfo['completionnotify'] = $course->completionnotify;
342 }
343
344 if ($courseadmin or $course->visible
345 or has_capability('moodle/course:viewhiddencourses', $context)) {
346 $coursesinfo[] = $courseinfo;
347 }
348 }
349
350 return $coursesinfo;
351 }
352
353 /**
354 * Returns description of method result value
4615817d 355 *
6bb31e40 356 * @return external_description
4615817d 357 * @since Moodle 2.2
6bb31e40 358 */
359 public static function get_courses_returns() {
360 return new external_multiple_structure(
361 new external_single_structure(
362 array(
363 'id' => new external_value(PARAM_INT, 'course id'),
364 'shortname' => new external_value(PARAM_TEXT, 'course short name'),
365 'categoryid' => new external_value(PARAM_INT, 'category id'),
366 'categorysortorder' => new external_value(PARAM_INT,
367 'sort order into the category', VALUE_OPTIONAL),
368 'fullname' => new external_value(PARAM_TEXT, 'full name'),
369 'idnumber' => new external_value(PARAM_RAW, 'id number', VALUE_OPTIONAL),
370 'summary' => new external_value(PARAM_RAW, 'summary'),
371 'summaryformat' => new external_value(PARAM_INT,
372 'the summary text Moodle format'),
aff24313 373 'format' => new external_value(PARAM_PLUGIN,
6bb31e40 374 'course format: weeks, topics, social, site,..'),
375 'showgrades' => new external_value(PARAM_INT,
376 '1 if grades are shown, otherwise 0', VALUE_OPTIONAL),
377 'newsitems' => new external_value(PARAM_INT,
378 'number of recent items appearing on the course page', VALUE_OPTIONAL),
379 'startdate' => new external_value(PARAM_INT,
380 'timestamp when the course start'),
381 'numsections' => new external_value(PARAM_INT, 'number of weeks/topics'),
382 'maxbytes' => new external_value(PARAM_INT,
383 'largest size of file that can be uploaded into the course',
384 VALUE_OPTIONAL),
385 'showreports' => new external_value(PARAM_INT,
386 'are activity report shown (yes = 1, no =0)', VALUE_OPTIONAL),
387 'visible' => new external_value(PARAM_INT,
388 '1: available to student, 0:not available', VALUE_OPTIONAL),
389 'hiddensections' => new external_value(PARAM_INT,
390 'How the hidden sections in the course are displayed to students',
391 VALUE_OPTIONAL),
392 'groupmode' => new external_value(PARAM_INT, 'no group, separate, visible',
393 VALUE_OPTIONAL),
394 'groupmodeforce' => new external_value(PARAM_INT, '1: yes, 0: no',
395 VALUE_OPTIONAL),
396 'defaultgroupingid' => new external_value(PARAM_INT, 'default grouping id',
397 VALUE_OPTIONAL),
398 'timecreated' => new external_value(PARAM_INT,
399 'timestamp when the course have been created', VALUE_OPTIONAL),
400 'timemodified' => new external_value(PARAM_INT,
401 'timestamp when the course have been modified', VALUE_OPTIONAL),
402 'enablecompletion' => new external_value(PARAM_INT,
403 'Enabled, control via completion and activity settings. Disbaled,
404 not shown in activity settings.',
405 VALUE_OPTIONAL),
406 'completionstartonenrol' => new external_value(PARAM_INT,
407 '1: begin tracking a student\'s progress in course completion
408 after course enrolment. 0: does not',
409 VALUE_OPTIONAL),
410 'completionnotify' => new external_value(PARAM_INT,
411 '1: yes 0: no', VALUE_OPTIONAL),
aff24313 412 'lang' => new external_value(PARAM_SAFEDIR,
6bb31e40 413 'forced course language', VALUE_OPTIONAL),
aff24313 414 'forcetheme' => new external_value(PARAM_PLUGIN,
6bb31e40 415 'name of the force theme', VALUE_OPTIONAL),
416 ), 'course'
417 )
418 );
419 }
420
421 /**
422 * Returns description of method parameters
4615817d 423 *
6bb31e40 424 * @return external_function_parameters
4615817d 425 * @since Moodle 2.2
6bb31e40 426 */
427 public static function create_courses_parameters() {
428 $courseconfig = get_config('moodlecourse'); //needed for many default values
429 return new external_function_parameters(
430 array(
431 'courses' => new external_multiple_structure(
432 new external_single_structure(
433 array(
434 'fullname' => new external_value(PARAM_TEXT, 'full name'),
435 'shortname' => new external_value(PARAM_TEXT, 'course short name'),
436 'categoryid' => new external_value(PARAM_INT, 'category id'),
437 'idnumber' => new external_value(PARAM_RAW, 'id number', VALUE_OPTIONAL),
438 'summary' => new external_value(PARAM_RAW, 'summary', VALUE_OPTIONAL),
439 'summaryformat' => new external_value(PARAM_INT,
440 'the summary text Moodle format', VALUE_DEFAULT, FORMAT_MOODLE),
aff24313 441 'format' => new external_value(PARAM_PLUGIN,
6bb31e40 442 'course format: weeks, topics, social, site,..',
443 VALUE_DEFAULT, $courseconfig->format),
444 'showgrades' => new external_value(PARAM_INT,
445 '1 if grades are shown, otherwise 0', VALUE_DEFAULT,
446 $courseconfig->showgrades),
447 'newsitems' => new external_value(PARAM_INT,
448 'number of recent items appearing on the course page',
449 VALUE_DEFAULT, $courseconfig->newsitems),
450 'startdate' => new external_value(PARAM_INT,
451 'timestamp when the course start', VALUE_OPTIONAL),
452 'numsections' => new external_value(PARAM_INT, 'number of weeks/topics',
453 VALUE_DEFAULT, $courseconfig->numsections),
454 'maxbytes' => new external_value(PARAM_INT,
455 'largest size of file that can be uploaded into the course',
456 VALUE_DEFAULT, $courseconfig->maxbytes),
457 'showreports' => new external_value(PARAM_INT,
458 'are activity report shown (yes = 1, no =0)', VALUE_DEFAULT,
459 $courseconfig->showreports),
460 'visible' => new external_value(PARAM_INT,
461 '1: available to student, 0:not available', VALUE_OPTIONAL),
462 'hiddensections' => new external_value(PARAM_INT,
463 'How the hidden sections in the course are displayed to students',
464 VALUE_DEFAULT, $courseconfig->hiddensections),
465 'groupmode' => new external_value(PARAM_INT, 'no group, separate, visible',
466 VALUE_DEFAULT, $courseconfig->groupmode),
467 'groupmodeforce' => new external_value(PARAM_INT, '1: yes, 0: no',
468 VALUE_DEFAULT, $courseconfig->groupmodeforce),
469 'defaultgroupingid' => new external_value(PARAM_INT, 'default grouping id',
470 VALUE_DEFAULT, 0),
471 'enablecompletion' => new external_value(PARAM_INT,
8a6b1193 472 'Enabled, control via completion and activity settings. Disabled,
6bb31e40 473 not shown in activity settings.',
474 VALUE_OPTIONAL),
475 'completionstartonenrol' => new external_value(PARAM_INT,
476 '1: begin tracking a student\'s progress in course completion after
477 course enrolment. 0: does not',
478 VALUE_OPTIONAL),
479 'completionnotify' => new external_value(PARAM_INT,
480 '1: yes 0: no', VALUE_OPTIONAL),
aff24313 481 'lang' => new external_value(PARAM_SAFEDIR,
6bb31e40 482 'forced course language', VALUE_OPTIONAL),
aff24313 483 'forcetheme' => new external_value(PARAM_PLUGIN,
6bb31e40 484 'name of the force theme', VALUE_OPTIONAL),
485 )
486 ), 'courses to create'
487 )
488 )
489 );
490 }
491
492 /**
493 * Create courses
4615817d 494 *
6bb31e40 495 * @param array $courses
496 * @return array courses (id and shortname only)
4615817d 497 * @since Moodle 2.2
6bb31e40 498 */
499 public static function create_courses($courses) {
500 global $CFG, $DB;
501 require_once($CFG->dirroot . "/course/lib.php");
502 require_once($CFG->libdir . '/completionlib.php');
503
504
505 $params = self::validate_parameters(self::create_courses_parameters(),
506 array('courses' => $courses));
507
508 $availablethemes = get_plugin_list('theme');
509 $availablelangs = get_string_manager()->get_list_of_translations();
510
511 $transaction = $DB->start_delegated_transaction();
512
513 foreach ($params['courses'] as $course) {
514
515 // Ensure the current user is allowed to run this function
516 $context = get_context_instance(CONTEXT_COURSECAT, $course['categoryid']);
517 try {
518 self::validate_context($context);
519 } catch (Exception $e) {
520 $exceptionparam = new stdClass();
521 $exceptionparam->message = $e->getMessage();
522 $exceptionparam->catid = $course['categoryid'];
523 throw new moodle_exception(
524 get_string('errorcatcontextnotvalid', 'webservice', $exceptionparam));
525 }
526 require_capability('moodle/course:create', $context);
527
528 // Make sure lang is valid
529 if (key_exists('lang', $course) and empty($availablelangs[$course['lang']])) {
530 throw new moodle_exception(
531 get_string('errorinvalidparam', 'webservice', 'lang'));
532 }
533
534 // Make sure theme is valid
535 if (key_exists('forcetheme', $course)) {
536 if (!empty($CFG->allowcoursethemes)) {
537 if (empty($availablethemes[$course['forcetheme']])) {
538 throw new moodle_exception(
539 get_string('errorinvalidparam', 'webservice', 'forcetheme'));
540 } else {
541 $course['theme'] = $course['forcetheme'];
542 }
543 }
544 }
545
546 //force visibility if ws user doesn't have the permission to set it
547 $category = $DB->get_record('course_categories', array('id' => $course['categoryid']));
548 if (!has_capability('moodle/course:visibility', $context)) {
549 $course['visible'] = $category->visible;
550 }
551
552 //set default value for completion
8a6b1193 553 $courseconfig = get_config('moodlecourse');
6bb31e40 554 if (completion_info::is_enabled_for_site()) {
555 if (!key_exists('enablecompletion', $course)) {
8a6b1193 556 $course['enablecompletion'] = $courseconfig->enablecompletion;
6bb31e40 557 }
558 if (!key_exists('completionstartonenrol', $course)) {
8a6b1193 559 $course['completionstartonenrol'] = $courseconfig->completionstartonenrol;
6bb31e40 560 }
561 } else {
562 $course['enablecompletion'] = 0;
563 $course['completionstartonenrol'] = 0;
564 }
565
566 $course['category'] = $course['categoryid'];
567
568 //Note: create_course() core function check shortname, idnumber, category
569 $course['id'] = create_course((object) $course)->id;
570
571 $resultcourses[] = array('id' => $course['id'], 'shortname' => $course['shortname']);
572 }
573
574 $transaction->allow_commit();
575
576 return $resultcourses;
577 }
578
579 /**
580 * Returns description of method result value
4615817d 581 *
6bb31e40 582 * @return external_description
4615817d 583 * @since Moodle 2.2
6bb31e40 584 */
585 public static function create_courses_returns() {
586 return new external_multiple_structure(
587 new external_single_structure(
588 array(
589 'id' => new external_value(PARAM_INT, 'course id'),
590 'shortname' => new external_value(PARAM_TEXT, 'short name'),
591 )
592 )
593 );
594 }
595
5d1017e1
JM
596}
597
598/**
4615817d
JM
599 * Deprecated course external functions
600 *
601 * @package core_course
602 * @copyright 2009 Petr Skodak
603 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
604 * @since Moodle 2.0
605 * @deprecated Moodle 2.2 MDL-29106 - Please do not use this class any more.
606 * @todo MDL-31194 This will be deleted in Moodle 2.5.
607 * @see core_course_external
5d1017e1
JM
608 */
609class moodle_course_external extends external_api {
610
611 /**
612 * Returns description of method parameters
4615817d 613 *
5d1017e1 614 * @return external_function_parameters
4615817d
JM
615 * @since Moodle 2.0
616 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
617 * @todo MDL-31194 This will be deleted in Moodle 2.5.
618 * @see core_course_external::get_courses_parameters()
5d1017e1
JM
619 */
620 public static function get_courses_parameters() {
621 return core_course_external::get_courses_parameters();
622 }
623
624 /**
625 * Get courses
4615817d 626 *
5d1017e1 627 * @param array $options
5d1017e1 628 * @return array
4615817d
JM
629 * @since Moodle 2.0
630 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
631 * @todo MDL-31194 This will be deleted in Moodle 2.5.
632 * @see core_course_external::get_courses()
5d1017e1
JM
633 */
634 public static function get_courses($options) {
635 return core_course_external::get_courses($options);
636 }
637
638 /**
639 * Returns description of method result value
4615817d 640 *
5d1017e1 641 * @return external_description
4615817d
JM
642 * @since Moodle 2.0
643 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
644 * @todo MDL-31194 This will be deleted in Moodle 2.5.
645 * @see core_course_external::get_courses_returns()
5d1017e1
JM
646 */
647 public static function get_courses_returns() {
648 return core_course_external::get_courses_returns();
649 }
650
651 /**
652 * Returns description of method parameters
4615817d 653 *
5d1017e1 654 * @return external_function_parameters
4615817d
JM
655 * @since Moodle 2.0
656 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
657 * @todo MDL-31194 This will be deleted in Moodle 2.5.
658 * @see core_course_external::create_courses_parameters()
5d1017e1
JM
659 */
660 public static function create_courses_parameters() {
661 return core_course_external::create_courses_parameters();
662 }
663
664 /**
665 * Create courses
4615817d 666 *
5d1017e1
JM
667 * @param array $courses
668 * @return array courses (id and shortname only)
4615817d
JM
669 * @since Moodle 2.0
670 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
671 * @todo MDL-31194 This will be deleted in Moodle 2.5.
672 * @see core_course_external::create_courses()
5d1017e1
JM
673 */
674 public static function create_courses($courses) {
675 return core_course_external::create_courses($courses);
676 }
677
678 /**
679 * Returns description of method result value
4615817d 680 *
5d1017e1 681 * @return external_description
4615817d
JM
682 * @since Moodle 2.0
683 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
684 * @todo MDL-31194 This will be deleted in Moodle 2.5.
685 * @see core_course_external::create_courses_returns()
5d1017e1
JM
686 */
687 public static function create_courses_returns() {
688 return core_course_external::create_courses_returns();
689 }
690
ec0d6ea2 691}