From 91479c14c13a60a0f097aaf37dd860234a849e5c Mon Sep 17 00:00:00 2001 From: Simon Thornett Date: Tue, 7 Jan 2025 07:41:39 +0000 Subject: [PATCH] WR422914 CI Updates CI check updates and a few minor changes. --- amd/build/course_selector.min.js | 2 +- amd/build/course_selector.min.js.map | 2 +- amd/src/course_selector.js | 2 +- classes/event/event_processed.php | 4 +- classes/external.php | 43 ++-- classes/frequency.php | 36 +-- classes/output/renderer.php | 17 +- classes/plugininfo/assessfreqreport.php | 213 ++++++++++-------- classes/plugininfo/assessfreqsource.php | 211 +++++++++-------- classes/report_base.php | 20 +- classes/source_base.php | 25 +- classes/task/data_process.php | 12 +- db/tasks.php | 2 +- db/upgrade.php | 114 +++++----- index.php | 2 +- lang/en/local_assessfreq.php | 52 ++--- lib.php | 47 ++-- .../classes/output/renderer.php | 43 ++-- .../activities_in_progress/classes/report.php | 41 ++-- ...ssessfreqreport_activities_in_progress.php | 74 +++--- report/activities_in_progress/lib.php | 6 +- report/activities_in_progress/styles.css | 4 +- .../activities-in-progress-table.mustache | 20 +- .../templates/activities-in-progress.mustache | 4 +- .../templates/filter-hoursahead.mustache | 2 +- .../templates/filter-hoursbehind.mustache | 2 +- .../templates/filter-type.mustache | 12 +- .../templates/filters.mustache | 5 +- report/activities_in_progress/version.php | 4 +- .../classes/form/search_form.php | 2 +- .../classes/output/renderer.php | 16 +- report/activity_dashboard/classes/report.php | 37 +-- .../assessfreqreport_activity_dashboard.php | 48 ++-- report/activity_dashboard/lib.php | 3 +- .../templates/activity-dashboard.mustache | 4 +- report/activity_dashboard/version.php | 4 +- report/heatmap/classes/output/renderer.php | 163 ++++++++++++-- report/heatmap/classes/report.php | 158 ++----------- report/heatmap/download.php | 2 +- report/heatmap/externallib.php | 8 +- .../lang/en/assessfreqreport_heatmap.php | 64 +++--- report/heatmap/lib.php | 4 +- report/heatmap/settings.php | 2 +- report/heatmap/templates/dayview.mustache | 3 +- report/heatmap/templates/download.mustache | 3 + .../heatmap/templates/filter-metric.mustache | 6 +- report/heatmap/templates/filter-type.mustache | 8 +- report/heatmap/templates/filter-year.mustache | 6 +- report/heatmap/templates/filters.mustache | 3 + report/heatmap/version.php | 2 +- .../classes/output/renderer.php | 14 +- .../classes/output/user_table.php | 156 +++++++------ report/student_search/classes/report.php | 37 +-- .../en/assessfreqreport_student_search.php | 68 +++--- report/student_search/lib.php | 5 +- .../templates/filter-hoursahead.mustache | 2 +- .../templates/filter-hoursbehind.mustache | 2 +- .../student_search/templates/filters.mustache | 5 +- .../templates/student-search.mustache | 4 +- report/student_search/version.php | 4 +- .../classes/output/assess_by_activity.php | 3 +- .../classes/output/assess_by_month.php | 3 +- .../output/assess_by_month_student.php | 3 +- .../output/generate_assess_by_month_chart.php | 9 +- .../classes/output/renderer.php | 28 ++- report/summary_graphs/classes/report.php | 37 +-- .../en/assessfreqreport_summary_graphs.php | 32 +-- report/summary_graphs/lib.php | 4 +- report/summary_graphs/settings.php | 2 +- .../summary_graphs/templates/filters.mustache | 5 +- .../templates/summary-graphs.mustache | 4 +- report/summary_graphs/version.php | 4 +- settingslib.php | 142 ++++++------ source/assign/classes/form/override_form.php | 10 +- .../classes/output/participant_summary.php | 10 +- .../classes/output/participant_trend.php | 8 + source/assign/classes/output/renderer.php | 55 +++-- source/assign/classes/output/user_table.php | 56 ++--- source/assign/classes/source.php | 131 +++++++---- .../assign/classes/task/assign_tracking.php | 17 +- .../lang/en/assessfreqsource_assign.php | 90 ++++---- source/assign/lib.php | 2 +- source/assign/settings.php | 2 +- .../templates/activity_dashboard.mustache | 5 +- source/assign/version.php | 4 +- source/choice/classes/source.php | 28 ++- source/choice/version.php | 4 +- source/data/classes/source.php | 26 ++- source/data/version.php | 4 +- source/feedback/classes/source.php | 26 ++- source/feedback/version.php | 4 +- source/forum/classes/source.php | 22 +- source/forum/version.php | 4 +- source/lesson/classes/source.php | 30 ++- source/lesson/version.php | 4 +- source/quiz/classes/form/override_form.php | 14 +- .../classes/output/participant_summary.php | 2 +- source/quiz/classes/output/renderer.php | 29 ++- source/quiz/classes/output/user_table.php | 57 +++-- source/quiz/classes/source.php | 106 +++++---- source/quiz/classes/task/quiz_tracking.php | 8 +- source/quiz/lang/en/assessfreqsource_quiz.php | 80 +++---- source/quiz/settings.php | 2 +- .../templates/activity_dashboard.mustache | 5 +- source/quiz/version.php | 4 +- source/scorm/classes/source.php | 28 ++- source/scorm/version.php | 4 +- source/workshop/classes/source.php | 28 ++- source/workshop/version.php | 4 +- styles.css | 11 +- templates/card.mustache | 3 + templates/index.mustache | 3 + templates/tabs.mustache | 3 + tests/external_test.php | 2 +- tests/frequency_test.php | 2 +- tests/output/assess_by_activity_test.php | 2 +- tests/output/assess_by_month_student_test.php | 2 +- tests/output/assess_by_month_test.php | 2 +- tests/output/participant_summary_test.php | 2 +- tests/output/participant_trend_test.php | 2 +- tests/output/quiz_user_table_test.php | 2 +- tests/output/student_search_table_test.php | 2 +- tests/quiz_test.php | 71 +++--- version.php | 8 +- 124 files changed, 1778 insertions(+), 1392 deletions(-) diff --git a/amd/build/course_selector.min.js b/amd/build/course_selector.min.js index ea4541ef..c33edafc 100644 --- a/amd/build/course_selector.min.js +++ b/amd/build/course_selector.min.js @@ -7,6 +7,6 @@ * @copyright2016 Frédéric Massart - FMCorz.net * @licensehttp://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define("local_assessfreq/course_selector",["core/ajax","core/notification"],(function(Ajax,Notification){let CourseSelector={transport:function(selector,query,callback){Ajax.call([{methodname:"local_assessfreq_get_courses",args:{query:query}}])[0].then((response=>{let courseArray=JSON.parse(response);callback(courseArray)}))},processResults:function(selector,results){let options=[];return results.forEach((element=>{options.push({value:element.id,label:element.fullname})})),options}};return CourseSelector})); +define("local_assessfreq/course_selector",["core/ajax"],(function(Ajax){let CourseSelector={transport:function(selector,query,callback){Ajax.call([{methodname:"local_assessfreq_get_courses",args:{query:query}}])[0].then((response=>{let courseArray=JSON.parse(response);callback(courseArray)}))},processResults:function(selector,results){let options=[];return results.forEach((element=>{options.push({value:element.id,label:element.fullname})})),options}};return CourseSelector})); //# sourceMappingURL=course_selector.min.js.map \ No newline at end of file diff --git a/amd/build/course_selector.min.js.map b/amd/build/course_selector.min.js.map index fe26f533..96bd5538 100644 --- a/amd/build/course_selector.min.js.map +++ b/amd/build/course_selector.min.js.map @@ -1 +1 @@ -{"version":3,"file":"course_selector.min.js","sources":["../src/course_selector.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle.If not, see .\n\n/**\n * Frameworks datasource.\n *\n * This module is compatible with core/form-autocomplete.\n *\n * @packagetool_lpmigrate\n * @copyright2016 Frédéric Massart - FMCorz.net\n * @licensehttp://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['core/ajax', 'core/notification'], function (Ajax, Notification) {\n\n /**\n * Module level variables.\n */\n let CourseSelector = {};\n\n /**\n * Source of data for Ajax element.\n *\n * @param {String} selector The selector of the auto complete element.\n * @param {String} query The query string.\n * @param {Function} callback A callback function receiving an array of results.\n */\n CourseSelector.transport = function(selector, query, callback) {\n Ajax.call([{\n methodname: 'local_assessfreq_get_courses',\n args: {\n query: query\n },\n }])[0].then((response) => {\n let courseArray = JSON.parse(response);\n // eslint-disable-next-line promise/no-callback-in-promise\n callback(courseArray);\n });\n };\n\n /**\n * Process the results for auto complete elements.\n *\n * @param {String} selector The selector of the auto complete element.\n * @param {Array} results An array or results.\n * @return {Array} New array of results.\n */\n CourseSelector.processResults = function (selector, results) {\n let options = [];\n results.forEach((element) => {\n options.push({\n value: element.id,\n label: element.fullname\n });\n });\n\n return options;\n };\n\n return CourseSelector;\n});\n"],"names":["define","Ajax","Notification","CourseSelector","selector","query","callback","call","methodname","args","then","response","courseArray","JSON","parse","results","options","forEach","element","push","value","id","label","fullname"],"mappings":";;;;;;;;;AAyBAA,0CAAO,CAAC,YAAa,sBAAsB,SAAUC,KAAMC,kBAKnDC,eAAiB,CASrBA,UAA2B,SAASC,SAAUC,MAAOC,UACjDL,KAAKM,KAAK,CAAC,CACPC,WAAY,+BACZC,KAAM,CACFJ,MAAOA,UAEX,GAAGK,MAAMC,eACLC,YAAcC,KAAKC,MAAMH,UAE7BL,SAASM,iBAWjBT,eAAgC,SAAUC,SAAUW,aAC5CC,QAAU,UACdD,QAAQE,SAASC,UACbF,QAAQG,KAAK,CACTC,MAAOF,QAAQG,GACfC,MAAOJ,QAAQK,cAIhBP,iBAGJb"} \ No newline at end of file +{"version":3,"file":"course_selector.min.js","sources":["../src/course_selector.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle.If not, see .\n\n/**\n * Frameworks datasource.\n *\n * This module is compatible with core/form-autocomplete.\n *\n * @packagetool_lpmigrate\n * @copyright2016 Frédéric Massart - FMCorz.net\n * @licensehttp://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['core/ajax'], function(Ajax) {\n\n /**\n * Module level variables.\n */\n let CourseSelector = {};\n\n /**\n * Source of data for Ajax element.\n *\n * @param {String} selector The selector of the auto complete element.\n * @param {String} query The query string.\n * @param {Function} callback A callback function receiving an array of results.\n */\n CourseSelector.transport = function(selector, query, callback) {\n Ajax.call([{\n methodname: 'local_assessfreq_get_courses',\n args: {\n query: query\n },\n }])[0].then((response) => {\n let courseArray = JSON.parse(response);\n // eslint-disable-next-line promise/no-callback-in-promise\n callback(courseArray);\n });\n };\n\n /**\n * Process the results for auto complete elements.\n *\n * @param {String} selector The selector of the auto complete element.\n * @param {Array} results An array or results.\n * @return {Array} New array of results.\n */\n CourseSelector.processResults = function (selector, results) {\n let options = [];\n results.forEach((element) => {\n options.push({\n value: element.id,\n label: element.fullname\n });\n });\n\n return options;\n };\n\n return CourseSelector;\n});\n"],"names":["define","Ajax","CourseSelector","selector","query","callback","call","methodname","args","then","response","courseArray","JSON","parse","results","options","forEach","element","push","value","id","label","fullname"],"mappings":";;;;;;;;;AAyBAA,0CAAO,CAAC,cAAc,SAASC,UAKvBC,eAAiB,CASrBA,UAA2B,SAASC,SAAUC,MAAOC,UACjDJ,KAAKK,KAAK,CAAC,CACPC,WAAY,+BACZC,KAAM,CACFJ,MAAOA,UAEX,GAAGK,MAAMC,eACLC,YAAcC,KAAKC,MAAMH,UAE7BL,SAASM,iBAWjBT,eAAgC,SAAUC,SAAUW,aAC5CC,QAAU,UACdD,QAAQE,SAASC,UACbF,QAAQG,KAAK,CACTC,MAAOF,QAAQG,GACfC,MAAOJ,QAAQK,cAIhBP,iBAGJb"} \ No newline at end of file diff --git a/amd/src/course_selector.js b/amd/src/course_selector.js index c9ceafad..5f194022 100644 --- a/amd/src/course_selector.js +++ b/amd/src/course_selector.js @@ -23,7 +23,7 @@ * @licensehttp://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define(['core/ajax', 'core/notification'], function (Ajax, Notification) { +define(['core/ajax'], function(Ajax) { /** * Module level variables. diff --git a/classes/event/event_processed.php b/classes/event/event_processed.php index 13f38253..525a451f 100644 --- a/classes/event/event_processed.php +++ b/classes/event/event_processed.php @@ -48,7 +48,7 @@ protected function init() { * * @return string */ - public static function get_name() : string { + public static function get_name(): string { return get_string('eventeventprocessed', 'local_assessfreq'); } @@ -57,7 +57,7 @@ public static function get_name() : string { * * @return string */ - public function get_description() : string { + public function get_description(): string { return get_string('eventeven_processed_desc', 'local_assessfreq'); } } diff --git a/classes/external.php b/classes/external.php index 3938d2f0..bcb78fe5 100644 --- a/classes/external.php +++ b/classes/external.php @@ -38,12 +38,13 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class local_assessfreq_external extends external_api { + /** * Returns description of method parameters. * * @return external_function_parameters */ - public static function get_courses_parameters() : external_function_parameters { + public static function get_courses_parameters(): external_function_parameters { return new external_function_parameters([ 'query' => new external_value(PARAM_TEXT, 'The query to find'), ]); @@ -55,7 +56,7 @@ public static function get_courses_parameters() : external_function_parameters { * @param string $query The search query. * @return string JSON response. */ - public static function get_courses(string $query) : string { + public static function get_courses(string $query): string { global $DB, $SITE, $COURSE; manager::write_close(); // Close session early this is a read op. @@ -66,7 +67,10 @@ public static function get_courses(string $query) : string { ); // Execute API call. - $sql = 'SELECT id, fullname, category FROM {course} WHERE ' . $DB->sql_like('fullname', ':fullname', false) . ' AND id <> 1'; + $sql = 'SELECT id, fullname, category + FROM {course} + WHERE ' . $DB->sql_like('fullname', ':fullname', false) . ' + AND id <> 1'; $params = ['fullname' => '%' . $DB->sql_like_escape($query) . '%']; $courses = $DB->get_records_sql($sql, $params, 0, 30); @@ -74,14 +78,15 @@ public static function get_courses(string $query) : string { if (has_capability('local/assessfreq:view', context_system::instance())) { $data[SITEID] = [ "id" => $SITE->id, - "fullname" => external_format_string($SITE->fullname, true, ["escape" => false]) + "fullname" => external_format_string($SITE->fullname, true, ["escape" => false]), ]; } - $categories = \core_course_category::make_categories_list(); + $categories = core_course_category::make_categories_list(); foreach ($courses as $course) { + $fullname = external_format_string($course->fullname, true, ["escape" => false]); $data[$course->id] = [ "id" => $course->id, - "fullname" => $categories[$course->category] . ' / ' . external_format_string($course->fullname, true, ["escape" => false]) + "fullname" => $categories[$course->category] . ' / ' . $fullname, ]; } @@ -96,7 +101,7 @@ public static function get_courses(string $query) : string { * Returns description of method result value * @return external_value */ - public static function get_courses_returns() : external_value { + public static function get_courses_returns(): external_value { return new external_value(PARAM_RAW, 'Course result JSON'); } @@ -105,7 +110,7 @@ public static function get_courses_returns() : external_value { * * @return external_function_parameters */ - public static function get_activities_parameters() : external_function_parameters { + public static function get_activities_parameters(): external_function_parameters { return new external_function_parameters([ 'courseid' => new external_value(PARAM_INT, 'The courseid to find'), ]); @@ -114,10 +119,10 @@ public static function get_activities_parameters() : external_function_parameter /** * Returns activities in the course that match search data. * - * @param $courseid + * @param int $courseid The course id we're requesting for. * @return string JSON response. */ - public static function get_activities($courseid) : string { + public static function get_activities(int $courseid): string { global $DB; manager::write_close(); // Close session early this is a read op. @@ -130,7 +135,7 @@ public static function get_activities($courseid) : string { // Execute API call. $modules = $DB->get_records('course_modules', ['course' => $courseid]); - $sources = get_sources(); + $sources = local_assessfreq_get_sources(); $data = []; foreach ($modules as $module) { @@ -144,7 +149,7 @@ public static function get_activities($courseid) : string { $data[$module->id] = [ "id" => $module->id, - "name" => $cm->get_module_type_name() . " - " . $cm->get_name() + "name" => $cm->get_module_type_name() . " - " . $cm->get_name(), ]; } @@ -157,7 +162,7 @@ public static function get_activities($courseid) : string { * Returns description of method result value * @return external_value */ - public static function get_activities_returns() : external_value { + public static function get_activities_returns(): external_value { return new external_value(PARAM_RAW, 'Result JSON'); } @@ -167,7 +172,7 @@ public static function get_activities_returns() : external_value { * * @return external_function_parameters */ - public static function set_table_preference_parameters() : external_function_parameters { + public static function set_table_preference_parameters(): external_function_parameters { return new external_function_parameters([ 'tableid' => new external_value(PARAM_ALPHANUMEXT, 'The table id to set the preference for'), 'preference' => new external_value(PARAM_ALPHAEXT, 'The table preference to set'), @@ -183,7 +188,7 @@ public static function set_table_preference_parameters() : external_function_par * @param string $values The values to set for the preference, encoded as JSON. * @return string JSON response. */ - public static function set_table_preference(string $tableid, string $preference, string $values) : string { + public static function set_table_preference(string $tableid, string $preference, string $values): string { global $SESSION, $PAGE; // Parameter validation. @@ -233,7 +238,7 @@ public static function set_table_preference_returns() { * * @return external_function_parameters */ - public static function process_override_form_parameters() : external_function_parameters { + public static function process_override_form_parameters(): external_function_parameters { return new external_function_parameters( [ 'jsonformdata' => new external_value(PARAM_RAW, 'The data from the create copy form, encoded as a json array'), @@ -251,7 +256,7 @@ public static function process_override_form_parameters() : external_function_pa * @param int $activityid The activity id to add an override for. * @return string */ - public static function process_override_form(string $jsonformdata, string $activitytype, int $activityid) : string { + public static function process_override_form(string $jsonformdata, string $activitytype, int $activityid): string { global $DB; // Release session lock. @@ -269,9 +274,9 @@ public static function process_override_form(string $jsonformdata, string $activ parse_str($formdata, $submitteddata); $processid = 0; - $sources = get_sources(); + $sources = local_assessfreq_get_sources(); $source = $sources[$activitytype]; - /* @var $source source_base */ + /* @var $source source_base for accessing the source class */ if (method_exists($source, 'process_override_form')) { $processid = $source->process_override_form($activityid, $submitteddata); } diff --git a/classes/frequency.php b/classes/frequency.php index 9bcd2446..6bfae570 100644 --- a/classes/frequency.php +++ b/classes/frequency.php @@ -60,12 +60,14 @@ class frequency { /** * Size of batch to insert records into database. * - * @var integer $batchsize + * @var int $batchsize */ private int $batchsize = 100; /** * Cache of event users. + * + * @var array $eventuserscache */ private array $eventuserscache = []; @@ -77,7 +79,7 @@ class frequency { * @return array Capabilities relating to the module. */ public function get_module_capabilities(string $module): array { - $sources = get_sources(true); + $sources = local_assessfreq_get_sources(true); return $sources[$module]->get_user_capabilities(); } @@ -91,11 +93,11 @@ public function get_module_capabilities(string $module): array { * @return array $modules Lis of modules to process. */ public function get_process_modules(): array { - $sources = get_sources(); + $sources = local_assessfreq_get_sources(); $modules = []; if (!empty($sources)) { - /* @var $source source_base */ + /* @var $source source_base for accessing the source class */ foreach ($sources as $source) { $modules[] = $source->get_module(); } @@ -105,12 +107,15 @@ public function get_process_modules(): array { } /** - * Generate SQL to use to get activity info. + * Generate SQL to use to get activity info. * - * @param string $module Activity module to get data for. - * @return string $sql The generated SQL. + * @param string $module The module that we're getting the query for. + * @param string $duedate The end date field for the module. + * @param string $startdate The start date field for the module. + * @param string $timelimit The time limit field for the module. + * @return string */ - private function get_sql_query(string $module, $duedate, $startdate, $timelimit): string { + private function get_sql_query(string $module, string $duedate, string $startdate, string $timelimit): string { $includehiddencourses = get_config('local_assessfreq', 'hiddencourses'); $sql = 'SELECT cm.id, cm.course, m.name, cm.instance, c.id as contextid, a.' . $duedate . ' AS duedate '; @@ -253,14 +258,14 @@ private function process_module_events(moodle_recordset $recordset): int { */ public function process_site_events(int $duedate): int { $recordsprocessed = 0; - $sources = get_sources(true); + $sources = local_assessfreq_get_sources(true); $includehiddencourses = get_config('local_assessfreq', 'hiddencourses'); if (!empty($sources)) { // Itterate through sources. foreach ($sources as $source) { - /* @var $source source_base */ + /* @var $source source_base for accessing the source class */ $sql = $this->get_sql_query( $source->get_module_table(), $source->get_close_field(), @@ -859,6 +864,7 @@ public function get_user_events_all(int $courseid, string $module = 'all', int $ * Get events for a given year, grouped by month. * * @param int $year The year to get the events for. + * @param int $month The month to get the events for. * @param bool $cache Fetch events from cache. * @return array $events The events. */ @@ -936,6 +942,7 @@ public function get_events_due_by_month(int $year, int $month = 0, bool $cache = * Get count of users who have an event for a given year grouped by month. * * @param int $year The year to get the events for. + * @param int $month The month to get the events for. * @param bool $cache Fetch events from cache. * @return array $events The events. */ @@ -1014,6 +1021,7 @@ public function get_events_due_monthly_by_user(int $year, int $month = 0, bool $ * Get count of assessments who have an event for a given year grouped by month. * * @param int $year The year to get the events for. + * @param int $month The month to get the events for. * @param bool $cache Fetch events from cache. * @return array $events The events. */ @@ -1037,7 +1045,7 @@ public function get_events_due_by_activity(int $year, int $month = 0, bool $cach $params = []; $sql = 'SELECT s.module, COUNT(s.id) as count FROM {local_assessfreq_site} s - LEFT JOIN {course} c ON s.courseid = c.id + LEFT JOIN {course} c ON s.courseid = c.id WHERE 1=1'; $includehiddencourses = get_config('local_assessfreq', 'hiddencourses'); @@ -1151,7 +1159,7 @@ public function get_day_events(int $courseid, string $date, array $modules): arr } } - $sources = get_sources(); + $sources = local_assessfreq_get_sources(); // Get additional information and format the event data. foreach ($events as $event) { @@ -1166,7 +1174,7 @@ public function get_day_events(int $courseid, string $date, array $modules): arr ($event->timelimit == 0) ? '-' : round(($event->timelimit / 60)); $event->dashurl = ''; - /* @var $source source_base */ + /* @var $source source_base for accessing the source class */ $source = $sources[$event->module]; if (method_exists($source, 'get_activity_dashboard')) { $dashurl = new \moodle_url('/local/assessfreq/', ['activityid' => $context->instanceid], 'activity_dashboard'); @@ -1203,6 +1211,7 @@ public function get_day_events(int $courseid, string $date, array $modules): arr * [yyyy][mm][dd]['number'] = number of events that day. * * @param int $year The year to get events for. + * @param int $month The month to get the events for. * @param string $metric The metric to get 'students' or 'assess'. * @param array $modules List of modules to get events for. * @return array $freqarray The array of even frequencies. @@ -1291,6 +1300,7 @@ public function get_frequency_array(int $year = 0, int $month = 0, string $metri * Get data for file download export. * * @param int $year The year to get the data for. + * @param int $month The month to get the events for. * @param string $metric The type of metric to get 'assess' or 'student'. * @param array $modules The modules to get. * @return array $data The data for the download file. diff --git a/classes/output/renderer.php b/classes/output/renderer.php index d661d17b..27ec8188 100644 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -25,21 +25,28 @@ namespace local_assessfreq\output; -use local_assessfreq\form\course_search; use local_assessfreq\report_base; use plugin_renderer_base; +/** + * Renderer. + * + * @package local_assessfreq + * @author Simon Thornett + * @copyright Catalyst IT, 2024 + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class renderer extends plugin_renderer_base { /** * Render each of the assessfreqreport subplugins as tabs to display. * * @return void */ - public function render_reports() : void { - $reports = get_reports(); + public function render_reports(): void { + $reports = local_assessfreq_get_reports(); $reportoutputs = []; foreach ($reports as $report) { - /* @var $report report_base */ + /* @var $report report_base for accessing the report class */ $reportoutputs[] = [ 'tablink' => $report->get_tablink(), // Plugin name. 'tabname' => $report->get_name(), // Display name. @@ -55,7 +62,7 @@ public function render_reports() : void { $output .= $this->render_from_template( 'local_assessfreq/index', [ - 'reports' => $reportoutputs + 'reports' => $reportoutputs, ] ); $output .= $this->output->footer(); diff --git a/classes/plugininfo/assessfreqreport.php b/classes/plugininfo/assessfreqreport.php index f61aaf31..319df2e8 100644 --- a/classes/plugininfo/assessfreqreport.php +++ b/classes/plugininfo/assessfreqreport.php @@ -1,100 +1,113 @@ -. - -/** - * Report plugininfo. - * - * @package local_assessfreq - * @author Simon Thornett - * @copyright Catalyst IT, 2024 - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace local_assessfreq\plugininfo; - -use admin_settingpage; -use core\plugininfo\base; -use moodle_url; -use part_of_admin_tree; - -class assessfreqreport extends base { - - /** - * Finds all enabled plugin names, the result may include missing plugins. - * @return array of enabled plugins $pluginname=>$pluginname, null means unknown - */ - public static function get_enabled_plugins() : array { - $pluginmanager = \core_plugin_manager::instance(); - $plugins = $pluginmanager->get_plugins_of_type('assessfreqreport'); - - if (empty($plugins)) { - return array(); - } - - $enabled = []; - foreach ($plugins as $name => $plugin) { - if ($plugin->is_enabled()) { - $enabled[$name] = $name; - } - } - return $enabled; - } - - /** - * Whether the subplugin is enabled. - * - * @return bool Whether enabled. - */ - public function is_enabled() : bool { - return get_config('assessfreqreport_' . $this->name, 'enabled'); - } - - /** - * Returns the node name used in admin settings menu for this plugin settings (if applicable) - * - * @return string node name or null if plugin does not create settings node (default) - */ - public function get_settings_section_name(): string { - return 'assessfreqreport_' . $this->name; - } - - /** - * Include the settings.php file from sub plugins if they provide it. - * This is a copy of very similar implementations from various other subplugin areas. - */ - public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) { - global $CFG, $USER, $DB, $OUTPUT, $PAGE; // In case settings.php wants to refer to them. - $ADMIN = $adminroot; // May be used in settings.php. - $plugininfo = $this; // Also can be used inside settings.php. - - if (!$this->is_installed_and_upgraded()) { - return; - } - - if (!$hassiteconfig || !file_exists($this->full_path('settings.php'))) { - return; - } - - $section = $this->get_settings_section_name(); - $settings = new admin_settingpage($section, $this->displayname, 'moodle/site:config', $this->is_enabled() === false); - include($this->full_path('settings.php')); // This may also set $settings to null. - - if ($settings) { - $ADMIN->add($parentnodename, $settings); - } - } -} - +. + +/** + * Report plugininfo. + * + * @package local_assessfreq + * @author Simon Thornett + * @copyright Catalyst IT, 2024 + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace local_assessfreq\plugininfo; + +use admin_settingpage; +use core\plugininfo\base; +use moodle_url; +use part_of_admin_tree; + +/** + * Report plugininfo. + * + * @package local_assessfreq + * @author Simon Thornett + * @copyright Catalyst IT, 2024 + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class assessfreqreport extends base { + + /** + * Finds all enabled plugin names, the result may include missing plugins. + * @return array of enabled plugins $pluginname=>$pluginname, null means unknown + */ + public static function get_enabled_plugins(): array { + $pluginmanager = \core_plugin_manager::instance(); + $plugins = $pluginmanager->get_plugins_of_type('assessfreqreport'); + + if (empty($plugins)) { + return []; + } + + $enabled = []; + foreach ($plugins as $name => $plugin) { + if ($plugin->is_enabled()) { + $enabled[$name] = $name; + } + } + return $enabled; + } + + /** + * Whether the subplugin is enabled. + * + * @return bool Whether enabled. + */ + public function is_enabled(): bool { + return get_config('assessfreqreport_' . $this->name, 'enabled'); + } + + /** + * Returns the node name used in admin settings menu for this plugin settings (if applicable) + * + * @return string node name or null if plugin does not create settings node (default) + */ + public function get_settings_section_name(): string { + return 'assessfreqreport_' . $this->name; + } + + /** + * Include the settings.php file from sub plugins if they provide it. + * This is a copy of very similar implementations from various other subplugin areas. + * + * @param part_of_admin_tree $adminroot + * @param string $parentnodename + * @param bool $hassiteconfig + * @return void + */ + public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig): void { + global $CFG, $USER, $DB, $OUTPUT, $PAGE; // In case settings.php wants to refer to them. + $ADMIN = $adminroot; // May be used in settings.php. + $plugininfo = $this; // Also can be used inside settings.php. + + if (!$this->is_installed_and_upgraded()) { + return; + } + + if (!$hassiteconfig || !file_exists($this->full_path('settings.php'))) { + return; + } + + $section = $this->get_settings_section_name(); + $settings = new admin_settingpage($section, $this->displayname, 'moodle/site:config', $this->is_enabled() === false); + include($this->full_path('settings.php')); // This may also set $settings to null. + + if ($settings) { + $ADMIN->add($parentnodename, $settings); + } + } +} + diff --git a/classes/plugininfo/assessfreqsource.php b/classes/plugininfo/assessfreqsource.php index f1c4e448..f1012937 100644 --- a/classes/plugininfo/assessfreqsource.php +++ b/classes/plugininfo/assessfreqsource.php @@ -1,99 +1,112 @@ -. - -/** - * Source plugininfo. - * - * @package local_assessfreq - * @author Simon Thornett - * @copyright Catalyst IT, 2024 - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -namespace local_assessfreq\plugininfo; - -use admin_settingpage; -use core\plugininfo\base; -use part_of_admin_tree; - -class assessfreqsource extends base { - - /** - * Finds all enabled plugin names, the result may include missing plugins. - * @return array of enabled plugins $pluginname=>$pluginname, null means unknown - */ - public static function get_enabled_plugins() : array { - $pluginmanager = \core_plugin_manager::instance(); - $plugins = $pluginmanager->get_plugins_of_type('assessfreqsource'); - - if (empty($plugins)) { - return array(); - } - - $enabled = []; - foreach ($plugins as $name => $plugin) { - if ($plugin->is_enabled()) { - $enabled[$name] = $name; - } - } - return $enabled; - } - - /** - * Whether the subplugin is enabled. - * - * @return bool Whether enabled. - */ - public function is_enabled() : bool { - return get_config('assessfreqsource_' . $this->name, 'enabled'); - } - - /** - * Returns the node name used in admin settings menu for this plugin settings (if applicable) - * - * @return string node name or null if plugin does not create settings node (default) - */ - public function get_settings_section_name() : string { - return 'assessfreqsource_' . $this->name; - } - - /** - * Include the settings.php file from sub plugins if they provide it. - * This is a copy of very similar implementations from various other subplugin areas. - */ - public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) { - global $CFG, $USER, $DB, $OUTPUT, $PAGE; // In case settings.php wants to refer to them. - $ADMIN = $adminroot; // May be used in settings.php. - $plugininfo = $this; // Also can be used inside settings.php. - - if (!$this->is_installed_and_upgraded()) { - return; - } - - if (!$hassiteconfig || !file_exists($this->full_path('settings.php'))) { - return; - } - - $section = $this->get_settings_section_name(); - $settings = new admin_settingpage($section, $this->displayname, 'moodle/site:config', $this->is_enabled() === false); - include($this->full_path('settings.php')); // This may also set $settings to null. - - if ($settings) { - $ADMIN->add($parentnodename, $settings); - } - } -} - +. + +/** + * Source plugininfo. + * + * @package local_assessfreq + * @author Simon Thornett + * @copyright Catalyst IT, 2024 + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace local_assessfreq\plugininfo; + +use admin_settingpage; +use core\plugininfo\base; +use part_of_admin_tree; + +/** + * Source plugininfo. + * + * @package local_assessfreq + * @author Simon Thornett + * @copyright Catalyst IT, 2024 + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class assessfreqsource extends base { + + /** + * Finds all enabled plugin names, the result may include missing plugins. + * @return array of enabled plugins $pluginname=>$pluginname, null means unknown + */ + public static function get_enabled_plugins(): array { + $pluginmanager = \core_plugin_manager::instance(); + $plugins = $pluginmanager->get_plugins_of_type('assessfreqsource'); + + if (empty($plugins)) { + return []; + } + + $enabled = []; + foreach ($plugins as $name => $plugin) { + if ($plugin->is_enabled()) { + $enabled[$name] = $name; + } + } + return $enabled; + } + + /** + * Whether the subplugin is enabled. + * + * @return bool Whether enabled. + */ + public function is_enabled(): bool { + return get_config('assessfreqsource_' . $this->name, 'enabled'); + } + + /** + * Returns the node name used in admin settings menu for this plugin settings (if applicable) + * + * @return string node name or null if plugin does not create settings node (default) + */ + public function get_settings_section_name(): string { + return 'assessfreqsource_' . $this->name; + } + + /** + * Include the settings.php file from sub plugins if they provide it. + * This is a copy of very similar implementations from various other subplugin areas. + * + * @param part_of_admin_tree $adminroot + * @param string $parentnodename + * @param bool $hassiteconfig + * @return void + */ + public function load_settings(part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig): void { + global $CFG, $USER, $DB, $OUTPUT, $PAGE; // In case settings.php wants to refer to them. + $ADMIN = $adminroot; // May be used in settings.php. + $plugininfo = $this; // Also can be used inside settings.php. + + if (!$this->is_installed_and_upgraded()) { + return; + } + + if (!$hassiteconfig || !file_exists($this->full_path('settings.php'))) { + return; + } + + $section = $this->get_settings_section_name(); + $settings = new admin_settingpage($section, $this->displayname, 'moodle/site:config', $this->is_enabled() === false); + include($this->full_path('settings.php')); // This may also set $settings to null. + + if ($settings) { + $ADMIN->add($parentnodename, $settings); + } + } +} + diff --git a/classes/report_base.php b/classes/report_base.php index c7327818..29e1a590 100644 --- a/classes/report_base.php +++ b/classes/report_base.php @@ -30,8 +30,15 @@ */ abstract class report_base { + /** + * Singleton instances. + * @var array + */ private static array $instances = []; + /** + * Contructor. + */ public function __construct() { $this->get_required_js(); $this->get_required_css(); @@ -42,7 +49,7 @@ public function __construct() { * * @return report_base */ - public static function get_instance() : report_base { + public static function get_instance(): report_base { $class = static::class; if (!isset(self::$instances[$class])) { self::$instances[$class] = new static(); @@ -55,35 +62,34 @@ public static function get_instance() : report_base { * Return the name of the tab being rendered. * @return string */ - abstract public function get_name() : string; + abstract public function get_name(): string; /** * Return the weight of the tab which is used to determine the loading order with the highest first. * @return int */ - abstract public function get_tab_weight() : int; + abstract public function get_tab_weight(): int; /** * Get the contents of the page as a string of HTML (template). * * @return object */ - - abstract public function get_contents() : string; + abstract public function get_contents(): string; /** * Get the anchor link to use for the tabs. * * @return string */ - abstract public function get_tablink() : string; + abstract public function get_tablink(): string; /** * Check if the report is visible to the user. * * @return bool */ - public function has_access() : bool { + public function has_access(): bool { return false; } diff --git a/classes/source_base.php b/classes/source_base.php index 6bfdccf5..5fefcce9 100644 --- a/classes/source_base.php +++ b/classes/source_base.php @@ -30,6 +30,10 @@ */ abstract class source_base { + /** + * Singleton instances. + * @var array + */ private static array $instances = []; /** @@ -39,6 +43,9 @@ abstract class source_base { */ private static array $cache = []; + /** + * Constructor. + */ public function __construct() { $this->get_required_js(); $this->get_required_css(); @@ -49,7 +56,7 @@ public function __construct() { * * @return source_base */ - public static function get_instance() : source_base { + public static function get_instance(): source_base { $class = static::class; if (!isset(self::$instances[$class])) { self::$instances[$class] = new static(); @@ -62,13 +69,13 @@ public static function get_instance() : source_base { * Return the name of the module the source refers to. * @return string */ - abstract public function get_module() : string; + abstract public function get_module(): string; /** * Return the module table. By default, this is the module name, however some mods use a different table. * @return string */ - public function get_module_table() : string { + public function get_module_table(): string { return $this->get_module(); } @@ -76,7 +83,7 @@ public function get_module_table() : string { * Return the timelimit field used in the module table. * @return string */ - public function get_timelimit_field() : string { + public function get_timelimit_field(): string { return ''; } @@ -84,7 +91,7 @@ public function get_timelimit_field() : string { * Return the available/timeopen field used in the module table. * @return string */ - public function get_open_field() : string { + public function get_open_field(): string { return ''; } @@ -92,7 +99,7 @@ public function get_open_field() : string { * Return the duedate/timeclose field used in the module table. * @return string */ - public function get_close_field() : string { + public function get_close_field(): string { return ''; } @@ -100,7 +107,7 @@ public function get_close_field() : string { * Return the capability map for the module that users must have before the activity applies to them. * @return array */ - public function get_user_capabilities() : array { + public function get_user_capabilities(): array { return []; } @@ -108,7 +115,7 @@ public function get_user_capabilities() : array { * Return the name of the source being rendered. * @return string */ - abstract public function get_name() : string; + abstract public function get_name(): string; /** * Set up the required JS in the global $PAGE object. @@ -131,7 +138,7 @@ protected function get_required_css() { * @param bool $limited If limited, only return a subset of data. Otherwise reports can try and render thousands of data points. * @return array $tracking Tracking reocrds for the quiz. */ - protected function get_tracking(int $assessid, bool $limited = false) : array { + protected function get_tracking(int $assessid, bool $limited = false): array { global $DB; $module = $this->get_module(); diff --git a/classes/task/data_process.php b/classes/task/data_process.php index 0ac5fc71..f7712277 100644 --- a/classes/task/data_process.php +++ b/classes/task/data_process.php @@ -43,7 +43,7 @@ class data_process extends scheduled_task { * * @return string */ - public function get_name() : string { + public function get_name(): string { return get_string('task:dataprocess', 'local_assessfreq'); } @@ -97,15 +97,5 @@ public function execute() { ]); $event->trigger(); mtrace('local_assessfreq: Processing user events finished in: ' . $actionduration . ' seconds'); - - //mtrace('local_assessfreq: Clearing legacy tracking data'); - //$actionstart = time(); - //$actionduration = time() - $actionstart; - //$event = event_processed::create([ - // 'context' => $context, - // 'other' => ['action' => 'user', 'duration' => $actionduration], - //]); - //$event->trigger(); - //mtrace('local_assessfreq: Processing user events finished in: ' . $actionduration . ' seconds'); } } diff --git a/db/tasks.php b/db/tasks.php index 3648ed85..a3964ed7 100644 --- a/db/tasks.php +++ b/db/tasks.php @@ -36,5 +36,5 @@ 'day' => '*', 'dayofweek' => '*', 'month' => '*', - ] + ], ]; diff --git a/db/upgrade.php b/db/upgrade.php index daa35493..3024176f 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -1,57 +1,57 @@ -. - -/** - * Upgrade file. - * - * @package local_assessfreq - * @author Simon Thornett - * @copyright Catalyst IT, 2024 - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -/** - * Function to upgrade local_assessfreq. - * @param int $oldversion the version we are upgrading from - * @return bool result - */ -function xmldb_local_assessfreq_upgrade($oldversion) { - global $DB; - - $dbman = $DB->get_manager(); - - if ($oldversion < 2024040302) { - - $table = new xmldb_table('local_assessfreq_trend'); - /* - * Previously we only used this table for quiz, so all existing modules will be quiz modules, hence the default. - */ - $field = new xmldb_field('module', XMLDB_TYPE_CHAR, '20', true, true, null, 'quiz'); - $index = new xmldb_index('module', XMLDB_INDEX_NOTUNIQUE, ['assessid', 'module']); - - if (!$dbman->field_exists($table, $field)) { - $dbman->add_field($table, $field); - } - - if (!$dbman->index_exists($table, $index)) { - $dbman->add_index($table, $index); - } - - upgrade_plugin_savepoint(true, 2024040302, 'local', 'assessfreq'); - } - - return true; -} +. + +/** + * Upgrade file. + * + * @package local_assessfreq + * @author Simon Thornett + * @copyright Catalyst IT, 2024 + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Function to upgrade local_assessfreq. + * @param int $oldversion the version we are upgrading from + * @return bool result + */ +function xmldb_local_assessfreq_upgrade($oldversion) { + global $DB; + + $dbman = $DB->get_manager(); + + if ($oldversion < 2024040302) { + + $table = new xmldb_table('local_assessfreq_trend'); + /* + * Previously we only used this table for quiz, so all existing modules will be quiz modules, hence the default. + */ + $field = new xmldb_field('module', XMLDB_TYPE_CHAR, '20', true, true, null, 'quiz'); + $index = new xmldb_index('module', XMLDB_INDEX_NOTUNIQUE, ['assessid', 'module']); + + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + if (!$dbman->index_exists($table, $index)) { + $dbman->add_index($table, $index); + } + + upgrade_plugin_savepoint(true, 2024040302, 'local', 'assessfreq'); + } + + return true; +} diff --git a/index.php b/index.php index 1cc018e3..22fa9e84 100644 --- a/index.php +++ b/index.php @@ -60,5 +60,5 @@ $output = $PAGE->get_renderer('local_assessfreq'); $PAGE->requires->js_call_amd('local_assessfreq/dashboard', 'init'); -/* @var $output local_assessfreq\output\renderer */ +/* @var $output local_assessfreq\output\renderer the output renderer for the reports. */ $output->render_reports(); diff --git a/lang/en/local_assessfreq.php b/lang/en/local_assessfreq.php index 76ef1426..721b88e2 100644 --- a/lang/en/local_assessfreq.php +++ b/lang/en/local_assessfreq.php @@ -23,42 +23,42 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['assessfreq:view'] = 'Ability to load the inital view. Report subplugins will also need to be allowed.'; +$string['courseselect'] = 'Select course...'; +$string['filter:entersearch'] = 'Enter search'; +$string['filter:reset'] = 'Reset'; +$string['filter:rows100'] = '100 rows'; +$string['filter:rows20'] = '20 rows'; +$string['filter:rows50'] = '50 rows'; +$string['filter:showrows'] = 'Show rows'; +$string['history:confirmreprocess'] = 'Delete ALL history and reprocess?'; +$string['history:reprocessall'] = 'Reprocess all events'; +$string['history:reprocessall_desc'] = 'This will delete ALL existing event records from the database and start a process to reprocess all events. This will happen in the background.'; +$string['modal:useroverride'] = 'User override'; +$string['noreports'] = 'No reports have been configured for you. +If you believe this is an error please contact your site administrator.'; $string['pluginname'] = 'Assessment Frequency Report'; +$string['privacy:metadata'] = 'The assessment frequency reports only display data'; +$string['settings:clearhistory'] = 'Assessment Frequency Clear History'; +$string['settings:enablereport'] = 'Enable: {$a}'; +$string['settings:enablereport_help'] = 'Check this control to allow the report to be used for the dashboard.'; +$string['settings:enablesource'] = 'Enable: {$a}'; +$string['settings:enablesource_help'] = 'Check this control to allow the source to be used for the dashboard.'; +$string['settings:head'] = 'Assessment Frequency Reports'; +$string['settings:hiddencourses'] = 'Include hidden courses'; +$string['settings:hiddencourses_desc'] = 'Included hidden courses in the reports'; +$string['settings:local_assessfreq'] = 'Global Settings'; +$string['settings:start_month'] = 'Start month'; +$string['settings:start_month_desc'] = 'Specify the month that the heatmap year should start from.'; $string['subplugintype_assessfreqreport_plural'] = 'Assessment Frequency Reports'; $string['subplugintype_assessfreqsource_plural'] = 'Assessment Frequency Sources'; -$string['privacy:metadata'] = 'The assessment frequency reports only display data'; -$string['assessfreq:view'] = 'Ability to load the inital view. Report subplugins will also need to be allowed.'; $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.'; -$string['history:confirmreprocess'] = 'Delete ALL history and reprocess?'; -$string['history:reprocessall'] = 'Reprocess all events'; -$string['history:reprocessall_desc'] = 'This will delete ALL existing event records from the database and start a process to reprocess all events. This will happen in the background.'; -$string['settings:clearhistory'] = 'Assessment Frequency Clear History'; -$string['settings:head'] = 'Assessment Frequency Reports'; -$string['settings:local_assessfreq'] = 'Global Settings'; -$string['settings:start_month'] = 'Start month'; -$string['settings:start_month_desc'] = 'Specify the month that the heatmap year should start from.'; -$string['settings:hiddencourses'] = 'Include hidden courses'; -$string['settings:hiddencourses_desc'] = 'Included hidden courses in the reports'; -$string['settings:enablesource'] = 'Enable: {$a}'; -$string['settings:enablesource_help'] = 'Check this control to allow the source to be used for the dashboard.'; -$string['settings:enablereport'] = 'Enable: {$a}'; -$string['settings:enablereport_help'] = 'Check this control to allow the report to be used for the dashboard.'; -$string['filter:entersearch'] = 'Enter search'; -$string['filter:reset'] = 'Reset'; -$string['filter:showrows'] = 'Show rows'; -$string['filter:rows20'] = '20 rows'; -$string['filter:rows50'] = '50 rows'; -$string['filter:rows100'] = '100 rows'; -$string['modal:useroverride'] = 'User override'; diff --git a/lib.php b/lib.php index 484ef139..409cb97d 100644 --- a/lib.php +++ b/lib.php @@ -13,6 +13,7 @@ // // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . + use local_assessfreq\frequency; use local_assessfreq\source_base; use local_assessfreq\report_base; @@ -32,7 +33,7 @@ * @param stdClass $course The course to object for the report * @param context $context The context of the course */ -function local_assessfreq_extend_navigation_course(navigation_node $navigation, stdClass $course, context $context) { +function local_assessfreq_extend_navigation_course(navigation_node $navigation, stdClass $course, context $context): void { if (has_capability('local/assessfreq:view', $context)) { $url = new moodle_url('/local/assessfreq/', ['courseid' => $course->id]); $settingsnode = navigation_node::create(get_string('pluginname', 'local_assessfreq'), $url); @@ -46,14 +47,14 @@ function local_assessfreq_extend_navigation_course(navigation_node $navigation, /** * Get all of the subplugin reports that are enabled and instantiate the class. * - * @param $ignoreenabled + * @param bool $ignoreenabled * @return array */ -function get_reports($ignoreenabled = false) : array { +function local_assessfreq_get_reports(bool $ignoreenabled = false): array { $reports = []; $pluginmanager = core_plugin_manager::instance(); foreach ($pluginmanager->get_plugins_of_type('assessfreqreport') as $subplugin) { - /* @var $class report_base */ + /* @var $class report_base for accessing the report class */ if ($subplugin->is_enabled() || $ignoreenabled) { $class = "assessfreqreport_{$subplugin->name}\\report"; $report = $class::get_instance(); @@ -68,23 +69,26 @@ function get_reports($ignoreenabled = false) : array { /** * Get all of the subplugin sources that are enabled and instantiate the class. * - * @param $ignoreenabled + * @param bool $ignoreenabled + * @param string $requiredmethod * @return array */ -function get_sources($ignoreenabled = false, $requiredmethod = '') : array { +function local_assessfreq_get_sources(bool $ignoreenabled = false, $requiredmethod = ''): array { $sources = []; $pluginmanager = core_plugin_manager::instance(); foreach ($pluginmanager->get_plugins_of_type('assessfreqsource') as $subplugin) { if ($subplugin->is_enabled() || $ignoreenabled) { - /* @var $class source_base */ + /* @var $class source_base for accessing the source class */ $class = "assessfreqsource_{$subplugin->name}\\source"; - $source = $class::get_instance(); - if (!empty($requiredmethod)) { - if (!method_exists($source, $requiredmethod)) { - continue; + if (class_exists($class)) { + $source = $class::get_instance(); + if (!empty($requiredmethod)) { + if (!method_exists($source, $requiredmethod)) { + continue; + } } + $sources[$subplugin->name] = $source; } - $sources[$subplugin->name] = $source; } } return $sources; @@ -95,7 +99,7 @@ function get_sources($ignoreenabled = false, $requiredmethod = '') : array { * * @return array */ -function get_months_ordered() : array { +function local_assessfreq_get_months_ordered(): array { $months = []; $startmonth = get_config('local_assessfreq', 'start_month'); @@ -115,10 +119,10 @@ function get_months_ordered() : array { /** * Get the years that have events with the preferred year active. * - * @param $preference + * @param int $preference * @return array */ -function get_years($preference) : array { +function local_assessfreq_get_years($preference): array { $currentyear = date('Y'); @@ -154,11 +158,14 @@ function get_years($preference) : array { * Get the modules to use in data collection. * This is based on which sources have been enabled. * + * @param array $preferences + * @param string $requiredmethod * @return array $modules The enabled modules. + * @throws coding_exception */ -function get_modules($preferences, $requiredmethod= '') : array { +function local_assessfreq_get_modules($preferences, $requiredmethod= ''): array { - $sources = get_sources(false, $requiredmethod); + $sources = local_assessfreq_get_sources(false, $requiredmethod); // Get modules for filters and load into context. $modules = []; @@ -189,7 +196,7 @@ function get_modules($preferences, $requiredmethod= '') : array { * @param array $userids User ids to get logged in status. * @return stdClass $usercounts Object with coutns of users logged in and not logged in. */ -function get_loggedin_users(array $userids): stdClass { +function local_assessfreq_get_loggedin_users(array $userids): stdClass { global $CFG, $DB; $maxlifetime = $CFG->sessiontimeout; @@ -243,10 +250,10 @@ function local_assessfreq_output_fragment_new_override_form($args): string { parse_str($serialiseddata, $formdata); } - $sources = get_sources(); + $sources = local_assessfreq_get_sources(); $source = $sources[$module]; $o = ''; - /* @var $source source_base */ + /* @var $source source_base for accessing the source class */ if (method_exists($source, 'get_override_form')) { $mform = $source->get_override_form($args['activityid'], $args['context'], $args['userid'], $serialiseddata); ob_start(); diff --git a/report/activities_in_progress/classes/output/renderer.php b/report/activities_in_progress/classes/output/renderer.php index 39a9b727..174cc672 100644 --- a/report/activities_in_progress/classes/output/renderer.php +++ b/report/activities_in_progress/classes/output/renderer.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * Renderer. + * Activities in progress renderer. * * @package assessfreqreport_activities_in_progress * @author Simon Thornett @@ -25,15 +25,16 @@ namespace assessfreqreport_activities_in_progress\output; -use context_system; +use coding_exception; use core\chart_bar; use core\chart_pie; use core\chart_series; +use dml_exception; use html_writer; use local_assessfreq\source_base; use local_assessfreq\utils; +use moodle_exception; use paging_bar; -use PHPUnit\TextUI\XmlConfiguration\PHPUnit; use plugin_renderer_base; defined('MOODLE_INTERNAL') || die(); @@ -41,9 +42,26 @@ global $CFG; require_once($CFG->dirroot . '/local/assessfreq/lib.php'); +/** + * Activities in progress renderer. + * + * @package assessfreqreport_activities_in_progress + * @author Simon Thornett + * @copyright Catalyst IT, 2024 + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class renderer extends plugin_renderer_base { - public function render_report($data) { + /** + * Report renderer. + * + * @param array $data + * @return array|bool|string + * @throws coding_exception + * @throws dml_exception + * @throws moodle_exception + */ + public function render_report(array $data): string { // Charts array for unit testing. $charts = []; @@ -58,7 +76,7 @@ public function render_report($data) { 'local_assessfreq/card', [ 'header' => get_string('inprogress:head', 'assessfreqreport_activities_in_progress'), - 'contents' => $contents + 'contents' => $contents, ] ); @@ -105,6 +123,7 @@ public function render_report($data) { $participantseriesdata = array_values($participantseriesdata); $labels = array_values($labels); + $chart = ''; if ($seriesdata) { $series = new chart_series($seriestitle, $seriesdata); $participantseries = new chart_series($participantseries, $participantseriesdata); @@ -178,7 +197,7 @@ public function render_report($data) { 'local_assessfreq/card', [ 'header' => get_string('summarychart:head', 'assessfreqreport_activities_in_progress'), - 'contents' => $contents + 'contents' => $contents, ] ); @@ -187,7 +206,7 @@ public function render_report($data) { 'local_assessfreq/card', [ 'header' => get_string('inprogresstable:head', 'assessfreqreport_activities_in_progress'), - 'contents' => 'No data' + 'contents' => 'No data', ] ); @@ -213,7 +232,7 @@ public function render_report($data) { true ); // Only get modules with the "get_inprogress_count" method as only these display on the report. - $modules = get_modules($preferencemodule, 'get_inprogress_count'); + $modules = local_assessfreq_get_modules($preferencemodule, 'get_inprogress_count'); if (PHPUNIT_TEST) { return $charts; @@ -235,7 +254,7 @@ public function render_report($data) { 'id' => 'assessfreqreport-activities-in-progress', 'name' => get_string('inprogresstable:head', 'assessfreqreport_activities_in_progress'), 'rows' => [$rows[$preferencerows] => 'true'], - ] + ], ] ); } @@ -249,8 +268,6 @@ public function render_report($data) { * @param int $page The page number of results. * @param string $sorton The value to sort by. * @param string $direction The direction to sort. - * @param int $hoursahead Amount of time in hours to look ahead for activity starting. - * @param int $hoursbehind Amount of time in hours to look behind for activity starting. * @return string $output HTML for the table. */ public function render_activities_inprogress_table( @@ -262,9 +279,9 @@ public function render_activities_inprogress_table( $now = time(); $hoursahead = (int)get_user_preferences('assessfreqreport_activities_in_progress_hoursahead_preference', 8); $hoursbehind = (int)get_user_preferences('assessfreqreport_activities_in_progress_hoursbehind_preference', 1); - $sources = get_sources(); + $sources = local_assessfreq_get_sources(); $inprogress = []; - /* @var $source source_base */ + /* @var $source source_base for accessing the source class */ foreach ($sources as $source) { if (method_exists($source, 'get_inprogress_data')) { $inprogress[] = $source->get_inprogress_data($now, $hoursahead, $hoursbehind); diff --git a/report/activities_in_progress/classes/report.php b/report/activities_in_progress/classes/report.php index 74c330b6..60bdbfec 100644 --- a/report/activities_in_progress/classes/report.php +++ b/report/activities_in_progress/classes/report.php @@ -28,43 +28,54 @@ use local_assessfreq\report_base; use local_assessfreq\source_base; +/** + * Main report class. + * + * @package assessfreqreport_activities_in_progress + * @author Simon Thornett + * @copyright Catalyst IT, 2024 + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class report extends report_base { + /** + * Weight is used to define the sort order. + */ const WEIGHT = 30; /** - * @inheritDoc + * {@inheritDoc} */ - public function get_name() : string { + public function get_name(): string { return get_string("tab:name", "assessfreqreport_activities_in_progress"); } /** - * @inheritDoc + * {@inheritDoc} */ - public function get_tab_weight() : int { + public function get_tab_weight(): int { return self::WEIGHT; } /** - * @inheritDoc + * {@inheritDoc} */ - public function get_tablink() : string { + public function get_tablink(): string { return 'activities_in_progress'; } /** - * @inheritDoc + * {@inheritDoc} */ - public function has_access() : bool { + public function has_access(): bool { global $PAGE; return has_capability('assessfreqreport/activities_in_progress:view', $PAGE->context); } /** - * @inheritDoc + * {@inheritDoc} */ - public function get_contents() : string { + public function get_contents(): string { global $PAGE; $data = []; @@ -75,12 +86,12 @@ public function get_contents() : string { $modulepreference = json_decode( get_user_preferences('assessfreqreport_activities_in_progress_modules_preference', '["all"]') ); - $sources = get_sources(); + $sources = local_assessfreq_get_sources(); $hoursahead = (int)get_user_preferences('assessfreqreport_activities_in_progress_hoursahead_preference', 8); $hoursbehind = (int)get_user_preferences('assessfreqreport_activities_in_progress_hoursbehind_preference', 1); foreach ($sources as $source) { - /* @var $source source_base */ + /* @var $source source_base for accessing the source class */ if (!in_array('all', $modulepreference) && !in_array($source->get_module(), $modulepreference)) { continue; } @@ -104,9 +115,9 @@ public function get_contents() : string { } /** - * @inheritDoc + * {@inheritDoc} */ - protected function get_required_js() : void { + protected function get_required_js(): void { global $PAGE; $PAGE->requires->js_call_amd( @@ -117,7 +128,7 @@ protected function get_required_js() : void { } /** - * @inheritDoc + * {@inheritDoc} */ protected function get_required_css(): void { global $PAGE; diff --git a/report/activities_in_progress/lang/en/assessfreqreport_activities_in_progress.php b/report/activities_in_progress/lang/en/assessfreqreport_activities_in_progress.php index 4c5857bb..6d5d8479 100644 --- a/report/activities_in_progress/lang/en/assessfreqreport_activities_in_progress.php +++ b/report/activities_in_progress/lang/en/assessfreqreport_activities_in_progress.php @@ -23,58 +23,58 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$string['pluginname'] = 'Report - Activities in Progress'; - -$string['tab:name'] = 'Activities in Progress'; - $string['activities_in_progress:view'] = 'Ability to view the activities in progress report.'; - -$string['settings:chartheading'] = 'Chart settings'; -$string['settings:chartheading_desc'] = 'These settings allow you to configure the the settings used in the charts and graphs'; -$string['settings:notloggedincolor'] = 'Not logged in color'; -$string['settings:notloggedincolor_desc'] = 'Select color to display for not logged in users in charts'; -$string['settings:loggedincolor'] = 'Logged in color'; -$string['settings:loggedincolor_desc'] = 'Select color to display for logged in users in charts'; -$string['settings:inprogresscolor'] = 'In progress color'; -$string['settings:inprogresscolor_desc'] = 'Select color to display for in progress users in charts'; -$string['settings:finishedcolor'] = 'Finished color'; -$string['settings:finishedcolor_desc'] = 'Select color to display for finished users in charts'; -$string['settings:graphsheading'] = 'Graph settings'; -$string['settings:graphsheading_desc'] = 'Specify the graph settings for each graph report'; - -$string['filter:selectassessment'] = 'Select assessment type'; $string['filter:closeapply'] = 'Close and apply'; $string['filter:header'] = 'Filters'; -$string['filter:submit'] = 'Filter'; $string['filter:hours0'] = 'Now'; $string['filter:hours1'] = '1 Hour'; $string['filter:hours4'] = '4 Hours'; $string['filter:hours8'] = '8 Hours'; $string['filter:hoursahead'] = 'Hours ahead'; $string['filter:hoursbehind'] = 'Hours behind'; - +$string['filter:selectassessment'] = 'Select assessment type'; +$string['filter:submit'] = 'Filter'; $string['inprogress'] = 'In progress'; $string['inprogress:head'] = 'In progress'; +$string['inprogresstable:activity'] = 'Activity'; +$string['inprogresstable:course'] = 'Course'; +$string['inprogresstable:dashboard'] = 'Dashboard'; +$string['inprogresstable:head'] = 'Activies in progress'; +$string['inprogresstable:participants'] = 'Participants (Overrides)'; +$string['inprogresstable:timeclose'] = 'Time close'; +$string['inprogresstable:timelimit'] = 'Time limit'; +$string['inprogresstable:timeopen'] = 'Time open'; +$string['pluginname'] = 'Report - Activities in Progress'; + +$string['report:usage_guidlines'] = ''; +$string['settings:chartheading'] = 'Chart settings'; +$string['settings:chartheading_desc'] = 'These settings allow you to configure the the settings used in the charts and graphs'; +$string['settings:finishedcolor'] = 'Finished color'; +$string['settings:finishedcolor_desc'] = 'Select color to display for finished users in charts'; +$string['settings:graphsheading'] = 'Graph settings'; +$string['settings:graphsheading_desc'] = 'Specify the graph settings for each graph report'; +$string['settings:inprogresscolor'] = 'In progress color'; +$string['settings:inprogresscolor_desc'] = 'Select color to display for in progress users in charts'; +$string['settings:loggedincolor'] = 'Logged in color'; +$string['settings:loggedincolor_desc'] = 'Select color to display for logged in users in charts'; +$string['settings:notloggedincolor'] = 'Not logged in color'; +$string['settings:notloggedincolor_desc'] = 'Select color to display for not logged in users in charts'; +$string['summarychart:finished'] = 'Finished'; +$string['summarychart:head'] = 'Participant summary'; +$string['summarychart:inprogress'] = 'In progress'; +$string['summarychart:loggedin'] = 'Logged in'; +$string['summarychart:notloggedin'] = 'Not logged in'; +$string['summarychart:participants'] = 'Students'; +$string['tab:name'] = 'Activities in Progress'; + + + + +$string['upcomingchart:activities'] = 'Activities'; $string['upcomingchart:head'] = 'Upcoming activities starting'; $string['upcomingchart:inprogressdatetime'] = '%H:00'; -$string['upcomingchart:activities'] = 'Activities'; $string['upcomingchart:participants'] = 'Students'; -$string['summarychart:head'] = 'Participant summary'; -$string['summarychart:participants'] = 'Students'; -$string['summarychart:notloggedin'] = 'Not logged in'; -$string['summarychart:loggedin'] = 'Logged in'; -$string['summarychart:inprogress'] = 'In progress'; -$string['summarychart:finished'] = 'Finished'; -$string['inprogresstable:head'] = 'Activies in progress'; -$string['inprogresstable:activity'] = 'Activity'; -$string['inprogresstable:course'] = 'Course'; -$string['inprogresstable:timelimit'] = 'Time limit'; -$string['inprogresstable:timeopen'] = 'Time open'; -$string['inprogresstable:timeclose'] = 'Time close'; -$string['inprogresstable:participants'] = 'Participants (Overrides)'; -$string['inprogresstable:dashboard'] = 'Dashboard'; -$string['report:usage_guidlines'] = ''; diff --git a/report/activities_in_progress/lib.php b/report/activities_in_progress/lib.php index 373555de..883a1fe5 100644 --- a/report/activities_in_progress/lib.php +++ b/report/activities_in_progress/lib.php @@ -15,6 +15,8 @@ // along with Moodle. If not, see . /** + * Library functions. + * * @package assessfreqreport_activities_in_progress * @copyright 2024 Simon Thornett * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -25,7 +27,7 @@ * * @return array */ -function assessfreqreport_activities_in_progress_user_preferences() : array { +function assessfreqreport_activities_in_progress_user_preferences(): array { $preferences['assessfreqreport_activities_in_progress_modules_preference'] = [ 'null' => NULL_NOT_ALLOWED, @@ -67,7 +69,7 @@ function assessfreqreport_activities_in_progress_user_preferences() : array { * @param array $args * @return string $o Form HTML. */ -function assessfreqreport_activities_in_progress_output_fragment_get_in_progress_table(array $args) : string { +function assessfreqreport_activities_in_progress_output_fragment_get_in_progress_table(array $args): string { global $PAGE; require_capability('assessfreqreport/activities_in_progress:view', $PAGE->context); diff --git a/report/activities_in_progress/styles.css b/report/activities_in_progress/styles.css index dd9125ba..bd5ae006 100644 --- a/report/activities_in_progress/styles.css +++ b/report/activities_in_progress/styles.css @@ -1,3 +1,3 @@ #local-assessfreq-report-activities-in-progress .chart-area .chart-image { - width: 100% !important; -} \ No newline at end of file + width: 100%; +} diff --git a/report/activities_in_progress/templates/activities-in-progress-table.mustache b/report/activities_in_progress/templates/activities-in-progress-table.mustache index 34d7bd2f..912ecad0 100644 --- a/report/activities_in_progress/templates/activities-in-progress-table.mustache +++ b/report/activities_in_progress/templates/activities-in-progress-table.mustache @@ -33,15 +33,17 @@
- - {{^iscourse}} - - {{/iscourse}} - - - - - + + + {{^iscourse}} + + {{/iscourse}} + + + + + + {{#activities}} diff --git a/report/activities_in_progress/templates/activities-in-progress.mustache b/report/activities_in_progress/templates/activities-in-progress.mustache index f2ce8b59..7ba140b0 100644 --- a/report/activities_in_progress/templates/activities-in-progress.mustache +++ b/report/activities_in_progress/templates/activities-in-progress.mustache @@ -20,9 +20,7 @@ Report Summary template. Example context (json): - { - - } + {} }}
diff --git a/report/activities_in_progress/templates/filter-hoursahead.mustache b/report/activities_in_progress/templates/filter-hoursahead.mustache index 4f6ae0e8..011084e3 100644 --- a/report/activities_in_progress/templates/filter-hoursahead.mustache +++ b/report/activities_in_progress/templates/filter-hoursahead.mustache @@ -35,7 +35,7 @@
{{#str}} inprogresstable:activity, assessfreqreport_activities_in_progress {{/str}}{{#str}} inprogresstable:course, assessfreqreport_activities_in_progress {{/str}}{{#str}} inprogresstable:timeopen, assessfreqreport_activities_in_progress {{/str}}{{#str}} inprogresstable:timeclose, assessfreqreport_activities_in_progress {{/str}}{{#str}} inprogresstable:timelimit, assessfreqreport_activities_in_progress {{/str}}{{#str}} inprogresstable:participants, assessfreqreport_activities_in_progress {{/str}}{{#str}} inprogresstable:dashboard, assessfreqreport_activities_in_progress {{/str}}
{{#str}} inprogresstable:activity, assessfreqreport_activities_in_progress {{/str}}{{#str}} inprogresstable:course, assessfreqreport_activities_in_progress {{/str}}{{#str}} inprogresstable:timeopen, assessfreqreport_activities_in_progress {{/str}}{{#str}} inprogresstable:timeclose, assessfreqreport_activities_in_progress {{/str}}{{#str}} inprogresstable:timelimit, assessfreqreport_activities_in_progress {{/str}}{{#str}} inprogresstable:participants, assessfreqreport_activities_in_progress {{/str}}{{#str}} inprogresstable:dashboard, assessfreqreport_activities_in_progress {{/str}}
diff --git a/report/heatmap/templates/download.mustache b/report/heatmap/templates/download.mustache index bcc29ca4..a7e3a1f8 100644 --- a/report/heatmap/templates/download.mustache +++ b/report/heatmap/templates/download.mustache @@ -18,6 +18,9 @@ @template assessfreqreport_heatmap/download Download template. + + Example context (json): + {} }}
diff --git a/report/heatmap/templates/filter-metric.mustache b/report/heatmap/templates/filter-metric.mustache index d476cfbc..f5f9566c 100644 --- a/report/heatmap/templates/filter-metric.mustache +++ b/report/heatmap/templates/filter-metric.mustache @@ -32,8 +32,8 @@ {{# str }} filter:metric:students, assessfreqreport_heatmap {{/ str }} - + diff --git a/report/heatmap/templates/filter-type.mustache b/report/heatmap/templates/filter-type.mustache index b2050bce..20ab4078 100644 --- a/report/heatmap/templates/filter-type.mustache +++ b/report/heatmap/templates/filter-type.mustache @@ -33,8 +33,8 @@ {{/filters.modules}} - + diff --git a/report/heatmap/templates/filter-year.mustache b/report/heatmap/templates/filter-year.mustache index 3911f315..2e32526d 100644 --- a/report/heatmap/templates/filter-year.mustache +++ b/report/heatmap/templates/filter-year.mustache @@ -33,8 +33,8 @@ {{/filters.years}} - + diff --git a/report/heatmap/templates/filters.mustache b/report/heatmap/templates/filters.mustache index a5ad206e..596b34a3 100644 --- a/report/heatmap/templates/filters.mustache +++ b/report/heatmap/templates/filters.mustache @@ -18,6 +18,9 @@ @template assessfreqreport_heatmap/filters This template renders all of the filters. + + Example context (json): + {} }}
diff --git a/report/heatmap/version.php b/report/heatmap/version.php index 8bca48b1..7826af65 100644 --- a/report/heatmap/version.php +++ b/report/heatmap/version.php @@ -28,6 +28,6 @@ $plugin->component = 'assessfreqreport_heatmap'; $plugin->release = '2024040300'; $plugin->version = 2024040300; -$plugin->requires = 2022041906; // Requires 4.0 +$plugin->requires = 2022041906; // Requires 4.0. $plugin->supported = [400, 401]; $plugin->maturity = MATURITY_STABLE; diff --git a/report/student_search/classes/output/renderer.php b/report/student_search/classes/output/renderer.php index 64266e35..d544759b 100644 --- a/report/student_search/classes/output/renderer.php +++ b/report/student_search/classes/output/renderer.php @@ -15,7 +15,7 @@ // along with Moodle. If not, see . /** - * Renderer. + * Student search renderer. * * @package assessfreqreport_student_search * @author Simon Thornett @@ -27,6 +27,14 @@ use plugin_renderer_base; +/** + * Student search renderer. + * + * @package assessfreqreport_student_search + * @author Simon Thornett + * @copyright Catalyst IT, 2024 + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class renderer extends plugin_renderer_base { /** @@ -34,7 +42,7 @@ class renderer extends plugin_renderer_base { * * @return bool|string */ - public function render_report() { + public function render_report(): bool|string { $preferencerows = get_user_preferences('local_assessfreq_student_search_table_rows_preference', 20); $rows = [ @@ -64,7 +72,7 @@ public function render_report() { 'id' => 'assessfreqreport-student-search', 'name' => get_string('student_search:head', 'assessfreqreport_student_search'), 'rows' => [$rows[$preferencerows] => 'true'], - ] + ], ] ); } diff --git a/report/student_search/classes/output/user_table.php b/report/student_search/classes/output/user_table.php index 97a8b09f..94ec4dfe 100644 --- a/report/student_search/classes/output/user_table.php +++ b/report/student_search/classes/output/user_table.php @@ -25,55 +25,70 @@ namespace assessfreqreport_student_search\output; +defined('MOODLE_INTERNAL') || die(); + require_once($CFG->libdir . '/tablelib.php'); use assessfreqsource_quiz\Source; +use coding_exception; +use html_writer; use local_assessfreq\frequency; +use moodle_exception; +use moodle_url; use renderable; +use stdClass; use table_sql; +/** + * Renderable table for student attempt statuses. + * + * @package assessfreqreport_student_search + * @author Simon Thornett + * @copyright Catalyst IT, 2024 + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class user_table extends table_sql implements renderable { /** * Ammount of time in hours for lookahead values. * * @var int $hoursahead. */ - private $hoursahead; + private int $hoursahead; /** * Ammount of time in hours for lookbehind values. * * @var int $hoursahead. */ - private $hoursbehind; + private int $hoursbehind; /** * The timestamp used when getting quiz data. * * @var int $now. */ - private $now; + private int $now; /** * * @var string $search The string to search for in the table data. */ - private $search; + private string $search; /** * @var string[] Extra fields to display. */ - protected $extrafields; + protected array $extrafields; /** - * report_table constructor. + * Report table contrustor. * - * @param string $baseurl Base URL of the page that contains the table. - * @param int $contextid The context id for the context the table is being displayed in. - * @param string $search The string to search for in the table. - * @param int $page the page number for pagination. - * - * @throws \coding_exception + * @param string $baseurl + * @param int $contextid + * @param string $search + * @param int $page + * @param int $now + * @throws coding_exception */ public function __construct( string $baseurl, @@ -87,9 +102,6 @@ public function __construct( $this->hoursahead = (int)get_user_preferences('assessfreqreport_student_search_hoursahead_preference', 8); $this->hoursbehind = (int)get_user_preferences('assessfreqreport_student_search_hoursbehind_preference', 1); - $this->hoursahead = 8; - $this->hoursbehind = 8; - $this->search = $search; $this->set_attribute('id', 'local_assessfreq_ackreport_table'); $this->set_attribute('class', 'generaltable generalbox'); @@ -128,9 +140,9 @@ public function __construct( /** * Get content for title column. * - * @param \stdClass $row + * @param stdClass $row * @return string html used to display the video field. - * @throws \moodle_exception + * @throws moodle_exception */ public function col_fullname($row): string { global $OUTPUT; @@ -142,15 +154,15 @@ public function col_fullname($row): string { * Get content for time start column. * Displays the user attempt start time. * - * @param \stdClass $row + * @param stdClass $row * @return string html used to display the field. */ - public function col_timestart($row) { + public function col_timestart(stdClass $row): string { if ($row->timestart == 0) { - $content = \html_writer::span(get_string('student_search:na', 'assessfreqreport_student_search')); + $content = html_writer::span(get_string('student_search:na', 'assessfreqreport_student_search')); } else { $datetime = userdate($row->timestart, get_string('student_search:trenddatetime', 'assessfreqreport_student_search')); - $content = \html_writer::span($datetime); + $content = html_writer::span($datetime); } return $content; @@ -160,19 +172,19 @@ public function col_timestart($row) { * Get content for time finish column. * Displays the user attempt finish time. * - * @param \stdClass $row + * @param stdClass $row * @return string html used to display the field. */ - public function col_timefinish($row) { + public function col_timefinish(stdClass $row): string { if ($row->timefinish == 0 && $row->timestart == 0) { - $content = \html_writer::span(get_string('student_search:na', 'assessfreqreport_student_search')); + $content = html_writer::span(get_string('student_search:na', 'assessfreqreport_student_search')); } else if ($row->timefinish == 0 && $row->timestart > 0) { $time = $row->timestart + $row->timelimit; $datetime = userdate($time, get_string('student_search:trenddatetime', 'assessfreqreport_student_search')); - $content = \html_writer::span($datetime, 'local-assessfreq-disabled'); + $content = html_writer::span($datetime, 'local-assessfreq-disabled'); } else { $datetime = userdate($row->timefinish, get_string('student_search:trenddatetime', 'assessfreqreport_student_search')); - $content = \html_writer::span($datetime); + $content = html_writer::span($datetime); } return $content; @@ -182,10 +194,12 @@ public function col_timefinish($row) { * Get content for state column. * Displays the users state in the quiz. * - * @param \stdClass $row + * @param stdClass $row * @return string html used to display the field. */ - public function col_state($row) { + public function col_state(stdClass $row): string { + + $color = ''; if ($row->state == 'notloggedin') { $color = 'background: ' . get_config('assessfreqreport_student_search', 'notloggedincolor'); } else if ($row->state == 'loggedin') { @@ -202,7 +216,7 @@ public function col_state($row) { $color = 'background: ' . get_config('assessfreqreport_student_search', 'finishedcolor'); } - $content = \html_writer::span('', 'local-assessfreq-status-icon', ['style' => $color]); + $content = html_writer::span('', 'local-assessfreq-status-icon', ['style' => $color]); $content .= get_string('student_search:'.$row->state, 'assessfreqreport_student_search'); return $content; @@ -245,10 +259,10 @@ protected function get_common_columns(): array { /** * Return HTML for common column actions. * - * @param \stdClass $row + * @param stdClass $row * @return string */ - protected function get_common_column_actions(\stdClass $row): string { + protected function get_common_column_actions(stdClass $row): string { global $OUTPUT; $actions = ''; if ( @@ -259,7 +273,7 @@ protected function get_common_column_actions(\stdClass $row): string { || $row->state == 'overdue' ) { $classes = 'action-icon'; - $attempturl = new \moodle_url('/mod/quiz/review.php', ['attempt' => $row->attemptid]); + $attempturl = new moodle_url('/mod/quiz/review.php', ['attempt' => $row->attemptid]); $attributes = [ 'class' => $classes, 'id' => 'tool-assessfreq-attempt-' . $row->id, @@ -276,11 +290,11 @@ protected function get_common_column_actions(\stdClass $row): string { ]; } $icon = $OUTPUT->render(new \pix_icon('i/search', '')); - $actions .= \html_writer::link($attempturl, $icon, $attributes); + $actions .= html_writer::link($attempturl, $icon, $attributes); - $profileurl = new \moodle_url('/user/profile.php', ['id' => $row->id]); + $profileurl = new moodle_url('/user/profile.php', ['id' => $row->id]); $icon = $OUTPUT->render(new \pix_icon('i/completion_self', '')); - $actions .= \html_writer::link($profileurl, $icon, [ + $actions .= html_writer::link($profileurl, $icon, [ 'class' => 'action-icon', 'id' => 'tool-assessfreq-profile-' . $row->id, 'data-toggle' => 'tooltip', @@ -288,9 +302,9 @@ protected function get_common_column_actions(\stdClass $row): string { 'title' => get_string('student_search:userprofile', 'assessfreqreport_student_search'), ]); - $logurl = new \moodle_url('/report/log/user.php', ['id' => $row->id, 'course' => 1, 'mode' => 'all']); + $logurl = new moodle_url('/report/log/user.php', ['id' => $row->id, 'course' => 1, 'mode' => 'all']); $icon = $OUTPUT->render(new \pix_icon('i/report', '')); - $actions .= \html_writer::link($logurl, $icon, [ + $actions .= html_writer::link($logurl, $icon, [ 'class' => 'action-icon', 'id' => 'tool-assessfreq-log-' . $row->id, 'data-toggle' => 'tooltip', @@ -307,47 +321,45 @@ protected function get_common_column_actions(\stdClass $row): string { * the list has the potential to increase in the future and we don't want to have to remember to add * a new method to this class. We also don't want to pollute this class with unnecessary methods. * - * @param string $colname The column name - * @param \stdClass $data + * @param string $column The column name + * @param stdClass $row * @return string */ - public function other_cols($colname, $data) { + public function other_cols($column, $row): string { // Do not process if it is not a part of the extra fields. - if (!in_array($colname, $this->extrafields)) { + if (!in_array($column, $this->extrafields)) { return ''; } - return s($data->{$colname}); + return s($row->{$column}); } /** * Displays quiz name * - * @param \stdClass $row + * @param stdClass $row * @return string html used to display the field. */ - public function col_quizname($row) { - - $quizurl = new \moodle_url('/mod/quiz/view.php', ['id' => $row->quizinstance]); - $quizlink = \html_writer::link($quizurl, format_string($row->quizname, true)); + public function col_quizname(stdClass $row): string { - return $quizlink; + $quizurl = new moodle_url('/mod/quiz/view.php', ['id' => $row->quizinstance]); + return html_writer::link($quizurl, format_string($row->quizname, true)); } /** * Get content for time open column. * Displays when the user attempt opens. * - * @param \stdClass $row + * @param stdClass $row * @return string html used to display the field. */ - public function col_timeopen($row) { + public function col_timeopen(stdClass $row): string { $datetime = userdate($row->timeopen, get_string('student_search:trenddatetime', 'assessfreqreport_student_search')); if ($row->timeopen != $row->quiztimeopen) { - $content = \html_writer::span($datetime, 'local-assessfreq-override-status'); + $content = html_writer::span($datetime, 'local-assessfreq-override-status'); } else { - $content = \html_writer::span($datetime); + $content = html_writer::span($datetime); } return $content; @@ -357,16 +369,16 @@ public function col_timeopen($row) { * Get content for time close column. * Displays when the user attempt closes. * - * @param \stdClass $row + * @param stdClass $row * @return string html used to display the field. */ - public function col_timeclose($row) { + public function col_timeclose(stdClass $row): string { $datetime = userdate($row->timeclose, get_string('student_search:trenddatetime', 'assessfreqreport_student_search')); if ($row->timeclose != $row->quiztimeclose) { - $content = \html_writer::span($datetime, 'local-assessfreq-override-status'); + $content = html_writer::span($datetime, 'local-assessfreq-override-status'); } else { - $content = \html_writer::span($datetime); + $content = html_writer::span($datetime); } return $content; @@ -376,19 +388,19 @@ public function col_timeclose($row) { * Get content for time limit column. * Displays the time the user has to finsih the quiz. * - * @param \stdClass $row + * @param stdClass $row * @return string html used to display the field. */ - public function col_timelimit($row) { + public function col_timelimit(stdClass $row): string { if ($row->timelimit == '0') { return '-'; } $timelimit = format_time($row->timelimit); if ($row->timelimit != $row->quiztimelimit) { - $content = \html_writer::span($timelimit, 'local-assessfreq-override-status'); + $content = html_writer::span($timelimit, 'local-assessfreq-override-status'); } else { - $content = \html_writer::span($timelimit); + $content = html_writer::span($timelimit); } return $content; @@ -398,26 +410,12 @@ public function col_timelimit($row) { * Get content for actions column. * Displays the actions for the user. * - * @param \stdClass $row + * @param stdClass $row * @return string html used to display the field. */ - public function col_actions($row) { - global $OUTPUT; - - $manage = ''; - - $icon = $OUTPUT->render(new \pix_icon('i/duration', '')); - //$manage .= \html_writer::link('#', $icon, [ - // 'class' => 'action-icon override', - // 'id' => 'tool-assessfreq-override-' . $row->id . '-' . $row->quiz, - // 'data-toggle' => 'tooltip', - // 'data-placement' => 'top', - // 'title' => get_string('student_search:useroverride', 'assessfreqreport_student_search'), - //]); - - $manage .= $this->get_common_column_actions($row); + public function col_actions(stdClass $row): string { - return $manage; + return $this->get_common_column_actions($row); } /** @@ -463,7 +461,7 @@ public function sort(array $quizzes): array { * @param int $pagesize size of page for paginated displayed table. * @param bool $useinitialsbar do you want to use the initials bar. */ - public function query_db($pagesize, $useinitialsbar = false) { + public function query_db($pagesize, $useinitialsbar = false): void { global $CFG, $DB; $maxlifetime = $CFG->sessiontimeout; @@ -625,7 +623,7 @@ public function query_db($pagesize, $useinitialsbar = false) { * @param int $index numerical index of the column. * @return string HTML fragment. */ - protected function show_hide_link($column, $index) { + protected function show_hide_link($column, $index): string { return ''; } } diff --git a/report/student_search/classes/report.php b/report/student_search/classes/report.php index ecb56356..9887e363 100644 --- a/report/student_search/classes/report.php +++ b/report/student_search/classes/report.php @@ -28,43 +28,54 @@ use context_system; use local_assessfreq\report_base; +/** + * Main report class. + * + * @package assessfreqreport_student_search + * @author Simon Thornett + * @copyright Catalyst IT, 2024 + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ class report extends report_base { + /** + * Weight is used to define the sort order. + */ const WEIGHT = 50; /** - * @inheritDoc + * {@inheritDoc} */ - public function get_name() : string { + public function get_name(): string { return get_string("tab:name", "assessfreqreport_student_search"); } /** - * @inheritDoc + * {@inheritDoc} */ - public function get_tab_weight() : int { + public function get_tab_weight(): int { return self::WEIGHT; } /** - * @inheritDoc + * {@inheritDoc} */ - public function get_tablink() : string { + public function get_tablink(): string { return 'student_search'; } /** - * @inheritDoc + * {@inheritDoc} */ - public function has_access() : bool { + public function has_access(): bool { global $PAGE; return has_capability('assessfreqreport/student_search:view', $PAGE->context); } /** - * @inheritDoc + * {@inheritDoc} */ - public function get_contents() : string { + public function get_contents(): string { global $PAGE; $renderer = $PAGE->get_renderer("assessfreqreport_student_search"); @@ -73,9 +84,9 @@ public function get_contents() : string { } /** - * @inheritDoc + * {@inheritDoc} */ - protected function get_required_js() : void { + protected function get_required_js(): void { global $PAGE; $PAGE->requires->js_call_amd( @@ -86,7 +97,7 @@ protected function get_required_js() : void { } /** - * @inheritDoc + * {@inheritDoc} */ protected function get_required_css(): void { global $PAGE; diff --git a/report/student_search/lang/en/assessfreqreport_student_search.php b/report/student_search/lang/en/assessfreqreport_student_search.php index 95865dd4..706e414c 100644 --- a/report/student_search/lang/en/assessfreqreport_student_search.php +++ b/report/student_search/lang/en/assessfreqreport_student_search.php @@ -17,59 +17,59 @@ /** * Lang file. * - * @package assessfreqreport_summary_graphs + * @package assessfreqreport_student_search * @author Simon Thornett * @copyright Catalyst IT, 2024 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$string['pluginname'] = 'Report - Student Search'; - -$string['tab:name'] = 'Student Search'; - -$string['student_search:head'] = 'Student attempt status'; -$string['student_search:view'] = 'Ability to view the student search report.'; - -$string['settings:graphsheading'] = 'Chart settings'; -$string['settings:graphsheading_desc'] = 'These settings allow you to configure the the settings used in the charts and graphs'; -$string['settings:notloggedincolor'] = 'Not logged in color'; -$string['settings:notloggedincolor_desc'] = 'Select color to display for not logged in users in charts'; -$string['settings:loggedincolor'] = 'Logged in color'; -$string['settings:loggedincolor_desc'] = 'Select color to display for logged in users in charts'; -$string['settings:inprogresscolor'] = 'In progress color'; -$string['settings:inprogresscolor_desc'] = 'Select color to display for in progress users in charts'; -$string['settings:finishedcolor'] = 'Finished color'; -$string['settings:finishedcolor_desc'] = 'Select color to display for finished users in charts'; - $string['filter:header'] = 'Filters'; -$string['filter:submit'] = 'Filter'; $string['filter:hours0'] = 'Now'; $string['filter:hours1'] = '1 Hour'; $string['filter:hours4'] = '4 Hours'; $string['filter:hours8'] = '8 Hours'; $string['filter:hoursahead'] = 'Hours ahead'; $string['filter:hoursbehind'] = 'Hours behind'; +$string['filter:submit'] = 'Filter'; +$string['pluginname'] = 'Report - Student Search'; $string['report:usage_guidlines'] = ''; - -$string['student_search:quiz'] = 'Quiz'; -$string['student_search:na'] = 'N/A'; -$string['student_search:trenddatetime'] = '%H:%M, %d-%m-%y'; +$string['settings:finishedcolor'] = 'Finished color'; +$string['settings:finishedcolor_desc'] = 'Select color to display for finished users in charts'; +$string['settings:graphsheading'] = 'Chart settings'; +$string['settings:graphsheading_desc'] = 'These settings allow you to configure the the settings used in the charts and graphs'; +$string['settings:inprogresscolor'] = 'In progress color'; +$string['settings:inprogresscolor_desc'] = 'Select color to display for in progress users in charts'; +$string['settings:loggedincolor'] = 'Logged in color'; +$string['settings:loggedincolor_desc'] = 'Select color to display for logged in users in charts'; +$string['settings:notloggedincolor'] = 'Not logged in color'; +$string['settings:notloggedincolor_desc'] = 'Select color to display for not logged in users in charts'; $string['student_search:abandoned'] = 'Abandoned'; -$string['student_search:notloggedin'] = 'Not logged in'; -$string['student_search:loggedin'] = 'Logged in'; -$string['student_search:inprogress'] = 'In progress'; +$string['student_search:actions'] = 'Actions'; $string['student_search:finished'] = 'Finished'; -$string['student_search:uploadpending'] = 'Upload pending'; +$string['student_search:head'] = 'Student attempt status'; +$string['student_search:inprogress'] = 'In progress'; +$string['student_search:loggedin'] = 'Logged in'; +$string['student_search:na'] = 'N/A'; +$string['student_search:notloggedin'] = 'Not logged in'; $string['student_search:overdue'] = 'Overdue'; -$string['student_search:useroverride'] = 'Add user override'; -$string['student_search:quiztimeopen'] = 'Open time'; +$string['student_search:quiz'] = 'Quiz'; $string['student_search:quiztimeclose'] = 'Close time'; +$string['student_search:quiztimefinish'] = 'Finish'; $string['student_search:quiztimelimit'] = 'Time limit'; +$string['student_search:quiztimeopen'] = 'Open time'; $string['student_search:quiztimestart'] = 'Start'; -$string['student_search:quiztimefinish'] = 'Finish'; $string['student_search:status'] = 'Status'; -$string['student_search:actions'] = 'Actions'; -$string['student_search:userlogs'] = 'View user logs'; +$string['student_search:trenddatetime'] = '%H:%M, %d-%m-%y'; +$string['student_search:uploadpending'] = 'Upload pending'; $string['student_search:userattempt'] = 'View user attempt'; -$string['student_search:userprofile'] = 'View user profile'; \ No newline at end of file +$string['student_search:userlogs'] = 'View user logs'; +$string['student_search:useroverride'] = 'Add user override'; +$string['student_search:userprofile'] = 'View user profile'; +$string['student_search:view'] = 'Ability to view the student search report.'; +$string['tab:name'] = 'Student Search'; + + + + + diff --git a/report/student_search/lib.php b/report/student_search/lib.php index 74e669a9..f44a1ba2 100644 --- a/report/student_search/lib.php +++ b/report/student_search/lib.php @@ -1,5 +1,4 @@ . /** + * Library functions. + * * @package assessfreqreport_student_search * @copyright 2024 Simon Thornett * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -70,7 +71,7 @@ function assessfreqreport_student_search_user_preferences(): array { * @param array $args * @return string $o Form HTML. */ -function assessfreqreport_student_search_output_fragment_get_student_search_table($args): string { +function assessfreqreport_student_search_output_fragment_get_student_search_table(array $args): string { global $CFG, $PAGE; $context = $args['context']; diff --git a/report/student_search/templates/filter-hoursahead.mustache b/report/student_search/templates/filter-hoursahead.mustache index e9add1a7..ca829fe0 100644 --- a/report/student_search/templates/filter-hoursahead.mustache +++ b/report/student_search/templates/filter-hoursahead.mustache @@ -35,7 +35,7 @@