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
15 changes: 10 additions & 5 deletions lbplanner/classes/helpers/course_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,18 @@ public static function get_eduplanner_course(int $courseid, int $userid): course
}

/**
* Get all current courses.
* Get current eduplanner-enabled courses.
* @param bool $onlyenrolled whether to include only courses in which the current user is enrolled in
* @return course[] all courses of the current year
*/
public static function get_all_eduplanner_courses(bool $onlyenrolled=true): array {
public static function get_eduplanner_courses(bool $onlyenrolled): array {
global $DB, $USER;
$userid = $USER->id;

$lbptag = core_tag_tag::get_by_name(core_tag_collection::get_default(), self::EDUPLANNER_TAG, strictness:MUST_EXIST);
$courseexpireseconds = config_helper::get_course_outdatedrange();
$courseexpiredate = (new DateTimeImmutable("{$courseexpireseconds} seconds ago"))->getTimestamp();
$now = time();

/* NOTE: We could use enrol_get_my_courses() and get_courses() here.
But their perf is so abysmal that we have to roll our own function.
Expand All @@ -106,8 +107,11 @@ public static function get_all_eduplanner_courses(bool $onlyenrolled=true): arra
WHERE
ue.status = :active
AND e.status = :enabled
AND ue.timestart <= :now
AND ue.timeend >= :now
AND ue.timestart <= :nowa
AND (
ue.timeend >= :nowb
OR ue.timeend = 0
)
AND (
c.enddate > :courseexpiredate
OR c.enddate = 0
Expand All @@ -118,7 +122,8 @@ public static function get_all_eduplanner_courses(bool $onlyenrolled=true): arra
"userid" => $userid,
"active" => ENROL_USER_ACTIVE,
"enabled" => ENROL_INSTANCE_ENABLED,
"now" => time(),
"nowa" => $now,
"nowb" => $now,
"courseexpiredate" => $courseexpiredate,
"lbptagid" => $lbptag->id,
]
Expand Down
2 changes: 1 addition & 1 deletion lbplanner/classes/helpers/slot_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public static function get_filters_for_slot(int $slotid): array {
* @return slot[] the filtered slot array
*/
public static function filter_slots_for_user(array $allslots, \stdClass $user): array {
$mycourses = course_helper::get_all_eduplanner_courses();
$mycourses = course_helper::get_eduplanner_courses(true);
$mycourseids = [];
foreach ($mycourses as $course) {
array_push($mycourseids, $course->courseid);
Expand Down
2 changes: 1 addition & 1 deletion lbplanner/services/courses/get_all_courses.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static function get_all_courses(): array {
throw new \moodle_exception('access denied: must be slotmaster');
}

$courses = course_helper::get_all_eduplanner_courses(false);
$courses = course_helper::get_eduplanner_courses(false);
$results = [];
foreach ($courses as $course) {
array_push($results, $course->prepare_for_api());
Expand Down
2 changes: 1 addition & 1 deletion lbplanner/services/courses/get_my_courses.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static function get_my_courses_parameters(): external_function_parameters
* Get all the courses of the current year.
*/
public static function get_my_courses(): array {
$courses = course_helper::get_all_eduplanner_courses(true);
$courses = course_helper::get_eduplanner_courses(true);
$results = [];
foreach ($courses as $course) {
array_push($results, $course->prepare_for_api());
Expand Down
2 changes: 1 addition & 1 deletion lbplanner/services/modules/get_all_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static function get_all_modules(bool $ekenabled): array {

$modules = [];

$courses = course_helper::get_all_eduplanner_courses();
$courses = course_helper::get_eduplanner_courses(true);
$planid = plan_helper::get_plan_id($USER->id);

foreach ($courses as $course) {
Expand Down
Loading