Skip to content

Commit

Permalink
#20 - Add pref for sorting order in grid view
Browse files Browse the repository at this point in the history
Default: newest recipes first (descending)

Also added gridview_itemspp to plugin.xml (was forgotten)
  • Loading branch information
Moc committed Dec 16, 2022
1 parent a0783d6 commit 7ce746e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
16 changes: 16 additions & 0 deletions admin_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,13 @@ class cookbook_recipes_ui extends e_admin_ui
'help' => 'Number of recipes that are shown per page (when using Grid view)',
'tab' => 0,
),
'gridview_sortorder' => array(
'title' => 'Grid overview: Sorting order',
'type' => 'hidden',
'data' => 'str',
'help' => 'Order recipes ascending (oldest recipes first) or descending (newest recipes first)',
'tab' => 0,
),
'date_format' => array(
'title' => 'Date format',
'type' => 'dropdown',
Expand Down Expand Up @@ -575,6 +582,15 @@ public function init()
{
// Change type from 'hidden' to 'number'
$this->prefs['gridview_itemspp']['type'] = 'number';

// Change type from 'hidden' to 'dropdown'
$this->prefs['gridview_sortorder']['type'] = 'dropdown';

// Set sorting order options
$this->prefs['gridview_sortorder']['writeParms'] = array(
"asc" => "Oldest recipes first", // TODO LAN
"desc" => "Newest recipes first", // TODO LAN
);
}

}
Expand Down
4 changes: 3 additions & 1 deletion cookbook_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,10 @@ public function renderRecipeOverview($parm = array())
$template = e107::getTemplate('cookbook');
$template = array_change_key_case($template);

$order = e107::getPlugPref('cookbook', 'gridview_sortorder', 'desc');

// Retrieve all recipe entries
$recipes = $sql->retrieve('cookbook_recipes', '*', '', TRUE);
$recipes = $sql->retrieve('cookbook_recipes', '*', 'ORDER BY r_datestamp '.$order, TRUE);

// Check if there are recipes
if($recipes)
Expand Down
2 changes: 2 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
</siteLinks>
<pluginPrefs>
<pref name='overview_format'>overview_grid</pref>
<pref name='gridview_itemspp'>10</pref>
<pref name='gridview_sortorder'>desc</pref>
<pref name='date_format'>short</pref>
<pref name='comments_enabled'>1</pref>
<pref name='recipe_authorrating'>0</pref>
Expand Down

0 comments on commit 7ce746e

Please sign in to comment.