Skip to content

Commit

Permalink
Manage course skills list capability updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
raja-lmsace committed Jan 20, 2024
1 parent 87b48c1 commit 3f701ae
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 60 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ See http://docs.moodle.org/en/Installing_plugins for details on installing Moodl

Admins or users with the capability tool/skills:manage (by default given to managers) need to create skills under Site Administration > Plugins > Tools > Skills and make them available either globally or for specific course categories.

Teachers (or users with the capability tool/skills:managecourseskills) can then manage skills in their course from the "Manage skills" page which is found in the secondary navigation of the course. From there, teachers can then enable specific skills and configure how many points students earn upon completion of the course.
Teachers (or users with the capability tool/skills:managecourseskillslist) can then manage skills in their course from the "Manage skills" page which is found in the secondary navigation of the course. From there, teachers can then enable specific skills and configure how many points students earn upon completion of the course.

# Documentation

Expand Down
26 changes: 25 additions & 1 deletion classes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,36 @@ public static function get_skills_list() {
// List of skills available.
$skills = $DB->get_records('tool_skills', []);
array_walk($skills, function(&$skill) {
$skill = new skills($skill->id);
$skill = \tool_skills\skills::get($skill->id);
});

return $skills;
}

/**
* Get the list of completed skills of the user.
*
* @param int $userid
* @return array
*/
public static function get_user_completedskills(int $userid) {
global $DB;
// List of skills available.
$skills = \tool_skills\user::get($userid)->get_user_skills();

foreach ($skills as $skill) {
$skillpoint = $skill->skillobj->get_points_to_earnskill();
$points = $skill->userpoints->points;
$percentage = ($points / $skillpoint) * 100;

if ($percentage >= 100) {
$completed[] = $skill->id;
}
}

return array_unique($completed);
}

/**
* Get addon extend method.
*
Expand Down
7 changes: 4 additions & 3 deletions db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@
],
],

'tool/skills:managecourseskills' => [
'tool/skills:managecourseskillslist' => [
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'contextlevel' => CONTEXT_COURSE,
'riskbitmask' => RISK_XSS | RISK_CONFIG,
'archetypes' => [
'manager' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW,
],
],

Expand Down
2 changes: 2 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function xmldb_tool_skills_upgrade($oldversion) {
global $CFG, $DB;

$dbman = $DB->get_manager();

if ($oldversion < 2023102505) {
$table = new xmldb_table('tool_skills_awardlogs');
$field = new xmldb_field('skill', XMLDB_TYPE_INTEGER, 18, null, null, null, null, 'id');
Expand All @@ -40,5 +41,6 @@ function xmldb_tool_skills_upgrade($oldversion) {
}
upgrade_plugin_savepoint(true, 2023102505, 'tool', 'skills');
}

return true;
}
2 changes: 1 addition & 1 deletion lang/en/tool_skills.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
$string['skills'] = 'Skills';
// ...Skills capabilities.
$string['skills:manage'] = 'Manage skills';
$string['skills:managecourseskills'] = 'Manage course skills';
$string['skills:managecourseskillslist'] = 'Manage course skills';
$string['skills:viewotherspoints'] = 'View others points';
// ...error strings.
$string['error:skillsnotfound'] = 'Skill record not found for the given id';
Expand Down
4 changes: 2 additions & 2 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);
$addnode = $addnode && has_capability('tool/skills:managecourseskillslist', $context);
if ($addnode) {
$id = $context->instanceid;
$url = new moodle_url('/admin/tool/skills/manage/courselist.php', [
Expand All @@ -52,7 +52,7 @@ function tool_skills_extend_navigation_course(navigation_node $navigation, stdCl
if (empty($navigation->get_children_key_list())) {
$navigation->add_node($node, null);
} else {
$navigation->add_node($node, 'gradebooksetup');
$navigation->add_node($node, 'coursereports');
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion manage/courselist.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
// Login check required.
require_login();
// Access checks.
require_capability('tool/skills:managecourseskills', $context);
require_capability('tool/skills:managecourseskillslist', $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);
Expand Down
84 changes: 42 additions & 42 deletions tests/behat/tool_skills_general.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,95 +21,95 @@ Feature: Configuring the tool_skills plugin on the "Skills" page, applying diffe
And I should see "Skills are not created yet or not in use"
And I click on "Create skill" "button"
And I set the following fields to these values:
| Skill name | Begineer |
| Key | begineer |
| Level #0 name | begineer |
| Skill name | Beginner |
| Key | beginner |
| Level #0 name | beginner |
| Level #0 point | 10 |
And I click on "Save changes" "button"
And I should see "Begineer" in the "tool_skills_list" "table"
And I should see "Beginner" in the "tool_skills_list" "table"

@javascript
Scenario: Change the skills visibility
When I log in as "admin"
And I create skill with the following fields to these values:
| Skill name | Begineer |
| Key | begineer |
| Level #0 name | begineer |
| Skill name | Beginner |
| Key | beginner |
| Level #0 name | beginner |
| Level #0 point | 10 |
And ".skill-item-actions .custom-control-input:checked" "css_element" should exist in the "begineer" "table_row"
And ".skill-item-actions .custom-control-input:checked" "css_element" should exist in the "beginner" "table_row"
Then I am on "Course 1" course homepage
And I click on "More" "link" in the ".secondary-navigation" "css_element"
And I click on "Manage skills" "link"
Then I should see "Begineer"
Then I should see "Beginner"
And I navigate to skills
And I click on ".skill-item-actions .toolskills-status-switch" "css_element" in the "begineer" "table_row"
And ".skill-item-actions .toolskills-status-switch.action-show" "css_element" should exist in the "begineer" "table_row"
And I click on ".skill-item-actions .toolskills-status-switch" "css_element" in the "beginner" "table_row"
And ".skill-item-actions .toolskills-status-switch.action-show" "css_element" should exist in the "beginner" "table_row"
Then I am on "Course 1" course homepage
And I click on "More" "link" in the ".secondary-navigation" "css_element"
And I click on "Manage skills" "link"
Then I should not see "Begineer"
Then I should not see "Beginner"

@javascript
Scenario: Update the existing skills and levels
When I log in as "admin"
And I create skill with the following fields to these values:
| Skill name | Begineer |
| Key | begineer |
| Level #0 name | begineer |
| Skill name | Beginner |
| Key | beginner |
| Level #0 name | beginner |
| Level #0 point | 10 |
Then I should see "Begineer"
And ".skill-item-actions .action-edit" "css_element" should exist in the "begineer" "table_row"
And I click on ".skill-item-actions .action-edit" "css_element" in the "begineer" "table_row"
Then I should see "Beginner"
And ".skill-item-actions .action-edit" "css_element" should exist in the "beginner" "table_row"
And I click on ".skill-item-actions .action-edit" "css_element" in the "beginner" "table_row"
And I set the following fields to these values:
| Skill name | Critical thinker |
And I click on "Save changes" "button"
Then I should not see "Begineer" in the "begineer" "table_row"
And I should see "Critical thinker" in the "begineer" "table_row"
Then I should not see "Beginner" in the "beginner" "table_row"
And I should see "Critical thinker" in the "beginner" "table_row"

@javascript
Scenario: Archive and unarchive the skills
When I log in as "admin"
And I navigate to skills
And I click on "Create skill" "button"
And I set the following fields to these values:
| Skill name | Begineer |
| Key | begineer |
| Level #0 name | begineer |
| Skill name | Beginner |
| Key | beginner |
| Level #0 name | beginner |
| Level #0 point | 10 |
And I click on "Save changes" "button"
And I should see "Begineer" in the "tool_skills_list" "table"
And I click on ".skill-item-actions .action-archive" "css_element" in the "begineer" "table_row"
And I should see "Beginner" in the "tool_skills_list" "table"
And I click on ".skill-item-actions .action-archive" "css_element" in the "beginner" "table_row"
And I should see "archive" message confirmation
And I navigate to confirmation
And I should see "Begineer" in the "tool_skills_archived_list" "table"
And I should see "Beginner" in the "tool_skills_archived_list" "table"
And I click on "Active skills" "link"
Then I should see "Skills are not created yet or not in use"
And I click on "Archived skills" "link"
And I click on ".skill-item-actions .action-active" "css_element" in the "begineer" "table_row"
And I click on ".skill-item-actions .action-active" "css_element" in the "beginner" "table_row"
And I should see "activate" message confirmation
And I navigate to confirmation
And I should see "Begineer" in the "tool_skills_list" "table"
And I should see "Beginner" in the "tool_skills_list" "table"

@javascript
Scenario: Delete skills and its levels
When I log in as "admin"
And I create skill with the following fields to these values:
| Skill name | Begineer |
| Key | begineer |
| Level #0 name | begineer |
| Skill name | Beginner |
| Key | beginner |
| Level #0 name | beginner |
| Level #0 point | 10 |
And I should see "Begineer" in the "tool_skills_list" "table"
And I click on ".skill-item-actions .action-archive" "css_element" in the "begineer" "table_row"
And I should see "Beginner" in the "tool_skills_list" "table"
And I click on ".skill-item-actions .action-archive" "css_element" in the "beginner" "table_row"
And I navigate to confirmation
And I click on "Archived skills" "link"
And I click on ".skill-item-actions .action-delete" "css_element" in the "begineer" "table_row"
And I click on ".skill-item-actions .action-delete" "css_element" in the "beginner" "table_row"
And I should see "delete" message confirmation
And I navigate to confirmation
Then I should not see "Begineer" in the "#region-main" "css_element"
Then I should not see "Beginner" in the "#region-main" "css_element"
And I create skill with the following fields to these values:
| Skill name | Critical thinker |
| Key | critical-thinker |
| Level #0 name | begineer |
| Level #0 name | beginner |
| Level #0 point | 20 |
Then I am on "Course 1" course homepage
And I click on "More" "link" in the ".secondary-navigation" "css_element"
Expand All @@ -131,12 +131,12 @@ Feature: Configuring the tool_skills plugin on the "Skills" page, applying diffe
Scenario: Create multiple levels
When I log in as "admin"
And I create skill with the following fields to these values:
| Skill name | Begineer |
| Key | begineer |
| Level #0 name | begineer |
| Skill name | Beginner |
| Key | beginner |
| Level #0 name | beginner |
| Level #0 point | 10 |
Then I should see "Begineer"
And ".skill-item-actions .action-edit" "css_element" should exist in the "begineer" "table_row"
Then I should see "Beginner"
And ".skill-item-actions .action-edit" "css_element" should exist in the "beginner" "table_row"
And I click on ".skill-item-actions .action-edit" "css_element"
And I set the field "Number of levels" to "3"
And I set the following fields to these values:
Expand All @@ -146,7 +146,7 @@ Feature: Configuring the tool_skills plugin on the "Skills" page, applying diffe
And I press "Save changes"
Then I am on "Course 1" course homepage
And I navigate to "Manage skills" in current page administration
And I should see "Begineer"
And I should see "Beginner"
And I click on ".skill-course-actions .action-edit" "css_element"
And I should see "Set course skills" in the ".modal-header" "css_element"
And I set the field "Status" to "Enabled"
Expand Down
16 changes: 8 additions & 8 deletions tests/behat/tool_skills_managelevels.feature
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ Feature: Allocate points to users, need to manage levels and assign skills to co
And I set the field "Test page1" to "1"
And I press "Save changes"
And I create skill with the following fields to these values:
| Skill name | Begineer |
| Key | begineer |
| Skill name | Beginner |
| Key | beginner |
| Number of levels | 2 |
| Level #0 name | begineer |
| Level #0 name | beginner |
| Level #0 point | 10 |
| Level #1 name | Level 1 |
| Level #1 point | 20 |
Expand All @@ -58,7 +58,7 @@ Feature: Allocate points to users, need to manage levels and assign skills to co
| Upon course completion | Points |
| Points | 200 |
And I press "Save changes"
Then I should see "Points - 200" in the "begineer" "table_row"
Then I should see "Points - 200" in the "beginner" "table_row"
And I log out
And I am on the "Course 1" course page logged in as student1
And I am on the "student1" "user > profile" page
Expand All @@ -78,7 +78,7 @@ Feature: Allocate points to users, need to manage levels and assign skills to co
| Upon course completion | Set level |
| Level | Level 1 |
And I press "Save changes"
Then I should see "Set level - Level 1" in the "begineer" "table_row"
Then I should see "Set level - Level 1" in the "beginner" "table_row"
And I log out
And I am on the "Course 1" course page logged in as student1
And I am on the "student1" "user > profile" page
Expand Down Expand Up @@ -111,7 +111,7 @@ Feature: Allocate points to users, need to manage levels and assign skills to co
| Upon course completion | Force level |
| Level | Level 2 |
And I press "Save changes"
Then I should see "Force level - Level 2" in the "begineer" "table_row"
Then I should see "Force level - Level 2" in the "beginner" "table_row"
And I log out
And I am on the "Course 1" course page logged in as student1
And I press "Mark as done"
Expand Down Expand Up @@ -145,7 +145,7 @@ Feature: Allocate points to users, need to manage levels and assign skills to co
| Upon course completion | Force level |
| Level | Level 2 |
And I press "Save changes"
Then I should see "Force level - Level 2" in the "begineer" "table_row"
Then I should see "Force level - Level 2" in the "beginner" "table_row"
And I log out
And I am on the "Course 1" course page logged in as student1
And I press "Mark as done"
Expand All @@ -169,4 +169,4 @@ Feature: Allocate points to users, need to manage levels and assign skills to co
And I wait until "Done" "button" exists
And I am on the "student1" "user > profile" page
Then I should see "Earned: -50" in the ".skills-points-C2" "css_element"
And I should see "Earned: -20" in the ".skill-begineer" "css_element"
And I should see "Earned: -20" in the ".skill-beginner" "css_element"
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

defined('MOODLE_INTERNAL') || die;

$plugin->version = 2024012006;
$plugin->version = 2024019003;
$plugin->requires = 2021051700; // Requires this Moodle version.
$plugin->component = 'tool_skills'; // Full name of the plugin (used for diagnostics).
$plugin->maturity = MATURITY_STABLE;
Expand Down

0 comments on commit 3f701ae

Please sign in to comment.