@@ -2357,6 +2357,10 @@ public static function get_exam_results_data(
2357
2357
.Display::getMdiIcon (ActionIcon::EXPORT_PDF , 'ch-tool-icon ' , null , ICON_SIZE_SMALL , get_lang ('Export to PDF ' ))
2358
2358
.'</a> ' ;
2359
2359
2360
+ $ sendMailUrl = api_get_path (WEB_CODE_PATH ).'exercise/exercise_report.php? ' .api_get_cidreq ().'&action=send_email&exerciseId= ' .$ exercise_id .'&attemptId= ' .$ results [$ i ]['exe_id ' ];
2361
+ $ emailLink = '<a href=" ' .$ sendMailUrl .'"> '
2362
+ .Display::getMdiIcon (ActionIcon::SEND_SINGLE_EMAIL , 'ch-tool-icon ' , null , ICON_SIZE_SMALL , get_lang ('Send by email ' ))
2363
+ .'</a> ' ;
2360
2364
2361
2365
$ filterByUser = isset ($ _GET ['filter_by_user ' ]) ? (int ) $ _GET ['filter_by_user ' ] : 0 ;
2362
2366
$ delete_link = '<a
@@ -2375,7 +2379,11 @@ public static function get_exam_results_data(
2375
2379
if (3 == $ revised ) {
2376
2380
$ delete_link = null ;
2377
2381
}
2382
+ if (1 !== $ revised ) {
2383
+ $ emailLink = '' ;
2384
+ }
2378
2385
$ actions .= $ delete_link ;
2386
+ $ actions .= $ emailLink ;
2379
2387
}
2380
2388
} else {
2381
2389
$ attempt_url = api_get_path (WEB_CODE_PATH ).'exercise/result.php? ' .api_get_cidreq ().'&id= ' .$ results [$ i ]['exe_id ' ].'&sid= ' .$ sessionId ;
@@ -2581,6 +2589,94 @@ public static function get_exam_results_data(
2581
2589
return $ listInfo ;
2582
2590
}
2583
2591
2592
+ /**
2593
+ * Returns email content for a specific attempt.
2594
+ */
2595
+ public static function getEmailContentForAttempt (int $ attemptId ): array
2596
+ {
2597
+ $ trackExerciseInfo = self ::get_exercise_track_exercise_info ($ attemptId );
2598
+
2599
+ if (empty ($ trackExerciseInfo )) {
2600
+ return [
2601
+ 'to ' => '' ,
2602
+ 'subject ' => 'No exercise info found ' ,
2603
+ 'message ' => 'Attempt ID not found or invalid. ' ,
2604
+ ];
2605
+ }
2606
+
2607
+ $ studentId = $ trackExerciseInfo ['exe_user_id ' ];
2608
+ $ courseInfo = api_get_course_info ();
2609
+ $ teacherId = api_get_user_id ();
2610
+
2611
+ if (
2612
+ empty ($ trackExerciseInfo ['orig_lp_id ' ]) ||
2613
+ empty ($ trackExerciseInfo ['orig_lp_item_id ' ])
2614
+ ) {
2615
+ $ url = api_get_path (WEB_CODE_PATH ).'exercise/result.php?id= ' .$ trackExerciseInfo ['exe_id ' ].'& ' .api_get_cidreq ()
2616
+ .'&show_headers=1&id_session= ' .api_get_session_id ();
2617
+ } else {
2618
+ $ url = api_get_path (WEB_CODE_PATH ).'lp/lp_controller.php?action=view&item_id= '
2619
+ .$ trackExerciseInfo ['orig_lp_item_id ' ].'&lp_id= ' .$ trackExerciseInfo ['orig_lp_id ' ].'& ' .api_get_cidreq ()
2620
+ .'&id_session= ' .api_get_session_id ();
2621
+ }
2622
+
2623
+ $ message = self ::getEmailNotification (
2624
+ $ teacherId ,
2625
+ $ courseInfo ,
2626
+ $ trackExerciseInfo ['title ' ],
2627
+ $ url
2628
+ );
2629
+
2630
+ return [
2631
+ 'to ' => $ studentId ,
2632
+ 'subject ' => get_lang ('Corrected test result ' ),
2633
+ 'message ' => $ message ,
2634
+ ];
2635
+ }
2636
+
2637
+ /**
2638
+ * Sends the exercise result email to the student.
2639
+ */
2640
+ public static function sendExerciseResultByEmail (int $ attemptId ): void
2641
+ {
2642
+ $ content = self ::getEmailContentForAttempt ($ attemptId );
2643
+
2644
+ if (empty ($ content ['to ' ])) {
2645
+ return ;
2646
+ }
2647
+
2648
+ MessageManager::send_message_simple (
2649
+ $ content ['to ' ],
2650
+ $ content ['subject ' ],
2651
+ $ content ['message ' ],
2652
+ api_get_user_id ()
2653
+ );
2654
+ }
2655
+
2656
+ /**
2657
+ * Returns all reviewed attempts for a given exercise and session.
2658
+ */
2659
+ public static function getReviewedAttemptsInfo (int $ exerciseId , int $ sessionId ): array
2660
+ {
2661
+ $ courseId = api_get_course_int_id ();
2662
+ $ trackTable = Database::get_main_table (TABLE_STATISTIC_TRACK_E_EXERCISES );
2663
+ $ qualifyTable = Database::get_main_table (TABLE_STATISTIC_TRACK_E_ATTEMPT_QUALIFY );
2664
+
2665
+ $ sessionCondition = api_get_session_condition ($ sessionId , true , false , 't.session_id ' );
2666
+
2667
+ $ sql = "
2668
+ SELECT DISTINCT t.exe_id
2669
+ FROM $ trackTable t
2670
+ INNER JOIN $ qualifyTable q ON (t.exe_id = q.exe_id AND q.author > 0)
2671
+ WHERE
2672
+ t.c_id = $ courseId AND
2673
+ t.exe_exo_id = $ exerciseId
2674
+ $ sessionCondition
2675
+ " ;
2676
+
2677
+ return Database::store_result (Database::query ($ sql ));
2678
+ }
2679
+
2584
2680
/**
2585
2681
* @param $score
2586
2682
* @param $weight
0 commit comments