Changeset 28063


Ignore:
Timestamp:
Apr 3, 2014, 8:03:58 PM (10 years ago)
Author:
mistic100
Message:

add recursive option for album filter
fix choosen display

Location:
extensions/SmartAlbums
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • extensions/SmartAlbums/admin/template/album.tpl

    r27266 r28063  
    7070      }
    7171      else if (type == "album") {
     72        var values = value.split(','),
     73            recursive = values.splice(0, 1)[0];
     74        value = values.join(',');
     75
    7276        select_options($block, value);
     77        $block.find('.filter-value input[type="checkbox"]').prop('checked', recursive=="true");
    7378      }
    7479      else if (type == "level") {
  • extensions/SmartAlbums/admin/template/filters.inc.tpl

    r27266 r28063  
    8282      {html_options options=$all_albums}
    8383    </select>
     84   
     85    <label><input type="checkbox" name="filters[iiii][recursive]"> {'include child albums'|translate}</label>
    8486  </span>
    8587</li>
  • extensions/SmartAlbums/admin/template/style.css

    r26442 r28063  
    2727  padding-left:0px;
    2828}
    29 #filtersList li {
     29#filtersList>li {
    3030  padding:3px 0;
    3131  border-bottom:1px dotted rgba(100, 100, 100, 0.5);
    3232  display:block;
    3333}
    34 #filtersList li>span {
     34#filtersList>li>span {
    3535  display:inline-block;
    3636  vertical-align:middle;
  • extensions/SmartAlbums/include/functions.inc.php

    r27266 r28063  
    277277      case 'album':
    278278      {
     279        $filter['values'] = explode(',', $filter['value']);
     280        $filter['recursive'] = array_shift($filter['values']) == "true";
     281        $filter['value'] = implode(',', $filter['values']);
     282
    279283        switch ($filter['cond'])
    280284        {
     
    282286          case 'all':
    283287          {
    284             $albums_arr = explode(',', $filter['value']);
    285             foreach($albums_arr as $value)
    286             {
     288            foreach ($filter['values'] as $value)
     289            {
     290              if ($filter['recursive'])
     291              {
     292                $value = get_subcat_ids_query(array($value));
     293              }
    287294              $sub_query = '
    288295      SELECT image_id
    289296        FROM '.IMAGE_CATEGORY_TABLE.'
    290         WHERE category_id = '.$value.'
     297        WHERE category_id IN('.$value.')
    291298      ';
    292299              $where[] = 'i.id IN ('.$sub_query.')';
     
    298305          case 'one':
    299306          {
     307            if ($filter['recursive'])
     308            {
     309              $value = get_subcat_ids_query($filter['values']);
     310            }
     311            else
     312            {
     313              $value = $filter['value'];
     314            }
    300315            $sub_query = '
    301316      SELECT image_id
    302317        FROM '.IMAGE_CATEGORY_TABLE.'
    303         WHERE category_id IN('.$filter['value'].')
     318        WHERE category_id IN('.$value.')
    304319      ';
    305320            $where[] = 'i.id IN ('.$sub_query.')';
     
    310325          case 'none':
    311326          {
     327            if ($filter['recursive'])
     328            {
     329              $value = get_subcat_ids_query($filter['values']);
     330            }
     331            else
     332            {
     333              $value = $filter['value'];
     334            }
    312335            $sub_query = '
    313336      SELECT image_id
    314337        FROM '.IMAGE_CATEGORY_TABLE.'
    315         WHERE category_id IN('.$filter['value'].')
     338        WHERE category_id IN('.$value.')
    316339      ';
    317340            $where[] = 'i.id NOT IN ('.$sub_query.')';
     
    322345          case 'only':
    323346          {
     347            if ($filter['recursive'])
     348            {
     349              $value = get_subcat_ids_query($filter['values']);
     350            }
     351            else
     352            {
     353              $value = $filter['value'];
     354            }
    324355            $sub_query = '
    325356      SELECT image_id
    326357        FROM '.IMAGE_CATEGORY_TABLE.'
    327         WHERE category_id NOT IN('.$filter['value'].')
     358        WHERE category_id NOT IN('.$value.')
    328359      ';
    329360            $where[] = 'i.id NOT IN ('.$sub_query.')';
    330361
    331             $albums_arr = explode(',', $filter['value']);
    332             foreach($albums_arr as $value)
    333             {
     362            foreach ($filter['values'] as $value)
     363            {
     364              if ($filter['recursive'])
     365              {
     366                $value = get_subcat_ids_query(array($value));
     367              }
    334368              $sub_query = '
    335369      SELECT image_id
     
    544578      else
    545579      {
     580        array_unshift($filter['value'], boolean_to_string(isset($filter['recursive'])));
    546581        $filter['value'] = implode(',', $filter['value']);
    547582      }
     
    651686  }
    652687}
     688
     689/**
     690 * Returns SQL query returning all subcategory identifiers of given category ids
     691 *
     692 * @param int[] $ids
     693 * @return int[]
     694 */
     695function get_subcat_ids_query($ids)
     696{
     697  $query = '
     698SELECT DISTINCT(id)
     699  FROM '.CATEGORIES_TABLE.'
     700  WHERE ';
     701  foreach ($ids as $num => $category_id)
     702  {
     703    if ($num > 0)
     704    {
     705      $query.= '
     706    OR ';
     707    }
     708    $query.= 'uppercats '.DB_REGEX_OPERATOR.' \'(^|,)'.$category_id.'(,|$)\'';
     709  }
     710  return $query;
     711}
  • extensions/SmartAlbums/maintain.inc.php

    r27300 r28063  
    119119    pwg_query('UPDATE `' . $this->table . '` SET cond = "" WHERE type = "limit" AND cond = "limit";');
    120120    pwg_query('ALTER TABLE `' . $this->table . '` CHANGE `cond` `cond` VARCHAR(32) NULL ;');
     121   
     122    $result = pwg_query('SELECT COUNT(*) FROM `' . $this->table . '` WHERE type="album" AND (value NOT LIKE "true,%" OR value NOT LIKE "false,%");');
     123    if (pwg_db_num_rows(pwg_query($query)))
     124    {
     125      pwg_query('UPDATE `' . $this->table . '` SET value = CONCAT("false,", value) WHERE type="album";');
     126    }
    121127
    122128    $this->installed = true;
Note: See TracChangeset for help on using the changeset viewer.