]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #2871 adding sorting to advanced plugin page
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Thu, 9 Jun 2011 18:49:15 +0000 (18:49 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Thu, 9 Jun 2011 18:49:15 +0000 (18:49 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@9153 36083f99-b078-4883-b0ff-0f9b5a30f544

languages/en.php
views/default/admin/plugins/advanced.php
views/default/forms/admin/plugins/filter.php [new file with mode: 0644]
views/default/forms/admin/plugins/sort.php [new file with mode: 0644]

index a3ee4e4210690f33f3c1a4e431282d9ae31e5c4b..9236478821ceb0abb7c428cef15251078a83d63e 100644 (file)
@@ -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.',
 
index dad1b778d84f3c1291122aaa599f614f12ffa7a4..deae9dcddfc5ccd39dd0d363a90e5cef7c36b7e4 100644 (file)
@@ -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;
 <div id="elgg-plugin-list">
 <?php
 
-echo elgg_view_entity_list($installed_plugins, 0, 0, 0, true, false, false); 
+echo elgg_view_entity_list($plugin_list, 0, 0, 0, true, false, false);
 
 ?>
 </div>
\ 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 (file)
index 0000000..d00906e
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+/**
+ * Category filter for plugins
+ *
+ * @uses $vars['category']
+ * @uses $vars['category_options']
+ * @uses $vvars['sort']
+ */
+
+echo elgg_view('input/dropdown', array(
+       'name' => '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 (file)
index 0000000..284e085
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+/**
+ * Sort plugins form body
+ *
+ * @uses $vars['sort']
+ * @uses $vars['sort_options']
+ * @uses $vars['category']
+ */
+
+echo elgg_view('input/dropdown', array(
+       'name' => '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'
+));