diff --git a/coach.php b/coach.php index 62a0f13..0c0d095 100644 --- a/coach.php +++ b/coach.php @@ -48,84 +48,5 @@ if ($CFG->debugdeveloper) { $PAGE->requires->js_call_amd('local_treestudyplan/page-coach', 'init', []); print $OUTPUT->header(); -$text = (object)[ - 'studyplan_select' => get_string("studyplan_select", 'local_treestudyplan'), - 'coacheditmode' => get_string("coacheditmode", 'local_treestudyplan'), - 'showoverview' => get_string("showoverview", 'local_treestudyplan'), - 'studyplan_noneselected' => get_string("studyplan_noneselected", 'local_treestudyplan'), - 'selectstudent_btn' => get_string('selectstudent_btn', 'local_treestudyplan'), - 'back' => get_string('back', 'local_treestudyplan'), -]; - -print << -
-
- Loading... -
-
-
-
- -
-
-

{{selectedstudent.firstname}} {{selectedstudent.lastname}} - {{displayedstudyplan.name}}

-

{$text->showoverview} - {{displayedstudyplan.name}}

- -
- Loading... -
-
-

{$text->studyplan_noneselected}

- - - -
-
-
- -END; - +print $OUTPUT->render_from_template('local_treestudyplan/edit_plan', []); print $OUTPUT->footer(); diff --git a/edit-plan.php b/edit-plan.php index 9e8cd15..bb5cec5 100644 --- a/edit-plan.php +++ b/edit-plan.php @@ -40,9 +40,14 @@ $categoryid = optional_param('categoryid', 0, PARAM_INT); // Category id. $contextid = optional_param('contextid', 0, PARAM_INT); // Context id. if ($categoryid > 0) { $studyplancontext = context_coursecat::instance($categoryid); - + if (!is_object($studyplancontext)) { + $studyplancontext = $systemcontext; + } } else if ($contextid > 0) { $studyplancontext = context::instance_by_id($contextid); + if (!is_object($studyplancontext)) { + $studyplancontext = $systemcontext; + } if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT])) { $categoryid = $studyplancontext->instanceid; } else { @@ -79,7 +84,7 @@ if ($studyplancontext->id > 1) { $cat = \core_course_category::top(); } -if (!$cat->is_uservisible()) { +if (!is_object($cat) || !$cat->is_uservisible()) { throw new \moodle_exception( "error:cannotviewcategory", @@ -108,110 +113,5 @@ $PAGE->requires->js_call_amd('local_treestudyplan/page-edit-plan', 'init', [$stu ]]); print $OUTPUT->header(); -$text = (object)[ - 'loading' => get_string("loading", "core"), - 'studyplan_select' => get_string("studyplan_select", 'local_treestudyplan'), - 'studyplan_noneselected' => get_string("studyplan_noneselected", 'local_treestudyplan'), - 'defaultaggregation' => get_config("local_treestudyplan", "aggregation_mode"), - 'back' => get_string('back', 'local_treestudyplan'), -]; - -print << -
-
- Loading... -
-
-
-
- - - {$text->loading}... - / {{ p }} ({{ ctx.studyplancount }}) - - -
- -
-

{$contextname}

-
- {$text->back} - {$text->studyplan_select}  - - {{ studyplan.name }} -   - -
- -
- -
- Loading... -
-
-

{$text->studyplan_noneselected}

- - - - - -
-
-
- -END; +print $OUTPUT->render_from_template('local_treestudyplan/edit_plan', ["contextname" => $contextname]); print $OUTPUT->footer(); diff --git a/myreport.php b/myreport.php index b49b0db..4f95aed 100644 --- a/myreport.php +++ b/myreport.php @@ -55,29 +55,9 @@ if ($CFG->debugdeveloper) { $PAGE->requires->js_call_amd('local_treestudyplan/page-myreport', 'init', [$amteaching ? 'teaching' : 'own']); print $OUTPUT->header(); - -print '
'; - -if (get_config("local_treestudyplan", "enableplansharing") && !$amteaching) { - print ''; - print '  '.get_string('manage_invites', 'local_treestudyplan').''; -} - -print "
"; -print "
"; -print "
"; -print "
"; -print " Loading..."; -print "
"; -print "
"; -print "
"; -if ($amteaching) { - print " "; -} else { - print " "; - -} -print "
"; -print "
"; +$data = new \stdClass; +$data->enableplansharing = get_config("local_treestudyplan", "enableplansharing") && !$amteaching; +$data->teachermode = $amteaching; +print $OUTPUT->render_from_template('local_treestudyplan/myreport', $data); print $OUTPUT->footer(); diff --git a/result-overview.php b/result-overview.php index 34cc299..55d1e59 100644 --- a/result-overview.php +++ b/result-overview.php @@ -63,74 +63,13 @@ $PAGE->requires->js_call_amd( ); print $OUTPUT->header(); -print "

{$contextname} / {$studyplan->name()}

"; +$data = new \stdClass; // Use an object instead of an array to make next lines easier to read. +$data->contextname = $contextname; +$data->studyplanname = $studyplan->name(); if ($studyplan->name() != $page->fullname()) { - print "

{$page->fullname()}

"; + $data->pagename = $page->fullname(); } -print << -
-
- Loading... -
-
-
-
-
- Loading... -
-
- -
- -END; +print $OUTPUT->render_from_template('local_treestudyplan/result_overview', $data); + print $OUTPUT->footer(); diff --git a/templates/coach.mustache b/templates/coach.mustache new file mode 100644 index 0000000..29f830d --- /dev/null +++ b/templates/coach.mustache @@ -0,0 +1,105 @@ +{{! + 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 . +}} +{{! + @template local_treestudyplan/coach + + Template for rendering the coach page + + Classes required for JS: + * vue-loader + + Data attributes required for JS: + * none + + Context variables required for this template: + * none + + Example context (json): + { + "contextname": "System", + } +}} +{{! Next line replaces mustache double curly braces with << and >> for this template, +so it does not mess up vue double curly braces}} +{{= << >> =}} +
+
+
+ Loading... +
+
+
+
+ +
+
+

{{selectedstudent.firstname}} {{selectedstudent.lastname}} - {{displayedstudyplan.name}}

+

<<#str>> showoverview, local_treestudyplan <> - {{displayedstudyplan.name}}

+ +
+ Loading... +
+
+ + + +
+
+
+
\ No newline at end of file diff --git a/templates/edit_plan.mustache b/templates/edit_plan.mustache new file mode 100644 index 0000000..ddab1e2 --- /dev/null +++ b/templates/edit_plan.mustache @@ -0,0 +1,134 @@ +{{! + 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 . +}} +{{! + @template local_treestudyplan/edit_plan + + Template for rendering the manage studyplans page + + Classes required for JS: + * vue-loader + + Data attributes required for JS: + * none + + Context variables required for this template: + * none + + Example context (json): + { + "contextname": "System", + } +}} +{{! Next line replaces mustache double curly braces with << and >> for this template, +so it does not mess up vue double curly braces}} +{{= << >> =}} +
+
+
+ Loading... +
+
+
+
+ + + <<#str>> loading, core<>... + / {{ p }} ({{ ctx.studyplancount }}) + + +
+ +
+

<< contextname >>

+
+ <<#str>> back, local_treestudyplan <> + <<#str>> studyplan_select, local_treestudyplan <>  + + {{ studyplan.name }} +   + +
+ +
+ +
+ Loading... +
+
+

<<#str>> studyplan_noneselected, local_treestudyplan <>

+ + + + + +
+
+
+
diff --git a/templates/myreport.mustache b/templates/myreport.mustache new file mode 100644 index 0000000..04e4ff7 --- /dev/null +++ b/templates/myreport.mustache @@ -0,0 +1,62 @@ +{{! + 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 . +}} +{{! + @template local_treestudyplan/myreport + + Template for rendering the student's "My studyplan" page + + Classes required for JS: + * vue-loader + + Data attributes required for JS: + * none + + Context variables required for this template: + * none + + Example context (json): + { + "enableplansharing": true, + "teachermode": false + } +}} +{{! Next line replaces mustache double curly braces with << and >> for this template, +so it does not mess up vue double curly braces}} +{{= << >> =}} +
+ +
+
+
+ Loading... +
+
+
+ <<#teachermode>> + + <> + <<^teachermode>> + + <> +
+
+
\ No newline at end of file diff --git a/templates/result_overview.mustache b/templates/result_overview.mustache new file mode 100644 index 0000000..788274f --- /dev/null +++ b/templates/result_overview.mustache @@ -0,0 +1,109 @@ +{{! + 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 . +}} +{{! + @template local_treestudyplan/result_overview + + Template for rendering the invitations page + + Classes required for JS: + * vue-loader + + Data attributes required for JS: + * none + + Context variables required for this template: + * none + + Example context (json): + { + "contextname": "System", + "studyplanname": "Name of studyplan", + "pagename": "Name of studyplan page" + } +}} +{{! Next line replaces mustache double curly braces with << and >> for this template, +so it does not mess up vue double curly braces in the rest of the code.}} +{{= << >> =}} +
+

<> / <>

+ <<#pagename>> +

<>

+ <> +
+
+
+ Loading... +
+
+
+
+
+ Loading... +
+
+ +
+
+
\ No newline at end of file diff --git a/templates/view_plan.mustache b/templates/view_plan.mustache new file mode 100644 index 0000000..504cac7 --- /dev/null +++ b/templates/view_plan.mustache @@ -0,0 +1,124 @@ +{{! + 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 . +}} +{{! + @template local_treestudyplan/view_plan + + Template for rendering the studyplan view page + + Classes required for JS: + * vue-loader + + Data attributes required for JS: + * none + + Context variables required for this template: + * none + + Example context (json): + { + "contextname": "System", + } +}} +{{! Next line replaces mustache double curly braces with << and >> for this template, +so it does not mess up vue double curly braces}} +{{= << >> =}} +
+
+
+ Loading... +
+
+
+
+ + + <<#str>> loading, core <>... + / {{ p }} + ({{ ctx.studyplancount }}) + +
+
+

<>

+
+ +
+
+

{{selectedstudent.firstname}} {{selectedstudent.lastname}} - {{displayedstudyplan.name}}

+

<<#str>> showoverview, local_treestudyplan <> - {{displayedstudyplan.name}}

+ +
+ Loading... +
+
+

<<#str>> studyplan_noneselected, local_treestudyplan <>

+ + + +
+
+
+
\ No newline at end of file diff --git a/view-plan.php b/view-plan.php index d1e69d0..36ed946 100644 --- a/view-plan.php +++ b/view-plan.php @@ -29,6 +29,7 @@ use local_treestudyplan\courseservice; require_once($CFG->libdir.'/weblib.php'); $systemcontext = context_system::instance(); + $PAGE->set_context($systemcontext); $PAGE->set_url("/local/treestudyplan/view-plan.php", []); require_login(); @@ -38,13 +39,19 @@ $categoryid = optional_param('categoryid', 0, PARAM_INT); // Category id. $contextid = optional_param('contextid', 0, PARAM_INT); // Context id. if ($categoryid > 0) { $studyplancontext = context_coursecat::instance($categoryid); - + if (!is_object($studyplancontext)) { + $studyplancontext = $systemcontext; + } } else if ($contextid > 0) { $studyplancontext = context::instance_by_id($contextid); - if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT])) { - $categoryid = $studyplancontext->instanceid; - } else { + if (!is_object($studyplancontext)) { $studyplancontext = $systemcontext; + } else { + if (in_array($studyplancontext->contextlevel, [CONTEXT_SYSTEM, CONTEXT_COURSECAT])) { + $categoryid = $studyplancontext->instanceid; + } else { + $studyplancontext = $systemcontext; + } } } else { // If no context is selected, find the first available one. @@ -80,7 +87,7 @@ if ($studyplancontext->id > 1) { $cat = \core_course_category::top(); } -if (!$cat->is_uservisible()) { +if (!is_object($cat) || !$cat->is_uservisible()) { throw new \moodle_exception( "error:cannotviewcategory", "local_treestudyplan", @@ -106,101 +113,5 @@ if ($CFG->debugdeveloper) { $PAGE->requires->js_call_amd('local_treestudyplan/page-view-plan', 'init', [$studyplancontext->id, $categoryid]); print $OUTPUT->header(); -$text = (object)[ - 'loading' => get_string("loading", "core"), - 'back' => get_string('back', 'local_treestudyplan'), - 'studyplan_select' => get_string("studyplan_select", 'local_treestudyplan'), - 'selectstudent_btn' => get_string('selectstudent_btn', 'local_treestudyplan'), - 'showoverview' => get_string("showoverview", 'local_treestudyplan'), - 'studyplan_noneselected' => get_string("studyplan_noneselected", 'local_treestudyplan'), -]; -print << -
-
- Loading... -
-
-
-
- - - {$text->loading}... - / {{ p }} - ({{ ctx.studyplancount }}) - -
-
-

{$contextname}

-
- -
-
-

{{selectedstudent.firstname}} {{selectedstudent.lastname}} - {{displayedstudyplan.name}}

-

{$text->showoverview} - {{displayedstudyplan.name}}

- -
- Loading... -
-
-

{$text->studyplan_noneselected}

- - - -
-
-
- -END; - +print $OUTPUT->render_from_template('local_treestudyplan/view_plan', ["contextname" => $contextname]); print $OUTPUT->footer();