Skip to content

Commit

Permalink
delete moodleoverflow native support, adapt locallib
Browse files Browse the repository at this point in the history
  • Loading branch information
TamaroWalter committed May 8, 2024
1 parent 14b2074 commit 3cae9ce
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
24 changes: 4 additions & 20 deletions classes/townsquareevents.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class townsquareevents {
*/
public function __construct() {
$this->timenow = time();
$this->timestart = $this->timenow - 15768000;
$this->timeend = $this->timenow + 15768000;
$this->timestart = townsquare_get_timestart();
$this->timeend = townsquare_get_timeend();
$this->courses = townsquare_get_courses();
}

Expand Down Expand Up @@ -97,7 +97,7 @@ public function get_coreevents(): array {
// Filter out events that are not relevant for the user.
if (townsquare_filter_availability($coreevent) ||
($coreevent->modulename == "assign" && $this->filter_assignment($coreevent)) ||
($coreevent->eventtype == "expectcompletionon" && $this->filter_activitycompletions($coreevent))) {
($coreevent->eventtype == "expectcompletionon" && townsquare_filter_activitycompletions($coreevent))) {
unset($coreevents[$coreevent->id]);
continue;
}
Expand Down Expand Up @@ -208,7 +208,7 @@ private function get_events_from_db($timestart, $timeend, $courses): array {
'wiki', 'workshop', ];

// TODO: Additional modules should be implemented with subplugins.
$additionalmodules = ['moodleoverflow', 'ratingallocate'];
$additionalmodules = ['ratingallocate'];
$modules = $coremodules + $additionalmodules;

// Prepare params for sql statement.
Expand Down Expand Up @@ -261,20 +261,4 @@ private function filter_assignment($coreevent): bool {
return false;
}

/**
* Filter that checks if the event needs to be filtered out for the current user because it is already completed..
* Applies to activity completion events.
* @param object $coreevent coreevent that is checked
* @return bool true if the event needs to filtered out, false if not.
*/
private function filter_activitycompletions($coreevent): bool {
global $DB, $USER;
if ($completionstatus = $DB->get_record('course_modules_completion',
['coursemoduleid' => $coreevent->coursemoduleid, 'userid' => $USER->id])) {
if ($completionstatus->completionstate != 0) {
return true;
}
}
return false;
}
}
31 changes: 31 additions & 0 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ function townsquare_get_timestart(): int {
return time() - 15768000;
}

/**
* Function for subplugins to get the end time of the search.
* @return int
*/
function townsquare_get_timeend(): int {
return time() + 15768000;
}

/**
* Merge sort function for townsquare events.
* @param $events
Expand Down Expand Up @@ -93,6 +101,8 @@ function townsquare_merge(array $left, array $right): array {
return $result;
}

// Filter functions.

function townsquare_filter_availability($event): bool {
// If there is no restriction defined, the event is available.
if ($event->availability == null) {
Expand All @@ -109,6 +119,27 @@ function townsquare_filter_availability($event): bool {
return true;
}

/**
* Filter that checks if the event needs to be filtered out for the current user because it is already completed..
* Applies to activity completion events.
* @param object $coreevent coreevent that is checked
* @return bool true if the event needs to filtered out, false if not.
*/
function townsquare_filter_activitycompletions($coreevent): bool {
global $DB, $USER;
if ($completionstatus = $DB->get_record('course_modules_completion',
['coursemoduleid' => $coreevent->coursemoduleid, 'userid' => $USER->id])) {
if ($completionstatus->completionstate != 0) {
return true;
}
}
return false;
}



// Strings adaptation functions.

/**
* General Support function for core events.
* Can be used to modify the event content, as in some cases, core events don't have a good text in the events-datatable.
Expand Down

0 comments on commit 3cae9ce

Please sign in to comment.