From f65bbe4020850d8cc85a94de08db69480f7fcc7e Mon Sep 17 00:00:00 2001
From: Myriam Delaruelle <myriam.delaruelle@univ-lorraine.fr>
Date: Tue, 4 Mar 2025 09:25:31 +0100
Subject: [PATCH] fix js caching + cleaning error messages

---
 amd/build/suivi.js | 18 ++++++++++--------
 suivi_unit.php     | 10 +++-------
 2 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/amd/build/suivi.js b/amd/build/suivi.js
index e706d2f..a135926 100644
--- a/amd/build/suivi.js
+++ b/amd/build/suivi.js
@@ -157,13 +157,11 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str'],
         		
 			    parsedrequest=JSON.parse(request);
         		data=calcPercentage(parsedrequest);
-        		console.log(data);
-        		if(data.countstudents.length<1000 && !localStorage.groups){
-
+        		if(data.countstudents<1500 && !localStorage.groups){
+        		
         			localStorage.setItem("courseid",parsedrequest["courseid"]);
         			localStorage.setItem("groups",parsedrequest["groups"]);
         		}
-        		
         		initActivityFilter(false);
 			    updateActivitiesFilterLabel(false);
 			    changeSection(false);
@@ -235,7 +233,8 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str'],
         		data=calcPercentage(parsedrequest);
         		
         		showHideStudents();
-        		if(data.countstudents.length<1000){
+        		if(data.countstudents<1500){
+        	
         			localStorage.setItem("courseid",parsedrequest["courseid"] )
         			localStorage.setItem("groups",JSON.stringify(parsedrequest["groups"]));
         			
@@ -398,7 +397,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str'],
                 }
             }
         }
-        if(data.countstudents.length<1000){
+        if(data.countstudents<1500){
         	localStorage.setItem("activities",JSON.stringify(activitiesToStore));
         }
         
@@ -744,7 +743,6 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str'],
             updateGroupsFilterLabel();
         }); 
         if(localStorage.groups && JSON.parse(localStorage.groups) != 0 && localStorage.courseid && localStorage.courseid==courseid ){
-        	console.log("on est passé dans le cache alors qu'on aurait pas dû");
         	var checkedGroups=JSON.parse(localStorage.groups);
             //var checkedGroups=JSON.parse(localStorage.groups);
             
@@ -768,9 +766,13 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str'],
             //}
         }
         else{
-        	if(data.countstudents<1000){
+        	if(data.countstudents<1500){
         		checkAllGroupsFilter();
         	}
+        	else{
+        		$('.selectallgroups').prop('checked', false);
+        		$('.group-option').prop('checked', false);
+        	}
         	
         }
     }
diff --git a/suivi_unit.php b/suivi_unit.php
index c5f537a..dee5e10 100644
--- a/suivi_unit.php
+++ b/suivi_unit.php
@@ -172,7 +172,6 @@ function get_activities($completion, $activesectionid) {
 }
 
 function get_sections($activesectionid) {
-    error_log("on passe par ici alors qu'on devrait pas");
     global $COURSE;
     // Liste des sections du cours.
     $modinfo = get_fast_modinfo($COURSE->id);
@@ -282,7 +281,7 @@ function get_progress_students($modules, $progress, $groups, $activegroupsids, $
                 $context
             );  
             //On active le cache seulement s'il y a plus de x étudiants
-            if($countstudents<1000){
+            if($countstudents<1500){
                 error_log("on set le cache");
                 $cache->set($courseid."-".$activegroupsids[$i], $progressrequest);
             }
@@ -338,7 +337,6 @@ function get_progress_student($identifier, $completion, $modules){
         $where_params = array();
        
         //regarder get_in_or_equal
-        error_log("flag2");
         for($i=0; $i<count($users);$i++){
        // foreach($users as $user){
             
@@ -357,12 +355,11 @@ function get_progress_student($identifier, $completion, $modules){
             }
             $arrayprogress=(object) array_unique(array_merge((array) $arrayprogress, (array) $completion_student), SORT_REGULAR);   
         }
-        error_log("flag3");
         return format_progress($arrayprogress, $modules, false, true);
 
     }
     else{
-        error_log("Pas trouvé ?");
+        
         //On a pas trouvé d'utilisateur
         return array("error"=>"Pas d'utilisateurs trouvés");
     }
@@ -453,7 +450,7 @@ if (isset($_POST['groupsid'])) {
     
     $activegroupsids = $_POST['groupsid'];
 } else {
-    if($countstudents>1000){
+    if($countstudents>1500){
 
         $activegroupsids = array();
     }
@@ -541,7 +538,6 @@ else if(isset($_POST['action']) && $_POST['action'] == 'search_student' && isset
 
     $data=[];
     $sanitized=filter_var($_POST['search_input'], FILTER_SANITIZE_STRING);
-    error_log($sanitized);
     $modules = get_activities($completion, $activesectionid);
     $data["modules"]=$modules;
     $data["students"]=get_progress_student($sanitized, $completion, $modules);
-- 
GitLab