From ef7b4cd2b5ae590f7abc86b37c7191e349036dd2 Mon Sep 17 00:00:00 2001 From: nikrou Date: Sat, 10 Apr 2010 13:25:20 +0000 Subject: Feature 1031 : Automatically sort photos by rank when manual ranks are edited Add fields to choose sorting mode. If order of images is changed, checked automaticaly rank for sorting mode. Need refactoring between admin/element_set_ranks.php admin/cat_modify.php git-svn-id: http://piwigo.org/svn/trunk@5759 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/element_set_ranks.php | 100 ++++++++++++++++++++- admin/themes/default/default-layout.css | 4 + .../themes/default/template/element_set_ranks.tpl | 30 ++++++- 3 files changed, 130 insertions(+), 4 deletions(-) diff --git a/admin/element_set_ranks.php b/admin/element_set_ranks.php index e6134f9f5..27d9012f4 100644 --- a/admin/element_set_ranks.php +++ b/admin/element_set_ranks.php @@ -84,6 +84,9 @@ function save_images_order($category_id, $images) // | global mode form submission | // +-----------------------------------------------------------------------+ +$image_order_choices = array('default', 'rank', 'user_define'); +$image_order_choice = 'default'; + if (isset($_POST['submit'])) { asort($_POST['rank_of_image'], SORT_NUMERIC); @@ -97,6 +100,40 @@ if (isset($_POST['submit'])) $page['infos'], l10n('Images manual order was saved') ); + + $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']; + } + + if ($image_order_choice=='user_define') + { + for ($i=1; $i<=3; $i++) + { + if ( !empty($_POST['order_field_'.$i]) ) + { + if (! empty($image_order) ) + { + $image_order .= ','; + } + $image_order .= $_POST['order_field_'.$i]; + if ($_POST['order_direction_'.$i]=='DESC') + { + $image_order .= ' DESC'; + } + } + } + } + elseif ($image_order_choice=='rank') + { + $image_order = 'rank'; + } + $query = ' +UPDATE '.CATEGORIES_TABLE.' SET image_order=\''.$image_order.'\' + WHERE id='.$page['category_id']; + pwg_query($query); } // +-----------------------------------------------------------------------+ @@ -108,15 +145,22 @@ $template->set_filenames( $base_url = get_root_url().'admin.php'; -// $form_action = $base_url.'?page=element_set_global'; - $query = ' -SELECT uppercats +SELECT * FROM '.CATEGORIES_TABLE.' WHERE id = '.$page['category_id'].' ;'; $category = pwg_db_fetch_assoc(pwg_query($query)); +if ($category['image_order']=='rank') +{ + $image_order_choice = 'rank'; +} +elseif ($category['image_order']!='') +{ + $image_order_choice = 'user_define'; +} + // Navigation path $navigation = get_cat_display_name_cache( $category['uppercats'], @@ -174,6 +218,56 @@ while ($row = pwg_db_fetch_assoc($result)) $current_rank++; } +// image order management +$sort_fields = array( + '' => '', + 'date_creation' => l10n('Creation date'), + 'date_available' => l10n('Post date'), + 'average_rate' => l10n('Average rate'), + 'hit' => l10n('Most visited'), + 'file' => l10n('File name'), + 'id' => 'Id', + 'rank' => l10n('Rank'), + ); + +$sort_directions = array( + 'ASC' => l10n('ascending'), + 'DESC' => l10n('descending'), + ); + +$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); +} + +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]) ) + { + $tpl_image_order_select['FIELD'] = array($matches[1][$i]); + } + + if (isset($matches[2][$i]) and strcasecmp($matches[2][$i],'DESC')==0) + { + $tpl_image_order_select['DIRECTION'] = array('DESC'); + } + $template->append( 'image_orders', $tpl_image_order_select); +} + +$template->assign('image_order_choice', $image_order_choice); + + // +-----------------------------------------------------------------------+ // | sending html code | // +-----------------------------------------------------------------------+ diff --git a/admin/themes/default/default-layout.css b/admin/themes/default/default-layout.css index 35de67694..3950825a3 100644 --- a/admin/themes/default/default-layout.css +++ b/admin/themes/default/default-layout.css @@ -293,6 +293,10 @@ FORM P { margin-bottom: 2em; } +form p.field { + text-align: left; +} + FORM FIELDSET P { margin-top: 1em; margin-bottom: 0; diff --git a/admin/themes/default/template/element_set_ranks.tpl b/admin/themes/default/template/element_set_ranks.tpl index b45ca5d19..804d053ff 100644 --- a/admin/themes/default/template/element_set_ranks.tpl +++ b/admin/themes/default/template/element_set_ranks.tpl @@ -1,7 +1,7 @@ {known_script id="jquery" src=$ROOT_URL|@cat:"themes/default/js/jquery.packed.js"} {known_script id="jquery.ui" src=$ROOT_URL|@cat:"themes/default/js/ui/packed/ui.core.packed.js" } {known_script id="jquery.ui.sortable" src=$ROOT_URL|@cat:"themes/default/js/ui/packed/ui.sortable.packed.js" } - +{html_head} {literal} {/literal} +{/html_head}

{'Manage image ranks'|@translate}

@@ -46,9 +48,35 @@ {/if} + +
+ {'Sort order'|@translate} +

+ + +

+

+ + +

+

+ + + {foreach from=$image_orders item=order} +

+ + +

+ {/foreach} +

+ {else}

{'No element in this category'|@translate}

{/if} -- cgit v1.2.3