From 9dde9a723c9e794f9db5c0bca7350317c2290c95 Mon Sep 17 00:00:00 2001 From: Prasanna LMSACE Date: Sat, 11 Nov 2023 12:05:51 +0530 Subject: [PATCH] Improved skills table and capabilities --- classes/form/skills_form.php | 8 ++++++++ classes/helper.php | 21 +++++++++++++-------- classes/privacy/provider.php | 4 ++++ classes/table/archived_skills.php | 2 +- classes/table/course_skills_table.php | 9 +++++++++ classes/table/skills_table.php | 2 +- db/access.php | 2 +- lang/en/tool_skills.php | 17 ++++++++++++++++- lib.php | 12 ++++++++++++ manage/courselist.php | 12 +++++++----- 10 files changed, 72 insertions(+), 17 deletions(-) diff --git a/classes/form/skills_form.php b/classes/form/skills_form.php index ba704e8..468ecdc 100644 --- a/classes/form/skills_form.php +++ b/classes/form/skills_form.php @@ -174,6 +174,14 @@ public function definition_after_data() { $mform->addElement('filemanager', "levels[$i][image]", get_string('levelsimage', 'tool_skills', $i)); $mform->addHelpButton("levels[$i][image]", 'levelsimage', 'tool_skills'); + // Set the default values for the level 0. + if ($i == 0 && !$mform->getElementValue("levels[$i][name]")) { + $mform->setDefaults([ + "levels[$i][name]" => get_string('skillslevel', 'tool_skills') . ' ' . $i, + "levels[$i][points]" => '0' + ]); + } + } // Action buttons. $this->add_action_buttons(); diff --git a/classes/helper.php b/classes/helper.php index e4e1def..d4b52c0 100644 --- a/classes/helper.php +++ b/classes/helper.php @@ -39,18 +39,23 @@ class helper { * @return string The HTML contents to display the create templates button. */ public static function skills_buttons($tab, $filtered=false) { - global $OUTPUT, $DB, $CFG; + global $OUTPUT, $PAGE, $CFG; require_once($CFG->dirroot. '/admin/tool/skills/locallib.php'); - // Setup create template button on page. - $caption = get_string('createskill', 'tool_skills'); - $editurl = new \moodle_url('/admin/tool/skills/manage/edit.php', array('sesskey' => sesskey())); + $button = ''; - // IN Moodle 4.2, primary button param depreceted. - $primary = defined('single_button::BUTTON_PRIMARY') ? single_button::BUTTON_PRIMARY : true; - $button = new single_button($editurl, $caption, 'get', $primary); - $button = $OUTPUT->render($button); + // Users with manageskills capability to create a new skill. + if (has_capability('tool/skills:manage', $PAGE->context)) { + // Setup create template button on page. + $caption = get_string('createskill', 'tool_skills'); + $editurl = new \moodle_url('/admin/tool/skills/manage/edit.php', array('sesskey' => sesskey())); + + // IN Moodle 4.2, primary button param depreceted. + $primary = defined('single_button::BUTTON_PRIMARY') ? single_button::BUTTON_PRIMARY : true; + $singlebutton = new single_button($editurl, $caption, 'get', $primary); + $button .= $OUTPUT->render($singlebutton); + } // Filter form. $button .= \html_writer::start_div('filter-form-container'); diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 3b336c6..f841144 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -141,6 +141,10 @@ public static function delete_data_for_users(approved_userlist $userlist) { $context = $userlist->get_context(); $course = $DB->get_record('course', ['id' => $context->instanceid]); + if (empty($userlist->count())) { + return false; + } + list($userinsql, $userinparams) = $DB->get_in_or_equal($userlist->get_userids(), SQL_PARAMS_NAMED); $params = $userinparams; diff --git a/classes/table/archived_skills.php b/classes/table/archived_skills.php index 40aa2a3..c3d19ff 100644 --- a/classes/table/archived_skills.php +++ b/classes/table/archived_skills.php @@ -187,7 +187,7 @@ public function col_actions(stdClass $row) : string { // Unarchive the skills. $actions[] = [ 'url' => new \moodle_url($listurl, ['action' => 'active']), - 'icon' => new \pix_icon('t/unlocked', \get_string('active', 'tool_skills')), + 'icon' => new \pix_icon('f/active', \get_string('active', 'tool_skills'), 'tool_skills'), 'attributes' => array('class' => 'action-active'), 'action' => new \confirm_action(get_string('activeskillwarning', 'tool_skills')) ]; diff --git a/classes/table/course_skills_table.php b/classes/table/course_skills_table.php index 8bd2370..399fb11 100644 --- a/classes/table/course_skills_table.php +++ b/classes/table/course_skills_table.php @@ -95,12 +95,21 @@ public function query_db($pagesize, $useinitialsbar = true) { // Set the query values to fetch skills. $select = 's.*, sc.status as coursestatus, sc.uponcompletion, sc.courseid, sc.id as skillcourseid, sc.points, sc.level'; + $from = '{tool_skills} s LEFT JOIN {tool_skills_courses} sc ON sc.skill = s.id AND sc.courseid = :courseid'; $this->set_sql($select, $from, 's.archived != 1 AND s.status <> 0', ['courseid' => $this->courseid]); parent::query_db($pagesize, $useinitialsbar); + + $categoryid = get_course($this->courseid)->category; + + $this->rawdata = array_filter($this->rawdata, function($row) use ($categoryid) { + $json = $row->categories ? json_decode($row->categories) : []; + // Categories in the skill should be empty or its must contain the currrent course categoryid. + return empty($json) || in_array($categoryid, $json); + }); } /** diff --git a/classes/table/skills_table.php b/classes/table/skills_table.php index 7d67be9..cf4d9f1 100644 --- a/classes/table/skills_table.php +++ b/classes/table/skills_table.php @@ -192,7 +192,7 @@ public function col_actions(stdClass $row) : string { // Archived. $actions[] = [ 'url' => new \moodle_url($listurl, ['t' => 'archive', 'action' => 'archive']), - 'icon' => new \pix_icon('f/archive', \get_string('archive', 'tool_skills')), + 'icon' => new \pix_icon('f/archive', \get_string('archive', 'tool_skills'), 'tool_skills'), 'attributes' => array('class' => 'action-archive'), 'action' => new \confirm_action(get_string('archiveskill', 'tool_skills')) ]; diff --git a/db/access.php b/db/access.php index dbeec36..31a532e 100644 --- a/db/access.php +++ b/db/access.php @@ -42,7 +42,7 @@ 'riskbitmask' => RISK_XSS | RISK_CONFIG, 'archetypes' => array( 'manager' => CAP_ALLOW, - 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, ), ), ); diff --git a/lang/en/tool_skills.php b/lang/en/tool_skills.php index ac8607f..c445f3b 100644 --- a/lang/en/tool_skills.php +++ b/lang/en/tool_skills.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die('No direct access'); -$string['pluginname'] = 'Skill award'; +$string['pluginname'] = 'Skills'; $string['skills'] = 'Skills'; // ...Skills capabilities. $string['skills:manage'] = 'Manage skills'; @@ -77,6 +77,7 @@ $string['updatelevelscount'] = 'Update levels count'; // ...Levels form fields string. $string['skillslevels'] = 'Levels'; +$string['skillslevel'] = 'Level'; $string['levelscount_help'] = 'Choose the number of levels that exist for this skill. Each level may have a specific number of points required for achievement.'; $string['levelsname'] = 'Level #{$a} name'; $string['levelsname_help'] = 'Enter the name for level'; @@ -118,3 +119,17 @@ $string['privacy:userpoint'] = 'User point'; $string['privacy:awardlogs'] = 'Points awarded'; +$string['privacy:metadata:userpoints:userid'] = 'User ID associated with earned points'; +$string['privacy:metadata:userpoints:skill'] = 'ID of the skill associated with points'; +$string['privacy:metadata:userpoints:points'] = 'Points earned by the user for the skill'; +$string['privacy:metadata:userpoints:timecreated'] = 'Time when points were initially earned'; +$string['privacy:metadata:userpoints:timemodified'] = 'Time when points were modified'; +$string['privacy:metadata:userpoints'] = 'Metadata for points earned by the user for skills'; +$string['privacy:metadata:awardlogs:userid'] = 'User ID for points awarded'; +$string['privacy:metadata:awardlogs:points'] = 'Points awarded for the skill to the user'; +$string['privacy:metadata:awardlogs:methodid'] = 'ID of the method record detailing how points were earned'; +$string['privacy:metadata:awardlogs:method'] = 'Method by which the user earned points (course or activity)'; +$string['privacy:metadata:awardlogs:timecreated'] = 'Time when awards were logged'; +$string['privacy:metadata:awardlogs'] = 'Metadata for logs recording user points awarded for each method'; +$string['privacy:metadata:userpointsexplanation'] = 'The skills store the points users earned for the skill and log the method by which they earned it, either through course completion or activity completion.'; + diff --git a/lib.php b/lib.php index 46f15f1..161993b 100644 --- a/lib.php +++ b/lib.php @@ -136,3 +136,15 @@ function tool_skills_myprofile_navigation(tree $tree, $user, $iscurrentuser, $co } return true; } + + +/** + * Get icon mapping for font-awesome. + * @return string[] + */ +function tool_skills_get_fontawesome_icon_map() { + return [ + 'tool_skills:f/archive' => 'fa-archive', + 'tool_skills:f/active' => 'fa-undo', + ]; +} diff --git a/manage/courselist.php b/manage/courselist.php index 07fe791..95d1468 100644 --- a/manage/courselist.php +++ b/manage/courselist.php @@ -103,11 +103,13 @@ echo get_string('assignskills_desc', 'tool_skills'); // Create skills button to create new skill. -$createbutton = $OUTPUT->box_start(); -$createbutton .= $OUTPUT->single_button( - new \moodle_url('/admin/tool/skills/manage/edit.php', array('sesskey' => sesskey())), - get_string('createskill', 'tool_skills'), 'get'); -$createbutton .= $OUTPUT->box_end(); +if (has_capability('tool/skills:manage', \context_system::instance())) { + $createbutton = $OUTPUT->box_start(); + $createbutton .= $OUTPUT->single_button( + new \moodle_url('/admin/tool/skills/manage/edit.php', array('sesskey' => sesskey())), + get_string('createskill', 'tool_skills'), 'get'); + $createbutton .= $OUTPUT->box_end(); +} $countmenus = $DB->count_records('tool_skills'); if ($countmenus < 1) {