diff --git a/MoodleSQL.sql b/MoodleSQL.sql index ec449338..7020dcd1 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 94e7620f..e6eefc1e 100644 --- a/server/moodle/blocks/homework/block_homework.php +++ b/server/moodle/blocks/homework/block_homework.php @@ -44,12 +44,38 @@ public function init() { /** * Retrieves and prepares the content to be displayed by the block + * + * @return stdClass|null */ public function get_content() { - global $OUTPUT, $DB, $value, $USER; + global $OUTPUT, $DB, $USER; + + // Get current time. + $currenttime = time(); + + // Fetch courses user is enrolled in. + $usercourses = enrol_get_users_courses($USER->id); + + // Extract course IDs. + $courseids = array_map(function($course) { + return $course->id; + }, $usercourses); + + + // 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([$currenttime], $courseids); + + // 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); + - $homeworks = $DB->get_records('homework'); $data = []; if ($this->content !== null) { @@ -57,6 +83,7 @@ public function get_content() { } $this->content = new stdClass(); + // 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); @@ -70,7 +97,7 @@ public function get_content() { $tmp = []; $tmp['id'] = $homework->id; $tmp['name'] = $homework->name; - $tmp['duedate'] = $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]); @@ -109,7 +136,8 @@ public function get_content() { $filearea, $itemid, $filepath, - $filename + $filename, + false ); // Get appropriate icon for file type. @@ -135,8 +163,6 @@ public function get_content() { // 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. $this->page->requires->js_call_amd('block_homework/scroll', 'init'); $this->page->requires->js_call_amd('block_homework/sort', 'init'); @@ -147,7 +173,6 @@ public function get_content() { ["homework", $data, $USER->id, $homeworkcompletionrecords] ); - return $this->content; } diff --git a/server/moodle/blocks/homework/db/access.php b/server/moodle/blocks/homework/db/access.php index 5dffa48c..f615ffe5 100644 --- a/server/moodle/blocks/homework/db/access.php +++ b/server/moodle/blocks/homework/db/access.php @@ -1,5 +1,6 @@ . +// along with Moodle. If not, see . + +defined('MOODLE_INTERNAL') || die(); + /** * Block definition class for the block_homework plugin. diff --git a/server/moodle/blocks/homework/templates/data.mustache b/server/moodle/blocks/homework/templates/data.mustache index b60946e2..dfc135e7 100644 --- a/server/moodle/blocks/homework/templates/data.mustache +++ b/server/moodle/blocks/homework/templates/data.mustache @@ -34,8 +34,10 @@
{{#data}}
-

name: {{name}}

-

Intro: {{intro}}

+

{{courseTitle}}

+

{{name}}

+

{{duedate}}

+

{{intro}}

{{#files}} File icon diff --git a/server/moodle/blocks/homework/tests/block_homework_test.php b/server/moodle/blocks/homework/tests/block_homework_test.php index d62eb3d4..cc3d4c17 100644 --- a/server/moodle/blocks/homework/tests/block_homework_test.php +++ b/server/moodle/blocks/homework/tests/block_homework_test.php @@ -1,4 +1,5 @@ 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() 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; + } + + // 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