From e81a6cdab0bcb92ef2eaa77d5fff67cee0cafb7f Mon Sep 17 00:00:00 2001 From: Prasanna LMSACE Date: Wed, 15 Nov 2023 16:12:32 +0530 Subject: [PATCH] Users list of skills added --- classes/table/users_skills.php | 131 +++++++++++++++++++++++ classes/table/users_skills_filterset.php | 39 +++++++ db/access.php | 11 ++ lang/en/tool_skills.php | 8 +- lib.php | 25 ++++- manage/courselist.php | 1 + manage/list.php | 13 ++- manage/usersreport.php | 76 +++++++++++++ styles.css | 8 ++ version.php | 2 +- 10 files changed, 305 insertions(+), 9 deletions(-) create mode 100644 classes/table/users_skills.php create mode 100644 classes/table/users_skills_filterset.php create mode 100644 manage/usersreport.php diff --git a/classes/table/users_skills.php b/classes/table/users_skills.php new file mode 100644 index 0000000..8fa9d59 --- /dev/null +++ b/classes/table/users_skills.php @@ -0,0 +1,131 @@ +. + +/** + * 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)); + } +} diff --git a/classes/table/users_skills_filterset.php b/classes/table/users_skills_filterset.php new file mode 100644 index 0000000..87cc834 --- /dev/null +++ b/classes/table/users_skills_filterset.php @@ -0,0 +1,39 @@ +. + +/** + * 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 { + +} diff --git a/db/access.php b/db/access.php index 31a532e..f0258e2 100644 --- a/db/access.php +++ b/db/access.php @@ -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 + ), + ), + ); diff --git a/lang/en/tool_skills.php b/lang/en/tool_skills.php index c445f3b..cb04b81 100644 --- a/lang/en/tool_skills.php +++ b/lang/en/tool_skills.php @@ -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'; @@ -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'; diff --git a/lib.php b/lib.php index 161993b..324ffe6 100644 --- a/lib.php +++ b/lib.php @@ -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', [ @@ -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'); + } } } @@ -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 = []; @@ -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. @@ -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) . ")" ); @@ -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); } diff --git a/manage/courselist.php b/manage/courselist.php index 95d1468..a9641bc 100644 --- a/manage/courselist.php +++ b/manage/courselist.php @@ -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); diff --git a/manage/list.php b/manage/list.php index 16505a6..eb9f0e5 100644 --- a/manage/list.php +++ b/manage/list.php @@ -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); @@ -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 = []; @@ -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. @@ -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'); diff --git a/manage/usersreport.php b/manage/usersreport.php new file mode 100644 index 0000000..a083bba --- /dev/null +++ b/manage/usersreport.php @@ -0,0 +1,76 @@ +. + +/** + * Tool Skills - Manage course skills list. + * + * @package tool_skills + * @copyright 2023 bdecent GmbH + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +// Require config. +require(__DIR__.'/../../../../config.php'); + +// Require admin library. +require_once($CFG->libdir.'/adminlib.php'); + +// Get parameters. +$skillid = required_param('id', PARAM_INT); +// Get the skill. +$skill = $DB->get_record('tool_skills', ['id' => $skillid], '*', MUST_EXIST); + +// Get system context. +$context = \context_system::instance(); + +// Login check required. +require_login(); +// Access checks. +require_capability('tool/skills:viewotherspoints', $context); + +// Prepare the page (to make sure that all necessary information is already set even if we just handle the actions as a start). +$PAGE->set_context($context); +$PAGE->set_url(new moodle_url('/admin/tool/skills/manage/usersreport.php', ['id' => $skillid])); +$PAGE->set_cacheable(false); + +// Skills points string. +$pointstr = get_string('skillpoints', 'tool_skills', format_string($skill->name)); +$PAGE->set_heading($pointstr); + +// Further prepare the page. +$PAGE->set_title($pointstr); + +$PAGE->navbar->add(get_string('profile', 'core'), new moodle_url('/user/profile.php')); +$PAGE->navbar->add(get_string('skills', 'tool_skills'), + new moodle_url('/admin/tool/skills/manage/usersreport.php', ['id' => $skillid])); + +// Build skills table. +$filterset = new tool_skills\table\users_skills_filterset; +// Users skills list of table. +$table = new \tool_skills\table\users_skills($skillid); +$table->define_baseurl($PAGE->url); +$table->set_filterset($filterset); + +// Header. +echo $OUTPUT->header(); + +// Skills description. +echo get_string('skillsotherspoint_desc', 'tool_skills'); + +$table->out(50, true); + +// Footer. +echo $OUTPUT->footer(); diff --git a/styles.css b/styles.css index 74fc486..5a6cfb6 100644 --- a/styles.css +++ b/styles.css @@ -42,3 +42,11 @@ body.behat-site .toolskills-status-switch input.custom-control-input { position: relative; z-index: -1; } + +#page-admin-tool-skills-manage-usersreport .table-dynamic { + padding-top: 40px; +} + +#page-user-profile li.contentnode.toolskill-courses-points { + padding-top: 20px; +} diff --git a/version.php b/version.php index e27d5ff..4c939b7 100644 --- a/version.php +++ b/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die('No direct access'); -$plugin->version = 2023102503; +$plugin->version = 2023102504; $plugin->requires = 2021051700; // Requires this Moodle version. $plugin->component = 'tool_skills'; // Full name of the plugin (used for diagnostics). $plugin->maturity = MATURITY_STABLE;