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,89 @@
<?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/>.
/**
* Course competencies element.
*
* @package tool_lp
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
use core_competency\api;
use core_competency\external\competency_exporter;
require_once($CFG->libdir . '/form/autocomplete.php');
/**
* Course competencies element.
*
* @package tool_lp
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_lp_course_competencies_form_element extends MoodleQuickForm_autocomplete {
/**
* Constructor
*
* @param string $elementName Element name
* @param mixed $elementLabel Label(s) for an element
* @param array $options Options to control the element's display
* @param mixed $attributes Either a typical HTML attribute string or an associative array.
*/
public function __construct($elementName=null, $elementLabel=null, $options=array(), $attributes=null) {
global $OUTPUT;
if ($elementName == null) {
// This is broken quickforms messing with the constructors.
return;
}
if (!isset($options['courseid'])) {
throw new coding_exception('Course id is required for the course_competencies form element');
}
$courseid = $options['courseid'];
if (!empty($options['cmid'])) {
$current = \core_competency\api::list_course_module_competencies_in_course_module($options['cmid']);
$ids = array();
foreach ($current as $coursemodulecompetency) {
array_push($ids, $coursemodulecompetency->get('competencyid'));
}
$this->setValue($ids);
}
$competencies = api::list_course_competencies($courseid);
$validoptions = array();
$context = context_course::instance($courseid);
foreach ($competencies as $competency) {
// We don't need to show the description as part of the options, so just set this to null.
$competency['competency']->set('description', null);
$exporter = new competency_exporter($competency['competency'], array('context' => $context));
$templatecontext = array('competency' => $exporter->export($OUTPUT));
$id = $competency['competency']->get('id');
$validoptions[$id] = $OUTPUT->render_from_template('tool_lp/competency_summary', $templatecontext);
}
$attributes['tags'] = false;
$attributes['multiple'] = 'multiple';
parent::__construct($elementName, $elementLabel, $validoptions, $attributes);
}
}
@@ -0,0 +1,69 @@
<?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/>.
/**
* Course competency override grade element.
*
* @package tool_lp
* @copyright 2022 Matthew Hilton <matthewhilton@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/form/advcheckbox.php');
/**
* Course competency override grade element.
*
* @package tool_lp
* @copyright 2022 Matthew Hilton <matthewhilton@catalyst-au.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_lp_course_competency_overridegrade_form_element extends MoodleQuickForm_advcheckbox {
/**
* Constructor
*
* @param string $elementname Element name
* @param mixed $elementlabel Label(s) for an element
* @param array $options Options to control the element's display
*/
public function __construct($elementname=null, $elementlabel=null, $options=[]) {
if ($elementname == null) {
// This is broken quickforms messing with the constructors.
return;
}
if (!empty($options['cmid'])) {
$cmid = $options['cmid'];
$current = \core_competency\api::list_course_module_competencies_in_course_module($cmid);
// Note: We just pick the override grade value set on the first course_module_competency.
// Because in the UI we force them to be the same for all.
if (!empty($current)) {
$one = array_pop($current);
$this->setValue($one->get('overridegrade'));
}
}
parent::__construct($elementname, $elementlabel);
}
}
@@ -0,0 +1,74 @@
<?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/>.
/**
* Course competency rule element.
*
* @package tool_lp
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
use core_competency\api;
use core_competency\external\competency_exporter;
use core_competency\course_module_competency;
require_once($CFG->libdir . '/form/select.php');
/**
* Course competency rule element.
*
* @package tool_lp
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_lp_course_competency_rule_form_element extends MoodleQuickForm_select {
/**
* Constructor
*
* @param string $elementName Element name
* @param mixed $elementLabel Label(s) for an element
* @param array $options Options to control the element's display
* @param mixed $attributes Either a typical HTML attribute string or an associative array.
*/
public function __construct($elementName=null, $elementLabel=null, $options=array(), $attributes=null) {
if ($elementName == null) {
// This is broken quickforms messing with the constructors.
return;
}
if (!empty($options['cmid'])) {
$cmid = $options['cmid'];
$current = \core_competency\api::list_course_module_competencies_in_course_module($cmid);
// Note: We just pick the outcome set on the first course_module_competency - because in our UI are are
// forcing them to be all the same for each activity.
if (!empty($current)) {
$one = array_pop($current);
$this->setValue($one->get('ruleoutcome'));
}
}
$validoptions = course_module_competency::get_ruleoutcome_list();
parent::__construct($elementName, $elementLabel, $validoptions, $attributes);
}
}
@@ -0,0 +1,60 @@
<?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/>.
/**
* Course competency statistics class
*
* @package tool_lp
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp;
defined('MOODLE_INTERNAL') || die();
use core_competency\api;
/**
* Course competency statistics class.
*
* @package tool_lp
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_competency_statistics {
/** @var $competencycount The number of competencies in the course */
public $competencycount = 0;
/** @var $proficientcompetencycount The number of proficient competencies for the current user */
public $proficientcompetencycount = 0;
/** @var $leastproficientcompetencies The competencies in this course that were proficient the least times */
public $leastproficientcompetencies = array();
/**
* Return the custom definition of the properties of this model.
*
* @param int $courseid The course we want to generate statistics for.
*/
public function __construct($courseid) {
global $USER;
$this->competencycount = api::count_competencies_in_course($courseid);
$this->proficientcompetencycount = api::count_proficient_competencies_in_course_for_user($courseid, $USER->id);
$this->leastproficientcompetencies = api::get_least_proficient_competencies_for_course($courseid, 0, 3);
}
}
File diff suppressed because it is too large Load Diff
@@ -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;
}
}
+171
View File
@@ -0,0 +1,171 @@
<?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 file contains the form add/update a competency framework.
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\form;
defined('MOODLE_INTERNAL') || die();
use stdClass;
use core\form\persistent;
/**
* Competency framework form.
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class competency extends persistent {
/** @var core_competency\competency persistent class for form */
protected static $persistentclass = 'core_competency\\competency';
/**
* Define the form - called by parent constructor
*/
public function definition() {
global $PAGE, $OUTPUT;
$mform = $this->_form;
$framework = $this->_customdata['competencyframework'];
$parent = $this->_customdata['parent'];
$pagecontextid = $this->_customdata['pagecontextid'];
$competency = $this->get_persistent();
$mform->addElement('hidden', 'competencyframeworkid');
$mform->setType('competencyframeworkid', PARAM_INT);
$mform->setConstant('competencyframeworkid', $framework->get('id'));
$mform->addElement('header', 'generalhdr', get_string('general'));
$mform->addElement('static',
'frameworkdesc',
get_string('competencyframework', 'tool_lp'),
s($framework->get('shortname')));
$mform->addElement('hidden', 'parentid', '', array('id' => 'tool_lp_parentcompetency'));
$mform->setType('parentid', PARAM_INT);
$mform->setConstant('parentid', ($parent) ? $parent->get('id') : 0);
$parentlevel = ($parent) ? $parent->get_level() : 0;
$parentname = ($parent) ? $parent->get('shortname') : get_string('competencyframeworkroot', 'tool_lp');
$parentlabel = '';
if (!empty($competency->get('id'))) {
$parentlabel = get_string('taxonomy_parent_' . $framework->get_taxonomy($parentlevel), 'tool_lp');
} else {
$parentlabel = get_string('parentcompetency', 'tool_lp');
}
$editaction = '';
if (!$competency->get('id')) {
$icon = $OUTPUT->pix_icon('t/editinline', get_string('parentcompetency_edit', 'tool_lp'));
$editaction = $OUTPUT->action_link('#', $icon, null, array('id' => 'id_parentcompetencybutton'));
}
$mform->addElement('static',
'parentdesc',
$parentlabel,
"<span id='id_parentdesc'>$parentname</span>&nbsp;".$editaction);
// Set the picker competency when adding new competency.
if (!$competency->get('id')) {
// Call the parentcompetency_form init to initialize the competency picker for parent competency.
$PAGE->requires->js_call_amd('tool_lp/parentcompetency_form', 'init', array('#id_parentcompetencybutton',
'#tool_lp_parentcompetency',
'#id_parentdesc',
$framework->get('id'),
$pagecontextid));
}
// Name.
$mform->addElement('text', 'shortname', get_string('shortname', 'tool_lp'), 'maxlength="100"');
$mform->setType('shortname', PARAM_TEXT);
$mform->addRule('shortname', null, 'required', null, 'client');
$mform->addRule('shortname', get_string('maximumchars', '', 100), 'maxlength', 100, 'client');
// Description.
$mform->addElement('editor', 'description',
get_string('description', 'tool_lp'), array('rows' => 4));
$mform->setType('description', PARAM_CLEANHTML);
// ID number.
$mform->addElement('text', 'idnumber', get_string('idnumber', 'tool_lp'), 'maxlength="100"');
$mform->setType('idnumber', PARAM_RAW);
$mform->addRule('idnumber', null, 'required', null, 'client');
$mform->addRule('idnumber', get_string('maximumchars', '', 100), 'maxlength', 100, 'client');
$scales = array(null => get_string('inheritfromframework', 'tool_lp')) + get_scales_menu();
$scaleid = $mform->addElement('select', 'scaleid', get_string('scale', 'tool_lp'), $scales);
$mform->setType('scaleid', PARAM_INT);
$mform->addHelpButton('scaleid', 'scale', 'tool_lp');
$mform->addElement('hidden', 'scaleconfiguration', '', array('id' => 'tool_lp_scaleconfiguration'));
$mform->setType('scaleconfiguration', PARAM_RAW);
$mform->addElement('button', 'scaleconfigbutton', get_string('configurescale', 'tool_lp'));
$PAGE->requires->js_call_amd('tool_lp/scaleconfig', 'init', array('#id_scaleid',
'#tool_lp_scaleconfiguration', '#id_scaleconfigbutton'));
if ($competency && $competency->has_user_competencies()) {
// The scale is used so we "freeze" the element. Though, the javascript code for the scale
// configuration requires this field so we only disable it. It is fine as setting the value
// as a constant will ensure that nobody can change it. And it's validated in the persistent anyway.
$scaleid->updateAttributes(array('disabled' => 'disabled'));
$mform->setConstant('scaleid', $competency->get('scaleid'));
}
// Disable short forms.
$mform->setDisableShortforms();
$this->add_action_buttons(true, get_string('savechanges', 'tool_lp'));
}
/**
* Convert some fields.
*
* @param stdClass $data
* @return object
*/
protected static function convert_fields(stdClass $data) {
$data = parent::convert_fields($data);
if (empty($data->scaleid)) {
$data->scaleid = null;
$data->scaleconfiguration = null;
}
return $data;
}
/**
* Extra validation.
*
* @param stdClass $data Data to validate.
* @param array $files Array of files.
* @param array $errors Currently reported errors.
* @return array of additional errors, or overridden errors.
*/
protected function extra_validation($data, $files, array &$errors) {
$newerrors = array();
// Move the error from scaleconfiguration to the form element scale ID.
if (isset($errors['scaleconfiguration']) && !isset($errors['scaleid'])) {
$newerrors['scaleid'] = $errors['scaleconfiguration'];
unset($errors['scaleconfiguration']);
}
return $newerrors;
}
}
@@ -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/>.
/**
* This file contains the form add/update a competency framework.
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\form;
defined('MOODLE_INTERNAL') || die();
use stdClass;
use core\form\persistent;
/**
* Competency framework form.
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class competency_framework extends persistent {
protected static $persistentclass = 'core_competency\\competency_framework';
/**
* Define the form - called by parent constructor
*/
public function definition() {
global $PAGE;
$mform = $this->_form;
$context = $this->_customdata['context'];
$framework = $this->get_persistent();
$mform->addElement('hidden', 'contextid');
$mform->setType('contextid', PARAM_INT);
$mform->setConstant('contextid', $context->id);
$mform->addElement('header', 'generalhdr', get_string('general'));
// Name.
$mform->addElement('text', 'shortname', get_string('shortname', 'tool_lp'), 'maxlength="100"');
$mform->setType('shortname', PARAM_TEXT);
$mform->addRule('shortname', null, 'required', null, 'client');
$mform->addRule('shortname', get_string('maximumchars', '', 100), 'maxlength', 100, 'client');
// Description.
$mform->addElement('editor', 'description',
get_string('description', 'tool_lp'), array('rows' => 4));
$mform->setType('description', PARAM_CLEANHTML);
// ID number.
$mform->addElement('text', 'idnumber', get_string('idnumber', 'tool_lp'), 'maxlength="100"');
$mform->setType('idnumber', PARAM_RAW);
$mform->addRule('idnumber', null, 'required', null, 'client');
$mform->addRule('idnumber', get_string('maximumchars', '', 100), 'maxlength', 100, 'client');
$scales = get_scales_menu();
$scaleid = $mform->addElement('select', 'scaleid', get_string('scale', 'tool_lp'), $scales);
$mform->setType('scaleid', PARAM_INT);
$mform->addHelpButton('scaleid', 'scale', 'tool_lp');
$mform->addRule('scaleid', null, 'required', null, 'client');
if ($framework && $framework->has_user_competencies()) {
// The scale is used so we "freeze" the element. Though, the javascript code for the scale
// configuration requires this field so we only disable it. It is fine as setting the value
// as a constant will ensure that nobody can change it. And it's validated in the persistent anyway.
$scaleid->updateAttributes(array('readonly' => 'readonly'));
$mform->setConstant('scaleid', $framework->get('scaleid'));
}
$mform->addElement('button', 'scaleconfigbutton', get_string('configurescale', 'tool_lp'));
// Add js.
$mform->addElement('hidden', 'scaleconfiguration', '', array('id' => 'tool_lp_scaleconfiguration'));
$mform->setType('scaleconfiguration', PARAM_RAW);
$PAGE->requires->js_call_amd('tool_lp/scaleconfig', 'init', array('#id_scaleid',
'#tool_lp_scaleconfiguration', '#id_scaleconfigbutton'));
$mform->addElement('selectyesno', 'visible',
get_string('visible', 'tool_lp'));
$mform->setDefault('visible', true);
$mform->addHelpButton('visible', 'visible', 'tool_lp');
$mform->addElement('static', 'context', get_string('category', 'tool_lp'));
$mform->setDefault('context', $context->get_context_name(false));
$mform->addElement('header', 'taxonomyhdr', get_string('taxonomies', 'tool_lp'));
$taxonomies = \core_competency\competency_framework::get_taxonomies_list();
$taxdefaults = array();
$taxcount = max($framework ? $framework->get_depth() : 4, 4);
for ($i = 1; $i <= $taxcount; $i++) {
$mform->addElement('select', "taxonomies[$i]", get_string('levela', 'tool_lp', $i), $taxonomies);
$taxdefaults[$i] = \core_competency\competency_framework::TAXONOMY_COMPETENCY;
}
// Not using taxonomies[n] here or it would takes precedence over set_data(array('taxonomies' => ...)).
$mform->setDefault('taxonomies', $taxdefaults);
$this->add_action_buttons(true, get_string('savechanges', 'tool_lp'));
}
/**
* Convert some fields.
*
* @param stdClass $data
* @return object
*/
protected static function convert_fields(stdClass $data) {
$data = parent::convert_fields($data);
$data->taxonomies = implode(',', $data->taxonomies);
return $data;
}
/**
* Extra validation.
*
* @param stdClass $data Data to validate.
* @param array $files Array of files.
* @param array $errors Currently reported errors.
* @return array of additional errors, or overridden errors.
*/
protected function extra_validation($data, $files, array &$errors) {
$newerrors = array();
// Move the error from scaleconfiguration to the form element scale ID.
if (isset($errors['scaleconfiguration']) && !isset($errors['scaleid'])) {
$newerrors['scaleid'] = $errors['scaleconfiguration'];
unset($errors['scaleconfiguration']);
}
return $newerrors;
}
/**
* Get the default data.
*
* @return stdClass
*/
protected function get_default_data() {
$data = parent::get_default_data();
$data->taxonomies = $this->get_persistent()->get('taxonomies');
return $data;
}
}
@@ -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/>.
/**
* Framework selector field.
*
* @package tool_lp
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\form;
use coding_exception;
use MoodleQuickForm_autocomplete;
use \core_competency\competency_framework;
global $CFG;
require_once($CFG->libdir . '/form/autocomplete.php');
/**
* Form field type for choosing a framework.
*
* @package tool_lp
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class framework_autocomplete extends MoodleQuickForm_autocomplete {
/** @var bool Only visible frameworks? */
protected $onlyvisible = false;
/**
* Constructor.
*
* @param string $elementName Element name
* @param mixed $elementLabel Label(s) for an element
* @param array $options Options to control the element's display
* Valid options are:
* - context context The context.
* - contextid int The context id.
* - multiple bool Whether or not the field accepts more than one values.
* - onlyvisible bool Whether or not only visible framework can be listed.
*/
public function __construct($elementName = null, $elementLabel = null, $options = array()) {
$contextid = null;
if (!empty($options['contextid'])) {
$contextid = $options['contextid'];
} else if (!empty($options['context'])) {
$contextid = $options['context']->id;
}
$this->onlyvisible = !empty($options['onlyvisible']);
$validattributes = array(
'ajax' => 'tool_lp/frameworks_datasource',
'data-contextid' => $contextid,
'data-onlyvisible' => $this->onlyvisible ? '1' : '0',
);
if (!empty($options['multiple'])) {
$validattributes['multiple'] = 'multiple';
}
parent::__construct($elementName, $elementLabel, array(), $validattributes);
}
/**
* Set the value of this element.
*
* @param string|array $value The value to set.
* @return boolean
*/
public function setValue($value) {
global $DB;
$values = (array) $value;
$ids = array();
foreach ($values as $onevalue) {
if (!empty($onevalue) && (!$this->optionExists($onevalue)) &&
($onevalue !== '_qf__force_multiselect_submission')) {
array_push($ids, $onevalue);
}
}
if (empty($ids)) {
return $this->setSelected(array());
}
// Logic here is simulating API.
$toselect = array();
list($insql, $inparams) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED, 'param');
$frameworks = competency_framework::get_records_select("id $insql", $inparams, 'shortname');
foreach ($frameworks as $framework) {
if (!has_any_capability(array('moodle/competency:competencyview', 'moodle/competency:competencymanage'),
$framework->get_context())) {
continue;
} else if ($this->onlyvisible && !$framework->get('visible')) {
continue;
}
$this->addOption($framework->get('shortname') . ' ' . $framework->get('idnumber'), $framework->get('id'));
array_push($toselect, $framework->get('id'));
}
return $this->setSelected($toselect);
}
}
+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/>.
/**
* This file contains the form add/update a learning plan.
*
* @package tool_lp
* @copyright 2015 David Monllao
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\form;
defined('MOODLE_INTERNAL') || die();
use core\form\persistent;
use core_competency\plan as planpersistent;
use required_capability_exception;
/**
* Learning plan form.
*
* @package tool_lp
* @copyright 2015 David Monllao
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class plan extends persistent {
protected static $persistentclass = 'core_competency\\plan';
/**
* Define the form - called by parent constructor
*/
public function definition() {
$mform = $this->_form;
$context = $this->_customdata['context'];
$mform->addElement('hidden', 'userid');
$mform->setType('userid', PARAM_INT);
$mform->setConstant('userid', $this->_customdata['userid']);
$mform->addElement('header', 'generalhdr', get_string('general'));
// Name.
$mform->addElement('text', 'name', get_string('planname', 'tool_lp'), 'maxlength="100"');
$mform->setType('name', PARAM_TEXT);
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', get_string('maximumchars', '', 100), 'maxlength', 100, 'client');
// Description.
$mform->addElement('editor', 'description', get_string('plandescription', 'tool_lp'), array('rows' => 4));
$mform->setType('description', PARAM_CLEANHTML);
$mform->addElement('date_time_selector', 'duedate', get_string('duedate', 'tool_lp'), array('optional' => true));
$mform->addHelpButton('duedate', 'duedate', 'tool_lp');
// Display status selector in form.
// When the plan was already saved then the status can not be changed via this form.
$status = planpersistent::get_status_list($this->_customdata['userid']);
$plan = $this->get_persistent();
if ($plan->get('id')) {
// The current status is not selectable (workflow status probably), we just display it.
$mform->addElement('static', 'staticstatus', get_string('status', 'tool_lp'), $plan->get_statusname());
} else if (!empty($status) && count($status) > 1) {
// There is more than one status to select from.
$mform->addElement('select', 'status', get_string('status', 'tool_lp'), $status);
} else if (count($status) === 1) {
// There is only one status to select from.
$mform->addElement('static', 'staticstatus', get_string('status', 'tool_lp'), current($status));
} else {
throw new required_capability_exception($context, 'moodle/competency:planmanage', 'nopermissions', '');
}
// Disable short forms.
$mform->setDisableShortforms();
$this->add_action_buttons(true, get_string('savechanges', 'tool_lp'));
}
}
+84
View File
@@ -0,0 +1,84 @@
<?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 file contains the form add/update a competency framework.
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\form;
defined('MOODLE_INTERNAL') || die();
use core\form\persistent;
/**
* Learning plan template form.
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class template extends persistent {
protected static $persistentclass = 'core_competency\\template';
/**
* Define the form - called by parent constructor
*/
public function definition() {
$mform = $this->_form;
$context = $this->_customdata['context'];
$mform->addElement('hidden', 'contextid');
$mform->setType('contextid', PARAM_INT);
$mform->setConstant('contextid', $context->id);
$mform->addElement('header', 'generalhdr', get_string('general'));
// Name.
$mform->addElement('text', 'shortname', get_string('shortname', 'tool_lp'), 'maxlength="100"');
$mform->setType('shortname', PARAM_TEXT);
$mform->addRule('shortname', null, 'required', null, 'client');
$mform->addRule('shortname', get_string('maximumchars', '', 100), 'maxlength', 100, 'client');
// Description.
$mform->addElement('editor', 'description',
get_string('description', 'tool_lp'), array('rows' => 4));
$mform->setType('description', PARAM_CLEANHTML);
$mform->addElement('selectyesno', 'visible',
get_string('visible', 'tool_lp'));
$mform->addElement('date_time_selector',
'duedate',
get_string('duedate', 'tool_lp'),
array('optional' => true));
$mform->addHelpButton('duedate', 'duedate', 'tool_lp');
$mform->setDefault('visible', true);
$mform->addHelpButton('visible', 'visible', 'tool_lp');
$mform->addElement('static', 'context', get_string('category', 'tool_lp'));
$mform->setDefault('context', $context->get_context_name(false));
// Disable short forms.
$mform->setDisableShortforms();
$this->add_action_buttons(true, get_string('savechanges', 'tool_lp'));
}
}
@@ -0,0 +1,57 @@
<?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/>.
/**
* Template cohorts form.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\form;
defined('MOODLE_INTERNAL') || die();
use moodleform;
require_once($CFG->libdir . '/formslib.php');
/**
* Template cohorts form class.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class template_cohorts extends moodleform {
/**
* Form definition
*
* @return void
*/
public function definition() {
$mform = $this->_form;
$options = array(
'multiple' => true,
'exclude' => implode(',', $this->_customdata['excludecohorts']),
'contextid' => $this->_customdata['pagecontextid'],
);
$mform->addElement('cohort', 'cohorts', get_string('selectcohortstosync', 'tool_lp'), $options);
$mform->addElement('submit', 'submit', get_string('addcohorts', 'tool_lp'));
}
}
@@ -0,0 +1,54 @@
<?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/>.
/**
* Template plans form.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\form;
defined('MOODLE_INTERNAL') || die();
use moodleform;
use core\form\persistent;
require_once($CFG->libdir . '/formslib.php');
/**
* Template plans form class.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class template_plans extends moodleform {
public function definition() {
$mform = $this->_form;
$options = array(
'ajax' => 'tool_lp/form-user-selector',
'multiple' => true,
'data-capability' => 'moodle/competency:planmanage'
);
$mform->addElement('autocomplete', 'users', get_string('selectuserstocreateplansfor', 'tool_lp'), array(), $options);
$mform->addElement('submit', 'submit', get_string('createplans', 'tool_lp'));
}
}
@@ -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/>.
/**
* User evidence form.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\form;
defined('MOODLE_INTERNAL') || die();
use core\form\persistent;
/**
* User evidence form class.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_evidence extends persistent {
protected static $persistentclass = 'core_competency\\user_evidence';
protected static $foreignfields = array('files');
public function definition() {
$mform = $this->_form;
$mform->addElement('hidden', 'userid');
$mform->setType('userid', PARAM_INT);
$mform->setConstant('userid', $this->_customdata['userid']);
$mform->addElement('header', 'generalhdr', get_string('general'));
// Name.
$mform->addElement('text', 'name', get_string('userevidencename', 'tool_lp'), 'maxlength="100"');
$mform->setType('name', PARAM_TEXT);
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', get_string('maximumchars', '', 100), 'maxlength', 100, 'client');
// Description.
$mform->addElement('editor', 'description', get_string('userevidencedescription', 'tool_lp'), array('rows' => 10));
$mform->setType('description', PARAM_CLEANHTML);
$mform->addElement('url', 'url', get_string('userevidenceurl', 'tool_lp'), array('size' => '60'), array('usefilepicker' => false));
$mform->setType('url', PARAM_RAW_TRIMMED); // Can not use PARAM_URL, it silently converts bad URLs to ''.
$mform->addHelpButton('url', 'userevidenceurl', 'tool_lp');
$mform->addElement('filemanager', 'files', get_string('userevidencefiles', 'tool_lp'), array(),
$this->_customdata['fileareaoptions']);
// Disable short forms.
$mform->setDisableShortforms();
$this->add_action_buttons();
}
}
@@ -0,0 +1,99 @@
<?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 competency plan page class.
*
* @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\output;
use renderable;
use renderer_base;
use templatable;
use context_course;
use core_competency\external\competency_exporter;
use core_competency\external\performance_helper;
use stdClass;
/**
* User competency plan navigation class.
*
* @package tool_lp
* @copyright 2016 Issam Taboubi <issam.taboubi@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class competency_plan_navigation implements renderable, templatable {
/** @var userid */
protected $userid;
/** @var competencyid */
protected $competencyid;
/** @var planid */
protected $planid;
/** @var baseurl */
protected $baseurl;
/**
* Construct.
*
* @param int $userid
* @param int $competencyid
* @param int $planid
* @param string $baseurl
*/
public function __construct($userid, $competencyid, $planid, $baseurl) {
$this->userid = $userid;
$this->competencyid = $competencyid;
$this->planid = $planid;
$this->baseurl = $baseurl;
}
/**
* Export the data.
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
$data = new stdClass();
$data->userid = $this->userid;
$data->competencyid = $this->competencyid;
$data->planid = $this->planid;
$data->baseurl = $this->baseurl;
$plancompetencies = \core_competency\api::list_plan_competencies($data->planid);
$data->competencies = array();
$helper = new performance_helper();
foreach ($plancompetencies as $plancompetency) {
$context = $helper->get_context_from_competency($plancompetency->competency);
$exporter = new competency_exporter($plancompetency->competency, array('context' => $context));
$competency = $exporter->export($output);
if ($competency->id == $this->competencyid) {
$competency->selected = true;
}
$data->competencies[] = $competency;
}
$data->hascompetencies = count($data->competencies);
return $data;
}
}
@@ -0,0 +1,94 @@
<?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 competency_page page
*
* @package tool_lp
* @copyright 2015 Issam Taboubi <issam.taboubi@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
defined('MOODLE_INTERNAL') || die();
use renderable;
use templatable;
use renderer_base;
use stdClass;
use core_competency\api;
use tool_lp\external\competency_summary_exporter;
/**
* Class containing data for competency summary
*
* @copyright 2015 Issam Taboubi <issam.taboubi@umontreal.ca>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class competency_summary implements renderable, templatable {
/** @var \core_competency\competency_framework $framework This competency framework. */
protected $framework = null;
/** @var \core_competency\competency $competency. */
protected $competency = null;
/** @var \core_competency\competency[] $relatedcompetencies List of competencies. */
protected $relatedcompetencies = array();
/** @var course[] $courses List of courses. */
protected $courses = array();
/**
* Construct this renderable.
*
* @param \core_competency\competency $competency Competency persistent.
* @param \core_competency\competency_framework $framework framework persistent.
* @param boolean $includerelated Include or not related competencies.
* @param boolean $includecourses Include or not competency courses.
*/
public function __construct($competency, $framework, $includerelated, $includecourses) {
$this->competency = $competency;
$this->framework = $framework;
if ($includerelated) {
$this->relatedcompetencies = api::list_related_competencies($competency->get('id'));
}
if ($includecourses) {
$this->courses = api::list_courses_using_competency($competency->get('id'));
}
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output Renderer base.
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
$related = array(
'context' => $this->framework->get_context(),
'framework' => $this->framework,
'linkedcourses' => $this->courses,
'relatedcompetencies' => $this->relatedcompetencies,
'competency' => $this->competency
);
$exporter = new competency_summary_exporter($this->competency, $related);
$data = $exporter->export($output);
return $data;
}
}
@@ -0,0 +1,265 @@
<?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 course competencies page
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
defined('MOODLE_INTERNAL') || die();
use renderable;
use templatable;
use renderer_base;
use stdClass;
use moodle_url;
use context_system;
use context_course;
use core_competency\api;
use tool_lp\course_competency_statistics;
use core_competency\competency;
use core_competency\course_competency;
use core_competency\external\performance_helper;
use core_competency\external\competency_exporter;
use core_competency\external\course_competency_exporter;
use core_competency\external\course_competency_settings_exporter;
use core_competency\external\user_competency_course_exporter;
use core_competency\external\user_competency_exporter;
use core_competency\external\plan_exporter;
use tool_lp\external\competency_path_exporter;
use tool_lp\external\course_competency_statistics_exporter;
use core_course\external\course_module_summary_exporter;
/**
* Class containing data for course competencies page
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class course_competencies_page implements renderable, templatable {
/** @var int $courseid Course id for this page. */
protected $courseid = null;
/** @var int $moduleid Module id for this page. */
protected $moduleid = null;
/** @var context $context The context for this page. */
protected $context = null;
/** @var \core_competency\course_competency[] $competencies List of competencies. */
protected $coursecompetencylist = array();
/** @var bool $canmanagecompetencyframeworks Can the current user manage competency frameworks. */
protected $canmanagecompetencyframeworks = false;
/** @var bool $canmanagecoursecompetencies Can the current user manage course competency frameworks.. */
protected $canmanagecoursecompetencies = false;
/** @var string $manageurl manage url. */
protected $manageurl = null;
/** @var bool */
protected bool $canconfigurecoursecompetencies = false;
/** @var bool */
protected bool $cangradecompetencies = false;
/** @var \core\persistent|null */
protected $coursecompetencysettings = null;
/** @var \tool_lp\course_competency_statistics|null */
protected $coursecompetencystatistics = null;
/**
* Construct this renderable.
* @param int $courseid The course record for this page.
*/
public function __construct($courseid, $moduleid) {
$this->context = context_course::instance($courseid);
$this->courseid = $courseid;
$this->moduleid = $moduleid;
$this->coursecompetencylist = api::list_course_competencies($courseid);
if ($this->moduleid > 0) {
$modulecompetencies = api::list_course_module_competencies_in_course_module($this->moduleid);
foreach ($this->coursecompetencylist as $ccid => $coursecompetency) {
$coursecompetency = $coursecompetency['coursecompetency'];
$found = false;
foreach ($modulecompetencies as $mcid => $modulecompetency) {
if ($modulecompetency->get('competencyid') == $coursecompetency->get('competencyid')) {
$found = true;
break;
}
}
if (!$found) {
// We need to filter out this competency.
unset($this->coursecompetencylist[$ccid]);
}
}
}
$this->canmanagecoursecompetencies = has_capability('moodle/competency:coursecompetencymanage', $this->context);
$this->canconfigurecoursecompetencies = has_capability('moodle/competency:coursecompetencyconfigure', $this->context);
$this->cangradecompetencies = has_capability('moodle/competency:competencygrade', $this->context);
$this->coursecompetencysettings = api::read_course_competency_settings($courseid);
$this->coursecompetencystatistics = new course_competency_statistics($courseid);
// Check the lowest level in which the user can manage the competencies.
$this->manageurl = null;
$this->canmanagecompetencyframeworks = false;
$contexts = array_reverse($this->context->get_parent_contexts(true));
foreach ($contexts as $context) {
$canmanage = has_capability('moodle/competency:competencymanage', $context);
if ($canmanage) {
$this->manageurl = new moodle_url('/admin/tool/lp/competencyframeworks.php',
array('pagecontextid' => $context->id));
$this->canmanagecompetencyframeworks = true;
break;
}
}
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output Renderer base.
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
global $USER;
$data = new stdClass();
$data->courseid = $this->courseid;
$data->moduleid = $this->moduleid;
$data->pagecontextid = $this->context->id;
$data->competencies = array();
$data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
$gradable = is_enrolled($this->context, $USER, 'moodle/competency:coursecompetencygradable');
if ($gradable) {
$usercompetencycourses = api::list_user_competencies_in_course($this->courseid, $USER->id);
$data->gradableuserid = $USER->id;
if ($this->moduleid > 0) {
$modulecompetencies = api::list_course_module_competencies_in_course_module($this->moduleid);
foreach ($usercompetencycourses as $ucid => $usercoursecompetency) {
$found = false;
foreach ($modulecompetencies as $mcid => $modulecompetency) {
if ($modulecompetency->get('competencyid') == $usercoursecompetency->get('competencyid')) {
$found = true;
break;
}
}
if (!$found) {
// We need to filter out this competency.
unset($usercompetencycourses[$ucid]);
}
}
}
}
$ruleoutcomelist = course_competency::get_ruleoutcome_list();
$ruleoutcomeoptions = array();
foreach ($ruleoutcomelist as $value => $text) {
$ruleoutcomeoptions[$value] = array('value' => $value, 'text' => (string) $text, 'selected' => false);
}
$helper = new performance_helper();
foreach ($this->coursecompetencylist as $coursecompetencyelement) {
$coursecompetency = $coursecompetencyelement['coursecompetency'];
$competency = $coursecompetencyelement['competency'];
$context = $helper->get_context_from_competency($competency);
$compexporter = new competency_exporter($competency, array('context' => $context));
$ccexporter = new course_competency_exporter($coursecompetency, array('context' => $context));
$ccoutcomeoptions = (array) (object) $ruleoutcomeoptions;
$ccoutcomeoptions[$coursecompetency->get('ruleoutcome')]['selected'] = true;
$coursemodules = api::list_course_modules_using_competency($competency->get('id'), $this->courseid);
$fastmodinfo = get_fast_modinfo($this->courseid);
$exportedmodules = array();
foreach ($coursemodules as $cmid) {
$cminfo = $fastmodinfo->cms[$cmid];
$cmexporter = new course_module_summary_exporter(null, array('cm' => $cminfo));
$exportedmodules[] = $cmexporter->export($output);
}
// Competency path.
$pathexporter = new competency_path_exporter([
'ancestors' => $competency->get_ancestors(),
'framework' => $helper->get_framework_from_competency($competency),
'context' => $context
]);
// User learning plans.
$plans = api::list_plans_with_competency($USER->id, $competency);
$exportedplans = array();
foreach ($plans as $plan) {
$planexporter = new plan_exporter($plan, array('template' => $plan->get_template()));
$exportedplans[] = $planexporter->export($output);
}
$onerow = array(
'competency' => $compexporter->export($output),
'coursecompetency' => $ccexporter->export($output),
'ruleoutcomeoptions' => $ccoutcomeoptions,
'coursemodules' => $exportedmodules,
'comppath' => $pathexporter->export($output),
'plans' => $exportedplans
);
if ($gradable) {
$foundusercompetencycourse = false;
foreach ($usercompetencycourses as $usercompetencycourse) {
if ($usercompetencycourse->get('competencyid') == $competency->get('id')) {
$foundusercompetencycourse = $usercompetencycourse;
}
}
if ($foundusercompetencycourse) {
$related = array(
'scale' => $helper->get_scale_from_competency($competency)
);
$exporter = new user_competency_course_exporter($foundusercompetencycourse, $related);
$onerow['usercompetencycourse'] = $exporter->export($output);
}
}
array_push($data->competencies, $onerow);
}
$data->canmanagecompetencyframeworks = $this->canmanagecompetencyframeworks;
$data->canmanagecoursecompetencies = $this->canmanagecoursecompetencies;
$data->canconfigurecoursecompetencies = $this->canconfigurecoursecompetencies;
$data->cangradecompetencies = $this->cangradecompetencies;
$exporter = new course_competency_settings_exporter($this->coursecompetencysettings);
$data->settings = $exporter->export($output);
$related = array('context' => $this->context);
$exporter = new course_competency_statistics_exporter($this->coursecompetencystatistics, $related);
$data->statistics = $exporter->export($output);
$data->manageurl = null;
if ($this->canmanagecompetencyframeworks) {
$data->manageurl = $this->manageurl->out(true);
}
return $data;
}
}
@@ -0,0 +1,137 @@
<?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 managecompetencyframeworks page
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
defined('MOODLE_INTERNAL') || die();
use renderable;
use templatable;
use renderer_base;
use single_button;
use stdClass;
use moodle_url;
use context_system;
use core_competency\api;
use core_competency\competency;
use core_competency\competency_framework;
use core_competency\external\competency_framework_exporter;
/**
* Class containing data for managecompetencies page
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class manage_competencies_page implements renderable, templatable {
/** @var \core_competency\competency_framework $framework This competency framework. */
protected $framework = null;
/** @var \core_competency\competency[] $competencies List of competencies. */
protected $competencies = array();
/** @var string $search Text to search for. */
protected $search = '';
/** @var bool $canmanage Result of permissions checks. */
protected $canmanage = false;
/** @var moodle_url $pluginurlbase Base url to use constructing links. */
protected $pluginbaseurl = null;
/** @var \context $pagecontext The page context. */
protected $pagecontext = null;
/** @var \core_competency\competency $competency The competency to show when the page loads. */
protected $competency = null;
/** @var array */
protected array $navigation = [];
/**
* Construct this renderable.
*
* @param \core_competency\competency_framework $framework Competency framework.
* @param string $search Search string.
* @param \context $pagecontext The page context.
* @param \core_competency\competency $competency The core competency to show when the page loads.
*/
public function __construct($framework, $search, $pagecontext, $competency) {
$this->framework = $framework;
$this->pagecontext = $pagecontext;
$this->search = $search;
$this->competency = $competency;
$addpage = new single_button(
new moodle_url('/admin/tool/lp/editcompetencyframework.php'),
get_string('addnewcompetency', 'tool_lp')
);
$this->navigation[] = $addpage;
$this->canmanage = has_capability('moodle/competency:competencymanage', $framework->get_context());
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output Renderer base.
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
$data = new stdClass();
$exporter = new competency_framework_exporter($this->framework);
$data->framework = $exporter->export($output);
$data->canmanage = $this->canmanage;
$data->search = $this->search;
$data->pagecontextid = $this->pagecontext->id;
$data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
$data->competencyid = 0;
if ($this->competency) {
$data->competencyid = $this->competency->get('id');
}
$rulesmodules = array();
$rules = competency::get_available_rules();
foreach ($rules as $type => $rulename) {
$amd = null;
if ($type == 'core_competency\\competency_rule_all') {
$amd = 'tool_lp/competency_rule_all';
} else if ($type == 'core_competency\\competency_rule_points') {
$amd = 'tool_lp/competency_rule_points';
} else {
// We do not know how to display that rule.
continue;
}
$rulesmodules[] = [
'name' => (string) $rulename,
'type' => $type,
'amd' => $amd,
];
}
$data->rulesmodules = json_encode(array_values($rulesmodules));
return $data;
}
}
@@ -0,0 +1,110 @@
<?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 managecompetencyframeworks page
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
defined('MOODLE_INTERNAL') || die();
use renderable;
use templatable;
use renderer_base;
use single_button;
use stdClass;
use moodle_url;
use context;
use context_system;
use core_competency\api;
use core_competency\competency_framework;
use core_competency\external\competency_framework_exporter;
/**
* Class containing data for managecompetencyframeworks page
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class manage_competency_frameworks_page implements renderable, templatable {
/** @var context The context in which everything is happening. */
protected $pagecontext;
/** @var array $navigation List of links to display on the page. Each link contains a url and a title. */
protected $navigation = array();
/** @var array $competencyframeworks List of competency frameworks. */
protected $competencyframeworks = array();
/** @var bool $canmanage Result of permissions checks. */
protected $canmanage = false;
/** @var moodle_url $pluginurlbase Base url to use constructing links. */
protected $pluginbaseurl = null;
/**
* Construct this renderable.
*
* @param context $pagecontext The page context
*/
public function __construct(context $pagecontext) {
$this->pagecontext = $pagecontext;
if (competency_framework::can_manage_context($this->pagecontext)) {
$addpage = new single_button(
new moodle_url('/admin/tool/lp/editcompetencyframework.php', array('pagecontextid' => $this->pagecontext->id)),
get_string('addnewcompetencyframework', 'tool_lp'),
'get'
);
$this->navigation[] = $addpage;
$competenciesrepository = new single_button(
new moodle_url('https://moodle.net/search', ['q' => 'competency frameworks']),
get_string('competencyframeworksrepository', 'tool_lp'),
'get'
);
$this->navigation[] = $competenciesrepository;
}
$this->competencyframeworks = api::list_frameworks('shortname', 'ASC', 0, 0, $this->pagecontext);
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output Renderer base.
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
$data = new stdClass();
$data->competencyframeworks = array();
$data->pagecontextid = $this->pagecontext->id;
foreach ($this->competencyframeworks as $framework) {
$exporter = new competency_framework_exporter($framework);
$data->competencyframeworks[] = $exporter->export($output);
}
$data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
$data->navigation = array();
foreach ($this->navigation as $button) {
$data->navigation[] = $output->render($button);
}
return $data;
}
}
@@ -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/>.
/**
* Class containing data for managelearningplans page
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
defined('MOODLE_INTERNAL') || die();
use context;
use renderable;
use templatable;
use renderer_base;
use single_button;
use stdClass;
use moodle_url;
use context_system;
use core_competency\api;
use core_competency\template;
use core_competency\external\template_exporter;
/**
* Class containing data for managecompetencyframeworks page
*
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class manage_templates_page implements renderable, templatable {
/** @var context The context in which everything is happening. */
protected $pagecontext;
/** @var array $navigation List of links to display on the page. Each link contains a url and a title. */
protected $navigation = array();
/** @var array $templates List of learning plan templates. */
protected $templates = array();
/**
* Construct this renderable.
* @param context $pagecontext
*/
public function __construct(context $pagecontext) {
$this->pagecontext = $pagecontext;
if (template::can_manage_context($this->pagecontext)) {
$addpage = new single_button(
new moodle_url('/admin/tool/lp/edittemplate.php', array('pagecontextid' => $this->pagecontext->id)),
get_string('addnewtemplate', 'tool_lp'),
'get'
);
$this->navigation[] = $addpage;
}
$this->templates = api::list_templates('shortname', 'ASC', 0, 0, $this->pagecontext);
}
/**
* Export this data so it can be used as the context for a mustache template.
*
* @param renderer_base $output Renderer base.
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
$data = new stdClass();
$data->pagecontextid = $this->pagecontext->id;
$data->templates = array();
foreach ($this->templates as $template) {
$exporter = new template_exporter($template);
$data->templates[] = $exporter->export($output);
}
$data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
$data->navigation = array();
foreach ($this->navigation as $button) {
$data->navigation[] = $output->render($button);
}
$data->canmanage = template::can_manage_context($this->pagecontext);
return $data;
}
}
@@ -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/>.
/**
* User navigation class.
*
* @package tool_lp
* @copyright 2019 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
defined('MOODLE_INTERNAL') || die();
use renderable;
use renderer_base;
use templatable;
use context_course;
use core_course\external\course_module_summary_exporter;
use stdClass;
/**
* User course navigation class.
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class module_navigation implements renderable, templatable {
/** @var courseid */
protected $courseid;
/** @var moduleid */
protected $moduleid;
/** @var baseurl */
protected $baseurl;
/**
* Construct.
*
* @param int $courseid
* @param int $moduleid
* @param string $baseurl
*/
public function __construct($courseid, $moduleid, $baseurl) {
$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) {
$context = context_course::instance($this->courseid);
$data = new stdClass();
$data->courseid = $this->courseid;
$data->moduleid = $this->moduleid;
$data->baseurl = $this->baseurl;
$data->hasmodules = false;
$data->modules = array();
$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;
}
}
return $data;
}
}
+124
View File
@@ -0,0 +1,124 @@
<?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/>.
/**
* Plan page output.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
defined('MOODLE_INTERNAL') || die();
use renderable;
use templatable;
use stdClass;
use moodle_url;
use core_competency\api;
use core_competency\external\performance_helper;
use core_competency\plan;
use core_competency\external\competency_exporter;
use core_competency\external\plan_exporter;
use tool_lp\external\competency_path_exporter;
/**
* Plan page class.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class plan_page implements renderable, templatable {
/** @var plan */
protected $plan;
/**
* Construct.
*
* @param plan $plan
*/
public function __construct($plan) {
$this->plan = $plan;
}
/**
* Export the data.
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(\renderer_base $output) {
$planexporter = new plan_exporter($this->plan, array('template' => $this->plan->get_template()));
$data = new stdClass();
$data->plan = $planexporter->export($output);
$data->competencies = array();
$data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(false);
$data->contextid = $this->plan->get_context()->id;
if ($data->plan->iscompleted) {
$ucproperty = 'usercompetencyplan';
$ucexporter = 'core_competency\\external\\user_competency_plan_exporter';
} else {
$ucproperty = 'usercompetency';
$ucexporter = 'core_competency\\external\\user_competency_exporter';
}
$helper = new performance_helper();
$pclist = api::list_plan_competencies($this->plan);
$proficientcount = 0;
foreach ($pclist as $pc) {
$comp = $pc->competency;
$usercomp = $pc->$ucproperty;
$compcontext = $helper->get_context_from_competency($comp);
$framework = $helper->get_framework_from_competency($comp);
$scale = $helper->get_scale_from_competency($comp);
// Prepare the data.
$record = new stdClass();
$exporter = new competency_exporter($comp, array('context' => $compcontext));
$record->competency = $exporter->export($output);
// Competency path.
$exporter = new competency_path_exporter([
'ancestors' => $comp->get_ancestors(),
'framework' => $framework,
'context' => $compcontext
]);
$record->comppath = $exporter->export($output);
$exporter = new $ucexporter($usercomp, array('scale' => $scale));
$record->$ucproperty = $exporter->export($output);
$data->competencies[] = $record;
if ($usercomp->get('proficiency')) {
$proficientcount++;
}
}
$data->competencycount = count($data->competencies);
$data->proficientcompetencycount = $proficientcount;
if ($data->competencycount) {
$data->proficientcompetencypercentage = ((float) $proficientcount / (float) $data->competencycount) * 100.0;
} else {
$data->proficientcompetencypercentage = 0.0;
}
$data->proficientcompetencypercentageformatted = format_float($data->proficientcompetencypercentage);
return $data;
}
}
+108
View File
@@ -0,0 +1,108 @@
<?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 a user learning plans list page.
*
* @package tool_lp
* @copyright 2015 David Monllao
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
defined('MOODLE_INTERNAL') || die();
use renderable;
use templatable;
use renderer_base;
use stdClass;
use single_button;
use moodle_url;
use core_competency\api;
use core_competency\external\plan_exporter;
use core_competency\plan;
use core_competency\user_evidence;
use context_user;
/**
* Class containing data for a user learning plans list page.
*
* @copyright 2015 David Monllao
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class plans_page implements renderable, templatable {
/** @var array $navigation List of links to display on the page. Each link contains a url and a title. */
protected $navigation = array();
/** @var array|\core_competency\plan[] $plans List of plans. */
protected $plans = array();
/** @var context_user|null $context context. */
protected $context = null;
/** @var int|null $userid Userid. */
protected $userid = null;
/**
* Construct this renderable.
*
* @param int $userid
*/
public function __construct($userid) {
$this->userid = $userid;
$this->plans = api::list_user_plans($userid);
$this->context = context_user::instance($userid);
if (plan::can_manage_user($userid) || plan::can_manage_user_draft($userid)) {
$addplan = new single_button(
new moodle_url('/admin/tool/lp/editplan.php', array('userid' => $userid)),
get_string('addnewplan', 'tool_lp'), 'get'
);
$this->navigation[] = $addplan;
}
}
/**
* 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) {
$data = new stdClass();
$data->userid = $this->userid;
$data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
$data->canreaduserevidence = user_evidence::can_read_user($this->userid);
$data->canmanageuserplans = plan::can_manage_user($this->userid);
// Attach standard objects as mustache can not parse \core_competency\plan objects.
$data->plans = array();
if ($this->plans) {
foreach ($this->plans as $plan) {
$exporter = new plan_exporter($plan, array('template' => $plan->get_template()));
$record = $exporter->export($output);
$data->plans[] = $record;
}
}
$data->navigation = array();
foreach ($this->navigation as $button) {
$data->navigation[] = $output->render($button);
}
return $data;
}
}
@@ -0,0 +1,86 @@
<?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 a competency.
*
* @package tool_lp
* @copyright 2015 David Monllao
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
defined('MOODLE_INTERNAL') || die();
use renderable;
use templatable;
use renderer_base;
use stdClass;
use moodle_url;
use core_competency\api;
use core_competency\external\competency_exporter;
/**
* Class containing data for related competencies.
*
* @package tool_lp
* @copyright 2015 David Monllao
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class related_competencies implements renderable, templatable {
/** @var array Related competencies. */
protected $relatedcompetencies = null;
/** @var \core_competency\competency|null */
protected $competency = null;
/** @var \context|null */
protected $context = null;
/**
* Construct this renderable.
*
* @param int $competencyid
*/
public function __construct($competencyid) {
$this->competency = api::read_competency($competencyid);
$this->context = $this->competency->get_context();
$this->relatedcompetencies = api::list_related_competencies($competencyid);
}
/**
* 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) {
$data = new stdClass();
$data->relatedcompetencies = array();
if ($this->relatedcompetencies) {
foreach ($this->relatedcompetencies as $competency) {
$exporter = new competency_exporter($competency, array('context' => $this->context));
$record = $exporter->export($output);
$data->relatedcompetencies[] = $record;
}
}
// We checked the user permissions in the constructor.
$data->showdeleterelatedaction = true;
return $data;
}
}
+278
View File
@@ -0,0 +1,278 @@
<?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 learning plans
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
defined('MOODLE_INTERNAL') || die();
use plugin_renderer_base;
use renderable;
/**
* Renderer class for learning plans
*
* @package tool_lp
* @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 manage_competency_frameworks_page $page
*
* @return string html for the page
*/
public function render_manage_competency_frameworks_page(manage_competency_frameworks_page $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('tool_lp/manage_competency_frameworks_page', $data);
}
/**
* Defer to template.
*
* @param manage_competencies_page $page
*
* @return string html for the page
*/
public function render_manage_competencies_page(manage_competencies_page $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('tool_lp/manage_competencies_page', $data);
}
/**
* Defer to template.
*
* @param course_competencies_page $page
*
* @return string html for the page
*/
public function render_course_competencies_page(course_competencies_page $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('tool_lp/course_competencies_page', $data);
}
/**
* Defer to template.
*
* @param template_competencies_page $page
*
* @return string html for the page
*/
public function render_template_competencies_page(template_competencies_page $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('tool_lp/template_competencies_page', $data);
}
/**
* Defer to template.
*
* @param manage_templates_page $page
*
* @return string html for the page
*/
public function render_manage_templates_page(manage_templates_page $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('tool_lp/manage_templates_page', $data);
}
/**
* Defer to template.
*
* @param plan_page $page
* @return bool|string
*/
public function render_plan_page(plan_page $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('tool_lp/plan_page', $data);
}
/**
* Defer to template.
*
* @param plans_page $page
* @return bool|string
*/
public function render_plans_page(plans_page $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('tool_lp/plans_page', $data);
}
/**
* Defer to template.
*
* @param renderable $page
* @return string
*/
public function render_related_competencies_section(renderable $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('tool_lp/related_competencies', $data);
}
/**
* Defer to template.
*
* @param user_competency_summary_in_course $page
* @return string
*/
public function render_user_competency_summary_in_course(user_competency_summary_in_course $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('tool_lp/user_competency_summary_in_course', $data);
}
/**
* Defer to template.
*
* @param user_competency_summary_in_plan $page
* @return string
*/
public function render_user_competency_summary_in_plan(user_competency_summary_in_plan $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('tool_lp/user_competency_summary_in_plan', $data);
}
/**
* Render the template plans page.
*
* @param renderable $page
* @return string
*/
public function render_template_plans_page(renderable $page) {
return $page->table->out(50, true);
}
/**
* Render the template cohorts page.
*
* @param renderable $page
* @return string
*/
public function render_template_cohorts_page(renderable $page) {
return $page->table->out(50, true);
}
/**
* Defer to template.
*
* @param user_evidence_page $page
* @return string
*/
public function render_user_evidence_page(user_evidence_page $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('tool_lp/user_evidence_page', $data);
}
/**
* Defer to template.
*
* @param user_evidence_list_page $page
* @return string
*/
public function render_user_evidence_list_page(user_evidence_list_page $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('tool_lp/user_evidence_list_page', $data);
}
/**
* Defer to template.
*
* @param user_competency_course_navigation $nav
* @return string
*/
public function render_user_competency_course_navigation(user_competency_course_navigation $nav) {
$data = $nav->export_for_template($this);
return parent::render_from_template('tool_lp/user_competency_course_navigation', $data);
}
/**
* Defer to template.
*
* @param competency_plan_navigation $nav
* @return string
*/
public function render_competency_plan_navigation(competency_plan_navigation $nav) {
$data = $nav->export_for_template($this);
return parent::render_from_template('tool_lp/competency_plan_navigation', $data);
}
/**
* Defer to template.
*
* @param user_competency_summary $page
* @return string
*/
public function render_user_competency_summary(user_competency_summary $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('tool_lp/user_competency_summary', $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);
}
/**
* Defer to template.
*
* @param module_navigation $nav
* @return string
*/
public function render_module_navigation(module_navigation $nav) {
$data = $nav->export_for_template($this);
return parent::render_from_template('tool_lp/module_navigation', $data);
}
}
@@ -0,0 +1,58 @@
<?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/>.
/**
* Template cohorts page renderable.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
defined('MOODLE_INTERNAL') || die();
/**
* Template cohorts renderable.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class template_cohorts_page implements \renderable {
/** @var \core_competency\template|null */
protected $template = null;
/** @var \moodle_url|null */
protected $url = null;
/** @var template_cohorts_table|null */
public $table = null;
/**
* Constructor.
* @param \core_competency\template $template
* @param \moodle_url $url
*/
public function __construct(\core_competency\template $template, \moodle_url $url) {
$this->template = $template;
$this->url = $url;
$this->table = new template_cohorts_table('tplcohorts', $template);
$this->table->define_baseurl($url);
}
}
@@ -0,0 +1,185 @@
<?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/>.
/**
* Template cohorts table.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/tablelib.php');
use html_writer;
use moodle_url;
use table_sql;
use core_competency\template;
/**
* Template cohorts table class.
*
* Note that presently this table may display some rows although the current user
* does not have permission to view those cohorts.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class template_cohorts_table extends table_sql {
/** @var context The context. */
protected $context;
/** @var \core_competency\template The template. */
protected $template;
/**
* Sets up the table.
*
* @param string $uniqueid Unique id of table.
* @param \core_competency\template $template The template.
*/
public function __construct($uniqueid, \core_competency\template $template) {
parent::__construct($uniqueid);
// This object should not be used without the right permissions.
if (!$template->can_read()) {
throw new \required_capability_exception($template->get_context(), 'moodle/competency:templateview',
'nopermissions', '');
}
// Set protected properties.
$this->template = $template;
$this->context = $this->template->get_context();
// Define columns in the table.
$this->define_table_columns();
// Define configs.
$this->define_table_configs();
}
/**
* Column actions.
*
* @param object $row
* @return string
*/
protected function col_actions($row) {
global $OUTPUT;
$action = new \confirm_action(get_string('areyousure'));
$url = new moodle_url($this->baseurl);
$url->params(array('removecohort' => $row->id, 'sesskey' => sesskey()));
$actionlink = $OUTPUT->action_link($url, '', $action, null, new \pix_icon('t/delete',
get_string('stopsyncingcohort', 'tool_lp')));
return $actionlink;
}
/**
* Setup the headers for the table.
*/
protected function define_table_columns() {
// Define headers and columns.
$cols = array(
'name' => get_string('name', 'cohort'),
'idnumber' => get_string('idnumber', 'cohort'),
);
if ($this->template->can_manage()) {
$cols['actions'] = get_string('actions');
}
$this->define_columns(array_keys($cols));
$this->define_headers(array_values($cols));
}
/**
* Define table configs.
*/
protected function define_table_configs() {
$this->collapsible(false);
$this->sortable(true, 'name', SORT_ASC);
$this->pageable(true);
$this->no_sorting('actions');
}
/**
* Builds the SQL query.
*
* @param bool $count When true, return the count SQL.
* @return array containing sql to use and an array of params.
*/
protected function get_sql_and_params($count = false) {
$fields = 'c.id, c.name, c.idnumber';
if ($count) {
$select = "COUNT(1)";
} else {
$select = "$fields";
}
$sql = "SELECT $select
FROM {" . \core_competency\template_cohort::TABLE . "} tc
JOIN {cohort} c ON c.id = tc.cohortid
WHERE tc.templateid = :templateid";
$params = array('templateid' => $this->template->get('id'));
// Add order by if needed.
if (!$count && $sqlsort = $this->get_sql_sort()) {
$sql .= " ORDER BY " . $sqlsort;
}
return array($sql, $params);
}
/**
* Override the default implementation to set a notification.
*/
public function print_nothing_to_display() {
global $OUTPUT;
echo $this->render_reset_button();
$this->print_initials_bar();
echo $OUTPUT->notification(get_string('nothingtodisplay'), 'info', false);
}
/**
* Query the DB.
*
* @param int $pagesize size of page for paginated displayed table.
* @param bool $useinitialsbar do you want to use the initials bar.
*/
public function query_db($pagesize, $useinitialsbar = true) {
global $DB;
list($countsql, $countparams) = $this->get_sql_and_params(true);
list($sql, $params) = $this->get_sql_and_params();
$total = $DB->count_records_sql($countsql, $countparams);
$this->pagesize($pagesize, $total);
$this->rawdata = $DB->get_records_sql($sql, $params, $this->get_page_start(), $this->get_page_size());
// Set initial bars.
if ($useinitialsbar) {
$this->initialbars($total > $pagesize);
}
}
}
@@ -0,0 +1,133 @@
<?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 tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
defined('MOODLE_INTERNAL') || die();
use renderable;
use templatable;
use renderer_base;
use stdClass;
use context;
use context_system;
use moodle_url;
use core_competency\external\template_exporter;
use core_competency\template;
use core_competency\api;
use core_competency\external\performance_helper;
use tool_lp\external\competency_summary_exporter;
use tool_lp\external\template_statistics_exporter;
use tool_lp\template_statistics;
/**
* 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 template_competencies_page implements renderable, templatable {
/** @var template $template Template for this page. */
protected $template = null;
/** @var \core_competency\competency[] $competencies List of competencies. */
protected $competencies = array();
/** @var bool $canmanagecompetencyframeworks Can the current user manage competency frameworks. */
protected $canmanagecompetencyframeworks = false;
/** @var bool $canmanagecoursecompetencies Can the current user manage course competency frameworks.. */
protected $canmanagecoursecompetencies = false;
/** @var string $manageurl manage url. */
protected $manageurl = null;
/** @var context $pagecontext The page context. */
protected $pagecontext = null;
/** @var template_statistics $templatestatistics The generated summary statistics for this template. */
protected $templatestatistics = null;
/** @var bool true if the user has this capability. Otherwise false. */
protected bool $canmanagetemplatecompetencies = false;
/**
* Construct this renderable.
*
* @param template $template The learning plan template.
* @param context $pagecontext The page context.
*/
public function __construct(template $template, context $pagecontext) {
$this->pagecontext = $pagecontext;
$this->template = $template;
$this->templatestatistics = new template_statistics($template->get('id'));
$this->competencies = api::list_competencies_in_template($template);
$this->canmanagecompetencyframeworks = has_capability('moodle/competency:competencymanage', $this->pagecontext);
$this->canmanagetemplatecompetencies = has_capability('moodle/competency:templatemanage', $this->pagecontext);
$this->manageurl = new moodle_url('/admin/tool/lp/competencyframeworks.php',
array('pagecontextid' => $this->pagecontext->id));
}
/**
* 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) {
$data = new stdClass();
$data->template = (new template_exporter($this->template))->export($output);
$data->pagecontextid = $this->pagecontext->id;
$data->competencies = array();
$helper = new performance_helper();
foreach ($this->competencies as $competency) {
$context = $helper->get_context_from_competency($competency);
$framework = $helper->get_framework_from_competency($competency);
$courses = api::list_courses_using_competency($competency->get('id'));
$relatedcompetencies = api::list_related_competencies($competency->get('id'));
$related = array(
'competency' => $competency,
'linkedcourses' => $courses,
'context' => $context,
'relatedcompetencies' => $relatedcompetencies,
'framework' => $framework
);
$exporter = new competency_summary_exporter(null, $related);
$record = $exporter->export($output);
array_push($data->competencies, $record);
}
$data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(false);
$data->canmanagecompetencyframeworks = $this->canmanagecompetencyframeworks;
$data->canmanagetemplatecompetencies = $this->canmanagetemplatecompetencies;
$data->manageurl = $this->manageurl->out(true);
$exporter = new template_statistics_exporter($this->templatestatistics);
$data->statistics = $exporter->export($output);
$data->showcompetencylinks = true;
return $data;
}
}
@@ -0,0 +1,58 @@
<?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/>.
/**
* Template plans renderable.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
defined('MOODLE_INTERNAL') || die();
/**
* Template plans renderable.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class template_plans_page implements \renderable {
/** @var \core_competency\template|null */
protected $template = null;
/** @var \moodle_url|null */
protected $url = null;
/** @var template_plans_table|null */
public $table = null;
/**
* Constructor.
* @param \core_competency\template $template
* @param \moodle_url $url
*/
public function __construct(\core_competency\template $template, \moodle_url $url) {
$this->template = $template;
$this->url = $url;
$this->table = new template_plans_table('tplplans', $template);
$this->table->define_baseurl($url);
}
}
@@ -0,0 +1,193 @@
<?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/>.
/**
* Template plans table.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/tablelib.php');
use html_writer;
use moodle_url;
use table_sql;
use core_competency\template;
/**
* Template plans table class.
*
* Note that presently this table may display some rows although the current user
* does not have permission to view those plans.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class template_plans_table extends table_sql {
/** @var context The context. */
protected $context;
/** @var \core_competency\template The template. */
protected $template;
/**
* Sets up the table.
*
* @param string $uniqueid Unique id of table.
* @param \core_competency\template $template The template.
*/
public function __construct($uniqueid, \core_competency\template $template) {
parent::__construct($uniqueid);
// This object should not be used without the right permissions.
if (!$template->can_read()) {
throw new \required_capability_exception($template->get_context(), 'moodle/competency:templateview',
'nopermissions', '');
}
// Set protected properties.
$this->template = $template;
$this->context = $this->template->get_context();
$this->useridfield = 'userid';
// Define columns in the table.
$this->define_table_columns();
// Define configs.
$this->define_table_configs();
}
/**
* Format column name.
*
* @param stdClass $row
* @return string
*/
protected function col_name($row) {
return html_writer::link(new moodle_url('/admin/tool/lp/plan.php', array('id' => $row->id)),
format_string($row->name, true, array('context' => $this->context)));
}
/**
* Setup the headers for the table.
*/
protected function define_table_columns() {
// TODO Does not support custom user profile fields (MDL-70456).
$extrafields = \core_user\fields::get_identity_fields($this->context, false);
// Define headers and columns.
$cols = array(
'name' => get_string('planname', 'tool_lp'),
'fullname' => get_string('name')
);
// Add headers for extra user fields.
foreach ($extrafields as $field) {
if (get_string_manager()->string_exists($field, 'moodle')) {
$cols[$field] = get_string($field);
} else {
$cols[$field] = $field;
}
}
// Add remaining headers.
$cols = array_merge($cols, array());
$this->define_columns(array_keys($cols));
$this->define_headers(array_values($cols));
}
/**
* Define table configs.
*/
protected function define_table_configs() {
$this->collapsible(false);
$this->sortable(true, 'lastname', SORT_ASC);
$this->pageable(true);
}
/**
* Builds the SQL query.
*
* @param bool $count When true, return the count SQL.
* @return array containing sql to use and an array of params.
*/
protected function get_sql_and_params($count = false) {
$fields = 'p.id, p.userid, p.name';
// Add extra user fields that we need for the graded user.
// TODO Does not support custom user profile fields (MDL-70456).
$userfieldsapi = \core_user\fields::for_identity($this->context, false)->with_name();
$fields .= $userfieldsapi->get_sql('u')->selects;
if ($count) {
$select = "COUNT(1)";
} else {
$select = "$fields";
}
$sql = "SELECT $select
FROM {" . \core_competency\plan::TABLE . "} p
JOIN {user} u ON u.id = p.userid
WHERE p.templateid = :templateid";
$params = array('templateid' => $this->template->get('id'));
// Add order by if needed.
if (!$count && $sqlsort = $this->get_sql_sort()) {
$sql .= " ORDER BY " . $sqlsort;
}
return array($sql, $params);
}
/**
* Override the default implementation to set a notification.
*/
public function print_nothing_to_display() {
global $OUTPUT;
echo $this->render_reset_button();
$this->print_initials_bar();
echo $OUTPUT->notification(get_string('nothingtodisplay'), 'info', false);
}
/**
* Query the DB.
*
* @param int $pagesize size of page for paginated displayed table.
* @param bool $useinitialsbar do you want to use the initials bar.
*/
public function query_db($pagesize, $useinitialsbar = true) {
global $DB;
list($countsql, $countparams) = $this->get_sql_and_params(true);
list($sql, $params) = $this->get_sql_and_params();
$total = $DB->count_records_sql($countsql, $countparams);
$this->pagesize($pagesize, $total);
$this->rawdata = $DB->get_records_sql($sql, $params, $this->get_page_start(), $this->get_page_size());
// Set initial bars.
if ($useinitialsbar) {
$this->initialbars($total > $pagesize);
}
}
}
@@ -0,0 +1,135 @@
<?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 competency page class.
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
use renderable;
use renderer_base;
use templatable;
use context_course;
use core_competency\external\competency_exporter;
use core_user\external\user_summary_exporter;
use core_competency\external\performance_helper;
use stdClass;
/**
* User competency course navigation class.
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_competency_course_navigation implements renderable, templatable {
/** @var userid */
protected $userid;
/** @var competencyid */
protected $competencyid;
/** @var courseid */
protected $courseid;
/** @var baseurl */
protected $baseurl;
/**
* Construct.
*
* @param int $userid
* @param int $competencyid
* @param int $courseid
* @param string $baseurl
*/
public function __construct($userid, $competencyid, $courseid, $baseurl) {
$this->userid = $userid;
$this->competencyid = $competencyid;
$this->courseid = $courseid;
$this->baseurl = $baseurl;
}
/**
* Export the data.
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
global $CFG, $DB, $PAGE;
$context = context_course::instance($this->courseid);
$data = new stdClass();
$data->userid = $this->userid;
$data->competencyid = $this->competencyid;
$data->courseid = $this->courseid;
$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);
$users = get_enrolled_users($context, 'moodle/competency:coursecompetencygradable', $currentgroup,
'u.*', null, 0, 0, $showonlyactiveenrol);
$data->users = array();
foreach ($users as $user) {
$exporter = new user_summary_exporter($user);
$user = $exporter->export($output);
if ($user->id == $this->userid) {
$user->selected = true;
}
$data->users[] = $user;
}
$data->hasusers = true;
} else {
$data->users = array();
$data->hasusers = false;
}
$coursecompetencies = \core_competency\api::list_course_competencies($this->courseid);
$data->competencies = array();
$helper = new performance_helper();
foreach ($coursecompetencies as $coursecompetency) {
$coursecompetencycontext = $helper->get_context_from_competency($coursecompetency['competency']);
$exporter = new competency_exporter($coursecompetency['competency'], array('context' => $coursecompetencycontext));
$competency = $exporter->export($output);
if ($competency->id == $this->competencyid) {
$competency->selected = true;
}
$data->competencies[] = $competency;
}
$data->hascompetencies = count($data->competencies);
return $data;
}
}
@@ -0,0 +1,86 @@
<?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 competency summary.
*
* @package tool_lp
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
defined('MOODLE_INTERNAL') || die();
use core_user;
use renderer_base;
use renderable;
use templatable;
use core_competency\api;
use core_competency\user_competency;
use tool_lp\external\user_competency_summary_exporter;
/**
* User competency summary class.
*
* @package tool_lp
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_competency_summary implements renderable, templatable {
/** @var usercompetency */
protected $usercompetency;
/** @var array */
protected $related;
/**
* Constructor.
*
* @param user_competency $usercompetency The user competency.
* @param array $related Related objects.
*/
public function __construct(user_competency $usercompetency, array $related = array()) {
$this->usercompetency = $usercompetency;
$this->related = $related;
}
/**
* Export the data.
*
* @param renderer_base $output
* @return \stdClass
*/
public function export_for_template(renderer_base $output) {
if (!isset($related['user'])) {
$related['user'] = core_user::get_user($this->usercompetency->get('userid'));
}
if (!isset($related['competency'])) {
$related['competency'] = $this->usercompetency->get_competency();
}
$related += array(
'usercompetency' => $this->usercompetency,
'usercompetencyplan' => null,
'usercompetencycourse' => null,
'evidence' => api::list_evidence($this->usercompetency->get('userid'), $this->usercompetency->get('competencyid')),
'relatedcompetencies' => api::list_related_competencies($this->usercompetency->get('competencyid'))
);
$exporter = new user_competency_summary_exporter(null, $related);
$data = $exporter->export($output);
return $data;
}
}
@@ -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/>.
/**
* User competency page class.
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
use renderable;
use renderer_base;
use templatable;
use core_competency\api;
use core_competency\user_competency;
use tool_lp\external\user_competency_summary_in_course_exporter;
/**
* User competency page class.
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_competency_summary_in_course implements renderable, templatable {
/** @var userid */
protected $userid;
/** @var competencyid */
protected $competencyid;
/** @var courseid */
protected $courseid;
/**
* Construct.
*
* @param int $userid
* @param int $competencyid
* @param int $courseid
*/
public function __construct($userid, $competencyid, $courseid) {
$this->userid = $userid;
$this->competencyid = $competencyid;
$this->courseid = $courseid;
}
/**
* Export the data.
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
global $DB;
$usercompetencycourse = api::get_user_competency_in_course($this->courseid, $this->userid, $this->competencyid);
$competency = $usercompetencycourse->get_competency();
if (empty($usercompetencycourse) || empty($competency)) {
throw new \invalid_parameter_exception('Invalid params. The competency does not belong to the course.');
}
$relatedcompetencies = api::list_related_competencies($competency->get('id'));
$user = $DB->get_record('user', array('id' => $this->userid));
$evidence = api::list_evidence_in_course($this->userid, $this->courseid, $this->competencyid);
$course = $DB->get_record('course', array('id' => $this->courseid));
$params = array(
'competency' => $competency,
'usercompetencycourse' => $usercompetencycourse,
'evidence' => $evidence,
'user' => $user,
'course' => $course,
'scale' => $competency->get_scale(),
'relatedcompetencies' => $relatedcompetencies
);
$exporter = new user_competency_summary_in_course_exporter(null, $params);
$data = $exporter->export($output);
return $data;
}
}
@@ -0,0 +1,96 @@
<?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 competency page class.
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
defined('MOODLE_INTERNAL') || die();
use renderable;
use templatable;
use core_competency\api;
use tool_lp\external\user_competency_summary_in_plan_exporter;
/**
* User competency page class.
*
* @package tool_lp
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_competency_summary_in_plan implements renderable, templatable {
/** @var int competencyid */
protected $competencyid;
/** @var int planid */
protected $planid;
/**
* Construct.
*
* @param int $competencyid
* @param int $planid
*/
public function __construct($competencyid, $planid) {
$this->competencyid = $competencyid;
$this->planid = $planid;
}
/**
* Export the data.
*
* @param \renderer_base $output
* @return \stdClass
*/
public function export_for_template(\renderer_base $output) {
global $DB;
$plan = api::read_plan($this->planid);
$pc = api::get_plan_competency($plan, $this->competencyid);
$competency = $pc->competency;
$usercompetency = $pc->usercompetency;
$usercompetencyplan = $pc->usercompetencyplan;
if (empty($competency)) {
throw new \invalid_parameter_exception('Invalid params. The competency does not belong to the plan.');
}
$relatedcompetencies = api::list_related_competencies($competency->get('id'));
$userid = $plan->get('userid');
$user = $DB->get_record('user', array('id' => $userid));
$evidence = api::list_evidence($userid, $this->competencyid, $plan->get('id'));
$params = array(
'competency' => $competency,
'usercompetency' => $usercompetency,
'usercompetencyplan' => $usercompetencyplan,
'evidence' => $evidence,
'user' => $user,
'plan' => $plan,
'relatedcompetencies' => $relatedcompetencies
);
$exporter = new user_competency_summary_in_plan_exporter(null, $params);
$data = $exporter->export($output);
return $data;
}
}
@@ -0,0 +1,110 @@
<?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/>.
/**
* Page listing the evidence of prior learning of a user.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
use renderable;
use templatable;
use renderer_base;
use stdClass;
use single_button;
use moodle_url;
use core_competency\api;
use tool_lp\external\user_evidence_summary_exporter;
use core_competency\user_evidence;
use context_user;
/**
* Class for the page listing the evidence of prior learning of a user.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_evidence_list_page implements renderable, templatable {
/** @var array $navigation List of links to display on the page. Each link contains a url and a title. */
protected $navigation = array();
/** @var tool_lp\user_evidence[] $evidence List of user evidence. */
protected $evidence = array();
/** @var context_user|null $context context. */
protected $context = null;
/** @var int|null $userid Userid. */
protected $userid = null;
/** @var bool Can the user manage the evidence. */
protected $canmanage;
/**
* Construct this renderable.
*
* @param int $userid
*/
public function __construct($userid) {
$this->userid = $userid;
$this->context = context_user::instance($userid);
$this->evidence = api::list_user_evidence($userid);
$this->canmanage = user_evidence::can_manage_user($this->userid);
if ($this->canmanage) {
$addevidence = new single_button(
new moodle_url('/admin/tool/lp/user_evidence_edit.php', array('userid' => $userid)),
get_string('addnewuserevidence', 'tool_lp'), 'get'
);
$this->navigation[] = $addevidence;
}
}
/**
* 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) {
$data = new stdClass();
$data->userid = $this->userid;
$data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
$data->canmanage = $this->canmanage;
$data->evidence = array();
if ($this->evidence) {
foreach ($this->evidence as $evidence) {
$userevidencesummaryexporter = new user_evidence_summary_exporter($evidence, array(
'context' => $this->context
));
$data->evidence[] = $userevidencesummaryexporter->export($output);
}
}
$data->navigation = array();
foreach ($this->navigation as $button) {
$data->navigation[] = $output->render($button);
}
return $data;
}
}
@@ -0,0 +1,74 @@
<?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 evidence page output.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\output;
use moodle_url;
use renderable;
use templatable;
use stdClass;
use core_competency\api;
use tool_lp\external\user_evidence_summary_exporter;
/**
* User evidence page class.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class user_evidence_page implements renderable, templatable {
/** @var context The context. */
protected $context;
/** @var userevidence The user evidence. */
protected $userevidence;
/**
* Construct.
*
* @param user_evidence $userevidence
*/
public function __construct($userevidence) {
$this->userevidence = $userevidence;
$this->context = $this->userevidence->get_context();
}
/**
* Export the data.
*
* @param renderer_base $output
* @return stdClass
*/
public function export_for_template(\renderer_base $output) {
$data = new stdClass();
$userevidencesummaryexporter = new user_evidence_summary_exporter($this->userevidence, array(
'context' => $this->context));
$data->userevidence = $userevidencesummaryexporter->export($output);
$data->pluginbaseurl = (new moodle_url('/admin/tool/lp'))->out(true);
return $data;
}
}
+476
View File
@@ -0,0 +1,476 @@
<?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/>.
/**
* Page helper.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp;
defined('MOODLE_INTERNAL') || die();
use coding_exception;
use context;
use moodle_exception;
use moodle_url;
use core_user;
use context_user;
use context_course;
use stdClass;
/**
* Page helper.
*
* @package tool_lp
* @copyright 2015 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class page_helper {
/**
* Set-up a course page.
*
* Example:
* list($title, $subtitle) = page_helper::setup_for_course($pagecontextid, $url, $course, $pagetitle);
* echo $OUTPUT->heading($title);
* echo $OUTPUT->heading($subtitle, 3);
*
* @param moodle_url $url The current page.
* @param stdClass $course The course.
* @param string $subtitle The title of the subpage, if any.
* @return array With the following:
* - Page title
* - Page sub title
* - Return URL (course competencies page)
*/
public static function setup_for_course(moodle_url $url, $course, $subtitle = '') {
global $PAGE;
$context = context_course::instance($course->id);
$PAGE->set_course($course);
if (!empty($subtitle)) {
$title = $subtitle;
} else {
$title = get_string('coursecompetencies', 'tool_lp');
}
$returnurl = new moodle_url('/admin/tool/lp/coursecompetencies.php', array('courseid' => $course->id));
$heading = $context->get_context_name();
$PAGE->set_pagelayout('incourse');
$PAGE->set_url($url);
$PAGE->set_title($title);
$PAGE->set_heading($heading);
if (!empty($subtitle)) {
$PAGE->navbar->add(get_string('coursecompetencies', 'tool_lp'), $returnurl);
// We're in a sub page without a specific template.
$PAGE->navbar->add($subtitle, $url);
}
return array($title, $subtitle, $returnurl);
}
/**
* Set-up a template page.
*
* Example:
* list($title, $subtitle) = page_helper::setup_for_template($pagecontextid, $url, $template, $pagetitle);
* echo $OUTPUT->heading($title);
* echo $OUTPUT->heading($subtitle, 3);
*
* @param int $pagecontextid The page context ID.
* @param moodle_url $url The current page.
* @param \core_competency\template $template The template, if any.
* @param string $subtitle The title of the subpage, if any.
* @param string $returntype The desired return page.
* @return array With the following:
* - Page title
* - Page sub title
* - Return URL
*/
public static function setup_for_template($pagecontextid, moodle_url $url, $template = null, $subtitle = '',
$returntype = null) {
global $PAGE, $SITE;
$pagecontext = context::instance_by_id($pagecontextid);
$context = $pagecontext;
if (!empty($template)) {
$context = $template->get_context();
}
$templatesurl = new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => $pagecontextid));
$templateurl = null;
if ($template) {
$templateurl = new moodle_url('/admin/tool/lp/templatecompetencies.php', [
'templateid' => $template->get('id'),
'pagecontextid' => $pagecontextid
]);
}
$returnurl = $templatesurl;
if ($returntype != 'templates' && $templateurl) {
$returnurl = $templateurl;
}
$PAGE->navigation->override_active_url($templatesurl);
$PAGE->set_context($pagecontext);
$PAGE->set_url($url);
if (!empty($template)) {
$title = format_string($template->get('shortname'), true, array('context' => $context));
} else {
$title = get_string('templates', 'tool_lp');
}
if ($pagecontext->contextlevel == CONTEXT_SYSTEM) {
$PAGE->set_heading($SITE->fullname);
} else if ($pagecontext->contextlevel == CONTEXT_COURSECAT) {
\core_course_category::page_setup();
// Set the learning plan templates node active in the settings navigation block.
if ($learningplannode = $PAGE->settingsnav->find('learningplantemplates', \navigation_node::TYPE_SETTING)) {
$learningplannode->make_active();
}
} else {
throw new coding_exception('Unexpected context!');
}
$PAGE->set_pagelayout('admin');
$PAGE->set_title($title);
if (!empty($template)) {
$PAGE->navbar->add($title, $templateurl);
if (!empty($subtitle)) {
$PAGE->navbar->add($subtitle, $url);
}
} else if (!empty($subtitle)) {
// We're in a sub page without a specific template.
$PAGE->navbar->add($subtitle, $url);
}
return array($title, $subtitle, $returnurl);
}
/**
* Set-up a plan page.
*
* Example:
* list($title, $subtitle) = page_helper::setup_for_plan($url, $template, $pagetitle);
* echo $OUTPUT->heading($title);
* echo $OUTPUT->heading($subtitle, 3);
*
* @param int $userid The user ID.
* @param moodle_url $url The current page.
* @param \core_competency\plan $plan The plan, if any.
* @param string $subtitle The title of the subpage, if any.
* @param string $returntype The desired return page.
* @return array With the following:
* - Page title
* - Page sub title
* - Return URL (main plan page)
*/
public static function setup_for_plan($userid, moodle_url $url, $plan = null, $subtitle = '', $returntype = null) {
global $PAGE, $USER;
// Check that the user is a valid user.
$user = core_user::get_user($userid);
if (!$user || !core_user::is_real_user($userid)) {
throw new \moodle_exception('invaliduser', 'error');
}
$context = context_user::instance($user->id);
$plansurl = new moodle_url('/admin/tool/lp/plans.php', array('userid' => $userid));
$planurl = null;
if ($plan) {
$planurl = new moodle_url('/admin/tool/lp/plan.php', array('id' => $plan->get('id')));
}
$returnurl = $plansurl;
if ($returntype != 'plans' && $planurl) {
$returnurl = $planurl;
}
$PAGE->navigation->override_active_url($plansurl);
$PAGE->set_context($context);
// If not his own plan, we want to extend the navigation for the user.
$iscurrentuser = ($USER->id == $user->id);
if (!$iscurrentuser) {
$PAGE->navigation->extend_for_user($user);
$PAGE->navigation->set_userid_for_parent_checks($user->id);
}
if (!empty($plan)) {
$title = format_string($plan->get('name'), true, array('context' => $context));
} else {
$title = get_string('learningplans', 'tool_lp');
}
$PAGE->set_pagelayout('standard');
$PAGE->set_url($url);
$PAGE->set_title($title);
if (!empty($plan)) {
$PAGE->navbar->add($title, $planurl);
if (!empty($subtitle)) {
$PAGE->navbar->add($subtitle, $url);
}
} else if (!empty($subtitle)) {
// We're in a sub page without a specific plan.
$PAGE->navbar->add($subtitle, $url);
}
return array($title, $subtitle, $returnurl);
}
/**
* Set-up a user evidence page.
*
* Example:
* list($title, $subtitle) = page_helper::setup_for_user_evidence($url, $template, $pagetitle);
* echo $OUTPUT->heading($title);
* echo $OUTPUT->heading($subtitle, 3);
*
* @param int $userid The user ID.
* @param moodle_url $url The current page.
* @param \core_competency\user_evidence $evidence The user evidence, if any.
* @param string $subtitle The title of the subpage, if any.
* @param string $returntype The desired return page.
* @return array With the following:
* - Page title
* - Page sub title
* - Return URL (main plan page)
*/
public static function setup_for_user_evidence($userid, moodle_url $url, $evidence = null, $subtitle = '', $returntype = null) {
global $PAGE, $USER;
// Check that the user is a valid user.
$user = core_user::get_user($userid);
if (!$user || !core_user::is_real_user($userid)) {
throw new \moodle_exception('invaliduser', 'error');
}
$context = context_user::instance($user->id);
$evidencelisturl = new moodle_url('/admin/tool/lp/user_evidence_list.php', array('userid' => $userid));
$evidenceurl = null;
if ($evidence) {
$evidenceurl = new moodle_url('/admin/tool/lp/user_evidence.php', array('id' => $evidence->get('id')));
}
$returnurl = $evidencelisturl;
if ($returntype != 'list' && $evidenceurl) {
$returnurl = $evidenceurl;
}
$PAGE->navigation->override_active_url($evidencelisturl);
$PAGE->set_context($context);
// If not his own evidence, we want to extend the navigation for the user.
$iscurrentuser = ($USER->id == $user->id);
if (!$iscurrentuser) {
$PAGE->navigation->extend_for_user($user);
$PAGE->navigation->set_userid_for_parent_checks($user->id);
}
if (!empty($evidence)) {
$title = format_string($evidence->get('name'), true, array('context' => $context));
} else {
$title = get_string('userevidence', 'tool_lp');
}
$PAGE->set_pagelayout('standard');
$PAGE->set_url($url);
$PAGE->set_title($title);
if (!empty($evidence)) {
$PAGE->navbar->add($title, $evidenceurl);
if (!empty($subtitle)) {
$PAGE->navbar->add($subtitle, $url);
}
} else if (!empty($subtitle)) {
// We're in a sub page without a specific evidence.
$PAGE->navbar->add($subtitle, $url);
}
return array($title, $subtitle, $returnurl);
}
/**
* Set-up a framework page.
*
* Example:
* list($pagetitle, $pagesubtitle, $url, $frameworksurl) = page_helper::setup_for_framework($id, $pagecontextid);
* echo $OUTPUT->heading($pagetitle);
* echo $OUTPUT->heading($pagesubtitle, 3);
*
* @param int $id The framework ID.
* @param int $pagecontextid The page context ID.
* @param \core_competency\competency_framework $framework The framework.
* @param string $returntype The desired return page.
* @return array With the following:
* - Page title
* - Page sub title
* - Page URL
* - Page framework URL
*/
public static function setup_for_framework($id, $pagecontextid, $framework = null, $returntype = null) {
global $PAGE, $SITE;
// We keep the original context in the URLs, so that we remain in the same context.
$url = new moodle_url("/admin/tool/lp/editcompetencyframework.php", array('id' => $id, 'pagecontextid' => $pagecontextid));
if ($returntype) {
$url->param('return', $returntype);
}
$frameworksurl = new moodle_url('/admin/tool/lp/competencyframeworks.php', array('pagecontextid' => $pagecontextid));
$context = context::instance_by_id($pagecontextid);
$PAGE->set_context($context);
$PAGE->set_pagelayout('admin');
$PAGE->set_url($url);
$title = get_string('competencies', 'core_competency');
if ($context->contextlevel == CONTEXT_COURSECAT) {
\core_course_category::page_setup();
// Set the competency frameworks node active in the settings navigation block.
if ($competencyframeworksnode = $PAGE->settingsnav->find('competencyframeworks', \navigation_node::TYPE_SETTING)) {
$competencyframeworksnode->make_active();
}
} else if ($context->contextlevel == CONTEXT_SYSTEM) {
$PAGE->set_heading($SITE->fullname);
} else {
$PAGE->set_heading($title);
}
$PAGE->navigation->override_active_url($frameworksurl);
if (empty($id)) {
$pagetitle = get_string('competencyframeworks', 'tool_lp');
$pagesubtitle = get_string('addnewcompetencyframework', 'tool_lp');
$url->remove_params(array('id'));
$PAGE->navbar->add($pagesubtitle, $url);
} else {
$pagetitle = $framework->get('shortname');
$pagesubtitle = get_string('editcompetencyframework', 'tool_lp');
if ($returntype == 'competencies') {
$frameworksurl = new moodle_url('/admin/tool/lp/competencies.php', array(
'pagecontextid' => $pagecontextid,
'competencyframeworkid' => $id
));
} else {
$frameworksurl->param('competencyframeworkid', $id);
}
$PAGE->navbar->add($pagetitle, $frameworksurl);
$PAGE->navbar->add($pagesubtitle, $url);
}
$PAGE->set_title($title);
return array($pagetitle, $pagesubtitle, $url, $frameworksurl);
}
/**
* Set-up a competency page.
*
* Example:
* list($title, $subtitle) = page_helper::setup_for_competency($pagecontextid, $url, $competency, $pagetitle);
* echo $OUTPUT->heading($title);
* echo $OUTPUT->heading($subtitle, 3);
*
* @param int $pagecontextid The page context ID.
* @param moodle_url $url The current page.
* @param \core_competency\competency_framework $framework The competency framework.
* @param \core_competency\competency $competency The competency, if any.
* @param \core_competency\competency $parent The parent competency, if any.
* @return array With the following:
* - Page title
* - Page sub title
* - Return URL (main competencies page)
* @throws coding_exception
*/
public static function setup_for_competency($pagecontextid, moodle_url $url, $framework, $competency = null, $parent = null) {
global $PAGE, $SITE;
// Set page context.
$pagecontext = context::instance_by_id($pagecontextid);
$PAGE->set_context($pagecontext);
// Set page heading.
if ($pagecontext->contextlevel == CONTEXT_SYSTEM) {
$heading = $SITE->fullname;
} else if ($pagecontext->contextlevel == CONTEXT_COURSECAT) {
$heading = $pagecontext->get_context_name();
} else {
throw new coding_exception('Unexpected context!');
}
$PAGE->set_heading($heading);
// Set override active url.
$frameworksurl = new moodle_url('/admin/tool/lp/competencyframeworks.php', ['pagecontextid' => $pagecontextid]);
$PAGE->navigation->override_active_url($frameworksurl);
// Set return url.
$returnurloptions = [
'competencyframeworkid' => $framework->get('id'),
'pagecontextid' => $pagecontextid
];
$returnurl = new moodle_url('/admin/tool/lp/competencies.php', $returnurloptions);
$PAGE->navbar->add($framework->get('shortname'), $returnurl);
// Set page layout.
$PAGE->set_pagelayout('admin');
if (empty($competency)) {
// Add mode.
$title = format_string($framework->get('shortname'), true, ['context' => $pagecontext]);
// Set the sub-title for add mode.
$level = $parent ? $parent->get_level() + 1 : 1;
$subtitle = get_string('taxonomy_add_' . $framework->get_taxonomy($level), 'tool_lp');
} else {
// Edit mode.
$title = format_string($competency->get('shortname'), true, ['context' => $competency->get_context()]);
// Add competency name to breadcrumbs, if available.
$PAGE->navbar->add($title);
// Set the sub-title for edit mode.
$subtitle = get_string('taxonomy_edit_' . $framework->get_taxonomy($competency->get_level()), 'tool_lp');
}
// Set page title.
$PAGE->set_title($title);
// Set page url.
$PAGE->set_url($url);
// Add editing mode link to breadcrumbs, if available.
if (!empty($subtitle)) {
$PAGE->navbar->add($subtitle, $url);
}
return [$title, $subtitle, $returnurl];
}
}
@@ -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 tool_lp.
*
* @package tool_lp
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for tool_lp 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';
}
}
@@ -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/>.
/**
* Site competencies element.
*
* @package tool_lp
* @copyright 2019 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/form/hidden.php');
/**
* Site competencies element.
*
* @package tool_lp
* @copyright 2019 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class tool_lp_site_competencies_form_element extends MoodleQuickForm_hidden {
/**
* Constructor
*
* @param string $elementname Element name.
* @param string $value The element value.
* @param mixed $attributes Either a typical HTML attribute string or an associative array.
*/
public function __construct($elementname=null, $value='', $attributes=null) {
if ($elementname == null) {
// This is broken quickforms messing with the constructors.
return;
}
$attributes = array_merge(['data-action' => 'competencies'], $attributes ? $attributes : []);
parent::__construct($elementname, $value, $attributes);
$this->setType('hidden');
}
/**
* Generate the hidden field and the controls to show and pick the competencies.
*/
public function toHtml() {
global $PAGE;
$html = parent::toHTML();
if (!$this->isFrozen()) {
$context = context_system::instance();
$params = [$context->id];
// Require some JS to select the competencies.
$PAGE->requires->js_call_amd('tool_lp/form_competency_element', 'init', $params);
$html .= '<div class="mb-3 row">';
$html .= '<div class="col-md-3"></div>';
$html .= '<div class="col-md-9">';
$html .= '<div data-region="competencies"></div>';
$html .= '<div class="mt-3">';
$html .= '<a class="btn btn-secondary" role="button" data-action="select-competencies">';
$html .= get_string('addcompetency', 'tool_lp');
$html .= '</a>';
$html .= '</div>';
$html .= '</div>';
$html .= '</div>';
}
return $html;
}
/**
* Accepts a renderer
*
* @param HTML_QuickForm_Renderer $renderer the renderer for the element.
* @param boolean $required not used.
* @param string $error not used.
* @return void
*/
public function accept(&$renderer, $required=false, $error=null) {
$renderer->renderElement($this, false, '');
}
}
@@ -0,0 +1,80 @@
<?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/>.
/**
* Template statistics class
*
* @package tool_lp
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp;
defined('MOODLE_INTERNAL') || die();
use core_competency\api;
use core_competency\plan;
use core_competency\template;
/**
* Template statistics class.
*
* @package tool_lp
* @copyright 2016 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class template_statistics {
/** @var $competencycount The number of competencies in the template */
public $competencycount = 0;
/** @var $unlinkedcompetencycount The number of unlinked competencies in the template */
public $unlinkedcompetencycount = 0;
/** @var $plancount The number of plans for the template */
public $plancount = 0;
/** @var $completedplancount The number of completed plans for the template */
public $completedplancount = 0;
/** @var $usercompetencyplancount The number of competencies in completed plans for the template */
public $usercompetencyplancount = 0;
/** @var $proficientusercompetencyplancount The number of proficient competencies in completed plans for the template */
public $proficientusercompetencyplancount = 0;
/** @var $leastproficientcompetencies The competencies in this template that were proficient the least times */
public $leastproficientcompetencies = array();
/**
* Return the custom definition of the properties of this model.
*
* @param int $templateid The template we want to generate statistics for.
*/
public function __construct($templateid) {
$template = new template($templateid);
$this->competencycount = api::count_competencies_in_template($template);
$this->unlinkedcompetencycount = api::count_competencies_in_template_with_no_courses($template);
$this->plancount = api::count_plans_for_template($template, 0);
$this->completedplancount = api::count_plans_for_template($template, plan::STATUS_COMPLETE);
$this->usercompetencyplancount = api::count_user_competency_plans_for_template($template);
$this->proficientusercompetencyplancount = api::count_user_competency_plans_for_template($template, true);
$this->leastproficientcompetencies = api::get_least_proficient_competencies_for_template($template, 0, 3);
}
}
+173
View File
@@ -0,0 +1,173 @@
<?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/>.
/**
* URL resolver.
*
* @package tool_lp
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_lp;
defined('MOODLE_INTERNAL') || die();
use moodle_url;
/**
* URL resolver class.
*
* @package tool_lp
* @copyright 2016 Frédéric Massart - FMCorz.net
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class url_resolver {
/**
* The URL where the competency can be found.
*
* @param int $competencyid The competency ID.
* @param int $pagecontextid The ID of the context we are in.
* @return moodle_url
*/
public function competency($competencyid, $pagecontextid) {
return new moodle_url('/admin/tool/lp/editcompetency.php', array(
'id' => $competencyid,
'pagecontextid' => $pagecontextid
));
}
/**
* The URL where the framework can be found.
*
* @param int $frameworkid The framework ID.
* @param int $pagecontextid The ID of the context we are in.
* @return moodle_url
*/
public function framework($frameworkid, $pagecontextid) {
return new moodle_url('/admin/tool/lp/competencies.php', array(
'competencyframeworkid' => $frameworkid,
'pagecontextid' => $pagecontextid
));
}
/**
* The URL where the frameworks can be found.
*
* @param int $pagecontextid The ID of the context that we are browsing.
* @return moodle_url
*/
public function frameworks($pagecontextid) {
return new moodle_url('/admin/tool/lp/competencyframeworks.php', array('pagecontextid' => $pagecontextid));
}
/**
* The URL where the plan can be found.
*
* @param int $planid The plan ID.
* @return moodle_url
*/
public function plan($planid) {
return new moodle_url('/admin/tool/lp/plan.php', array('id' => $planid));
}
/**
* The URL where the plans of a user can be found.
*
* @param int $userid The user ID.
* @return moodle_url
*/
public function plans($userid) {
return new moodle_url('/admin/tool/lp/plans.php', array('userid' => $userid));
}
/**
* The URL where the template can be found.
*
* @param int $templateid The template ID.
* @param int $pagecontextid The ID of the context we are in.
* @return moodle_url
*/
public function template($templateid, $pagecontextid) {
return new moodle_url('/admin/tool/lp/templatecompetencies.php', array(
'templateid' => $templateid,
'pagecontextid' => $pagecontextid
));
}
/**
* The URL where the templates can be found.
*
* @param int $pagecontextid The ID of the context that we are browsing.
* @return moodle_url
*/
public function templates($pagecontextid) {
return new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => $pagecontextid));
}
/**
* The URL where the user competency can be found.
*
* @param int $usercompetencyid The user competency ID
* @return moodle_url
*/
public function user_competency($usercompetencyid) {
return new moodle_url('/admin/tool/lp/user_competency.php', array('id' => $usercompetencyid));
}
/**
* The URL where the user competency can be found in the context of a course.
*
* @param int $userid The user ID
* @param int $competencyid The competency ID.
* @param int $courseid The course ID.
* @return moodle_url
*/
public function user_competency_in_course($userid, $competencyid, $courseid) {
return new moodle_url('/admin/tool/lp/user_competency_in_course.php', array(
'userid' => $userid,
'competencyid' => $competencyid,
'courseid' => $courseid
));
}
/**
* The URL where the user competency can be found in the context of a plan.
*
* @param int $userid The user ID
* @param int $competencyid The competency ID.
* @param int $planid The plan ID.
* @return moodle_url
*/
public function user_competency_in_plan($userid, $competencyid, $planid) {
return new moodle_url('/admin/tool/lp/user_competency_in_plan.php', array(
'userid' => $userid,
'competencyid' => $competencyid,
'planid' => $planid
));
}
/**
* The URL where the user evidence (of prior learning) can be found.
*
* @param int $userevidenceid The user evidence ID
* @return moodle_url
*/
public function user_evidence($userevidenceid) {
return new moodle_url('/admin/tool/lp/user_evidence.php', array('id' => $userevidenceid));
}
}