MDL-49459 Learning plans: Support for creating and editing competency frameworks.
[moodle.git] / admin / tool / lp / classes / external.php
CommitLineData
d9a39950
DW
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * This is the external API for this tool.
19 *
20 * @package tool_lp
21 * @copyright 2015 Damyon Wiese
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24namespace tool_lp;
25
26require_once("$CFG->libdir/externallib.php");
27
28use external_api;
29use external_function_parameters;
30use external_value;
31use external_format_value;
32use external_single_structure;
33use external_multiple_structure;
34use invalid_parameter_exception;
35
36/**
37 * This is the external API for this tool.
38 *
39 * @copyright 2015 Damyon Wiese
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41 */
42class external extends external_api {
43
44 /**
45 * Returns description of a generic list() parameters.
46 *
47 * @return external_function_parameters
48 */
49 protected static function list_parameters_structure() {
50 $filters = new external_multiple_structure(new external_single_structure(
51 array(
52 'column' => new external_value(PARAM_ALPHANUMEXT, 'Column name to filter by'),
53 'value' => new external_value(PARAM_TEXT, 'Value to filter by. Must be exact match')
54 )
55 ));
56 $sort = new external_value(
57 PARAM_ALPHANUMEXT,
58 'Column to sort by.',
59 VALUE_DEFAULT,
60 ''
61 );
62 $order = new external_value(
63 PARAM_ALPHA,
64 'Sort direction. Should be either ASC or DESC',
65 VALUE_DEFAULT,
66 ''
67 );
68 $skip = new external_value(
69 PARAM_INT,
70 'Skip this number of records before returning results',
71 VALUE_DEFAULT,
72 0
73 );
74 $limit = new external_value(
75 PARAM_INT,
76 'Return this number of records at most.',
77 VALUE_DEFAULT,
78 0
79 );
80
81 $params = array(
82 'filters' => $filters,
83 'sort' => $sort,
84 'order' => $order,
85 'skip' => $skip,
86 'limit' => $limit
87 );
88 return new external_function_parameters($params);
89 }
90
91 /**
92 * Returns description of a generic count_x() parameters.
93 *
94 * @return external_function_parameters
95 */
96 public static function count_parameters_structure() {
97 $filters = new external_multiple_structure(new external_single_structure(
98 array(
99 'column' => new external_value(PARAM_ALPHANUMEXT, 'Column name to filter by'),
100 'value' => new external_value(PARAM_TEXT, 'Value to filter by. Must be exact match')
101 )
102 ));
103
104 $params = array(
105 'filters' => $filters,
106 );
107 return new external_function_parameters($params);
108 }
109
110 /**
111 * Returns the external structure of a full competency_framework record.
112 *
113 * @return external_single_structure
114 */
115 protected static function get_competency_framework_external_structure() {
116 $id = new external_value(
117 PARAM_INT,
118 'Database record id'
119 );
120 $shortname = new external_value(
121 PARAM_TEXT,
122 'Short name for the competency framework'
123 );
124 $idnumber = new external_value(
125 PARAM_TEXT,
126 'If provided, must be a unique string to identify this competency framework'
127 );
128 $description = new external_value(
129 PARAM_RAW,
130 'Description for the framework'
131 );
132 $descriptionformat = new external_format_value(
133 'Description format for the framework'
134 );
135 $descriptionformatted = new external_value(
136 PARAM_RAW,
137 'Description that has been formatted for display'
138 );
139 $visible = new external_value(
140 PARAM_BOOL,
141 'Is this framework visible?'
142 );
143 $sortorder = new external_value(
144 PARAM_INT,
145 'Relative sort order of this framework'
146 );
147 $timecreated = new external_value(
148 PARAM_INT,
149 'Timestamp this record was created'
150 );
151 $timemodified = new external_value(
152 PARAM_INT,
153 'Timestamp this record was modified'
154 );
155 $usermodified = new external_value(
156 PARAM_INT,
157 'User who modified this record last'
158 );
159
160 $returns = array(
161 'id' => $id,
162 'shortname' => $shortname,
163 'idnumber' => $idnumber,
164 'description' => $description,
165 'descriptionformat' => $descriptionformat,
166 'descriptionformatted' => $descriptionformatted,
167 'visible' => $visible,
168 'sortorder' => $sortorder,
169 'timecreated' => $timecreated,
170 'timemodified' => $timemodified,
171 'usermodified' => $usermodified,
172 );
173 return new external_single_structure($returns);
174 }
175
176 /**
177 * Returns description of create_competency_framework() parameters.
178 *
179 * @return external_function_parameters
180 */
181 public static function create_competency_framework_parameters() {
182 $shortname = new external_value(
183 PARAM_TEXT,
184 'Short name for the competency framework.',
185 VALUE_REQUIRED
186 );
187 $idnumber = new external_value(
188 PARAM_TEXT,
189 'If provided, must be a unique string to identify this competency framework.',
190 VALUE_DEFAULT,
191 ''
192 );
193 $description = new external_value(
194 PARAM_RAW,
195 'Optional description for the framework',
196 VALUE_DEFAULT,
197 ''
198 );
199 $descriptionformat = new external_format_value(
200 'Optional description format for the framework',
201 VALUE_DEFAULT,
202 FORMAT_HTML
203 );
204 $visible = new external_value(
205 PARAM_BOOL,
206 'Is this framework visible?',
207 VALUE_DEFAULT,
208 true
209 );
210
211 $params = array(
212 'shortname' => $shortname,
213 'idnumber' => $idnumber,
214 'description' => $description,
215 'descriptionformat' => $descriptionformat,
216 'visible' => $visible,
217 );
218 return new external_function_parameters($params);
219 }
220
221 /**
222 * Expose to AJAX
223 * @return boolean
224 */
225 public static function create_competency_framework_is_allowed_from_ajax() {
226 return true;
227 }
228
229 /**
230 * Create a new competency framework
231 *
232 * @param string $shortname The short name
233 * @param string $idnumber The idnumber
234 * @param string $description The description
235 * @param int $descriptionformat The description format
236 * @param bool $visible Is this framework visible.
237 * @return stdClass The new record
238 */
239 public static function create_competency_framework($shortname, $idnumber, $description, $descriptionformat, $visible) {
240 $params = self::validate_parameters(self::create_competency_framework_parameters(),
241 array(
242 'shortname' => $shortname,
243 'idnumber' => $idnumber,
244 'description' => $description,
245 'descriptionformat' => $descriptionformat,
246 'visible' => $visible,
247 ));
248
249 $params = (object) $params;
250
251 $result = api::create_framework($params);
252 return $result->to_record();
253 }
254
255 /**
256 * Returns description of create_competency_framework() result value.
257 *
258 * @return external_description
259 */
260 public static function create_competency_framework_returns() {
261 return self::get_competency_framework_external_structure();
262 }
263
264 /**
265 * Returns description of read_competency_framework() parameters.
266 *
267 * @return external_function_parameters
268 */
269 public static function read_competency_framework_parameters() {
270 $id = new external_value(
271 PARAM_INT,
272 'Data base record id for the framework',
273 VALUE_REQUIRED
274 );
275
276 $params = array(
277 'id' => $id,
278 );
279 return new external_function_parameters($params);
280 }
281
282 /**
283 * Expose to AJAX
284 * @return boolean
285 */
286 public static function read_competency_framework_is_allowed_from_ajax() {
287 return true;
288 }
289
290 /**
291 * Read a competency framework by id.
292 *
293 * @param int $id The id of the framework.
294 * @return stdClass
295 */
296 public static function read_competency_framework($id) {
297 $params = self::validate_parameters(self::read_competency_framework_parameters(),
298 array(
299 'id' => $id,
300 ));
301
302 $result = api::read_framework($params['id']);
303 return $result->to_record();
304 }
305
306 /**
307 * Returns description of read_competency_framework() result value.
308 *
309 * @return external_description
310 */
311 public static function read_competency_framework_returns() {
312 return self::get_competency_framework_external_structure();
313 }
314
315 /**
316 * Returns description of delete_competency_framework() parameters.
317 *
318 * @return external_function_parameters
319 */
320 public static function delete_competency_framework_parameters() {
321 $id = new external_value(
322 PARAM_INT,
323 'Data base record id for the framework',
324 VALUE_REQUIRED
325 );
326
327 $params = array(
328 'id' => $id,
329 );
330 return new external_function_parameters($params);
331 }
332
333 /**
334 * Expose to AJAX
335 * @return boolean
336 */
337 public static function delete_competency_framework_is_allowed_from_ajax() {
338 return true;
339 }
340
341 /**
342 * Delete a competency framework
343 *
344 * @param int $id The competency framework id
345 * @return boolean
346 */
347 public static function delete_competency_framework($id) {
348 $params = self::validate_parameters(self::delete_competency_framework_parameters(),
349 array(
350 'id' => $id,
351 ));
352
353 return api::delete_framework($params['id']);
354 }
355
356 /**
357 * Returns description of delete_competency_framework() result value.
358 *
359 * @return external_description
360 */
361 public static function delete_competency_framework_returns() {
362 return new external_value(PARAM_BOOL, 'True if the delete was successful');
363 }
364
365 /**
366 * Returns description of update_competency_framework() parameters.
367 *
368 * @return external_function_parameters
369 */
370 public static function update_competency_framework_parameters() {
371 $id = new external_value(
372 PARAM_INT,
373 'Data base record id for the framework',
374 VALUE_REQUIRED
375 );
376 $shortname = new external_value(
377 PARAM_TEXT,
378 'Short name for the competency framework.',
379 VALUE_REQUIRED
380 );
381 $idnumber = new external_value(
382 PARAM_TEXT,
383 'If provided, must be a unique string to identify this competency framework.',
384 VALUE_REQUIRED
385 );
386 $description = new external_value(
387 PARAM_RAW,
388 'Description for the framework',
389 VALUE_REQUIRED
390 );
391 $descriptionformat = new external_format_value(
392 'Description format for the framework',
393 VALUE_REQUIRED
394 );
395 $visible = new external_value(
396 PARAM_BOOL,
397 'Is this framework visible?',
398 VALUE_REQUIRED
399 );
400
401 $params = array(
402 'id' => $id,
403 'shortname' => $shortname,
404 'idnumber' => $idnumber,
405 'description' => $description,
406 'descriptionformat' => $descriptionformat,
407 'visible' => $visible,
408 );
409 return new external_function_parameters($params);
410 }
411
412 /**
413 * Expose to AJAX
414 * @return boolean
415 */
416 public static function update_competency_framework_is_allowed_from_ajax() {
417 return true;
418 }
419
420 /**
421 * Update an existing competency framework
422 *
423 * @param int $id The competency framework id
424 * @param string $shortname
425 * @param string $idnumber
426 * @param string $description
427 * @param int $descriptionformat
428 * @param boolean $visible
429 * @return boolean
430 */
431 public static function update_competency_framework($id,
432 $shortname,
433 $idnumber,
434 $description,
435 $descriptionformat,
436 $visible) {
437
438 $params = self::validate_parameters(self::update_competency_framework_parameters(),
439 array(
440 'id' => $id,
441 'shortname' => $shortname,
442 'idnumber' => $idnumber,
443 'description' => $description,
444 'descriptionformat' => $descriptionformat,
445 'visible' => $visible
446 ));
447 $params = (object) $params;
448
449 return api::update_framework($params);
450 }
451
452 /**
453 * Returns description of update_competency_framework() result value.
454 *
455 * @return external_description
456 */
457 public static function update_competency_framework_returns() {
458 return new external_value(PARAM_BOOL, 'True if the update was successful');
459 }
460
461 /**
462 * Returns description of list_competency_frameworks() parameters.
463 *
464 * @return external_function_parameters
465 */
466 public static function list_competency_frameworks_parameters() {
467 return self::list_parameters_structure();
468 }
469
470 /**
471 * Expose to AJAX
472 * @return boolean
473 */
474 public static function list_competency_frameworks_is_allowed_from_ajax() {
475 return true;
476 }
477
478 /**
479 * List the existing competency frameworks
480 *
481 * @return boolean
482 */
483 public static function list_competency_frameworks($filters, $sort, $order, $skip, $limit) {
484 $params = self::validate_parameters(self::list_competency_frameworks_parameters(),
485 array(
486 'filters' => $filters,
487 'sort' => $sort,
488 'order' => $order,
489 'skip' => $skip,
490 'limit' => $limit
491 ));
492
493 if ($params['order'] !== '' && $params['order'] !== 'ASC' && $params['order'] !== 'DESC') {
494 throw new invalid_parameter_exception('Invalid order param. Must be ASC, DESC or empty.');
495 }
496
497 $safefilters = array();
498 $validcolumns = array('id', 'shortname', 'description', 'sortorder', 'idnumber', 'visible');
499 foreach ($params['filters'] as $filter) {
500 if (!in_array($filter->column, $validcolumns)) {
501 throw new invalid_parameter_exception('Filter column was invalid');
502 }
503 $safefilters[$filter->column] = $filter->value;
504 }
505
506 $results = api::list_frameworks($safefilters,
507 $params['sort'],
508 $params['order'],
509 $params['skip'],
510 $params['limit']);
511 $records = array();
512 foreach ($results as $result) {
513 $record = $result->to_record();
514 array_push($records, $record);
515 }
516 return $records;
517 }
518
519 /**
520 * Returns description of list_competency_frameworks() result value.
521 *
522 * @return external_description
523 */
524 public static function list_competency_frameworks_returns() {
525 return new external_multiple_structure(self::get_competency_framework_external_structure());
526 }
527
528 /**
529 * Returns description of count_competency_frameworks() parameters.
530 *
531 * @return external_function_parameters
532 */
533 public static function count_competency_frameworks_parameters() {
534 $filters = new external_multiple_structure(new external_single_structure(
535 array(
536 'column' => new external_value(PARAM_ALPHANUMEXT, 'Column name to filter by'),
537 'value' => new external_value(PARAM_TEXT, 'Value to filter by. Must be exact match')
538 )
539 ));
540
541 $params = array(
542 'filters' => $filters,
543 );
544 return new external_function_parameters($params);
545 }
546
547 /**
548 * Expose to AJAX
549 * @return boolean
550 */
551 public static function count_competency_frameworks_is_allowed_from_ajax() {
552 return true;
553 }
554
555 /**
556 * Count the existing competency frameworks
557 *
558 * @return boolean
559 */
560 public static function count_competency_frameworks($filters) {
561 $params = self::validate_parameters(self::count_competency_frameworks_parameters(),
562 array(
563 'filters' => $filters
564 ));
565
566 $safefilters = array();
567 $validcolumns = array('id', 'shortname', 'description', 'sortorder', 'idnumber', 'visible');
568 foreach ($params['filters'] as $filter) {
569 if (!in_array($filter->column, $validcolumns)) {
570 throw new invalid_parameter_exception('Filter column was invalid');
571 }
572 $safefilters[$filter->column] = $filter->value;
573 }
574
575 return api::count_frameworks($safefilters);
576 }
577
578 /**
579 * Returns description of count_competency_frameworks() result value.
580 *
581 * @return external_description
582 */
583 public static function count_competency_frameworks_returns() {
584 return new external_value(PARAM_INT, 'The number of competency frameworks found.');
585 }
586
587 /**
588 * Returns description of data_for_competency_frameworks_manage_page() parameters.
589 *
590 * @return external_function_parameters
591 */
592 public static function data_for_competency_frameworks_manage_page_parameters() {
593 // No params required.
594 $params = array();
595 return new external_function_parameters($params);
596 }
597
598 /**
599 * Expose to AJAX
600 * @return boolean
601 */
602 public static function data_for_competency_frameworks_manage_page_is_allowed_from_ajax() {
603 return true;
604 }
605
606 /**
607 * Loads the data required to render the competency_frameworks_manage_page template.
608 *
609 * @return boolean
610 */
611 public static function data_for_competency_frameworks_manage_page() {
612 global $PAGE;
613
614 $renderable = new \tool_lp\output\manage_competency_frameworks_page();
615 $renderer = $PAGE->get_renderer('tool_lp');
616
617 $data = $renderable->export_for_template($renderer);
618
619 return $data;
620 }
621
622 /**
623 * Returns description of data_for_competency_frameworks_manage_page() result value.
624 *
625 * @return external_description
626 */
627 public static function data_for_competency_frameworks_manage_page_returns() {
628 return new external_single_structure(array (
629 'canmanage' => new external_value(PARAM_BOOL, 'True if this user has permission to manage competency frameworks'),
630 'competencyframeworks' => new external_multiple_structure(
631 self::get_competency_framework_external_structure()
632 ),
633 'pluginbaseurl' => new external_value(PARAM_LOCALURL, 'Url to the tool_lp plugin folder on this Moodle site'),
634 'navigation' => new external_multiple_structure(
635 new external_value(PARAM_RAW, 'HTML for a navigation item that should be on this page')
636 )
637 ));
638
639 }
640
641 /**
642 * Move a competency framework and adjust sort order of all affected.
643 *
644 * @return external_function_parameters
645 */
646 public static function reorder_competency_framework_parameters() {
647 $from = new external_value(
648 PARAM_INT,
649 'Framework id to reorder.',
650 VALUE_REQUIRED
651 );
652 $to = new external_value(
653 PARAM_INT,
654 'Framework id to move to.',
655 VALUE_REQUIRED
656 );
657 $params = array(
658 'from' => $from,
659 'to' => $to
660 );
661 return new external_function_parameters($params);
662 }
663
664 /**
665 * Expose to AJAX
666 * @return boolean
667 */
668 public static function reorder_competency_framework_is_allowed_from_ajax() {
669 return true;
670 }
671
672 /**
673 * Move this competency_framework to a new relative sort order.
674 *
675 * @param int $from
676 * @param int $to
677 * @return boolean
678 */
679 public static function reorder_competency_framework($from, $to) {
680 $params = self::validate_parameters(self::reorder_competency_framework_parameters(),
681 array(
682 'from' => $from,
683 'to' => $to
684 ));
685 return api::reorder_framework($params['from'], $params['to']);
686 }
687
688 /**
689 * Returns description of reorder_competency_framework return value.
690 *
691 * @return external_description
692 */
693 public static function reorder_competency_framework_returns() {
694 return new external_value(PARAM_BOOL, 'True if this framework was moved.');
695 }
696
697 /**
698 * Returns the external structure of a full competency record.
699 *
700 * @return external_single_structure
701 */
702 protected static function get_competency_external_structure() {
703 $id = new external_value(
704 PARAM_INT,
705 'Database record id'
706 );
707 $shortname = new external_value(
708 PARAM_TEXT,
709 'Short name for the competency'
710 );
711 $idnumber = new external_value(
712 PARAM_TEXT,
713 'If provided, must be a unique string to identify this competency'
714 );
715 $description = new external_value(
716 PARAM_RAW,
717 'Description for the competency'
718 );
719 $descriptionformat = new external_format_value(
720 'Description format for the competency'
721 );
722 $descriptionformatted = new external_value(
723 PARAM_RAW,
724 'Description formatted for display'
725 );
726 $visible = new external_value(
727 PARAM_BOOL,
728 'Is this competency visible?'
729 );
730 $sortorder = new external_value(
731 PARAM_INT,
732 'Relative sort order of this competency'
733 );
734 $competencyframeworkid = new external_value(
735 PARAM_INT,
736 'Competency framework id that this competency belongs to'
737 );
738 $parentid = new external_value(
739 PARAM_INT,
740 'Parent competency id. 0 means top level node.'
741 );
742 $timecreated = new external_value(
743 PARAM_INT,
744 'Timestamp this record was created'
745 );
746 $timemodified = new external_value(
747 PARAM_INT,
748 'Timestamp this record was modified'
749 );
750 $usermodified = new external_value(
751 PARAM_INT,
752 'User who modified this record last'
753 );
754 $parentid = new external_value(
755 PARAM_INT,
756 'The id of the parent competency.'
757 );
758 $path = new external_value(
759 PARAM_RAW,
760 'The path of parents all the way to the root of the tree.'
761 );
762
763 $returns = array(
764 'id' => $id,
765 'shortname' => $shortname,
766 'idnumber' => $idnumber,
767 'description' => $description,
768 'descriptionformat' => $descriptionformat,
769 'descriptionformatted' => $descriptionformatted,
770 'visible' => $visible,
771 'sortorder' => $sortorder,
772 'timecreated' => $timecreated,
773 'timemodified' => $timemodified,
774 'usermodified' => $usermodified,
775 'parentid' => $parentid,
776 'competencyframeworkid' => $competencyframeworkid,
777 'path' => $path,
778 );
779 return new external_single_structure($returns);
780 }
781
782 /**
783 * Expose to AJAX
784 * @return boolean
785 */
786 public static function create_competency_is_allowed_from_ajax() {
787 return true;
788 }
789
790 /**
791 * Returns description of create_competency() parameters.
792 *
793 * @return external_function_parameters
794 */
795 public static function create_competency_parameters() {
796 $shortname = new external_value(
797 PARAM_TEXT,
798 'Short name for the competency framework.',
799 VALUE_REQUIRED
800 );
801 $idnumber = new external_value(
802 PARAM_TEXT,
803 'If provided, must be a unique string to identify this competency framework.',
804 VALUE_DEFAULT,
805 ''
806 );
807 $description = new external_value(
808 PARAM_RAW,
809 'Optional description for the framework',
810 VALUE_DEFAULT,
811 ''
812 );
813 $descriptionformat = new external_format_value(
814 'Optional description format for the framework',
815 VALUE_DEFAULT,
816 FORMAT_HTML
817 );
818 $visible = new external_value(
819 PARAM_BOOL,
820 'Is this competency visible?',
821 VALUE_DEFAULT,
822 true
823 );
824 $competencyframeworkid = new external_value(
825 PARAM_INT,
826 'Which competency framework does this competency belong to?'
827 );
828 $parentid = new external_value(
829 PARAM_INT,
830 'The parent competency. 0 means this is a top level competency.'
831 );
832
833 $params = array(
834 'shortname' => $shortname,
835 'idnumber' => $idnumber,
836 'description' => $description,
837 'descriptionformat' => $descriptionformat,
838 'visible' => $visible,
839 'competencyframeworkid' => $competencyframeworkid,
840 'parentid' => $parentid,
841 );
842 return new external_function_parameters($params);
843 }
844
845 /**
846 * Create a new competency framework
847 *
848 * @param string $shortname
849 * @param string $idnumber
850 * @param string $description
851 * @param int $descriptionformat
852 * @param bool $visible
853 * @param int $competencyframeworkid
854 * @param int $parentid
855 * @return string the template
856 */
857 public static function create_competency($shortname,
858 $idnumber,
859 $description,
860 $descriptionformat,
861 $visible,
862 $competencyframeworkid,
863 $parentid) {
864 $params = self::validate_parameters(self::create_competency_parameters(),
865 array(
866 'shortname' => $shortname,
867 'idnumber' => $idnumber,
868 'description' => $description,
869 'descriptionformat' => $descriptionformat,
870 'visible' => $visible,
871 'competencyframeworkid' => $competencyframeworkid,
872 'parentid' => $parentid,
873 ));
874
875 $params = (object) $params;
876
877 $result = api::create_competency($params);
878 return $result->to_record();
879 }
880
881 /**
882 * Returns description of create_competency() result value.
883 *
884 * @return external_description
885 */
886 public static function create_competency_returns() {
887 return self::get_competency_external_structure();
888 }
889
890 /**
891 * Returns description of read_competency() parameters.
892 *
893 * @return external_function_parameters
894 */
895 public static function read_competency_parameters() {
896 $id = new external_value(
897 PARAM_INT,
898 'Data base record id for the competency',
899 VALUE_REQUIRED
900 );
901
902 $params = array(
903 'id' => $id,
904 );
905 return new external_function_parameters($params);
906 }
907
908 /**
909 * Expose to AJAX
910 * @return boolean
911 */
912 public static function read_competency_is_allowed_from_ajax() {
913 return true;
914 }
915
916 /**
917 * Read a competency by id.
918 *
919 * @param int $id The id of the competency
920 * @return stdClass
921 */
922 public static function read_competency($id) {
923 $params = self::validate_parameters(self::read_competency_parameters(),
924 array(
925 'id' => $id,
926 ));
927
928 $result = api::read_competency($params['id']);
929 return $result->to_record();
930 }
931
932 /**
933 * Returns description of read_competency() result value.
934 *
935 * @return external_description
936 */
937 public static function read_competency_returns() {
938 return self::get_competency_external_structure();
939 }
940
941 /**
942 * Returns description of delete_competency() parameters.
943 *
944 * @return external_function_parameters
945 */
946 public static function delete_competency_parameters() {
947 $id = new external_value(
948 PARAM_INT,
949 'Data base record id for the competency',
950 VALUE_REQUIRED
951 );
952
953 $params = array(
954 'id' => $id,
955 );
956 return new external_function_parameters($params);
957 }
958
959 /**
960 * Expose to AJAX
961 * @return boolean
962 */
963 public static function delete_competency_is_allowed_from_ajax() {
964 return true;
965 }
966
967 /**
968 * Delete a competency
969 *
970 * @param int $id The competency id
971 * @return boolean
972 */
973 public static function delete_competency($id) {
974 $params = self::validate_parameters(self::delete_competency_parameters(),
975 array(
976 'id' => $id,
977 ));
978
979 return api::delete_competency($params['id']);
980 }
981
982 /**
983 * Returns description of delete_competency() result value.
984 *
985 * @return external_description
986 */
987 public static function delete_competency_returns() {
988 return new external_value(PARAM_BOOL, 'True if the delete was successful');
989 }
990
991 /**
992 * Returns description of update_competency() parameters.
993 *
994 * @return external_function_parameters
995 */
996 public static function update_competency_parameters() {
997 $id = new external_value(
998 PARAM_INT,
999 'Data base record id for the competency',
1000 VALUE_REQUIRED
1001 );
1002 $shortname = new external_value(
1003 PARAM_TEXT,
1004 'Short name for the competency.',
1005 VALUE_REQUIRED
1006 );
1007 $idnumber = new external_value(
1008 PARAM_TEXT,
1009 'If provided, must be a unique string to identify this competency.',
1010 VALUE_REQUIRED
1011 );
1012 $description = new external_value(
1013 PARAM_RAW,
1014 'Description for the framework',
1015 VALUE_REQUIRED
1016 );
1017 $descriptionformat = new external_format_value(
1018 'Description format for the framework',
1019 VALUE_REQUIRED
1020 );
1021 $visible = new external_value(
1022 PARAM_BOOL,
1023 'Is this framework visible?',
1024 VALUE_REQUIRED
1025 );
1026
1027 $params = array(
1028 'id' => $id,
1029 'shortname' => $shortname,
1030 'idnumber' => $idnumber,
1031 'description' => $description,
1032 'descriptionformat' => $descriptionformat,
1033 'visible' => $visible,
1034 );
1035 return new external_function_parameters($params);
1036 }
1037
1038 /**
1039 * Expose to AJAX
1040 * @return boolean
1041 */
1042 public static function update_competency_is_allowed_from_ajax() {
1043 return true;
1044 }
1045
1046 /**
1047 * Update an existing competency
1048 *
1049 * @param int $id The competency id
1050 * @param string $shortname
1051 * @param string $idnumber
1052 * @param string $description
1053 * @param int $descriptionformat
1054 * @param boolean $visible
1055 * @return boolean
1056 */
1057 public static function update_competency($id,
1058 $shortname,
1059 $idnumber,
1060 $description,
1061 $descriptionformat,
1062 $visible) {
1063
1064 $params = self::validate_parameters(self::update_competency_parameters(),
1065 array(
1066 'id' => $id,
1067 'shortname' => $shortname,
1068 'idnumber' => $idnumber,
1069 'description' => $description,
1070 'descriptionformat' => $descriptionformat,
1071 'visible' => $visible
1072 ));
1073 $params = (object) $params;
1074
1075 return api::update_competency($params);
1076 }
1077
1078 /**
1079 * Returns description of update_competency_framework() result value.
1080 *
1081 * @return external_description
1082 */
1083 public static function update_competency_returns() {
1084 return new external_value(PARAM_BOOL, 'True if the update was successful');
1085 }
1086
1087 /**
1088 * Returns description of list_competencies() parameters.
1089 *
1090 * @return external_function_parameters
1091 */
1092 public static function list_competencies_parameters() {
1093 return self::list_parameters_structure();
1094 }
1095
1096 /**
1097 * Expose to AJAX
1098 * @return boolean
1099 */
1100 public static function list_competencies_is_allowed_from_ajax() {
1101 return true;
1102 }
1103
1104 /**
1105 * List the existing competency frameworks
1106 *
1107 * @return boolean
1108 */
1109 public static function list_competencies($filters, $sort, $order, $skip, $limit) {
1110 $params = self::validate_parameters(self::list_competencies_parameters(),
1111 array(
1112 'filters' => $filters,
1113 'sort' => $sort,
1114 'order' => $order,
1115 'skip' => $skip,
1116 'limit' => $limit
1117 ));
1118
1119 if ($params['order'] !== '' && $params['order'] !== 'ASC' && $params['order'] !== 'DESC') {
1120 throw new invalid_parameter_exception('Invalid order param. Must be ASC, DESC or empty.');
1121 }
1122
1123 $safefilters = array();
1124 $validcolumns = array('id', 'shortname', 'description', 'sortorder', 'idnumber', 'visible', 'parentid', 'competencyframeworkid');
1125 foreach ($params['filters'] as $filter) {
1126 if (!in_array($filter->column, $validcolumns)) {
1127 throw new invalid_parameter_exception('Filter column was invalid');
1128 }
1129 $safefilters[$filter->column] = $filter->value;
1130 }
1131
1132 $results = api::list_competencies($safefilters,
1133 $params['sort'],
1134 $params['order'],
1135 $params['skip'],
1136 $params['limit']);
1137 $records = array();
1138 foreach ($results as $result) {
1139 $record = $result->to_record();
1140 array_push($records, $record);
1141 }
1142 return $records;
1143 }
1144
1145 /**
1146 * Returns description of list_competencies() result value.
1147 *
1148 * @return external_description
1149 */
1150 public static function list_competencies_returns() {
1151 return new external_multiple_structure(self::get_competency_external_structure());
1152 }
1153
1154 /**
1155 * Returns description of search_competencies() parameters.
1156 *
1157 * @return external_function_parameters
1158 */
1159 public static function search_competencies_parameters() {
1160 $searchtext = new external_value(
1161 PARAM_RAW,
1162 'Text to search for',
1163 VALUE_REQUIRED
1164 );
1165 $frameworkid = new external_value(
1166 PARAM_INT,
1167 'Competency framework id',
1168 VALUE_REQUIRED
1169 );
1170
1171 $params = array(
1172 'searchtext' => $searchtext,
1173 'competencyframeworkid' => $frameworkid
1174 );
1175 return new external_function_parameters($params);
1176 }
1177
1178 /**
1179 * Expose to AJAX
1180 * @return boolean
1181 */
1182 public static function search_competencies_is_allowed_from_ajax() {
1183 return true;
1184 }
1185
1186 /**
1187 * List the existing competency frameworks
1188 *
1189 * @return boolean
1190 */
1191 public static function search_competencies($searchtext, $competencyframeworkid) {
1192 $params = self::validate_parameters(self::search_competencies_parameters(),
1193 array(
1194 'searchtext' => $searchtext,
1195 'competencyframeworkid' => $competencyframeworkid
1196 ));
1197
1198 $results = api::search_competencies($searchtext, $competencyframeworkid);
1199 $records = array();
1200 foreach ($results as $result) {
1201 $record = $result->to_record();
1202 array_push($records, $record);
1203 }
1204 return $records;
1205 }
1206
1207 /**
1208 * Returns description of search_competencies() result value.
1209 *
1210 * @return external_description
1211 */
1212 public static function search_competencies_returns() {
1213 return new external_multiple_structure(self::get_competency_external_structure());
1214 }
1215
1216
1217 /**
1218 * Returns description of count_competencies() parameters.
1219 *
1220 * @return external_function_parameters
1221 */
1222 public static function count_competencies_parameters() {
1223 return self::count_parameters_structure();
1224 }
1225
1226 /**
1227 * Expose to AJAX
1228 * @return boolean
1229 */
1230 public static function count_competencies_is_allowed_from_ajax() {
1231 return true;
1232 }
1233
1234 /**
1235 * Count the existing competency frameworks
1236 *
1237 * @return boolean
1238 */
1239 public static function count_competencies($filters) {
1240 $params = self::validate_parameters(self::count_competencies_parameters(),
1241 array(
1242 'filters' => $filters
1243 ));
1244
1245 $safefilters = array();
1246 $validcolumns = array('id', 'shortname', 'description', 'sortorder', 'idnumber', 'visible', 'parentid', 'competencyframeworkid');
1247 foreach ($params['filters'] as $filter) {
1248 if (!in_array($filter->column, $validcolumns)) {
1249 throw new invalid_parameter_exception('Filter column was invalid');
1250 }
1251 $safefilters[$filter->column] = $filter->value;
1252 }
1253
1254 return api::count_competencies($safefilters);
1255 }
1256
1257 /**
1258 * Returns description of count_competencies() result value.
1259 *
1260 * @return external_description
1261 */
1262 public static function count_competencies_returns() {
1263 return new external_value(PARAM_INT, 'The number of competencies found.');
1264 }
1265
1266 /**
1267 * Returns description of data_for_competencies_manage_page() parameters.
1268 *
1269 * @return external_function_parameters
1270 */
1271 public static function data_for_competencies_manage_page_parameters() {
1272 $competencyframeworkid = new external_value(
1273 PARAM_INT,
1274 'The competency framework id',
1275 VALUE_REQUIRED
1276 );
1277 $search = new external_value(
1278 PARAM_RAW,
1279 'A search string',
1280 VALUE_DEFAULT,
1281 ''
1282 );
1283 $params = array(
1284 'competencyframeworkid' => $competencyframeworkid,
1285 'search' => $search
1286 );
1287 return new external_function_parameters($params);
1288 }
1289
1290 /**
1291 * Expose to AJAX
1292 * @return boolean
1293 */
1294 public static function data_for_competencies_manage_page_is_allowed_from_ajax() {
1295 return true;
1296 }
1297
1298 /**
1299 * Loads the data required to render the competencies_manage_page template.
1300 *
1301 * @return boolean
1302 */
1303 public static function data_for_competencies_manage_page($competencyframeworkid, $search) {
1304 global $PAGE;
1305 $params = self::validate_parameters(self::data_for_competencies_manage_page_parameters(),
1306 array(
1307 'competencyframeworkid' => $competencyframeworkid,
1308 'search' => $search
1309 ));
1310
1311 $framework = new \tool_lp\competency_framework($params['competencyframeworkid']);
1312
1313 $renderable = new \tool_lp\output\manage_competencies_page($framework, $params['search']);
1314 $renderer = $PAGE->get_renderer('tool_lp');
1315
1316 $data = $renderable->export_for_template($renderer);
1317
1318 return $data;
1319 }
1320
1321 /**
1322 * Returns description of data_for_competencies_manage_page() result value.
1323 *
1324 * @return external_description
1325 */
1326 public static function data_for_competencies_manage_page_returns() {
1327 return new external_single_structure(array (
1328 'framework' => self::get_competency_framework_external_structure(),
1329 'canmanage' => new external_value(PARAM_BOOL, 'True if this user has permission to manage competency frameworks'),
1330 'competencies' => new external_multiple_structure(
1331 self::get_competency_external_structure()
1332 )
1333 ));
1334
1335 }
1336
1337 /**
1338 * Returns description of set_parent_competency() parameters.
1339 *
1340 * @return external_function_parameters
1341 */
1342 public static function set_parent_competency_parameters() {
1343 $competencyid = new external_value(
1344 PARAM_INT,
1345 'The competency id',
1346 VALUE_REQUIRED
1347 );
1348 $parentid = new external_value(
1349 PARAM_INT,
1350 'The new competency parent id',
1351 VALUE_REQUIRED
1352 );
1353 $params = array(
1354 'competencyid' => $competencyid,
1355 'parentid' => $parentid
1356 );
1357 return new external_function_parameters($params);
1358 }
1359
1360 /**
1361 * Expose to AJAX
1362 * @return boolean
1363 */
1364 public static function set_parent_competency_is_allowed_from_ajax() {
1365 return true;
1366 }
1367
1368 /**
1369 * Move the competency to a new parent.
1370 *
1371 * @return boolean
1372 */
1373 public static function set_parent_competency($competencyid, $parentid) {
1374 global $PAGE;
1375 $params = self::validate_parameters(self::set_parent_competency_parameters(),
1376 array(
1377 'competencyid' => $competencyid,
1378 'parentid' => $parentid
1379 ));
1380
1381 return api::set_parent_competency($competencyid, $parentid);
1382 }
1383
1384 /**
1385 * Returns description of set_parent_competency() result value.
1386 *
1387 * @return external_description
1388 */
1389 public static function set_parent_competency_returns() {
1390 return new external_value(PARAM_BOOL, 'True if the update was successful');
1391 }
1392
1393 /**
1394 * Returns description of move_up_competency() parameters.
1395 *
1396 * @return external_function_parameters
1397 */
1398 public static function move_up_competency_parameters() {
1399 $competencyid = new external_value(
1400 PARAM_INT,
1401 'The competency id',
1402 VALUE_REQUIRED
1403 );
1404 $params = array(
1405 'id' => $competencyid,
1406 );
1407 return new external_function_parameters($params);
1408 }
1409
1410 /**
1411 * Expose to AJAX
1412 * @return boolean
1413 */
1414 public static function move_up_competency_is_allowed_from_ajax() {
1415 return true;
1416 }
1417
1418 /**
1419 * Change the sort order of a competency.
1420 *
1421 * @return boolean
1422 */
1423 public static function move_up_competency($competencyid) {
1424 global $PAGE;
1425 $params = self::validate_parameters(self::move_up_competency_parameters(),
1426 array(
1427 'id' => $competencyid,
1428 ));
1429
1430 return api::move_up_competency($params['id']);
1431 }
1432
1433 /**
1434 * Returns description of move_up_competency() result value.
1435 *
1436 * @return external_description
1437 */
1438 public static function move_up_competency_returns() {
1439 return new external_value(PARAM_BOOL, 'True if the update was successful');
1440 }
1441
1442 /**
1443 * Returns description of move_down_competency() parameters.
1444 *
1445 * @return external_function_parameters
1446 */
1447 public static function move_down_competency_parameters() {
1448 $competencyid = new external_value(
1449 PARAM_INT,
1450 'The competency id',
1451 VALUE_REQUIRED
1452 );
1453 $params = array(
1454 'id' => $competencyid,
1455 );
1456 return new external_function_parameters($params);
1457 }
1458
1459 /**
1460 * Expose to AJAX
1461 * @return boolean
1462 */
1463 public static function move_down_competency_is_allowed_from_ajax() {
1464 return true;
1465 }
1466
1467 /**
1468 * Change the sort order of a competency.
1469 *
1470 * @return boolean
1471 */
1472 public static function move_down_competency($competencyid) {
1473 global $PAGE;
1474 $params = self::validate_parameters(self::move_down_competency_parameters(),
1475 array(
1476 'id' => $competencyid,
1477 ));
1478
1479 return api::move_down_competency($params['id']);
1480 }
1481
1482 /**
1483 * Returns description of move_down_competency() result value.
1484 *
1485 * @return external_description
1486 */
1487 public static function move_down_competency_returns() {
1488 return new external_value(PARAM_BOOL, 'True if the update was successful');
1489 }
1490
1491 /**
1492 * Returns description of count_courses_using_competency() parameters.
1493 *
1494 * @return external_function_parameters
1495 */
1496 public static function count_courses_using_competency_parameters() {
1497 $competencyid = new external_value(
1498 PARAM_INT,
1499 'The competency id',
1500 VALUE_REQUIRED
1501 );
1502 $params = array(
1503 'id' => $competencyid,
1504 );
1505 return new external_function_parameters($params);
1506 }
1507
1508 /**
1509 * Expose to AJAX
1510 * @return boolean
1511 */
1512 public static function count_courses_using_competency_is_allowed_from_ajax() {
1513 return true;
1514 }
1515
1516 /**
1517 * Count the courses (visible to this user) that use this competency.
1518 *
1519 * @return int
1520 */
1521 public static function count_courses_using_competency($competencyid) {
1522 global $PAGE;
1523 $params = self::validate_parameters(self::count_courses_using_competency_parameters(),
1524 array(
1525 'id' => $competencyid,
1526 ));
1527
1528 return api::count_courses_using_competency($params['id']);
1529 }
1530
1531 /**
1532 * Returns description of count_courses_using_competency() result value.
1533 *
1534 * @return external_description
1535 */
1536 public static function count_courses_using_competency_returns() {
1537 return new external_value(PARAM_INT, 'The number of courses using this competency');
1538 }
1539
1540 /**
1541 * Returns description of list_courses_using_competency() parameters.
1542 *
1543 * @return external_function_parameters
1544 */
1545 public static function list_courses_using_competency_parameters() {
1546 $competencyid = new external_value(
1547 PARAM_INT,
1548 'The competency id',
1549 VALUE_REQUIRED
1550 );
1551 $params = array(
1552 'id' => $competencyid,
1553 );
1554 return new external_function_parameters($params);
1555 }
1556
1557 /**
1558 * Expose to AJAX
1559 * @return boolean
1560 */
1561 public static function list_courses_using_competency_is_allowed_from_ajax() {
1562 return true;
1563 }
1564
1565 /**
1566 * Count the courses (visible to this user) that use this competency.
1567 *
1568 * @return array
1569 */
1570 public static function list_courses_using_competency($competencyid) {
1571 global $PAGE;
1572 $params = self::validate_parameters(self::list_courses_using_competency_parameters(),
1573 array(
1574 'id' => $competencyid,
1575 ));
1576
1577 return api::list_courses_using_competency($params['id']);
1578 }
1579
1580 /**
1581 * Returns description of list_courses_using_competency() result value.
1582 *
1583 * @return external_description
1584 */
1585 public static function list_courses_using_competency_returns() {
1586 $id = new external_value(
1587 PARAM_INT,
1588 'Course id'
1589 );
1590 $visible = new external_value(
1591 PARAM_BOOL,
1592 'Is the course visible.'
1593 );
1594 $idnumber = new external_value(
1595 PARAM_TEXT,
1596 'Course id number'
1597 );
1598 $shortname = new external_value(
1599 PARAM_TEXT,
1600 'Course short name'
1601 );
1602 $shortnameformatted = new external_value(
1603 PARAM_RAW,
1604 'Shortname that has been formatted for display'
1605 );
1606 $fullname = new external_value(
1607 PARAM_TEXT,
1608 'Course fullname'
1609 );
1610 $fullnameformatted = new external_value(
1611 PARAM_RAW,
1612 'Fullname that has been formatted for display'
1613 );
1614
1615 $returns = array(
1616 'id' => $id,
1617 'shortname' => $shortname,
1618 'shortnameformatted' => $shortnameformatted,
1619 'idnumber' => $idnumber,
1620 'fullname' => $fullname,
1621 'fullnameformatted' => $fullnameformatted,
1622 'visible' => $visible
1623 );
1624 return new external_multiple_structure(new external_single_structure($returns));
1625 }
1626
1627 /**
1628 * Returns description of count_competencies_in_course() parameters.
1629 *
1630 * @return external_function_parameters
1631 */
1632 public static function count_competencies_in_course_parameters() {
1633 $courseid = new external_value(
1634 PARAM_INT,
1635 'The course id',
1636 VALUE_REQUIRED
1637 );
1638 $params = array(
1639 'id' => $courseid,
1640 );
1641 return new external_function_parameters($params);
1642 }
1643
1644 /**
1645 * Expose to AJAX
1646 * @return boolean
1647 */
1648 public static function count_competencies_in_course_is_allowed_from_ajax() {
1649 return true;
1650 }
1651
1652 /**
1653 * Count the competencies (visible to this user) in this course.
1654 *
1655 * @param int $couseid The course id to check.
1656 * @return int
1657 */
1658 public static function count_competencies_in_course($courseid) {
1659 global $PAGE;
1660 $params = self::validate_parameters(self::count_competencies_in_course_parameters(),
1661 array(
1662 'id' => $courseid,
1663 ));
1664
1665 return api::count_competencies_in_course($params['id']);
1666 }
1667
1668 /**
1669 * Returns description of count_competencies_in_course() result value.
1670 *
1671 * @return external_description
1672 */
1673 public static function count_competencies_in_course_returns() {
1674 return new external_value(PARAM_INT, 'The number of competencies in this course.');
1675 }
1676
1677 /**
1678 * Returns description of list_competencies_in_course() parameters.
1679 *
1680 * @return external_function_parameters
1681 */
1682 public static function list_competencies_in_course_parameters() {
1683 $courseid = new external_value(
1684 PARAM_INT,
1685 'The course id',
1686 VALUE_REQUIRED
1687 );
1688 $params = array(
1689 'id' => $courseid,
1690 );
1691 return new external_function_parameters($params);
1692 }
1693
1694 /**
1695 * Expose to AJAX
1696 * @return boolean
1697 */
1698 public static function list_competencies_in_course_is_allowed_from_ajax() {
1699 return true;
1700 }
1701
1702 /**
1703 * List the competencies (visible to this user) in this course.
1704 *
1705 * @return array
1706 */
1707 public static function list_competencies_in_course($courseid) {
1708 global $PAGE;
1709 $params = self::validate_parameters(self::list_competencies_in_course_parameters(),
1710 array(
1711 'id' => $courseid,
1712 ));
1713
1714 $competencies = api::list_competencies_in_course($params['id']);
1715 $results = array();
1716 foreach ($competencies as $competency) {
1717 $record = $competency->to_record();
1718 array_push($results, $record);
1719 }
1720 return $results;
1721 }
1722
1723 /**
1724 * Returns description of list_competencies_in_course() result value.
1725 *
1726 * @return external_description
1727 */
1728 public static function list_competencies_in_course_returns() {
1729 return new external_multiple_structure(self::get_competency_external_structure());
1730 }
1731
1732 /**
1733 * Returns description of add_competency_to_course() parameters.
1734 *
1735 * @return external_function_parameters
1736 */
1737 public static function add_competency_to_course_parameters() {
1738 $courseid = new external_value(
1739 PARAM_INT,
1740 'The course id',
1741 VALUE_REQUIRED
1742 );
1743 $competencyid = new external_value(
1744 PARAM_INT,
1745 'The competency id',
1746 VALUE_REQUIRED
1747 );
1748 $params = array(
1749 'courseid' => $courseid,
1750 'competencyid' => $competencyid,
1751 );
1752 return new external_function_parameters($params);
1753 }
1754
1755 /**
1756 * Expose to AJAX
1757 * @return boolean
1758 */
1759 public static function add_competency_to_course_is_allowed_from_ajax() {
1760 return true;
1761 }
1762
1763 /**
1764 * Count the competencies (visible to this user) in this course.
1765 *
1766 * @return int
1767 */
1768 public static function add_competency_to_course($courseid, $competencyid) {
1769 global $PAGE;
1770 $params = self::validate_parameters(self::add_competency_to_course_parameters(),
1771 array(
1772 'courseid' => $courseid,
1773 'competencyid' => $competencyid,
1774 ));
1775
1776 return api::add_competency_to_course($params['courseid'], $params['competencyid']);
1777 }
1778
1779 /**
1780 * Returns description of add_competency_to_course() result value.
1781 *
1782 * @return external_description
1783 */
1784 public static function add_competency_to_course_returns() {
1785 return new external_value(PARAM_BOOL, 'True if successful.');
1786 }
1787
1788 /**
1789 * Returns description of remove_competency_from_course() parameters.
1790 *
1791 * @return external_function_parameters
1792 */
1793 public static function remove_competency_from_course_parameters() {
1794 $courseid = new external_value(
1795 PARAM_INT,
1796 'The course id',
1797 VALUE_REQUIRED
1798 );
1799 $competencyid = new external_value(
1800 PARAM_INT,
1801 'The competency id',
1802 VALUE_REQUIRED
1803 );
1804 $params = array(
1805 'courseid' => $courseid,
1806 'competencyid' => $competencyid,
1807 );
1808 return new external_function_parameters($params);
1809 }
1810
1811 /**
1812 * Expose to AJAX
1813 * @return boolean
1814 */
1815 public static function remove_competency_from_course_is_allowed_from_ajax() {
1816 return true;
1817 }
1818
1819 /**
1820 * Count the competencies (visible to this user) in this course.
1821 *
1822 * @return int
1823 */
1824 public static function remove_competency_from_course($courseid, $competencyid) {
1825 $params = self::validate_parameters(self::remove_competency_from_course_parameters(),
1826 array(
1827 'courseid' => $courseid,
1828 'competencyid' => $competencyid,
1829 ));
1830
1831 return api::remove_competency_from_course($params['courseid'], $params['competencyid']);
1832 }
1833
1834 /**
1835 * Returns description of remove_competency_from_course() result value.
1836 *
1837 * @return external_description
1838 */
1839 public static function remove_competency_from_course_returns() {
1840 return new external_value(PARAM_BOOL, 'True if successful.');
1841 }
1842
1843 /**
1844 * Returns description of data_for_course_competenies_page() parameters.
1845 *
1846 * @return external_function_parameters
1847 */
1848 public static function data_for_course_competencies_page_parameters() {
1849 $courseid = new external_value(
1850 PARAM_INT,
1851 'The course id',
1852 VALUE_REQUIRED
1853 );
1854 $params = array('courseid' => $courseid);
1855 return new external_function_parameters($params);
1856 }
1857
1858 /**
1859 * Expose to AJAX
1860 * @return boolean
1861 */
1862 public static function data_for_course_competencies_page_is_allowed_from_ajax() {
1863 return true;
1864 }
1865
1866 /**
1867 * Loads the data required to render the course_competencies_page template.
1868 *
1869 * @return boolean
1870 */
1871 public static function data_for_course_competencies_page($courseid) {
1872 global $PAGE;
1873 $params = self::validate_parameters(self::data_for_course_competencies_page_parameters(),
1874 array(
1875 'courseid' => $courseid,
1876 ));
1877
1878 $renderable = new \tool_lp\output\course_competencies_page($params['courseid']);
1879 $renderer = $PAGE->get_renderer('tool_lp');
1880
1881 $data = $renderable->export_for_template($renderer);
1882
1883 return $data;
1884 }
1885
1886 /**
1887 * Returns description of data_for_course_competencies_page() result value.
1888 *
1889 * @return external_description
1890 */
1891 public static function data_for_course_competencies_page_returns() {
1892 return new external_single_structure(array (
1893 'courseid' => new external_value(PARAM_INT, 'The current course id'),
1894 'canmanagecompetencyframeworks' => new external_value(PARAM_BOOL, 'User can manage competency frameworks'),
1895 'canmanagecoursecompetencies' => new external_value(PARAM_BOOL, 'User can manage linked course competencies'),
1896 'competencies' => new external_multiple_structure(
1897 self::get_competency_external_structure()
1898 ),
1899 'manageurl' => new external_value(PARAM_LOCALURL, 'Url to the manage competencies page.'),
1900 ));
1901
1902 }
1903
1904 /**
1905 * Returns description of reorder_course_competency() parameters.
1906 *
1907 * @return external_function_parameters
1908 */
1909 public static function reorder_course_competency_parameters() {
1910 $courseid = new external_value(
1911 PARAM_INT,
1912 'The course id',
1913 VALUE_REQUIRED
1914 );
1915 $competencyidfrom = new external_value(
1916 PARAM_INT,
1917 'The competency id we are moving',
1918 VALUE_REQUIRED
1919 );
1920 $competencyidto = new external_value(
1921 PARAM_INT,
1922 'The competency id we are moving to',
1923 VALUE_REQUIRED
1924 );
1925 $params = array(
1926 'courseid' => $courseid,
1927 'competencyidfrom' => $competencyidfrom,
1928 'competencyidto' => $competencyidto,
1929 );
1930 return new external_function_parameters($params);
1931 }
1932
1933 /**
1934 * Expose to AJAX
1935 * @return boolean
1936 */
1937 public static function reorder_course_competency_is_allowed_from_ajax() {
1938 return true;
1939 }
1940
1941 /**
1942 * Change the order of course competencies.
1943 *
1944 * @param int $courseid The course id
1945 * @param int $competencyidfrom The competency to move.
1946 * @param int $competencyidto The competency to move to.
1947 * @return bool
1948 */
1949 public static function reorder_course_competency($courseid, $competencyidfrom, $competencyidto) {
1950 $params = self::validate_parameters(self::reorder_course_competency_parameters(),
1951 array(
1952 'courseid' => $courseid,
1953 'competencyidfrom' => $competencyidfrom,
1954 'competencyidto' => $competencyidto,
1955 ));
1956
1957 return api::reorder_course_competency($params['courseid'], $params['competencyidfrom'], $params['competencyidto']);
1958 }
1959
1960 /**
1961 * Returns description of reorder_course_competency() result value.
1962 *
1963 * @return external_description
1964 */
1965 public static function reorder_course_competency_returns() {
1966 return new external_value(PARAM_BOOL, 'True if successful.');
1967 }
1968
1969 /**
1970 * Returns the external structure of a full template record.
1971 *
1972 * @return external_single_structure
1973 */
1974 protected static function get_template_external_structure() {
1975 $id = new external_value(
1976 PARAM_INT,
1977 'Database record id'
1978 );
1979 $shortname = new external_value(
1980 PARAM_TEXT,
1981 'Short name for the learning plan template'
1982 );
1983 $idnumber = new external_value(
1984 PARAM_TEXT,
1985 'If provided, must be a unique string to identify this learning plan template'
1986 );
1987 $duedate = new external_value(
1988 PARAM_INT,
1989 'The default due date for instances of this plan.'
1990 );
1991 $duedateformatted = new external_value(
1992 PARAM_RAW,
1993 'Due date that has been formatted for display'
1994 );
1995 $description = new external_value(
1996 PARAM_RAW,
1997 'Description for the template'
1998 );
1999 $descriptionformat = new external_format_value(
2000 'Description format for the template'
2001 );
2002 $descriptionformatted = new external_value(
2003 PARAM_RAW,
2004 'Description that has been formatted for display'
2005 );
2006 $visible = new external_value(
2007 PARAM_BOOL,
2008 'Is this template visible?'
2009 );
2010 $sortorder = new external_value(
2011 PARAM_INT,
2012 'Relative sort order of this template'
2013 );
2014 $timecreated = new external_value(
2015 PARAM_INT,
2016 'Timestamp this record was created'
2017 );
2018 $timemodified = new external_value(
2019 PARAM_INT,
2020 'Timestamp this record was modified'
2021 );
2022 $usermodified = new external_value(
2023 PARAM_INT,
2024 'User who modified this record last'
2025 );
2026
2027 $returns = array(
2028 'id' => $id,
2029 'shortname' => $shortname,
2030 'idnumber' => $idnumber,
2031 'description' => $description,
2032 'descriptionformat' => $descriptionformat,
2033 'descriptionformatted' => $descriptionformatted,
2034 'visible' => $visible,
2035 'sortorder' => $sortorder,
2036 'timecreated' => $timecreated,
2037 'timemodified' => $timemodified,
2038 'usermodified' => $usermodified,
2039 );
2040 return new external_single_structure($returns);
2041 }
2042
2043 /**
2044 * Returns description of create_template() parameters.
2045 *
2046 * @return external_function_parameters
2047 */
2048 public static function create_template_parameters() {
2049 $shortname = new external_value(
2050 PARAM_TEXT,
2051 'Short name for the learning plan template.',
2052 VALUE_REQUIRED
2053 );
2054 $idnumber = new external_value(
2055 PARAM_TEXT,
2056 'If provided, must be a unique string to identify this learning plan template.',
2057 VALUE_DEFAULT,
2058 ''
2059 );
2060 $duedate = new external_value(
2061 PARAM_INT,
2062 'The default due date for instances of this plan',
2063 VALUE_DEFAULT,
2064 0
2065 );
2066 $description = new external_value(
2067 PARAM_RAW,
2068 'Optional description for the learning plan template',
2069 VALUE_DEFAULT,
2070 ''
2071 );
2072 $descriptionformat = new external_format_value(
2073 'Optional description format for the learning plan template',
2074 VALUE_DEFAULT,
2075 FORMAT_HTML
2076 );
2077 $visible = new external_value(
2078 PARAM_BOOL,
2079 'Is this learning plan template visible?',
2080 VALUE_DEFAULT,
2081 true
2082 );
2083
2084 $params = array(
2085 'shortname' => $shortname,
2086 'idnumber' => $idnumber,
2087 'duedate' => $duedate,
2088 'description' => $description,
2089 'descriptionformat' => $descriptionformat,
2090 'visible' => $visible,
2091 );
2092 return new external_function_parameters($params);
2093 }
2094
2095 /**
2096 * Expose to AJAX
2097 * @return boolean
2098 */
2099 public static function create_template_is_allowed_from_ajax() {
2100 return true;
2101 }
2102
2103 /**
2104 * Create a new learning plan template
2105 *
2106 * @param string $shortname The short name of the template.
2107 * @param string $idnumber The idnumber of the template.
2108 * @param int $duedate The due date for instances of this plan.
2109 * @param string $description The description of the template.
2110 * @param int $descriptionformat The format of the description
2111 * @param bool $visible Is this template visible.
2112 * @return stdClass Record of new template.
2113 */
2114 public static function create_template($shortname, $idnumber, $description, $descriptionformat, $visible) {
2115 $params = self::validate_parameters(self::create_template_parameters(),
2116 array(
2117 'shortname' => $shortname,
2118 'idnumber' => $idnumber,
2119 'duedate' => $duedate,
2120 'description' => $description,
2121 'descriptionformat' => $descriptionformat,
2122 'visible' => $visible,
2123 ));
2124
2125 $params = (object) $params;
2126
2127 $result = api::create_template($params);
2128 return $result->to_record();
2129 }
2130
2131 /**
2132 * Returns description of create_template() result value.
2133 *
2134 * @return external_description
2135 */
2136 public static function create_template_returns() {
2137 return self::get_template_external_structure();
2138 }
2139
2140 /**
2141 * Returns description of read_template() parameters.
2142 *
2143 * @return external_function_parameters
2144 */
2145 public static function read_template_parameters() {
2146 $id = new external_value(
2147 PARAM_INT,
2148 'Data base record id for the template',
2149 VALUE_REQUIRED
2150 );
2151
2152 $params = array(
2153 'id' => $id,
2154 );
2155 return new external_function_parameters($params);
2156 }
2157
2158 /**
2159 * Expose to AJAX
2160 * @return boolean
2161 */
2162 public static function read_template_is_allowed_from_ajax() {
2163 return true;
2164 }
2165
2166 /**
2167 * Read a learning plan template by id.
2168 *
2169 * @param int $id The id of the template.
2170 * @return stdClass
2171 */
2172 public static function read_template($id) {
2173 $params = self::validate_parameters(self::read_template_parameters(),
2174 array(
2175 'id' => $id,
2176 ));
2177
2178 $result = api::read_template($params['id']);
2179 return $result->to_record();
2180 }
2181
2182 /**
2183 * Returns description of read_template() result value.
2184 *
2185 * @return external_description
2186 */
2187 public static function read_template_returns() {
2188 return self::get_template_external_structure();
2189 }
2190
2191 /**
2192 * Returns description of delete_template() parameters.
2193 *
2194 * @return external_function_parameters
2195 */
2196 public static function delete_template_parameters() {
2197 $id = new external_value(
2198 PARAM_INT,
2199 'Data base record id for the template',
2200 VALUE_REQUIRED
2201 );
2202
2203 $params = array(
2204 'id' => $id,
2205 );
2206 return new external_function_parameters($params);
2207 }
2208
2209 /**
2210 * Expose to AJAX
2211 * @return boolean
2212 */
2213 public static function delete_template_is_allowed_from_ajax() {
2214 return true;
2215 }
2216
2217 /**
2218 * Delete a learning plan template
2219 *
2220 * @param int $id The learning plan template id
2221 * @return boolean
2222 */
2223 public static function delete_template($id) {
2224 $params = self::validate_parameters(self::delete_template_parameters(),
2225 array(
2226 'id' => $id,
2227 ));
2228
2229 return api::delete_template($params['id']);
2230 }
2231
2232 /**
2233 * Returns description of delete_template() result value.
2234 *
2235 * @return external_description
2236 */
2237 public static function delete_template_returns() {
2238 return new external_value(PARAM_BOOL, 'True if the delete was successful');
2239 }
2240
2241 /**
2242 * Returns description of update_template() parameters.
2243 *
2244 * @return external_function_parameters
2245 */
2246 public static function update_template_parameters() {
2247 $id = new external_value(
2248 PARAM_INT,
2249 'Data base record id for the template',
2250 VALUE_REQUIRED
2251 );
2252 $shortname = new external_value(
2253 PARAM_TEXT,
2254 'Short name for the learning plan template.',
2255 VALUE_REQUIRED
2256 );
2257 $idnumber = new external_value(
2258 PARAM_TEXT,
2259 'If provided, must be a unique string to identify this learning plan template.',
2260 VALUE_REQUIRED
2261 );
2262 $duedate = new external_value(
2263 PARAM_INT,
2264 'Default due date for instances of this plan',
2265 VALUE_REQUIRED
2266 );
2267 $description = new external_value(
2268 PARAM_RAW,
2269 'Description for the template',
2270 VALUE_REQUIRED
2271 );
2272 $descriptionformat = new external_format_value(
2273 'Description format for the template',
2274 VALUE_REQUIRED
2275 );
2276 $visible = new external_value(
2277 PARAM_BOOL,
2278 'Is this template visible?',
2279 VALUE_REQUIRED
2280 );
2281
2282 $params = array(
2283 'id' => $id,
2284 'shortname' => $shortname,
2285 'idnumber' => $idnumber,
2286 'duedate' => $duedate,
2287 'description' => $description,
2288 'descriptionformat' => $descriptionformat,
2289 'visible' => $visible,
2290 );
2291 return new external_function_parameters($params);
2292 }
2293
2294 /**
2295 * Expose to AJAX
2296 * @return boolean
2297 */
2298 public static function update_template_is_allowed_from_ajax() {
2299 return true;
2300 }
2301
2302 /**
2303 * Update an existing learning plan template
2304 *
2305 * @param int $id The learning plan template id
2306 * @param string $shortname
2307 * @param string $idnumber
2308 * @param int $duedate
2309 * @param string $description
2310 * @param int $descriptionformat
2311 * @param boolean $visible
2312 * @return boolean
2313 */
2314 public static function update_template($id,
2315 $shortname,
2316 $idnumber,
2317 $duedate,
2318 $description,
2319 $descriptionformat,
2320 $visible) {
2321
2322 $params = self::validate_parameters(self::update_template_parameters(),
2323 array(
2324 'id' => $id,
2325 'shortname' => $shortname,
2326 'idnumber' => $idnumber,
2327 'duedate' => $duedate,
2328 'description' => $description,
2329 'descriptionformat' => $descriptionformat,
2330 'visible' => $visible
2331 ));
2332 $params = (object) $params;
2333
2334 return api::update_template($params);
2335 }
2336
2337 /**
2338 * Returns description of update_template() result value.
2339 *
2340 * @return external_description
2341 */
2342 public static function update_template_returns() {
2343 return new external_value(PARAM_BOOL, 'True if the update was successful');
2344 }
2345
2346 /**
2347 * Returns description of list_templates() parameters.
2348 *
2349 * @return external_function_parameters
2350 */
2351 public static function list_templates_parameters() {
2352 return self::list_parameters_structure();
2353 }
2354
2355 /**
2356 * Expose to AJAX
2357 * @return boolean
2358 */
2359 public static function list_templates_is_allowed_from_ajax() {
2360 return true;
2361 }
2362
2363 /**
2364 * List the existing learning plan templates
2365 *
2366 * @return boolean
2367 */
2368 public static function list_templates($filters, $sort, $order, $skip, $limit) {
2369 $params = self::validate_parameters(self::list_templates_parameters(),
2370 array(
2371 'filters' => $filters,
2372 'sort' => $sort,
2373 'order' => $order,
2374 'skip' => $skip,
2375 'limit' => $limit
2376 ));
2377
2378 if ($params['order'] !== '' && $params['order'] !== 'ASC' && $params['order'] !== 'DESC') {
2379 throw new invalid_parameter_exception('Invalid order param. Must be ASC, DESC or empty.');
2380 }
2381
2382 $safefilters = array();
2383 $validcolumns = array('id', 'shortname', 'description', 'sortorder', 'idnumber', 'visible');
2384 foreach ($params['filters'] as $filter) {
2385 if (!in_array($filter->column, $validcolumns)) {
2386 throw new invalid_parameter_exception('Filter column was invalid');
2387 }
2388 $safefilters[$filter->column] = $filter->value;
2389 }
2390
2391 $results = api::list_templates($safefilters,
2392 $params['sort'],
2393 $params['order'],
2394 $params['skip'],
2395 $params['limit']);
2396 $records = array();
2397 foreach ($results as $result) {
2398 $record = $result->to_record();
2399 array_push($records, $record);
2400 }
2401 return $records;
2402 }
2403
2404 /**
2405 * Returns description of list_templates() result value.
2406 *
2407 * @return external_description
2408 */
2409 public static function list_templates_returns() {
2410 return new external_multiple_structure(self::get_template_external_structure());
2411 }
2412
2413 /**
2414 * Returns description of count_templates() parameters.
2415 *
2416 * @return external_function_parameters
2417 */
2418 public static function count_templates_parameters() {
2419 $filters = new external_multiple_structure(new external_single_structure(
2420 array(
2421 'column' => new external_value(PARAM_ALPHANUMEXT, 'Column name to filter by'),
2422 'value' => new external_value(PARAM_TEXT, 'Value to filter by. Must be exact match')
2423 )
2424 ));
2425
2426 $params = array(
2427 'filters' => $filters,
2428 );
2429 return new external_function_parameters($params);
2430 }
2431
2432 /**
2433 * Expose to AJAX
2434 * @return boolean
2435 */
2436 public static function count_templates_is_allowed_from_ajax() {
2437 return true;
2438 }
2439
2440 /**
2441 * Count the existing learning plan templates
2442 *
2443 * @return boolean
2444 */
2445 public static function count_templates($filters) {
2446 $params = self::validate_parameters(self::count_templates_parameters(),
2447 array(
2448 'filters' => $filters
2449 ));
2450
2451 $safefilters = array();
2452 $validcolumns = array('id', 'shortname', 'description', 'sortorder', 'idnumber', 'visible');
2453 foreach ($params['filters'] as $filter) {
2454 if (!in_array($filter->column, $validcolumns)) {
2455 throw new invalid_parameter_exception('Filter column was invalid');
2456 }
2457 $safefilters[$filter->column] = $filter->value;
2458 }
2459
2460 return api::count_templates($safefilters);
2461 }
2462
2463 /**
2464 * Returns description of count_templates() result value.
2465 *
2466 * @return external_description
2467 */
2468 public static function count_templates_returns() {
2469 return new external_value(PARAM_INT, 'The number of learning plan templates found.');
2470 }
2471
2472 /**
2473 * Move a learning plan template and adjust sort order of all affected.
2474 *
2475 * @return external_function_parameters
2476 */
2477 public static function reorder_template_parameters() {
2478 $from = new external_value(
2479 PARAM_INT,
2480 'Template id to reorder.',
2481 VALUE_REQUIRED
2482 );
2483 $to = new external_value(
2484 PARAM_INT,
2485 'Template id to move to.',
2486 VALUE_REQUIRED
2487 );
2488 $params = array(
2489 'from' => $from,
2490 'to' => $to
2491 );
2492 return new external_function_parameters($params);
2493 }
2494
2495 /**
2496 * Expose to AJAX
2497 * @return boolean
2498 */
2499 public static function reorder_template_is_allowed_from_ajax() {
2500 return true;
2501 }
2502
2503 /**
2504 * Move this template to a new relative sort order.
2505 *
2506 * @param int $from
2507 * @param int $to
2508 * @return boolean
2509 */
2510 public static function reorder_template($from, $to) {
2511 $params = self::validate_parameters(self::reorder_template_parameters(),
2512 array(
2513 'from' => $from,
2514 'to' => $to
2515 ));
2516 return api::reorder_template($params['from'], $params['to']);
2517 }
2518
2519 /**
2520 * Returns description of reorder_template return value.
2521 *
2522 * @return external_description
2523 */
2524 public static function reorder_template_returns() {
2525 return new external_value(PARAM_BOOL, 'True if this template was moved.');
2526 }
2527
2528 /**
2529 * Returns description of data_for_templates_manage_page() parameters.
2530 *
2531 * @return external_function_parameters
2532 */
2533 public static function data_for_templates_manage_page_parameters() {
2534 // No params required.
2535 $params = array();
2536 return new external_function_parameters($params);
2537 }
2538
2539 /**
2540 * Expose to AJAX
2541 * @return boolean
2542 */
2543 public static function data_for_templates_manage_page_is_allowed_from_ajax() {
2544 return true;
2545 }
2546
2547 /**
2548 * Loads the data required to render the templates_manage_page template.
2549 *
2550 * @return boolean
2551 */
2552 public static function data_for_templates_manage_page() {
2553 global $PAGE;
2554
2555 $renderable = new \tool_lp\output\manage_templates_page();
2556 $renderer = $PAGE->get_renderer('tool_lp');
2557
2558 $data = $renderable->export_for_template($renderer);
2559
2560 return $data;
2561 }
2562
2563 /**
2564 * Returns description of data_for_templates_manage_page() result value.
2565 *
2566 * @return external_description
2567 */
2568 public static function data_for_templates_manage_page_returns() {
2569 return new external_single_structure(array (
2570 'canmanage' => new external_value(PARAM_BOOL, 'True if this user has permission to manage learning plan templates'),
2571 'templates' => new external_multiple_structure(
2572 self::get_template_external_structure()
2573 ),
2574 'pluginbaseurl' => new external_value(PARAM_LOCALURL, 'Url to the tool_lp plugin folder on this Moodle site'),
2575 'navigation' => new external_multiple_structure(
2576 new external_value(PARAM_RAW, 'HTML for a navigation item that should be on this page')
2577 )
2578 ));
2579
2580 }
2581
2582 /**
2583 * Returns description of count_templates_using_competency() parameters.
2584 *
2585 * @return external_function_parameters
2586 */
2587 public static function count_templates_using_competency_parameters() {
2588 $competencyid = new external_value(
2589 PARAM_INT,
2590 'The competency id',
2591 VALUE_REQUIRED
2592 );
2593 $params = array(
2594 'id' => $competencyid,
2595 );
2596 return new external_function_parameters($params);
2597 }
2598
2599 /**
2600 * Expose to AJAX
2601 * @return boolean
2602 */
2603 public static function count_templates_using_competency_is_allowed_from_ajax() {
2604 return true;
2605 }
2606
2607 /**
2608 * Count the learning plan templates (visible to this user) that use this competency.
2609 *
2610 * @return int
2611 */
2612 public static function count_templates_using_competency($competencyid) {
2613 global $PAGE;
2614 $params = self::validate_parameters(self::count_templates_using_competency_parameters(),
2615 array(
2616 'id' => $competencyid,
2617 ));
2618
2619 return api::count_templates_using_competency($params['id']);
2620 }
2621
2622 /**
2623 * Returns description of count_templates_using_competency() result value.
2624 *
2625 * @return external_description
2626 */
2627 public static function count_templates_using_competency_returns() {
2628 return new external_value(PARAM_INT, 'The number of learning plan templates using this competency');
2629 }
2630
2631 /**
2632 * Returns description of list_templates_using_competency() parameters.
2633 *
2634 * @return external_function_parameters
2635 */
2636 public static function list_templates_using_competency_parameters() {
2637 $competencyid = new external_value(
2638 PARAM_INT,
2639 'The competency id',
2640 VALUE_REQUIRED
2641 );
2642 $params = array(
2643 'id' => $competencyid,
2644 );
2645 return new external_function_parameters($params);
2646 }
2647
2648 /**
2649 * Expose to AJAX
2650 * @return boolean
2651 */
2652 public static function list_templates_using_competency_is_allowed_from_ajax() {
2653 return true;
2654 }
2655
2656 /**
2657 * List the learning plan templates (visible to this user) that use this competency.
2658 *
2659 * @return array
2660 */
2661 public static function list_templates_using_competency($competencyid) {
2662 global $PAGE;
2663 $params = self::validate_parameters(self::list_templates_using_competency_parameters(),
2664 array(
2665 'id' => $competencyid,
2666 ));
2667
2668 return api::list_templates_using_competency($params['id']);
2669 }
2670
2671 /**
2672 * Returns description of list_templates_using_competency() result value.
2673 *
2674 * @return external_description
2675 */
2676 public static function list_templates_using_competency_returns() {
2677 return new external_multiple_structure(self::get_template_external_structure());
2678 }
2679
2680 /**
2681 * Returns description of count_competencies_in_template() parameters.
2682 *
2683 * @return external_function_parameters
2684 */
2685 public static function count_competencies_in_template_parameters() {
2686 $templateid = new external_value(
2687 PARAM_INT,
2688 'The template id',
2689 VALUE_REQUIRED
2690 );
2691 $params = array(
2692 'id' => $templateid,
2693 );
2694 return new external_function_parameters($params);
2695 }
2696
2697 /**
2698 * Expose to AJAX
2699 * @return boolean
2700 */
2701 public static function count_competencies_in_template_is_allowed_from_ajax() {
2702 return true;
2703 }
2704
2705 /**
2706 * Count the competencies (visible to this user) in this learning plan template.
2707 *
2708 * @param int $templateid The template id to check
2709 * @return int
2710 */
2711 public static function count_competencies_in_template($templateid) {
2712 global $PAGE;
2713 $params = self::validate_parameters(self::count_competencies_in_template_parameters(),
2714 array(
2715 'id' => $templateid,
2716 ));
2717
2718 return api::count_competencies_in_template($params['id']);
2719 }
2720
2721 /**
2722 * Returns description of count_competencies_in_template() result value.
2723 *
2724 * @return external_description
2725 */
2726 public static function count_competencies_in_template_returns() {
2727 return new external_value(PARAM_INT, 'The number of competencies in this learning plan template.');
2728 }
2729
2730 /**
2731 * Returns description of list_competencies_in_template() parameters.
2732 *
2733 * @return external_function_parameters
2734 */
2735 public static function list_competencies_in_template_parameters() {
2736 $templateid = new external_value(
2737 PARAM_INT,
2738 'The template id',
2739 VALUE_REQUIRED
2740 );
2741 $params = array(
2742 'id' => $courseid,
2743 );
2744 return new external_function_parameters($params);
2745 }
2746
2747 /**
2748 * Expose to AJAX
2749 * @return boolean
2750 */
2751 public static function list_competencies_in_template_is_allowed_from_ajax() {
2752 return true;
2753 }
2754
2755 /**
2756 * List the competencies (visible to this user) in this learning plan template.
2757 *
2758 * @return array
2759 */
2760 public static function list_competencies_in_template($templateid) {
2761 global $PAGE;
2762 $params = self::validate_parameters(self::list_competencies_in_template_parameters(),
2763 array(
2764 'id' => $templateid,
2765 ));
2766
2767 $competencies = api::list_competencies_in_template($params['id']);
2768 $results = array();
2769 foreach ($competencies as $competency) {
2770 $record = $competency->to_record();
2771 array_push($results, $record);
2772 }
2773 return $results;
2774 }
2775
2776 /**
2777 * Returns description of list_competencies_in_template() result value.
2778 *
2779 * @return external_description
2780 */
2781 public static function list_competencies_in_template_returns() {
2782 return new external_multiple_structure(self::get_competency_external_structure());
2783 }
2784
2785 /**
2786 * Returns description of add_competency_to_template() parameters.
2787 *
2788 * @return external_function_parameters
2789 */
2790 public static function add_competency_to_template_parameters() {
2791 $templateid = new external_value(
2792 PARAM_INT,
2793 'The template id',
2794 VALUE_REQUIRED
2795 );
2796 $competencyid = new external_value(
2797 PARAM_INT,
2798 'The competency id',
2799 VALUE_REQUIRED
2800 );
2801 $params = array(
2802 'templateid' => $templateid,
2803 'competencyid' => $competencyid,
2804 );
2805 return new external_function_parameters($params);
2806 }
2807
2808 /**
2809 * Expose to AJAX
2810 * @return boolean
2811 */
2812 public static function add_competency_to_template_is_allowed_from_ajax() {
2813 return true;
2814 }
2815
2816 /**
2817 * Count the competencies (visible to this user) in this template.
2818 *
2819 * @return int
2820 */
2821 public static function add_competency_to_template($templateid, $competencyid) {
2822 global $PAGE;
2823 $params = self::validate_parameters(self::add_competency_to_template_parameters(),
2824 array(
2825 'templateid' => $templateid,
2826 'competencyid' => $competencyid,
2827 ));
2828
2829 return api::add_competency_to_template($params['templateid'], $params['competencyid']);
2830 }
2831
2832 /**
2833 * Returns description of add_competency_to_template() result value.
2834 *
2835 * @return external_description
2836 */
2837 public static function add_competency_to_template_returns() {
2838 return new external_value(PARAM_BOOL, 'True if successful.');
2839 }
2840
2841 /**
2842 * Returns description of remove_competency_from_template() parameters.
2843 *
2844 * @return external_function_parameters
2845 */
2846 public static function remove_competency_from_template_parameters() {
2847 $templateid = new external_value(
2848 PARAM_INT,
2849 'The template id',
2850 VALUE_REQUIRED
2851 );
2852 $competencyid = new external_value(
2853 PARAM_INT,
2854 'The competency id',
2855 VALUE_REQUIRED
2856 );
2857 $params = array(
2858 'templateid' => $templateid,
2859 'competencyid' => $competencyid,
2860 );
2861 return new external_function_parameters($params);
2862 }
2863
2864 /**
2865 * Expose to AJAX
2866 * @return boolean
2867 */
2868 public static function remove_competency_from_template_is_allowed_from_ajax() {
2869 return true;
2870 }
2871
2872 /**
2873 * Count the competencies (visible to this user) in this learning plan template.
2874 *
2875 * @return int
2876 */
2877 public static function remove_competency_from_template($templateid, $competencyid) {
2878 $params = self::validate_parameters(self::remove_competency_from_template_parameters(),
2879 array(
2880 'templateid' => $templateid,
2881 'competencyid' => $competencyid,
2882 ));
2883
2884 return api::remove_competency_from_template($params['templateid'], $params['competencyid']);
2885 }
2886
2887 /**
2888 * Returns description of remove_competency_from_template() result value.
2889 *
2890 * @return external_description
2891 */
2892 public static function remove_competency_from_template_returns() {
2893 return new external_value(PARAM_BOOL, 'True if successful.');
2894 }
2895
2896 /**
2897 * Returns description of data_for_template_competenies_page() parameters.
2898 *
2899 * @return external_function_parameters
2900 */
2901 public static function data_for_template_competencies_page_parameters() {
2902 $templateid = new external_value(
2903 PARAM_INT,
2904 'The template id',
2905 VALUE_REQUIRED
2906 );
2907 $params = array('templateid' => $templateid);
2908 return new external_function_parameters($params);
2909 }
2910
2911 /**
2912 * Expose to AJAX
2913 * @return boolean
2914 */
2915 public static function data_for_template_competencies_page_is_allowed_from_ajax() {
2916 return true;
2917 }
2918
2919 /**
2920 * Loads the data required to render the template_competencies_page template.
2921 *
2922 * @return boolean
2923 */
2924 public static function data_for_template_competencies_page($templateid) {
2925 global $PAGE;
2926 $params = self::validate_parameters(self::data_for_template_competencies_page_parameters(),
2927 array(
2928 'templateid' => $templateid,
2929 ));
2930
2931 $renderable = new \tool_lp\output\template_competencies_page($params['templateid']);
2932 $renderer = $PAGE->get_renderer('tool_lp');
2933
2934 $data = $renderable->export_for_template($renderer);
2935
2936 return $data;
2937 }
2938
2939 /**
2940 * Returns description of data_for_template_competencies_page() result value.
2941 *
2942 * @return external_description
2943 */
2944 public static function data_for_template_competencies_page_returns() {
2945 return new external_single_structure(array (
2946 'templateid' => new external_value(PARAM_INT, 'The current template id'),
2947 'canmanagecompetencyframeworks' => new external_value(PARAM_BOOL, 'User can manage competency frameworks'),
2948 'canmanagetemplates' => new external_value(PARAM_BOOL, 'User can manage learning plan templates'),
2949 'competencies' => new external_multiple_structure(
2950 self::get_competency_external_structure()
2951 ),
2952 'manageurl' => new external_value(PARAM_LOCALURL, 'Url to the manage competencies page.'),
2953 ));
2954
2955 }
2956}