Skip to content

Commit

Permalink
Improved skills table and capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
prasanna-lmsace committed Nov 11, 2023
1 parent 30ece05 commit 9dde9a7
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 17 deletions.
8 changes: 8 additions & 0 deletions classes/form/skills_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
21 changes: 13 additions & 8 deletions classes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 4 additions & 0 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion classes/table/archived_skills.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
];
Expand Down
9 changes: 9 additions & 0 deletions classes/table/course_skills_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/table/skills_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
];
Expand Down
2 changes: 1 addition & 1 deletion db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
'riskbitmask' => RISK_XSS | RISK_CONFIG,
'archetypes' => array(
'manager' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
),
),
);
17 changes: 16 additions & 1 deletion lang/en/tool_skills.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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.';

12 changes: 12 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
}
12 changes: 7 additions & 5 deletions manage/courselist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9dde9a7

Please sign in to comment.