Finished enable/disable setting for studyplan sharing

This commit is contained in:
PMKuipers 2023-12-11 23:57:56 +01:00
parent f6b53a1623
commit 43c0af4730
3 changed files with 93 additions and 50 deletions

View File

@ -198,6 +198,10 @@ class studentstudyplanservice extends \external_api {
*/ */
public static function list_invited_studyplans($invitekey) { public static function list_invited_studyplans($invitekey) {
global $DB; global $DB;
// First check if studyplan sharing is enabled.
if (!get_config("local_treestudyplan","enableplansharing")) {
return [];
}
$invite = $DB->get_record_select( $invite = $DB->get_record_select(
"local_treestudyplan_invit", "local_treestudyplan_invit",
@ -252,7 +256,10 @@ class studentstudyplanservice extends \external_api {
*/ */
public static function get_invited_studyplan($invitekey,$studyplanid) { public static function get_invited_studyplan($invitekey,$studyplanid) {
global $DB; global $DB;
// First check if studyplan sharing is enabled.
if (!get_config("local_treestudyplan","enableplansharing")) {
return [];
}
$invite = $DB->get_record_select( $invite = $DB->get_record_select(
"local_treestudyplan_invit", "local_treestudyplan_invit",
$DB->sql_compare_text("invitekey"). " = " . $DB->sql_compare_text(":invitekey"), $DB->sql_compare_text("invitekey"). " = " . $DB->sql_compare_text(":invitekey"),
@ -306,7 +313,10 @@ class studentstudyplanservice extends \external_api {
*/ */
public static function get_invited_page($invitekey,$pageid) { public static function get_invited_page($invitekey,$pageid) {
global $DB; global $DB;
// First check if studyplan sharing is enabled.
if (!get_config("local_treestudyplan","enableplansharing")) {
return [];
}
$invite = $DB->get_record_select( $invite = $DB->get_record_select(
"local_treestudyplan_invit", "local_treestudyplan_invit",
$DB->sql_compare_text("invitekey"). " = " . $DB->sql_compare_text(":invitekey"), $DB->sql_compare_text("invitekey"). " = " . $DB->sql_compare_text(":invitekey"),

View File

@ -51,6 +51,23 @@ if (!empty($sent)) {
}; };
if (!get_config("local_treestudyplan","enableplansharing")) {
$PAGE->set_title(get_string('accessdenied', 'admin'));
$PAGE->set_heading(get_string('accessdenied', 'admin'));
print $OUTPUT->header();
// Render page for skill level 0 (global).
print "<div class='box errorbox alert alert-danger'>";
print get_string('accessdenied','admin');
print "</div>";
print $OUTPUT->footer();
exit;
} else {
print $OUTPUT->header(); print $OUTPUT->header();
print "<p>".get_string('invite_description', 'local_treestudyplan')."</p>"; print "<p>".get_string('invite_description', 'local_treestudyplan')."</p>";
@ -106,3 +123,4 @@ print "<a class='btn btn-info' href='/local/treestudyplan/edit-invite.php?add=tr
print "<i class='fa fa-plus'></i> ".get_string('invite_button_new', 'local_treestudyplan')."</a>"; print "<i class='fa fa-plus'></i> ".get_string('invite_button_new', 'local_treestudyplan')."</a>";
print $OUTPUT->footer(); print $OUTPUT->footer();
}

View File

@ -47,7 +47,22 @@ $invite = $DB->get_record_select("local_treestudyplan_invit",
$DB->sql_compare_text("invitekey"). " = " . $DB->sql_compare_text(":invitekey"), $DB->sql_compare_text("invitekey"). " = " . $DB->sql_compare_text(":invitekey"),
['invitekey' => $invitekey]); ['invitekey' => $invitekey]);
if (empty($invite)) { if (!get_config("local_treestudyplan","enableplansharing")) {
$PAGE->set_title(get_string('accessdenied', 'admin'));
$PAGE->set_heading(get_string('accessdenied', 'admin'));
print $OUTPUT->header();
// Render page for skill level 0 (global).
print "<div class='box errorbox alert alert-danger'>";
print get_string('accessdenied','admin');
print "</div>";
print $OUTPUT->footer();
exit;
} else if (empty($invite)) {
$PAGE->set_title(get_string('invalid_invitekey_title', 'local_treestudyplan')); $PAGE->set_title(get_string('invalid_invitekey_title', 'local_treestudyplan'));
$PAGE->set_heading(get_string('invalid_invitekey_title', 'local_treestudyplan')); $PAGE->set_heading(get_string('invalid_invitekey_title', 'local_treestudyplan'));