diff --git a/amd/build/suivi.js b/amd/build/suivi.js index 8bbaf0d8884b8ca498d25c811358c2a79e4be63e..8ecf59e9fc836390a4fe89eaa7779d37ccc67ad9 100644 --- a/amd/build/suivi.js +++ b/amd/build/suivi.js @@ -129,27 +129,47 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str'], } function fetchProgress(){ - completeUrl=getCompleteUrl(); + data={action: 'fetchprogress'}; + if(localStorage.groups && JSON.parse(localStorage.groups).length > 0){ + var cachedgroupsid=JSON.parse(localStorage.groups); + var groupsid=[]; + for (var i = 0; i < cachedgroupsid.length; i++) { + groupsid.push(cachedgroupsid[i]); + } + + if(groupsid.length==0){ + groupsid.push(-2); + } + data.groupsid=groupsid; + } $.ajax({ url: completeUrl, - data: {action: 'fetchprogress'}, + data: data, type: 'post', success: function(request) { - - data=calcPercentage(JSON.parse(request)); - if(data.students.length<1000){ - - localStorage.setItem("groups",request); + + + + + + parsedrequest=JSON.parse(request); + data=calcPercentage(parsedrequest); + if(data.students.length<1000 && !localStorage.groups){ + localStorage.setItem("groups",parsedrequest["groups"]); } - + initActivityFilter(false); - updateActivitiesFilterLabel(false); - initGroupFilter(false); - updateGroupsFilterLabel(false); - showHideActivities(false); + updateActivitiesFilterLabel(false); + changeSection(false); + initGroupFilter(false); + + updateGroupsFilterLabel(false); + reloadTable(data); - changeSection(false); - reloadTable(data); + + + + return data; } }); @@ -205,12 +225,13 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str'], success: function(request) { showHideActivities(); + parsedrequest=JSON.parse(request); + data=calcPercentage(parsedrequest); - data=calcPercentage(JSON.parse(request)); showHideStudents(); if(data.students.length<1000){ + localStorage.setItem("groups",JSON.stringify(parsedrequest["groups"])); - localStorage.setItem("groups",request); } reloadTable(data); updateGroupsFilterLabel(false); @@ -715,12 +736,13 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str'], } updateGroupsFilterLabel(); }); - if(localStorage.groups){ - var checkedGroups=JSON.parse(localStorage.groups); + if(localStorage.groups && JSON.parse(localStorage.groups) != 0){ + var checkedGroups=JSON.parse(localStorage.groups); + //var checkedGroups=JSON.parse(localStorage.groups); + var groups=$("input[type='checkbox'].justone-group"); - - if($("input[type='checkbox'].justone-group[value="+checkedGroups[0]+"]").length > 0){ - if(groups.length===checkedGroups.length ){ + //if($("input[type='checkbox'].justone-group[value="+checkedGroups[0]+"]").length > 0){ + if(groups.length===checkedGroups.length && checkedGroups[0]!=0){ $(".selectallgroups").prop("checked", true); $("input[type='checkbox'].justone-group").prop("checked", true); } @@ -735,7 +757,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str'], } } } - } + //} } else{ if(data.countstudents<1000){ @@ -788,7 +810,6 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str'], $.when(message).done(function(localizedEditString) { $("#partial-table").html("<div class='alert alert-primary' role='alert'>"+localizedEditString+loader+"</div>"); - console.log($("#partial-table")); }); } @@ -836,6 +857,8 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str'], form.submit(); } else if(value=="download"){ + e.stopPropagation(); + e.preventDefault(); table_download(data); } } @@ -846,7 +869,8 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str'], .replace(/\s+/g, '-') /* Replace spaces with - */ .replace(/&/g, '-and-') /* Replace & with 'and' */ .replace(/[^\w\-]+/g, '') /* Remove all non-word chars */ - .replace(/\-\-+/g, '-'); /* Replace multiple - with single - */ + .replace(/\-\-+/g, '-') /* Replace multiple - with single - */ + } @@ -869,9 +893,8 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str'], continue; } head.push('"'+data.modules[m].displayname.replace(',', '')+'"'); - } - + } csvContent += head.join(","); csvContent += "\n"; @@ -942,9 +965,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str'], csvContent += dataString + "\n"; } } - var encodedUri = encodeURI(csvContent); - var section_name = data.active_section_id; if ( section_name == 0 ) { section_name = "cours-complet"; diff --git a/suivi_unit.php b/suivi_unit.php index 4292f418f530938375c9411257fb14ce0bee904d..c245781cd94987fb5175dc41b4d9a5d57f8da55c 100644 --- a/suivi_unit.php +++ b/suivi_unit.php @@ -266,11 +266,11 @@ function get_progress_students($modules, $progress, $groups, $activegroupsids, $ $arrayprogress=array(); for($i=0; $i<count($activegroupsids); $i++){ if($cache->get($courseid."-".$activegroupsids[$i]) !== false){ + error_log("on est passé dans le cache"); $progress=$cache->get($courseid."-".$activegroupsids[$i]); } else{ - error_log("pas dans le cache"); //On récupère le progrès des étudiants qui font partie des groupes activegroupsids $progressrequest = $completion->get_progress_all( '', @@ -283,6 +283,7 @@ function get_progress_students($modules, $progress, $groups, $activegroupsids, $ ); //On active le cache seulement s'il y a plus de x étudiants if($countstudents<1000){ + error_log("on set le cache"); $cache->set($courseid."-".$activegroupsids[$i], $progressrequest); } $progress=$progressrequest; @@ -300,9 +301,10 @@ function get_progress_student($identifier, $completion, $modules){ global $COURSE; $countmethod=0; $users=array(); - $start = microtime(true); + //Essayer de faire des switch case avec counttries $arrayparams=array(); + $explodedname=explode(" ", $identifier); $sql="SELECT DISTINCT u.id, u.firstname, u.lastname, u.email, u.idnumber FROM {user} u @@ -317,27 +319,26 @@ function get_progress_student($identifier, $completion, $modules){ if(count($explodedname)>1){ - $sql.=" AND (u.lastname LIKE ? AND u.firstname LIKE '?') OR (u.lastname LIKE '?' AND u.firstname LIKE '?')"; + $sql.=" AND (u.lastname LIKE ? AND u.firstname LIKE ?) OR (u.lastname LIKE ? AND u.firstname LIKE ?)"; - array_push($arrayparams, $identifier[0], $identifier[1], $identifier[1], $identifier[0]); + array_push($arrayparams, $explodedname[0], $explodedname[1], $explodedname[1], $explodedname[0]); } else{ $sql.=" AND u.lastname LIKE ? OR u.idnumber = ?"; - array_push($arrayparams, "%".$identifier."%", $identifier); + array_push($arrayparams, "".$identifier."%", $identifier); } - $users=array_values($DB->get_records_sql($sql, $arrayparams)); - error_log("Après le sql"); - error_log($time_elapsed_secs = microtime(true) - $start); + $users=array_values($DB->get_records_sql($sql, $arrayparams)); if(count($users)>0){ - + $completion_student=array(); $where = array(); $where_params = array(); //regarder get_in_or_equal + error_log("flag2"); for($i=0; $i<count($users);$i++){ // foreach($users as $user){ @@ -356,12 +357,12 @@ function get_progress_student($identifier, $completion, $modules){ } $arrayprogress=(object) array_unique(array_merge((array) $arrayprogress, (array) $completion_student), SORT_REGULAR); } - error_log("avant le format progress"); - error_log($time_elapsed_secs = microtime(true) - $start); + 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"); } @@ -540,22 +541,24 @@ 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); - $data = set_links($data, $modules, $listoptions); + //$data = set_links($data, $modules, $listoptions); echo json_encode($data); } // If a post is sent trought the page --> Si on change les filtres (de groupes), le template est appelé en JS else if (isset($_POST['action']) && !empty($_POST['action'])) { - error_log("on passe dans l'action "); + $groups = groups_get_all_groups($COURSE->id, 0, 0, 'g.*', true); $data = []; $modules = get_activities($completion, $activesectionid); $data["students"]=get_progress_students($modules, $arrayprogress, $groups, $activegroupsids, $activesectionid, $courseid, $cache, $completion); $data["modules"]=$modules; $data["countstudents"]=count($data["students"]); - $data = set_links($data, $modules, $listoptions); + $data["groups"]=$activegroupsids; + //$data = set_links($data, $modules, $listoptions); echo json_encode($data); } @@ -563,7 +566,6 @@ else if (isset($_POST['action']) && !empty($_POST['action'])) { else { init_page($course, $PAGE); echo $OUTPUT->header(); - error_log("je load juste la page"); //$progress=$cache->get($activegroupids); $groups = groups_get_all_groups($COURSE->id, 0, 0, 'g.*', true); $data = []; @@ -589,8 +591,9 @@ else { //$groups = $groupsall->groups; $sections = get_sections($activesectionid); //$data["countstudents"]=$countstudents; + $data = set_links($data, $modules, $listoptions); $data = set_filters($data, $filters, $symbols, $sections, $groupsall->current_user_groups, $groupsall->othergroups, $activesectionid); - + $data["groups"]=$activegroupsids; if (isset($_GET["msg_success"])) { $msg = $_GET["msg_success"]; $data["msg_success"] = $msg;