From fc7f76bb2cbda51ab2ceb59f34bc5e0ccfb15d10 Mon Sep 17 00:00:00 2001 From: Simon Thornett Date: Tue, 24 Sep 2024 07:44:52 +0100 Subject: [PATCH] WR422914 Added course select interface --- classes/output/renderer.php | 23 ++++++++++++++++++++++- lang/en/local_assessfreq.php | 1 + lib.php | 14 +++++--------- templates/index.mustache | 4 ++++ 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/classes/output/renderer.php b/classes/output/renderer.php index 8fbda00..3cb0d4b 100644 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -34,6 +34,7 @@ class renderer extends plugin_renderer_base { * @return void */ public function render_reports() : void { + global $PAGE; $reports = get_reports(); $reportoutputs = []; foreach ($reports as $report) { @@ -47,11 +48,31 @@ public function render_reports() : void { usort($reportoutputs, function($a, $b) { return $a['weight'] <=> $b['weight']; }); + $courseselectoptions = []; + $courseselect = ''; + $categories = \core_course_category::make_categories_list(); + + foreach ($categories as $categoryid => $category) { + $courses = get_courses($categoryid); + foreach ($courses as $course) { + $courseselectoptions[$course->id] = $category . ' - ' . $course->fullname; + } + } + if (!empty($courseselectoptions)) { + $courseselect = $this->single_select( + '#', + 'courseid', + $courseselectoptions, + $PAGE->course->id != SITEID ? $PAGE->course->id : '', + ['' => get_string('courseselect', 'local_assessfreq')], + ); + } $output = $this->output->header(); $output .= $this->render_from_template( 'local_assessfreq/index', [ - 'reports' => $reportoutputs + 'reports' => $reportoutputs, + 'courseselect' => $courseselect, ] ); $output .= $this->output->footer(); diff --git a/lang/en/local_assessfreq.php b/lang/en/local_assessfreq.php index 509927a..29c9b5b 100644 --- a/lang/en/local_assessfreq.php +++ b/lang/en/local_assessfreq.php @@ -32,6 +32,7 @@ $string['task:dataprocess'] = 'Data collection task'; $string['task:quiztracking'] = 'Quiz tracking task'; +$string['courseselect'] = 'Select course...'; $string['noreports'] = 'No reports have been configured for you. If you believe this is an error please contact your site administrator.'; diff --git a/lib.php b/lib.php index 25c2652..2c3bfd1 100644 --- a/lib.php +++ b/lib.php @@ -33,17 +33,13 @@ * @param context $context The context of the course */ function local_assessfreq_extend_navigation_course(navigation_node $navigation, stdClass $course, context $context) { - global $CFG, $OUTPUT; if (has_capability('local/assessfreq:view', $context)) { $url = new moodle_url('/local/assessfreq/', ['courseid' => $course->id]); - $navigation->add( - get_string('pluginname', 'local_assessfreq'), - $url, - navigation_node::TYPE_SETTING, - null, - null, - new pix_icon('i/report', '') - ); + $settingsnode = navigation_node::create(get_string('pluginname', 'local_assessfreq'), $url); + $reportnode = $navigation->get('coursereports'); + if (isset($settingsnode) && !empty($reportnode)) { + $reportnode->add_node($settingsnode); + } } } diff --git a/templates/index.mustache b/templates/index.mustache index 2a78ccd..d525196 100644 --- a/templates/index.mustache +++ b/templates/index.mustache @@ -21,6 +21,10 @@ }}
+ +

+ {{{courseselect}}} +

{{> local_assessfreq/tabs}}