Changeset 5759


Ignore:
Timestamp:
Apr 10, 2010, 3:25:20 PM (10 years ago)
Author:
nikrou
Message:

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

Location:
trunk/admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/element_set_ranks.php

    r5196 r5759  
    8585// +-----------------------------------------------------------------------+
    8686
     87$image_order_choices = array('default', 'rank', 'user_define');
     88$image_order_choice = 'default';
     89
    8790if (isset($_POST['submit']))
    8891{
     
    98101    l10n('Images manual order was saved')
    99102    );
     103
     104  $image_order = null;
     105  if (!empty($_POST['image_order_choice'])
     106      && in_array($_POST['image_order_choice'], $image_order_choices))
     107  {
     108    $image_order_choice = $_POST['image_order_choice'];
     109  }
     110     
     111  if ($image_order_choice=='user_define')
     112  {
     113    for ($i=1; $i<=3; $i++)
     114    {
     115      if ( !empty($_POST['order_field_'.$i]) )
     116      {
     117        if (! empty($image_order) )
     118        {
     119          $image_order .= ',';
     120        }
     121        $image_order .= $_POST['order_field_'.$i];
     122        if ($_POST['order_direction_'.$i]=='DESC')
     123        {
     124          $image_order .= ' DESC';
     125        }
     126      }
     127    }
     128  }
     129  elseif ($image_order_choice=='rank')
     130  {
     131    $image_order = 'rank';
     132  }
     133  $query = '
     134UPDATE '.CATEGORIES_TABLE.' SET image_order=\''.$image_order.'\'
     135  WHERE id='.$page['category_id'];
     136  pwg_query($query);
    100137}
    101138
     
    109146$base_url = get_root_url().'admin.php';
    110147
    111 // $form_action = $base_url.'?page=element_set_global';
    112 
    113148$query = '
    114 SELECT uppercats
     149SELECT *
    115150  FROM '.CATEGORIES_TABLE.'
    116151  WHERE id = '.$page['category_id'].'
    117152;';
    118153$category = pwg_db_fetch_assoc(pwg_query($query));
     154
     155if ($category['image_order']=='rank')
     156{
     157  $image_order_choice = 'rank';
     158}
     159elseif ($category['image_order']!='')
     160{
     161  $image_order_choice = 'user_define';
     162}
    119163
    120164// Navigation path
     
    175219}
    176220
     221// image order management
     222$sort_fields = array(
     223  '' => '',
     224  'date_creation' => l10n('Creation date'),
     225  'date_available' => l10n('Post date'),
     226  'average_rate' => l10n('Average rate'),
     227  'hit' => l10n('Most visited'),
     228  'file' => l10n('File name'),
     229  'id' => 'Id',
     230  'rank' => l10n('Rank'),
     231  );
     232
     233$sort_directions = array(
     234  'ASC' => l10n('ascending'),
     235  'DESC' => l10n('descending'),
     236  );
     237
     238$template->assign('image_order_field_options', $sort_fields);
     239$template->assign('image_order_direction_options', $sort_directions);
     240
     241$matches = array();
     242if ( !empty( $category['image_order'] ) )
     243{
     244  preg_match_all('/([a-z_]+) *(?:(asc|desc)(?:ending)?)? *(?:, *|$)/i',
     245    $category['image_order'], $matches);
     246}
     247
     248for ($i=0; $i<3; $i++) // 3 fields
     249{
     250  $tpl_image_order_select = array(
     251      'ID' => $i+1,
     252      'FIELD' => array(''),
     253      'DIRECTION' => array('ASC'),
     254    );
     255
     256  if ( isset($matches[1][$i]) )
     257  {
     258    $tpl_image_order_select['FIELD'] = array($matches[1][$i]);
     259  }
     260
     261  if (isset($matches[2][$i]) and strcasecmp($matches[2][$i],'DESC')==0)
     262  {
     263    $tpl_image_order_select['DIRECTION'] = array('DESC');
     264  }
     265  $template->append( 'image_orders', $tpl_image_order_select);
     266}
     267
     268$template->assign('image_order_choice', $image_order_choice);
     269
     270
    177271// +-----------------------------------------------------------------------+
    178272// |                          sending html code                            |
  • trunk/admin/themes/default/default-layout.css

    r5702 r5759  
    292292        margin-top: 2em;
    293293        margin-bottom: 2em;
     294}
     295
     296form p.field {
     297  text-align: left;
    294298}
    295299
  • trunk/admin/themes/default/template/element_set_ranks.tpl

    r5187 r5759  
    22{known_script id="jquery.ui" src=$ROOT_URL|@cat:"themes/default/js/ui/packed/ui.core.packed.js" }
    33{known_script id="jquery.ui.sortable" src=$ROOT_URL|@cat:"themes/default/js/ui/packed/ui.sortable.packed.js" }
    4 
     4{html_head}
    55{literal}
    66<script type="text/javascript">
     
    1616  .each(function() { $(this).attr('value', (i+1)*10)});
    1717  });
     18  $('#image_order_rank').attr('checked', true);
    1819  }
    1920  });
     
    2223</script>
    2324{/literal}
     25{/html_head}
    2426
    2527<h2>{'Manage image ranks'|@translate}</h2>
     
    4749    {/if}
    4850  </fieldset>
     51
     52  <fieldset>
     53    <legend>{'Sort order'|@translate}</legend>
     54    <p class="field">
     55      <input type="radio" name="image_order_choice" id="image_order_default" value="default"{if $image_order_choice=='default'} checked="checked"{/if}>
     56      <label for="image_order_default">{'Use the default image sort order (defined in the configuration file)'|@translate}</label>
     57    </p>
     58    <p class="field">
     59      <input type="radio" name="image_order_choice" id="image_order_rank" value="rank"{if $image_order_choice=='rank'} checked="checked"{/if}>
     60      <label for="image_order_rank">{'By rank'|@translate}</label>
     61    </p>
     62    <p class="field">
     63      <input type="radio" name="image_order_choice" id="image_order_user_define" value="user_define"{if $image_order_choice=='user_define'} checked="checked"{/if}>
     64      <label for="image_order_user_define">{'Manual order'|@translate}</label>
     65      {foreach from=$image_orders item=order}
     66      <p class="field">
     67        <select name="order_field_{$order.ID}">
     68          {html_options options=$image_order_field_options selected=$order.FIELD }
     69        </select>
     70        <select name="order_direction_{$order.ID}">
     71          {html_options options=$image_order_direction_options selected=$order.DIRECTION }
     72        </select>     
     73      </p>
     74      {/foreach}
     75  </fieldset>
    4976  <p><input class="submit" type="submit" value="{'Submit'|@translate}" name="submit" {$TAG_INPUT_ENABLED}></p>
    5077</form>
     78
    5179
    5280{else}
Note: See TracChangeset for help on using the changeset viewer.