Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Le tri des questions est maintenant sauvegardé #276

Open
wants to merge 1 commit into
base: Release-1.5.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions application/controllers/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,25 @@ 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=");
}
}

if(isset($_GET['module']) && isset($_GET['topic']) && isset($_GET['type'])){
$_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";
Expand Down Expand Up @@ -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');
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions application/language/french/MY_application_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions application/views/questions/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -171,6 +171,9 @@
echo "<a onclick='sortClick(\"".(isset($_GET['sort'])?$_GET['sort']."\"":"\"").", \"points\")' class='sorted_btn btn btn-default'>$points_sort</a>"
?>
</th>
<th colspan="2">
<a href="<?php echo base_url('Question/reset_sort');?>" class="col-12 utton-align btn btn-secondary no-border" ><?php echo $this->lang->line('reset_sort'); ?></a>
</th>
</tr>
</thead>
<tbody>
Expand Down
5 changes: 4 additions & 1 deletion assets/js/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down