Changeset 12630


Ignore:
Timestamp:
Nov 15, 2011, 12:58:10 PM (9 years ago)
Author:
plg
Message:

merge r12629 from branch 2.3 to trunk

bug 2506 fixed: Batch Manager does not take permissions into account when
filtering on tags

feature 2507 added: Batch Manager can filter on "all tags" or "any tag"

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/batch_manager.php

    r12259 r12630  
    7272  {
    7373    $_SESSION['bulk_manager_filter']['tags'] = get_tag_ids($_POST['filter_tags'], false);
     74
     75    if (isset($_POST['tag_mode']) and in_array($_POST['tag_mode'], array('AND', 'OR')))
     76    {
     77      $_SESSION['bulk_manager_filter']['tag_mode'] = $_POST['tag_mode'];
     78    }
    7479  }
    7580
     
    298303if (!empty($_SESSION['bulk_manager_filter']['tags']))
    299304{
    300         $query = '
    301 SELECT image_id
    302         FROM '.IMAGE_TAG_TABLE.
    303         'WHERE tag_id IN('.implode(',',$_SESSION['bulk_manager_filter']['tags']).')
    304         GROUP BY image_id
    305         HAVING COUNT(tag_id)='.count($_SESSION['bulk_manager_filter']['tags']);
    306         array_push(
     305  array_push(
    307306    $filter_sets,
    308                 get_image_ids_for_tags($_SESSION['bulk_manager_filter']['tags'])
    309                 );
     307    get_image_ids_for_tags(
     308      $_SESSION['bulk_manager_filter']['tags'],
     309      $_SESSION['bulk_manager_filter']['tag_mode'],
     310      null,
     311      null,
     312      false // we don't apply permissions in administration screens
     313      )
     314    );
    310315}
    311316
  • trunk/admin/themes/default/template/batch_manager_global.tpl

    r12474 r12630  
    484484        <label><input type="checkbox" name="filter_category_recursive" {if isset($filter.category_recursive)}checked="checked"{/if}> {'include child albums'|@translate}</label>
    485485      </li>
    486                         <li id="filter_tags" {if !isset($filter.tags)}style="display:none"{/if}>
    487                                 <a href="#" class="removeFilter" title="remove this filter"><span>[x]</span></a>
    488                                 <input type="checkbox" name="filter_tags_use" class="useFilterCheckbox" {if isset($filter.tags)}checked="checked"{/if}>
    489                                 {'Tags'|@translate}
    490                                 <select id="tagsFilter" name="filter_tags">
    491                                         {foreach from=$filter_tags item=tag}
    492                                         <option value="{$tag.id}">{$tag.name}</option>
    493                                         {/foreach}
    494                                 </select>
    495                         </li>
     486      <li id="filter_tags" {if !isset($filter.tags)}style="display:none"{/if}>
     487        <a href="#" class="removeFilter" title="remove this filter"><span>[x]</span></a>
     488        <input type="checkbox" name="filter_tags_use" class="useFilterCheckbox" {if isset($filter.tags)}checked="checked"{/if}>
     489        {'Tags'|@translate}
     490        <select id="tagsFilter" name="filter_tags">
     491          {foreach from=$filter_tags item=tag}
     492          <option value="{$tag.id}">{$tag.name}</option>
     493          {/foreach}
     494        </select>
     495        <label><span><input type="radio" name="tag_mode" value="AND" {if !isset($filter.tag_mode) or $filter.tag_mode eq 'AND'}checked="checked"{/if}> {'All tags'|@translate}</span></label>
     496        <label><span><input type="radio" name="tag_mode" value="OR" {if isset($filter.tag_mode) and $filter.tag_mode eq 'OR'}checked="checked"{/if}> {'Any tag'|@translate}</span></label>
     497      </li>
    496498      <li id="filter_level" {if !isset($filter.level)}style="display:none"{/if}>
    497499        <a href="#" class="removeFilter" title="remove this filter"><span>[x]</span></a>
  • trunk/include/functions_tag.inc.php

    r12118 r12630  
    167167 * @return array
    168168 */
    169 function get_image_ids_for_tags($tag_ids, $mode='AND', $extra_images_where_sql='', $order_by='')
     169function get_image_ids_for_tags($tag_ids, $mode='AND', $extra_images_where_sql='', $order_by='', $use_permissions=true)
    170170{
    171171  global $conf;
     
    176176
    177177  $query = 'SELECT id
    178   FROM '.IMAGES_TABLE.' i
    179     INNER JOIN '.IMAGE_CATEGORY_TABLE.' ic ON id=ic.image_id
     178  FROM '.IMAGES_TABLE.' i ';
     179
     180  if ($use_permissions)
     181  {
     182    $query.= '
     183    INNER JOIN '.IMAGE_CATEGORY_TABLE.' ic ON id=ic.image_id';
     184  }
     185
     186  $query.= '
    180187    INNER JOIN '.IMAGE_TAG_TABLE.' it ON id=it.image_id
    181     WHERE tag_id IN ('.implode(',', $tag_ids).')'
    182     .get_sql_condition_FandF
    183     (
    184       array
    185         (
    186           'forbidden_categories' => 'category_id',
    187           'visible_categories' => 'category_id',
    188           'visible_images' => 'id'
     188    WHERE tag_id IN ('.implode(',', $tag_ids).')';
     189
     190  if ($use_permissions)
     191  {
     192    $query.= get_sql_condition_FandF(
     193      array(
     194        'forbidden_categories' => 'category_id',
     195        'visible_categories' => 'category_id',
     196        'visible_images' => 'id'
    189197        ),
    190198      "\n  AND"
    191     )
    192   .(empty($extra_images_where_sql) ? '' : " \nAND (".$extra_images_where_sql.')')
    193   .'
     199      );
     200  }
     201
     202  $query.= (empty($extra_images_where_sql) ? '' : " \nAND (".$extra_images_where_sql.')').'
    194203  GROUP BY id';
    195204 
Note: See TracChangeset for help on using the changeset viewer.