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

Removed require_once in block_homework & mod_homework #101

Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,20 @@

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

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

use coding_exception;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_value;
use core_external\external_single_structure;

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

/**
* Class used to filter homework on block plugin.
*/
class filter_homework extends \external_api {
class filter_homework extends external_api {
/**
*
* @return external_function_parameters Is a definition of the functions parameter type and a description of it.
Expand Down
13 changes: 5 additions & 8 deletions server/moodle/blocks/homework/classes/external/get_courses.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,19 @@

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

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

use coding_exception;
use core_external\external_api;
use dml_exception;
use external_function_parameters;
use external_value;
use external_single_structure;
use core_external\external_function_parameters;
use core_external\external_value;
use core_external\external_single_structure;

use JsonException;

/**
*
*/
class get_courses extends \external_api {
class get_courses extends external_api {
/**
*
* @return external_function_parameters
Expand Down
12 changes: 7 additions & 5 deletions server/moodle/blocks/homework/classes/external/get_homework.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,16 @@

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

global $CFG;

use coding_exception;
use dml_exception;
use JsonException;

use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_value;
use core_external\external_single_structure;

use dml_exception;
use JsonException;

/**
*
*/
Expand All @@ -60,10 +58,13 @@ public static function execute_parameters() {
*/
public static function execute($sort) {
global $DB, $USER;

$usercourses = enrol_get_users_courses($USER->id, true);
$homeworkarray = [];

foreach ($usercourses as $course) {
$homeworkrecords = $DB->get_records('homework', ['course_id' => $course->id]);

foreach ($homeworkrecords as $homework) {
$homeworkarray[] = [
'id' => $homework->id,
Expand All @@ -75,6 +76,7 @@ public static function execute($sort) {
];
}
}

if ($sort === 'due') {
$homeworkarray = self::sortDueDate($homeworkarray);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.

namespace block_homework\external;

defined('MOODLE_INTERNAL') || die();
global $CFG;

use coding_exception;
use core_external\external_api;
use dml_exception;
use core_external\external_function_parameters;
use core_external\external_value;
use core_external\external_single_structure;
use JsonException;

use coding_exception;
use dml_exception;
use Mustache_Engine;

/**
Expand Down Expand Up @@ -56,24 +55,30 @@ public static function execute_parameters(): external_function_parameters {
*/
public static function execute(int $homeworkid, float $readingspeed): array {
global $DB, $USER;

$homework = $DB->get_record('homework', ['id' => $homeworkid], '*', MUST_EXIST);
$course = $DB->get_record('course', ['id' => $homework->course_id]);
$materials = $DB->get_records('homework_materials', ['homework_id' => $homework->id]);
$completedmaterials = $DB->get_records('completions', ['usermodified' => $USER->id]);

$literaturearray = [];
$linksarray = [];
$videosarray = [];

foreach ($materials as $material) {
$completed = false;

foreach ($completedmaterials as $completedmaterial) {
if ($completedmaterial->material_id === $material->id) {
$completed = true;
break;
}
}

if ($completed) {
continue;
}

if ($material->startpage !== null && $material->endpage !== null) {
if ($material->file_id !== null) {
$material->fileurl = self::get_file_link_by_id($material->file_id);
Expand All @@ -88,6 +93,7 @@ public static function execute(int $homeworkid, float $readingspeed): array {
}
$videosarray[] = $material;
}

if ($material->starttime != null && $material->endtime != null) {
$material->expectedTime = ceil(($material->endtime - $material->starttime)/60);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.

namespace block_homework\external;

defined('MOODLE_INTERNAL') || die();
global $CFG;

use coding_exception;
use core\router\schema\objects\array_of_things;
use core_external\external_api;
use dml_exception;
use core_external\external_function_parameters;
use core_external\external_value;
use core_external\external_single_structure;
use core_external\external_multiple_structure;

use coding_exception;
use dml_exception;
use JsonException;
use Mustache_Engine;

Expand Down Expand Up @@ -54,7 +52,7 @@ public static function execute_parameters(): external_function_parameters {
/**
* Generates the custom HTML for the stats modal.
*
* @param array_of_things $stats The stats array
* @param string[] $stats The stats array
* @return string[] - The HTML to be shown client-side
* @throws dml_exception|JsonException
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.

namespace block_homework\external;

defined('MOODLE_INTERNAL') || die();
global $CFG;
// Comment out line below for test if phpunit does not respond to putting run in separate process.

use core_external\external_api;
use core_external\external_multiple_structure;
Expand Down
7 changes: 4 additions & 3 deletions server/moodle/mod/homework/classes/external/delete_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@

namespace mod_homework\external;

use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_value;

use core\exception\coding_exception;
use core\exception\invalid_parameter_exception;
use core\exception\moodle_exception;
use core\exception\require_login_exception;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_value;
use context_system;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,13 @@
*/

namespace mod_homework\external;

defined('MOODLE_INTERNAL') || die();

global $CFG;

use core\exception\coding_exception;
use core\exception\invalid_parameter_exception;
use core\exception\moodle_exception;
use core\exception\require_login_exception;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_value;
use core_external\external_single_structure;
use Matrix\Exception;

/**
* Class for editing homework materials.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
*/

namespace mod_homework\external;

defined('MOODLE_INTERNAL') || die();

global $CFG;

use core_external\external_api;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
* @author group 11
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_homework\external;

use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_single_structure;
use core_external\external_value;

use dml_exception;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

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

global $CFG;

use core\exception\coding_exception;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_value;
use core_external\external_single_structure;

use core\exception\coding_exception;
use core\output\mustache_engine;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@
* @author group 11
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_homework\external;

use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_single_structure;
use core_external\external_value;

use dml_exception;
use invalid_parameter_exception;


/**
* Class for linking homework and events.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
*/

namespace mod_homework\external;

defined('MOODLE_INTERNAL') || die();

global $CFG;

use core_external\external_api;
Expand Down
Loading