Added coaching navigation links and enable/disable setting

This commit is contained in:
PMKuipers 2024-03-10 21:51:37 +01:00
parent 747e1decd1
commit 3002a866bb
9 changed files with 65 additions and 18 deletions

View File

@ -22,6 +22,7 @@
namespace local_treestudyplan\local\helpers;
use \core_course_category;
use local_treestudyplan\courseservice;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/webservice/lib.php');
@ -73,19 +74,11 @@ class webservicehelper {
$list = [];
// Initialize parent if needed.
if ($parent == null) {
$parent = \core_course_category::user_top();
if ($parent == null) {
// If the parent is still null, we do not have a valid user top.
return false;
}
if (has_capability($capability, $parent->get_context())) {
$list[] = $parent;
}
$children = courseservice::user_tops();
} else {
$children = $parent->get_children();
array_unshift($children,$parent);
}
$children = $parent->get_children();
// Since the change for a category permission is greatest at the lower levels,.
// We scan in two stages, to focus the search more on the lower levels instead of diving deep into the first category.
// Stage one (surface check): check all children for the capability.

View File

@ -555,7 +555,12 @@ class studentstudyplanservice extends \external_api {
$userid = $USER->id;
\external_api::validate_context(\context_system::instance());
// Return empty list if coach role not enabled
if ( ! (premium::enabled() && \get_config("local_treestudyplan","enablecoach")) ) {
return [];
}
$records = $DB->get_records("local_treestudyplan_coach",["user_id" => $userid]);
$list = [];

View File

@ -636,7 +636,12 @@ class studyplan {
* @param bool|stdClass|null $user The userid or user record of the user Leave empty to check current user.
*/
public function is_coach($user=null) {
global $DB, $USER;
global $DB, $USER
;
if ( ! (premium::enabled() && \get_config("local_treestudyplan","enablecoach")) ) {
// If coach role is not available, return false immediately.
return false;
}
if($user == null) {
$user = $USER;
$userid = $USER->id;

View File

@ -39,6 +39,9 @@ $PAGE->set_heading(get_string('coaching_plans', 'local_treestudyplan'));
premium::require_premium();
if ( ! (\get_config("local_treestudyplan","enablecoach")) ) {
throw new \moodle_exception("error:coachdisabled","local_treestudyplan");
}
// Load javascripts and specific css.

View File

@ -114,7 +114,8 @@ $string["settingdesc_enableplansharing"] = 'Allow students to share access to th
$string["setting_limitcourselist"] = 'Limit course list to studyplan category';
$string["settingdesc_limitcourselist"] = 'Limit the list of available courses for a studyplan to the category the studyplan is located in.';
$string["setting_enablecoach"] = 'Enable coach rolae';
$string["settingdesc_enablecoach"] = 'The coach role allows one coach specific access to one studyplan with limited access to modify it.';
$string["setting_courseprogressbar"] = 'Show progress bar in course';
$string["settingdesc_courseprogressbar"] = 'Show a progress bar in the course popup';
@ -258,6 +259,7 @@ $string["studyplan_future"] = "Upcoming study plans";
$string["link_myreport"] = "My study plan";
$string["link_viewplan"] = "Study plans";
$string["link_editplan"] = "Manage study plans";
$string["link_coach"] = "Coaching studyplans";
$string["nav_invited"] = "View study plan by invitation";
$string["associations"] = 'Associations';
$string["associated_cohorts"] = 'Linked cohorts';
@ -476,6 +478,7 @@ $string["settingdesc_premium_key"] = 'Paste the premium key you received in the
$string["premiumfeature:morestudyplans"] = 'Creating more than 5 studyplans in a single category is a premium feature.';
$string["premiumfeature:morecategories"] = 'Creating studyplans in more than 20 categories is a premium feature.';
$string["premiumfeature:warning"] = 'The features on this page are only accessible if your site has premium features enabled.';
$string["error:coachdisabled"] = "The coach page has been disabled by the system administrator";
$string["overall"] = 'Course';
$string["studyplan_report"] = 'Studyplan result overview';
$string["overviewreport:all"] = 'Result overview';

View File

@ -115,6 +115,8 @@ $string["settingdesc_enableplansharing"] = 'Sta studenten toe om hun studieplann
$string["setting_limitcourselist"] = 'Cursusenlijst beperken tot categorie';
$string["settingdesc_limitcourselist"] = 'Beperk de lijst met beschikbare cursussen om in een studieplan te slepen tot de cateogrie waarin het studieplan zich bevindt.';
$string["setting_enablecoach"] = 'Coach rol inschakelen';
$string["settingdesc_enablecoach"] = 'Een coach kan aan een specifiek studieplan gekoppeld worden om deze te bewerken en studentresultaten te bekijken.';
$string["setting_courseprogressbar"] = 'Toon voortgangsbalk in cursus';
$string["settingdesc_courseprogressbar"] = 'Laat een voortgangsbalk zien in de cursuspopup';
@ -259,6 +261,7 @@ $string["studyplan_future"] = "Toekomstige studieplannen";
$string["link_myreport"] = "Mijn studieplan";
$string["link_viewplan"] = "Studieplannen";
$string["link_editplan"] = "Studieplannen beheren";
$string["link_coach"] = "Coach op studieplannen";
$string["nav_invited"] = "Studieplan op uitnodiging bekijken";
$string["associations"] = 'Koppelingen';
$string["associated_cohorts"] = 'Gekoppelde site-groepen';
@ -476,7 +479,8 @@ $string["settingdesc_premium_key"] = 'Premium activation key';
$string["premiumfeature:morestudyplans"] = 'Meer dan 5 studieplannen in één categorie aanmaken kan alleen met premium toegang.';
$string["premiumfeature:morecategories"] = 'In meer dan 20 categoriën een studieplan aanmaken kan alleen met premium toegang.';
$string["premiumfeature:warning"] = 'De fucnties in deze pagina kun je alleen gebruiken met premium toegang.';
$string["premiumfeature:warning"] = 'De functies in deze pagina kun je alleen gebruiken met premium toegang.';
$string["error:coachdisabled"] = "De coach functie is uitgeschakeld";
$string["overall"] = 'Cursus voltooid';
$string["studyplan_report"] = 'Studieplan resultatenoverzicht';
$string["overviewreport:all"] = 'Resultatenoverzicht';

27
lib.php
View File

@ -24,6 +24,7 @@
require_once($CFG->dirroot.'/course/modlib.php');
use local_treestudyplan\local\helpers\webservicehelper;
use local_treestudyplan\premium;
use \local_treestudyplan\studyplan;
use local_treestudyplan\studyplanpage;
@ -55,6 +56,10 @@ function local_treestudyplan_autofill_customusermenuitems() {
"/local/treestudyplan/view-plan.php" => ["included" => false, "strkey" => "link_viewplan"],
"/local/treestudyplan/edit-plan.php" => ["included" => false, "strkey" => "link_editplan"],
];
if ((premium::enabled() && \get_config("local_treestudyplan","enablecoach"))) {
// Also include the coach role if enabled
$navitems["/local/treestudyplan/coach.php"] = ["included" => false, "strkey" => "link_coach"];
}
// Load the custom menu items from config.
$custommenuitems = get_config("core", "custommenuitems");
@ -98,7 +103,7 @@ function local_treestudyplan_autofill_customusermenuitems() {
* @param global_navigation $navigation Navigation object
*/
function local_treestudyplan_extend_navigation(global_navigation $navigation) {
global $CFG, $PAGE, $COURSE, $USER;
global $CFG, $PAGE, $COURSE, $USER, $DB;
$systemcontext = context_system::instance();
@ -193,10 +198,30 @@ function local_treestudyplan_extend_navigation(global_navigation $navigation) {
} else {
$hideprimaryhrefs[] = "/local/treestudyplan/edit-plan.php";
}
if ( (premium::enabled() && \get_config("local_treestudyplan","enablecoach")) &&
(has_capability('local/treestudyplan:coach', context_system::instance())
|| webservicehelper::has_capability_in_any_category('local/treestudyplan:coach')
) && $DB->count_records("local_treestudyplan_coach",["user_id" => $USER->id]) > 0
) {
$node = navigation_node::create(
get_string("link_coach", "local_treestudyplan"),
new moodle_url($CFG->wwwroot . "/local/treestudyplan/coach.php", array()),
global_navigation::TYPE_SYSTEM ,
null,
"local_treestudyplan_coach",
new pix_icon("viewplans", '', 'local_treestudyplan')
);
$node->showinflatnavigation = true;
$node->showinsecondarynavigation = true;
$navigation->add_node($node, 'mycourses');
} else {
$hideprimaryhrefs[] = "/local/treestudyplan/coach.php";
}
} else {
$hideprimaryhrefs[] = "/local/treestudyplan/myreport.php";
$hideprimaryhrefs[] = "/local/treestudyplan/edit-plan.php";
$hideprimaryhrefs[] = "/local/treestudyplan/view-plan.php";
$hideprimaryhrefs[] = "/local/treestudyplan/coach.php";
}
// Create invitenode node.
$invitenode = navigation_node::create(

View File

@ -119,6 +119,15 @@ if ($hassiteconfig) {
get_string('settingdesc_limitcourselist', 'local_treestudyplan'),
false,
));
if (premium::enabled()) {
//get_config("local_treestudyplan","enablecoach")
$page->add(new admin_setting_configcheckbox('local_treestudyplan/enablecoach',
get_string('setting_enablecoach', 'local_treestudyplan'),
get_string('settingdesc_enablecoach', 'local_treestudyplan'),
false,
));
}
$page->add(new admin_setting_configselect('local_treestudyplan/display_field',
get_string('setting_display_field', 'local_treestudyplan'),

View File

@ -22,7 +22,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->component = 'local_treestudyplan'; // Recommended since 2.0.2 (MDL-26035). Required since 3.0 (MDL-48494).
$plugin->version = 2024031000; // YYYYMMDDHH (year, month, day, iteration).
$plugin->version = 2024031002; // YYYYMMDDHH (year, month, day, iteration).
$plugin->requires = 2021051700; // YYYYMMDDHH (This is the release version for Moodle 3.11).
$plugin->release = "1.1.6";