From 3c76f29e4fc1bb2d5e5f1d0cb1eeefebf13d6635 Mon Sep 17 00:00:00 2001 From: mistic100 Date: Fri, 10 Feb 2012 21:41:08 +0000 Subject: feature 2568: redesigned order_by fields in Admin->Config->Options git-svn-id: http://piwigo.org/svn/trunk@13087 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/configuration.php | 83 ++++++++-------------- admin/element_set_ranks.php | 76 ++++++++------------ admin/themes/default/template/configuration.tpl | 13 ++-- .../themes/default/template/element_set_ranks.tpl | 9 +-- 4 files changed, 66 insertions(+), 115 deletions(-) (limited to 'admin') diff --git a/admin/configuration.php b/admin/configuration.php index 95d6943ca..c71da8d67 100644 --- a/admin/configuration.php +++ b/admin/configuration.php @@ -106,21 +106,24 @@ $display_info_checkboxes = array( // image order management $sort_fields = array( - '' => '', - 'rank' => l10n('Rank'), - 'file' => l10n('File name'), - 'name' => l10n('Photo name'), - 'date_creation' => l10n('Creation date'), - 'date_available' => l10n('Post date'), - 'rating_score' => l10n('Rating score'), - 'hit' => l10n('Most visited'), - 'id' => 'Id', - ); - -$sort_directions = array( - 'ASC' => l10n('ascending'), - 'DESC' => l10n('descending'), + '' => '', + 'file ASC' => l10n('file name, A → Z'), + 'file DESC' => l10n('file name, Z → A'), + 'name ASC' => l10n('photo title, A → Z'), + 'name DESC' => l10n('photo title, Z → A'), + 'date_creation DESC' => l10n('date created, new → old'), + 'date_creation ASC' => l10n('date created, old → new'), + 'date_available DESC' => l10n('date posted, new → old'), + 'date_available ASC' => l10n('date posted, old → new'), + 'rating_score DESC' => l10n('rating score, high → low'), + 'rating_score ASC' => l10n('rating score, low → high'), + 'hit DESC' => l10n('visits, high → low'), + 'hit ASC' => l10n('visits, low → high'), + 'id ASC' => l10n('numeric identifier, 1 → 9'), + 'id DESC' => l10n('numeric identifier, 9 → 1'), + 'rank ASC' => l10n('manual sort order'), ); + //------------------------------ verification and registration of modifications if (isset($_POST['submit'])) @@ -133,29 +136,14 @@ if (isset($_POST['submit'])) { if ( !isset($conf['order_by_custom']) and !isset($conf['order_by_inside_category_custom']) ) { - if ( !empty($_POST['order_by_field']) ) - { - $order_by = array(); - $order_by_inside_category = array(); + if ( !empty($_POST['order_by']) ) + { + // limit to the number of available parameters + $order_by = $order_by_inside_category = array_slice($_POST['order_by'], 0, ceil(count($sort_fields)/2)); + + // there is no rank outside categories + unset($order_by[ array_search('rank ASC', $order_by) ]); - for ($i=0; $i= (count($sort_fields)-1) ) break; // limit to the number of available parameters - if ( empty($_POST['order_by_field'][$i]) ) - { - array_push($page['errors'], l10n('No field selected')); - break; - } - else - { - // there is no rank outside categories - if ($_POST['order_by_field'][$i] != 'rank') - { - $order_by[] = $_POST['order_by_field'][$i].' '.$_POST['order_by_direction'][$i]; - } - $order_by_inside_category[] = $_POST['order_by_field'][$i].' '.$_POST['order_by_direction'][$i]; - } - } // must define a default order_by if user want to order by rank only if ( count($order_by) == 0 ) { @@ -164,7 +152,10 @@ if (isset($_POST['submit'])) $_POST['order_by'] = 'ORDER BY '.implode(', ', $order_by); $_POST['order_by_inside_category'] = 'ORDER BY '.implode(', ', $order_by_inside_category); - unset($_POST['order_by_field']); + } + else + { + array_push($page['errors'], l10n('No field selected')); } } @@ -323,11 +314,7 @@ switch ($page['section']) if ( isset($conf['order_by_custom']) or isset($conf['order_by_inside_category_custom']) ) { - $order_by = array(array( - 'FIELD' => '', - 'DIRECTION' => 'ASC', - )); - + $order_by = array(''); $template->assign('ORDER_BY_IS_CUSTOM', true); } else @@ -336,15 +323,6 @@ switch ($page['section']) $order_by = trim($conf['order_by_inside_category']); $order_by = str_replace('ORDER BY ', null, $order_by); $order_by = explode(', ', $order_by); - foreach ($order_by as $field) - { - $field= explode(' ', $field); - $out[] = array( - 'FIELD' => $field[0], - 'DIRECTION' => $field[1], - ); - } - $order_by = $out; } $template->assign( @@ -358,8 +336,7 @@ switch ($page['section']) ), 'week_starts_on_options_selected' => $conf['week_starts_on'], 'order_by' => $order_by, - 'order_field_options' => $sort_fields, - 'order_direction_options' => $sort_directions, + 'order_by_options' => $sort_fields, ) ); diff --git a/admin/element_set_ranks.php b/admin/element_set_ranks.php index cfdceaacd..e66e84f74 100644 --- a/admin/element_set_ranks.php +++ b/admin/element_set_ranks.php @@ -104,28 +104,21 @@ if (isset($_POST['submit'])) ); } - $image_order = null; if (!empty($_POST['image_order_choice']) && in_array($_POST['image_order_choice'], $image_order_choices)) { $image_order_choice = $_POST['image_order_choice']; } + $image_order = null; if ($image_order_choice=='user_define') { - for ($i=1; $i<=3; $i++) + for ($i=0; $i<3; $i++) { - if ( !empty($_POST['order_field_'.$i]) ) + if (!empty($_POST['image_order'][$i])) { - if (! empty($image_order) ) - { - $image_order .= ','; - } - $image_order .= $_POST['order_field_'.$i]; - if ($_POST['order_direction_'.$i]=='DESC') - { - $image_order .= ' DESC'; - } + if (!empty($image_order)) $image_order.= ','; + $image_order.= $_POST['image_order'][$i]; } } } @@ -134,7 +127,8 @@ if (isset($_POST['submit'])) $image_order = 'rank'; } $query = ' -UPDATE '.CATEGORIES_TABLE.' SET image_order=\''.$image_order.'\' +UPDATE '.CATEGORIES_TABLE.' + SET image_order=\''.$image_order.'\' WHERE id='.$page['category_id']; pwg_query($query); @@ -272,50 +266,38 @@ if (pwg_db_num_rows($result) > 0) } // image order management $sort_fields = array( - '' => '', - 'date_creation' => l10n('Creation date'), - 'date_available' => l10n('Post date'), - 'rating_score' => l10n('Rating score'), - 'hit' => l10n('Most visited'), - 'file' => l10n('File name'), - 'name' => l10n('Photo name'), - 'id' => 'Id', - 'rank' => l10n('Rank'), + '' => '', + 'file' => l10n('file name, A → Z'), + 'file DESC' => l10n('file name, Z → A'), + 'name' => l10n('photo title, A → Z'), + 'name DESC' => l10n('photo title, Z → A'), + 'date_creation DESC' => l10n('date created, new → old'), + 'date_creation' => l10n('date created, old → new'), + 'date_available DESC' => l10n('date posted, new → old'), + 'date_available' => l10n('date posted, old → new'), + 'rating_score DESC' => l10n('rating score, high → low'), + 'rating_score' => l10n('rating score, low → high'), + 'hit DESC' => l10n('visits, high → low'), + 'hit' => l10n('visits, low → high'), + 'id' => l10n('numeric identifier, 1 → 9'), + 'id DESC' => l10n('numeric identifier, 9 → 1'), + 'rank' => l10n('manual sort order'), ); -$sort_directions = array( - 'ASC' => l10n('ascending'), - 'DESC' => l10n('descending'), - ); +$template->assign('image_order_options', $sort_fields); -$template->assign('image_order_field_options', $sort_fields); -$template->assign('image_order_direction_options', $sort_directions); - -$matches = array(); -if ( !empty( $category['image_order'] ) ) -{ - preg_match_all('/([a-z_]+) *(?:(asc|desc)(?:ending)?)? *(?:, *|$)/i', - $category['image_order'], $matches); -} +$image_order = explode(',', $category['image_order']); for ($i=0; $i<3; $i++) // 3 fields { - $tpl_image_order_select = array( - 'ID' => $i+1, - 'FIELD' => array(''), - 'DIRECTION' => array('ASC'), - ); - - if ( isset($matches[1][$i]) ) + if ( isset($image_order[$i]) ) { - $tpl_image_order_select['FIELD'] = array($matches[1][$i]); + $template->append('image_order', $image_order[$i]); } - - if (isset($matches[2][$i]) and strcasecmp($matches[2][$i],'DESC')==0) + else { - $tpl_image_order_select['DIRECTION'] = array('DESC'); + $template->append('image_order', ''); } - $template->append( 'image_orders', $tpl_image_order_select); } $template->assign('image_order_choice', $image_order_choice); diff --git a/admin/themes/default/template/configuration.tpl b/admin/themes/default/template/configuration.tpl index 4c7aa31f2..df4df0157 100644 --- a/admin/themes/default/template/configuration.tpl +++ b/admin/themes/default/template/configuration.tpl @@ -108,12 +108,9 @@ jQuery(document).ready(function(){ {foreach from=$main.order_by item=order} - + {html_options options=$main.order_by_options selected=$order} - {'delete'|@translate} {/foreach} @@ -128,7 +125,7 @@ jQuery(document).ready(function(){ {if !$ORDER_BY_IS_CUSTOM} {footer_script require='jquery'} // counters for displaying of addFilter link -fields = {$main.order_by|@count}; max_fields = {$main.order_field_options|@count}; max_fields--; +fields = {$main.order_by|@count}; max_fields = Math.ceil({$main.order_by_options|@count}/2); {literal} function updateAddFilterLink() { @@ -149,10 +146,8 @@ function updateRemoveFilterTrigger() { jQuery(document).ready(function () { $('.addFilter').click(function() { - rel = $(this).attr('rel'); $(this).prev('span.filter').clone().insertBefore($(this)); - $(this).prev('span.filter').children('select[name="order_by_field[]"]').val(''); - $(this).prev('span.filter').children('select[name="order_by_direction[]"]').val('ASC'); + $(this).prev('span.filter').children('select[name="order_by[]"]').val(''); fields++; updateAddFilterLink(); diff --git a/admin/themes/default/template/element_set_ranks.tpl b/admin/themes/default/template/element_set_ranks.tpl index ca677b4d6..91ec0b39d 100644 --- a/admin/themes/default/template/element_set_ranks.tpl +++ b/admin/themes/default/template/element_set_ranks.tpl @@ -78,14 +78,11 @@ jQuery('.clipwrapper').tipTip({
- {foreach from=$image_orders item=order} + {foreach from=$image_order item=order}

- + {html_options options=$image_order_options selected=$order} -

{/foreach}
-- cgit v1.2.3