From a9577d3af1a18b72fdd5c7d5690acb926625694d Mon Sep 17 00:00:00 2001 From: StoreMikkel <113053176+StoreMikkel@users.noreply.github.com> Date: Mon, 28 Oct 2024 13:45:12 +0100 Subject: [PATCH 01/10] more data shown --- server/moodle/blocks/homework/block_homework.php | 2 +- server/moodle/blocks/homework/templates/data.mustache | 6 ++++-- server/moodle/mod/homework/view.php | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/server/moodle/blocks/homework/block_homework.php b/server/moodle/blocks/homework/block_homework.php index e95829cf5..7a6bb00bb 100644 --- a/server/moodle/blocks/homework/block_homework.php +++ b/server/moodle/blocks/homework/block_homework.php @@ -58,7 +58,7 @@ public function get_content() { foreach($homeworks as $homework) { $tmp = []; $tmp['name'] = $homework->name; - $tmp['duedate'] = $homework->duedate; + $tmp['duedate'] = date('m-d-Y', $homework->duedate); $tmp['intro'] = strip_tags($homework->intro); $tmp['courseTitle'] = $DB->get_field('course', 'fullname', ['id' => $homework->course]); diff --git a/server/moodle/blocks/homework/templates/data.mustache b/server/moodle/blocks/homework/templates/data.mustache index a1c734f12..798b941ef 100644 --- a/server/moodle/blocks/homework/templates/data.mustache +++ b/server/moodle/blocks/homework/templates/data.mustache @@ -28,8 +28,10 @@
{{#data}}
-

name: {{name}}

-

Intro: {{intro}}

+

{{courseTitle}}

+

{{name}}

+

{{duedate}}

+

{{intro}}

{{#files}} File icon diff --git a/server/moodle/mod/homework/view.php b/server/moodle/mod/homework/view.php index ac40e4e61..6384c499f 100644 --- a/server/moodle/mod/homework/view.php +++ b/server/moodle/mod/homework/view.php @@ -80,7 +80,7 @@ $viewobj = new view_page(); $viewobj->canedit = true; -$viewobj->editurl = new moodle_url('/mod/homework/edit.php', ['cmid' => $cm->id]); +$viewobj->editurl = new moodle_url('/mod/homework/edit.php', ['id' => $cm->id]); // Add the actual page content here. echo html_writer::tag('div', 'This is the homework view page', ['class' => 'content']); From fea373f9f51847266c8482751fd504943defc69d Mon Sep 17 00:00:00 2001 From: StoreMikkel <113053176+StoreMikkel@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:10:10 +0100 Subject: [PATCH 02/10] file download homeworkfeed now shows file and user is able to download file by clicking on link --- .../moodle/blocks/homework/block_homework.php | 5 +- server/moodle/mod/homework/lib.php | 51 +++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/server/moodle/blocks/homework/block_homework.php b/server/moodle/blocks/homework/block_homework.php index 7a6bb00bb..1c2929c2b 100644 --- a/server/moodle/blocks/homework/block_homework.php +++ b/server/moodle/blocks/homework/block_homework.php @@ -66,7 +66,7 @@ public function get_content() { //Get ids of homeworkfiles $fileids = []; - $homeworkfiles = $DB->get_records('files_homework', ['files_id'=>$homework->id]); + $homeworkfiles = $DB->get_records('files_homework', ['homework_id'=>$homework->id]); foreach ($homeworkfiles as $homeworkfile) { array_push($fileids, $homeworkfile->files_id); } @@ -89,7 +89,8 @@ public function get_content() { $filearea, $itemid, $filepath, - $filename + $filename, + false ); //Get appropriate icon for file type diff --git a/server/moodle/mod/homework/lib.php b/server/moodle/mod/homework/lib.php index 064e2a390..fcbab38d8 100644 --- a/server/moodle/mod/homework/lib.php +++ b/server/moodle/mod/homework/lib.php @@ -85,3 +85,54 @@ function homework_delete_instance($id) { return true; } + +/** + * Serve the files from the myplugin file areas. + * + * @param stdClass $course the course object + * @param stdClass $cm the course module object + * @param stdClass $context the context + * @param string $filearea the name of the file area + * @param array $args extra arguments (itemid, path) + * @param bool $forcedownload whether or not force download + * @param array $options additional options affecting the file serving + * @return bool false if the file not found, just send the file otherwise and do not return anything + */ +function homework_pluginfile( + $course, + $cm, + $context, + string $filearea, + array $args, + bool $forcedownload, + array $options = [] +): bool { + //Make sure the user is logged in and has access to the module + require_login($course, true); + + // Extract the filename / filepath from the $args array. + $filename = array_pop($args); // The last item in the $args array. + if (empty($args)) { + // $args is empty => the path is '/'. + $filepath = '/'; + } else { + // $args contains the remaining elements of the filepath. + $filepath = '/' . implode('/', $args) . '/'; + } + + $itemid = null; + + // Retrieve the file from the Files API. + $fs = get_file_storage(); + $file = $fs->get_file($context->id, 'homework', $filearea, $itemid, $filepath, $filename); + if (!$file) { + // The file does not exist. + error_log("File not found: Context ID - $context->id, File area - $filearea, Item ID - $itemid, Path - $filepath, Filename - $filename"); + return false; + } + + // Send file to browser with a cache lifetime of 1 day and no filtering. + send_stored_file($file, 86400, 0, $forcedownload, $options); + return true; + +} \ No newline at end of file From 01bc5596c4ccf58711088dbe0c584fb1ff48484e Mon Sep 17 00:00:00 2001 From: StoreMikkel <113053176+StoreMikkel@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:10:59 +0100 Subject: [PATCH 03/10] Update lib.php added inspiration comment --- server/moodle/mod/homework/lib.php | 1 + 1 file changed, 1 insertion(+) diff --git a/server/moodle/mod/homework/lib.php b/server/moodle/mod/homework/lib.php index fcbab38d8..db3121826 100644 --- a/server/moodle/mod/homework/lib.php +++ b/server/moodle/mod/homework/lib.php @@ -87,6 +87,7 @@ function homework_delete_instance($id) { } /** + * Inspiration taken from https://moodledev.io/docs/4.5/apis/subsystems/files * Serve the files from the myplugin file areas. * * @param stdClass $course the course object From c7b388fc7c8441c74a7968dae722484fb3421c1e Mon Sep 17 00:00:00 2001 From: StoreMikkel <113053176+StoreMikkel@users.noreply.github.com> Date: Tue, 29 Oct 2024 13:22:58 +0100 Subject: [PATCH 04/10] show only future homework homeworkfeed now only fetches future homework --- MoodleSQL.sql | 2 +- server/moodle/blocks/homework/block_homework.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/MoodleSQL.sql b/MoodleSQL.sql index ec449338b..7020dcd16 100644 --- a/MoodleSQL.sql +++ b/MoodleSQL.sql @@ -1,4 +1,4 @@ --- -------------------------------------------------------- +mdl_user-- -------------------------------------------------------- -- Host: 127.0.0.1 -- Server version: 11.5.2-MariaDB - mariadb.org binary distribution -- Server OS: Win64 diff --git a/server/moodle/blocks/homework/block_homework.php b/server/moodle/blocks/homework/block_homework.php index 1c2929c2b..75f5ebb16 100644 --- a/server/moodle/blocks/homework/block_homework.php +++ b/server/moodle/blocks/homework/block_homework.php @@ -41,7 +41,8 @@ public function get_content() { global $OUTPUT, $PAGE, $DB; - $homeworks = $DB->get_records('homework'); + $current_time = time(); + $homeworks = $DB->get_records_select('homework', 'duedate > ?', array($current_time) ); $data = []; if ($this->content !== null) { From 652c5ecf1989fdc98eebcc24ec4d0d695eeb8a8a Mon Sep 17 00:00:00 2001 From: StoreMikkel <113053176+StoreMikkel@users.noreply.github.com> Date: Tue, 29 Oct 2024 16:07:11 +0100 Subject: [PATCH 05/10] Update block_homework.php homework is now only shown for courses in which the logged in user is enrolled --- .../moodle/blocks/homework/block_homework.php | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/server/moodle/blocks/homework/block_homework.php b/server/moodle/blocks/homework/block_homework.php index 75f5ebb16..3b4d75fe4 100644 --- a/server/moodle/blocks/homework/block_homework.php +++ b/server/moodle/blocks/homework/block_homework.php @@ -39,10 +39,34 @@ public function init() { */ public function get_content() { - global $OUTPUT, $PAGE, $DB; + global $OUTPUT, $PAGE, $DB, $USER; + //Get current time $current_time = time(); - $homeworks = $DB->get_records_select('homework', 'duedate > ?', array($current_time) ); + + //Fetch courses user is enrolled in + $user_courses = enrol_get_users_courses($USER->id); + + //Extract course IDs + $course_ids = array_map(function($course) { + return $course->id; + }, $user_courses); + + + //Create a string of ? placeholders for each found course_id, seperated by commas + $placeholders = implode(',', array_fill(0, count($course_ids), '?')); + + //Merge parameters + $parameters = array_merge(array($current_time), $course_ids); + + //Construct WHERE condition for select + $select = "duedate > ? AND course IN ($placeholders)"; + + + // Fetch homeworks using get_records_select + $homeworks = $DB->get_records_select('homework', $select, $parameters); + + $data = []; if ($this->content !== null) { From 7ce9cfca33758fb7453b4280960b442c1c53b85b Mon Sep 17 00:00:00 2001 From: StoreMikkel <113053176+StoreMikkel@users.noreply.github.com> Date: Mon, 4 Nov 2024 16:12:35 +0100 Subject: [PATCH 06/10] Update block_homework.php corrected duedate display --- server/moodle/blocks/homework/block_homework.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/moodle/blocks/homework/block_homework.php b/server/moodle/blocks/homework/block_homework.php index 3b4d75fe4..845a523c7 100644 --- a/server/moodle/blocks/homework/block_homework.php +++ b/server/moodle/blocks/homework/block_homework.php @@ -83,7 +83,7 @@ public function get_content() { foreach($homeworks as $homework) { $tmp = []; $tmp['name'] = $homework->name; - $tmp['duedate'] = date('m-d-Y', $homework->duedate); + $tmp['duedate'] = date('d-m-Y', $homework->duedate); $tmp['intro'] = strip_tags($homework->intro); $tmp['courseTitle'] = $DB->get_field('course', 'fullname', ['id' => $homework->course]); From 4fc4050d666cf2e46c2c1db38fab7d5ed29023d8 Mon Sep 17 00:00:00 2001 From: StoreMikkel <113053176+StoreMikkel@users.noreply.github.com> Date: Tue, 5 Nov 2024 13:32:23 +0100 Subject: [PATCH 07/10] Update block_homework_test.php code sniffer fixes --- .../homework/tests/block_homework_test.php | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/server/moodle/blocks/homework/tests/block_homework_test.php b/server/moodle/blocks/homework/tests/block_homework_test.php index e725c1f48..c6c2cf186 100644 --- a/server/moodle/blocks/homework/tests/block_homework_test.php +++ b/server/moodle/blocks/homework/tests/block_homework_test.php @@ -1,14 +1,25 @@ -eventid = 0; - //Assert that a course belonging to the correct course is returned + // Assert that a course belonging to the correct course is returned. array_push($homeworks, $testhomework1); - $tmpArray = \block_homework::filter_homework_content('http://localhost/course/view.php?id=3',$homeworks); - $this->assertEquals($tmpArray, $homeworks); + $tmparray = \block_homework::filter_homework_content('http://localhost/course/view.php?id=3',$homeworks); + $this->assertEquals($tmparray, $homeworks); - //Assert that homework can be removed if the ids don't match + // Assert that homework can be removed if the ids don't match. array_push($homeworks, $testhomework2); - $tmpArray = \block_homework::filter_homework_content('http://localhost/course/view.php?id=3',$homeworks); - $this->assertNotContains($testhomework2, $tmpArray); - + $tmparray = \block_homework::filter_homework_content('http://localhost/course/view.php?id=3', $homeworks); + $this->assertNotContains($testhomework2, $tmparray); } - - -} \ No newline at end of file +} From 200eceaf5835c6c905ba1d27836c29a4d1463b05 Mon Sep 17 00:00:00 2001 From: StoreMikkel <113053176+StoreMikkel@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:39:54 +0100 Subject: [PATCH 08/10] codesniffer fixes more codesniffer fixes --- .../moodle/blocks/homework/block_homework.php | 91 ++++++++++--------- server/moodle/blocks/homework/db/access.php | 25 ++++- .../homework/lang/en/block_homework.php | 4 +- server/moodle/blocks/homework/version.php | 8 +- 4 files changed, 72 insertions(+), 56 deletions(-) diff --git a/server/moodle/blocks/homework/block_homework.php b/server/moodle/blocks/homework/block_homework.php index 845a523c7..0328a822b 100644 --- a/server/moodle/blocks/homework/block_homework.php +++ b/server/moodle/blocks/homework/block_homework.php @@ -23,13 +23,14 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -// Checks for Moodle environment +// Checks for Moodle environment. defined('MOODLE_INTERNAL') || die(); class block_homework extends block_base { - - //constructor for the block + /* + * Constructor for the block. + */ public function init() { $this->title = get_string('homework', 'block_homework'); } @@ -39,31 +40,30 @@ public function init() { */ public function get_content() { - global $OUTPUT, $PAGE, $DB, $USER; + global $OUTPUT, $DB, $USER; - //Get current time - $current_time = time(); + // Get current time. + $currenttime = time(); - //Fetch courses user is enrolled in - $user_courses = enrol_get_users_courses($USER->id); + // Fetch courses user is enrolled in. + $usercourses = enrol_get_users_courses($USER->id); - //Extract course IDs - $course_ids = array_map(function($course) { + // Extract course IDs. + $courseids = array_map(function($course) { return $course->id; - }, $user_courses); + }, $usercourses); - //Create a string of ? placeholders for each found course_id, seperated by commas - $placeholders = implode(',', array_fill(0, count($course_ids), '?')); + // Create a string of ? placeholders for each found course_id, seperated by commas. + $placeholders = implode(',', array_fill(0, count($courseids), '?')); - //Merge parameters - $parameters = array_merge(array($current_time), $course_ids); + // Merge parameters. + $parameters = array_merge([$currenttime], $courseids); - //Construct WHERE condition for select + // Construct WHERE condition for select. $select = "duedate > ? AND course IN ($placeholders)"; - - // Fetch homeworks using get_records_select + // Fetch homeworks using get_records_select. $homeworks = $DB->get_records_select('homework', $select, $parameters); @@ -75,12 +75,12 @@ public function get_content() { $this->content = new stdClass(); - //If the current page is a course then remove unrelated homework - if ($PAGE->pagetype == 'course-view-topics') { - $homeworks = $this->filter_homework_content($PAGE->url, $homeworks); + // If the current page is a course then remove unrelated homework. + if ($this->page->pagetype == 'course-view-topics') { + $homeworks = $this->filter_homework_content($this->page->url, $homeworks); } - foreach($homeworks as $homework) { + foreach ($homeworks as $homework) { $tmp = []; $tmp['name'] = $homework->name; $tmp['duedate'] = date('d-m-Y', $homework->duedate); @@ -89,17 +89,17 @@ public function get_content() { $files = []; - //Get ids of homeworkfiles + // Get ids of homeworkfiles. $fileids = []; - $homeworkfiles = $DB->get_records('files_homework', ['homework_id'=>$homework->id]); + $homeworkfiles = $DB->get_records('files_homework', ['homework_id' => $homework->id]); foreach ($homeworkfiles as $homeworkfile) { array_push($fileids, $homeworkfile->files_id); } - //Get file records - if(!empty($fileids)) { - $file_records = $DB->get_records_list('files', 'id', $fileids); - foreach ($file_records as $file) { + // Get file records. + if (!empty($fileids)) { + $filerecords = $DB->get_records_list('files', 'id', $fileids); + foreach ($filerecords as $file) { $contextid = $file->contextid; $component = $file->component; $filearea = $file->filearea; @@ -107,7 +107,7 @@ public function get_content() { $filepath = $file->filepath; $filename = $file->filename; - //Generate url + // Generate url. $url = moodle_url::make_pluginfile_url( $contextid, $component, @@ -118,13 +118,13 @@ public function get_content() { false ); - //Get appropriate icon for file type + // Get appropriate icon for file type. $iconurl = $OUTPUT->image_url(file_mimetype_icon($file->mimetype)); $files[] = [ 'fileurl' => $url->out(), 'filename' => $filename, - 'iconurl' => $iconurl + 'iconurl' => $iconurl, ]; } } @@ -135,28 +135,30 @@ public function get_content() { } - // Render the content using a template and pass the homework data to it + // Render the content using a template and pass the homework data to it. $this->content->text = $OUTPUT->render_from_template('block_homework/data', ['data' => $data]); - // Include JavaScript functionality for scrolling behavior in the block - $PAGE->requires->js_call_amd('block_homework/scroll', 'init'); + // Include JavaScript functionality for scrolling behavior in the block. + $this->page->requires->js_call_amd('block_homework/scroll', 'init'); return $this->content; } - public static function filter_homework_content($URL,$homeworks): array - { - //Use a regex to remove everything but digits from the url - $courseid = preg_replace('/\D/', '',$URL); - $tmpHomeworks = []; + /* + * Filters homework + */ + public static function filter_homework_content($url, $homeworks): array { + // Use a regex to remove everything but digits from the url. + $courseid = preg_replace('/\D/', '', $url); + $tmphomeworks = []; - //Check each homework to see if the course matches the id + // Check each homework to see if the course matches the id. foreach ($homeworks as $homework) { - if($courseid == $homework->course){ - array_push($tmpHomeworks, $homework); + if ($courseid == $homework->course) { + array_push($tmphomeworks, $homework); } } - return $tmpHomeworks; + return $tmphomeworks; } @@ -172,5 +174,4 @@ public function applicable_formats() { 'my' => true, ]; } - -} \ No newline at end of file +} diff --git a/server/moodle/blocks/homework/db/access.php b/server/moodle/blocks/homework/db/access.php index e14025ef1..7a4503f6b 100644 --- a/server/moodle/blocks/homework/db/access.php +++ b/server/moodle/blocks/homework/db/access.php @@ -1,4 +1,19 @@ . + /** * Block definition class for the block_homework plugin. * @@ -12,9 +27,9 @@ 'captype' => 'write', 'contextlevel' => CONTEXT_SYSTEM, 'archetypes' => [ - 'user' => CAP_ALLOW + 'user' => CAP_ALLOW, ], - 'clonepermissionsfrom' => 'moodle/my:manageblocks' + 'clonepermissionsfrom' => 'moodle/my:manageblocks', ], 'block/homework:addinstance' => [ 'riskbitmask' => RISK_SPAM | RISK_XSS, @@ -22,8 +37,8 @@ 'contextlevel' => CONTEXT_BLOCK, 'archetypes' => [ 'editingteacher' => CAP_ALLOW, - 'manager' => CAP_ALLOW + 'manager' => CAP_ALLOW, ], - 'clonepermissionsfrom' => 'moodle/site:manageblocks' + 'clonepermissionsfrom' => 'moodle/site:manageblocks', ], -]; \ No newline at end of file +]; diff --git a/server/moodle/blocks/homework/lang/en/block_homework.php b/server/moodle/blocks/homework/lang/en/block_homework.php index 1c092d74d..66609351e 100644 --- a/server/moodle/blocks/homework/lang/en/block_homework.php +++ b/server/moodle/blocks/homework/lang/en/block_homework.php @@ -23,7 +23,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$string['homework block'] = 'homework block'; $string['homework'] = 'Homework'; +$string['homework block'] = 'homework block'; $string['homework:addinstance'] = 'Add a new homework block'; -$string['homework:myaddinstance'] = 'Add a new homework block to the My Moodle page'; \ No newline at end of file +$string['homework:myaddinstance'] = 'Add a new homework block to the My Moodle page'; diff --git a/server/moodle/blocks/homework/version.php b/server/moodle/blocks/homework/version.php index ef5f51f65..bd634bec8 100644 --- a/server/moodle/blocks/homework/version.php +++ b/server/moodle/blocks/homework/version.php @@ -23,9 +23,9 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -// Checks for Moodle environment +// Checks for Moodle environment. defined('MOODLE_INTERNAL') || die(); -$plugin->component = 'block_homework'; // Plugin name -$plugin->version = 2024101400; // Plugin version -$plugin->requires = 2016052300; // Moodle version \ No newline at end of file +$plugin->component = 'block_homework'; // Plugin name. +$plugin->version = 2024101400; // Plugin version. +$plugin->requires = 2016052300; // Moodle version. From 7c956c39b5a155c28f05d25faa10fa90d4fd8a40 Mon Sep 17 00:00:00 2001 From: StoreMikkel <113053176+StoreMikkel@users.noreply.github.com> Date: Tue, 5 Nov 2024 17:25:13 +0100 Subject: [PATCH 09/10] codesniffer fixes more --- .../moodle/blocks/homework/block_homework.php | 11 ++-- .../homework/tests/block_homework_test.php | 60 ++++++++++++------- 2 files changed, 44 insertions(+), 27 deletions(-) diff --git a/server/moodle/blocks/homework/block_homework.php b/server/moodle/blocks/homework/block_homework.php index 0328a822b..44a0b0ac1 100644 --- a/server/moodle/blocks/homework/block_homework.php +++ b/server/moodle/blocks/homework/block_homework.php @@ -22,14 +22,11 @@ * @author group 11 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -// Checks for Moodle environment. -defined('MOODLE_INTERNAL') || die(); - - class block_homework extends block_base { /* * Constructor for the block. + * + * @return void */ public function init() { $this->title = get_string('homework', 'block_homework'); @@ -37,6 +34,8 @@ public function init() { /** * Retrieves and prepares the content to be displayed by the block + * + * @return stdClass|null */ public function get_content() { @@ -146,6 +145,8 @@ public function get_content() { /* * Filters homework + * + * @return array */ public static function filter_homework_content($url, $homeworks): array { // Use a regex to remove everything but digits from the url. diff --git a/server/moodle/blocks/homework/tests/block_homework_test.php b/server/moodle/blocks/homework/tests/block_homework_test.php index c6c2cf186..77f0d0d72 100644 --- a/server/moodle/blocks/homework/tests/block_homework_test.php +++ b/server/moodle/blocks/homework/tests/block_homework_test.php @@ -1,5 +1,20 @@ . + +// File: mod/myplugin/tests/sample_test.php. namespace block_homework\tests; @@ -7,10 +22,11 @@ /* * This class is responsible for testing the homework block functionality - * @copyright - * @license + * * @package block_homework - * @author Daniel + * @copyright Year, You Name + * @author group 5 + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ final class block_homework_test extends \basic_testcase { /* @@ -23,26 +39,26 @@ public function test_course_homeworkfilter(): void { $homeworks = []; $testhomework1 = new stdClass(); - $testhomework1->id = 1; - $testhomework1->course = 2; - $testhomework1->name = 'test 1'; - $testhomework1->timecreated = time(); - $testhomework1->timemodified = 0; - $testhomework1->intro = '

test 1

'; - $testhomework1->introformat = 1; - $testhomework1->description = ''; - $testhomework1->eventid = 0; + $testhomework1->id = 1; + $testhomework1->course = 2; + $testhomework1->name = 'test 1'; + $testhomework1->timecreated = time(); + $testhomework1->timemodified = 0; + $testhomework1->intro = '

test 1

'; + $testhomework1->introformat = 1; + $testhomework1->description = ''; + $testhomework1->eventid = 0; $testhomework2 = new stdClass(); - $testhomework2->id = 2; - $testhomework2->course = 3; - $testhomework2->name = 'test 1'; - $testhomework2->timecreated = time(); - $testhomework2->timemodified = 0; - $testhomework2->intro = '

test 2

'; - $testhomework2->introformat = 1; - $testhomework2->description = ''; - $testhomework2->eventid = 0; + $testhomework2->id = 2; + $testhomework2->course = 3; + $testhomework2->name = 'test 1'; + $testhomework2->timecreated = time(); + $testhomework2->timemodified = 0; + $testhomework2->intro = '

test 2

'; + $testhomework2->introformat = 1; + $testhomework2->description = ''; + $testhomework2->eventid = 0; // Assert that a course belonging to the correct course is returned. From 8bb28c4228457536d3426a0d678663939593fa29 Mon Sep 17 00:00:00 2001 From: StoreMikkel <113053176+StoreMikkel@users.noreply.github.com> Date: Wed, 6 Nov 2024 13:07:33 +0100 Subject: [PATCH 10/10] codesniffer fixes MORE --- server/moodle/blocks/homework/db/access.php | 2 ++ .../homework/classes/external/save_homework_link.php | 1 + .../classes/external/save_homework_literature.php | 4 +++- server/moodle/mod/homework/lib.php | 10 ++++++---- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/server/moodle/blocks/homework/db/access.php b/server/moodle/blocks/homework/db/access.php index 7a4503f6b..621492bf2 100644 --- a/server/moodle/blocks/homework/db/access.php +++ b/server/moodle/blocks/homework/db/access.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +defined('MOODLE_INTERNAL') || die(); + /** * Block definition class for the block_homework plugin. * diff --git a/server/moodle/mod/homework/classes/external/save_homework_link.php b/server/moodle/mod/homework/classes/external/save_homework_link.php index cfb4e9219..e933eef0e 100644 --- a/server/moodle/mod/homework/classes/external/save_homework_link.php +++ b/server/moodle/mod/homework/classes/external/save_homework_link.php @@ -77,6 +77,7 @@ public static function execute($inputfield, $link) { } /** + * Returns single structure of status and message. * * @return external_single_structure Define the return values. */ diff --git a/server/moodle/mod/homework/classes/external/save_homework_literature.php b/server/moodle/mod/homework/classes/external/save_homework_literature.php index 8da4f9f65..299bb0957 100644 --- a/server/moodle/mod/homework/classes/external/save_homework_literature.php +++ b/server/moodle/mod/homework/classes/external/save_homework_literature.php @@ -36,10 +36,11 @@ use external_single_structure; /** - * + * Class for saving homework literature. */ class save_homework_literature extends \external_api { /** + * Returns parameters inputfield, startpage and endpage * * @return external_function_parameters Define the parameters expected by this function. */ @@ -79,6 +80,7 @@ public static function execute($inputfield, $startpage, $endpage) { } /** + * Returns status and message as single structure * * @return external_single_structure Define the return values. */ diff --git a/server/moodle/mod/homework/lib.php b/server/moodle/mod/homework/lib.php index db3121826..ffab7cb1b 100644 --- a/server/moodle/mod/homework/lib.php +++ b/server/moodle/mod/homework/lib.php @@ -108,16 +108,16 @@ function homework_pluginfile( bool $forcedownload, array $options = [] ): bool { - //Make sure the user is logged in and has access to the module + // Make sure the user is logged in and has access to the module. require_login($course, true); // Extract the filename / filepath from the $args array. $filename = array_pop($args); // The last item in the $args array. if (empty($args)) { - // $args is empty => the path is '/'. + // ... $args is empty => the path is '/'. $filepath = '/'; } else { - // $args contains the remaining elements of the filepath. + // ... $args contains the remaining elements of the filepath. $filepath = '/' . implode('/', $args) . '/'; } @@ -128,7 +128,9 @@ function homework_pluginfile( $file = $fs->get_file($context->id, 'homework', $filearea, $itemid, $filepath, $filename); if (!$file) { // The file does not exist. - error_log("File not found: Context ID - $context->id, File area - $filearea, Item ID - $itemid, Path - $filepath, Filename - $filename"); + //error_log() is forbidden, changed to debuggin + debugging("File not found: Context ID - $context->id, File area - $filearea, Item ID - $itemid, + Path - $filepath, Filename - $filename"); return false; }