Skip to content

Commit

Permalink
Users list of skills added
Browse files Browse the repository at this point in the history
  • Loading branch information
prasanna-lmsace committed Nov 15, 2023
1 parent 9dde9a7 commit e81a6cd
Show file tree
Hide file tree
Showing 10 changed files with 305 additions and 9 deletions.
131 changes: 131 additions & 0 deletions classes/table/users_skills.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?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/>.

/**
* Tool skills - Users skill points report.
*
* @package tool_skills
* @copyright 2023, bdecent gmbh bdecent.de
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_skills\table;

defined('MOODLE_INTERNAL') || die();

use html_writer;
use moodle_url;

use core_table\dynamic as dynamic_table;
use core_table\local\filter\filterset;

require_once($CFG->libdir.'/tablelib.php');

/**
* View the users skills for this skill.
*/
class users_skills extends \table_sql implements dynamic_table {

/**
* Current skill instance record data.
*
* @var stdclass
*/
public $skill;

/**
* Fetch completions users list.
*
* @param int $skillid
* @return void
*/
public function __construct($skillid) {
global $PAGE, $DB;
parent::__construct($skillid);

// Define the headers and columns.
$headers = [];
$columns = [];
$headers[] = get_string('fullname');
$columns[] = 'fullname';

$headers[] = get_string('pointsearned', 'tool_skills');
$columns[] = 'points';

$this->define_columns($columns);
$this->define_headers($headers);

// Remove sorting for some fields.
$this->sortable(false);

// Do not make the table collapsible.
$this->collapsible(false);

$this->set_attribute('id', 'tool_skills_users_report');

$this->skill = $DB->get_record('tool_skills', ['id' => $skillid] );

}

/**
* Get the context of this table.
*
* @return \context
*/
public function get_context(): \context {

return \context_system::instance();
}

/**
* Guess the base url for the participants table.
*/
public function guess_base_url(): void {
$this->baseurl = new \moodle_url('/admin/tools/skills/manage/usersreport.php', ['id' => $this->skill->id]);
}

/**
* Query the database for results to display in the table.
*
* @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) {

// Set the query values to fetch skills.
$select = 'usp.*, s.*, u.*';

$from = '{tool_skills_userpoints} usp
LEFT JOIN {tool_skills} s ON usp.skill = s.id
LEFT JOIN {user} u ON usp.userid = u.id';

$this->set_sql($select, $from, 's.id = :skillid', ['skillid' => $this->skill->id]);

parent::query_db($pagesize, $useinitialsbar);
}

/**
* Generate the fullname column.
*
* @param \stdClass $data
* @return string
*/
public function col_fullname($data) {
global $OUTPUT;

return $OUTPUT->user_picture($data, array('size' => 35, 'includefullname' => true));
}
}
39 changes: 39 additions & 0 deletions classes/table/users_skills_filterset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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/>.

/**
* Filterset
*
* @package tool_skills
* @copyright 2023, bdecent gmbh bdecent.de
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

declare(strict_types=1);

namespace tool_skills\table;

use core_table\local\filter\boolean_filter;
use core_table\local\filter\filterset;
use core_table\local\filter\integer_filter;
use core_table\local\filter\string_filter;

/**
* Participants table filterset.
*/
class users_skills_filterset extends filterset {

}
11 changes: 11 additions & 0 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,15 @@
'editingteacher' => CAP_ALLOW,
),
),

'tool/skills:viewotherspoints' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'riskbitmask' => RISK_XSS | RISK_CONFIG,
'archetypes' => array(
'manager' => CAP_ALLOW,
'user' => CAP_ALLOW
),
),

);
8 changes: 7 additions & 1 deletion lang/en/tool_skills.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
// ...Skills capabilities.
$string['skills:manage'] = 'Manage skills';
$string['skills:managecourseskills'] = 'Manage course skills';
$string['skills:viewotherspoints'] = 'View others points';
// ...error strings.
$string['error:skillsnotfound'] = 'Skill record not found for the given id';
$string['error:identityexists'] = 'Given skill identity is exists, Please use unique value';
Expand Down Expand Up @@ -113,7 +114,12 @@
// ...Profile page skills result category.
$string['skillprofilecategory'] = 'Skills earned';
$string['earned'] = 'Earned';
$string['pointscompletie'] = 'Points to complete this skill: {$a} ';
$string['pointsearned'] = 'Points earned';
$string['pointscomplete'] = 'Points to complete this skill: {$a} ';
$string['pointsforcompletion'] = 'Points for completion';
$string['usersreport'] = 'View users points for this skill';
$string['skillpoints'] = '{$a} - users points';
$string['skillsotherspoint_desc'] = 'This table displays the points earned by other users in this skill. It provides an overview of the achievements and progress of peers within the same skill category';
// ...Privacy API strings.
$string['userpoints'] = 'User points earned';
$string['privacy:userpoint'] = 'User point';
Expand Down
25 changes: 20 additions & 5 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function tool_skills_extend_navigation_course(navigation_node $navigation, stdCl
global $PAGE;

$addnode = $context->contextlevel === CONTEXT_COURSE;
$addnode = $addnode && has_capability('tool/skills:managecourseskills', $context); // TODO: Custom capability.
$addnode = $addnode && has_capability('tool/skills:managecourseskills', $context);
if ($addnode) {
$id = $context->instanceid;
$url = new moodle_url('/admin/tool/skills/manage/courselist.php', [
Expand All @@ -48,8 +48,12 @@ function tool_skills_extend_navigation_course(navigation_node $navigation, stdCl
$node->set_force_into_more_menu(false);
$node->set_show_in_secondary_navigation(true);
$node->key = 'manage-tool-skills';
$navigation->add_node($node, 'gradebooksetup');

if (empty($navigation->get_children_key_list())) {
$navigation->add_node($node, null);
} else {
$navigation->add_node($node, 'gradebooksetup');
}
}
}

Expand Down Expand Up @@ -79,6 +83,14 @@ function tool_skills_myprofile_navigation(tree $tree, $user, $iscurrentuser, $co

if ($iscurrentuser) {
$systemcontext = \context_system::instance();

if (has_capability('tool/skills:manage', $systemcontext)) {
$link = new moodle_url('/admin/tool/skills/manage/list.php');
$skillstr = html_writer::link($link, get_string('skills:manage', 'tool_skills'));
$coursenode = new core_user\output\myprofile\node('toolskills', 'manageskills', $skillstr, null, null);
$tree->add_node($coursenode);
}

$skills = \tool_skills\user::get($USER->id)->get_user_skills();

$newskills = [];
Expand All @@ -99,7 +111,7 @@ function tool_skills_myprofile_navigation(tree $tree, $user, $iscurrentuser, $co
// Skill name.
$skillstr = html_writer::tag('h5', $skillslist[$skillid]->get_name());
// Point to completion this skill.
$skillstr .= html_writer::tag('p', 'Points to complete this skill: ' . $skillpoints . $earnedstring,
$skillstr .= html_writer::tag('p', get_string('pointscomplete', 'tool_skills', $skillpoints . $earnedstring),
['class' => 'skill-'.$skill->get_data()->identitykey]);

$skillstr .= html_writer::start_tag('ul'); // Start the list of skills courses.
Expand All @@ -116,7 +128,7 @@ function tool_skills_myprofile_navigation(tree $tree, $user, $iscurrentuser, $co
$course = $data->skillcourse->get_course();
$li = html_writer::link($courseurl, format_string($course->fullname));

$coursepointstr = "Points for completion" . " : " . $pointstoearn;
$coursepointstr = get_string('pointsforcompletion', 'tool_skills') . " : " . $pointstoearn;
$coursepointstr .= html_writer::tag('b',
" (".get_string('earned', 'tool_skills') . ": " .( $pointsfromcourse ?? 0) . ")" );

Expand All @@ -127,8 +139,11 @@ function tool_skills_myprofile_navigation(tree $tree, $user, $iscurrentuser, $co

$skillstr .= html_writer::end_tag('ul'); // End the skill list.

$report = new \moodle_url('/admin/tool/skills/manage/usersreport.php', ['id' => $skillid]);
$skillstr .= html_writer::link($report, get_string('usersreport', 'tool_skills'));

$coursenode = new core_user\output\myprofile\node('toolskills', "skill_".$skill->get_data()->id,
$skillstr, null, null);
'', null, null, $skillstr, null, 'toolskill-courses-points');

$tree->add_node($coursenode);
}
Expand Down
1 change: 1 addition & 0 deletions manage/courselist.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

// Require admin library.
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/tablelib.php');

// Get parameters.
$courseid = required_param('courseid', PARAM_INT);
Expand Down
13 changes: 11 additions & 2 deletions manage/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

// Require admin library.
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/tablelib.php');


// Get parameters.
$action = optional_param('action', null, PARAM_ALPHAEXT);
Expand All @@ -37,7 +39,8 @@
$context = context_system::instance();

// Access checks.
admin_externalpage_setup('manageskills');
require_login();
require_capability('tool/skills:manage', $context);

// Create a page URL.
$urlparams = [];
Expand All @@ -49,6 +52,13 @@
$PAGE->set_url($pageurl);
$PAGE->set_cacheable(false);

// Further prepare the page.
$PAGE->set_heading(get_string('skillslisthead', 'tool_skills'));

// Setup the breadcrumb.
$PAGE->navbar->add(get_string('tools', 'admin'), new moodle_url('/admin/category.php', array('category' => 'tool')));
$PAGE->navbar->add(get_string('pluginname', 'tool_skills'), $pageurl);

// Process actions.
if ($action !== null && confirm_sesskey()) {
// Every action is based on a skill, thus the skill ID param has to exist.
Expand Down Expand Up @@ -129,7 +139,6 @@

// Header.
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('skillslisthead', 'tool_skills'));

// Skills description.
echo get_string('skillslist_desc', 'tool_skills');
Expand Down
Loading

0 comments on commit e81a6cd

Please sign in to comment.