Converted invitation pages to mustache instead of html in php

This commit is contained in:
PMKuipers 2024-12-30 16:02:41 +01:00
parent 4c556ba402
commit c64b7f765f
8 changed files with 206 additions and 96 deletions

View file

@ -22,12 +22,9 @@
*/
require_once("../../config.php");
require_once($CFG->libdir.'/weblib.php');
require_once($CFG->dirroot.'/grade/querylib.php');
$invitedurl = "{$CFG->wwwroot}/local/treestudyplan/invited.php";
$systemcontext = context_system::instance();
$PAGE->set_url("/local/treestudyplan/invitations.php", []);
@ -46,7 +43,6 @@ $sent = optional_param('sent', '', PARAM_INT);
if (!empty($sent)) {
$invite = $DB->get_record('local_treestudyplan_invit', ['id' => $sent]);
\core\notification::success(get_string('invite_resent_msg', 'local_treestudyplan', $invite));
};
if (!get_config("local_treestudyplan", "enableplansharing")) {
@ -54,71 +50,22 @@ if (!get_config("local_treestudyplan", "enableplansharing")) {
$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->render_from_template('local_treestudyplan/error', [
"title" => get_string('accessdenied', 'admin'),
"message" => get_string('error:invitationsdisabled', 'local_treestudyplan'),
]);
print $OUTPUT->footer();
exit;
exit; // Just in case some code is added after this if statement erroneously later.
} else {
print $OUTPUT->header();
print "<p>".get_string('invite_description', 'local_treestudyplan')."</p>";
$invites = $DB->get_records('local_treestudyplan_invit', ['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='{$CFG->wwwroot}/local/treestudyplan/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='{$CFG->wwwroot}/local/treestudyplan/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='{$CFG->wwwroot}/local/treestudyplan/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='{$CFG->wwwroot}/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>";
$data = [
"invites" => array_values($invites),
"hasinvites" => boolval(count($invites) > 0),
"invitedurl" => "{$CFG->wwwroot}/local/treestudyplan/invited.php",
];
print $OUTPUT->render_from_template('local_treestudyplan/invitations', $data);
print $OUTPUT->footer();
}

View file

@ -52,13 +52,10 @@ if (!get_config("local_treestudyplan", "enableplansharing")) {
$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->render_from_template('local_treestudyplan/error', [
"title" => get_string('accessdenied', 'admin'),
"message" => get_string('error:invitationsdisabled', 'local_treestudyplan'),
]);
print $OUTPUT->footer();
exit;
@ -67,13 +64,9 @@ if (!get_config("local_treestudyplan", "enableplansharing")) {
$PAGE->set_heading(get_string('invalid_invitekey_title', 'local_treestudyplan'));
print $OUTPUT->header();
// Render page for skill level 0 (global).
print "<div class='box errorbox alert alert-danger'>";
print get_string('invalid_invitekey_error', 'local_treestudyplan');
print "</div>";
print $OUTPUT->render_from_template('local_treestudyplan/error', [
"message" => get_string('error:invalid_invitekey', 'local_treestudyplan'),
]);
print $OUTPUT->footer();
exit;
@ -90,18 +83,6 @@ if (!get_config("local_treestudyplan", "enableplansharing")) {
$PAGE->set_heading(get_string('report_invited', 'local_treestudyplan', "{$student->firstname} {$student->lastname}"));
print $OUTPUT->header();
print "
<div id='root'>
<div class='vue-loader' v-show='false'>
<div class='spinner-border text-primary' role='status'>
<span class='sr-only'>Loading...</span>
</div>
</div>
<div v-cloak>
<r-report type='invited' :invitekey='invitekey'></r-report>
</div>
</div>
";
print $OUTPUT->render_from_template('local_treestudyplan/invited', []);
print $OUTPUT->footer();
}

View file

@ -64,7 +64,7 @@ $string["report_index"] = 'View student progress reports';
$string["manage_invites"] = 'Share study plan access';
$string["share_report"] = 'Share';
$string["invalid_invitekey_title"] = "Invite key required";
$string["invalid_invitekey_error"] = "You need an invitation to view data via this portal";
$string["error:invalid_invitekey"] = "You need an invitation to view data via this portal";
$string["invite_description"] = "You can invite your parents or guardians to view your results. Those who receive your sharing link can view your grades until you revoke the invite";
$string["invite_tablecaption"] = "Active invites";
$string["invite_table_empty"] = "No active invites";
@ -518,8 +518,9 @@ $string["error:nostudyplanviewaccess"] = 'Error: You do not have access to view
$string["error:nostudyplaneditaccess"] = 'Error: You do not have access to manage study plans in this category or context: {$a}';
$string["error:nocategoriesvisible"] = 'Error: You have no viewing permissions in any category. Therefore the course list remains empty.';
$string["error:usernotassociated"] = 'Error: Requested student is not associated with this studyplan';
$string["error:invitationsdisabled"] = "Sharing studyplans with 3rd parties has been disabled on this site.";
$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

@ -64,7 +64,7 @@ $string["report_index"] = 'Studieplannen van studenten inzien';
$string["manage_invites"] = 'Studieplan delen';
$string["share_report"] = 'Delen';
$string["invalid_invitekey_title"] = "Uitnodiging vereist";
$string["invalid_invitekey_error"] = "Je moet een uitnodiging hebben om via deze portal informatie te bekijken";
$string["error:invalid_invitekey"] = "Je moet een uitnodiging hebben om via deze portal informatie te bekijken";
$string["invite_description"] = "Je kunt je ouders/verzorgers een uitnodiging sturen waarmee je live inzage in jouw studieplan en voortgang met ze deelt. Degene die de uitnodiging krijgt kan jouw studieplan inzien totdat je de uitnodiging weer intrekt.";
$string["invite_tablecaption"] = "Actieve uitnodigingen";
$string["invite_table_empty"] = "Geen openstaande uitnodigingen";
@ -518,8 +518,9 @@ $string["error:nostudyplanviewaccess"] = 'Fout: Je hebt geen rechten om studiepl
$string["error:nostudyplaneditaccess"] = 'Fout: Je hebt geen rechten om studieplannen in deze categorie of context te beheren: {$a}';
$string["error:nocategoriesvisible"] = 'Fout: Je kunt geen cursussen in een categorie bekijken. Daarom blijft de cursuslijst leeg';
$string["error:usernotassociated"] = 'Fout: De gevraagde student is niet gekoppeld aan dit studieplan';
$string["error:invitationsdisabled"] = "De optie om een studieplan te kunnen delen is uitgeschakeld op deze site.";
$string["error:coachdisabled"] = "De coach functie is uitgeschakeld";
$string["overall"] = 'Cursus voltooid';
$string["studyplan_report"] = 'Studieplan resultatenoverzicht';
$string["overviewreport:all"] = 'Resultatenoverzicht';

44
templates/error.mustache Normal file
View file

@ -0,0 +1,44 @@
{{!
This file is part of Moodle - https://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template local_treestudyplan/error
Template for error messages like access denied
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* none
Example context (json):
{
"title": "test",
"message": "detailed html message",
}
}}
<div class='local_treestudyplan_error box errorbox alert alert-danger'>
{{#title}}
<h3>{{title}}</h3>
{{/title}}
{{#message}}
{{message}}
{{/message}}
</div>

View file

@ -1,5 +1,5 @@
{{!
@template local_treestudyplan/element_text_integer
@template local_treestudyplan/form/element_text_integer
Template for integer only field

View file

@ -0,0 +1,92 @@
{{!
This file is part of Moodle - https://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template local_treestudyplan/invitations
Template for rendering the invitations page
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* none
Example context (json):
{
"invites": array_values($DB->get_records('local_treestudyplan_invit', ['user_id' => $USER->id]));
"hasinvites": true,
}
}}
<div class="local_treestudyplan_invitations">
<p>{{#str}} invite_description, local_treestudyplan {{/str}}</p>
<h3>{{#str}} invite_tablecaption, local_treestudyplan {{/str}}</h3>
<table class='m-manage_invites'>
<thead>
<th>&nbsp;{{#str}} invite_name, local_treestudyplan {{/str}} </th>
<th> {{#str}} invite_email, local_treestudyplan {{/str}} </th>
<th> {{#str}} invite_date, local_treestudyplan {{/str}} </th>
<th>&nbsp;</th>
</thead>
<tbody>
{{#hasinvites}}
{{#invites}}
<tr data-id='{{.id}}'>
<td data-field='name'>{{name}}</td>
<td data-field='email'>{{email}}</td>
<td data-field='date'>{{#userdate}} {{idate}}, %x {{/userdate}}</td>
<td data-field='control'>
<a class='m-action-view '
href='{{globals.config.wwwroot}}/local/treestudyplan/invited.php?key={{invitekey}}'
title='{{#str}} invite_tooltip_testlink, local_treestudyplan {{/str}}'
><i class='fa fa-eye'></i></a>
<a class='m-action-resend m-action-confirm'
data-confirmtext='{{#str}} invite_confirm_resend, local_treestudyplan {{/str}}'
data-confirmbtn='{{#str}} send, local_treestudyplan {{/str}}'
href='#'
data-actionhref='{{globals.config.wwwroot}}/local/treestudyplan/edit-invite.php?resend={{id}}'
title='{{#str}} invite_tooltip_resend, local_treestudyplan {{/str}}'
><i class='fa fa-envelope'></i></a>
<a href='{{globals.config.wwwroot}}/local/treestudyplan/edit-invite.php?update={{id}}'
><i class='fa fa-pencil' title='{{#str}} invite_tooltip_edit, local_treestudyplan {{/str}}'></i></a>
<a class='m-action-delete m-action-confirm'
data-confirmtext='{{#str}} invite_confirm_delete, local_treestudyplan, {{name}} {{/str}}'
data-confirmbtn='{{#str}} delete, core {{/str}}'
href='#' data-actionhref='{{globals.config.wwwroot}}/local/treestudyplan/edit-invite.php?delete={{id}}'
title='{{#str}} invite_tooltip_delete, local_treestudyplan {{/str}}'
><i class='fa fa-trash'></i></a>
</td>
</tr>
{{/invites}}
{{/hasinvites}}
{{^hasinvites}}
<tr><td colspan='6'>{{#str}} invite_table_empty, local_treestudyplan {{/str}}</td></tr>
{{/hasinvites}}
</tbody>
</table>
<a class='btn btn-info'
href='{{globals.config.wwwroot}}/local/treestudyplan/edit-invite.php?add=true' class='btn btn-primary' id='add_invite'>
<i class='fa fa-plus'></i> {{#str}} invite_button_new, local_treestudyplan {{/str}}
</a>
</div>

View file

@ -0,0 +1,44 @@
{{!
This file is part of Moodle - https://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template local_treestudyplan/invitations
Template for rendering the invitations page
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* none
Example context (json):
{
}
}}
<div id="root" class="local_treestudyplan_invited">
<div class='vue-loader' v-show='false'>
<div class='spinner-border text-primary' role='status'>
<span class='sr-only'>Loading...</span>
</div>
</div>
<div v-cloak>
<r-report type='invited' :invitekey='invitekey'></r-report>
</div>
</div>