MDL-32941 use + operator instead array merge to avoid duplicate. Sort resulting array...
[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 */
dd5e31f3 257 public static function get_categories_parameters() {
6c6ec1d6 258 return new external_function_parameters(
dd5e31f3 259 array(
d4a17894 260 'criteria' => new external_multiple_structure(
261 new external_single_structure(
262 array(
6c6ec1d6
JM
263 'key' => new external_value(PARAM_ALPHA,
264 'The category column to search, expected keys (value format) are:'.
265 '"id" (int) the category id,'.
266 '"name" (string) the category name,'.
267 '"parent" (int) the parent category id,'.
268 '"idnumber" (string) category idnumber'.
269 ' - user must have \'moodle/category:manage\' to search on idnumber,'.
270 '"visible" (int) whether the category is visible or not'.
271 ' - user must have \'moodle/category:manage\' or \'moodle/category:viewhiddencategories\' to search on visible,'.
272 '"theme" (string) category theme'.
273 ' - user must have \'moodle/category:manage\' to search on theme'),
20854c75 274 'value' => new external_value(PARAM_RAW, 'the value to match')
d4a17894 275 )
20854c75
EL
276 ), VALUE_DEFAULT, array()
277 ),
d4a17894 278 'addsubcategories' => new external_value(PARAM_BOOL, 'return the sub categories infos
20854c75 279 (1 - default) otherwise only the category info (0)', VALUE_DEFAULT, 1)
d4a17894 280 )
6bb31e40 281 );
282 }
283
d4a246bc 284 /**
dd5e31f3
JM
285 * Get categories
286 *
d4a17894 287 * @param array $criteria Criteria to match the results
20854c75 288 * @param booln $addsubcategories obtain only the category (false) or its subcategories (true - default)
dd5e31f3
JM
289 * @return array list of categories
290 * @since Moodle 2.3
291 */
d4a17894 292 public static function get_categories($criteria = array(), $addsubcategories = true) {
d4a246bc
FS
293 global $CFG, $DB;
294 require_once($CFG->dirroot . "/course/lib.php");
d4a246bc 295
d4a17894 296 // Validate parameters.
dd5e31f3 297 $params = self::validate_parameters(self::get_categories_parameters(),
d4a17894 298 array('criteria' => $criteria, 'addsubcategories' => $addsubcategories));
dd5e31f3 299
d4a17894 300 // Retrieve the categories.
dd5e31f3 301 $categories = array();
d4a17894 302 if (!empty($params['criteria'])) {
303
304 $conditions = array();
305 $wheres = array();
306 foreach ($params['criteria'] as $crit) {
307 $key = trim($crit['key']);
308
309 // Trying to avoid duplicate keys.
310 if (!isset($conditions[$key])) {
311
312 $context = context_system::instance();
20854c75 313 $value = null;
6c6ec1d6
JM
314 // $criteriaerrormsg is a code error, do not fix typo, do not edit it.
315 $criteriaerrormsg = 'Missing permissions to search on a criteria.';
d4a17894 316 switch ($key) {
20854c75
EL
317 case 'id':
318 $value = clean_param($crit['value'], PARAM_INT);
319 break;
320
321 case 'idnumber':
322 if (has_capability('moodle/category:manage', $context)) {
323 $value = clean_param($crit['value'], PARAM_RAW);
6c6ec1d6
JM
324 } else {
325 // We must throw an exception.
326 // Otherwise the dev client would think no idnumber exists.
327 throw new moodle_exception($criteriaerrormsg,
328 '', '', null,
329 'You don\'t have the permissions to search on the "idnumber" field.');
20854c75
EL
330 }
331 break;
332
333 case 'name':
334 $value = clean_param($crit['value'], PARAM_TEXT);
335 break;
336
337 case 'parent':
338 $value = clean_param($crit['value'], PARAM_INT);
339 break;
340
341 case 'visible':
6c6ec1d6
JM
342 if (has_capability('moodle/category:manage', $context)
343 or has_capability('moodle/category:viewhiddencategories',
344 context_system::instance())) {
345 $value = clean_param($crit['value'], PARAM_INT);
346 } else {
347 throw new moodle_exception($criteriaerrormsg,
348 '', '', null,
349 'You don\'t have the permissions to search on the "visible" field.');
350 }
20854c75
EL
351 break;
352
353 case 'theme':
354 if (has_capability('moodle/category:manage', $context)) {
355 $value = clean_param($crit['value'], PARAM_THEME);
6c6ec1d6
JM
356 } else {
357 throw new moodle_exception($criteriaerrormsg,
358 '', '', null,
359 'You don\'t have the permissions to search on the "theme" field.');
20854c75
EL
360 }
361 break;
362
363 default:
6c6ec1d6
JM
364 throw new moodle_exception($criteriaerrormsg,
365 '', '', null,
366 'You can not search on this criteria: ' . $key);
d4a17894 367 }
368
20854c75 369 if (isset($value)) {
d4a17894 370 $conditions[$key] = $crit['value'];
371 $wheres[] = $key . " = :" . $key;
372 }
373 }
374 }
375
376 if (!empty($wheres)) {
377 $wheres = implode(" AND ", $wheres);
378
6c6ec1d6 379 $categories = $DB->get_records_select('course_categories', $wheres, $conditions);
d4a17894 380
381 // Retrieve its sub subcategories (all levels).
382 if ($categories and !empty($params['addsubcategories'])) {
383 $newcategories = array();
384
385 foreach ($categories as $category) {
386 $sqllike = $DB->sql_like('path', ':path');
20854c75 387 $sqlparams = array('path' => $category->path.'/%'); // It will NOT include the specified category.
6c6ec1d6
JM
388 $subcategories = $DB->get_records_select('course_categories', $sqllike, $sqlparams);
389 $newcategories = $newcategories + $subcategories; // Both arrays have integer as keys.
d4a17894 390 }
6c6ec1d6 391 $categories = $categories + $newcategories;
d4a17894 392 }
393 }
394
dd5e31f3 395 } else {
d4a17894 396 // Retrieve all categories in the database.
6c6ec1d6 397 $categories = $DB->get_records('course_categories');
d4a246bc
FS
398 }
399
d4a17894 400 // The not returned categories. key => category id, value => reason of exclusion.
dd5e31f3
JM
401 $excludedcats = array();
402
d4a17894 403 // The returned categories.
d4a246bc 404 $categoriesinfo = array();
dd5e31f3 405
6c6ec1d6
JM
406 // We need to sort the categories by path.
407 // The parent cats need to be checked by the algo first.
408 usort($categories, "core_course_external::compare_categories_by_path");
409
d4a246bc 410 foreach ($categories as $category) {
dd5e31f3 411
d4a17894 412 // Check if the category is a child of an excluded category, if yes exclude it too (excluded => do not return).
dd5e31f3 413 $parents = explode('/', $category->path);
d4a17894 414 unset($parents[0]); // First key is always empty because path start with / => /1/2/4.
dd5e31f3
JM
415 foreach ($parents as $parentid) {
416 // Note: when the parent exclusion was due to the context,
d4a17894 417 // the sub category could still be returned.
dd5e31f3
JM
418 if (isset($excludedcats[$parentid]) and $excludedcats[$parentid] != 'context') {
419 $excludedcats[$category->id] = 'parent';
420 }
421 }
422
d4a17894 423 // Check category depth is <= maxdepth (do not check for user who can manage categories).
dd5e31f3
JM
424 if ((!empty($CFG->maxcategorydepth) && count($parents) > $CFG->maxcategorydepth)
425 and !has_capability('moodle/category:manage', $context)) {
426 $excludedcats[$category->id] = 'depth';
427 }
428
d4a17894 429 // Check the user can use the category context.
d4a246bc
FS
430 $context = context_coursecat::instance($category->id);
431 try {
432 self::validate_context($context);
433 } catch (Exception $e) {
dd5e31f3
JM
434 $excludedcats[$category->id] = 'context';
435
d4a17894 436 // If it was the requested category then throw an exception.
dd5e31f3
JM
437 if (isset($params['categoryid']) && $category->id == $params['categoryid']) {
438 $exceptionparam = new stdClass();
439 $exceptionparam->message = $e->getMessage();
440 $exceptionparam->catid = $category->id;
d4a246bc 441 throw new moodle_exception('errorcatcontextnotvalid', 'webservice', '', $exceptionparam);
dd5e31f3 442 }
d4a246bc
FS
443 }
444
d4a17894 445 // Return the category information.
dd5e31f3
JM
446 if (!isset($excludedcats[$category->id])) {
447
d4a17894 448 // Final check to see if the category is visible to the user.
dd5e31f3
JM
449 if ($category->visible
450 or has_capability('moodle/category:viewhiddencategories', context_system::instance())
451 or has_capability('moodle/category:manage', $context)) {
452
453 $categoryinfo = array();
454 $categoryinfo['id'] = $category->id;
455 $categoryinfo['name'] = $category->name;
456 $categoryinfo['description'] = file_rewrite_pluginfile_urls($category->description,
457 'webservice/pluginfile.php', $context->id, 'coursecat', 'description', null);
458 $options = new stdClass;
459 $options->noclean = true;
460 $options->para = false;
461 $categoryinfo['description'] = format_text($categoryinfo['description'],
462 $category->descriptionformat, $options);
463 $categoryinfo['parent'] = $category->parent;
464 $categoryinfo['sortorder'] = $category->sortorder;
465 $categoryinfo['coursecount'] = $category->coursecount;
466 $categoryinfo['depth'] = $category->depth;
467 $categoryinfo['path'] = $category->path;
468
d4a17894 469 // Some fields only returned for admin.
dd5e31f3
JM
470 if (has_capability('moodle/category:manage', $context)) {
471 $categoryinfo['idnumber'] = $category->idnumber;
472 $categoryinfo['visible'] = $category->visible;
473 $categoryinfo['visibleold'] = $category->visibleold;
474 $categoryinfo['timemodified'] = $category->timemodified;
475 $categoryinfo['theme'] = $category->theme;
476 }
d4a246bc 477
dd5e31f3
JM
478 $categoriesinfo[] = $categoryinfo;
479 } else {
480 $excludedcats[$category->id] = 'visibility';
481 }
d4a246bc
FS
482 }
483 }
484
6c6ec1d6
JM
485 // Sorting the resulting array so it looks a bit better for the client developer.
486 usort($categoriesinfo, "core_course_external::compare_categories_by_sortorder");
487
d4a246bc
FS
488 return $categoriesinfo;
489 }
490
6c6ec1d6
JM
491 /**
492 * Sort categories array by path
493 * private function: only used by get_categories
494 *
495 * @param array $category1
496 * @param array $category2
497 * @return int result of strcmp
498 * @since Moodle 2.3
499 */
500 public static function compare_categories_by_path($category1, $category2) {
501 return strcmp($category1->path, $category2->path);
502 }
503
504 /**
505 * Sort categories array by sortorder
506 * private function: only used by get_categories
507 *
508 * @param array $category1
509 * @param array $category2
510 * @return int result of strcmp
511 * @since Moodle 2.3
512 */
513 public static function compare_categories_by_sortorder($category1, $category2) {
514 return strcmp($category1['sortorder'], $category2['sortorder']);
515 }
516
d4a246bc 517 /**
dd5e31f3
JM
518 * Returns description of method result value
519 *
520 * @return external_description
521 * @since Moodle 2.3
522 */
d4a246bc
FS
523 public static function get_categories_returns() {
524 return new external_multiple_structure(
525 new external_single_structure(
526 array(
527 'id' => new external_value(PARAM_INT, 'category id'),
528 'name' => new external_value(PARAM_TEXT, 'category name'),
529 'idnumber' => new external_value(PARAM_RAW, 'category id number', VALUE_OPTIONAL),
dd5e31f3 530 'description' => new external_value(PARAM_RAW, 'category description'),
d4a246bc
FS
531 'parent' => new external_value(PARAM_INT, 'parent category id'),
532 'sortorder' => new external_value(PARAM_INT, 'category sorting order'),
533 'coursecount' => new external_value(PARAM_INT, 'number of courses in this category'),
534 'visible' => new external_value(PARAM_INT, '1: available, 0:not available', VALUE_OPTIONAL),
535 'visibleold' => new external_value(PARAM_INT, '1: available, 0:not available', VALUE_OPTIONAL),
536 'timemodified' => new external_value(PARAM_INT, 'timestamp', VALUE_OPTIONAL),
537 'depth' => new external_value(PARAM_INT, 'category depth'),
538 'path' => new external_value(PARAM_TEXT, 'category path'),
539 'theme' => new external_value(PARAM_THEME, 'category theme', VALUE_OPTIONAL),
d4a17894 540 ), 'List of categories'
d4a246bc
FS
541 )
542 );
543 }
544
545 /**
546 * Returns description of method parameters
20854c75 547 *
d4a246bc 548 * @return external_function_parameters
20854c75 549 * @since Moodle 2.2
d4a246bc 550 */
dd5e31f3 551 public static function get_courses_parameters() {
d4a246bc 552 return new external_function_parameters(
dd5e31f3
JM
553 array('options' => new external_single_structure(
554 array('ids' => new external_multiple_structure(
555 new external_value(PARAM_INT, 'Course id')
556 , 'List of course id. If empty return all courses
557 except front page course.',
558 VALUE_OPTIONAL)
559 ), 'options - operator OR is used', VALUE_DEFAULT, array())
d4a246bc 560 )
d4a246bc
FS
561 );
562 }
563
6bb31e40 564 /**
565 * Get courses
4615817d
JM
566 *
567 * @param array $options It contains an array (list of ids)
6bb31e40 568 * @return array
4615817d 569 * @since Moodle 2.2
6bb31e40 570 */
571 public static function get_courses($options) {
572 global $CFG, $DB;
573 require_once($CFG->dirroot . "/course/lib.php");
574
575 //validate parameter
576 $params = self::validate_parameters(self::get_courses_parameters(),
577 array('options' => $options));
578
579 //retrieve courses
580 if (!key_exists('ids', $params['options'])
581 or empty($params['options']['ids'])) {
582 $courses = $DB->get_records('course');
583 } else {
584 $courses = $DB->get_records_list('course', 'id', $params['options']['ids']);
585 }
586
587 //create return value
588 $coursesinfo = array();
589 foreach ($courses as $course) {
590
591 // now security checks
592 $context = get_context_instance(CONTEXT_COURSE, $course->id);
593 try {
594 self::validate_context($context);
595 } catch (Exception $e) {
596 $exceptionparam = new stdClass();
597 $exceptionparam->message = $e->getMessage();
598 $exceptionparam->courseid = $course->id;
599 throw new moodle_exception(
600 get_string('errorcoursecontextnotvalid', 'webservice', $exceptionparam));
601 }
602 require_capability('moodle/course:view', $context);
603
604 $courseinfo = array();
605 $courseinfo['id'] = $course->id;
606 $courseinfo['fullname'] = $course->fullname;
607 $courseinfo['shortname'] = $course->shortname;
608 $courseinfo['categoryid'] = $course->category;
609 $courseinfo['summary'] = $course->summary;
610 $courseinfo['summaryformat'] = $course->summaryformat;
611 $courseinfo['format'] = $course->format;
612 $courseinfo['startdate'] = $course->startdate;
613 $courseinfo['numsections'] = $course->numsections;
614
615 //some field should be returned only if the user has update permission
616 $courseadmin = has_capability('moodle/course:update', $context);
617 if ($courseadmin) {
618 $courseinfo['categorysortorder'] = $course->sortorder;
619 $courseinfo['idnumber'] = $course->idnumber;
620 $courseinfo['showgrades'] = $course->showgrades;
621 $courseinfo['showreports'] = $course->showreports;
622 $courseinfo['newsitems'] = $course->newsitems;
623 $courseinfo['visible'] = $course->visible;
624 $courseinfo['maxbytes'] = $course->maxbytes;
625 $courseinfo['hiddensections'] = $course->hiddensections;
626 $courseinfo['groupmode'] = $course->groupmode;
627 $courseinfo['groupmodeforce'] = $course->groupmodeforce;
628 $courseinfo['defaultgroupingid'] = $course->defaultgroupingid;
629 $courseinfo['lang'] = $course->lang;
630 $courseinfo['timecreated'] = $course->timecreated;
631 $courseinfo['timemodified'] = $course->timemodified;
632 $courseinfo['forcetheme'] = $course->theme;
633 $courseinfo['enablecompletion'] = $course->enablecompletion;
634 $courseinfo['completionstartonenrol'] = $course->completionstartonenrol;
635 $courseinfo['completionnotify'] = $course->completionnotify;
636 }
637
638 if ($courseadmin or $course->visible
639 or has_capability('moodle/course:viewhiddencourses', $context)) {
640 $coursesinfo[] = $courseinfo;
641 }
642 }
643
644 return $coursesinfo;
645 }
646
647 /**
648 * Returns description of method result value
4615817d 649 *
6bb31e40 650 * @return external_description
4615817d 651 * @since Moodle 2.2
6bb31e40 652 */
653 public static function get_courses_returns() {
654 return new external_multiple_structure(
655 new external_single_structure(
656 array(
657 'id' => new external_value(PARAM_INT, 'course id'),
658 'shortname' => new external_value(PARAM_TEXT, 'course short name'),
659 'categoryid' => new external_value(PARAM_INT, 'category id'),
660 'categorysortorder' => new external_value(PARAM_INT,
661 'sort order into the category', VALUE_OPTIONAL),
662 'fullname' => new external_value(PARAM_TEXT, 'full name'),
663 'idnumber' => new external_value(PARAM_RAW, 'id number', VALUE_OPTIONAL),
664 'summary' => new external_value(PARAM_RAW, 'summary'),
665 'summaryformat' => new external_value(PARAM_INT,
666 'the summary text Moodle format'),
aff24313 667 'format' => new external_value(PARAM_PLUGIN,
6bb31e40 668 'course format: weeks, topics, social, site,..'),
669 'showgrades' => new external_value(PARAM_INT,
670 '1 if grades are shown, otherwise 0', VALUE_OPTIONAL),
671 'newsitems' => new external_value(PARAM_INT,
672 'number of recent items appearing on the course page', VALUE_OPTIONAL),
673 'startdate' => new external_value(PARAM_INT,
674 'timestamp when the course start'),
675 'numsections' => new external_value(PARAM_INT, 'number of weeks/topics'),
676 'maxbytes' => new external_value(PARAM_INT,
677 'largest size of file that can be uploaded into the course',
678 VALUE_OPTIONAL),
679 'showreports' => new external_value(PARAM_INT,
680 'are activity report shown (yes = 1, no =0)', VALUE_OPTIONAL),
681 'visible' => new external_value(PARAM_INT,
682 '1: available to student, 0:not available', VALUE_OPTIONAL),
683 'hiddensections' => new external_value(PARAM_INT,
684 'How the hidden sections in the course are displayed to students',
685 VALUE_OPTIONAL),
686 'groupmode' => new external_value(PARAM_INT, 'no group, separate, visible',
687 VALUE_OPTIONAL),
688 'groupmodeforce' => new external_value(PARAM_INT, '1: yes, 0: no',
689 VALUE_OPTIONAL),
690 'defaultgroupingid' => new external_value(PARAM_INT, 'default grouping id',
691 VALUE_OPTIONAL),
692 'timecreated' => new external_value(PARAM_INT,
693 'timestamp when the course have been created', VALUE_OPTIONAL),
694 'timemodified' => new external_value(PARAM_INT,
695 'timestamp when the course have been modified', VALUE_OPTIONAL),
696 'enablecompletion' => new external_value(PARAM_INT,
697 'Enabled, control via completion and activity settings. Disbaled,
698 not shown in activity settings.',
699 VALUE_OPTIONAL),
700 'completionstartonenrol' => new external_value(PARAM_INT,
701 '1: begin tracking a student\'s progress in course completion
702 after course enrolment. 0: does not',
703 VALUE_OPTIONAL),
704 'completionnotify' => new external_value(PARAM_INT,
705 '1: yes 0: no', VALUE_OPTIONAL),
aff24313 706 'lang' => new external_value(PARAM_SAFEDIR,
6bb31e40 707 'forced course language', VALUE_OPTIONAL),
aff24313 708 'forcetheme' => new external_value(PARAM_PLUGIN,
6bb31e40 709 'name of the force theme', VALUE_OPTIONAL),
710 ), 'course'
711 )
712 );
713 }
714
479a5db1 715 /**
be051808
FS
716 * Returns description of method parameters
717 *
718 * @return external_function_parameters
719 * @since Moodle 2.3
720 */
95693c43
JM
721 public static function create_categories_parameters() {
722 return new external_function_parameters(
723 array(
724 'categories' => new external_multiple_structure(
725 new external_single_structure(
726 array(
727 'name' => new external_value(PARAM_TEXT, 'new category name'),
be051808
FS
728 'parent' => new external_value(PARAM_INT,
729 'the parent category id inside which the new category will be created'),
730 'idnumber' => new external_value(PARAM_RAW,
731 'the new category idnumber', VALUE_OPTIONAL),
732 'description' => new external_value(PARAM_RAW,
733 'the new category description', VALUE_OPTIONAL),
95693c43 734 'theme' => new external_value(PARAM_THEME,
be051808
FS
735 'the new category theme. This option must be enabled on moodle',
736 VALUE_OPTIONAL),
95693c43
JM
737 )
738 )
739 )
740 )
741 );
742 }
743
744 /**
745 * Create categories
746 *
747 * @param array $categories - see create_categories_parameters() for the array structure
748 * @return array - see create_categories_returns() for the array structure
749 * @since Moodle 2.3
95693c43
JM
750 */
751 public static function create_categories($categories) {
479a5db1
FS
752 global $CFG, $DB;
753 require_once($CFG->dirroot . "/course/lib.php");
754
95693c43
JM
755 $params = self::validate_parameters(self::create_categories_parameters(),
756 array('categories' => $categories));
757
758 $transaction = $DB->start_delegated_transaction();
95693c43 759
be051808
FS
760 $createdcategories = array();
761 foreach ($params['categories'] as $category) {
479a5db1 762 if ($category['parent']) {
95693c43 763 if (!$DB->record_exists('course_categories', array('id' => $category['parent']))) {
be051808 764 throw new moodle_exception('unknowcategory');
95693c43 765 }
479a5db1 766 $context = context_coursecat::instance($category['parent']);
be051808 767 } else {
479a5db1
FS
768 $context = context_system::instance();
769 }
770 self::validate_context($context);
95693c43 771 require_capability('moodle/category:manage', $context);
479a5db1 772
be051808
FS
773 // Check id number.
774 if (!empty($category['idnumber'])) { // Same as in course/editcategory_form.php .
775 if (textlib::strlen($category['idnumber'])>100) {
776 throw new moodle_exception('idnumbertoolong');
777 }
95693c43
JM
778 if ($existing = $DB->get_record('course_categories', array('idnumber' => $category['idnumber']))) {
779 if ($existing->id) {
780 throw new moodle_exception('idnumbertaken');
781 }
782 }
783 }
be051808
FS
784 // Check name.
785 if (textlib::strlen($category['name'])>30) {
786 throw new moodle_exception('categorytoolong');
95693c43 787 }
95693c43 788
be051808
FS
789 $newcategory = new stdClass();
790 $newcategory->name = $category['name'];
791 $newcategory->parent = $category['parent'];
792 $newcategory->idnumber = $category['idnumber'];
793 $newcategory->sortorder = 999; // Same as in the course/editcategory.php .
794 // Format the description.
795 if (!empty($category['description'])) {
796 $newcategory->description = $category['description'];
95693c43
JM
797 }
798 $newcategory->descriptionformat = FORMAT_HTML;
479a5db1
FS
799 if (isset($category['theme']) and !empty($CFG->allowcategorythemes)) {
800 $newcategory->theme = $category['theme'];
801 }
479a5db1 802
be051808
FS
803 $newcategory = create_course_category($newcategory);
804 // Populate special fields.
805 fix_course_sortorder();
95693c43 806
479a5db1
FS
807 $createdcategories[] = array('id' => $newcategory->id, 'name' => $newcategory->name);
808 }
809
95693c43
JM
810 $transaction->allow_commit();
811
479a5db1
FS
812 return $createdcategories;
813 }
479a5db1
FS
814
815 /**
be051808
FS
816 * Returns description of method parameters
817 *
818 * @return external_function_parameters
819 * @since Moodle 2.3
820 */
479a5db1
FS
821 public static function create_categories_returns() {
822 return new external_multiple_structure(
823 new external_single_structure(
824 array(
825 'id' => new external_value(PARAM_INT, 'new category id'),
826 'name' => new external_value(PARAM_TEXT, 'new category name'),
827 )
828 )
829 );
830 }
831
6bb31e40 832 /**
833 * Returns description of method parameters
4615817d 834 *
6bb31e40 835 * @return external_function_parameters
4615817d 836 * @since Moodle 2.2
6bb31e40 837 */
838 public static function create_courses_parameters() {
839 $courseconfig = get_config('moodlecourse'); //needed for many default values
840 return new external_function_parameters(
841 array(
842 'courses' => new external_multiple_structure(
843 new external_single_structure(
844 array(
845 'fullname' => new external_value(PARAM_TEXT, 'full name'),
846 'shortname' => new external_value(PARAM_TEXT, 'course short name'),
847 'categoryid' => new external_value(PARAM_INT, 'category id'),
848 'idnumber' => new external_value(PARAM_RAW, 'id number', VALUE_OPTIONAL),
849 'summary' => new external_value(PARAM_RAW, 'summary', VALUE_OPTIONAL),
850 'summaryformat' => new external_value(PARAM_INT,
851 'the summary text Moodle format', VALUE_DEFAULT, FORMAT_MOODLE),
aff24313 852 'format' => new external_value(PARAM_PLUGIN,
6bb31e40 853 'course format: weeks, topics, social, site,..',
854 VALUE_DEFAULT, $courseconfig->format),
855 'showgrades' => new external_value(PARAM_INT,
856 '1 if grades are shown, otherwise 0', VALUE_DEFAULT,
857 $courseconfig->showgrades),
858 'newsitems' => new external_value(PARAM_INT,
859 'number of recent items appearing on the course page',
860 VALUE_DEFAULT, $courseconfig->newsitems),
861 'startdate' => new external_value(PARAM_INT,
862 'timestamp when the course start', VALUE_OPTIONAL),
863 'numsections' => new external_value(PARAM_INT, 'number of weeks/topics',
864 VALUE_DEFAULT, $courseconfig->numsections),
865 'maxbytes' => new external_value(PARAM_INT,
866 'largest size of file that can be uploaded into the course',
867 VALUE_DEFAULT, $courseconfig->maxbytes),
868 'showreports' => new external_value(PARAM_INT,
869 'are activity report shown (yes = 1, no =0)', VALUE_DEFAULT,
870 $courseconfig->showreports),
871 'visible' => new external_value(PARAM_INT,
872 '1: available to student, 0:not available', VALUE_OPTIONAL),
873 'hiddensections' => new external_value(PARAM_INT,
874 'How the hidden sections in the course are displayed to students',
875 VALUE_DEFAULT, $courseconfig->hiddensections),
876 'groupmode' => new external_value(PARAM_INT, 'no group, separate, visible',
877 VALUE_DEFAULT, $courseconfig->groupmode),
878 'groupmodeforce' => new external_value(PARAM_INT, '1: yes, 0: no',
879 VALUE_DEFAULT, $courseconfig->groupmodeforce),
880 'defaultgroupingid' => new external_value(PARAM_INT, 'default grouping id',
881 VALUE_DEFAULT, 0),
882 'enablecompletion' => new external_value(PARAM_INT,
8a6b1193 883 'Enabled, control via completion and activity settings. Disabled,
6bb31e40 884 not shown in activity settings.',
885 VALUE_OPTIONAL),
886 'completionstartonenrol' => new external_value(PARAM_INT,
887 '1: begin tracking a student\'s progress in course completion after
888 course enrolment. 0: does not',
889 VALUE_OPTIONAL),
890 'completionnotify' => new external_value(PARAM_INT,
891 '1: yes 0: no', VALUE_OPTIONAL),
aff24313 892 'lang' => new external_value(PARAM_SAFEDIR,
6bb31e40 893 'forced course language', VALUE_OPTIONAL),
aff24313 894 'forcetheme' => new external_value(PARAM_PLUGIN,
6bb31e40 895 'name of the force theme', VALUE_OPTIONAL),
896 )
897 ), 'courses to create'
898 )
899 )
900 );
901 }
902
903 /**
904 * Create courses
4615817d 905 *
6bb31e40 906 * @param array $courses
907 * @return array courses (id and shortname only)
4615817d 908 * @since Moodle 2.2
6bb31e40 909 */
910 public static function create_courses($courses) {
911 global $CFG, $DB;
912 require_once($CFG->dirroot . "/course/lib.php");
913 require_once($CFG->libdir . '/completionlib.php');
914
915
916 $params = self::validate_parameters(self::create_courses_parameters(),
917 array('courses' => $courses));
918
919 $availablethemes = get_plugin_list('theme');
920 $availablelangs = get_string_manager()->get_list_of_translations();
921
922 $transaction = $DB->start_delegated_transaction();
923
924 foreach ($params['courses'] as $course) {
925
926 // Ensure the current user is allowed to run this function
927 $context = get_context_instance(CONTEXT_COURSECAT, $course['categoryid']);
928 try {
929 self::validate_context($context);
930 } catch (Exception $e) {
931 $exceptionparam = new stdClass();
932 $exceptionparam->message = $e->getMessage();
933 $exceptionparam->catid = $course['categoryid'];
934 throw new moodle_exception(
935 get_string('errorcatcontextnotvalid', 'webservice', $exceptionparam));
936 }
937 require_capability('moodle/course:create', $context);
938
939 // Make sure lang is valid
940 if (key_exists('lang', $course) and empty($availablelangs[$course['lang']])) {
941 throw new moodle_exception(
942 get_string('errorinvalidparam', 'webservice', 'lang'));
943 }
944
945 // Make sure theme is valid
946 if (key_exists('forcetheme', $course)) {
947 if (!empty($CFG->allowcoursethemes)) {
948 if (empty($availablethemes[$course['forcetheme']])) {
949 throw new moodle_exception(
950 get_string('errorinvalidparam', 'webservice', 'forcetheme'));
951 } else {
952 $course['theme'] = $course['forcetheme'];
953 }
954 }
955 }
956
957 //force visibility if ws user doesn't have the permission to set it
958 $category = $DB->get_record('course_categories', array('id' => $course['categoryid']));
959 if (!has_capability('moodle/course:visibility', $context)) {
960 $course['visible'] = $category->visible;
961 }
962
963 //set default value for completion
8a6b1193 964 $courseconfig = get_config('moodlecourse');
6bb31e40 965 if (completion_info::is_enabled_for_site()) {
966 if (!key_exists('enablecompletion', $course)) {
8a6b1193 967 $course['enablecompletion'] = $courseconfig->enablecompletion;
6bb31e40 968 }
969 if (!key_exists('completionstartonenrol', $course)) {
8a6b1193 970 $course['completionstartonenrol'] = $courseconfig->completionstartonenrol;
6bb31e40 971 }
972 } else {
973 $course['enablecompletion'] = 0;
974 $course['completionstartonenrol'] = 0;
975 }
976
977 $course['category'] = $course['categoryid'];
978
979 //Note: create_course() core function check shortname, idnumber, category
980 $course['id'] = create_course((object) $course)->id;
981
982 $resultcourses[] = array('id' => $course['id'], 'shortname' => $course['shortname']);
983 }
984
985 $transaction->allow_commit();
986
987 return $resultcourses;
988 }
989
990 /**
991 * Returns description of method result value
4615817d 992 *
6bb31e40 993 * @return external_description
4615817d 994 * @since Moodle 2.2
6bb31e40 995 */
996 public static function create_courses_returns() {
997 return new external_multiple_structure(
998 new external_single_structure(
999 array(
1000 'id' => new external_value(PARAM_INT, 'course id'),
1001 'shortname' => new external_value(PARAM_TEXT, 'short name'),
1002 )
1003 )
1004 );
1005 }
1006
63a85dc7
JL
1007 /**
1008 * Returns description of method parameters
1009 * @return external_function_parameters
1010 */
1011 public static function delete_courses_parameters() {
1012 return new external_function_parameters(
1013 array(
1014 'courseids' => new external_multiple_structure(new external_value(PARAM_INT, 'course ID')),
1015 )
1016 );
1017 }
1018
1019 /**
1020 * Delete courses
1021 * @param array $courseids A list of course ids
1022 */
1023 public static function delete_courses($courseids) {
1024 global $CFG, $DB;
1025 require_once($CFG->dirroot."/course/lib.php");
1026
1027 // Parameter validation.
1028 $params = self::validate_parameters(self::delete_courses_parameters(), array('courseids'=>$courseids));
1029
1030 $transaction = $DB->start_delegated_transaction();
1031
1032 foreach ($params['courseids'] as $courseid) {
1033 $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
1034
1035 // Check if the context is valid.
1036 $coursecontext = context_course::instance($course->id);
1037 self::validate_context($coursecontext);
1038
1039 // Check if the current user has enought permissions.
1040 if (!can_delete_course($courseid)) {
1041 throw new moodle_exception('cannotdeletecategorycourse', 'error', '', format_string($course->fullname)." (id: $courseid)");
1042 }
1043
1044 delete_course($course, false);
1045 }
1046
1047 $transaction->allow_commit();
1048
1049 return null;
1050 }
1051
1052 /**
1053 * Returns description of method result value
1054 * @return external_description
1055 */
1056 public static function delete_courses_returns() {
1057 return null;
1058 }
1059
2f951d86
FS
1060 /**
1061 * Returns description of method parameters
1062 * @return external_function_parameters
1063 * @since Moodle 2.3
1064 */
1065 public static function delete_categories_parameters() {
1066 return new external_function_parameters(
1067 array(
1068 'categories' => new external_multiple_structure(
1069 new external_single_structure(
1070 array(
1071 'id' => new external_value(PARAM_INT, 'category id to delete'),
1072 'newparent' => new external_value(PARAM_INT,
1073 'the parent category to move the contents to, if specified', VALUE_OPTIONAL),
1074 'recursive' => new external_value(PARAM_BOOL, '1: recursively delete all contents inside this
1075 category, 0 (default): move contents to newparent or current parent category (except if parent is root)', VALUE_DEFAULT, 0)
1076 )
1077 )
1078 )
1079 )
1080 );
1081 }
1082
1083 /**
1084 * Delete categories
1085 * @param array $categories A list of category ids
1086 * @return array
1087 * @since Moodle 2.3
1088 */
1089 public static function delete_categories($categories) {
1090 global $CFG, $DB;
1091 require_once($CFG->dirroot . "/course/lib.php");
1092
1093 // Validate parameters.
1094 $params = self::validate_parameters(self::delete_categories_parameters(), array('categories' => $categories));
1095
1096 foreach ($params['categories'] as $category) {
1097 if (!$deletecat = $DB->get_record('course_categories', array('id' => $category['id']))) {
1098 throw new moodle_exception('unknowcategory');
1099 }
1100 $context = context_coursecat::instance($deletecat->id);
1101 require_capability('moodle/category:manage', $context);
1102 self::validate_context($context);
1103 self::validate_context(get_category_or_system_context($deletecat->parent));
1104
1105 if ($category['recursive']) {
1106 // If recursive was specified, then we recursively delete the category's contents.
1107 category_delete_full($deletecat, false);
1108 } else {
1109 // In this situation, we don't delete the category's contents, we either move it to newparent or parent.
1110 // If the parent is the root, moving is not supported (because a course must always be inside a category).
1111 // We must move to an existing category.
1112 if (!empty($category['newparent'])) {
1113 if (!$DB->record_exists('course_categories', array('id' => $category['newparent']))) {
1114 throw new moodle_exception('unknowcategory');
1115 }
1116 $newparent = $category['newparent'];
1117 } else {
1118 $newparent = $deletecat->parent;
1119 }
1120
1121 // This operation is not allowed. We must move contents to an existing category.
1122 if ($newparent == 0) {
1123 throw new moodle_exception('movecatcontentstoroot');
1124 }
1125
1126 $parentcontext = get_category_or_system_context($newparent);
1127 require_capability('moodle/category:manage', $parentcontext);
1128 self::validate_context($parentcontext);
1129 category_delete_move($deletecat, $newparent, false);
1130 }
1131 }
1132
1133 }
1134
1135 /**
1136 * Returns description of method parameters
1137 * @return external_function_parameters
1138 * @since Moodle 2.3
1139 */
1140 public static function delete_categories_returns() {
1141 return null;
1142 }
5d1017e1
JM
1143}
1144
1145/**
4615817d
JM
1146 * Deprecated course external functions
1147 *
1148 * @package core_course
1149 * @copyright 2009 Petr Skodak
1150 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
1151 * @since Moodle 2.0
1152 * @deprecated Moodle 2.2 MDL-29106 - Please do not use this class any more.
1153 * @todo MDL-31194 This will be deleted in Moodle 2.5.
1154 * @see core_course_external
5d1017e1
JM
1155 */
1156class moodle_course_external extends external_api {
1157
1158 /**
1159 * Returns description of method parameters
4615817d 1160 *
5d1017e1 1161 * @return external_function_parameters
4615817d
JM
1162 * @since Moodle 2.0
1163 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1164 * @todo MDL-31194 This will be deleted in Moodle 2.5.
1165 * @see core_course_external::get_courses_parameters()
5d1017e1
JM
1166 */
1167 public static function get_courses_parameters() {
1168 return core_course_external::get_courses_parameters();
1169 }
1170
1171 /**
1172 * Get courses
4615817d 1173 *
5d1017e1 1174 * @param array $options
5d1017e1 1175 * @return array
4615817d
JM
1176 * @since Moodle 2.0
1177 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1178 * @todo MDL-31194 This will be deleted in Moodle 2.5.
1179 * @see core_course_external::get_courses()
5d1017e1
JM
1180 */
1181 public static function get_courses($options) {
1182 return core_course_external::get_courses($options);
1183 }
1184
1185 /**
1186 * Returns description of method result value
4615817d 1187 *
5d1017e1 1188 * @return external_description
4615817d
JM
1189 * @since Moodle 2.0
1190 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1191 * @todo MDL-31194 This will be deleted in Moodle 2.5.
1192 * @see core_course_external::get_courses_returns()
5d1017e1
JM
1193 */
1194 public static function get_courses_returns() {
1195 return core_course_external::get_courses_returns();
1196 }
1197
1198 /**
1199 * Returns description of method parameters
4615817d 1200 *
5d1017e1 1201 * @return external_function_parameters
4615817d
JM
1202 * @since Moodle 2.0
1203 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1204 * @todo MDL-31194 This will be deleted in Moodle 2.5.
1205 * @see core_course_external::create_courses_parameters()
5d1017e1
JM
1206 */
1207 public static function create_courses_parameters() {
1208 return core_course_external::create_courses_parameters();
1209 }
1210
1211 /**
1212 * Create courses
4615817d 1213 *
5d1017e1
JM
1214 * @param array $courses
1215 * @return array courses (id and shortname only)
4615817d
JM
1216 * @since Moodle 2.0
1217 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1218 * @todo MDL-31194 This will be deleted in Moodle 2.5.
1219 * @see core_course_external::create_courses()
5d1017e1
JM
1220 */
1221 public static function create_courses($courses) {
1222 return core_course_external::create_courses($courses);
1223 }
1224
1225 /**
1226 * Returns description of method result value
4615817d 1227 *
5d1017e1 1228 * @return external_description
4615817d
JM
1229 * @since Moodle 2.0
1230 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
1231 * @todo MDL-31194 This will be deleted in Moodle 2.5.
1232 * @see core_course_external::create_courses_returns()
5d1017e1
JM
1233 */
1234 public static function create_courses_returns() {
1235 return core_course_external::create_courses_returns();
1236 }
1237
ec0d6ea2 1238}