diff --git a/classes/local/helpers/webservicehelper.php b/classes/local/helpers/webservicehelper.php index 3fbf140..119c288 100644 --- a/classes/local/helpers/webservicehelper.php +++ b/classes/local/helpers/webservicehelper.php @@ -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. diff --git a/classes/studentstudyplanservice.php b/classes/studentstudyplanservice.php index ccbba88..9ad7359 100644 --- a/classes/studentstudyplanservice.php +++ b/classes/studentstudyplanservice.php @@ -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 = []; diff --git a/classes/studyplan.php b/classes/studyplan.php index 5c0e1c5..d73cef4 100644 --- a/classes/studyplan.php +++ b/classes/studyplan.php @@ -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; diff --git a/coach.php b/coach.php index 3f47910..9f5a15a 100644 --- a/coach.php +++ b/coach.php @@ -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. diff --git a/lang/en/local_treestudyplan.php b/lang/en/local_treestudyplan.php index 579377a..c9ac5d4 100644 --- a/lang/en/local_treestudyplan.php +++ b/lang/en/local_treestudyplan.php @@ -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'; diff --git a/lang/nl/local_treestudyplan.php b/lang/nl/local_treestudyplan.php index 66946f6..ce59d49 100644 --- a/lang/nl/local_treestudyplan.php +++ b/lang/nl/local_treestudyplan.php @@ -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'; diff --git a/lib.php b/lib.php index 905725b..94faf87 100644 --- a/lib.php +++ b/lib.php @@ -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( diff --git a/settings.php b/settings.php index 7f675d6..df0c156 100644 --- a/settings.php +++ b/settings.php @@ -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'), diff --git a/version.php b/version.php index 908a389..36d423b 100644 --- a/version.php +++ b/version.php @@ -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";