Skip to content

Commit dacb55d

Browse files
Fix tracking
1 parent 5468d21 commit dacb55d

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

classes/readtracking.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,18 +470,29 @@ public static function get_untracked_moodleoverflows($userid, $courseid) {
470470
*
471471
* @return int|mixed
472472
*/
473-
public static function moodleoverflow_count_unread_posts_moodleoverflow($cm, $course) {
473+
public static function moodleoverflow_count_unread_posts_moodleoverflow($cm) {
474474
global $DB, $USER;
475475

476-
// Get the moodleoverflow ids.
477-
$moodleoverflowid = $cm->instance;
478-
476+
$moodleoverflow = $DB->get_record_sql("SELECT m.*, tm.id as hasdisabledtracking " .
477+
"FROM {moodleoverflow} m " .
478+
"LEFT JOIN {moodleoverflow_tracking} tm ON m.id = tm.moodleoverflowid AND tm.userid = :userid " .
479+
"WHERE m.id = :moodleoverflowid", ['userid' => $USER->id, 'moodleoverflowid' => $cm->instance]);
480+
481+
// Return if tracking is off, or ((optional or forced, but forced disallowed by admin) and user has disabled tracking).
482+
if ($moodleoverflow->trackingtype == MOODLEOVERFLOW_TRACKING_OFF || (
483+
($moodleoverflow->trackingtype == MOODLEOVERFLOW_TRACKING_OPTIONAL || (
484+
$moodleoverflow->trackingtype == MOODLEOVERFLOW_TRACKING_FORCED &&
485+
!get_config('moodleoverflow', 'allowforcedreadtracking')
486+
)
487+
) && $moodleoverflow->hasdisabledtracking)) {
488+
return 0;
489+
}
479490
// Get the current timestamp and the cutoffdate.
480-
$now = round(time(), -2);
491+
$now = round(time(), -2);
481492
$cutoffdate = $now - (get_config('moodleoverflow', 'oldpostdays') * 24 * 60 * 60);
482493

483494
// Define a sql-query.
484-
$params = array($USER->id, $moodleoverflowid, $cutoffdate);
495+
$params = array($USER->id, $cm->instance, $cutoffdate);
485496
$sql = "SELECT COUNT(p.id)
486497
FROM {moodleoverflow_posts} p
487498
JOIN {moodleoverflow_discussions} d ON p.discussion = d.id

index.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,7 @@
251251
if (isset($untracked[$moodleoverflow->id])) {
252252
$unreadlink = '-';
253253

254-
} else if ($unread = \mod_moodleoverflow\readtracking::moodleoverflow_count_unread_posts_moodleoverflow($cm,
255-
$course)
254+
} else if ($unread = \mod_moodleoverflow\readtracking::moodleoverflow_count_unread_posts_moodleoverflow($cm)
256255
) {
257256
// There are unread posts in the moodleoverflow instance.
258257

lib.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,8 +1078,7 @@ function moodleoverflow_cm_info_view(cm_info $cm) {
10781078

10791079
$cantrack = \mod_moodleoverflow\readtracking::moodleoverflow_can_track_moodleoverflows();
10801080
if ($cantrack) {
1081-
$unread = \mod_moodleoverflow\readtracking::moodleoverflow_count_unread_posts_moodleoverflow($cm,
1082-
$cm->get_course());
1081+
$unread = \mod_moodleoverflow\readtracking::moodleoverflow_count_unread_posts_moodleoverflow($cm);
10831082
if ($unread) {
10841083
$out = '<span class="unread"> <a href="' . $cm->url . '">';
10851084
if ($unread == 1) {

0 commit comments

Comments
 (0)