Changeset 11546


Ignore:
Timestamp:
Jun 28, 2011, 3:19:44 PM (13 years ago)
Author:
mistic100
Message:

keep category representant if possible

Location:
extensions/SmartAlbums
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • extensions/SmartAlbums/admin/albums.inc.php

    r11392 r11546  
    6565      array_push(
    6666        $page['infos'],
    67         l10n_args(get_l10n_args(
    68           '%d photos associated to album «%s»',
    69           array(
    70             count($associated_images),
    71             trigger_event(
    72               'render_category_name',
    73               $category['name'],
    74               'admin_cat_list'
    75               )
    76             )
    77           ))
     67        sprintf(
     68          l10n('%d photos associated to album %s'),
     69          count($associated_images),
     70          '«'.trigger_event(
     71            'render_category_name',
     72            $category['name'],
     73            'admin_cat_list'
     74            ).'»'
     75          )
    7876        );
    7977    }
     
    8583    array_push(
    8684      $page['infos'],
    87       l10n_args(get_l10n_args(
    88         '%d photos associated to album «%s»',
    89         array(
    90           count($associated_images),
    91           trigger_event(
    92             'render_category_name',
    93             $categories[$_GET['smart_generate']]['name'],
    94             'admin_cat_list'
    95             )
    96           )
    97         ))
     85      sprintf(
     86        l10n('%d photos associated to album %s'),
     87        count($associated_images),
     88        '«'.trigger_event(
     89          'render_category_name',
     90          $categories[$_GET['smart_generate']]['name'],
     91          'admin_cat_list'
     92          ).'»'
     93        )
    9894      );
    9995  }
  • extensions/SmartAlbums/include/functions.inc.php

    r11381 r11546  
    99function smart_make_associations($cat_id)
    1010{
    11   pwg_query('DELETE FROM '.IMAGE_CATEGORY_TABLE.' WHERE category_id = '.$cat_id.' AND smart = true;');
     11  $query = '
     12DELETE FROM '.IMAGE_CATEGORY_TABLE.'
     13  WHERE
     14    category_id = '.$cat_id.'
     15    AND smart = true
     16;';
     17  pwg_query($query);
    1218 
    1319  $images = smart_get_pictures($cat_id);
     
    3036  }
    3137 
    32   if (!function_exists('set_random_representant'))
    33   {
    34     include(PHPWG_ROOT_PATH.'admin/include/functions.php');
    35   }
    36   set_random_representant(array($cat_id));
     38  // represantant, try to not overwrite if still in images list
     39  $query = '
     40SELECT representative_picture_id
     41  FROM '.CATEGORIES_TABLE.'
     42  WHERE id = '.$cat_id.'
     43;';
     44  list($rep_id) = pwg_db_fetch_row(pwg_query($query));
     45 
     46  if ( !in_array($rep_id, $images) )
     47  {
     48    if (!function_exists('set_random_representant'))
     49    {
     50      include(PHPWG_ROOT_PATH.'admin/include/functions.php');
     51    }
     52    set_random_representant(array($cat_id));
     53  }
    3754 
    3855  return $images;
     
    7996  if ($filters == null)
    8097  {
     98    $filters = array();
     99   
    81100    $query = '
    82101SELECT *
     
    85104  ORDER BY type ASC, cond ASC
    86105;';
    87     $filters = pwg_query($query);
    88    
    89     if (!pwg_db_num_rows($filters)) return array();
    90    
    91     while ($filter = pwg_db_fetch_assoc($filters))
    92     {
    93       $temp[] = array(
    94         'type' => $filter['type'],
    95         'cond' => $filter['cond'],
    96         'value' => $filter['value'],
     106    $result = pwg_query($query);
     107   
     108    if (!pwg_db_num_rows($result)) return $filters;
     109   
     110    while ($row = pwg_db_fetch_assoc($result))
     111    {
     112      $filters[] = array(
     113        'type' => $row['type'],
     114        'cond' => $row['cond'],
     115        'value' => $row['value'],
    97116        );
    98117    }
    99      
    100     $filters = $temp;
    101118  }
    102119   
     
    110127    if ($filter['type'] == 'tags')
    111128    {
    112         if($filter['cond'] == "all")
    113         {
    114           $tags_arr = explode(',', $filter['value']);
    115          
    116           foreach($tags_arr as $value)
    117           {
    118             $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id';
    119             $where[] = 'it_'.$i_tags.'.tag_id = '.$value;
    120             $i_tags++;
    121           }
    122         }
    123         else if ($filter['cond'] == 'one')
     129      if($filter['cond'] == "all")
     130      {
     131        $tags_arr = explode(',', $filter['value']);
     132       
     133        foreach($tags_arr as $value)
    124134        {
    125135          $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id';
    126           $where[] = 'it_'.$i_tags.'.tag_id IN ('.$filter['value'].')';
     136          $where[] = 'it_'.$i_tags.'.tag_id = '.$value;
    127137          $i_tags++;
    128138        }
    129         else if ($filter['cond'] == 'none')
    130         {
    131           $sub_query = '
     139      }
     140      else if ($filter['cond'] == 'one')
     141      {
     142        $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id';
     143        $where[] = 'it_'.$i_tags.'.tag_id IN ('.$filter['value'].')';
     144        $i_tags++;
     145      }
     146      else if ($filter['cond'] == 'none')
     147      {
     148        $sub_query = '
    132149      SELECT it_'.$i_tags.'.image_id
    133150        FROM '.IMAGE_TAG_TABLE.' AS it_'.$i_tags.'
     
    137154        GROUP BY it_'.$i_tags.'.image_id
    138155    ';
    139           $where[] = 'NOT EXISTS ('.$sub_query.')';
    140           $i_tags++;
    141         }
    142         else if ($filter['cond'] == 'only')
    143         {
    144           $sub_query = '
     156        $where[] = 'NOT EXISTS ('.$sub_query.')';
     157        $i_tags++;
     158      }
     159      else if ($filter['cond'] == 'only')
     160      {
     161        $sub_query = '
    145162      SELECT it_'.$i_tags.'.image_id
    146163        FROM '.IMAGE_TAG_TABLE.' AS it_'.$i_tags.'
     
    150167        GROUP BY it_'.$i_tags.'.image_id
    151168    ';
    152           $where[] = 'NOT EXISTS ('.$sub_query.')';
     169        $where[] = 'NOT EXISTS ('.$sub_query.')';
     170     
     171        $i_tags++;
     172        $tags_arr = explode(',', $filter['value']);
    153173       
     174        foreach($tags_arr as $value)
     175        {
     176          $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id';
     177          $where[] = 'it_'.$i_tags.'.tag_id = '.$value;
    154178          $i_tags++;
    155           $tags_arr = explode(',', $filter['value']);
    156          
    157           foreach($tags_arr as $value)
    158           {
    159             $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id';
    160             $where[] = 'it_'.$i_tags.'.tag_id = '.$value;
    161             $i_tags++;
    162           }
    163         }       
     179        }
     180      }       
    164181    }
    165182    // date
     
    234251/**
    235252 * Check if the filter is proper
    236  *
    237253 * @param array filter
    238254 * @return array or false
     
    246262  if ($filter['type'] == 'tags')
    247263  {
    248     if ($filter['value'] == null) // tags fields musn't be null
     264    if ($filter['value'] == null)
    249265    {
    250266      $error = true;
     
    259275  else if ($filter['type'] == 'date')
    260276  {
    261     if (!preg_match('#([0-9]{4})-([0-9]{2})-([0-9]{2})#', $filter['value'])) // dates must be proper
     277    if (!preg_match('#([0-9]{4})-([0-9]{2})-([0-9]{2})#', $filter['value']))
    262278    {
    263279      $error = true;
     
    268284  else if ($filter['type'] == 'limit')
    269285  {
    270     if (!preg_match('#([0-9]{1,})#', $filter['value'])) // limit must be an integer
     286    if (!preg_match('#([0-9]{1,})#', $filter['value']))
    271287    {
    272288      $error = true;
     
    298314/**
    299315 * inserts multiple lines in a table, ignore duplicate entries
    300  *
    301316 * @param string table_name
    302317 * @param array dbfields
  • extensions/SmartAlbums/include/init_cat_list.php

    r11392 r11546  
    4444        array_push(
    4545          $page['infos'],
    46           l10n_args(get_l10n_args(
    47             '%d photos associated to album «%s»',
    48             array(
    49               count($associated_images),
    50               trigger_event(
    51                 'render_category_name',
    52                 $category['name'],
    53                 'admin_cat_list'
    54                 )
    55               )
    56             ))
     46          sprintf(
     47            l10n('%d photos associated to album %s'),
     48            count($associated_images),
     49            '«'.trigger_event(
     50              'render_category_name',
     51              $category['name'],
     52              'admin_cat_list'
     53              ).'»'
     54            )
    5755          );
    5856      }
     
    6462      array_push(
    6563        $page['infos'],
    66         l10n_args(get_l10n_args(
    67           '%d photos associated to album «%s»',
    68           array(
    69             count($associated_images),
    70             trigger_event(
    71               'render_category_name',
    72               $smart_cats[$_GET['smart_generate']]['name'],
    73               'admin_cat_list'
    74               )
    75             )
    76           ))
     64        sprintf(
     65          l10n('%d photos associated to album %s'),
     66          count($associated_images),
     67          '«'.trigger_event(
     68            'render_category_name',
     69            $smart_cats[$_GET['smart_generate']]['name'],
     70            'admin_cat_list'
     71            ).'»'
     72          )
    7773        );
    7874    }
     
    113109  {
    114110    $search[1] = '</ul>
    115 </form>
    116 {/if}';
     111</form>';
    117112    $replacement[1] = $search[1].'
    118113<form method="post" action="{$SMART_URL.all}">
  • extensions/SmartAlbums/include/init_cat_modify.php

    r11392 r11546  
    6262      $associated_images = smart_make_associations($cat_id);
    6363      $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', count($associated_images)));
     64     
     65      array_push(
     66          $page['infos'],
     67          sprintf(
     68            l10n('%d photos associated to album %s'),
     69            count($associated_images),
     70            ''
     71            )
     72          );
    6473     
    6574      define('SMART_NOT_UPDATE', 1);
  • extensions/SmartAlbums/language/en_UK/plugin.lang.php

    r11451 r11546  
    11<?php
    22
    3 $lang['%d photos associated to album &laquo;%s&raquo;'] = '%d photos associated to album &laquo;%s&raquo;';
     3$lang['%d photos associated to album %s'] = '%d photos associated to album %s';
    44$lang['No filter selected'] = 'No filter selected';
    55$lang['No tag selected'] = 'No tag selected';
  • extensions/SmartAlbums/language/fr_FR/plugin.lang.php

    r11451 r11546  
    11<?php
    22
    3 $lang['%d photos associated to album &laquo;%s&raquo;'] = '%d photos associées à l\'album &laquo;%s&raquo;';
     3$lang['%d photos associated to album %s'] = '%d photos associées à l\'album %s';
    44$lang['No filter selected'] = 'Aucun filtre sélectionné';
    55$lang['No tag selected'] = 'Aucun tag sélectionné';
  • extensions/SmartAlbums/language/it_IT/plugin.lang.php

    r11451 r11546  
    11<?php
    22
    3 $lang['%d photos associated to album &laquo;%s&raquo;'] = '%d foto associate all\'album "%s"';
     3$lang['%d photos associated to album %s'] = '%d foto associate all\'album %s';
    44$lang['No filter selected'] = 'Nessun filtro selezionato';
    55$lang['No tag selected'] = 'Nessun tag selezionato';
  • extensions/SmartAlbums/language/lv_LV/plugin.lang.php

    r11451 r11546  
    11<?php
    22
    3 $lang['%d photos associated to album «%s»'] = '%d fotogrāfiju saistītas ar albūmu «%s»';
     3$lang['%d photos associated to album %s'] = '%d fotogrāfiju saistītas ar albūmu %s';
    44$lang['No filter selected'] = 'Nav izvēlēts neviens no filtriem';
    55$lang['No tag selected'] = 'Nav izvēlēts neviens no tagiem';
Note: See TracChangeset for help on using the changeset viewer.