From 8ca50adb6694780d8a638f335813faf2b09dbf5b Mon Sep 17 00:00:00 2001
From: tamaro
Date: Tue, 24 Mar 2026 18:57:08 +0100
Subject: [PATCH 01/12] WIP - redesign request.php
---
lang/de/local_lsf_unification.php | 2 +-
lang/en/local_lsf_unification.php | 2 +-
request.php | 127 ++++++------------
templates/courserequest/coursetable.mustache | 66 +++++++++
templates/courserequest/final.mustache | 32 +++++
templates/courserequest/helptext.mustache | 29 ++++
.../courserequest/request_handler.mustache | 44 ++++++
templates/first_overview.mustache | 78 ++++++-----
8 files changed, 259 insertions(+), 121 deletions(-)
create mode 100644 templates/courserequest/coursetable.mustache
create mode 100644 templates/courserequest/final.mustache
create mode 100644 templates/courserequest/helptext.mustache
create mode 100644 templates/courserequest/request_handler.mustache
diff --git a/lang/de/local_lsf_unification.php b/lang/de/local_lsf_unification.php
index fa85cf7..11d361d 100644
--- a/lang/de/local_lsf_unification.php
+++ b/lang/de/local_lsf_unification.php
@@ -27,7 +27,7 @@
$string['already_requested'] = 'Diesr Kurs wurde bereits angefragt. Der/die Lehrende muss erst die bestehende Anfrage beantworten, bevor neue Anfragen getätigt werden können.';
$string['answer_course_found'] = "Der zu beantragende Kurs befindet sich in der nachfolgenden Liste:";
$string['answer_course_in_lsf_and_visible'] = "Der zu beantragende Kurs befindet sich im HIS-LSF und Sie sind dort als Lehrende(r) eingetragen.";
-$string['answer_course_in_lsf_but_invisible'] = 'Der zu beantragende Kurs befindet sich im HIS-LSF und der Kurs wird oben nicht angezeigt, obwohl der Nutzer mit der Kennung {$a} als Lehrende(r) für den Kurs eingetragen ist.';
+$string['answer_course_in_lsf_but_invisible'] = 'Der zu beantragende Kurs befindet sich im HIS-LSF und der Kurs wird oben nicht angezeigt, obwohl der Lehrende für den Kurs eingetragen ist.';
$string['answer_goto_old_requestform'] = "Sie möchten eine Kursbeantragung ohne Übernahme der Daten aus dem HIS-LSF vornehmen.";
$string['answer_proxy_creation'] = "Der Kurs existiert im HIS-LSF und Sie möchten im Auftrag einer/s dort eingetragenen Lehrenden diesen Kurs erstellen.";
$string['answer_sent'] = 'Vielen Dank für das Verarbeiten dieser Anfrage. Ihre Entscheidung wird dem Anfragenden automatisch per Email mitgeteilt.';
diff --git a/lang/en/local_lsf_unification.php b/lang/en/local_lsf_unification.php
index daf6c3a..ebc807e 100644
--- a/lang/en/local_lsf_unification.php
+++ b/lang/en/local_lsf_unification.php
@@ -29,7 +29,7 @@
$string['already_requested'] = 'Sorry, this course was already requested and the teacher has to reply to this request before a new request can be issued';
$string['answer_course_found'] = "The following list contains the course I'm looking for:";
$string['answer_course_in_lsf_and_visible'] = "The course exists on the HIS-LSF platform and you are registered as a teacher for that course.";
-$string['answer_course_in_lsf_but_invisible'] = 'The course is not listed above, but exists on the HIS-LSF platform and {$a} is registered as a teacher for that course.';
+$string['answer_course_in_lsf_but_invisible'] = 'The course is not listed above, but exists on the HIS-LSF platform and the teacher is registered as a teacher for that course.';
$string['answer_goto_old_requestform'] = "None of the above apply and you are authorized to create this course in the Learnweb.";
$string['answer_proxy_creation'] = "The course exists on the HIS-LSF platform and you are authorized to create this course on behalf of a registered teacher.";
$string['answer_sent'] = 'Thank you for processing this request, your decision will be sent to the requester.';
diff --git a/request.php b/request.php
index 23f7fe0..3347311 100644
--- a/request.php
+++ b/request.php
@@ -102,48 +102,28 @@ function ($course) {
* @throws coding_exception
*/
function print_helptext(string $t, string|null $s = null): void {
- $answerstr = get_string('answer_' . $t, 'local_lsf_unification');
- $infostr = get_string('info_' . $t, 'local_lsf_unification', $s, true);
- echo "" . $answerstr . "
" . $infostr;
- echo "
" . get_string('back', 'local_lsf_unification') . "";
-}
-
-/**
- * Print the courses the user can see.
- * @return void
- * @throws coding_exception
- */
-function print_courseselection(): void {
- global $USER, $answer;
- echo "";
- echo "
" . get_string('back', 'local_lsf_unification') . "";
+ global $OUTPUT;
+ $mustachedata = [
+ 'answerstr' => get_string('answer_' . $t, 'local_lsf_unification'),
+ 'infostr' => get_string('info_' . $t, 'local_lsf_unification', $s),
+ ];
+ echo $OUTPUT->render_from_template('local_lsf_unification/courserequest/helptext', $mustachedata);
}
/**
* Print the course table for a teacher.
* @param string $teacher
- * @param string $appendix
* @return void
* @throws coding_exception
*/
-function print_coursetable(string $teacher, string $appendix = ""): void {
- echo "";
+function print_coursetable(string $teacher, array $options = []): void {
+ global $OUTPUT, $answer;
+ $mustachedata = [
+ 'courses' => array_values(get_teachers_course_list($teacher, true)),
+ 'answer' => $answer,
+ ];
+ $mustachedata = array_merge($mustachedata, $options);
+ echo $OUTPUT->render_from_template('local_lsf_unification/courserequest/coursetable', $mustachedata);
}
/**
@@ -153,20 +133,12 @@ function print_coursetable(string $teacher, string $appendix = ""): void {
*/
function print_final() {
global $OUTPUT, $CFG, $courseid;
- $nextsteps = get_string('next_steps', 'local_lsf_unification');
- $linktext = [
- 'users' => get_string('linktext_users', 'local_lsf_unification'),
- 'content' => get_string('linktext_content', 'local_lsf_unification'),
- 'course' => get_string('linktext_course', 'local_lsf_unification'),
- ];
- $href = [
- 0 => $CFG->wwwroot . "/user/index.php?id=" . ($courseid),
- 1 => $CFG->wwwroot . "/backup/import.php?id=" . ($courseid),
- 2 => $CFG->wwwroot . "/course/view.php?id=" . ($courseid),
+ $mustachedata = [
+ 'userlink' => new moodle_url("/user/index.php", ['id' => $courseid]),
+ 'backuplink' => new moodle_url("/backup/import.php", ['id' => $courseid]),
+ 'courselink' => new moodle_url("/course/view.php", ['id' => $courseid]),
];
- echo $OUTPUT->box("" . $nextsteps . ":
" . $linktext['users'] . "
- " . $linktext['content'] . "
- " . $linktext['course'] . "
");
+ echo $OUTPUT->render_from_template('local_lsf_unification/courserequest/final', $mustachedata);
}
@@ -177,32 +149,18 @@ function print_final() {
* @throws dml_exception
*/
function print_remote_creation() {
- global $USER, $answer, $teachername, $veranstid;
+ global $teachername, $veranstid;
if (!get_config('local_lsf_unification', 'remote_creation')) {
return;
}
if (empty($veranstid)) {
- echo "
" . $back . "";
+ $mustachedata = [
+ 'emptyteacher' => empty($teachername),
+ 'remote' => true,
+ 'teachername' => $teachername,
+ 'appendix' => true,
+ ];
+ print_coursetable($teachername, $mustachedata);
} else {
if ($veranstid < 0) {
echo get_string('his_info', 'local_lsf_unification');
@@ -275,7 +233,7 @@ function print_coursecreation() {
$warnings = get_string('warnings', 'local_lsf_unification');
$out = "" . $OUTPUT->box("" . $warnings . "
" . "
" . $result["warnings"] . "") . "
";
echo (!empty($result["warnings"])) ? $out : "";
- print_final($result["course"]->id);
+ print_final();
} else {
$editform->display();
}
@@ -288,21 +246,18 @@ function print_coursecreation() {
* @throws dml_exception
*/
function print_request_handler() {
- global $CFG, $DB, $answer, $request, $veranstid, $accept;
+ global $DB, $answer, $request, $veranstid, $accept, $OUTPUT;
$course = get_course_by_veranstid($veranstid);
$requester = $DB->get_record("user", ["id" => $request->requesterid]);
- if (empty($accept)) {
- echo get_string('remote_request_select_alternative', 'local_lsf_unification');
- $params = new stdClass();
- $params->a = $requester->firstname . " " . $requester->lastname;
- $params->b = mb_convert_encoding($course->titel, 'UTF-8', 'ISO-8859-1');
- $href = $CFG->wwwroot . "/local/lsf_unification/request.php?answer=" . $answer . "&requestid=" . $request->id;
- $remoteaccept = get_string('remote_request_accept', 'local_lsf_unification', $params);
- $remotedeclined = get_string('remote_request_decline', 'local_lsf_unification', $params);
- echo '' .
- "" . $remoteaccept . "" . "
";
- echo "" . $remotedeclined . "" . "
";
- } else {
+ $basepath = '/local/lsf_unification/request.php';
+ $mustachedata = [
+ 'emptyaccept' => empty($accept),
+ 'link1' => new moodle_url($basepath, ['answer' => $answer, 'requestid' => $request->id, 'accept' => 1]),
+ 'link2' => new moodle_url($basepath, ['answer' => $answer, 'requestid' => $request->id, 'accept' => 2]),
+ 'param_a' => $requester->firstname . " " . $requester->lastname,
+ 'param_b' => mb_convert_encoding($course->titel, 'UTF-8', 'ISO-8859-1'),
+ ];
+ if (!empty($accept)) {
if ($accept == 1) {
set_course_accepted($veranstid);
send_course_creation_mail($requester, $course);
@@ -310,19 +265,17 @@ function print_request_handler() {
set_course_declined($veranstid);
send_sorry_mail($requester, $course);
}
- echo get_string('answer_sent', 'local_lsf_unification');
}
+ echo $OUTPUT->render_from_template('local_lsf_unification/courserequest/request_handler', $mustachedata);
}
-
// Handle Course-Request.
-
if (establish_secondary_DB_connection() === true) {
if (empty($answer)) {
print_first_overview(); // Task Selection.
} else if ($answer == 1) {
if (empty($veranstid)) {
- print_courseselection(); // Extern Course Selection.
+ print_coursetable($USER->username);
} else {
if (has_course_import_rights($veranstid, $USER)) { // Validate veranstid, user.
print_coursecreation(); // Request neccessary details and create course.
diff --git a/templates/courserequest/coursetable.mustache b/templates/courserequest/coursetable.mustache
new file mode 100644
index 0000000..0400c51
--- /dev/null
+++ b/templates/courserequest/coursetable.mustache
@@ -0,0 +1,66 @@
+{{!
+ This file is part of Moodle - http://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 .
+}}
+{{!
+ @template local_lsf_unification/courserequest/coursetable
+
+ This template is part of the page to request a new course.
+
+ Example (json):
+ {
+
+ }
+}}
+
+
+{{#str}} back, local_lsf_unification {{/str}}
diff --git a/templates/courserequest/final.mustache b/templates/courserequest/final.mustache
new file mode 100644
index 0000000..070de79
--- /dev/null
+++ b/templates/courserequest/final.mustache
@@ -0,0 +1,32 @@
+{{!
+ This file is part of Moodle - http://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 .
+}}
+{{!
+ @template local_lsf_unification/courserequest/final
+
+ This template is part of the page to request a new course.
+
+ Example (json):
+ {
+
+ }
+}}
+
diff --git a/templates/courserequest/helptext.mustache b/templates/courserequest/helptext.mustache
new file mode 100644
index 0000000..ad07578
--- /dev/null
+++ b/templates/courserequest/helptext.mustache
@@ -0,0 +1,29 @@
+{{!
+ This file is part of Moodle - http://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 .
+}}
+{{!
+ @template local_lsf_unification/courserequest/helptext
+
+ This template is part of the page to request a new course.
+
+ Example (json):
+ {
+
+ }
+}}
+{{answerstr}}
+{{{infostr}}}
+{{#str}} back, local_lsf_unification {{/str}}
\ No newline at end of file
diff --git a/templates/courserequest/request_handler.mustache b/templates/courserequest/request_handler.mustache
new file mode 100644
index 0000000..0d40d81
--- /dev/null
+++ b/templates/courserequest/request_handler.mustache
@@ -0,0 +1,44 @@
+{{!
+ This file is part of Moodle - http://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 .
+}}
+{{!
+ @template local_lsf_unification/courserequest/request_handler
+
+ This template is part of the page to request a new course.
+
+ Example (json):
+ {
+
+ }
+}}
+{{#empty_accept}}
+ {{#str}} remote_request_select_alternative, local_lsf_unification {{/str}}
+
+ {{#str}} remote_request_accept, local_lsf_unification,
+ {"a": {{#quote}}{{param_a}}{{/quote}}, "b": {{#quote}}{{param_b}}{{/quote}} }
+ {{/str}}
+
+
+
+ {{#str}} remote_request_decline, local_lsf_unification,
+ {"a": {{#quote}}{{param_a}}{{/quote}}, "b": {{#quote}}{{param_b}}{{/quote}} }
+ {{/str}}
+
+
+{{/empty_accept}}
+{{^empty_accept}}
+ {{#str}} answer_sent, local_lsf_unification {{/str}}
+{{/empty_accept}}
\ No newline at end of file
diff --git a/templates/first_overview.mustache b/templates/first_overview.mustache
index dee4323..399780a 100644
--- a/templates/first_overview.mustache
+++ b/templates/first_overview.mustache
@@ -36,39 +36,53 @@
}}
{{#str}} notice, local_lsf_unification {{/str}}
+