Commit e61743d9 authored by Plugins bot's avatar Plugins bot
Browse files

PLUGIN-24026 block_lpprogress: cibot precheck request

parent ff833a08
This diff is collapsed.
# Learning Plans Progress #
This blocks shows the progress of learning plans in a vertical progress bar with "check" icons for each competency.
By clicking in the competency name the user can see the list of linked courses and access the course by clicking on it's name.
## License ##
2021 Daniel Neis Araujo <daniel@adapta.online>
This program 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.
This program 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
this program. If not, see <http://www.gnu.org/licenses/>.
<?php
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.
/**
* Block lpprogress is defined here.
*
* @package block_lpprogress
* @copyright 2021 Daniel Neis Araujo <daniel@adapta.online>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* lpprogress block.
*
* @package block_lpprogress
* @copyright 2021 Daniel Neis Araujo <daniel@adapta.online>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_lpprogress extends block_base {
/**
* Initializes class member variables.
*/
public function init() {
// Needed by Moodle to differentiate between blocks.
$this->title = get_string('pluginname', 'block_lpprogress');
}
/**
* Returns the block contents.
*
* @return stdClass The block contents.
*/
public function get_content() {
global $USER;
if ($this->content !== null) {
return $this->content;
}
if (empty($this->instance)) {
$this->content = '';
return $this->content;
}
if (!get_config('core_competency', 'enabled')) {
return $this->content;
}
try {
$plans = core_competency\api::list_user_plans($USER->id);
} catch (required_capability_exception $e) {
$plans = [];
}
$renderer = $this->page->get_renderer('block_lpprogress');
$renderable = new \block_lpprogress\output\lpprogress($plans);
$this->content = (object) [
'text' => $renderer->render($renderable),
'footer' => ''
];
return $this->content;
}
/**
* Defines configuration data.
*
* The function is called immediatly after init().
*/
public function specialization() {
// Load user defined title and make sure it's never empty.
if (empty($this->config->title)) {
$this->title = get_string('pluginname', 'block_lpprogress');
} else {
$this->title = $this->config->title;
}
}
/**
* Sets the applicable formats for the block.
*
* @return string[] Array of pages and permissions.
*/
public function applicable_formats() {
return array(
'all' => true,
);
}
}
<?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 lpprogress block.
*
* @package block_lpprogress
* @copyright 2021 Daniel Neis Araujo <daniel@adapta.online>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_lpprogress\output;
defined('MOODLE_INTERNAL') || die();
use renderable;
use renderer_base;
use templatable;
use core_competency\api;
use core_competency\plan;
use core_competency\external\performance_helper;
use core_competency\external\competency_exporter;
use core_competency\external\plan_exporter;
/**
* Class containing data for timeline block.
*
* @copyright Daniel Neis Araujo <daniel@adapta.online>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class lpprogress implements renderable, templatable {
/**
* lpprogress constructor.
*
* @param array $plans The list of learning plans
*/
public function __construct(array $plans) {
$this->plans = $plans;
}
/**
* 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) {
$plans = [];
foreach ($this->plans as $plan) {
if (($plan->get('status') == plan::STATUS_ACTIVE) || ($plan->get('status') == plan::STATUS_COMPLETE)) {
$plans[] = $plan;
}
}
$helper = new performance_helper();
$activeplans = array();
foreach ($plans as $plan) {
$planexporter = new plan_exporter($plan, array('template' => $plan->get_template()));
$currentplan = $planexporter->export($output);
if ($currentplan->iscompleted) {
$ucproperty = 'usercompetencyplan';
$ucexporter = 'core_competency\\external\\user_competency_plan_exporter';
} else {
$ucproperty = 'usercompetency';
$ucexporter = 'core_competency\\external\\user_competency_exporter';
}
$pclist = api::list_plan_competencies($plan);
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);
$exporter = new $ucexporter($usercomp, array('scale' => $scale));
$record->$ucproperty = $exporter->export($output);
if ($currentplan->iscompleted) {
$record->isproficient = $record->usercompetencyplan->proficiency;
} else {
$record->isproficient = $record->usercompetency->proficiency;
}
$currentplan->competencies[] = $record;
}
$activeplans[] = $currentplan;
}
return ['plans' => $activeplans];
}
}
<?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/>.
/**
* Learning Plan Progress block block renderer.
*
* @package block_lpprogress
* @copyright 2021 Daniel Neis Araujo <daniel@adapta.online>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_lpprogress\output;
defined('MOODLE_INTERNAL') || die;
use plugin_renderer_base;
use renderable;
/**
* Learning Plan Progress block renderer.
*
* @package block_lpprogress
* @copyright 2021 Daniel Neis Araujo <daniel@adapta.online>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends plugin_renderer_base {
}
<?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/>.
/**
* Capabilities for the lpprogress block.
*
* @package block_lpprogress
* @copyright 2018 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'block/lpprogress:myaddinstance' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'user' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/my:manageblocks'
),
'block/lpprogress:addinstance' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'user' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/my:manageblocks'
)
);
<?php
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.
/**
* Plugin strings are defined here.
*
* @package block_lpprogress
* @category string
* @copyright 2021 Daniel Neis Araujo <daniel@adapta.online>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$string['completed'] = 'Completed!';
$string['pluginname'] = 'Learning Plans Progress';
.block_lpprogress {
color: #000;
background-color: #f44336;
background-repeat: no-repeat;
}
.block_lpprogress .final {
display: inline;
vertical-align: super;
margin-left: 0.7em;
}
.block_lpprogress #progressbar li {
list-style-type: none;
}
.block_lpprogress #progressbar li a {
margin-left: 1em;
vertical-align: -15%;
}
.block_lpprogress #progressbar .step0:before {
content: "";
background-color: #999da0;
position: absolute;
left: 0.55em;
}
.block_lpprogress #progressbar li:before {
width: 30px;
height: 30px;
line-height: 30px;
display: inline-block;
font-size: 20px;
background: #fff;
border: 2px solid white;
border-radius: 50%;
}
.block_lpprogress #progressbar li:after {
content: '';
width: 4px;
height: 2em;
background: #bdbdbd;
display: block;
margin-left: -0.5em;
}
.block_lpprogress #progressbar li:last-child:before {
width: 40px;
height: 40px;
display: inline-block;
margin-left: -0.25em;
}
.block_lpprogress #progressbar li:last-child:after {
height: 0;
}
.block_lpprogress #progressbar li.active:after {
background: #c6e4c0;
}
.block_lpprogress #progressbar li.active:before {
background: #17a23f;
font-family: fontawesome;
}
#block-region-side-pre .block_lpprogress .col-3 {
flex: unset;
max-width: 100% ;
}
{{!
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 block_lpprogress/lpprogress
This template renders the learning plan progress.
Example context (json):
{
"plans": [{
"name": "A learning plan example",
"iscompleted": 1,
"competencies": [{
"isproficient": 1,
"competency": {
"id": 1,
"shortname": "Competency number one"
}
},
{
"isproficient": 1,
"competency": {
"id": 1,
"shortname": "Competency number two"
}
}]
}]
}
}}
<div class="row">
{{#plans}}
<div class="col-3">
<div class="card">
<h3 class="text-center">{{name}}</h3>
<div class="col-md-12">
<ul id="progressbar">
{{#competencies}}
<li class="step0 {{#isproficient}}active{{/isproficient}}">
<a href="#" data-id="{{competency.id}}" data-action="find-courses-link">{{competency.shortname}}</a>
</li>
{{/competencies}}
<li class="step0 {{#iscompleted}}active{{/iscompleted}}">
<h2 class="text-muted final">{{#str}} completed, block_lpprogress {{/str}}</h2>
</li>
</ul>
</div>
</div>
</div>
{{/plans}}
</div>
{{#js}}
require(['jquery',
'core/templates',
'core/ajax',
'core/notification',
'core/str',
'tool_lp/dialogue'],
function($, templates, ajax, notification, str, Dialogue) {
$('section.block_lpprogress').find('[data-action="find-courses-link"]').click(function(e) {
e.preventDefault();
var competencyid = $(e.target).data('id');
var requests = ajax.call([{
methodname: 'tool_lp_list_courses_using_competency',
args: {id: competencyid}
}]);
requests[0].done(function(courses) {
var context = {
courses: courses
};
templates.render('tool_lp/linked_courses_summary', context).done(function(html) {
str.get_string('linkedcourses', 'tool_lp').done(function(linkedcourses) {
new Dialogue(
linkedcourses, // Title.
html // The linked courses.
);
}).fail(notification.exception);
}).fail(notification.exception);
}).fail(notification.exception);
});
});
{{/js}}
<?php
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.
/**
* Plugin version and other meta-data are defined here.
*
* @package block_lpprogress
* @copyright 2021 Daniel Neis Araujo <daniel@adapta.online>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'block_lpprogress';
$plugin->release = '4';
$plugin->version = 2021042900;
$plugin->requires = 2020061500;
$plugin->maturity = MATURITY_STABLE;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment