Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402] [Versions 402 and 403]
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 */ 24 namespace tool_lp; 25 defined('MOODLE_INTERNAL') || die(); 26 27 require_once("$CFG->libdir/grade/grade_scale.php"); 28 29 use context_course; 30 use context_system; 31 use context_user; 32 use core_competency\api; 33 use core_competency\external\competency_exporter; 34 use core_competency\external\competency_framework_exporter; 35 use core_competency\external\course_competency_exporter; 36 use core_competency\external\course_competency_settings_exporter; 37 use core_competency\external\plan_exporter; 38 use core_competency\external\template_exporter; 39 use core_competency\external\user_competency_course_exporter; 40 use core_competency\external\user_competency_exporter; 41 use core_competency\external\user_competency_plan_exporter; 42 use core_course\external\course_module_summary_exporter; 43 use core_course\external\course_summary_exporter; 44 use core_external\external_api; 45 use core_external\external_description; 46 use core_external\external_function_parameters; 47 use core_external\external_multiple_structure; 48 use core_external\external_single_structure; 49 use core_external\external_value; 50 use core_user\external\user_summary_exporter; 51 use tool_lp\external\competency_path_exporter; 52 use tool_lp\external\competency_summary_exporter; 53 use tool_lp\external\course_competency_statistics_exporter; 54 use tool_lp\external\template_statistics_exporter; 55 use tool_lp\external\user_competency_summary_exporter; 56 use tool_lp\external\user_competency_summary_in_course_exporter; 57 use tool_lp\external\user_competency_summary_in_plan_exporter; 58 use tool_lp\external\user_evidence_summary_exporter; 59 use tool_lp\output\user_competency_summary_in_course; 60 use tool_lp\output\user_competency_summary_in_plan; 61 62 /** 63 * This is the external API for this tool. 64 * 65 * @copyright 2015 Damyon Wiese 66 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 67 */ 68 class external extends external_api { 69 70 /** 71 * Returns a prepared structure to use a context parameters. 72 * @return external_single_structure 73 */ 74 protected static function get_context_parameters() { 75 $id = new external_value( 76 PARAM_INT, 77 'Context ID. Either use this value, or level and instanceid.', 78 VALUE_DEFAULT, 79 0 80 ); 81 $level = new external_value( 82 PARAM_ALPHA, 83 'Context level. To be used with instanceid.', 84 VALUE_DEFAULT, 85 '' 86 ); 87 $instanceid = new external_value( 88 PARAM_INT, 89 'Context instance ID. To be used with level', 90 VALUE_DEFAULT, 91 0 92 ); 93 return new external_single_structure(array( 94 'contextid' => $id, 95 'contextlevel' => $level, 96 'instanceid' => $instanceid, 97 )); 98 } 99 100 /** 101 * Returns description of data_for_competency_frameworks_manage_page() parameters. 102 * 103 * @return external_function_parameters 104 */ 105 public static function data_for_competency_frameworks_manage_page_parameters() { 106 $params = array('pagecontext' => self::get_context_parameters()); 107 return new external_function_parameters($params); 108 } 109 110 /** 111 * Loads the data required to render the competency_frameworks_manage_page template. 112 * 113 * @param \context $pagecontext The page context 114 * @return \stdClass 115 */ 116 public static function data_for_competency_frameworks_manage_page($pagecontext) { 117 global $PAGE; 118 119 $params = self::validate_parameters( 120 self::data_for_competency_frameworks_manage_page_parameters(), 121 array( 122 'pagecontext' => $pagecontext 123 ) 124 ); 125 $context = self::get_context_from_params($params['pagecontext']); 126 self::validate_context($context); 127 128 $renderable = new output\manage_competency_frameworks_page($context); 129 $renderer = $PAGE->get_renderer('tool_lp'); 130 131 $data = $renderable->export_for_template($renderer); 132 133 return $data; 134 } 135 136 /** 137 * Returns description of data_for_competency_frameworks_manage_page() result value. 138 * 139 * @return external_description 140 */ 141 public static function data_for_competency_frameworks_manage_page_returns() { 142 return new external_single_structure(array ( 143 'competencyframeworks' => new external_multiple_structure( 144 competency_framework_exporter::get_read_structure() 145 ), 146 'pluginbaseurl' => new external_value(PARAM_LOCALURL, 'Url to the tool_lp plugin folder on this Moodle site'), 147 'navigation' => new external_multiple_structure( 148 new external_value(PARAM_RAW, 'HTML for a navigation item that should be on this page') 149 ), 150 'pagecontextid' => new external_value(PARAM_INT, 'The page context id') 151 )); 152 153 } 154 155 /** 156 * Returns description of data_for_competencies_manage_page() parameters. 157 * 158 * @return external_function_parameters 159 */ 160 public static function data_for_competencies_manage_page_parameters() { 161 $competencyframeworkid = new external_value( 162 PARAM_INT, 163 'The competency framework id', 164 VALUE_REQUIRED 165 ); 166 $search = new external_value( 167 PARAM_RAW, 168 'A search string', 169 VALUE_DEFAULT, 170 '' 171 ); 172 $params = array( 173 'competencyframeworkid' => $competencyframeworkid, 174 'search' => $search 175 ); 176 return new external_function_parameters($params); 177 } 178 179 /** 180 * Loads the data required to render the competencies_manage_page template. 181 * 182 * @param int $competencyframeworkid Framework id. 183 * @param string $search Text to search. 184 * 185 * @return boolean 186 */ 187 public static function data_for_competencies_manage_page($competencyframeworkid, $search) { 188 global $PAGE; 189 190 $params = self::validate_parameters(self::data_for_competencies_manage_page_parameters(), array( 191 'competencyframeworkid' => $competencyframeworkid, 192 'search' => $search 193 )); 194 195 $framework = api::read_framework($params['competencyframeworkid']); 196 self::validate_context($framework->get_context()); 197 $output = $PAGE->get_renderer('tool_lp'); 198 199 $renderable = new output\manage_competencies_page($framework, $params['search'], $framework->get_context(), null); 200 201 $data = $renderable->export_for_template($output); 202 203 return $data; 204 } 205 206 /** 207 * Returns description of data_for_competencies_manage_page() result value. 208 * 209 * @return external_description 210 */ 211 public static function data_for_competencies_manage_page_returns() { 212 return new external_single_structure(array ( 213 'framework' => competency_framework_exporter::get_read_structure(), 214 'canmanage' => new external_value(PARAM_BOOL, 'True if this user has permission to manage competency frameworks'), 215 'pagecontextid' => new external_value(PARAM_INT, 'Context id for the framework'), 216 'search' => new external_value(PARAM_RAW, 'Current search string'), 217 'rulesmodules' => new external_value(PARAM_RAW, 'JSON encoded data for rules'), 218 'pluginbaseurl' => new external_value(PARAM_RAW, 'Plugin base url') 219 )); 220 221 } 222 223 /** 224 * Returns description of data_for_competency_summary() parameters. 225 * 226 * @return external_function_parameters 227 */ 228 public static function data_for_competency_summary_parameters() { 229 $competencyid = new external_value( 230 PARAM_INT, 231 'The competency id', 232 VALUE_REQUIRED 233 ); 234 $includerelated = new external_value( 235 PARAM_BOOL, 236 'Include or not related competencies', 237 VALUE_DEFAULT, 238 false 239 ); 240 $includecourses = new external_value( 241 PARAM_BOOL, 242 'Include or not competency courses', 243 VALUE_DEFAULT, 244 false 245 ); 246 $params = array( 247 'competencyid' => $competencyid, 248 'includerelated' => $includerelated, 249 'includecourses' => $includecourses 250 ); 251 return new external_function_parameters($params); 252 } 253 254 /** 255 * Loads the data required to render the competency_page template. 256 * 257 * @param int $competencyid Competency id. 258 * @param boolean $includerelated Include or not related competencies. 259 * @param boolean $includecourses Include or not competency courses. 260 * 261 * @return \stdClass 262 */ 263 public static function data_for_competency_summary($competencyid, $includerelated = false, $includecourses = false) { 264 global $PAGE; 265 $params = self::validate_parameters(self::data_for_competency_summary_parameters(), array( 266 'competencyid' => $competencyid, 267 'includerelated' => $includerelated, 268 'includecourses' => $includecourses 269 )); 270 271 $competency = api::read_competency($params['competencyid']); 272 $framework = api::read_framework($competency->get('competencyframeworkid')); 273 self::validate_context($framework->get_context()); 274 $renderable = new output\competency_summary($competency, $framework, $params['includerelated'], $params['includecourses']); 275 $renderer = $PAGE->get_renderer('tool_lp'); 276 277 $data = $renderable->export_for_template($renderer); 278 279 return $data; 280 } 281 282 /** 283 * Returns description of data_for_competency_summary_() result value. 284 * 285 * @return external_description 286 */ 287 public static function data_for_competency_summary_returns() { 288 return competency_summary_exporter::get_read_structure(); 289 } 290 291 /** 292 * Returns description of list_courses_using_competency() parameters. 293 * 294 * @return external_function_parameters 295 */ 296 public static function list_courses_using_competency_parameters() { 297 $competencyid = new external_value( 298 PARAM_INT, 299 'The competency id', 300 VALUE_REQUIRED 301 ); 302 $params = array( 303 'id' => $competencyid, 304 ); 305 return new external_function_parameters($params); 306 } 307 308 /** 309 * Count the courses (visible to this user) that use this competency. 310 * 311 * @param int $competencyid Competency id. 312 * @return array 313 */ 314 public static function list_courses_using_competency($competencyid) { 315 global $PAGE; 316 317 $params = self::validate_parameters(self::list_courses_using_competency_parameters(), array( 318 'id' => $competencyid, 319 )); 320 321 $competency = api::read_competency($params['id']); 322 self::validate_context($competency->get_context()); 323 $output = $PAGE->get_renderer('tool_lp'); 324 325 $results = array(); 326 $courses = api::list_courses_using_competency($params['id']); 327 foreach ($courses as $course) { 328 $context = context_course::instance($course->id); 329 $exporter = new course_summary_exporter($course, array('context' => $context)); 330 $result = $exporter->export($output); 331 array_push($results, $result); 332 } 333 return $results; 334 } 335 336 /** 337 * Returns description of list_courses_using_competency() result value. 338 * 339 * @return external_description 340 */ 341 public static function list_courses_using_competency_returns() { 342 return new external_multiple_structure(course_summary_exporter::get_read_structure()); 343 } 344 345 346 /** 347 * Returns description of data_for_course_competenies_page() parameters. 348 * 349 * @return external_function_parameters 350 */ 351 public static function data_for_course_competencies_page_parameters() { 352 $courseid = new external_value( 353 PARAM_INT, 354 'The course id', 355 VALUE_REQUIRED 356 ); 357 $moduleid = new external_value( 358 PARAM_INT, 359 'The module id', 360 VALUE_DEFAULT, 361 0 362 ); 363 $params = array('courseid' => $courseid, 'moduleid' => $moduleid); 364 return new external_function_parameters($params); 365 } 366 367 /** 368 * Loads the data required to render the course_competencies_page template. 369 * 370 * @param int $courseid The course id to check. 371 * @param int $moduleid The module id to check (0 for no filter). 372 * @return boolean 373 */ 374 public static function data_for_course_competencies_page($courseid, $moduleid) { 375 global $PAGE; 376 $params = self::validate_parameters(self::data_for_course_competencies_page_parameters(), array( 377 'courseid' => $courseid, 378 'moduleid' => $moduleid, 379 )); 380 self::validate_context(context_course::instance($params['courseid'])); 381 382 $renderable = new output\course_competencies_page($params['courseid'], $params['moduleid']); 383 $renderer = $PAGE->get_renderer('tool_lp'); 384 385 $data = $renderable->export_for_template($renderer); 386 387 return $data; 388 } 389 390 /** 391 * Returns description of data_for_course_competencies_page() result value. 392 * 393 * @return external_description 394 */ 395 public static function data_for_course_competencies_page_returns() { 396 $ucc = user_competency_course_exporter::get_read_structure(); 397 $ucc->required = VALUE_OPTIONAL; 398 399 return new external_single_structure(array ( 400 'courseid' => new external_value(PARAM_INT, 'The current course id'), 401 'pagecontextid' => new external_value(PARAM_INT, 'The current page context ID.'), 402 'gradableuserid' => new external_value(PARAM_INT, 'Current user id, if the user is a gradable user.', VALUE_OPTIONAL), 403 'canmanagecompetencyframeworks' => new external_value(PARAM_BOOL, 'User can manage competency frameworks'), 404 'canmanagecoursecompetencies' => new external_value(PARAM_BOOL, 'User can manage linked course competencies'), 405 'canconfigurecoursecompetencies' => new external_value(PARAM_BOOL, 'User can configure course competency settings'), 406 'cangradecompetencies' => new external_value(PARAM_BOOL, 'User can grade competencies.'), 407 'settings' => course_competency_settings_exporter::get_read_structure(), 408 'statistics' => course_competency_statistics_exporter::get_read_structure(), 409 'competencies' => new external_multiple_structure(new external_single_structure(array( 410 'competency' => competency_exporter::get_read_structure(), 411 'coursecompetency' => course_competency_exporter::get_read_structure(), 412 'coursemodules' => new external_multiple_structure(course_module_summary_exporter::get_read_structure()), 413 'usercompetencycourse' => $ucc, 414 'ruleoutcomeoptions' => new external_multiple_structure( 415 new external_single_structure(array( 416 'value' => new external_value(PARAM_INT, 'The option value'), 417 'text' => new external_value(PARAM_NOTAGS, 'The name of the option'), 418 'selected' => new external_value(PARAM_BOOL, 'If this is the currently selected option'), 419 )) 420 ), 421 'comppath' => competency_path_exporter::get_read_structure(), 422 'plans' => new external_multiple_structure( 423 plan_exporter::get_read_structure() 424 ), 425 ))), 426 'manageurl' => new external_value(PARAM_LOCALURL, 'Url to the manage competencies page.'), 427 'pluginbaseurl' => new external_value(PARAM_LOCALURL, 'Url to the course competencies page.'), 428 )); 429 430 } 431 432 /** 433 * Returns description of data_for_templates_manage_page() parameters. 434 * 435 * @return external_function_parameters 436 */ 437 public static function data_for_templates_manage_page_parameters() { 438 $params = array('pagecontext' => self::get_context_parameters()); 439 return new external_function_parameters($params); 440 } 441 442 /** 443 * Loads the data required to render the templates_manage_page template. 444 * 445 * @param array $pagecontext The page context info. 446 * @return boolean 447 */ 448 public static function data_for_templates_manage_page($pagecontext) { 449 global $PAGE; 450 451 $params = self::validate_parameters(self::data_for_templates_manage_page_parameters(), array( 452 'pagecontext' => $pagecontext 453 )); 454 $context = self::get_context_from_params($params['pagecontext']); 455 self::validate_context($context); 456 457 $renderable = new output\manage_templates_page($context); 458 $renderer = $PAGE->get_renderer('tool_lp'); 459 460 $data = $renderable->export_for_template($renderer); 461 462 return $data; 463 } 464 465 /** 466 * Returns description of data_for_templates_manage_page() result value. 467 * 468 * @return external_description 469 */ 470 public static function data_for_templates_manage_page_returns() { 471 return new external_single_structure(array ( 472 'templates' => new external_multiple_structure( 473 template_exporter::get_read_structure() 474 ), 475 'pluginbaseurl' => new external_value(PARAM_LOCALURL, 'Url to the tool_lp plugin folder on this Moodle site'), 476 'navigation' => new external_multiple_structure( 477 new external_value(PARAM_RAW, 'HTML for a navigation item that should be on this page') 478 ), 479 'pagecontextid' => new external_value(PARAM_INT, 'The page context id'), 480 'canmanage' => new external_value(PARAM_BOOL, 'Whether the user manage the templates') 481 )); 482 483 } 484 485 /** 486 * Returns description of data_for_template_competenies_page() parameters. 487 * 488 * @return external_function_parameters 489 */ 490 public static function data_for_template_competencies_page_parameters() { 491 $templateid = new external_value( 492 PARAM_INT, 493 'The template id', 494 VALUE_REQUIRED 495 ); 496 $params = array('templateid' => $templateid, 'pagecontext' => self::get_context_parameters()); 497 return new external_function_parameters($params); 498 } 499 500 /** 501 * Loads the data required to render the template_competencies_page template. 502 * 503 * @param int $templateid Template id. 504 * @param array $pagecontext The page context info. 505 * @return boolean 506 */ 507 public static function data_for_template_competencies_page($templateid, $pagecontext) { 508 global $PAGE; 509 $params = self::validate_parameters(self::data_for_template_competencies_page_parameters(), array( 510 'templateid' => $templateid, 511 'pagecontext' => $pagecontext 512 )); 513 514 $context = self::get_context_from_params($params['pagecontext']); 515 self::validate_context($context); 516 517 $template = api::read_template($params['templateid']); 518 $renderable = new output\template_competencies_page($template, $context); 519 $renderer = $PAGE->get_renderer('tool_lp'); 520 521 $data = $renderable->export_for_template($renderer); 522 523 return $data; 524 } 525 526 /** 527 * Returns description of data_for_template_competencies_page() result value. 528 * 529 * @return external_description 530 */ 531 public static function data_for_template_competencies_page_returns() { 532 return new external_single_structure(array ( 533 'template' => template_exporter::get_read_structure(), 534 'pagecontextid' => new external_value(PARAM_INT, 'Context ID'), 535 'canmanagecompetencyframeworks' => new external_value(PARAM_BOOL, 'User can manage competency frameworks'), 536 'canmanagetemplatecompetencies' => new external_value(PARAM_BOOL, 'User can manage learning plan templates'), 537 'competencies' => new external_multiple_structure( 538 competency_summary_exporter::get_read_structure() 539 ), 540 'manageurl' => new external_value(PARAM_LOCALURL, 'Url to the manage competencies page.'), 541 'pluginbaseurl' => new external_value(PARAM_LOCALURL, 'Base URL of the plugin.'), 542 'statistics' => template_statistics_exporter::get_read_structure() 543 )); 544 545 } 546 547 /** 548 * Returns description of data_for_plan_competenies_page() parameters. 549 * 550 * @return external_function_parameters 551 */ 552 public static function data_for_plan_page_parameters() { 553 $planid = new external_value( 554 PARAM_INT, 555 'The plan id', 556 VALUE_REQUIRED 557 ); 558 $params = array('planid' => $planid); 559 return new external_function_parameters($params); 560 } 561 562 /** 563 * Loads the data required to render the plan_page template. 564 * 565 * @param int $planid Learning Plan id. 566 * @return boolean 567 */ 568 public static function data_for_plan_page($planid) { 569 global $PAGE; 570 $params = self::validate_parameters(self::data_for_plan_page_parameters(), array( 571 'planid' => $planid 572 )); 573 $plan = api::read_plan($params['planid']); 574 self::validate_context($plan->get_context()); 575 576 $renderable = new output\plan_page($plan); 577 $renderer = $PAGE->get_renderer('tool_lp'); 578 579 $data = $renderable->export_for_template($renderer); 580 581 return $data; 582 } 583 584 /** 585 * Returns description of data_for_plan_page() result value. 586 * 587 * @return external_description 588 */ 589 public static function data_for_plan_page_returns() { 590 $uc = user_competency_exporter::get_read_structure(); 591 $ucp = user_competency_plan_exporter::get_read_structure(); 592 593 $uc->required = VALUE_OPTIONAL; 594 $ucp->required = VALUE_OPTIONAL; 595 596 return new external_single_structure(array ( 597 'plan' => plan_exporter::get_read_structure(), 598 'contextid' => new external_value(PARAM_INT, 'Context ID.'), 599 'pluginbaseurl' => new external_value(PARAM_URL, 'Plugin base URL.'), 600 'competencies' => new external_multiple_structure( 601 new external_single_structure(array( 602 'competency' => competency_exporter::get_read_structure(), 603 'comppath' => competency_path_exporter::get_read_structure(), 604 'usercompetency' => $uc, 605 'usercompetencyplan' => $ucp 606 )) 607 ), 608 'competencycount' => new external_value(PARAM_INT, 'Count of competencies'), 609 'proficientcompetencycount' => new external_value(PARAM_INT, 'Count of proficientcompetencies'), 610 'proficientcompetencypercentage' => new external_value(PARAM_FLOAT, 'Percentage of competencies proficient'), 611 'proficientcompetencypercentageformatted' => new external_value(PARAM_RAW, 'Displayable percentage'), 612 )); 613 } 614 615 /** 616 * Returns description of data_for_plans_page() parameters. 617 * 618 * @return external_function_parameters 619 */ 620 public static function data_for_plans_page_parameters() { 621 $userid = new external_value( 622 PARAM_INT, 623 'The user id', 624 VALUE_REQUIRED 625 ); 626 $params = array('userid' => $userid); 627 return new external_function_parameters($params); 628 } 629 630 /** 631 * Loads the data required to render the plans_page template. 632 * 633 * @param int $userid User id. 634 * @return boolean 635 */ 636 public static function data_for_plans_page($userid) { 637 global $PAGE; 638 639 $params = self::validate_parameters(self::data_for_plans_page_parameters(), array( 640 'userid' => $userid, 641 )); 642 643 $context = context_user::instance($params['userid']); 644 self::validate_context($context); 645 $output = $PAGE->get_renderer('tool_lp'); 646 647 $renderable = new \tool_lp\output\plans_page($params['userid']); 648 649 return $renderable->export_for_template($output); 650 } 651 652 /** 653 * Returns description of data_for_plans_page() result value. 654 * 655 * @return external_description 656 */ 657 public static function data_for_plans_page_returns() { 658 return new external_single_structure(array ( 659 'userid' => new external_value(PARAM_INT, 'The learning plan user id'), 660 'plans' => new external_multiple_structure( 661 plan_exporter::get_read_structure() 662 ), 663 'pluginbaseurl' => new external_value(PARAM_LOCALURL, 'Url to the tool_lp plugin folder on this Moodle site'), 664 'navigation' => new external_multiple_structure( 665 new external_value(PARAM_RAW, 'HTML for a navigation item that should be on this page') 666 ), 667 'canreaduserevidence' => new external_value(PARAM_BOOL, 'Can the current user view the user\'s evidence'), 668 'canmanageuserplans' => new external_value(PARAM_BOOL, 'Can the current user manage the user\'s plans'), 669 )); 670 } 671 672 /** 673 * Returns description of external function parameters. 674 * 675 * @return external_function_parameters 676 */ 677 public static function data_for_user_evidence_list_page_parameters() { 678 return new external_function_parameters(array( 679 'userid' => new external_value(PARAM_INT, 'The user ID') 680 )); 681 } 682 683 /** 684 * Loads the data required to render the user_evidence_list_page template. 685 * 686 * @param int $userid User id. 687 * @return boolean 688 */ 689 public static function data_for_user_evidence_list_page($userid) { 690 global $PAGE; 691 $params = self::validate_parameters(self::data_for_user_evidence_list_page_parameters(), 692 array('userid' => $userid)); 693 694 $context = context_user::instance($params['userid']); 695 self::validate_context($context); 696 $output = $PAGE->get_renderer('tool_lp'); 697 698 $renderable = new \tool_lp\output\user_evidence_list_page($params['userid']); 699 return $renderable->export_for_template($output); 700 } 701 702 /** 703 * Returns description of external function result value. 704 * 705 * @return external_description 706 */ 707 public static function data_for_user_evidence_list_page_returns() { 708 return new external_single_structure(array ( 709 'canmanage' => new external_value(PARAM_BOOL, 'Can the current user manage the user\'s evidence'), 710 'userid' => new external_value(PARAM_INT, 'The user ID'), 711 'pluginbaseurl' => new external_value(PARAM_LOCALURL, 'Url to the tool_lp plugin folder on this Moodle site'), 712 'evidence' => new external_multiple_structure(user_evidence_summary_exporter::get_read_structure()), 713 'navigation' => new external_multiple_structure( 714 new external_value(PARAM_RAW, 'HTML for a navigation item that should be on this page') 715 ), 716 )); 717 } 718 719 /** 720 * Returns description of external function parameters. 721 * 722 * @return external_function_parameters 723 */ 724 public static function data_for_user_evidence_page_parameters() { 725 return new external_function_parameters(array( 726 'id' => new external_value(PARAM_INT, 'The user evidence ID') 727 )); 728 } 729 730 /** 731 * Loads the data required to render the user_evidence_page template. 732 * 733 * @param int $id User id. 734 * @return boolean 735 */ 736 public static function data_for_user_evidence_page($id) { 737 global $PAGE; 738 $params = self::validate_parameters(self::data_for_user_evidence_page_parameters(), 739 array('id' => $id)); 740 741 $userevidence = api::read_user_evidence($id); 742 self::validate_context($userevidence->get_context()); 743 $output = $PAGE->get_renderer('tool_lp'); 744 745 $renderable = new \tool_lp\output\user_evidence_page($userevidence); 746 return $renderable->export_for_template($output); 747 } 748 749 /** 750 * Returns description of external function result value. 751 * 752 * @return external_description 753 */ 754 public static function data_for_user_evidence_page_returns() { 755 return new external_single_structure(array( 756 'userevidence' => user_evidence_summary_exporter::get_read_structure(), 757 'pluginbaseurl' => new external_value(PARAM_LOCALURL, 'Url to the tool_lp plugin folder on this Moodle site') 758 )); 759 } 760 761 /** 762 * Returns the description of the data_for_related_competencies_section_parameters() parameters. 763 * 764 * @return external_function_parameters. 765 */ 766 public static function data_for_related_competencies_section_parameters() { 767 $competencyid = new external_value( 768 PARAM_INT, 769 'The competency id', 770 VALUE_REQUIRED 771 ); 772 return new external_function_parameters(array('competencyid' => $competencyid)); 773 } 774 775 /** 776 * Data to render in the related competencies section. 777 * 778 * @param int $competencyid 779 * @return array Related competencies and whether to show delete action button or not. 780 */ 781 public static function data_for_related_competencies_section($competencyid) { 782 global $PAGE; 783 784 $params = self::validate_parameters(self::data_for_related_competencies_section_parameters(), array( 785 'competencyid' => $competencyid, 786 )); 787 $competency = api::read_competency($params['competencyid']); 788 self::validate_context($competency->get_context()); 789 790 $renderable = new \tool_lp\output\related_competencies($params['competencyid']); 791 $renderer = $PAGE->get_renderer('tool_lp'); 792 793 return $renderable->export_for_template($renderer); 794 } 795 796 /** 797 * Returns description of data_for_related_competencies_section_returns() result value. 798 * 799 * @return \core_external\external_description 800 */ 801 public static function data_for_related_competencies_section_returns() { 802 return new external_single_structure(array( 803 'relatedcompetencies' => new external_multiple_structure(competency_exporter::get_read_structure()), 804 'showdeleterelatedaction' => new external_value(PARAM_BOOL, 'Whether to show the delete relation link or not') 805 )); 806 } 807 808 /** 809 * Returns the description of external function parameters. 810 * 811 * @return external_function_parameters. 812 */ 813 public static function search_users_parameters() { 814 $query = new external_value( 815 PARAM_RAW, 816 'Query string' 817 ); 818 $capability = new external_value( 819 PARAM_RAW, 820 'Required capability' 821 ); 822 $limitfrom = new external_value( 823 PARAM_INT, 824 'Number of records to skip', 825 VALUE_DEFAULT, 826 0 827 ); 828 $limitnum = new external_value( 829 PARAM_RAW, 830 'Number of records to fetch', 831 VALUE_DEFAULT, 832 100 833 ); 834 return new external_function_parameters(array( 835 'query' => $query, 836 'capability' => $capability, 837 'limitfrom' => $limitfrom, 838 'limitnum' => $limitnum 839 )); 840 } 841 842 /** 843 * Search users. 844 * 845 * @param string $query 846 * @param string $capability 847 * @param int $limitfrom 848 * @param int $limitnum 849 * @return array 850 */ 851 public static function search_users($query, $capability = '', $limitfrom = 0, $limitnum = 100) { 852 global $DB, $CFG, $PAGE, $USER; 853 854 $params = self::validate_parameters(self::search_users_parameters(), array( 855 'query' => $query, 856 'capability' => $capability, 857 'limitfrom' => $limitfrom, 858 'limitnum' => $limitnum, 859 )); 860 $query = $params['query']; 861 $cap = $params['capability']; 862 $limitfrom = $params['limitfrom']; 863 $limitnum = $params['limitnum']; 864 865 $context = context_system::instance(); 866 self::validate_context($context); 867 $output = $PAGE->get_renderer('tool_lp'); 868 869 list($filtercapsql, $filtercapparams) = api::filter_users_with_capability_on_user_context_sql($cap, 870 $USER->id, SQL_PARAMS_NAMED); 871 872 // TODO Does not support custom user profile fields (MDL-70456). 873 $userfieldsapi = \core_user\fields::for_identity($context, false)->with_userpic(); 874 $fields = $userfieldsapi->get_sql('u', false, '', '', false)->selects; 875 $extrasearchfields = $userfieldsapi->get_required_fields([\core_user\fields::PURPOSE_IDENTITY]); 876 877 list($wheresql, $whereparams) = users_search_sql($query, 'u', true, $extrasearchfields); 878 list($sortsql, $sortparams) = users_order_by_sql('u', $query, $context); 879 880 $countsql = "SELECT COUNT('x') FROM {user} u WHERE $wheresql AND u.id $filtercapsql"; 881 $countparams = $whereparams + $filtercapparams; 882 $sql = "SELECT $fields FROM {user} u WHERE $wheresql AND u.id $filtercapsql ORDER BY $sortsql"; 883 $params = $whereparams + $filtercapparams + $sortparams; 884 885 $count = $DB->count_records_sql($countsql, $countparams); 886 $result = $DB->get_recordset_sql($sql, $params, $limitfrom, $limitnum); 887 888 $users = array(); 889 foreach ($result as $key => $user) { 890 // Make sure all required fields are set. 891 foreach (user_summary_exporter::define_properties() as $propertykey => $definition) { 892 if (empty($user->$propertykey) || !in_array($propertykey, $extrasearchfields)) { 893 if ($propertykey != 'id') { 894 $user->$propertykey = ''; 895 } 896 } 897 } 898 $exporter = new user_summary_exporter($user); 899 $newuser = $exporter->export($output); 900 901 $users[$key] = $newuser; 902 } 903 $result->close(); 904 905 return array( 906 'users' => $users, 907 'count' => $count 908 ); 909 } 910 911 /** 912 * Returns description of external function result value. 913 * 914 * @return \core_external\external_description 915 */ 916 public static function search_users_returns() { 917 global $CFG; 918 require_once($CFG->dirroot . '/user/externallib.php'); 919 return new external_single_structure(array( 920 'users' => new external_multiple_structure(user_summary_exporter::get_read_structure()), 921 'count' => new external_value(PARAM_INT, 'Total number of results.') 922 )); 923 } 924 925 /** 926 * Returns description of external function. 927 * 928 * @return external_function_parameters 929 */ 930 public static function data_for_user_competency_summary_parameters() { 931 $userid = new external_value( 932 PARAM_INT, 933 'Data base record id for the user', 934 VALUE_REQUIRED 935 ); 936 $competencyid = new external_value( 937 PARAM_INT, 938 'Data base record id for the competency', 939 VALUE_REQUIRED 940 ); 941 $params = array( 942 'userid' => $userid, 943 'competencyid' => $competencyid, 944 ); 945 return new external_function_parameters($params); 946 } 947 948 /** 949 * Data for user competency summary. 950 * 951 * @param int $userid The user ID 952 * @param int $competencyid The competency ID 953 * @return \stdClass 954 */ 955 public static function data_for_user_competency_summary($userid, $competencyid) { 956 global $PAGE; 957 $params = self::validate_parameters(self::data_for_user_competency_summary_parameters(), array( 958 'userid' => $userid, 959 'competencyid' => $competencyid, 960 )); 961 962 $uc = api::get_user_competency($params['userid'], $params['competencyid']); 963 self::validate_context($uc->get_context()); 964 $output = $PAGE->get_renderer('tool_lp'); 965 966 $renderable = new \tool_lp\output\user_competency_summary($uc); 967 return $renderable->export_for_template($output); 968 } 969 970 /** 971 * Returns description of external function. 972 * 973 * @return external_description 974 */ 975 public static function data_for_user_competency_summary_returns() { 976 return user_competency_summary_exporter::get_read_structure(); 977 } 978 979 /** 980 * Returns description of data_for_user_competency_summary_in_plan() parameters. 981 * 982 * @return external_function_parameters 983 */ 984 public static function data_for_user_competency_summary_in_plan_parameters() { 985 $competencyid = new external_value( 986 PARAM_INT, 987 'Data base record id for the competency', 988 VALUE_REQUIRED 989 ); 990 $planid = new external_value( 991 PARAM_INT, 992 'Data base record id for the plan', 993 VALUE_REQUIRED 994 ); 995 996 $params = array( 997 'competencyid' => $competencyid, 998 'planid' => $planid, 999 ); 1000 return new external_function_parameters($params); 1001 } 1002 1003 /** 1004 * Read a user competency summary. 1005 * 1006 * @param int $competencyid The competency id 1007 * @param int $planid The plan id 1008 * @return \stdClass 1009 */ 1010 public static function data_for_user_competency_summary_in_plan($competencyid, $planid) { 1011 global $PAGE; 1012 $params = self::validate_parameters(self::data_for_user_competency_summary_in_plan_parameters(), array( 1013 'competencyid' => $competencyid, 1014 'planid' => $planid 1015 )); 1016 1017 $plan = api::read_plan($params['planid']); 1018 $context = $plan->get_context(); 1019 self::validate_context($context); 1020 $output = $PAGE->get_renderer('tool_lp'); 1021 1022 $renderable = new user_competency_summary_in_plan($params['competencyid'], $params['planid']); 1023 return $renderable->export_for_template($output); 1024 } 1025 1026 /** 1027 * Returns description of data_for_user_competency_summary_in_plan() result value. 1028 * 1029 * @return external_description 1030 */ 1031 public static function data_for_user_competency_summary_in_plan_returns() { 1032 return user_competency_summary_in_plan_exporter::get_read_structure(); 1033 } 1034 1035 /** 1036 * Returns description of data_for_user_competency_summary_in_course() parameters. 1037 * 1038 * @return external_function_parameters 1039 */ 1040 public static function data_for_user_competency_summary_in_course_parameters() { 1041 $userid = new external_value( 1042 PARAM_INT, 1043 'Data base record id for the user', 1044 VALUE_REQUIRED 1045 ); 1046 $competencyid = new external_value( 1047 PARAM_INT, 1048 'Data base record id for the competency', 1049 VALUE_REQUIRED 1050 ); 1051 $courseid = new external_value( 1052 PARAM_INT, 1053 'Data base record id for the course', 1054 VALUE_REQUIRED 1055 ); 1056 1057 $params = array( 1058 'userid' => $userid, 1059 'competencyid' => $competencyid, 1060 'courseid' => $courseid, 1061 ); 1062 return new external_function_parameters($params); 1063 } 1064 1065 /** 1066 * Read a user competency summary. 1067 * 1068 * @param int $userid The user id 1069 * @param int $competencyid The competency id 1070 * @param int $courseid The course id 1071 * @return \stdClass 1072 */ 1073 public static function data_for_user_competency_summary_in_course($userid, $competencyid, $courseid) { 1074 global $PAGE; 1075 $params = self::validate_parameters(self::data_for_user_competency_summary_in_course_parameters(), array( 1076 'userid' => $userid, 1077 'competencyid' => $competencyid, 1078 'courseid' => $courseid 1079 )); 1080 $context = context_user::instance($params['userid']); 1081 self::validate_context($context); 1082 $output = $PAGE->get_renderer('tool_lp'); 1083 1084 $renderable = new user_competency_summary_in_course($params['userid'], $params['competencyid'], $params['courseid']); 1085 return $renderable->export_for_template($output); 1086 } 1087 1088 /** 1089 * Returns description of data_for_user_competency_summary_in_course() result value. 1090 * 1091 * @return external_description 1092 */ 1093 public static function data_for_user_competency_summary_in_course_returns() { 1094 return user_competency_summary_in_course_exporter::get_read_structure(); 1095 } 1096 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body