[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/report/competency/classes/ -> external.php (source)

   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 report.
  19   *
  20   * @package    report_competency
  21   * @copyright  2015 Damyon Wiese
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace report_competency;
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  require_once("$CFG->libdir/externallib.php");
  29  
  30  use context_course;
  31  use external_api;
  32  use external_function_parameters;
  33  use external_multiple_structure;
  34  use external_single_structure;
  35  use external_value;
  36  use core_competency\external\user_competency_course_exporter;
  37  use core_competency\external\user_summary_exporter;
  38  use tool_lp\external\competency_summary_exporter;
  39  use tool_lp\external\course_summary_exporter;
  40  
  41  /**
  42   * This is the external API for this report.
  43   *
  44   * @copyright  2015 Damyon Wiese
  45   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  46   */
  47  class external extends external_api {
  48  
  49      /**
  50       * Returns description of data_for_competency_frameworks_manage_page() parameters.
  51       *
  52       * @return \external_function_parameters
  53       */
  54      public static function data_for_report_parameters() {
  55          $courseid = new external_value(
  56              PARAM_INT,
  57              'The course id',
  58              VALUE_REQUIRED
  59          );
  60          $userid = new external_value(
  61              PARAM_INT,
  62              'The user id',
  63              VALUE_REQUIRED
  64          );
  65          $params = array(
  66              'courseid' => $courseid,
  67              'userid' => $userid
  68          );
  69          return new external_function_parameters($params);
  70      }
  71  
  72      /**
  73       * Loads the data required to render the report.
  74       *
  75       * @param int $courseid The course id
  76       * @param int $userid The user id
  77       * @return \stdClass
  78       */
  79      public static function data_for_report($courseid, $userid) {
  80          global $PAGE;
  81  
  82          $params = self::validate_parameters(
  83              self::data_for_report_parameters(),
  84              array(
  85                  'courseid' => $courseid,
  86                  'userid' => $userid
  87              )
  88          );
  89          $context = context_course::instance($params['courseid']);
  90          self::validate_context($context);
  91          if (!is_enrolled($context, $params['userid'], 'moodle/competency:coursecompetencygradable')) {
  92              throw new coding_exception('invaliduser');
  93          }
  94  
  95          $renderable = new output\report($params['courseid'], $params['userid']);
  96          $renderer = $PAGE->get_renderer('report_competency');
  97  
  98          $data = $renderable->export_for_template($renderer);
  99  
 100          return $data;
 101      }
 102  
 103      /**
 104       * Returns description of data_for_report() result value.
 105       *
 106       * @return \external_description
 107       */
 108      public static function data_for_report_returns() {
 109          return new external_single_structure(array (
 110              'courseid' => new external_value(PARAM_INT, 'Course id'),
 111              'user' => user_summary_exporter::get_read_structure(),
 112              'course' => course_summary_exporter::get_read_structure(),
 113              'usercompetencies' => new external_multiple_structure(
 114                  new external_single_structure(array(
 115                      'usercompetencycourse' => user_competency_course_exporter::get_read_structure(),
 116                      'competency' => competency_summary_exporter::get_read_structure()
 117                  ))
 118              ),
 119              'pushratingstouserplans' => new external_value(PARAM_BOOL, 'True if rating is push to user plans')
 120          ));
 121      }
 122  
 123  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1