From 92819a1cd4ac44607c35de069a1edf8ef5bc4048 Mon Sep 17 00:00:00 2001 From: cash Date: Thu, 9 Jun 2011 18:49:15 +0000 Subject: Refs #2871 adding sorting to advanced plugin page git-svn-id: http://code.elgg.org/elgg/trunk@9153 36083f99-b078-4883-b0ff-0f9b5a30f544 --- languages/en.php | 4 ++ views/default/admin/plugins/advanced.php | 76 ++++++++++++++++++++++------ views/default/forms/admin/plugins/filter.php | 24 +++++++++ views/default/forms/admin/plugins/sort.php | 24 +++++++++ 4 files changed, 112 insertions(+), 16 deletions(-) create mode 100644 views/default/forms/admin/plugins/filter.php create mode 100644 views/default/forms/admin/plugins/sort.php diff --git a/languages/en.php b/languages/en.php index a3ee4e421..923647882 100644 --- a/languages/en.php +++ b/languages/en.php @@ -609,6 +609,10 @@ $english = array( 'admin:plugins:category:theme' => 'Themes', 'admin:plugins:category:widget' => 'Widgets', + 'admin:plugins:sort:priority' => 'Priority', + 'admin:plugins:sort:alpha' => 'Alphabetical', + 'admin:plugins:sort:date' => 'Newest', + 'admin:plugins:markdown:unknown_plugin' => 'Unknown plugin.', 'admin:plugins:markdown:unknown_file' => 'Unknown file.', diff --git a/views/default/admin/plugins/advanced.php b/views/default/admin/plugins/advanced.php index dad1b778d..deae9dcdd 100644 --- a/views/default/admin/plugins/advanced.php +++ b/views/default/admin/plugins/advanced.php @@ -11,6 +11,7 @@ elgg_generate_plugin_entities(); $installed_plugins = elgg_get_plugins('any'); $show_category = get_input('category', 'all'); +$sort = get_input('sort', 'priority'); // Get a list of the all categories // and trim down the plugin list if we're not viewing all categories. @@ -45,9 +46,6 @@ foreach ($installed_plugins as $id => $plugin) { } break; } - //if ($show_category && !in_array($show_category, $plugin_categories)) { - // unset($installed_plugins[$id]); - //} if (isset($plugin_categories)) { foreach ($plugin_categories as $category) { @@ -58,6 +56,34 @@ foreach ($installed_plugins as $id => $plugin) { } } +// sort plugins +switch ($sort) { + case 'date': + $plugin_list = array(); + foreach ($installed_plugins as $plugin) { + $create_date = $plugin->getTimeCreated(); + while (isset($plugin_list[$create_date])) { + $create_date++; + } + $plugin_list[$create_date] = $plugin; + } + krsort($plugin_list); + break; + case 'alpha': + $plugin_list = array(); + foreach ($installed_plugins as $plugin) { + $plugin_list[$plugin->getManifest()->getName()] = $plugin; + } + ksort($plugin_list); + break; + case 'priority': + default: + $plugin_list = $installed_plugins; + break; +} + + + asort($categories); $common_categories = array( @@ -67,25 +93,43 @@ $common_categories = array( ); $categories = array_merge($common_categories, $categories); +// security - only want a defined option +if (!array_key_exists($show_category, $categories)) { + $show_category = reset($categories); +} -$category_dropdown = elgg_view('input/dropdown', array( - 'name' => 'category', - 'options_values' => $categories, - 'value' => $show_category +$category_form = elgg_view_form('admin/plugins/filter', array( + 'action' => 'admin/plugins/advanced', + 'method' => 'get', + 'disable_security' => true, +), array( + 'category' => $show_category, + 'category_options' => $categories, + 'sort' => $sort, )); -$category_button = elgg_view('input/submit', array( - 'value' => elgg_echo('filter'), - 'class' => 'elgg-button elgg-button-action' -)); -$category_form = elgg_view('input/form', array( - 'body' => $category_dropdown . $category_button, - 'method' => 'get', +$sort_options = array( + 'priority' => elgg_echo('admin:plugins:sort:priority'), + 'alpha' => elgg_echo('admin:plugins:sort:alpha'), + 'date' => elgg_echo('admin:plugins:sort:date'), +); +// security - only want a defined option +if (!array_key_exists($sort, $sort_options)) { + $sort = reset($sort_options); +} + +$sort_form = elgg_view_form('admin/plugins/sort', array( 'action' => 'admin/plugins/advanced', + 'method' => 'get', 'disable_security' => true, +), array( + 'sort' => $sort, + 'sort_options' => $sort_options, + 'category' => $show_category, )); + // @todo Until "en/deactivate all" means "All plugins on this page" hide when not looking at all. if ($show_category == 'all') { $activate_url = "action/admin/plugins/activate_all"; @@ -101,7 +145,7 @@ if ($show_category == 'all') { $buttons = ''; } -$buttons .= $category_form; +$buttons .= $category_form . $sort_form; // construct page header ?> @@ -112,7 +156,7 @@ $buttons .= $category_form;
\ No newline at end of file diff --git a/views/default/forms/admin/plugins/filter.php b/views/default/forms/admin/plugins/filter.php new file mode 100644 index 000000000..d00906e6a --- /dev/null +++ b/views/default/forms/admin/plugins/filter.php @@ -0,0 +1,24 @@ + 'category', + 'options_values' => $vars['category_options'], + 'value' => $vars['category'], +)); + +echo elgg_view('input/hidden', array( + 'name' => 'sort', + 'value' => $vars['sort'], +)); + +echo elgg_view('input/submit', array( + 'value' => elgg_echo('filter'), + 'class' => 'elgg-button elgg-button-action', +)); diff --git a/views/default/forms/admin/plugins/sort.php b/views/default/forms/admin/plugins/sort.php new file mode 100644 index 000000000..284e085e6 --- /dev/null +++ b/views/default/forms/admin/plugins/sort.php @@ -0,0 +1,24 @@ + 'sort', + 'options_values' => $vars['sort_options'], + 'value' => $vars['sort'], +)); + +echo elgg_view('input/hidden', array( + 'name' => 'category', + 'value' => $vars['category'], +)); + +echo elgg_view('input/submit', array( + 'value' => elgg_echo('sort'), + 'class' => 'elgg-button elgg-button-action' +)); -- cgit v1.2.3