2015-12-15 14:14:51 +08:00
|
|
|
<?php
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the external API for this report.
|
|
|
|
*
|
|
|
|
* @package report_competency
|
|
|
|
* @copyright 2015 Damyon Wiese
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
namespace report_competency;
|
|
|
|
|
|
|
|
defined('MOODLE_INTERNAL') || die();
|
|
|
|
|
|
|
|
require_once("$CFG->libdir/externallib.php");
|
|
|
|
|
|
|
|
use context_course;
|
|
|
|
use external_api;
|
|
|
|
use external_function_parameters;
|
|
|
|
use external_multiple_structure;
|
|
|
|
use external_single_structure;
|
|
|
|
use external_value;
|
2016-01-28 16:03:41 +08:00
|
|
|
use tool_lp\external\competency_summary_exporter;
|
2015-12-15 14:14:51 +08:00
|
|
|
use tool_lp\external\course_summary_exporter;
|
2016-04-01 15:00:29 +08:00
|
|
|
use tool_lp\external\user_competency_course_exporter;
|
2015-12-15 14:14:51 +08:00
|
|
|
use tool_lp\external\user_summary_exporter;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the external API for this report.
|
|
|
|
*
|
|
|
|
* @copyright 2015 Damyon Wiese
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
class external extends external_api {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns description of data_for_competency_frameworks_manage_page() parameters.
|
|
|
|
*
|
|
|
|
* @return \external_function_parameters
|
|
|
|
*/
|
|
|
|
public static function data_for_report_parameters() {
|
|
|
|
$courseid = new external_value(
|
|
|
|
PARAM_INT,
|
|
|
|
'The course id',
|
|
|
|
VALUE_REQUIRED
|
|
|
|
);
|
2016-01-28 16:03:41 +08:00
|
|
|
$userid = new external_value(
|
|
|
|
PARAM_INT,
|
|
|
|
'The user id',
|
|
|
|
VALUE_REQUIRED
|
|
|
|
);
|
2015-12-15 14:14:51 +08:00
|
|
|
$params = array(
|
|
|
|
'courseid' => $courseid,
|
2016-02-09 14:59:23 +08:00
|
|
|
'userid' => $userid
|
2015-12-15 14:14:51 +08:00
|
|
|
);
|
|
|
|
return new external_function_parameters($params);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the data required to render the report.
|
|
|
|
*
|
|
|
|
* @param int $courseid The course id
|
2016-03-14 13:22:01 +08:00
|
|
|
* @param int $userid The user id
|
2015-12-15 14:14:51 +08:00
|
|
|
* @return \stdClass
|
|
|
|
*/
|
2016-02-09 14:59:23 +08:00
|
|
|
public static function data_for_report($courseid, $userid) {
|
2015-12-15 14:14:51 +08:00
|
|
|
global $PAGE;
|
|
|
|
|
|
|
|
$params = self::validate_parameters(
|
|
|
|
self::data_for_report_parameters(),
|
|
|
|
array(
|
|
|
|
'courseid' => $courseid,
|
2016-02-09 14:59:23 +08:00
|
|
|
'userid' => $userid
|
2015-12-15 14:14:51 +08:00
|
|
|
)
|
|
|
|
);
|
2016-01-28 16:03:41 +08:00
|
|
|
$context = context_course::instance($params['courseid']);
|
2015-12-15 14:14:51 +08:00
|
|
|
self::validate_context($context);
|
2016-01-28 16:03:41 +08:00
|
|
|
if (!is_enrolled($context, $params['userid'], 'tool/lp:coursecompetencygradable')) {
|
|
|
|
throw new coding_exception('invaliduser');
|
|
|
|
}
|
2015-12-15 14:14:51 +08:00
|
|
|
|
2016-02-09 14:59:23 +08:00
|
|
|
$renderable = new output\report($params['courseid'], $params['userid']);
|
2015-12-15 14:14:51 +08:00
|
|
|
$renderer = $PAGE->get_renderer('report_competency');
|
|
|
|
|
|
|
|
$data = $renderable->export_for_template($renderer);
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns description of data_for_report() result value.
|
|
|
|
*
|
|
|
|
* @return \external_description
|
|
|
|
*/
|
|
|
|
public static function data_for_report_returns() {
|
|
|
|
return new external_single_structure(array (
|
|
|
|
'courseid' => new external_value(PARAM_INT, 'Course id'),
|
2016-01-28 16:03:41 +08:00
|
|
|
'user' => user_summary_exporter::get_read_structure(),
|
2015-12-15 14:14:51 +08:00
|
|
|
'course' => course_summary_exporter::get_read_structure(),
|
|
|
|
'pluginbaseurl' => new external_value(PARAM_LOCALURL, 'Url to the tool_lp plugin folder on this Moodle site'),
|
|
|
|
'usercompetencies' => new external_multiple_structure(
|
|
|
|
new external_single_structure(array(
|
2016-04-01 15:00:29 +08:00
|
|
|
'usercompetencycourse' => user_competency_course_exporter::get_read_structure(),
|
2016-01-28 16:03:41 +08:00
|
|
|
'competency' => competency_summary_exporter::get_read_structure()
|
2015-12-15 14:14:51 +08:00
|
|
|
))
|
2016-03-30 16:51:24 -04:00
|
|
|
),
|
|
|
|
'pushratingstouserplans' => new external_value(PARAM_BOOL, 'True if rating is push to user plans')
|
2015-12-15 14:14:51 +08:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|