Skip to content

Commit d2772e4

Browse files
LudiscapeXApiywarnier
authored andcommitted
Tracking: Add support for c_lp_item_view in notification icons on course homepage - refs #5132
1 parent 766c5d3 commit d2772e4

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

main/inc/lib/display.lib.php

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,11 @@ public static function show_notification($courseInfo, $loadAjax = true)
15721572
$row = Database::fetch_array($result, 'ASSOC');
15731573
$latestDate = $row['access_date'];
15741574
}
1575+
// Get a timestamp format copy, for use in c_lp_item_view below
1576+
$originalTimeZone = date_default_timezone_get();
1577+
date_default_timezone_set('UTC');
1578+
$latestTimestamp = strtotime($latestDate);
1579+
date_default_timezone_set($originalTimeZone);
15751580

15761581
$sessionCondition = api_get_session_condition(
15771582
$sessionId,
@@ -1596,6 +1601,7 @@ public static function show_notification($courseInfo, $loadAjax = true)
15961601
$group_ids[] = 0; //add group 'everyone'
15971602
$notifications = [];
15981603
if ($tools) {
1604+
$latestLocalDate = $latestDate;
15991605
foreach ($tools as $tool) {
16001606
$toolName = $tool['name'];
16011607
$toolName = Database::escape_string($toolName);
@@ -1604,6 +1610,13 @@ public static function show_notification($courseInfo, $loadAjax = true)
16041610
if ($toolName == 'student_publication' || $toolName == 'work') {
16051611
$toolCondition = " (tool = 'work' OR tool = 'student_publication') AND ";
16061612
}
1613+
if ($toolName == 'learnpath') {
1614+
// Make sure c_lp_item_view is considered in the latestDate calculation for LPs
1615+
$lpLatest = self::getLatestLpView($course_id, $user_id, $sessionId, $latestTimestamp);
1616+
if (!empty($lpLatest)) {
1617+
$latestLocalDate = $lpLatest;
1618+
}
1619+
}
16071620

16081621
$toolName = addslashes($toolName);
16091622

@@ -1614,7 +1627,7 @@ public static function show_notification($courseInfo, $loadAjax = true)
16141627
lastedit_type NOT LIKE '%Deleted%' AND
16151628
lastedit_type NOT LIKE '%deleted%' AND
16161629
lastedit_type NOT LIKE '%DocumentInvisible%' AND
1617-
lastedit_date > '$latestDate' AND
1630+
lastedit_date > '$latestLocalDate' AND
16181631
lastedit_user_id != $user_id $sessionCondition AND
16191632
visibility != 2 AND
16201633
(to_user_id IN ('$user_id', '0') OR to_user_id IS NULL) AND
@@ -3071,4 +3084,40 @@ public static function returnHeaderWithPercentage($header, $percentage)
30713084

30723085
return "$header<br><small>$percentHtml</small>";
30733086
}
3087+
3088+
/**
3089+
* Get the latest view (later than given date) in any LP in this course/session
3090+
* as datetime format, or null
3091+
* @param int $courseId
3092+
* @param int $userId
3093+
* @param int $sessionId
3094+
* @param int $latestTimestamp The latest time for the tool in general, as obtained through track_e_access
3095+
* @return string|null The latest view if later than $latestTimestamp, or null otherwise
3096+
*/
3097+
public static function getLatestLpView(int $courseId, int $userId, int $sessionId, int $latestTimestamp): ?string
3098+
{
3099+
// Control if the latest view in c_lp_view is more recent than in track_e_access
3100+
// Use case: a user skipped the course home page by following a direct link to a LP in an email
3101+
// $latestDate is in datetime format, while c_lp_item_view.start_time is in EPOCH
3102+
$t_lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW);
3103+
$t_lp_view = Database::get_course_table(TABLE_LP_VIEW);
3104+
$sql = "SELECT cliv.start_time FROM $t_lp_item_view cliv
3105+
INNER JOIN $t_lp_view clv ON cliv.lp_view_id = clv.id
3106+
WHERE
3107+
clv.c_id = $courseId AND
3108+
clv.user_id = $userId AND
3109+
clv.session_id = $sessionId AND
3110+
cliv.start_time > $latestTimestamp
3111+
ORDER BY cliv.start_time DESC
3112+
LIMIT 1";
3113+
$resultItems = Database::query($sql);
3114+
if (Database::num_rows($resultItems)) {
3115+
$rowItems = Database::fetch_assoc($resultItems);
3116+
$controlDate = $rowItems['start_time'];
3117+
// convert to date
3118+
return date('Y-m-d H:i:s', $controlDate);
3119+
}
3120+
3121+
return null;
3122+
}
30743123
}

0 commit comments

Comments
 (0)