1212
1313api_protect_admin_script ();
1414
15+ opcache_reset ();
16+
1517$ testSessionId = 182 ;
1618$ testCourseId = 97 ;
1719$ max = 10 ;
8082function compareLpTimeAndCourseTime ($ user , $ courseInfo , $ sessionId = 0 )
8183{
8284 $ userId = $ user ['user_id ' ];
83- $ defaultValue = 1800 ; // 30 min
85+ $ defaultValue = 600 ; // 10 min
8486 $ courseCode = $ courseInfo ['code ' ];
8587 $ courseId = $ courseInfo ['real_id ' ];
8688
@@ -102,9 +104,12 @@ function compareLpTimeAndCourseTime($user, $courseInfo, $sessionId = 0)
102104 );
103105 $ content = '' ;
104106 if ($ totalLpTime > $ totalCourseTime ) {
105- $ totalCourseTime = api_time_to_hms ($ totalCourseTime );
106- $ totalLpTime = api_time_to_hms ($ totalLpTime );
107- $ content = "User: " .$ user ['user_id ' ]." - Total course: $ totalCourseTime / Total LP: $ totalLpTime " ;
107+ $ totalCourseTimeFormatted = api_time_to_hms ($ totalCourseTime );
108+ $ totalLpTimeFormatted = api_time_to_hms ($ totalLpTime );
109+ $ diff = $ totalLpTime - $ totalCourseTime ;
110+
111+ $ content = PHP_EOL ."User: " .$ user ['user_id ' ]." - Total course: $ totalCourseTimeFormatted / Total LP: $ totalLpTimeFormatted " .PHP_EOL ;
112+ $ content .= PHP_EOL ."Diff: " .api_time_to_hms ($ diff ).PHP_EOL ;
108113 $ url = api_get_path (WEB_CODE_PATH ).'mySpace/myStudents.php?student= ' .$ userId .'&course= ' .$ courseCode .'&id_session= ' .$ sessionId ;
109114 $ content .= Display::url ('Check ' , $ url , ['target ' => '_blank ' ]);
110115 $ content .= PHP_EOL ;
@@ -121,6 +126,7 @@ function compareLpTimeAndCourseTime($user, $courseInfo, $sessionId = 0)
121126 ORDER BY total_time desc
122127 LIMIT 1
123128 " ;
129+ echo $ sql .PHP_EOL ;
124130 $ result = Database::query ($ sql );
125131 $ results = Database::store_result ($ result , 'ASSOC ' );
126132 if (!empty ($ results )) {
@@ -132,7 +138,12 @@ function compareLpTimeAndCourseTime($user, $courseInfo, $sessionId = 0)
132138 $ content .= "total_time = " .api_time_to_hms ($ item ['total_time ' ]).PHP_EOL ;
133139 $ content .= Display::url ('See report before update ' , $ link , ['target ' => '_blank ' ]).PHP_EOL ;
134140 $ content .= "SQL with possible fix: " .PHP_EOL ;
135- $ content .= "UPDATE c_lp_item_view SET total_time = ' $ defaultValue' WHERE iid = " .$ item ['iid ' ]."; " .PHP_EOL .PHP_EOL ;
141+
142+ if ($ item ['total_time ' ] < $ defaultValue ) {
143+ $ content .= "Skip because total_time is too short. total_time: " .$ item ['total_time ' ].' value to rest ' .$ defaultValue .PHP_EOL ;
144+ continue ;
145+ }
146+ $ content .= "UPDATE c_lp_item_view SET total_time = total_time - ' $ defaultValue' WHERE iid = " .$ item ['iid ' ]."; " .PHP_EOL .PHP_EOL ;
136147 }
137148 }
138149 }
0 commit comments