first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+121
View File
@@ -0,0 +1,121 @@
<?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/>.
namespace report_competency;
use context_course;
use core_competency\external\user_competency_course_exporter;
use core_course\external\course_summary_exporter;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_multiple_structure;
use core_external\external_single_structure;
use core_external\external_value;
use core_user\external\user_summary_exporter;
use tool_lp\external\competency_summary_exporter;
/**
* 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
*/
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
);
$userid = new external_value(
PARAM_INT,
'The user id',
VALUE_REQUIRED
);
$moduleid = new external_value(
PARAM_INT,
'The module id',
VALUE_REQUIRED
);
$params = array(
'courseid' => $courseid,
'userid' => $userid,
'moduleid' => $moduleid,
);
return new external_function_parameters($params);
}
/**
* Loads the data required to render the report.
*
* @param int $courseid The course id
* @param int $userid The user id
* @param int $moduleid The module id
* @return \stdClass
*/
public static function data_for_report($courseid, $userid, $moduleid) {
global $PAGE;
$params = self::validate_parameters(
self::data_for_report_parameters(),
array(
'courseid' => $courseid,
'userid' => $userid,
'moduleid' => $moduleid
)
);
$context = context_course::instance($params['courseid']);
self::validate_context($context);
if (!is_enrolled($context, $params['userid'], 'moodle/competency:coursecompetencygradable')) {
throw new coding_exception('invaliduser');
}
$renderable = new output\report($params['courseid'], $params['userid'], $params['moduleid']);
$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'),
'user' => user_summary_exporter::get_read_structure(),
'course' => course_summary_exporter::get_read_structure(),
'usercompetencies' => new external_multiple_structure(
new external_single_structure(array(
'usercompetencycourse' => user_competency_course_exporter::get_read_structure(),
'competency' => competency_summary_exporter::get_read_structure()
))
),
'pushratingstouserplans' => new external_value(PARAM_BOOL, 'True if rating is push to user plans')
));
}
}
@@ -0,0 +1,98 @@
<?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/>.
/**
* Renderer class for report_competency
*
* @package report_competency
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace report_competency\output;
defined('MOODLE_INTERNAL') || die;
use plugin_renderer_base;
use renderable;
/**
* Renderer class for competency breakdown report
*
* @package report_competency
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends plugin_renderer_base {
/**
* Defer to template.
*
* @param report $page
* @return string html for the page
*/
public function render_report(report $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('report_competency/report', $data);
}
/**
* Defer to template.
*
* @param user_course_navigation $nav
* @return string
*/
public function render_user_course_navigation(user_course_navigation $nav) {
$data = $nav->export_for_template($this);
return parent::render_from_template('report_competency/user_course_navigation', $data);
}
/**
* Output a nofication.
*
* @param string $message the message to print out
* @return string HTML fragment.
* @see \core\output\notification
*/
public function notify_message($message) {
$n = new \core\output\notification($message, \core\output\notification::NOTIFY_INFO);
return $this->render($n);
}
/**
* Output an error notification.
*
* @param string $message the message to print out
* @return string HTML fragment.
* @see \core\output\notification
*/
public function notify_problem($message) {
$n = new \core\output\notification($message, \core\output\notification::NOTIFY_ERROR);
return $this->render($n);
}
/**
* Output a success notification.
*
* @param string $message the message to print out
* @return string HTML fragment.
* @see \core\output\notification
*/
public function notify_success($message) {
$n = new \core\output\notification($message, \core\output\notification::NOTIFY_SUCCESS);
return $this->render($n);
}
}
+157
View File
@@ -0,0 +1,157 @@
<?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/>.
/**
* Class containing data for learning plan template competencies page
*
* @package report_competency
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace report_competency\output;
use context_course;
use renderable;
use core_user;
use templatable;
use renderer_base;
use moodle_url;
use stdClass;
use core_competency\api;
use core_competency\external\user_competency_course_exporter;
use core_user\external\user_summary_exporter;
use core_competency\external\performance_helper;
use core_competency\url;
use core_competency\user_competency;
use tool_lp\external\competency_summary_exporter;
use core_course\external\course_summary_exporter;
/**
* Class containing data for learning plan template competencies page
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class report implements renderable, templatable {
/** @var context $context */
protected $context;
/** @var int $courseid */
protected $courseid;
/** @var int $moduleid */
protected $moduleid;
/** @var array $competencies */
protected $competencies;
/** @var int The user id */
protected $userid;
/**
* Construct this renderable.
*
* @param int $courseid The course id
* @param int $userid The user id
* @param int $moduleid The module id
*/
public function __construct($courseid, $userid, $moduleid) {
$this->courseid = $courseid;
$this->userid = $userid;
$this->moduleid = $moduleid;
$this->context = context_course::instance($courseid);
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param \renderer_base $output
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
global $DB;
$data = new stdClass();
$data->courseid = $this->courseid;
$data->moduleid = $this->moduleid;
if (empty($data->moduleid)) {
$data->moduleid = 0;
}
$course = $DB->get_record('course', array('id' => $this->courseid));
$coursecontext = context_course::instance($course->id);
$exporter = new course_summary_exporter($course, array('context' => $coursecontext));
$coursecompetencysettings = api::read_course_competency_settings($course->id);
$data->pushratingstouserplans = $coursecompetencysettings->get('pushratingstouserplans');
$data->course = $exporter->export($output);
$data->usercompetencies = array();
$user = core_user::get_user($this->userid);
$exporter = new user_summary_exporter($user);
$data->user = $exporter->export($output);
$data->usercompetencies = array();
$coursecompetencies = api::list_course_competencies($this->courseid);
$usercompetencycourses = api::list_user_competencies_in_course($this->courseid, $user->id);
if ($this->moduleid > 0) {
$modulecompetencies = api::list_course_module_competencies_in_course_module($this->moduleid);
foreach ($usercompetencycourses as $ucid => $usercompetency) {
$found = false;
foreach ($modulecompetencies as $mcid => $modulecompetency) {
if ($modulecompetency->get('competencyid') == $usercompetency->get('competencyid')) {
$found = true;
break;
}
}
if (!$found) {
// We need to filter out this competency.
unset($usercompetencycourses[$ucid]);
}
}
}
$helper = new performance_helper();
foreach ($usercompetencycourses as $usercompetencycourse) {
$onerow = new stdClass();
$competency = null;
foreach ($coursecompetencies as $coursecompetency) {
if ($coursecompetency['competency']->get('id') == $usercompetencycourse->get('competencyid')) {
$competency = $coursecompetency['competency'];
break;
}
}
if (!$competency) {
continue;
}
$framework = $helper->get_framework_from_competency($competency);
$scale = $helper->get_scale_from_competency($competency);
$exporter = new user_competency_course_exporter($usercompetencycourse, array('scale' => $scale));
$record = $exporter->export($output);
$onerow->usercompetencycourse = $record;
$exporter = new competency_summary_exporter(null, array(
'competency' => $competency,
'framework' => $framework,
'context' => $framework->get_context(),
'relatedcompetencies' => array(),
'linkedcourses' => array()
));
$onerow->competency = $exporter->export($output);
array_push($data->usercompetencies, $onerow);
}
return $data;
}
}
@@ -0,0 +1,146 @@
<?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/>.
/**
* User navigation class.
*
* @package report_competency
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace report_competency\output;
use renderable;
use renderer_base;
use templatable;
use context_course;
use core_user\external\user_summary_exporter;
use core_course\external\course_module_summary_exporter;
use stdClass;
/**
* User course navigation class.
*
* @package report_competency
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_course_navigation implements renderable, templatable {
/** @var userid */
protected $userid;
/** @var courseid */
protected $courseid;
/** @var moduleid */
protected $moduleid;
/** @var baseurl */
protected $baseurl;
/**
* Construct.
*
* @param int $userid
* @param int $courseid
* @param int $moduleid
* @param string $baseurl
*/
public function __construct($userid, $courseid, $baseurl, $moduleid) {
$this->userid = $userid;
$this->courseid = $courseid;
$this->moduleid = $moduleid;
$this->baseurl = $baseurl;
}
/**
* Export the data.
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
global $CFG, $DB, $SESSION, $PAGE;
$context = context_course::instance($this->courseid);
$data = new stdClass();
$data->userid = $this->userid;
$data->courseid = $this->courseid;
$data->moduleid = $this->moduleid;
if (empty($data->moduleid)) {
// Moduleid is optional.
$data->moduleid = 0;
}
$data->baseurl = $this->baseurl;
$data->groupselector = '';
if (has_any_capability(array('moodle/competency:usercompetencyview', 'moodle/competency:coursecompetencymanage'),
$context)) {
$course = $DB->get_record('course', array('id' => $this->courseid));
$currentgroup = groups_get_course_group($course, true);
if ($currentgroup !== false) {
$select = groups_allgroups_course_menu($course, $PAGE->url, true, $currentgroup);
$data->groupselector = $select;
}
// Fetch showactive.
$defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
$showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
$showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context);
// Fetch current active group.
$groupmode = groups_get_course_groupmode($course);
$users = get_enrolled_users($context, 'moodle/competency:coursecompetencygradable', $currentgroup,
'u.*', null, 0, 0, $showonlyactiveenrol);
$data->users = array();
foreach ($users as $user) {
$data->users[] = (object)[
'id' => $user->id,
'fullname' => fullname($user, has_capability('moodle/site:viewfullnames', $context)),
'selected' => $user->id == $this->userid
];
}
$data->hasusers = true;
$data->hasmodules = true;
$data->modules = array();
$empty = (object)['id' => 0, 'name' => get_string('nofiltersapplied')];
$data->modules[] = $empty;
$modinfo = get_fast_modinfo($this->courseid);
foreach ($modinfo->get_cms() as $cm) {
if ($cm->uservisible) {
$exporter = new course_module_summary_exporter(null, ['cm' => $cm]);
$module = $exporter->export($output);
if ($module->id == $this->moduleid) {
$module->selected = true;
}
$data->modules[] = $module;
$data->hasmodules = true;
}
}
} else {
$data->users = array();
$data->hasusers = false;
}
return $data;
}
}
@@ -0,0 +1,46 @@
<?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/>.
/**
* Privacy Subsystem implementation for report_competency.
*
* @package report_competency
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace report_competency\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for report_competency implementing null_provider.
*
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}