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,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;
}
}