Skip to content
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
13 changes: 9 additions & 4 deletions lbplanner/classes/helpers/modules_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

namespace local_lbplanner\helpers;

use coding_exception;
use core_customfield\category_controller;
use DateTimeImmutable;
use DateTimeZone;
Expand Down Expand Up @@ -116,6 +117,9 @@ public static function determine_type(int $cmid): int {
throw new \moodle_exception("found multiple data for module ID {$cmid} in category ID {$catid}");
}
$type = intval($instancedata[1]->get_value()) - 1; // NOTE: why the hell is this on index one?
if ($type === -1) {
$type = MODULE_TYPE::GK; // Default is GK if nothing is selected.
}
MODULE_TYPE::name_from($type); // Basically asserting that this value exists as a module type.
return $type;
}
Expand Down Expand Up @@ -188,13 +192,14 @@ public static function get_all_modules_by_course(int $courseid, bool $ekenabled)
$modules = [];

foreach ($assignments as $assign) {
if ($assign === null) {
throw new coding_exception("what the fuck? 1 {$courseid} {$ekenabled}");
}
$module = module::from_assignobj($assign);
if (!$ekenabled && self::determine_type($module->get_assignid()) == MODULE_TYPE::EK) {
if ((!$ekenabled) && $module->get_type() === MODULE_TYPE::EK) {
continue;
}
if ($module != null) {
$modules[] = $module;
}
array_push($modules, $module);
}

return $modules;
Expand Down
22 changes: 16 additions & 6 deletions lbplanner/services/modules/get_all_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace local_lbplanner_services;

use core_external\{external_api, external_function_parameters, external_multiple_structure};
use core_external\{external_api, external_function_parameters, external_multiple_structure, external_value};
use local_lbplanner\helpers\{modules_helper, plan_helper, course_helper};
use local_lbplanner\model\module;

Expand All @@ -34,23 +34,33 @@ class modules_get_all_modules extends external_api {
* @return external_function_parameters
*/
public static function get_all_modules_parameters(): external_function_parameters {
return new external_function_parameters([]);
return new external_function_parameters([
'ekenabled' => new external_value(
PARAM_BOOL,
'Whether to include ek modules',
VALUE_DEFAULT,
false,
NULL_NOT_ALLOWED
),
]);
}

/**
* Returns all the modules for a user.
*
* @param bool $ekenabled Whether to include ek modules
* @return array the modules
*/
public static function get_all_modules(): array {
public static function get_all_modules(bool $ekenabled): array {
global $USER;
self::validate_parameters(
self::get_all_modules_parameters(),
['ekenabled' => $ekenabled]
);

$modules = [];

$courses = course_helper::get_all_lbplanner_courses();
$planid = plan_helper::get_plan_id($USER->id);
$plan = plan_helper::get_plan($planid);
$ekenabled = $plan["enableek"];

foreach ($courses as $course) {
if (!$course->enabled) {
Expand Down
Loading