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
@@ -0,0 +1,128 @@
<?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 for exporting competency_path data.
*
* @package tool_lp
* @copyright 2016 Issam Taboubi <issam.taboubi@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\external;
defined('MOODLE_INTERNAL') || die();
use renderer_base;
use moodle_url;
/**
* Class for exporting competency_path data.
*
* @copyright 2016 Issam Taboubi <issam.taboubi@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class competency_path_exporter extends \core\external\exporter {
/**
* Constructor.
*
* @param array $related - related objects.
*/
public function __construct($related) {
parent::__construct([], $related);
}
/**
* Return the list of properties.
*
* @return array
*/
protected static function define_related() {
return [
'ancestors' => 'core_competency\\competency[]',
'framework' => 'core_competency\\competency_framework',
'context' => 'context'
];
}
/**
* Return the list of additional properties used only for display.
*
* @return array - Keys with their types.
*/
protected static function define_other_properties() {
return [
'ancestors' => [
'type' => path_node_exporter::read_properties_definition(),
'multiple' => true,
],
'framework' => [
'type' => path_node_exporter::read_properties_definition()
],
'pluginbaseurl' => [
'type' => PARAM_URL
],
'pagecontextid' => [
'type' => PARAM_INT
],
'showlinks' => [
'type' => PARAM_BOOL
]
];
}
/**
* Get the additional values to inject while exporting.
*
* @param renderer_base $output The renderer.
* @return array Keys are the property names, values are their values.
*/
protected function get_other_values(renderer_base $output) {
$result = new \stdClass();
$ancestors = [];
$nodescount = count($this->related['ancestors']);
$i = 1;
$result->showlinks = \core_competency\api::show_links();
foreach ($this->related['ancestors'] as $competency) {
$exporter = new path_node_exporter([
'id' => $competency->get('id'),
'name' => $competency->get('idnumber'),
'position' => $i,
'first' => $i == 1,
'last' => $i == $nodescount
], [
'context' => $this->related['context'],
]
);
$ancestors[] = $exporter->export($output);
$i++;
}
$result->ancestors = $ancestors;
$exporter = new path_node_exporter([
'id' => $this->related['framework']->get('id'),
'name' => $this->related['framework']->get('shortname'),
'first' => 0,
'last' => 0,
'position' => -1
], [
'context' => $this->related['context']
]
);
$result->framework = $exporter->export($output);
$result->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
$result->pagecontextid = $this->related['context']->id;
return (array) $result;
}
}
@@ -0,0 +1,148 @@
<?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 for exporting competency data with the set of linked courses.
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\external;
defined('MOODLE_INTERNAL') || die();
use context_course;
use renderer_base;
use stdClass;
use moodle_url;
use core_competency\competency_framework;
use core_competency\external\competency_exporter;
use core_competency\external\competency_framework_exporter;
use core_course\external\course_summary_exporter;
/**
* Class for exporting competency data with additional related data.
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class competency_summary_exporter extends \core\external\exporter {
protected static function define_related() {
// We cache the context so it does not need to be retrieved from the framework every time.
return array('context' => '\\context',
'competency' => '\\core_competency\\competency',
'framework' => '\\core_competency\\competency_framework',
'linkedcourses' => '\\stdClass[]',
'relatedcompetencies' => '\\core_competency\\competency[]');
}
protected static function define_other_properties() {
return array(
'linkedcourses' => array(
'type' => course_summary_exporter::read_properties_definition(),
'multiple' => true
),
'relatedcompetencies' => array(
'type' => competency_exporter::read_properties_definition(),
'multiple' => true
),
'competency' => array(
'type' => competency_exporter::read_properties_definition()
),
'framework' => array(
'type' => competency_framework_exporter::read_properties_definition()
),
'hascourses' => array(
'type' => PARAM_BOOL
),
'hasrelatedcompetencies' => array(
'type' => PARAM_BOOL
),
'scaleid' => array(
'type' => PARAM_INT
),
'scaleconfiguration' => array(
'type' => PARAM_RAW
),
'taxonomyterm' => array(
'type' => PARAM_TEXT
),
'comppath' => array(
'type' => competency_path_exporter::read_properties_definition(),
),
'pluginbaseurl' => [
'type' => PARAM_URL
]
);
}
protected function get_other_values(renderer_base $output) {
$result = new stdClass();
$context = $this->related['context'];
$courses = $this->related['linkedcourses'];
$linkedcourses = array();
foreach ($courses as $course) {
$context = context_course::instance($course->id);
$exporter = new course_summary_exporter($course, array('context' => $context));
$courseexport = $exporter->export($output);
array_push($linkedcourses, $courseexport);
}
$result->linkedcourses = $linkedcourses;
$result->hascourses = count($linkedcourses) > 0;
$relatedcompetencies = array();
foreach ($this->related['relatedcompetencies'] as $competency) {
$exporter = new competency_exporter($competency, array('context' => $context));
$competencyexport = $exporter->export($output);
array_push($relatedcompetencies, $competencyexport);
}
$result->relatedcompetencies = $relatedcompetencies;
$result->hasrelatedcompetencies = count($relatedcompetencies) > 0;
$competency = $this->related['competency'];
$exporter = new competency_exporter($competency, array('context' => $context));
$result->competency = $exporter->export($output);
$exporter = new competency_framework_exporter($this->related['framework']);
$result->framework = $exporter->export($output);
$scaleconfiguration = $this->related['framework']->get('scaleconfiguration');
$scaleid = $this->related['framework']->get('scaleid');
if ($competency->get('scaleid')) {
$scaleconfiguration = $competency->get('scaleconfiguration');
$scaleid = $competency->get('scaleid');
}
$result->scaleconfiguration = $scaleconfiguration;
$result->scaleid = $scaleid;
$level = $competency->get_level();
$taxonomy = $this->related['framework']->get_taxonomy($level);
$result->taxonomyterm = (string) (competency_framework::get_taxonomies_list()[$taxonomy]);
// Competency path.
$exporter = new competency_path_exporter([
'ancestors' => $competency->get_ancestors(),
'framework' => $this->related['framework'],
'context' => $context
]);
$result->comppath = $exporter->export($output);
$result->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
$result->showlinks = \core_competency\api::show_links();
return (array) $result;
}
}
@@ -0,0 +1,103 @@
<?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 for exporting a course competency statistics summary.
*
* @package tool_lp
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\external;
defined('MOODLE_INTERNAL') || die();
use renderer_base;
use moodle_url;
use core_competency\external\competency_exporter;
use core_competency\external\performance_helper;
/**
* Class for exporting a course competency statistics summary.
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_competency_statistics_exporter extends \core\external\exporter {
public static function define_properties() {
return array(
'competencycount' => array(
'type' => PARAM_INT,
),
'proficientcompetencycount' => array(
'type' => PARAM_INT,
),
);
}
public static function define_other_properties() {
return array(
'proficientcompetencypercentage' => array(
'type' => PARAM_FLOAT
),
'proficientcompetencypercentageformatted' => array(
'type' => PARAM_RAW
),
'leastproficient' => array(
'type' => competency_exporter::read_properties_definition(),
'multiple' => true
),
'leastproficientcount' => array(
'type' => PARAM_INT
),
'canbegradedincourse' => array(
'type' => PARAM_BOOL
),
'canmanagecoursecompetencies' => array(
'type' => PARAM_BOOL
),
);
}
protected static function define_related() {
return array('context' => 'context');
}
protected function get_other_values(renderer_base $output) {
$proficientcompetencypercentage = 0;
$proficientcompetencypercentageformatted = '';
if ($this->data->competencycount > 0) {
$proficientcompetencypercentage = ((float) $this->data->proficientcompetencycount
/ (float) $this->data->competencycount) * 100.0;
$proficientcompetencypercentageformatted = format_float($proficientcompetencypercentage);
}
$competencies = array();
$helper = new performance_helper();
foreach ($this->data->leastproficientcompetencies as $competency) {
$context = $helper->get_context_from_competency($competency);
$exporter = new competency_exporter($competency, array('context' => $context));
$competencies[] = $exporter->export($output);
}
return array(
'proficientcompetencypercentage' => $proficientcompetencypercentage,
'proficientcompetencypercentageformatted' => $proficientcompetencypercentageformatted,
'leastproficient' => $competencies,
'leastproficientcount' => count($competencies),
'canbegradedincourse' => has_capability('moodle/competency:coursecompetencygradable', $this->related['context']),
'canmanagecoursecompetencies' => has_capability('moodle/competency:coursecompetencymanage', $this->related['context'])
);
}
}
+90
View File
@@ -0,0 +1,90 @@
<?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 for exporting path_node data.
*
* @package tool_lp
* @copyright 2016 Issam Taboubi <issam.taboubi@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\external;
defined('MOODLE_INTERNAL') || die();
use context_system;
/**
* Class for exporting path_node data.
*
* @copyright 2016 Issam Taboubi <issam.taboubi@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class path_node_exporter extends \core\external\exporter {
/**
* Constructor - saves the persistent object, and the related objects.
*
* @param mixed $data The data.
* @param array $related Array of relateds.
*/
public function __construct($data, $related = array()) {
if (!isset($related['context'])) {
// Previous code was automatically using the system context which was not always correct.
// We let developers know that they must fix their code without breaking anything,
// and fallback on the previous behaviour. This should be removed at a later stage: Moodle 3.5.
debugging('Missing related context in path_node_exporter.', DEBUG_DEVELOPER);
$related['context'] = context_system::instance();
}
parent::__construct($data, $related);
}
/**
* Return the list of properties.
*
* @return array
*/
protected static function define_related() {
return [
'context' => 'context'
];
}
/**
* Return the list of properties.
*
* @return array
*/
protected static function define_properties() {
return [
'id' => [
'type' => PARAM_INT,
'null' => NULL_ALLOWED
],
'name' => [
'type' => PARAM_TEXT
],
'first' => [
'type' => PARAM_BOOL
],
'last' => [
'type' => PARAM_BOOL
],
'position' => [
'type' => PARAM_INT
]
];
}
}
@@ -0,0 +1,140 @@
<?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 for exporting a template statistics summary.
*
* @package tool_lp
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\external;
defined('MOODLE_INTERNAL') || die();
use renderer_base;
use moodle_url;
use core_competency\external\competency_exporter;
use core_competency\external\performance_helper;
/**
* Class for exporting a cohort summary from an stdClass.
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class template_statistics_exporter extends \core\external\exporter {
public static function define_properties() {
return array(
'competencycount' => array(
'type' => PARAM_INT,
),
'unlinkedcompetencycount' => array(
'type' => PARAM_INT,
),
'plancount' => array(
'type' => PARAM_INT,
),
'completedplancount' => array(
'type' => PARAM_INT,
),
'usercompetencyplancount' => array(
'type' => PARAM_INT,
),
'proficientusercompetencyplancount' => array(
'type' => PARAM_INT,
)
);
}
public static function define_other_properties() {
return array(
'linkedcompetencypercentage' => array(
'type' => PARAM_FLOAT
),
'linkedcompetencypercentageformatted' => array(
'type' => PARAM_RAW
),
'linkedcompetencycount' => array(
'type' => PARAM_INT
),
'completedplanpercentage' => array(
'type' => PARAM_FLOAT
),
'completedplanpercentageformatted' => array(
'type' => PARAM_RAW
),
'proficientusercompetencyplanpercentage' => array(
'type' => PARAM_FLOAT
),
'proficientusercompetencyplanpercentageformatted' => array(
'type' => PARAM_RAW
),
'leastproficient' => array(
'type' => competency_exporter::read_properties_definition(),
'multiple' => true
),
'leastproficientcount' => array(
'type' => PARAM_INT
),
);
}
protected function get_other_values(renderer_base $output) {
$linkedcompetencycount = $this->data->competencycount - $this->data->unlinkedcompetencycount;
if ($linkedcompetencycount < 0) {
// Should never happen.
$linkedcompetencycount = 0;
}
$linkedcompetencypercentage = 0;
$linkedcompetencypercentageformatted = '';
if ($this->data->competencycount > 0) {
$linkedcompetencypercentage = ((float) $linkedcompetencycount / (float) $this->data->competencycount) * 100.0;
$linkedcompetencypercentageformatted = format_float($linkedcompetencypercentage);
}
$completedplanpercentage = 0;
$completedplanpercentageformatted = '';
if ($this->data->plancount > 0) {
$completedplanpercentage = ((float) $this->data->completedplancount / (float) $this->data->plancount) * 100.0;
$completedplanpercentageformatted = format_float($completedplanpercentage);
}
$proficientusercompetencyplanpercentage = 0;
$proficientusercompetencyplanpercentageformatted = '';
if ($this->data->usercompetencyplancount > 0) {
$proficientusercompetencyplanpercentage = ((float) $this->data->proficientusercompetencyplancount
/ (float) $this->data->usercompetencyplancount) * 100.0;
$proficientusercompetencyplanpercentageformatted = format_float($proficientusercompetencyplanpercentage);
}
$competencies = array();
$helper = new performance_helper();
foreach ($this->data->leastproficientcompetencies as $competency) {
$context = $helper->get_context_from_competency($competency);
$exporter = new competency_exporter($competency, array('context' => $context));
$competencies[] = $exporter->export($output);
}
return array(
'linkedcompetencycount' => $linkedcompetencycount,
'linkedcompetencypercentage' => $linkedcompetencypercentage,
'linkedcompetencypercentageformatted' => $linkedcompetencypercentageformatted,
'completedplanpercentage' => $completedplanpercentage,
'completedplanpercentageformatted' => $completedplanpercentageformatted,
'proficientusercompetencyplanpercentage' => $proficientusercompetencyplanpercentage,
'proficientusercompetencyplanpercentageformatted' => $proficientusercompetencyplanpercentageformatted,
'leastproficient' => $competencies,
'leastproficientcount' => count($competencies)
);
}
}
@@ -0,0 +1,175 @@
<?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 for exporting user competency data with all the evidence
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\external;
defined('MOODLE_INTERNAL') || die();
use context_user;
use renderer_base;
use stdClass;
use core_comment\external\comment_area_exporter;
use core_competency\external\evidence_exporter;
use core_competency\external\user_competency_exporter;
use core_competency\external\user_competency_plan_exporter;
use core_competency\external\user_competency_course_exporter;
use core_user\external\user_summary_exporter;
use core_competency\user_competency;
/**
* Class for exporting user competency data with additional related data.
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_competency_summary_exporter extends \core\external\exporter {
protected static function define_related() {
// We cache the context so it does not need to be retrieved from the framework every time.
return array('competency' => '\\core_competency\\competency',
'relatedcompetencies' => '\\core_competency\\competency[]',
'user' => '\\stdClass',
'usercompetency' => '\\core_competency\\user_competency?',
'usercompetencyplan' => '\\core_competency\\user_competency_plan?',
'usercompetencycourse' => '\\core_competency\\user_competency_course?',
'evidence' => '\\core_competency\\evidence[]');
}
protected static function define_other_properties() {
return array(
'showrelatedcompetencies' => array(
'type' => PARAM_BOOL
),
'cangrade' => array(
'type' => PARAM_BOOL
),
'competency' => array(
'type' => competency_summary_exporter::read_properties_definition()
),
'user' => array(
'type' => user_summary_exporter::read_properties_definition(),
),
'usercompetency' => array(
'type' => user_competency_exporter::read_properties_definition(),
'optional' => true
),
'usercompetencyplan' => array(
'type' => user_competency_plan_exporter::read_properties_definition(),
'optional' => true
),
'usercompetencycourse' => array(
'type' => user_competency_course_exporter::read_properties_definition(),
'optional' => true
),
'evidence' => array(
'type' => evidence_exporter::read_properties_definition(),
'multiple' => true
),
'commentarea' => array(
'type' => comment_area_exporter::read_properties_definition(),
'optional' => true
),
);
}
protected function get_other_values(renderer_base $output) {
global $DB;
$result = new stdClass();
$result->showrelatedcompetencies = true;
$competency = $this->related['competency'];
$exporter = new competency_summary_exporter(null, array(
'competency' => $competency,
'context' => $competency->get_context(),
'framework' => $competency->get_framework(),
'linkedcourses' => array(),
'relatedcompetencies' => $this->related['relatedcompetencies']
));
$result->competency = $exporter->export($output);
$result->cangrade = user_competency::can_grade_user($this->related['user']->id);
if ($this->related['user']) {
$exporter = new user_summary_exporter($this->related['user']);
$result->user = $exporter->export($output);
}
$related = array('scale' => $competency->get_scale());
if ($this->related['usercompetency']) {
$exporter = new user_competency_exporter($this->related['usercompetency'], $related);
$result->usercompetency = $exporter->export($output);
}
if ($this->related['usercompetencyplan']) {
$exporter = new user_competency_plan_exporter($this->related['usercompetencyplan'], $related);
$result->usercompetencyplan = $exporter->export($output);
}
if ($this->related['usercompetencycourse']) {
$exporter = new user_competency_course_exporter($this->related['usercompetencycourse'], $related);
$result->usercompetencycourse = $exporter->export($output);
}
$allevidence = array();
$usercache = array();
$scale = $competency->get_scale();
$result->evidence = array();
if (count($this->related['evidence'])) {
foreach ($this->related['evidence'] as $evidence) {
$actionuserid = $evidence->get('actionuserid');
if (!empty($actionuserid)) {
$usercache[$evidence->get('actionuserid')] = true;
}
}
$users = array();
if (!empty($usercache)) {
list($sql, $params) = $DB->get_in_or_equal(array_keys($usercache));
$users = $DB->get_records_select('user', 'id ' . $sql, $params);
}
foreach ($users as $user) {
$usercache[$user->id] = $user;
}
foreach ($this->related['evidence'] as $evidence) {
$actionuserid = $evidence->get('actionuserid');
$related = array(
'scale' => $scale,
'usercompetency' => ($this->related['usercompetency'] ? $this->related['usercompetency'] : null),
'usercompetencyplan' => ($this->related['usercompetencyplan'] ? $this->related['usercompetencyplan'] : null),
'context' => $evidence->get_context()
);
$related['actionuser'] = !empty($actionuserid) ? $usercache[$actionuserid] : null;
$exporter = new evidence_exporter($evidence, $related);
$allevidence[] = $exporter->export($output);
}
$result->evidence = $allevidence;
}
$usercompetency = !empty($this->related['usercompetency']) ? $this->related['usercompetency'] : null;
if (!empty($usercompetency) && $usercompetency->can_read_comments()) {
$commentareaexporter = new comment_area_exporter($usercompetency->get_comment_object());
$result->commentarea = $commentareaexporter->export($output);
}
return (array) $result;
}
}
@@ -0,0 +1,119 @@
<?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 for exporting user competency data with all the evidence in a course
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\external;
defined('MOODLE_INTERNAL') || die();
use core_competency\api;
use core_competency\user_competency;
use core_competency\external\plan_exporter;
use core_course\external\course_module_summary_exporter;
use core_course\external\course_summary_exporter;
use context_course;
use renderer_base;
use stdClass;
use moodle_url;
/**
* Class for exporting user competency data with additional related data in a plan.
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_competency_summary_in_course_exporter extends \core\external\exporter {
protected static function define_related() {
// We cache the context so it does not need to be retrieved from the framework every time.
return array('competency' => '\\core_competency\\competency',
'relatedcompetencies' => '\\core_competency\\competency[]',
'user' => '\\stdClass',
'course' => '\\stdClass',
'usercompetencycourse' => '\\core_competency\\user_competency_course?',
'evidence' => '\\core_competency\\evidence[]',
'scale' => '\\grade_scale');
}
protected static function define_other_properties() {
return array(
'usercompetencysummary' => array(
'type' => user_competency_summary_exporter::read_properties_definition()
),
'course' => array(
'type' => course_summary_exporter::read_properties_definition(),
),
'coursemodules' => array(
'type' => course_module_summary_exporter::read_properties_definition(),
'multiple' => true
),
'plans' => array(
'type' => plan_exporter::read_properties_definition(),
'multiple' => true
),
'pluginbaseurl' => [
'type' => PARAM_URL
],
);
}
protected function get_other_values(renderer_base $output) {
// Arrays are copy on assign.
$related = $this->related;
$result = new stdClass();
// Remove course from related as it is not wanted by the user_competency_summary_exporter.
unset($related['course']);
$related['usercompetencyplan'] = null;
$related['usercompetency'] = null;
$exporter = new user_competency_summary_exporter(null, $related);
$result->usercompetencysummary = $exporter->export($output);
$result->usercompetencysummary->cangrade = user_competency::can_grade_user_in_course($this->related['user']->id,
$this->related['course']->id);
$context = context_course::instance($this->related['course']->id);
$exporter = new course_summary_exporter($this->related['course'], array('context' => $context));
$result->course = $exporter->export($output);
$coursemodules = api::list_course_modules_using_competency($this->related['competency']->get('id'),
$this->related['course']->id);
$fastmodinfo = get_fast_modinfo($this->related['course']->id);
$exportedmodules = array();
foreach ($coursemodules as $cm) {
$cminfo = $fastmodinfo->cms[$cm];
$cmexporter = new course_module_summary_exporter(null, array('cm' => $cminfo));
$exportedmodules[] = $cmexporter->export($output);
}
$result->coursemodules = $exportedmodules;
// User learning plans.
$plans = api::list_plans_with_competency($this->related['user']->id, $this->related['competency']);
$exportedplans = array();
foreach ($plans as $plan) {
$planexporter = new plan_exporter($plan, array('template' => $plan->get_template()));
$exportedplans[] = $planexporter->export($output);
}
$result->plans = $exportedplans;
$result->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
return (array) $result;
}
}
@@ -0,0 +1,78 @@
<?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 for exporting user competency data with all the evidence in a plan
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\external;
defined('MOODLE_INTERNAL') || die();
use context_user;
use renderer_base;
use stdClass;
use core_competency\external\plan_exporter;
/**
* Class for exporting user competency data with additional related data in a plan.
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_competency_summary_in_plan_exporter extends \core\external\exporter {
protected static function define_related() {
// We cache the context so it does not need to be retrieved from the framework every time.
return array('competency' => '\\core_competency\\competency',
'relatedcompetencies' => '\\core_competency\\competency[]',
'user' => '\\stdClass',
'plan' => '\\core_competency\\plan',
'usercompetency' => '\\core_competency\\user_competency?',
'usercompetencyplan' => '\\core_competency\\user_competency_plan?',
'evidence' => '\\core_competency\\evidence[]');
}
protected static function define_other_properties() {
return array(
'usercompetencysummary' => array(
'type' => user_competency_summary_exporter::read_properties_definition()
),
'plan' => array(
'type' => plan_exporter::read_properties_definition(),
)
);
}
protected function get_other_values(renderer_base $output) {
// Arrays are copy on assign.
$related = $this->related;
// Remove plan from related as it is not wanted by the user_competency_summary_exporter.
unset($related['plan']);
// We do not need user_competency_course in user_competency_summary_exporter.
$related['usercompetencycourse'] = null;
$exporter = new user_competency_summary_exporter(null, $related);
$result = new stdClass();
$result->usercompetencysummary = $exporter->export($output);
$exporter = new plan_exporter($this->related['plan'], array('template' => $this->related['plan']->get_template()));
$result->plan = $exporter->export($output);
return (array) $result;
}
}
@@ -0,0 +1,73 @@
<?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 for exporting user evidence competency data.
*
* @package tool_lp
* @copyright 2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\external;
defined('MOODLE_INTERNAL') || die();
use moodle_url;
use renderer_base;
use core_competency\external\competency_exporter;
use core_competency\external\user_competency_exporter;
/**
* Class for exporting user evidence competency data.
*
* @copyright 2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_evidence_competency_summary_exporter extends \core\external\exporter {
protected static function define_related() {
return array('competency' => '\\core_competency\\competency',
'usercompetency' => '\\core_competency\\user_competency',
'scale' => 'grade_scale',
'context' => '\\context'
);
}
protected static function define_other_properties() {
return array(
'competency' => array(
'type' => competency_exporter::read_properties_definition()
),
'usercompetency' => array(
'type' => user_competency_exporter::read_properties_definition(),
)
);
}
protected function get_other_values(renderer_base $output) {
$competencyexporter = new competency_exporter($this->related['competency'],
array('context' => $this->related['context']));
$usercompetencyexporter = new user_competency_exporter($this->related['usercompetency'],
array('scale' => $this->related['scale']));
$values = array(
'competency' => $competencyexporter->export($output),
'usercompetency' => $usercompetencyexporter->export($output)
);
return $values;
}
}
@@ -0,0 +1,128 @@
<?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 for exporting user evidence with all competencies.
*
* @package tool_lp
* @copyright 2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\external;
defined('MOODLE_INTERNAL') || die();
use moodle_url;
use renderer_base;
use core_files\external\stored_file_exporter;
use core_competency\external\performance_helper;
/**
* Class for exporting user evidence with all competencies.
*
* @copyright 2016 Serge Gauthier - <serge.gauthier.2@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_evidence_summary_exporter extends \core\external\persistent_exporter {
protected static function define_class() {
return \core_competency\user_evidence::class;
}
protected static function define_other_properties() {
return array(
'canmanage' => array(
'type' => PARAM_BOOL
),
'filecount' => array(
'type' => PARAM_INT
),
'files' => array(
'type' => stored_file_exporter::read_properties_definition(),
'multiple' => true
),
'hasurlorfiles' => array(
'type' => PARAM_BOOL
),
'urlshort' => array(
'type' => PARAM_TEXT
),
'competencycount' => array(
'type' => PARAM_INT
),
'usercompetencies' => array(
'type' => user_evidence_competency_summary_exporter::read_properties_definition(),
'optional' => true,
'multiple' => true
),
'userhasplan' => array(
'type' => PARAM_BOOL
),
);
}
protected function get_other_values(renderer_base $output) {
$urlshort = '';
$url = $this->persistent->get('url');
if (!empty($url)) {
$murl = new moodle_url($url);
$shorturl = preg_replace('@^https?://(www\.)?@', '', $murl->out(false));
$urlshort = shorten_text($shorturl, 30, true);
}
$files = array();
$storedfiles = $this->persistent->get_files();
if (!empty($storedfiles)) {
foreach ($storedfiles as $storedfile) {
$fileexporter = new stored_file_exporter($storedfile, array('context' => $this->related['context']));
$files[] = $fileexporter->export($output);
}
}
$userevidencecompetencies = array();
$usercompetencies = $this->persistent->get_user_competencies();
$helper = new performance_helper();
foreach ($usercompetencies as $usercompetency) {
$competency = $usercompetency->get_competency();
$context = $helper->get_context_from_competency($competency);
$framework = $helper->get_framework_from_competency($competency);
$scale = $helper->get_scale_from_competency($competency);
$related = array('competency' => $competency,
'usercompetency' => $usercompetency,
'scale' => $scale,
'context' => $context);
$userevidencecompetencysummaryexporter = new user_evidence_competency_summary_exporter(null, $related);
$userevidencecompetencies[] = $userevidencecompetencysummaryexporter->export($output);
}
$values = array(
'canmanage' => $this->persistent->can_manage(),
'filecount' => count($files),
'files' => $files,
'userhasplan' => $this->persistent->user_has_plan(),
'hasurlorfiles' => !empty($files) || !empty($url),
'urlshort' => $urlshort,
'competencycount' => count($userevidencecompetencies),
'usercompetencies' => $userevidencecompetencies
);
return $values;
}
}