diff --git a/application/controllers/Question.php b/application/controllers/Question.php index a6b6bb7e..b2c06349 100644 --- a/application/controllers/Question.php +++ b/application/controllers/Question.php @@ -34,7 +34,7 @@ public function index($page = 1) if(!empty($_GET['module']) && !empty($_GET['topic'])){ $nbTopic = $this->topic_model->count_by("ID = ".$_GET['topic']." AND FK_Parent_Topic = ".$_GET['module']); if($nbTopic==0){ - redirect("Question?module=".$_GET['module']."&topic="."&type=".$_GET['type']); + redirect("Question?module=".$_GET['module']."&topic="."&type=".$_GET['type']."&sort="); } } @@ -42,8 +42,17 @@ public function index($page = 1) $_SESSION['filtres'] = "Question?module=".$_GET['module']."&topic=".$_GET['topic']."&type=".$_GET['type']; } - if(isset($_SESSION['filtres']) && strpos($_SERVER['REQUEST_URI'], "?") === false){ + if(isset($_GET['sort'])){ + $_SESSION['tri'] = "&sort=".$_GET['sort']; + } + + + if(isset($_SESSION['filtres']) && !isset($_SESSION['tri']) && strpos($_SERVER['REQUEST_URI'], "?") === false){ redirect($_SESSION['filtres']); + } elseif(!isset($_SESSION['filtres']) && isset($_SESSION['tri']) && strpos($_SERVER['REQUEST_URI'], "?") === false){ + redirect("Question?module=&topic=&type=".$_SESSION['tri']); + } elseif(isset($_SESSION['filtres']) && isset($_SESSION['tri']) && strpos($_SERVER['REQUEST_URI'], "?") === false){ + redirect($_SESSION['filtres'].$_SESSION['tri']); } $where = "Archive = 0"; @@ -160,7 +169,24 @@ public function index($page = 1) */ public function reset_filters() { unset($_SESSION['filtres']); - redirect('question'); + if(isset($_SESSION['tri'])){ + redirect("Question?" . $_SESSION['tri']); + } else { + redirect('question'); + } + } + + /** + * Resets the index sorting in $_SESSION['tri'] + * and redirect the user to index + */ + public function reset_sort(){ + unset($_SESSION['tri']); + if(isset($_SESSION['filtres'])){ + redirect($_SESSION['filtres']); + } else { + redirect('question'); + } } /** diff --git a/application/language/french/MY_application_lang.php b/application/language/french/MY_application_lang.php index 41a8a279..7f898f2a 100644 --- a/application/language/french/MY_application_lang.php +++ b/application/language/french/MY_application_lang.php @@ -169,6 +169,7 @@ $lang['filter'] = 'Filtrer'; $lang['delete_question'] = 'Supprimer la question'; $lang['detail_question'] = 'Détails de la question'; +$lang['reset_sort'] = 'Effacer le tri'; // Topics pages diff --git a/application/views/questions/index.php b/application/views/questions/index.php index b5effbd8..ca0b4296 100644 --- a/application/views/questions/index.php +++ b/application/views/questions/index.php @@ -129,22 +129,22 @@ if (isset($_GET['sort'])){ switch ($_GET['sort']){ case 'question_asc': - $question_sort='▼'; + $question_sort='▲'; break; case 'question_desc': - $question_sort='▲'; + $question_sort='▼'; break; case 'question_type_asc': - $question_type_sort='▼'; + $question_type_sort='▲'; break; case 'question_type_desc': - $question_type_sort='▲'; + $question_type_sort='▼'; break; case 'points_asc': - $points_sort='▼'; + $points_sort='▲'; break; case 'points_desc': - $points_sort='▲'; + $points_sort='▼'; break; } } @@ -171,6 +171,9 @@ echo "$points_sort" ?> + + lang->line('reset_sort'); ?> + diff --git a/assets/js/javascript.js b/assets/js/javascript.js index 1cc082fd..0ad73c65 100644 --- a/assets/js/javascript.js +++ b/assets/js/javascript.js @@ -12,7 +12,10 @@ function changeselect() { var type = document.getElementById("question_type_selected").value; var search = encodeURI(document.getElementById("search").value); - window.location = '?module=' + module + '&topic=' + topic + '&type=' + type + '&search=' + search; + //Get URL parameter for sort + var sort = new URLSearchParams(window.location.search).get('sort') + + window.location = '?module=' + module + '&topic=' + topic + '&type=' + type + '&sort=' + sort + '&search=' + search; return false; }