Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

68 bugfix make sure the students dont have accesss to the edit page #74

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/moodle/blocks/homework/amd/build/filter.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions server/moodle/blocks/homework/block_homework.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public function get_content() {
global $OUTPUT, $DB, $USER;

// Fetch courses user is enrolled in.
$usercourses = enrol_get_users_courses($USER->id,true);
$usercourses = enrol_get_users_courses($USER->id, true);

$homeworks = [];
foreach ($usercourses as $course) {
// Fetch homeworks using get_records_select.
$tmp = $DB->get_records('homework', ['course'=>$course->id]);
$tmp = $DB->get_records('homework', ['course' => $course->id]);
foreach ($tmp as $tm) {
$homeworks[] = $tm;
}
Expand All @@ -61,13 +61,11 @@ 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);
}


// Retrieving all of the user's completions.
$homeworkcompletionrecords = $DB->get_records('completions', ['usermodified' => $USER->id]);

Expand Down
238 changes: 125 additions & 113 deletions server/moodle/blocks/homework/classes/external/filter_homework.php
Original file line number Diff line number Diff line change
@@ -1,113 +1,125 @@
<?php

// This file is part of Moodle - https://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.

/**
* homework/classes/external/get_homework_chooser.php
* A class defining an external API function
*
* @package block_homework
* @copyright 2024, cs-24-sw-5-13 <cs-24-sw-5-13@student.aau.dk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
*/

namespace block_homework\external;
defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once("$CFG->libdir/externallib.php");

use coding_exception;
use dml_exception;
use external_function_parameters;
use external_value;
use external_single_structure;
use JsonException;

class filter_homework extends \external_api {
/**
*
* @return external_function_parameters Is a definition of the functions parameter type and a description of it.
*/
public static function execute_parameters() {
return new external_function_parameters([
'filter' => new external_value(PARAM_TEXT, 'Filtering parameter'),
]);
}

/**
* The logic making the custom html for modal client-side
* @param $filter - The current modules id
* @return array - The html to be shown client-side
* @throws JsonException|dml_exception
*/
public static function execute($filter) {
global $DB, $USER;
$usercourses = enrol_get_users_courses($USER->id, true);
$homeworkarray = [];
foreach ($usercourses as $course) {
$homeworkrecords = $DB->get_records('homework', ['course' => $course->id]);
foreach ($homeworkrecords as $homework) {
$homeworkarray[] = [
'id' => $homework->id,
'name' => $homework->name,
'intro' => strip_tags($homework->intro),
'duedate' => date('d-m-y',$homework->duedate),
'time' => $homework->duedate,
'course' => $course->fullname,
];
}
}
$returnarray = filter_homework::filter($filter, $homeworkarray);
return ["homework" => json_encode($returnarray,JSON_THROW_ON_ERROR), JSON_THROW_ON_ERROR];
}

public static function execute_returns(){
return new external_single_structure([
'homework' => new external_value(PARAM_TEXT, 'Data array of homework'),
]);
}

public static function filter($filter, $homeworkarray){
$returnarray = [];
switch ($filter) {
case ("all"):
return $homeworkarray;
case ("current"):
foreach ($homeworkarray as $homework) {
if ($homework["time"] > time()) {
$returnarray[] = $homework;
}
}
break;
case ("previous"):
foreach ($homeworkarray as $homework) {
if ($homework["time"] < time()) {
$returnarray[] = $homework;
}
}
break;
default:
foreach ($homeworkarray as $homework) {
if ($homework["course"] == $filter){
$returnarray[] = $homework;
}
}
}
return $returnarray;
}
}
<?php
// This file is part of Moodle - https://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.

/**
* homework/classes/external/get_homework_chooser.php
* A class defining an external API function
*
* @package block_homework
* @copyright 2024, cs-24-sw-5-13 <cs-24-sw-5-13@student.aau.dk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
*/

namespace block_homework\external;
defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once("$CFG->libdir/externallib.php");

use coding_exception;
use dml_exception;
use external_function_parameters;
use external_value;
use external_single_structure;
use JsonException;

/**
*
*/
class filter_homework extends \external_api {
/**
*
* @return external_function_parameters Is a definition of the functions parameter type and a description of it.
*/
public static function execute_parameters() {
return new external_function_parameters([
'filter' => new external_value(PARAM_TEXT, 'Filtering parameter'),
]);
}

/**
* The logic making the custom html for modal client-side
* @param $filter - The current modules id
* @return array - The html to be shown client-side
* @throws JsonException|dml_exception
*/
public static function execute($filter) {
global $DB, $USER;
$usercourses = enrol_get_users_courses($USER->id, true);
$homeworkarray = [];
foreach ($usercourses as $course) {
$homeworkrecords = $DB->get_records('homework', ['course' => $course->id]);
foreach ($homeworkrecords as $homework) {
$homeworkarray[] = [
'id' => $homework->id,
'name' => $homework->name,
'intro' => strip_tags($homework->intro),
'duedate' => date('d-m-y', $homework->duedate),
'time' => $homework->duedate,
'course' => $course->fullname,
];
}
}
$returnarray = self::filter($filter, $homeworkarray);
return ["homework" => json_encode($returnarray, JSON_THROW_ON_ERROR), JSON_THROW_ON_ERROR];
}

/**
*
* @return external_single_structure
*/
public static function execute_returns() {
return new external_single_structure([
'homework' => new external_value(PARAM_TEXT, 'Data array of homework'),
]);
}

/**
*
* @param $filter
* @param $homeworkarray
* @return array
*/
public static function filter($filter, $homeworkarray) {
$returnarray = [];
switch ($filter) {
case ("all"):
return $homeworkarray;
case ("current"):
foreach ($homeworkarray as $homework) {
if ($homework["time"] > time()) {
$returnarray[] = $homework;
}
}
break;
case ("previous"):
foreach ($homeworkarray as $homework) {
if ($homework["time"] < time()) {
$returnarray[] = $homework;
}
}
break;
default:
foreach ($homeworkarray as $homework) {
if ($homework["course"] == $filter) {
$returnarray[] = $homework;
}
}
}
return $returnarray;
}
}
Loading
Loading