Changeset 13087


Ignore:
Timestamp:
Feb 10, 2012, 10:41:08 PM (9 years ago)
Author:
mistic100
Message:

feature 2568: redesigned order_by fields in Admin->Config->Options

Location:
trunk/admin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/configuration.php

    r13068 r13087  
    107107// image order management
    108108$sort_fields = array(
    109   '' => '',
    110   'rank' => l10n('Rank'),
    111   'file' => l10n('File name'),
    112   'name' => l10n('Photo name'),
    113   'date_creation' => l10n('Creation date'),
    114   'date_available' => l10n('Post date'),
    115   'rating_score' => l10n('Rating score'),
    116   'hit' => l10n('Most visited'),
    117   'id' => 'Id',
     109  ''                    => '',
     110  'file ASC'            => l10n('file name, A → Z'),
     111  'file DESC'           => l10n('file name, Z → A'),
     112  'name ASC'            => l10n('photo title, A → Z'),
     113  'name DESC'           => l10n('photo title, Z → A'),
     114  'date_creation DESC'  => l10n('date created, new → old'),
     115  'date_creation ASC'   => l10n('date created, old → new'),
     116  'date_available DESC' => l10n('date posted, new → old'),
     117  'date_available ASC'  => l10n('date posted, old → new'),
     118  'rating_score DESC'   => l10n('rating score, high → low'),
     119  'rating_score ASC'    => l10n('rating score, low → high'),
     120  'hit DESC'            => l10n('visits, high → low'),
     121  'hit ASC'             => l10n('visits, low → high'),
     122  'id ASC'              => l10n('numeric identifier, 1 → 9'),
     123  'id DESC'             => l10n('numeric identifier, 9 → 1'),
     124  'rank ASC'            => l10n('manual sort order'),
    118125  );
    119 
    120 $sort_directions = array(
    121   'ASC' => l10n('ascending'),
    122   'DESC' => l10n('descending'),
    123   );
     126 
    124127
    125128//------------------------------ verification and registration of modifications
     
    134137      if ( !isset($conf['order_by_custom']) and !isset($conf['order_by_inside_category_custom']) )
    135138      {
    136         if ( !empty($_POST['order_by_field']) )
    137         {
    138           $order_by = array();
    139           $order_by_inside_category = array();
     139        if ( !empty($_POST['order_by']) )
     140        {         
     141          // limit to the number of available parameters
     142          $order_by = $order_by_inside_category = array_slice($_POST['order_by'], 0, ceil(count($sort_fields)/2));
    140143         
    141           for ($i=0; $i<count($_POST['order_by_field']); $i++)
    142           {
    143             if ( $i >= (count($sort_fields)-1) ) break; // limit to the number of available parameters
    144             if ( empty($_POST['order_by_field'][$i]) )
    145             {
    146               array_push($page['errors'], l10n('No field selected'));
    147               break;
    148             }
    149             else
    150             {
    151               // there is no rank outside categories
    152               if ($_POST['order_by_field'][$i] != 'rank')
    153               {
    154                 $order_by[] = $_POST['order_by_field'][$i].' '.$_POST['order_by_direction'][$i];
    155               }
    156               $order_by_inside_category[] = $_POST['order_by_field'][$i].' '.$_POST['order_by_direction'][$i];
    157             }
    158           }
     144          // there is no rank outside categories
     145          unset($order_by[ array_search('rank ASC', $order_by) ]);
     146         
    159147          // must define a default order_by if user want to order by rank only
    160148          if ( count($order_by) == 0 )
     
    165153          $_POST['order_by'] = 'ORDER BY '.implode(', ', $order_by);
    166154          $_POST['order_by_inside_category'] = 'ORDER BY '.implode(', ', $order_by_inside_category);
    167           unset($_POST['order_by_field']);
     155        }
     156        else
     157        {
     158          array_push($page['errors'], l10n('No field selected'));
    168159        }
    169160      }
     
    324315    if ( isset($conf['order_by_custom']) or isset($conf['order_by_inside_category_custom']) )
    325316    {
    326       $order_by = array(array(
    327         'FIELD' => '',   
    328         'DIRECTION' => 'ASC',
    329         ));
    330        
     317      $order_by = array('');
    331318      $template->assign('ORDER_BY_IS_CUSTOM', true);
    332319    }
     
    337324      $order_by = str_replace('ORDER BY ', null, $order_by);
    338325      $order_by = explode(', ', $order_by);
    339       foreach ($order_by as $field)
    340       {
    341         $field= explode(' ', $field);
    342         $out[] = array(
    343           'FIELD' => $field[0],   
    344           'DIRECTION' => $field[1],   
    345         );
    346       }
    347       $order_by = $out;
    348326    }
    349327 
     
    359337        'week_starts_on_options_selected' => $conf['week_starts_on'],
    360338        'order_by' => $order_by,
    361         'order_field_options' => $sort_fields,
    362         'order_direction_options' => $sort_directions,
     339        'order_by_options' => $sort_fields,
    363340        )
    364341      );
  • trunk/admin/element_set_ranks.php

    r13013 r13087  
    105105  }
    106106
    107   $image_order = null;
    108107  if (!empty($_POST['image_order_choice'])
    109108      && in_array($_POST['image_order_choice'], $image_order_choices))
     
    112111  }
    113112
     113  $image_order = null;
    114114  if ($image_order_choice=='user_define')
    115115  {
    116     for ($i=1; $i<=3; $i++)
     116    for ($i=0; $i<3; $i++)
    117117    {
    118       if ( !empty($_POST['order_field_'.$i]) )
     118      if (!empty($_POST['image_order'][$i]))
    119119      {
    120         if (! empty($image_order) )
    121         {
    122           $image_order .= ',';
    123         }
    124         $image_order .= $_POST['order_field_'.$i];
    125         if ($_POST['order_direction_'.$i]=='DESC')
    126         {
    127           $image_order .= ' DESC';
    128         }
     120        if (!empty($image_order)) $image_order.= ',';
     121        $image_order.= $_POST['image_order'][$i];
    129122      }
    130123    }
     
    135128  }
    136129  $query = '
    137 UPDATE '.CATEGORIES_TABLE.' SET image_order=\''.$image_order.'\'
     130UPDATE '.CATEGORIES_TABLE.'
     131  SET image_order=\''.$image_order.'\'
    138132  WHERE id='.$page['category_id'];
    139133  pwg_query($query);
     
    273267// image order management
    274268$sort_fields = array(
    275   '' => '',
    276   'date_creation' => l10n('Creation date'),
    277   'date_available' => l10n('Post date'),
    278   'rating_score' => l10n('Rating score'),
    279   'hit' => l10n('Most visited'),
    280   'file' => l10n('File name'),
    281   'name' => l10n('Photo name'),
    282   'id' => 'Id',
    283   'rank' => l10n('Rank'),
     269  ''                    => '',
     270  'file'                => l10n('file name, A &rarr; Z'),
     271  'file DESC'           => l10n('file name, Z &rarr; A'),
     272  'name'                => l10n('photo title, A &rarr; Z'),
     273  'name DESC'           => l10n('photo title, Z &rarr; A'),
     274  'date_creation DESC'  => l10n('date created, new &rarr; old'),
     275  'date_creation'       => l10n('date created, old &rarr; new'),
     276  'date_available DESC' => l10n('date posted, new &rarr; old'),
     277  'date_available'      => l10n('date posted, old &rarr; new'),
     278  'rating_score DESC'   => l10n('rating score, high &rarr; low'),
     279  'rating_score'        => l10n('rating score, low &rarr; high'),
     280  'hit DESC'            => l10n('visits, high &rarr; low'),
     281  'hit'                 => l10n('visits, low &rarr; high'),
     282  'id'                  => l10n('numeric identifier, 1 &rarr; 9'),
     283  'id DESC'             => l10n('numeric identifier, 9 &rarr; 1'),
     284  'rank'                => l10n('manual sort order'),
    284285  );
    285286
    286 $sort_directions = array(
    287   'ASC' => l10n('ascending'),
    288   'DESC' => l10n('descending'),
    289   );
    290 
    291 $template->assign('image_order_field_options', $sort_fields);
    292 $template->assign('image_order_direction_options', $sort_directions);
    293 
    294 $matches = array();
    295 if ( !empty( $category['image_order'] ) )
    296 {
    297   preg_match_all('/([a-z_]+) *(?:(asc|desc)(?:ending)?)? *(?:, *|$)/i',
    298     $category['image_order'], $matches);
    299 }
     287$template->assign('image_order_options', $sort_fields);
     288
     289$image_order = explode(',', $category['image_order']);
    300290
    301291for ($i=0; $i<3; $i++) // 3 fields
    302292{
    303   $tpl_image_order_select = array(
    304       'ID' => $i+1,
    305       'FIELD' => array(''),
    306       'DIRECTION' => array('ASC'),
    307     );
    308 
    309   if ( isset($matches[1][$i]) )
    310   {
    311     $tpl_image_order_select['FIELD'] = array($matches[1][$i]);
    312   }
    313 
    314   if (isset($matches[2][$i]) and strcasecmp($matches[2][$i],'DESC')==0)
    315   {
    316     $tpl_image_order_select['DIRECTION'] = array('DESC');
    317   }
    318   $template->append( 'image_orders', $tpl_image_order_select);
     293  if ( isset($image_order[$i]) )
     294  {
     295    $template->append('image_order', $image_order[$i]);
     296  }
     297  else
     298  {
     299    $template->append('image_order', '');
     300  }
    319301}
    320302
  • trunk/admin/themes/default/template/configuration.tpl

    r13024 r13087  
    109109        {foreach from=$main.order_by item=order}
    110110        <span class="filter {if $ORDER_BY_IS_CUSTOM}transparent{/if}">         
    111           <select name="order_by_field[]" {if $ORDER_BY_IS_CUSTOM}disabled{/if}>
    112             {html_options options=$main.order_field_options selected=$order.FIELD }
     111          <select name="order_by[]" {if $ORDER_BY_IS_CUSTOM}disabled{/if}>
     112            {html_options options=$main.order_by_options selected=$order}
    113113          </select>
    114           <select name="order_by_direction[]" {if $ORDER_BY_IS_CUSTOM}disabled{/if}>
    115             {html_options options=$main.order_direction_options selected=$order.DIRECTION }
    116           </select> 
    117114          <a class="removeFilter">{'delete'|@translate}</a>
    118115        </span>
     
    129126{footer_script require='jquery'}
    130127// counters for displaying of addFilter link
    131 fields = {$main.order_by|@count}; max_fields = {$main.order_field_options|@count}; max_fields--;
     128fields = {$main.order_by|@count}; max_fields = Math.ceil({$main.order_by_options|@count}/2);
    132129
    133130{literal}
     
    150147jQuery(document).ready(function () {
    151148  $('.addFilter').click(function() {
    152     rel = $(this).attr('rel');
    153149    $(this).prev('span.filter').clone().insertBefore($(this));
    154     $(this).prev('span.filter').children('select[name="order_by_field[]"]').val('');
    155     $(this).prev('span.filter').children('select[name="order_by_direction[]"]').val('ASC');
     150    $(this).prev('span.filter').children('select[name="order_by[]"]').val('');
    156151   
    157152    fields++;
  • trunk/admin/themes/default/template/element_set_ranks.tpl

    r13013 r13087  
    7979      <label for="image_order_user_define">{'automatic order'|@translate}</label>
    8080      <div id="image_order_user_define_options">
    81       {foreach from=$image_orders item=order}
     81      {foreach from=$image_order item=order}
    8282      <p class="field">
    83         <select name="order_field_{$order.ID}">
    84           {html_options options=$image_order_field_options selected=$order.FIELD }
     83        <select name="image_order[]">
     84          {html_options options=$image_order_options selected=$order}
    8585        </select>
    86         <select name="order_direction_{$order.ID}">
    87           {html_options options=$image_order_direction_options selected=$order.DIRECTION }
    88         </select>     
    8986      </p>
    9087      {/foreach}
Note: See TracChangeset for help on using the changeset viewer.