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,58 +51,76 @@ if (!empty($sent)) {
}; };
print $OUTPUT->header(); if (!get_config("local_treestudyplan","enableplansharing")) {
$PAGE->set_title(get_string('accessdenied', 'admin'));
$PAGE->set_heading(get_string('accessdenied', 'admin'));
print "<p>".get_string('invite_description', 'local_treestudyplan')."</p>"; print $OUTPUT->header();
$invites = $DB->get_records('local_treestudyplan_invit', array('user_id' => $USER->id)); // Render page for skill level 0 (global).
print "<h3>".get_string('invite_tablecaption', 'local_treestudyplan')."</h3>"; print "<div class='box errorbox alert alert-danger'>";
print "<table class='m-manage_invites'>"; print get_string('accessdenied','admin');
print "<thead>"; print "</div>";
print "<th>".get_string('invite_name', 'local_treestudyplan')."</th>";
print "<th>".get_string('invite_email', 'local_treestudyplan')."</th>";
print "<th>".get_string('invite_date', 'local_treestudyplan')."</th>";
print "<th>&nbsp;</th>";
print "</thead>";
print "<tbody>"; print $OUTPUT->footer();
if (count($invites) > 0) {
foreach ($invites as $invite) {
$testlink = $invitedurl."?key={$invite->invitekey}";
print "<tr data-id='{$invite->id}'>";
print "<td data-field='name'>{$invite->name}</td>";
print "<td data-field='email'>{$invite->email}</td>";
print "<td data-field='date'>".userdate($invite->idate, "%x")."</td>";
print "<td data-field='control'>";
print "<a class='m-action-view ' href='{$testlink}' title='" exit;
.get_string('invite_tooltip_testlink', 'local_treestudyplan')."'><i class='fa fa-eye'></i></a>";
print "<a class='m-action-resend m-action-confirm'";
print " data-confirmtext='".get_string('invite_confirm_resend', 'local_treestudyplan', $invite->name)."'";
print " data-confirmbtn='".get_string('send', 'local_treestudyplan')."'";
print " href='#' data-actionhref='edit-invite.php?resend={$invite->id}' title='"
.get_string('invite_tooltip_resend', 'local_treestudyplan')."'";
print " ><i class='fa fa-envelope'></i></a>";
print "<a href='edit-invite.php?update={$invite->id}'><i class='fa fa-pencil' title='"
.get_string('invite_tooltip_edit', 'local_treestudyplan')."'></i></a>";
print "<a class='m-action-delete m-action-confirm'";
print " data-confirmtext='".get_string('invite_confirm_delete', 'local_treestudyplan', $invite->name)."'";
print " data-confirmbtn='".get_string('delete')."'";
print " href='#' data-actionhref='edit-invite.php?delete={$invite->id}' title='"
.get_string('invite_tooltip_delete', 'local_treestudyplan')."'";
print " ><i class='fa fa-trash'></i></a>";
print "</td>";
}
} else { } else {
print "<tr><td colspan='6'>".get_string('invite_table_empty', 'local_treestudyplan')."</td></tr>";
}
print "</tbody></table>";
print "<a class='btn btn-info' href='/local/treestudyplan/edit-invite.php?add=true' class='btn btn-primary' id='add_invite'>"; print $OUTPUT->header();
print "<i class='fa fa-plus'></i> ".get_string('invite_button_new', 'local_treestudyplan')."</a>";
print $OUTPUT->footer(); print "<p>".get_string('invite_description', 'local_treestudyplan')."</p>";
$invites = $DB->get_records('local_treestudyplan_invit', array('user_id' => $USER->id));
print "<h3>".get_string('invite_tablecaption', 'local_treestudyplan')."</h3>";
print "<table class='m-manage_invites'>";
print "<thead>";
print "<th>".get_string('invite_name', 'local_treestudyplan')."</th>";
print "<th>".get_string('invite_email', 'local_treestudyplan')."</th>";
print "<th>".get_string('invite_date', 'local_treestudyplan')."</th>";
print "<th>&nbsp;</th>";
print "</thead>";
print "<tbody>";
if (count($invites) > 0) {
foreach ($invites as $invite) {
$testlink = $invitedurl."?key={$invite->invitekey}";
print "<tr data-id='{$invite->id}'>";
print "<td data-field='name'>{$invite->name}</td>";
print "<td data-field='email'>{$invite->email}</td>";
print "<td data-field='date'>".userdate($invite->idate, "%x")."</td>";
print "<td data-field='control'>";
print "<a class='m-action-view ' href='{$testlink}' title='"
.get_string('invite_tooltip_testlink', 'local_treestudyplan')."'><i class='fa fa-eye'></i></a>";
print "<a class='m-action-resend m-action-confirm'";
print " data-confirmtext='".get_string('invite_confirm_resend', 'local_treestudyplan', $invite->name)."'";
print " data-confirmbtn='".get_string('send', 'local_treestudyplan')."'";
print " href='#' data-actionhref='edit-invite.php?resend={$invite->id}' title='"
.get_string('invite_tooltip_resend', 'local_treestudyplan')."'";
print " ><i class='fa fa-envelope'></i></a>";
print "<a href='edit-invite.php?update={$invite->id}'><i class='fa fa-pencil' title='"
.get_string('invite_tooltip_edit', 'local_treestudyplan')."'></i></a>";
print "<a class='m-action-delete m-action-confirm'";
print " data-confirmtext='".get_string('invite_confirm_delete', 'local_treestudyplan', $invite->name)."'";
print " data-confirmbtn='".get_string('delete')."'";
print " href='#' data-actionhref='edit-invite.php?delete={$invite->id}' title='"
.get_string('invite_tooltip_delete', 'local_treestudyplan')."'";
print " ><i class='fa fa-trash'></i></a>";
print "</td>";
}
} else {
print "<tr><td colspan='6'>".get_string('invite_table_empty', 'local_treestudyplan')."</td></tr>";
}
print "</tbody></table>";
print "<a class='btn btn-info' href='/local/treestudyplan/edit-invite.php?add=true' class='btn btn-primary' id='add_invite'>";
print "<i class='fa fa-plus'></i> ".get_string('invite_button_new', 'local_treestudyplan')."</a>";
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'));