2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
20 * @package core_competency
21 * @copyright 2016 Frédéric Massart - FMCorz.net
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 namespace core_competency
;
26 defined('MOODLE_INTERNAL') ||
die();
28 require_once("$CFG->libdir/externallib.php");
29 require_once("$CFG->libdir/grade/grade_scale.php");
38 use external_function_parameters
;
40 use external_format_value
;
41 use external_single_structure
;
42 use external_multiple_structure
;
43 use invalid_parameter_exception
;
44 use required_capability_exception
;
47 use core_competency\external\competency_exporter
;
48 use core_competency\external\competency_framework_exporter
;
49 use core_competency\external\course_competency_exporter
;
50 use core_competency\external\course_competency_settings_exporter
;
51 use core_competency\external\evidence_exporter
;
52 use core_competency\external\performance_helper
;
53 use core_competency\external\plan_exporter
;
54 use core_competency\external\template_exporter
;
55 use core_competency\external\user_competency_exporter
;
56 use core_competency\external\user_competency_plan_exporter
;
57 use core_competency\external\user_evidence_competency_exporter
;
58 use core_competency\external\user_evidence_exporter
;
63 * @package core_competency
64 * @copyright 2016 Frédéric Massart - FMCorz.net
65 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
67 class external
extends external_api
{
70 * Returns a prepared structure to use a context parameters.
71 * @return external_single_structure
73 protected static function get_context_parameters() {
74 $id = new external_value(
76 'Context ID. Either use this value, or level and instanceid.',
80 $level = new external_value(
82 'Context level. To be used with instanceid.',
86 $instanceid = new external_value(
88 'Context instance ID. To be used with level',
92 return new external_single_structure(array(
94 'contextlevel' => $level,
95 'instanceid' => $instanceid,
100 * Returns description of create_competency_framework() parameters.
102 * @return \external_function_parameters
104 public static function create_competency_framework_parameters() {
105 $structure = competency_framework_exporter
::get_create_structure();
106 $params = array('competencyframework' => $structure);
107 return new external_function_parameters($params);
111 * Create a new competency framework
113 * @param array $competencyframework A single param with all the fields for a competency framework.
114 * @return \stdClass The new record
116 public static function create_competency_framework($competencyframework) {
119 $params = self
::validate_parameters(self
::create_competency_framework_parameters(), array(
120 'competencyframework' => $competencyframework
122 $params = $params['competencyframework'];
124 $context = self
::get_context_from_params($params);
125 self
::validate_context($context);
126 $output = $PAGE->get_renderer('core');
128 unset($params['contextlevel']);
129 unset($params['instanceid']);
130 $params['contextid'] = $context->id
;
132 $params = (object) $params;
133 $result = api
::create_framework($params);
134 $exporter = new competency_framework_exporter($result);
135 $record = $exporter->export($output);
140 * Returns description of create_competency_framework() result value.
142 * @return \external_description
144 public static function create_competency_framework_returns() {
145 return competency_framework_exporter
::get_read_structure();
149 * Returns description of read_competency_framework() parameters.
151 * @return \external_function_parameters
153 public static function read_competency_framework_parameters() {
154 $id = new external_value(
156 'Data base record id for the framework',
163 return new external_function_parameters($params);
167 * Read a competency framework by id.
169 * @param int $id The id of the framework.
172 public static function read_competency_framework($id) {
175 $params = self
::validate_parameters(self
::read_competency_framework_parameters(), array(
179 $framework = api
::read_framework($params['id']);
180 self
::validate_context($framework->get_context());
181 $output = $PAGE->get_renderer('core');
182 $exporter = new competency_framework_exporter($framework);
183 $record = $exporter->export($output);
188 * Returns description of read_competency_framework() result value.
190 * @return \external_description
192 public static function read_competency_framework_returns() {
193 return competency_framework_exporter
::get_read_structure();
197 * Returns description of competency_viewed() parameters.
199 * @return \external_function_parameters
201 public static function competency_viewed_parameters() {
202 $id = new external_value(
210 return new external_function_parameters($params);
214 * Log event competency viewed.
216 * @param int $id The competency ID.
219 public static function competency_viewed($id) {
220 $params = self
::validate_parameters(self
::competency_viewed_parameters(), array(
223 return api
::competency_viewed($params['id']);
227 * Returns description of competency_viewed() result value.
229 * @return \external_description
231 public static function competency_viewed_returns() {
232 return new external_value(PARAM_BOOL
, 'True if the event competency viewed was logged');
236 * Returns description of duplicate_competency_framework() parameters.
238 * @return \external_function_parameters
240 public static function duplicate_competency_framework_parameters() {
241 $id = new external_value(
243 'Data base record id for the framework',
250 return new external_function_parameters($params);
254 * Duplicate a competency framework
256 * @param int $id The competency framework id
259 public static function duplicate_competency_framework($id) {
261 $params = self
::validate_parameters(self
::duplicate_competency_framework_parameters(), array(
265 $framework = api
::read_framework($params['id']);
266 self
::validate_context($framework->get_context());
268 $output = $PAGE->get_renderer('core');
269 $framework = api
::duplicate_framework($params['id']);
270 $exporter = new competency_framework_exporter($framework);
271 $record = $exporter->export($output);
276 * Returns description of duplicate_competency_framework() result value.
278 * @return \external_description
280 public static function duplicate_competency_framework_returns() {
281 return competency_framework_exporter
::get_read_structure();
285 * Returns description of delete_competency_framework() parameters.
287 * @return \external_function_parameters
289 public static function delete_competency_framework_parameters() {
290 $id = new external_value(
292 'Data base record id for the framework',
299 return new external_function_parameters($params);
303 * Delete a competency framework
305 * @param int $id The competency framework id
308 public static function delete_competency_framework($id) {
309 $params = self
::validate_parameters(self
::delete_competency_framework_parameters(), array(
313 $framework = api
::read_framework($params['id']);
314 self
::validate_context($framework->get_context());
316 return api
::delete_framework($params['id']);
320 * Returns description of delete_competency_framework() result value.
322 * @return \external_description
324 public static function delete_competency_framework_returns() {
325 return new external_value(PARAM_BOOL
, 'True if the delete was successful');
329 * Returns description of update_competency_framework() parameters.
331 * @return \external_function_parameters
333 public static function update_competency_framework_parameters() {
334 $structure = competency_framework_exporter
::get_update_structure();
335 $params = array('competencyframework' => $structure);
336 return new external_function_parameters($params);
340 * Update an existing competency framework
342 * @param array $competencyframework An array with all the fields for a competency framework.
345 public static function update_competency_framework($competencyframework) {
347 $params = self
::validate_parameters(self
::update_competency_framework_parameters(), array(
348 'competencyframework' => $competencyframework
350 $params = $params['competencyframework'];
352 $framework = api
::read_framework($params['id']);
353 self
::validate_context($framework->get_context());
355 $params = (object) $params;
357 return api
::update_framework($params);
361 * Returns description of update_competency_framework() result value.
363 * @return \external_description
365 public static function update_competency_framework_returns() {
366 return new external_value(PARAM_BOOL
, 'True if the update was successful');
370 * Returns description of list_competency_frameworks() parameters.
372 * @return \external_function_parameters
374 public static function list_competency_frameworks_parameters() {
375 $sort = new external_value(
377 'Column to sort by.',
381 $order = new external_value(
383 'Sort direction. Should be either ASC or DESC',
387 $skip = new external_value(
389 'Skip this number of records before returning results',
393 $limit = new external_value(
395 'Return this number of records at most.',
399 $includes = new external_value(
401 'What other contextes to fetch the frameworks from. (children, parents, self)',
405 $onlyvisible = new external_value(
407 'Only visible frameworks will be returned if visible true',
411 $query = new external_value(
413 'A query string to filter the results',
423 'context' => self
::get_context_parameters(),
424 'includes' => $includes,
425 'onlyvisible' => $onlyvisible,
428 return new external_function_parameters($params);
432 * List the existing competency frameworks
435 * @param string $order
436 * @param string $skip
438 * @param array $context
439 * @param bool $includes
440 * @param bool $onlyvisible
441 * @param string $query
444 * @throws \required_capability_exception
445 * @throws invalid_parameter_exception
447 public static function list_competency_frameworks($sort, $order, $skip, $limit, $context, $includes, $onlyvisible,
451 $params = self
::validate_parameters(self
::list_competency_frameworks_parameters(), array(
456 'context' => $context,
457 'includes' => $includes,
458 'onlyvisible' => $onlyvisible,
462 $context = self
::get_context_from_params($params['context']);
463 self
::validate_context($context);
464 $output = $PAGE->get_renderer('core');
466 if ($params['order'] !== '' && $params['order'] !== 'ASC' && $params['order'] !== 'DESC') {
467 throw new invalid_parameter_exception('Invalid order param. Must be ASC, DESC or empty.');
470 $results = api
::list_frameworks($params['sort'],
476 $params['onlyvisible'],
479 foreach ($results as $result) {
480 $exporter = new competency_framework_exporter($result);
481 $record = $exporter->export($output);
482 array_push($records, $record);
488 * Returns description of list_competency_frameworks() result value.
490 * @return \external_description
492 public static function list_competency_frameworks_returns() {
493 return new external_multiple_structure(competency_framework_exporter
::get_read_structure());
497 * Returns description of count_competency_frameworks() parameters.
499 * @return \external_function_parameters
501 public static function count_competency_frameworks_parameters() {
502 $includes = new external_value(
504 'What other contextes to fetch the frameworks from. (children, parents, self)',
510 'context' => self
::get_context_parameters(),
511 'includes' => $includes
513 return new external_function_parameters($params);
517 * Count the existing competency frameworks
519 * @param array $context
520 * @param string $includes
523 public static function count_competency_frameworks($context, $includes) {
524 $params = self
::validate_parameters(self
::count_competency_frameworks_parameters(), array(
525 'context' => $context,
526 'includes' => $includes
529 $context = self
::get_context_from_params($params['context']);
530 self
::validate_context($context);
532 return api
::count_frameworks($context, $params['includes']);
536 * Returns description of count_competency_frameworks() result value.
538 * @return \external_description
540 public static function count_competency_frameworks_returns() {
541 return new external_value(PARAM_INT
, 'The number of competency frameworks found.');
545 * Returns description of competency_framework_viewed() parameters.
547 * @return \external_function_parameters
549 public static function competency_framework_viewed_parameters() {
550 $id = new external_value(
552 'The competency framework id',
559 return new external_function_parameters($params);
563 * Log event competency framework viewed.
565 * @param int $id The competency framework ID.
568 public static function competency_framework_viewed($id) {
569 $params = self
::validate_parameters(self
::competency_framework_viewed_parameters(), array(
572 return api
::competency_framework_viewed($params['id']);
577 * Returns description of competency_framework_viewed() result value.
579 * @return \external_description
581 public static function competency_framework_viewed_returns() {
582 return new external_value(PARAM_BOOL
, 'True if the event competency framework was logged');
586 * Returns description of create_competency() parameters.
588 * @return \external_function_parameters
590 public static function create_competency_parameters() {
591 $structure = competency_exporter
::get_create_structure();
592 $params = array('competency' => $structure);
593 return new external_function_parameters($params);
597 * Create a new competency
599 * @param array $competency All the fields for a competency record (including id)
600 * @return array the competency
602 public static function create_competency($competency) {
605 $params = self
::validate_parameters(self
::create_competency_parameters(), array(
606 'competency' => $competency
609 $params = $params['competency'];
610 $framework = api
::read_framework($params['competencyframeworkid']);
611 $context = $framework->get_context();
612 self
::validate_context($context);
613 $output = $PAGE->get_renderer('core');
615 $params = (object) $params;
616 $result = api
::create_competency($params);
617 $exporter = new competency_exporter($result, array('context' => $context));
618 $record = $exporter->export($output);
623 * Returns description of create_competency() result value.
625 * @return \external_description
627 public static function create_competency_returns() {
628 return competency_exporter
::get_read_structure();
632 * Returns description of read_competency() parameters.
634 * @return \external_function_parameters
636 public static function read_competency_parameters() {
637 $id = new external_value(
639 'Data base record id for the competency',
646 return new external_function_parameters($params);
650 * Read a competency by id.
652 * @param int $id The id of the competency
655 public static function read_competency($id) {
658 $params = self
::validate_parameters(self
::read_competency_parameters(), array(
662 $competency = api
::read_competency($params['id']);
663 $context = $competency->get_context();
664 self
::validate_context($context);
665 $output = $PAGE->get_renderer('core');
666 $exporter = new competency_exporter($competency, array('context' => $context));
667 $record = $exporter->export($output);
672 * Returns description of read_competency() result value.
674 * @return \external_description
676 public static function read_competency_returns() {
677 return competency_exporter
::get_read_structure();
681 * Returns description of delete_competency() parameters.
683 * @return \external_function_parameters
685 public static function delete_competency_parameters() {
686 $id = new external_value(
688 'Data base record id for the competency',
695 return new external_function_parameters($params);
699 * Delete a competency
701 * @param int $id The competency id
704 public static function delete_competency($id) {
705 $params = self
::validate_parameters(self
::delete_competency_parameters(), array(
709 $competency = api
::read_competency($params['id']);
710 $context = $competency->get_context();
711 self
::validate_context($context);
713 return api
::delete_competency($params['id']);
717 * Returns description of delete_competency() result value.
719 * @return \external_description
721 public static function delete_competency_returns() {
722 return new external_value(PARAM_BOOL
, 'True if the delete was successful');
726 * Returns description of update_competency() parameters.
728 * @return \external_function_parameters
730 public static function update_competency_parameters() {
731 $structure = competency_exporter
::get_update_structure();
732 $params = array('competency' => $structure);
733 return new external_function_parameters($params);
737 * Update an existing competency
739 * @param array $competency The array of competency fields (id is required).
742 public static function update_competency($competency) {
743 $params = self
::validate_parameters(self
::update_competency_parameters(), array(
744 'competency' => $competency
746 $params = $params['competency'];
748 $competency = api
::read_competency($params['id']);
749 self
::validate_context($competency->get_context());
751 $params = (object) $params;
753 return api
::update_competency($params);
757 * Returns description of update_competency_framework() result value.
759 * @return \external_description
761 public static function update_competency_returns() {
762 return new external_value(PARAM_BOOL
, 'True if the update was successful');
766 * Returns description of list_competencies() parameters.
768 * @return \external_function_parameters
770 public static function list_competencies_parameters() {
771 $filters = new external_multiple_structure(new external_single_structure(
773 'column' => new external_value(PARAM_ALPHANUMEXT
, 'Column name to filter by'),
774 'value' => new external_value(PARAM_TEXT
, 'Value to filter by. Must be exact match')
777 $sort = new external_value(
779 'Column to sort by.',
783 $order = new external_value(
785 'Sort direction. Should be either ASC or DESC',
789 $skip = new external_value(
791 'Skip this number of records before returning results',
795 $limit = new external_value(
797 'Return this number of records at most.',
803 'filters' => $filters,
809 return new external_function_parameters($params);
813 * List the existing competency.
815 * @param string $filters
817 * @param string $order
818 * @param string $skip
822 * @throws \required_capability_exception
823 * @throws invalid_parameter_exception
825 public static function list_competencies($filters, $sort, $order, $skip, $limit) {
828 $params = self
::validate_parameters(self
::list_competencies_parameters(), array(
829 'filters' => $filters,
836 if ($params['order'] !== '' && $params['order'] !== 'ASC' && $params['order'] !== 'DESC') {
837 throw new invalid_parameter_exception('Invalid order param. Must be ASC, DESC or empty.');
840 $safefilters = array();
841 $validcolumns = array('id', 'shortname', 'description', 'sortorder', 'idnumber',
842 'parentid', 'competencyframeworkid');
843 foreach ($params['filters'] as $filter) {
844 if (!in_array($filter['column'], $validcolumns)) {
845 throw new invalid_parameter_exception('Filter column was invalid');
847 $safefilters[$filter['column']] = $filter['value'];
851 if (isset($safefilters['competencyframeworkid'])) {
852 $framework = api
::read_framework($safefilters['competencyframeworkid']);
853 $context = $framework->get_context();
855 $context = context_system
::instance();
858 self
::validate_context($context);
859 $output = $PAGE->get_renderer('core');
861 $results = api
::list_competencies(
870 foreach ($results as $result) {
871 $exporter = new competency_exporter($result, array('context' => $context));
872 $record = $exporter->export($output);
873 array_push($records, $record);
879 * Returns description of list_competencies() result value.
881 * @return \external_description
883 public static function list_competencies_returns() {
884 return new external_multiple_structure(competency_exporter
::get_read_structure());
888 * Returns description of search_competencies() parameters.
890 * @return \external_function_parameters
892 public static function search_competencies_parameters() {
893 $searchtext = new external_value(
895 'Text to search for',
898 $frameworkid = new external_value(
900 'Competency framework id',
905 'searchtext' => $searchtext,
906 'competencyframeworkid' => $frameworkid
908 return new external_function_parameters($params);
912 * List the existing competency frameworks
914 * @param string $searchtext Text to search.
915 * @param int $competencyframeworkid Framework id.
919 public static function search_competencies($searchtext, $competencyframeworkid) {
922 $params = self
::validate_parameters(self
::search_competencies_parameters(), array(
923 'searchtext' => $searchtext,
924 'competencyframeworkid' => $competencyframeworkid
927 $framework = api
::read_framework($params['competencyframeworkid']);
928 $context = $framework->get_context();
929 self
::validate_context($context);
930 $output = $PAGE->get_renderer('core');
932 $results = api
::search_competencies($params['searchtext'], $params['competencyframeworkid']);
934 foreach ($results as $result) {
935 $exporter = new competency_exporter($result, array('context' => $context));
936 $record = $exporter->export($output);
938 array_push($records, $record);
945 * Returns description of search_competencies() result value.
947 * @return \external_description
949 public static function search_competencies_returns() {
950 return new external_multiple_structure(competency_exporter
::get_read_structure());
954 * Returns description of count_competencies() parameters.
956 * @return \external_function_parameters
958 public static function count_competencies_parameters() {
959 $filters = new external_multiple_structure(new external_single_structure(
961 'column' => new external_value(PARAM_ALPHANUMEXT
, 'Column name to filter by'),
962 'value' => new external_value(PARAM_TEXT
, 'Value to filter by. Must be exact match')
967 'filters' => $filters,
969 return new external_function_parameters($params);
973 * Count the existing competency frameworks.
975 * @param string $filters Filters to use.
978 public static function count_competencies($filters) {
979 $params = self
::validate_parameters(self
::count_competencies_parameters(), array(
980 'filters' => $filters
983 $safefilters = array();
984 $validcolumns = array('id', 'shortname', 'description', 'sortorder', 'idnumber', 'parentid', 'competencyframeworkid');
985 foreach ($params['filters'] as $filter) {
986 if (!in_array($filter['column'], $validcolumns)) {
987 throw new invalid_parameter_exception('Filter column was invalid');
989 $safefilters[$filter['column']] = $filter['value'];
993 if (isset($safefilters['competencyframeworkid'])) {
994 $framework = api
::read_framework($safefilters['competencyframeworkid']);
995 $context = $framework->get_context();
997 $context = context_system
::instance();
1000 self
::validate_context($context);
1002 return api
::count_competencies($safefilters);
1006 * Returns description of count_competencies() result value.
1008 * @return \external_description
1010 public static function count_competencies_returns() {
1011 return new external_value(PARAM_INT
, 'The number of competencies found.');
1015 * Returns description of set_parent_competency() parameters.
1017 * @return \external_function_parameters
1019 public static function set_parent_competency_parameters() {
1020 $competencyid = new external_value(
1022 'The competency id',
1025 $parentid = new external_value(
1027 'The new competency parent id',
1031 'competencyid' => $competencyid,
1032 'parentid' => $parentid
1034 return new external_function_parameters($params);
1038 * Move the competency to a new parent.
1040 * @param int $competencyid Competency id.
1041 * @param int $parentid Parent id.
1045 public static function set_parent_competency($competencyid, $parentid) {
1046 $params = self
::validate_parameters(self
::set_parent_competency_parameters(), array(
1047 'competencyid' => $competencyid,
1048 'parentid' => $parentid
1051 $competency = api
::read_competency($params['competencyid']);
1052 self
::validate_context($competency->get_context());
1054 return api
::set_parent_competency($params['competencyid'], $params['parentid']);
1058 * Returns description of set_parent_competency() result value.
1060 * @return \external_description
1062 public static function set_parent_competency_returns() {
1063 return new external_value(PARAM_BOOL
, 'True if the update was successful');
1067 * Returns description of move_up_competency() parameters.
1069 * @return \external_function_parameters
1071 public static function move_up_competency_parameters() {
1072 $competencyid = new external_value(
1074 'The competency id',
1078 'id' => $competencyid,
1080 return new external_function_parameters($params);
1084 * Change the sort order of a competency.
1086 * @param int $competencyid Competency id.
1089 public static function move_up_competency($competencyid) {
1090 $params = self
::validate_parameters(self
::move_up_competency_parameters(), array(
1091 'id' => $competencyid,
1094 $competency = api
::read_competency($params['id']);
1095 self
::validate_context($competency->get_context());
1097 return api
::move_up_competency($params['id']);
1101 * Returns description of move_up_competency() result value.
1103 * @return \external_description
1105 public static function move_up_competency_returns() {
1106 return new external_value(PARAM_BOOL
, 'True if the update was successful');
1110 * Returns description of move_down_competency() parameters.
1112 * @return \external_function_parameters
1114 public static function move_down_competency_parameters() {
1115 $competencyid = new external_value(
1117 'The competency id',
1121 'id' => $competencyid,
1123 return new external_function_parameters($params);
1127 * Change the sort order of a competency.
1129 * @param int $competencyid Competency id.
1132 public static function move_down_competency($competencyid) {
1133 $params = self
::validate_parameters(self
::move_down_competency_parameters(), array(
1134 'id' => $competencyid,
1137 $competency = api
::read_competency($params['id']);
1138 self
::validate_context($competency->get_context());
1140 return api
::move_down_competency($params['id']);
1144 * Returns description of move_down_competency() result value.
1146 * @return \external_description
1148 public static function move_down_competency_returns() {
1149 return new external_value(PARAM_BOOL
, 'True if the update was successful');
1153 * Returns description of count_courses_using_competency() parameters.
1155 * @return \external_function_parameters
1157 public static function count_courses_using_competency_parameters() {
1158 $competencyid = new external_value(
1160 'The competency id',
1164 'id' => $competencyid,
1166 return new external_function_parameters($params);
1170 * Count the courses (visible to this user) that use this competency.
1172 * @param int $competencyid Competency id.
1175 public static function count_courses_using_competency($competencyid) {
1176 $params = self
::validate_parameters(self
::count_courses_using_competency_parameters(), array(
1177 'id' => $competencyid,
1180 $competency = api
::read_competency($params['id']);
1181 self
::validate_context($competency->get_context());
1183 return api
::count_courses_using_competency($params['id']);
1187 * Returns description of count_courses_using_competency() result value.
1189 * @return \external_description
1191 public static function count_courses_using_competency_returns() {
1192 return new external_value(PARAM_INT
, 'The number of courses using this competency');
1196 * Returns description of count_competencies_in_course() parameters.
1198 * @return \external_function_parameters
1200 public static function count_competencies_in_course_parameters() {
1201 $courseid = new external_value(
1209 return new external_function_parameters($params);
1213 * Count the competencies (visible to this user) in this course.
1215 * @param int $courseid The course id to check.
1218 public static function count_competencies_in_course($courseid) {
1219 $params = self
::validate_parameters(self
::count_competencies_in_course_parameters(), array(
1223 self
::validate_context(context_course
::instance($params['id']));
1225 return api
::count_competencies_in_course($params['id']);
1229 * Returns description of count_competencies_in_course() result value.
1231 * @return \external_description
1233 public static function count_competencies_in_course_returns() {
1234 return new external_value(PARAM_INT
, 'The number of competencies in this course.');
1238 * Returns description of list_course_module_competencies() parameters.
1240 * @return \external_function_parameters
1242 public static function list_course_module_competencies_parameters() {
1243 $cmid = new external_value(
1245 'The course module id',
1251 return new external_function_parameters($params);
1255 * List the course modules using this competency (visible to this user) in this course.
1257 * @param int $cmid The course module id to check.
1260 public static function list_course_module_competencies($cmid) {
1263 $params = self
::validate_parameters(self
::list_course_module_competencies_parameters(), array(
1267 $context = context_module
::instance($params['cmid']);
1268 self
::validate_context($context);
1270 $output = $PAGE->get_renderer('core');
1272 $apiresult = api
::list_course_module_competencies($params['cmid']);
1275 foreach ($apiresult as $cmrecord) {
1276 $one = new \
stdClass();
1277 $exporter = new competency_exporter($cmrecord['competency']);
1278 $one->competency
= $exporter->export($output);
1279 $exporter = new course_module_competency_exporter($cmrecord['coursemodulecompetency']);
1280 $one->coursemodulecompetency
= $exporter->export($output);
1282 $result[] = (array) $one;
1289 * Returns description of list_course_module_competencies() result value.
1291 * @return \external_description
1293 public static function list_course_module_competencies_returns() {
1294 return new external_multiple_structure(
1295 new external_single_structure(array(
1296 'competency' => competency_exporter
::get_read_structure(),
1297 'coursemodulecompetency' => course_module_competency_exporter
::get_read_structure()
1303 * Returns description of list_course_competencies() parameters.
1305 * @return \external_function_parameters
1307 public static function list_course_competencies_parameters() {
1308 $courseid = new external_value(
1316 return new external_function_parameters($params);
1320 * List the competencies (visible to this user) in this course.
1322 * @param int $courseid The course id to check.
1325 public static function list_course_competencies($courseid) {
1328 $params = self
::validate_parameters(self
::list_course_competencies_parameters(), array(
1332 $coursecontext = context_course
::instance($params['id']);
1333 self
::validate_context($coursecontext);
1335 $output = $PAGE->get_renderer('core');
1337 $competencies = api
::list_course_competencies($params['id']);
1340 $contextcache = array();
1341 $helper = new performance_helper();
1342 foreach ($competencies as $competency) {
1343 $context = $helper->get_context_from_competency($competency['competency']);
1344 $exporter = new competency_exporter($competency['competency'], array('context' => $context));
1345 $competencyrecord = $exporter->export($output);
1346 $exporter = new course_competency_exporter($competency['coursecompetency']);
1347 $coursecompetencyrecord = $exporter->export($output);
1350 'competency' => $competencyrecord,
1351 'coursecompetency' => $coursecompetencyrecord
1359 * Returns description of list_course_competencies() result value.
1361 * @return \external_description
1363 public static function list_course_competencies_returns() {
1364 return new external_multiple_structure(
1365 new external_single_structure(array(
1366 'competency' => competency_exporter
::get_read_structure(),
1367 'coursecompetency' => course_competency_exporter
::get_read_structure()
1373 * Returns description of add_competency_to_course() parameters.
1375 * @return \external_function_parameters
1377 public static function add_competency_to_course_parameters() {
1378 $courseid = new external_value(
1383 $competencyid = new external_value(
1385 'The competency id',
1389 'courseid' => $courseid,
1390 'competencyid' => $competencyid,
1392 return new external_function_parameters($params);
1396 * Count the competencies (visible to this user) in this course.
1398 * @param int $courseid The course id to check.
1399 * @param int $competencyid Competency id.
1402 public static function add_competency_to_course($courseid, $competencyid) {
1403 $params = self
::validate_parameters(self
::add_competency_to_course_parameters(), array(
1404 'courseid' => $courseid,
1405 'competencyid' => $competencyid,
1407 self
::validate_context(context_course
::instance($params['courseid']));
1408 return api
::add_competency_to_course($params['courseid'], $params['competencyid']);
1412 * Returns description of add_competency_to_course() result value.
1414 * @return \external_description
1416 public static function add_competency_to_course_returns() {
1417 return new external_value(PARAM_BOOL
, 'True if successful.');
1421 * Returns description of remove_competency_from_course() parameters.
1423 * @return \external_function_parameters
1425 public static function remove_competency_from_course_parameters() {
1426 $courseid = new external_value(
1431 $competencyid = new external_value(
1433 'The competency id',
1437 'courseid' => $courseid,
1438 'competencyid' => $competencyid,
1440 return new external_function_parameters($params);
1444 * Count the competencies (visible to this user) in this course.
1446 * @param int $courseid The course id to check.
1447 * @param int $competencyid Competency id.
1450 public static function remove_competency_from_course($courseid, $competencyid) {
1451 $params = self
::validate_parameters(self
::remove_competency_from_course_parameters(), array(
1452 'courseid' => $courseid,
1453 'competencyid' => $competencyid,
1455 self
::validate_context(context_course
::instance($params['courseid']));
1456 return api
::remove_competency_from_course($params['courseid'], $params['competencyid']);
1460 * Returns description of remove_competency_from_course() result value.
1462 * @return \external_description
1464 public static function remove_competency_from_course_returns() {
1465 return new external_value(PARAM_BOOL
, 'True if successful.');
1469 * Returns description of reorder_course_competency() parameters.
1471 * @return \external_function_parameters
1473 public static function reorder_course_competency_parameters() {
1474 $courseid = new external_value(
1479 $competencyidfrom = new external_value(
1481 'The competency id we are moving',
1484 $competencyidto = new external_value(
1486 'The competency id we are moving to',
1490 'courseid' => $courseid,
1491 'competencyidfrom' => $competencyidfrom,
1492 'competencyidto' => $competencyidto,
1494 return new external_function_parameters($params);
1498 * Change the order of course competencies.
1500 * @param int $courseid The course id
1501 * @param int $competencyidfrom The competency to move.
1502 * @param int $competencyidto The competency to move to.
1505 public static function reorder_course_competency($courseid, $competencyidfrom, $competencyidto) {
1506 $params = self
::validate_parameters(self
::reorder_course_competency_parameters(), array(
1507 'courseid' => $courseid,
1508 'competencyidfrom' => $competencyidfrom,
1509 'competencyidto' => $competencyidto,
1511 self
::validate_context(context_course
::instance($params['courseid']));
1512 return api
::reorder_course_competency($params['courseid'], $params['competencyidfrom'], $params['competencyidto']);
1516 * Returns description of reorder_course_competency() result value.
1518 * @return \external_description
1520 public static function reorder_course_competency_returns() {
1521 return new external_value(PARAM_BOOL
, 'True if successful.');
1525 * Returns description of reorder_template_competency() parameters.
1527 * @return \external_function_parameters
1529 public static function reorder_template_competency_parameters() {
1530 $templateid = new external_value(
1535 $competencyidfrom = new external_value(
1537 'The competency id we are moving',
1540 $competencyidto = new external_value(
1542 'The competency id we are moving to',
1546 'templateid' => $templateid,
1547 'competencyidfrom' => $competencyidfrom,
1548 'competencyidto' => $competencyidto,
1550 return new external_function_parameters($params);
1554 * Change the order of template competencies.
1556 * @param int $templateid The template id
1557 * @param int $competencyidfrom The competency to move.
1558 * @param int $competencyidto The competency to move to.
1561 public static function reorder_template_competency($templateid, $competencyidfrom, $competencyidto) {
1562 $params = self
::validate_parameters(self
::reorder_template_competency_parameters(), array(
1563 'templateid' => $templateid,
1564 'competencyidfrom' => $competencyidfrom,
1565 'competencyidto' => $competencyidto,
1568 $template = api
::read_template($params['templateid']);
1569 self
::validate_context($template->get_context());
1571 return api
::reorder_template_competency($params['templateid'], $params['competencyidfrom'], $params['competencyidto']);
1575 * Returns description of reorder_template_competency() result value.
1577 * @return \external_description
1579 public static function reorder_template_competency_returns() {
1580 return new external_value(PARAM_BOOL
, 'True if successful.');
1584 * Returns description of create_template() parameters.
1586 * @return \external_function_parameters
1588 public static function create_template_parameters() {
1589 $structure = template_exporter
::get_create_structure();
1590 $params = array('template' => $structure);
1591 return new external_function_parameters($params);
1595 * Create a new learning plan template
1597 * @param array $template The list of fields for the template.
1598 * @return \stdClass Record of new template.
1600 public static function create_template($template) {
1603 $params = self
::validate_parameters(self
::create_template_parameters(), array('template' => $template));
1604 $params = $params['template'];
1605 $context = self
::get_context_from_params($params);
1606 self
::validate_context($context);
1607 $output = $PAGE->get_renderer('core');
1609 unset($params['contextlevel']);
1610 unset($params['instanceid']);
1611 $params = (object) $params;
1612 $params->contextid
= $context->id
;
1614 $result = api
::create_template($params);
1615 $exporter = new template_exporter($result);
1616 $record = $exporter->export($output);
1621 * Returns description of create_template() result value.
1623 * @return \external_description
1625 public static function create_template_returns() {
1626 return template_exporter
::get_read_structure();
1630 * Returns description of read_template() parameters.
1632 * @return \external_function_parameters
1634 public static function read_template_parameters() {
1635 $id = new external_value(
1637 'Data base record id for the template',
1644 return new external_function_parameters($params);
1648 * Read a learning plan template by id.
1650 * @param int $id The id of the template.
1653 public static function read_template($id) {
1656 $params = self
::validate_parameters(self
::read_template_parameters(), array('id' => $id));
1657 $template = api
::read_template($params['id']);
1658 self
::validate_context($template->get_context());
1659 $output = $PAGE->get_renderer('core');
1661 $exporter = new template_exporter($template);
1662 $record = $exporter->export($output);
1667 * Returns description of read_template() result value.
1669 * @return \external_description
1671 public static function read_template_returns() {
1672 return template_exporter
::get_read_structure();
1676 * Returns description of delete_template() parameters.
1678 * @return \external_function_parameters
1680 public static function delete_template_parameters() {
1681 $id = new external_value(
1683 'Data base record id for the template',
1687 $deleteplans = new external_value(
1689 'Boolean to indicate if plans must be deleted',
1695 'deleteplans' => $deleteplans
1697 return new external_function_parameters($params);
1701 * Delete a learning plan template
1703 * @param int $id The learning plan template id
1704 * @param boolean $deleteplans True to delete the plans associated to template or false to unlink them
1707 public static function delete_template($id, $deleteplans = true) {
1708 $params = self
::validate_parameters(self
::delete_template_parameters(), array(
1710 'deleteplans' => $deleteplans,
1713 $template = api
::read_template($params['id']);
1714 self
::validate_context($template->get_context());
1716 return api
::delete_template($params['id'], $params['deleteplans']);
1720 * Returns description of delete_template() result value.
1722 * @return \external_description
1724 public static function delete_template_returns() {
1725 return new external_value(PARAM_BOOL
, 'True if the delete was successful');
1729 * Returns description of update_template() parameters.
1731 * @return \external_function_parameters
1733 public static function update_template_parameters() {
1734 $structure = template_exporter
::get_update_structure();
1735 $params = array('template' => $structure);
1736 return new external_function_parameters($params);
1740 * Update an existing learning plan template
1742 * @param array $template The list of fields for the template.
1745 public static function update_template($template) {
1747 $params = self
::validate_parameters(self
::update_template_parameters(), array('template' => $template));
1748 $params = $params['template'];
1749 $template = api
::read_template($params['id']);
1750 self
::validate_context($template->get_context());
1752 $params = (object) $params;
1754 return api
::update_template($params);
1758 * Returns description of update_template() result value.
1760 * @return \external_description
1762 public static function update_template_returns() {
1763 return new external_value(PARAM_BOOL
, 'True if the update was successful');
1767 * Returns description of duplicate_template() parameters.
1769 * @return \external_function_parameters
1771 public static function duplicate_template_parameters() {
1772 $templateid = new external_value(
1781 return new external_function_parameters($params);
1785 * Duplicate a learning plan template.
1787 * @param int $id the id of the learning plan template to duplicate
1788 * @return boolean Record of new template.
1790 public static function duplicate_template($id) {
1793 $params = self
::validate_parameters(self
::duplicate_template_parameters(), array('id' => $id));
1795 $template = api
::read_template($params['id']);
1796 self
::validate_context($template->get_context());
1797 $output = $PAGE->get_renderer('core');
1799 $result = api
::duplicate_template($params['id']);
1800 $exporter = new template_exporter($result);
1801 return $exporter->export($output);
1805 * Returns description of duplicate_template() result value.
1807 * @return \external_description
1809 public static function duplicate_template_returns() {
1810 return template_exporter
::get_read_structure();
1814 * Returns description of list_templates() parameters.
1816 * @return \external_function_parameters
1818 public static function list_templates_parameters() {
1819 $sort = new external_value(
1821 'Column to sort by.',
1825 $order = new external_value(
1827 'Sort direction. Should be either ASC or DESC',
1831 $skip = new external_value(
1833 'Skip this number of records before returning results',
1837 $limit = new external_value(
1839 'Return this number of records at most.',
1843 $includes = new external_value(
1845 'What other contexts to fetch the templates from. (children, parents, self)',
1849 $onlyvisible = new external_value(
1851 'If should list only visible templates',
1861 'context' => self
::get_context_parameters(),
1862 'includes' => $includes,
1863 'onlyvisible' => $onlyvisible
1865 return new external_function_parameters($params);
1869 * List the existing learning plan templates
1871 * @param string $sort Field to sort by.
1872 * @param string $order Sort order.
1873 * @param int $skip Limitstart.
1874 * @param int $limit Number of rows to return.
1875 * @param array $context
1876 * @param bool $includes
1877 * @param bool $onlyvisible
1881 public static function list_templates($sort, $order, $skip, $limit, $context, $includes, $onlyvisible) {
1884 $params = self
::validate_parameters(self
::list_templates_parameters(), array(
1889 'context' => $context,
1890 'includes' => $includes,
1891 'onlyvisible' => $onlyvisible
1894 $context = self
::get_context_from_params($params['context']);
1895 self
::validate_context($context);
1896 $output = $PAGE->get_renderer('core');
1898 if ($params['order'] !== '' && $params['order'] !== 'ASC' && $params['order'] !== 'DESC') {
1899 throw new invalid_parameter_exception('Invalid order param. Must be ASC, DESC or empty.');
1902 $results = api
::list_templates($params['sort'],
1907 $params['includes'],
1908 $params['onlyvisible']);
1910 foreach ($results as $result) {
1911 $exporter = new template_exporter($result);
1912 $record = $exporter->export($output);
1913 array_push($records, $record);
1919 * Returns description of list_templates() result value.
1921 * @return \external_description
1923 public static function list_templates_returns() {
1924 return new external_multiple_structure(template_exporter
::get_read_structure());
1928 * Returns description of count_templates() parameters.
1930 * @return \external_function_parameters
1932 public static function count_templates_parameters() {
1933 $includes = new external_value(
1935 'What other contextes to fetch the frameworks from. (children, parents, self)',
1941 'context' => self
::get_context_parameters(),
1942 'includes' => $includes
1944 return new external_function_parameters($params);
1948 * Count the existing learning plan templates
1950 * @param array $context
1951 * @param string $includes
1954 public static function count_templates($context, $includes) {
1955 $params = self
::validate_parameters(self
::count_templates_parameters(), array(
1956 'context' => $context,
1957 'includes' => $includes
1959 $context = self
::get_context_from_params($params['context']);
1960 self
::validate_context($context);
1962 return api
::count_templates($context, $includes);
1966 * Returns description of count_templates() result value.
1968 * @return \external_description
1970 public static function count_templates_returns() {
1971 return new external_value(PARAM_INT
, 'The number of learning plan templates found.');
1975 * Returns description of count_templates_using_competency() parameters.
1977 * @return \external_function_parameters
1979 public static function count_templates_using_competency_parameters() {
1980 $competencyid = new external_value(
1982 'The competency id',
1986 'id' => $competencyid,
1988 return new external_function_parameters($params);
1992 * Count the learning plan templates (visible to this user) that use this competency.
1994 * @param int $competencyid Competency id.
1997 public static function count_templates_using_competency($competencyid) {
1998 $params = self
::validate_parameters(self
::count_templates_using_competency_parameters(), array(
1999 'id' => $competencyid,
2002 $competency = api
::read_competency($params['id']);
2003 self
::validate_context($competency->get_context());
2005 return api
::count_templates_using_competency($params['id']);
2009 * Returns description of count_templates_using_competency() result value.
2011 * @return \external_description
2013 public static function count_templates_using_competency_returns() {
2014 return new external_value(PARAM_INT
, 'The number of learning plan templates using this competency');
2018 * Returns description of list_templates_using_competency() parameters.
2020 * @return \external_function_parameters
2022 public static function list_templates_using_competency_parameters() {
2023 $competencyid = new external_value(
2025 'The competency id',
2029 'id' => $competencyid,
2031 return new external_function_parameters($params);
2035 * List the learning plan templates (visible to this user) that use this competency.
2037 * @param int $competencyid Competency id.
2040 public static function list_templates_using_competency($competencyid) {
2043 $params = self
::validate_parameters(self
::list_templates_using_competency_parameters(), array(
2044 'id' => $competencyid,
2047 $competency = api
::read_competency($params['id']);
2048 self
::validate_context($competency->get_context());
2049 $output = $PAGE->get_renderer('core');
2051 $templates = api
::list_templates_using_competency($params['id']);
2054 foreach ($templates as $template) {
2055 $exporter = new template_exporter($template);
2056 $record = $exporter->export($output);
2057 $records[] = $record;
2064 * Returns description of list_templates_using_competency() result value.
2066 * @return \external_description
2068 public static function list_templates_using_competency_returns() {
2069 return new external_multiple_structure(template_exporter
::get_read_structure());
2073 * Returns description of count_competencies_in_template() parameters.
2075 * @return \external_function_parameters
2077 public static function count_competencies_in_template_parameters() {
2078 $templateid = new external_value(
2084 'id' => $templateid,
2086 return new external_function_parameters($params);
2090 * Count the competencies (visible to this user) in this learning plan template.
2092 * @param int $templateid The template id to check
2095 public static function count_competencies_in_template($templateid) {
2096 $params = self
::validate_parameters(self
::count_competencies_in_template_parameters(), array(
2097 'id' => $templateid,
2099 $template = api
::read_template($params['id']);
2100 self
::validate_context($template->get_context());
2102 return api
::count_competencies_in_template($params['id']);
2106 * Returns description of count_competencies_in_template() result value.
2108 * @return \external_description
2110 public static function count_competencies_in_template_returns() {
2111 return new external_value(PARAM_INT
, 'The number of competencies in this learning plan template.');
2115 * Returns description of list_competencies_in_template() parameters.
2117 * @return \external_function_parameters
2119 public static function list_competencies_in_template_parameters() {
2120 $templateid = new external_value(
2126 'id' => $templateid,
2128 return new external_function_parameters($params);
2132 * List the competencies (visible to this user) in this learning plan template.
2134 * @param int $templateid Template id.
2137 public static function list_competencies_in_template($templateid) {
2140 $params = self
::validate_parameters(self
::list_competencies_in_template_parameters(), array(
2141 'id' => $templateid,
2144 $template = api
::read_template($params['id']);
2145 self
::validate_context($template->get_context());
2146 $output = $PAGE->get_renderer('core');
2148 $competencies = api
::list_competencies_in_template($params['id']);
2151 $helper = new performance_helper();
2152 foreach ($competencies as $competency) {
2153 $context = $helper->get_context_from_competency($competency);
2154 $exporter = new competency_exporter($competency, array('context' => $context));
2155 $record = $exporter->export($output);
2156 array_push($results, $record);
2162 * Returns description of list_competencies_in_template() result value.
2164 * @return \external_description
2166 public static function list_competencies_in_template_returns() {
2167 return new external_multiple_structure(competency_exporter
::get_read_structure());
2171 * Returns description of add_competency_to_template() parameters.
2173 * @return \external_function_parameters
2175 public static function add_competency_to_template_parameters() {
2176 $templateid = new external_value(
2181 $competencyid = new external_value(
2183 'The competency id',
2187 'templateid' => $templateid,
2188 'competencyid' => $competencyid,
2190 return new external_function_parameters($params);
2194 * Count the competencies (visible to this user) in this template.
2196 * @param int $templateid Template id.
2197 * @param int $competencyid Competency id.
2200 public static function add_competency_to_template($templateid, $competencyid) {
2202 $params = self
::validate_parameters(self
::add_competency_to_template_parameters(), array(
2203 'templateid' => $templateid,
2204 'competencyid' => $competencyid,
2207 $template = api
::read_template($params['templateid']);
2208 self
::validate_context($template->get_context());
2210 return api
::add_competency_to_template($params['templateid'], $params['competencyid']);
2214 * Returns description of add_competency_to_template() result value.
2216 * @return \external_description
2218 public static function add_competency_to_template_returns() {
2219 return new external_value(PARAM_BOOL
, 'True if successful.');
2223 * Returns description of add_competency_to_plan() parameters.
2225 * @return \external_function_parameters
2227 public static function add_competency_to_plan_parameters() {
2228 $planid = new external_value(
2233 $competencyid = new external_value(
2235 'The competency id',
2239 'planid' => $planid,
2240 'competencyid' => $competencyid,
2242 return new external_function_parameters($params);
2246 * add competency to a learning plan.
2248 * @param int $planid Plan id.
2249 * @param int $competencyid Competency id.
2252 public static function add_competency_to_plan($planid, $competencyid) {
2253 $params = self
::validate_parameters(self
::add_competency_to_plan_parameters(), array(
2254 'planid' => $planid,
2255 'competencyid' => $competencyid,
2258 $plan = api
::read_plan($params['planid']);
2259 self
::validate_context($plan->get_context());
2261 return api
::add_competency_to_plan($params['planid'], $params['competencyid']);
2265 * Returns description of add_competency_to_plan() result value.
2267 * @return \external_description
2269 public static function add_competency_to_plan_returns() {
2270 return new external_value(PARAM_BOOL
, 'True if successful.');
2274 * Returns description of remove_competency_from_plan() parameters.
2276 * @return \external_function_parameters
2278 public static function remove_competency_from_plan_parameters() {
2279 $planid = new external_value(
2284 $competencyid = new external_value(
2286 'The competency id',
2290 'planid' => $planid,
2291 'competencyid' => $competencyid,
2293 return new external_function_parameters($params);
2297 * Remove a competency from plan.
2299 * @param int $planid Plan id.
2300 * @param int $competencyid Competency id.
2303 public static function remove_competency_from_plan($planid, $competencyid) {
2304 $params = self
::validate_parameters(self
::remove_competency_from_plan_parameters(), array(
2305 'planid' => $planid,
2306 'competencyid' => $competencyid,
2308 $plan = api
::read_plan($params['planid']);
2309 self
::validate_context($plan->get_context());
2311 return api
::remove_competency_from_plan($params['planid'], $params['competencyid']);
2315 * Returns description of remove_competency_from_plan() result value.
2317 * @return \external_description
2319 public static function remove_competency_from_plan_returns() {
2320 return new external_value(PARAM_BOOL
, 'True if successful.');
2324 * Returns description of remove_competency_from_template() parameters.
2326 * @return \external_function_parameters
2328 public static function remove_competency_from_template_parameters() {
2329 $templateid = new external_value(
2334 $competencyid = new external_value(
2336 'The competency id',
2340 'templateid' => $templateid,
2341 'competencyid' => $competencyid,
2343 return new external_function_parameters($params);
2347 * Returns description of reorder_plan_competency() parameters.
2349 * @return \external_function_parameters
2351 public static function reorder_plan_competency_parameters() {
2352 $planid = new external_value(
2357 $competencyidfrom = new external_value(
2359 'The competency id we are moving',
2362 $competencyidto = new external_value(
2364 'The competency id we are moving to',
2368 'planid' => $planid,
2369 'competencyidfrom' => $competencyidfrom,
2370 'competencyidto' => $competencyidto,
2372 return new external_function_parameters($params);
2376 * Change the order of plan competencies.
2378 * @param int $planid The plan id
2379 * @param int $competencyidfrom The competency to move.
2380 * @param int $competencyidto The competency to move to.
2383 public static function reorder_plan_competency($planid, $competencyidfrom, $competencyidto) {
2384 $params = self
::validate_parameters(self
::reorder_plan_competency_parameters(), array(
2385 'planid' => $planid,
2386 'competencyidfrom' => $competencyidfrom,
2387 'competencyidto' => $competencyidto,
2390 $plan = api
::read_plan($params['planid']);
2391 self
::validate_context($plan->get_context());
2393 return api
::reorder_plan_competency($params['planid'], $params['competencyidfrom'], $params['competencyidto']);
2397 * Returns description of reorder_plan_competency() result value.
2399 * @return \external_description
2401 public static function reorder_plan_competency_returns() {
2402 return new external_value(PARAM_BOOL
, 'True if successful.');
2406 * Returns description of external function parameters.
2408 * @return \external_function_parameters
2410 public static function user_competency_cancel_review_request_parameters() {
2411 return new external_function_parameters(array(
2412 'userid' => new external_value(PARAM_INT
, 'The user ID'),
2413 'competencyid' => new external_value(PARAM_INT
, 'The competency ID'),
2418 * External function user_competency_cancel_review_request.
2420 * @param int $userid The user ID.
2421 * @param int $competencyid The competency ID.
2424 public static function user_competency_cancel_review_request($userid, $competencyid) {
2425 $params = self
::validate_parameters(self
::user_competency_cancel_review_request_parameters(), array(
2426 'userid' => $userid,
2427 'competencyid' => $competencyid
2430 $context = context_user
::instance($params['userid']);
2431 self
::validate_context($context);
2433 return api
::user_competency_cancel_review_request($userid, $competencyid);
2437 * Returns description of external function result value.
2439 * @return \external_function_parameters
2441 public static function user_competency_cancel_review_request_returns() {
2442 return new external_value(PARAM_BOOL
, 'The success');
2446 * Returns description of external function parameters.
2448 * @return \external_function_parameters
2450 public static function user_competency_request_review_parameters() {
2451 return new external_function_parameters(array(
2452 'userid' => new external_value(PARAM_INT
, 'The user ID'),
2453 'competencyid' => new external_value(PARAM_INT
, 'The competency ID'),
2458 * External function user_competency_request_review.
2460 * @param int $userid The user ID.
2461 * @param int $competencyid The competency ID.
2464 public static function user_competency_request_review($userid, $competencyid) {
2465 $params = self
::validate_parameters(self
::user_competency_request_review_parameters(), array(
2466 'userid' => $userid,
2467 'competencyid' => $competencyid,
2470 $context = context_user
::instance($params['userid']);
2471 self
::validate_context($context);
2473 return api
::user_competency_request_review($userid, $competencyid);
2477 * Returns description of external function result value.
2479 * @return \external_function_parameters
2481 public static function user_competency_request_review_returns() {
2482 return new external_value(PARAM_BOOL
, 'The success');
2486 * Returns description of external function parameters.
2488 * @return \external_function_parameters
2490 public static function user_competency_start_review_parameters() {
2491 return new external_function_parameters(array(
2492 'userid' => new external_value(PARAM_INT
, 'The user ID'),
2493 'competencyid' => new external_value(PARAM_INT
, 'The competency ID'),
2498 * External function user_competency_start_review.
2500 * @param int $userid The user ID.
2501 * @param int $competencyid The competency ID.
2504 public static function user_competency_start_review($userid, $competencyid) {
2505 $params = self
::validate_parameters(self
::user_competency_start_review_parameters(), array(
2506 'userid' => $userid,
2507 'competencyid' => $competencyid
2510 $context = context_user
::instance($params['userid']);
2511 self
::validate_context($context);
2513 return api
::user_competency_start_review($userid, $competencyid);
2517 * Returns description of external function result value.
2519 * @return \external_function_parameters
2521 public static function user_competency_start_review_returns() {
2522 return new external_value(PARAM_BOOL
, 'The success');
2526 * Returns description of external function parameters.
2528 * @return \external_function_parameters
2530 public static function user_competency_stop_review_parameters() {
2531 return new external_function_parameters(array(
2532 'userid' => new external_value(PARAM_INT
, 'The user ID'),
2533 'competencyid' => new external_value(PARAM_INT
, 'The competency ID'),
2538 * External function user_competency_stop_review.
2540 * @param int $userid The user ID.
2541 * @param int $competencyid The competency ID.
2544 public static function user_competency_stop_review($userid, $competencyid) {
2545 $params = self
::validate_parameters(self
::user_competency_stop_review_parameters(), array(
2546 'userid' => $userid,
2547 'competencyid' => $competencyid
2550 $context = context_user
::instance($params['userid']);
2551 self
::validate_context($context);
2553 return api
::user_competency_stop_review($userid, $competencyid);
2557 * Returns description of external function result value.
2559 * @return \external_function_parameters
2561 public static function user_competency_stop_review_returns() {
2562 return new external_value(PARAM_BOOL
, 'The success');
2566 * Returns description of template_has_related_data() parameters.
2568 * @return \external_function_parameters
2570 public static function template_has_related_data_parameters() {
2571 $templateid = new external_value(
2577 'id' => $templateid,
2579 return new external_function_parameters($params);
2583 * Check if template has related data.
2585 * @param int $templateid Template id.
2588 public static function template_has_related_data($templateid) {
2589 $params = self
::validate_parameters(self
::template_has_related_data_parameters(), array(
2590 'id' => $templateid,
2593 $template = api
::read_template($params['id']);
2594 self
::validate_context($template->get_context());
2596 return api
::template_has_related_data($params['id']);
2600 * Returns description of template_has_related_data() result value.
2602 * @return \external_description
2604 public static function template_has_related_data_returns() {
2605 return new external_value(PARAM_BOOL
, 'True if the template has related data');
2609 * Count the competencies (visible to this user) in this learning plan template.
2611 * @param int $templateid Template id.
2612 * @param int $competencyid Competency id.
2615 public static function remove_competency_from_template($templateid, $competencyid) {
2616 $params = self
::validate_parameters(self
::remove_competency_from_template_parameters(), array(
2617 'templateid' => $templateid,
2618 'competencyid' => $competencyid,
2620 $template = api
::read_template($params['templateid']);
2621 self
::validate_context($template->get_context());
2623 return api
::remove_competency_from_template($params['templateid'], $params['competencyid']);
2627 * Returns description of remove_competency_from_template() result value.
2629 * @return \external_description
2631 public static function remove_competency_from_template_returns() {
2632 return new external_value(PARAM_BOOL
, 'True if successful.');
2636 * Returns description of create_plan() parameters.
2638 * @return \external_function_parameters
2640 public static function create_plan_parameters() {
2641 $structure = plan_exporter
::get_create_structure();
2642 $params = array('plan' => $structure);
2643 return new external_function_parameters($params);
2647 * Create a new learning plan.
2649 * @param array $plan List of fields for the plan.
2650 * @return array New plan record.
2652 public static function create_plan($plan) {
2655 $params = self
::validate_parameters(self
::create_plan_parameters(), array('plan' => $plan));
2656 $params = $params['plan'];
2658 $context = context_user
::instance($params['userid']);
2659 self
::validate_context($context);
2660 $output = $PAGE->get_renderer('core');
2662 $params = (object) $params;
2664 $result = api
::create_plan($params);
2665 $exporter = new plan_exporter($result, array('template' => null));
2666 return $exporter->export($output);
2670 * Returns description of create_plan() result value.
2672 * @return \external_description
2674 public static function create_plan_returns() {
2675 return plan_exporter
::get_read_structure();
2679 * Returns description of update_plan() parameters.
2681 * @return \external_function_parameters
2683 public static function update_plan_parameters() {
2684 $structure = plan_exporter
::get_update_structure();
2685 $params = array('plan' => $structure);
2686 return new external_function_parameters($params);
2690 * Updates a new learning plan.
2692 * @param array $plan Fields for the plan (id is required)
2695 public static function update_plan($plan) {
2698 $params = self
::validate_parameters(self
::update_plan_parameters(), array('plan' => $plan));
2700 $params = $params['plan'];
2702 $plan = api
::read_plan($params['id']);
2703 self
::validate_context($plan->get_context());
2704 $output = $PAGE->get_renderer('core');
2706 $params = (object) $params;
2707 $result = api
::update_plan($params);
2708 $exporter = new plan_exporter($result, ['template' => $plan->get_template()]);
2709 return $exporter->export($output);
2713 * Returns description of update_plan() result value.
2715 * @return \external_description
2717 public static function update_plan_returns() {
2718 return plan_exporter
::get_read_structure();
2722 * Returns description of complete_plan() parameters.
2724 * @return \external_function_parameters
2726 public static function complete_plan_parameters() {
2727 $planid = new external_value(
2732 $params = array('planid' => $planid);
2733 return new external_function_parameters($params);
2737 * Complete Learning plan.
2739 * @param int $planid plan id (id is required)
2742 public static function complete_plan($planid) {
2743 $params = self
::validate_parameters(self
::complete_plan_parameters(), array(
2747 return api
::complete_plan($params['planid']);
2751 * Returns description of complete_plan() result value.
2753 * @return \external_description
2755 public static function complete_plan_returns() {
2756 return new external_value(PARAM_BOOL
, 'True if completing learning plan was successful');
2760 * Returns description of reopen_plan() parameters.
2762 * @return \external_function_parameters
2764 public static function reopen_plan_parameters() {
2765 $planid = new external_value(
2770 $params = array('planid' => $planid);
2771 return new external_function_parameters($params);
2775 * Reopen Learning plan.
2777 * @param int $planid plan id (id is required)
2780 public static function reopen_plan($planid) {
2781 $params = self
::validate_parameters(self
::reopen_plan_parameters(), array(
2785 return api
::reopen_plan($params['planid']);
2789 * Returns description of reopen_plan() result value.
2791 * @return \external_description
2793 public static function reopen_plan_returns() {
2794 return new external_value(PARAM_BOOL
, 'True if reopening learning plan was successful');
2798 * Returns description of read_plan() parameters.
2800 * @return \external_function_parameters
2802 public static function read_plan_parameters() {
2803 $id = new external_value(
2805 'Data base record id for the plan',
2808 return new external_function_parameters(array('id' => $id));
2812 * Read a plan by id.
2814 * @param int $id The id of the plan.
2817 public static function read_plan($id) {
2820 $params = self
::validate_parameters(self
::read_plan_parameters(), array(
2824 $plan = api
::read_plan($params['id']);
2825 self
::validate_context($plan->get_context());
2826 $output = $PAGE->get_renderer('core');
2828 $exporter = new plan_exporter($plan, array('template' => $plan->get_template()));
2829 $record = $exporter->export($output);
2830 return external_api
::clean_returnvalue(self
::read_plan_returns(), $record);
2834 * Returns description of read_plan() result value.
2836 * @return \external_description
2838 public static function read_plan_returns() {
2839 return plan_exporter
::get_read_structure();
2843 * Returns description of delete_plan() parameters.
2845 * @return \external_function_parameters
2847 public static function delete_plan_parameters() {
2848 $id = new external_value(
2850 'Data base record id for the learning plan',
2857 return new external_function_parameters($params);
2863 * @param int $id The plan id
2866 public static function delete_plan($id) {
2867 $params = self
::validate_parameters(self
::delete_plan_parameters(), array(
2871 $plan = api
::read_plan($params['id']);
2872 self
::validate_context($plan->get_context());
2874 return external_api
::clean_returnvalue(self
::delete_plan_returns(), api
::delete_plan($params['id']));
2878 * Returns description of delete_plan() result value.
2880 * @return \external_description
2882 public static function delete_plan_returns() {
2883 return new external_value(PARAM_BOOL
, 'True if the delete was successful');
2887 * Returns description of external function parameters.
2889 * @return \external_function_parameters
2891 public static function plan_cancel_review_request_parameters() {
2892 return new external_function_parameters(array(
2893 'id' => new external_value(PARAM_INT
, 'The plan ID'),
2898 * External function plan_cancel_review_request.
2900 * @param int $id The plan ID.
2903 public static function plan_cancel_review_request($id) {
2904 $params = self
::validate_parameters(self
::plan_cancel_review_request_parameters(), array(
2908 $plan = api
::read_plan($id);
2909 self
::validate_context($plan->get_context());
2911 return api
::plan_cancel_review_request($plan);
2915 * Returns description of external function result value.
2917 * @return \external_function_parameters
2919 public static function plan_cancel_review_request_returns() {
2920 return new external_value(PARAM_BOOL
, 'The success');
2924 * Returns description of external function parameters.
2926 * @return \external_function_parameters
2928 public static function plan_request_review_parameters() {
2929 return new external_function_parameters(array(
2930 'id' => new external_value(PARAM_INT
, 'The plan ID'),
2935 * External function plan_request_review.
2937 * @param int $id The plan ID.
2940 public static function plan_request_review($id) {
2941 $params = self
::validate_parameters(self
::plan_request_review_parameters(), array(
2945 $plan = api
::read_plan($id);
2946 self
::validate_context($plan->get_context());
2948 return api
::plan_request_review($plan);
2952 * Returns description of external function result value.
2954 * @return \external_function_parameters
2956 public static function plan_request_review_returns() {
2957 return new external_value(PARAM_BOOL
, 'The success');
2961 * Returns description of external function parameters.
2963 * @return \external_function_parameters
2965 public static function plan_start_review_parameters() {
2966 return new external_function_parameters(array(
2967 'id' => new external_value(PARAM_INT
, 'The plan ID'),
2972 * External function plan_start_review.
2974 * @param int $id The plan ID.
2977 public static function plan_start_review($id) {
2978 $params = self
::validate_parameters(self
::plan_start_review_parameters(), array(
2982 $plan = api
::read_plan($id);
2983 self
::validate_context($plan->get_context());
2985 return api
::plan_start_review($plan);
2989 * Returns description of external function result value.
2991 * @return \external_function_parameters
2993 public static function plan_start_review_returns() {
2994 return new external_value(PARAM_BOOL
, 'The success');
2998 * Returns description of external function parameters.
3000 * @return \external_function_parameters
3002 public static function plan_stop_review_parameters() {
3003 return new external_function_parameters(array(
3004 'id' => new external_value(PARAM_INT
, 'The plan ID'),
3009 * External function plan_stop_review.
3011 * @param int $id The plan ID.
3014 public static function plan_stop_review($id) {
3015 $params = self
::validate_parameters(self
::plan_stop_review_parameters(), array(
3019 $plan = api
::read_plan($id);
3020 self
::validate_context($plan->get_context());
3022 return api
::plan_stop_review($plan);
3026 * Returns description of external function result value.
3028 * @return \external_function_parameters
3030 public static function plan_stop_review_returns() {
3031 return new external_value(PARAM_BOOL
, 'The success');
3035 * Returns description of external function parameters.
3037 * @return \external_function_parameters
3039 public static function approve_plan_parameters() {
3040 return new external_function_parameters(array(
3041 'id' => new external_value(PARAM_INT
, 'The plan ID'),
3046 * External function approve_plan.
3048 * @param int $id The plan ID.
3051 public static function approve_plan($id) {
3052 $params = self
::validate_parameters(self
::approve_plan_parameters(), array(
3056 $plan = api
::read_plan($id);
3057 self
::validate_context($plan->get_context());
3059 return api
::approve_plan($plan);
3063 * Returns description of external function result value.
3065 * @return \external_function_parameters
3067 public static function approve_plan_returns() {
3068 return new external_value(PARAM_BOOL
, 'The success');
3072 * Returns description of external function parameters.
3074 * @return \external_function_parameters
3076 public static function unapprove_plan_parameters() {
3077 return new external_function_parameters(array(
3078 'id' => new external_value(PARAM_INT
, 'The plan ID'),
3083 * External function unapprove_plan.
3085 * @param int $id The plan ID.
3088 public static function unapprove_plan($id) {
3089 $params = self
::validate_parameters(self
::unapprove_plan_parameters(), array(
3093 $plan = api
::read_plan($id);
3094 self
::validate_context($plan->get_context());
3096 return api
::unapprove_plan($plan);
3100 * Returns description of external function result value.
3102 * @return \external_function_parameters
3104 public static function unapprove_plan_returns() {
3105 return new external_value(PARAM_BOOL
, 'The success');
3109 * External function parameters structure.
3111 * @return \external_description
3113 public static function list_plan_competencies_parameters() {
3114 return new external_function_parameters(array(
3115 'id' => new external_value(PARAM_INT
, 'The plan ID.')
3120 * List plan competencies.
3121 * @param int $id The plan ID.
3124 public static function list_plan_competencies($id) {
3127 $params = self
::validate_parameters(self
::list_plan_competencies_parameters(), array('id' => $id));
3128 $id = $params['id'];
3129 $plan = api
::read_plan($id);
3130 $usercontext = $plan->get_context();
3131 self
::validate_context($usercontext);
3132 $output = $PAGE->get_renderer('core');
3134 $result = api
::list_plan_competencies($plan);
3136 if ($plan->get('status') == plan
::STATUS_COMPLETE
) {
3137 $ucproperty = 'usercompetencyplan';
3139 $ucproperty = 'usercompetency';
3142 $helper = new performance_helper();
3143 foreach ($result as $key => $r) {
3144 $context = $helper->get_context_from_competency($r->competency
);
3145 $scale = $helper->get_scale_from_competency($r->competency
);
3147 $exporter = new competency_exporter($r->competency
, array('context' => $context));
3148 $r->competency
= $exporter->export($output);
3150 if ($r->usercompetency
) {
3151 $exporter = new user_competency_exporter($r->usercompetency
, array('scale' => $scale));
3152 $r->usercompetency
= $exporter->export($output);
3153 unset($r->usercompetencyplan
);
3155 $exporter = new user_competency_plan_exporter($r->usercompetencyplan
, array('scale' => $scale));
3156 $r->usercompetencyplan
= $exporter->export($output);
3157 unset($r->usercompetency
);
3164 * External function return structure.
3166 * @return \external_description
3168 public static function list_plan_competencies_returns() {
3169 $uc = user_competency_exporter
::get_read_structure();
3170 $ucp = user_competency_plan_exporter
::get_read_structure();
3172 $uc->required
= VALUE_OPTIONAL
;
3173 $ucp->required
= VALUE_OPTIONAL
;
3175 return new external_multiple_structure(
3176 new external_single_structure(array(
3177 'competency' => competency_exporter
::get_read_structure(),
3178 'usercompetency' => $uc,
3179 'usercompetencyplan' => $ucp
3185 * Returns description of external function parameters.
3187 * @return \external_function_parameters
3189 public static function list_user_plans_parameters() {
3190 return new external_function_parameters(array(
3191 'userid' => new external_value(PARAM_INT
, 'The user ID'),
3196 * External function list_user_plans.
3198 * @param int $userid The user ID.
3201 public static function list_user_plans($userid) {
3203 $params = self
::validate_parameters(self
::list_user_plans_parameters(), array(
3207 $context = context_user
::instance($params['userid']);
3208 self
::validate_context($context);
3209 $output = $PAGE->get_renderer('core');
3211 $response = array();
3212 $plans = api
::list_user_plans($params['userid']);
3213 foreach ($plans as $plan) {
3214 $exporter = new plan_exporter($plan, array('template' => $plan->get_template()));
3215 $response[] = $exporter->export($output);
3222 * Returns description of external function result value.
3224 * @return \external_function_parameters
3226 public static function list_user_plans_returns() {
3227 return new external_multiple_structure(
3228 plan_exporter
::get_read_structure()
3233 * Returns description of external function parameters.
3235 * @return \external_description
3237 public static function read_user_evidence_parameters() {
3238 return new external_function_parameters(array(
3239 'id' => new external_value(PARAM_INT
, 'The user evidence ID.'),
3244 * Delete a user evidence.
3246 * @param int $id The evidence id
3249 public static function read_user_evidence($id) {
3251 $params = self
::validate_parameters(self
::read_user_evidence_parameters(), array('id' => $id));
3253 $userevidence = api
::read_user_evidence($params['id']);
3254 $context = $userevidence->get_context();
3255 self
::validate_context($context);
3256 $output = $PAGE->get_renderer('core');
3258 $exporter = new user_evidence_exporter($userevidence, array('context' => $context,
3259 'competencies' => $userevidence->get_competencies()));
3260 return $exporter->export($output);
3264 * Returns description of external function result value.
3266 * @return \external_description
3268 public static function read_user_evidence_returns() {
3269 return user_evidence_exporter
::get_read_structure();
3273 * Returns description of external function parameters.
3275 * @return \external_function_parameters
3277 public static function delete_user_evidence_parameters() {
3278 return new external_function_parameters(array(
3279 'id' => new external_value(PARAM_INT
, 'The user evidence ID.'),
3284 * Delete a user evidence.
3286 * @param int $id The evidence id
3289 public static function delete_user_evidence($id) {
3290 $params = self
::validate_parameters(self
::delete_user_evidence_parameters(), array('id' => $id));
3292 $userevidence = api
::read_user_evidence($params['id']);
3293 self
::validate_context($userevidence->get_context());
3295 return api
::delete_user_evidence($userevidence->get('id'));
3299 * Returns description of external function result value.
3301 * @return \external_description
3303 public static function delete_user_evidence_returns() {
3304 return new external_value(PARAM_BOOL
, 'True if the delete was successful');
3308 * Returns description of external function parameters.
3310 * @return \external_function_parameters
3312 public static function create_user_evidence_competency_parameters() {
3313 return new external_function_parameters(array(
3314 'userevidenceid' => new external_value(PARAM_INT
, 'The user evidence ID.'),
3315 'competencyid' => new external_value(PARAM_INT
, 'The competency ID.'),
3320 * Delete a user evidence competency relationship.
3322 * @param int $userevidenceid The user evidence id.
3323 * @param int $competencyid The competency id.
3326 public static function create_user_evidence_competency($userevidenceid, $competencyid) {
3328 $params = self
::validate_parameters(self
::create_user_evidence_competency_parameters(), array(
3329 'userevidenceid' => $userevidenceid,
3330 'competencyid' => $competencyid,
3333 $userevidence = api
::read_user_evidence($params['userevidenceid']);
3334 self
::validate_context($userevidence->get_context());
3336 $relation = api
::create_user_evidence_competency($userevidence, $competencyid);
3337 $exporter = new user_evidence_competency_exporter($relation);
3338 return $exporter->export($PAGE->get_renderer('core'));
3342 * Returns description of external function result value.
3344 * @return \external_description
3346 public static function create_user_evidence_competency_returns() {
3347 return user_evidence_competency_exporter
::get_read_structure();
3351 * Returns description of external function parameters.
3353 * @return \external_function_parameters
3355 public static function delete_user_evidence_competency_parameters() {
3356 return new external_function_parameters(array(
3357 'userevidenceid' => new external_value(PARAM_INT
, 'The user evidence ID.'),
3358 'competencyid' => new external_value(PARAM_INT
, 'The competency ID.'),
3363 * Delete a user evidence competency relationship.
3365 * @param int $userevidenceid The user evidence id.
3366 * @param int $competencyid The competency id.
3369 public static function delete_user_evidence_competency($userevidenceid, $competencyid) {
3370 $params = self
::validate_parameters(self
::delete_user_evidence_competency_parameters(), array(
3371 'userevidenceid' => $userevidenceid,
3372 'competencyid' => $competencyid,
3375 $userevidence = api
::read_user_evidence($params['userevidenceid']);
3376 self
::validate_context($userevidence->get_context());
3378 return api
::delete_user_evidence_competency($userevidence, $params['competencyid']);
3382 * Returns description of external function result value.
3384 * @return \external_description
3386 public static function delete_user_evidence_competency_returns() {
3387 return new external_value(PARAM_BOOL
, 'True if the delete was successful');
3391 * Returns description of external function parameters.
3393 * @return \external_function_parameters
3395 public static function request_review_of_user_evidence_linked_competencies_parameters() {
3396 return new external_function_parameters(array(
3397 'id' => new external_value(PARAM_INT
, 'The user evidence ID.')
3402 * Send user evidence competencies to review.
3404 * @param int $id The user evidence id.
3407 public static function request_review_of_user_evidence_linked_competencies($id) {
3408 $params = self
::validate_parameters(self
::request_review_of_user_evidence_linked_competencies_parameters(), array(
3412 $userevidence = api
::read_user_evidence($id);
3413 self
::validate_context($userevidence->get_context());
3415 return api
::request_review_of_user_evidence_linked_competencies($id);
3419 * Returns description of external function result value.
3421 * @return \external_description
3423 public static function request_review_of_user_evidence_linked_competencies_returns() {
3424 return new external_value(PARAM_BOOL
, 'True if all competencies were send to review');
3429 * Returns the description of the get_scale_values() parameters.
3431 * @return external_function_parameters.
3433 public static function get_scale_values_parameters() {
3434 $scaleid = new external_value(
3439 $params = array('scaleid' => $scaleid);
3440 return new external_function_parameters($params);
3444 * Get the values associated with a scale.
3446 * @param int $scaleid Scale ID
3447 * @return array Values for a scale.
3449 public static function get_scale_values($scaleid) {
3451 $params = self
::validate_parameters(self
::get_scale_values_parameters(),
3453 'scaleid' => $scaleid,
3456 $context = context_system
::instance();
3457 self
::validate_context($context);
3458 // The following section is not learning plan specific and so has not been moved to the api.
3459 // Retrieve the scale value from the database.
3460 $scale = grade_scale
::fetch(array('id' => $scaleid));
3461 $scalevalues = $scale->load_items();
3462 foreach ($scalevalues as $key => $value) {
3463 // Add a key (make the first value 1).
3464 $scalevalues[$key] = array(
3466 'name' => external_format_string($value, $context->id
)
3469 return $scalevalues;
3473 * Returns description of get_scale_values() result value.
3475 * @return external_multiple_structure
3477 public static function get_scale_values_returns() {
3478 return new external_multiple_structure(
3479 new external_single_structure(array(
3480 'id' => new external_value(PARAM_INT
, 'Scale value ID'),
3481 'name' => new external_value(PARAM_RAW
, 'Scale value name')
3488 * Returns the description of the add_related_competency_parameters() parameters.
3490 * @return external_function_parameters.
3492 public static function add_related_competency_parameters() {
3493 $competencyid = new external_value(
3495 'The competency id',
3498 $relatedcompetencyid = new external_value(
3500 'The related competency id',
3504 'competencyid' => $competencyid,
3505 'relatedcompetencyid' => $relatedcompetencyid
3507 return new external_function_parameters($params);
3511 * Adds a related competency.
3513 * @param int $competencyid
3514 * @param int $relatedcompetencyid
3517 public static function add_related_competency($competencyid, $relatedcompetencyid) {
3518 $params = self
::validate_parameters(self
::add_related_competency_parameters(), array(
3519 'competencyid' => $competencyid,
3520 'relatedcompetencyid' => $relatedcompetencyid
3522 $competency = api
::read_competency($params['competencyid']);
3523 self
::validate_context($competency->get_context());
3525 return api
::add_related_competency($params['competencyid'], $params['relatedcompetencyid']);
3529 * Returns description of add_related_competency_returns() result value.
3531 * @return external_description
3533 public static function add_related_competency_returns() {
3534 return new external_value(PARAM_BOOL
, 'True if successful.');
3538 * Returns the description of the remove_related_competency_parameters() parameters.
3540 * @return external_function_parameters.
3542 public static function remove_related_competency_parameters() {
3543 $competencyid = new external_value(
3545 'The competency id',
3548 $relatedcompetencyid = new external_value(
3550 'The related competency id',
3554 'competencyid' => $competencyid,
3555 'relatedcompetencyid' => $relatedcompetencyid
3557 return new external_function_parameters($params);
3561 * Removes a related competency.
3563 * @param int $competencyid
3564 * @param int $relatedcompetencyid
3567 public static function remove_related_competency($competencyid, $relatedcompetencyid) {
3568 $params = self
::validate_parameters(self
::remove_related_competency_parameters(), array(
3569 'competencyid' => $competencyid,
3570 'relatedcompetencyid' => $relatedcompetencyid
3572 $competency = api
::read_competency($params['competencyid']);
3573 self
::validate_context($competency->get_context());
3575 return api
::remove_related_competency($params['competencyid'], $params['relatedcompetencyid']);
3579 * Returns description of remove_related_competency_returns() result value.
3581 * @return external_description
3583 public static function remove_related_competency_returns() {
3584 return new external_value(PARAM_BOOL
, 'True if successful.');
3588 * Returns description of update_ruleoutcome_course_competency() parameters.
3590 * @return \external_function_parameters
3592 public static function set_course_competency_ruleoutcome_parameters() {
3593 $coursecompetencyid = new external_value(
3595 'Data base record id for the course competency',
3599 $ruleoutcome = new external_value(
3601 'Ruleoutcome value',
3606 'coursecompetencyid' => $coursecompetencyid,
3607 'ruleoutcome' => $ruleoutcome,
3609 return new external_function_parameters($params);
3613 * Change the ruleoutcome of a course competency.
3615 * @param int $coursecompetencyid The course competency id
3616 * @param int $ruleoutcome The ruleoutcome value
3619 public static function set_course_competency_ruleoutcome($coursecompetencyid, $ruleoutcome) {
3620 $params = self
::validate_parameters(self
::set_course_competency_ruleoutcome_parameters(), array(
3621 'coursecompetencyid' => $coursecompetencyid,
3622 'ruleoutcome' => $ruleoutcome,
3625 $coursecompetency = new course_competency($params['coursecompetencyid']);
3626 self
::validate_context(context_course
::instance($coursecompetency->get('courseid')));
3628 return api
::set_course_competency_ruleoutcome($coursecompetency, $params['ruleoutcome']);
3632 * Returns description of update_ruleoutcome_course_competency() result value.
3634 * @return \external_value
3636 public static function set_course_competency_ruleoutcome_returns() {
3637 return new external_value(PARAM_BOOL
, 'True if the update was successful');
3642 * Returns description of external function parameters.
3644 * @return \external_function_parameters
3646 public static function grade_competency_parameters() {
3647 $userid = new external_value(
3652 $competencyid = new external_value(
3657 $grade = new external_value(
3662 $note = new external_value(
3664 'A note to attach to the evidence',
3669 'userid' => $userid,
3670 'competencyid' => $competencyid,
3674 return new external_function_parameters($params);
3678 * Grade a competency.
3680 * @param int $userid The user ID.
3681 * @param int $competencyid The competency id
3682 * @param int $grade The new grade value
3683 * @param string $note A note to attach to the evidence
3686 public static function grade_competency($userid, $competencyid, $grade, $note = null) {
3687 global $USER, $PAGE;
3688 $params = self
::validate_parameters(self
::grade_competency_parameters(), array(
3689 'userid' => $userid,
3690 'competencyid' => $competencyid,
3695 $uc = api
::get_user_competency($params['userid'], $params['competencyid']);
3696 self
::validate_context($uc->get_context());
3698 $output = $PAGE->get_renderer('core');
3699 $evidence = api
::grade_competency(
3701 $uc->get('competencyid'),
3706 $scale = $uc->get_competency()->get_scale();
3707 $exporter = new evidence_exporter($evidence, [
3708 'actionuser' => $USER,
3710 'usercompetency' => $uc,
3711 'usercompetencyplan' => null,
3712 'context' => $evidence->get_context()
3714 return $exporter->export($output);
3718 * Returns description of external function result value.
3720 * @return \external_value
3722 public static function grade_competency_returns() {
3723 return evidence_exporter
::get_read_structure();
3727 * Returns description of grade_competency_in_plan() parameters.
3729 * @return \external_function_parameters
3731 public static function grade_competency_in_plan_parameters() {
3732 $planid = new external_value(
3737 $competencyid = new external_value(
3742 $grade = new external_value(
3747 $note = new external_value(
3749 'A note to attach to the evidence',
3754 'planid' => $planid,
3755 'competencyid' => $competencyid,
3759 return new external_function_parameters($params);
3763 * Grade a competency in a plan.
3765 * @param int $planid The plan id
3766 * @param int $competencyid The competency id
3767 * @param int $grade The new grade value
3768 * @param string $note A note to add to the evidence
3771 public static function grade_competency_in_plan($planid, $competencyid, $grade, $note = null) {
3772 global $USER, $PAGE;
3774 $params = self
::validate_parameters(self
::grade_competency_in_plan_parameters(), array(
3775 'planid' => $planid,
3776 'competencyid' => $competencyid,
3781 $plan = new plan($params['planid']);
3782 $context = $plan->get_context();
3783 self
::validate_context($context);
3784 $output = $PAGE->get_renderer('core');
3786 $evidence = api
::grade_competency_in_plan(
3788 $params['competencyid'],
3792 $competency = api
::read_competency($params['competencyid']);
3793 $scale = $competency->get_scale();
3794 $exporter = new evidence_exporter($evidence, [
3795 'actionuser' => $USER,
3797 'usercompetency' => null,
3798 'usercompetencyplan' => null,
3799 'context' => $evidence->get_context()
3801 return $exporter->export($output);
3805 * Returns description of grade_competency_in_plan() result value.
3807 * @return \external_value
3809 public static function grade_competency_in_plan_returns() {
3810 return evidence_exporter
::get_read_structure();
3814 * Returns description of user_competency_viewed() parameters.
3816 * @return \external_function_parameters
3818 public static function user_competency_viewed_parameters() {
3819 $usercompetencyid = new external_value(
3821 'The user competency id',
3825 'usercompetencyid' => $usercompetencyid
3827 return new external_function_parameters($params);
3831 * Log user competency viewed event.
3833 * @param int $usercompetencyid The user competency ID.
3836 public static function user_competency_viewed($usercompetencyid) {
3837 $params = self
::validate_parameters(self
::user_competency_viewed_parameters(), array(
3838 'usercompetencyid' => $usercompetencyid
3841 $uc = api
::get_user_competency_by_id($params['usercompetencyid']);
3842 $result = api
::user_competency_viewed($uc);
3848 * Returns description of user_competency_viewed() result value.
3850 * @return \external_description
3852 public static function user_competency_viewed_returns() {
3853 return new external_value(PARAM_BOOL
, 'True if the event user competency viewed was logged');
3857 * Returns description of user_competency_viewed_in_plan() parameters.
3859 * @return \external_function_parameters
3861 public static function user_competency_viewed_in_plan_parameters() {
3862 $competencyid = new external_value(
3864 'The competency id',
3867 $userid = new external_value(
3872 $planid = new external_value(
3878 'competencyid' => $competencyid,
3879 'userid' => $userid,
3882 return new external_function_parameters($params);
3886 * Log user competency viewed in plan event.
3888 * @param int $competencyid The competency ID.
3889 * @param int $userid The user ID.
3890 * @param int $planid The plan ID.
3893 public static function user_competency_viewed_in_plan($competencyid, $userid, $planid) {
3894 $params = self
::validate_parameters(self
::user_competency_viewed_in_plan_parameters(), array(
3895 'competencyid' => $competencyid,
3896 'userid' => $userid,
3899 $pl = api
::get_plan_competency($params['planid'], $params['competencyid']);
3900 $result = api
::user_competency_viewed_in_plan($pl->usercompetency
, $params['planid']);
3906 * Returns description of user_competency_viewed_in_plan() result value.
3908 * @return \external_description
3910 public static function user_competency_viewed_in_plan_returns() {
3911 return new external_value(PARAM_BOOL
, 'True if the event user competency viewed in plan was logged');
3915 * Returns description of user_competency_viewed_in_course() parameters.
3917 * @return \external_function_parameters
3919 public static function user_competency_viewed_in_course_parameters() {
3920 $competencyid = new external_value(
3922 'The competency id',
3925 $userid = new external_value(
3930 $courseid = new external_value(
3936 'competencyid' => $competencyid,
3937 'userid' => $userid,
3938 'courseid' => $courseid
3940 return new external_function_parameters($params);
3944 * Log user competency viewed in course event.
3946 * @param int $competencyid The competency ID.
3947 * @param int $userid The user ID.
3948 * @param int $courseid The course ID.
3951 public static function user_competency_viewed_in_course($competencyid, $userid, $courseid) {
3952 $params = self
::validate_parameters(self
::user_competency_viewed_in_course_parameters(), array(
3953 'competencyid' => $competencyid,
3954 'userid' => $userid,
3955 'courseid' => $courseid
3957 $ucc = api
::get_user_competency_in_course($params['courseid'], $params['userid'], $params['competencyid']);
3958 $result = api
::user_competency_viewed_in_course($ucc);
3964 * Returns description of user_competency_viewed_in_course() result value.
3966 * @return \external_description
3968 public static function user_competency_viewed_in_course_returns() {
3969 return new external_value(PARAM_BOOL
, 'True if the event user competency viewed in course was logged');
3973 * Returns description of user_competency_plan_viewed() parameters.
3975 * @return \external_function_parameters
3977 public static function user_competency_plan_viewed_parameters() {
3978 $competencyid = new external_value(
3980 'The competency id',
3983 $userid = new external_value(
3988 $planid = new external_value(
3994 'competencyid' => $competencyid,
3995 'userid' => $userid,
3998 return new external_function_parameters($params);
4002 * Log user competency plan viewed event.
4004 * @param int $competencyid The competency ID.
4005 * @param int $userid The user ID.
4006 * @param int $planid The plan ID.
4009 public static function user_competency_plan_viewed($competencyid, $userid, $planid) {
4010 $params = self
::validate_parameters(self
::user_competency_viewed_in_plan_parameters(), array(
4011 'competencyid' => $competencyid,
4012 'userid' => $userid,
4015 $pl = api
::get_plan_competency($params['planid'], $params['competencyid']);
4016 $result = api
::user_competency_plan_viewed($pl->usercompetencyplan
);
4022 * Returns description of user_competency_plan_viewed() result value.
4024 * @return \external_description
4026 public static function user_competency_plan_viewed_returns() {
4027 return new external_value(PARAM_BOOL
, 'True if the event user competency plan viewed was logged');
4031 * Returns description of grade_competency_in_course() parameters.
4033 * @return \external_function_parameters
4035 public static function grade_competency_in_course_parameters() {
4036 $courseid = new external_value(
4041 $userid = new external_value(
4046 $competencyid = new external_value(
4051 $grade = new external_value(
4056 $note = new external_value(
4058 'A note to attach to the evidence',
4063 'courseid' => $courseid,
4064 'userid' => $userid,
4065 'competencyid' => $competencyid,
4069 return new external_function_parameters($params);
4073 * Grade a competency in a course.
4075 * @param int $courseid The course id
4076 * @param int $userid The user id
4077 * @param int $competencyid The competency id
4078 * @param int $grade The new grade value
4079 * @param string $note A note to add to the evidence
4082 public static function grade_competency_in_course($courseid, $userid, $competencyid, $grade, $note = null) {
4083 global $USER, $PAGE, $DB;
4085 $params = self
::validate_parameters(self
::grade_competency_in_course_parameters(), array(
4086 'courseid' => $courseid,
4087 'userid' => $userid,
4088 'competencyid' => $competencyid,
4093 $course = $DB->get_record('course', array('id' => $params['courseid']));
4094 $context = context_course
::instance($course->id
);
4095 self
::validate_context($context);
4096 $output = $PAGE->get_renderer('core');
4098 $evidence = api
::grade_competency_in_course(
4099 $params['courseid'],
4101 $params['competencyid'],
4105 $competency = api
::read_competency($params['competencyid']);
4106 $scale = $competency->get_scale();
4107 $exporter = new evidence_exporter($evidence, array(
4108 'actionuser' => $USER,
4110 'usercompetency' => null,
4111 'usercompetencyplan' => null,
4112 'context' => $evidence->get_context(),
4114 return $exporter->export($output);
4118 * Returns description of grade_competency_in_course() result value.
4120 * @return \external_value
4122 public static function grade_competency_in_course_returns() {
4123 return evidence_exporter
::get_read_structure();
4127 * Returns description of unlink_plan_from_template_() parameters.
4129 * @return \external_function_parameters
4131 public static function unlink_plan_from_template_parameters() {
4132 $planid = new external_value(
4134 'Data base record id for the plan',
4139 'planid' => $planid,
4141 return new external_function_parameters($params);
4145 * Unlink the plan from the template.
4147 * @param int $planid The plan id
4150 public static function unlink_plan_from_template($planid) {
4151 $params = self
::validate_parameters(self
::unlink_plan_from_template_parameters(), array(
4152 'planid' => $planid,
4155 $plan = new plan($params['planid']);
4156 self
::validate_context($plan->get_context());
4158 return api
::unlink_plan_from_template($plan);
4162 * Returns description of unlink_plan_from_template_() result value.
4164 * @return \external_value
4166 public static function unlink_plan_from_template_returns() {
4167 return new external_value(PARAM_BOOL
, 'True if the unlink was successful');
4171 * Returns description of template_viewed() parameters.
4173 * @return \external_function_parameters
4175 public static function template_viewed_parameters() {
4176 $id = new external_value(
4178 'Data base record id for the template',
4185 return new external_function_parameters($params);
4189 * Log the template viewed event.
4191 * @param int $id the template id
4192 * @return array of warnings and status result
4193 * @throws moodle_exception
4195 public static function template_viewed($id) {
4196 $params = self
::validate_parameters(self
::view_book_parameters(), array(
4200 $template = api
::read_template($params['id']);
4201 self
::validate_context($template->get_context());
4203 return api
::template_viewed($params['id']);
4207 * Returns description of template_viewed() result value.
4209 * @return \external_value
4211 public static function template_viewed_returns() {
4212 return new external_value(PARAM_BOOL
, 'True if the log of the view was successful');
4216 * Returns description of update_course_competency_settings() parameters.
4218 * @return \external_function_parameters
4220 public static function update_course_competency_settings_parameters() {
4221 $courseid = new external_value(
4223 'Course id for the course to update',
4226 $pushratingstouserplans = new external_value(
4228 'New value of the setting',
4231 $settings = new external_single_structure(array(
4232 'pushratingstouserplans' => $pushratingstouserplans
4235 'courseid' => $courseid,
4236 'settings' => $settings,
4238 return new external_function_parameters($params);
4242 * Update the course competency settings
4244 * @param int $courseid the course id
4245 * @param stdClass $settings The list of settings (currently only pushratingstouserplans).
4246 * @throws moodle_exception
4248 public static function update_course_competency_settings($courseid, $settings) {
4249 $params = self
::validate_parameters(self
::update_course_competency_settings_parameters(), array(
4250 'courseid' => $courseid,
4251 'settings' => $settings
4254 $context = context_course
::instance($params['courseid']);
4255 self
::validate_context($context);
4256 $result = api
::update_course_competency_settings($params['courseid'], $params['settings']);
4262 * Returns description of update_course_competency_settings() result value.
4264 * @return \external_value
4266 public static function update_course_competency_settings_returns() {
4267 return new external_value(PARAM_BOOL
, 'True if the update was successful.');
4271 * Returns description of external function parameters.
4273 * @return \external_function_parameters
4275 public static function delete_evidence_parameters() {
4276 return new external_function_parameters(array(
4277 'id' => new external_value(PARAM_INT
, 'The evidence ID'),
4282 * External function delete_evidence.
4284 * @param int $id The evidence ID.
4287 public static function delete_evidence($id) {
4288 $params = self
::validate_parameters(self
::delete_evidence_parameters(), array(
4292 $evidence = api
::read_evidence($params['id']);
4293 $uc = api
::get_user_competency_by_id($evidence->get('usercompetencyid'));
4294 self
::validate_context($uc->get_context());
4296 return api
::delete_evidence($evidence);
4300 * Returns description of external function result value.
4302 * @return \external_function_parameters
4304 public static function delete_evidence_returns() {
4305 return new external_value(PARAM_BOOL
, 'The success');