Skip to content

Commit

Permalink
chore: quick return if sorting options are already present
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalsem committed Jun 10, 2022
1 parent 5109739 commit 2995cf8
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions classes/ColdTrick/GroupTools/Views.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class Views {
* @return void
*/
public static function prepareGroupAll(\Elgg\Hook $hook) {
if (!empty(get_input('sort_by')) || !empty(get_input('sort'))) {
return;
}

$default_filter = elgg_get_plugin_setting('group_listing', 'group_tools');
if ($default_filter === 'yours' && !elgg_is_logged_in()) {
$default_filter = 'all';
Expand All @@ -30,49 +34,49 @@ public static function prepareGroupAll(\Elgg\Hook $hook) {
// support for 'old' tabs
switch ($filter) {
case 'newest':
set_input('sort_by', get_input('sort_by', [
set_input('sort_by', [
'property_type' => 'attribute',
'property' => 'time_created',
'direction' => 'desc',
]));
]);
set_input('filter', 'all');
$vars['filter_sorting_selected'] = 'sort:time_created:desc';
break;
case 'popular':
set_input('sort', get_input('sort', 'popular'));
set_input('sort', 'popular');
set_input('filter', 'all');
$vars['filter_sorting_selected'] = 'popular';
break;
case 'alpha':
set_input('sort_by', get_input('sort_by', [
set_input('sort_by', [
'property_type' => 'metadata',
'property' => 'name',
'direction' => 'asc',
]));
]);
set_input('filter', 'all');
$vars['filter_sorting_selected'] = 'sort:name:asc';
break;
default:
$sorting = elgg_get_plugin_setting("group_listing_{$filter}_sorting", 'group_tools', 'newest');
switch ($sorting) {
case 'alpha':
set_input('sort_by', get_input('sort_by', [
set_input('sort_by', [
'property_type' => 'metadata',
'property' => 'name',
'direction' => 'asc',
]));
]);
$vars['filter_sorting_selected'] = 'sort:name:asc';
break;
case 'newest':
set_input('sort_by', get_input('sort_by', [
set_input('sort_by', [
'property_type' => 'attribute',
'property' => 'time_created',
'direction' => 'desc',
]));
]);
$vars['filter_sorting_selected'] = 'sort:time_created:desc';
break;
case 'popular':
set_input('sort', get_input('sort', $sorting));
set_input('sort', $sorting);
$vars['filter_sorting_selected'] = 'popular';
break;
default:
Expand Down

0 comments on commit 2995cf8

Please sign in to comment.