@@ -1572,6 +1572,11 @@ public static function show_notification($courseInfo, $loadAjax = true)
1572
1572
$ row = Database::fetch_array ($ result , 'ASSOC ' );
1573
1573
$ latestDate = $ row ['access_date ' ];
1574
1574
}
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 );
1575
1580
1576
1581
$ sessionCondition = api_get_session_condition (
1577
1582
$ sessionId ,
@@ -1596,6 +1601,7 @@ public static function show_notification($courseInfo, $loadAjax = true)
1596
1601
$ group_ids [] = 0 ; //add group 'everyone'
1597
1602
$ notifications = [];
1598
1603
if ($ tools ) {
1604
+ $ latestLocalDate = $ latestDate ;
1599
1605
foreach ($ tools as $ tool ) {
1600
1606
$ toolName = $ tool ['name ' ];
1601
1607
$ toolName = Database::escape_string ($ toolName );
@@ -1604,6 +1610,13 @@ public static function show_notification($courseInfo, $loadAjax = true)
1604
1610
if ($ toolName == 'student_publication ' || $ toolName == 'work ' ) {
1605
1611
$ toolCondition = " (tool = 'work' OR tool = 'student_publication') AND " ;
1606
1612
}
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
+ }
1607
1620
1608
1621
$ toolName = addslashes ($ toolName );
1609
1622
@@ -1614,7 +1627,7 @@ public static function show_notification($courseInfo, $loadAjax = true)
1614
1627
lastedit_type NOT LIKE '%Deleted%' AND
1615
1628
lastedit_type NOT LIKE '%deleted%' AND
1616
1629
lastedit_type NOT LIKE '%DocumentInvisible%' AND
1617
- lastedit_date > ' $ latestDate ' AND
1630
+ lastedit_date > ' $ latestLocalDate ' AND
1618
1631
lastedit_user_id != $ user_id $ sessionCondition AND
1619
1632
visibility != 2 AND
1620
1633
(to_user_id IN (' $ user_id', '0') OR to_user_id IS NULL) AND
@@ -3071,4 +3084,40 @@ public static function returnHeaderWithPercentage($header, $percentage)
3071
3084
3072
3085
return "$ header<br><small> $ percentHtml</small> " ;
3073
3086
}
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
+ }
3074
3123
}
0 commit comments