Ignore:
Timestamp:
Mar 23, 2013, 11:50:57 AM (11 years ago)
Author:
rvelices
Message:

feature 2557 recent photos/albums should never be empty

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/category_cats.inc.php

    r20177 r21802  
    4747{
    4848  $query.= '
    49   WHERE date_last >= '.pwg_db_get_recent_period_expression($user['recent_period']);
     49  WHERE '.get_recent_photos_sql('date_last');
    5050}
    5151else
     
    6767}
    6868
    69 $query.= '
    70 ;';
    71 
    7269$result = pwg_query($query);
    7370$categories = array();
     
    8481    $image_id = $row['user_representative_picture_id'];
    8582  }
    86   else if (!empty($row['representative_picture_id']))
     83  elseif (!empty($row['representative_picture_id']))
    8784  { // if a representative picture is set, it has priority
    8885    $image_id = $row['representative_picture_id'];
    8986  }
    90   else if ($conf['allow_random_representative'])
    91   {
    92     // searching a random representant among elements in sub-categories
     87  elseif ($conf['allow_random_representative'])
     88  { // searching a random representant among elements in sub-categories
    9389    $image_id = get_random_image_in_category($row);
    9490  }
    95   else
     91  elseif ($row['count_categories']>0 and $row['count_images']>0)
    9692  { // searching a random representant among representant of sub-categories
    97     if ($row['count_categories']>0 and $row['count_images']>0)
    98     {
    99       $query = '
    100   SELECT representative_picture_id
    101     FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
    102     ON id = cat_id and user_id = '.$user['id'].'
    103     WHERE uppercats LIKE \''.$row['uppercats'].',%\'
    104       AND representative_picture_id IS NOT NULL'
    105     .get_sql_condition_FandF
    106     (
    107       array
    108         (
    109           'visible_categories' => 'id',
    110         ),
    111       "\n  AND"
    112     ).'
    113     ORDER BY '.DB_RANDOM_FUNCTION.'()
    114     LIMIT 1
    115   ;';
    116       $subresult = pwg_query($query);
    117       if (pwg_db_num_rows($subresult) > 0)
    118       {
    119         list($image_id) = pwg_db_fetch_row($subresult);
    120       }
    121     }
    122   }
     93    $query = '
     94SELECT representative_picture_id
     95  FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
     96  ON id = cat_id and user_id = '.$user['id'].'
     97  WHERE uppercats LIKE \''.$row['uppercats'].',%\'
     98    AND representative_picture_id IS NOT NULL'
     99  .get_sql_condition_FandF
     100  (
     101    array
     102      (
     103        'visible_categories' => 'id',
     104      ),
     105    "\n  AND"
     106  ).'
     107  ORDER BY '.DB_RANDOM_FUNCTION.'()
     108  LIMIT 1
     109;';
     110    $subresult = pwg_query($query);
     111    if (pwg_db_num_rows($subresult) > 0)
     112    {
     113      list($image_id) = pwg_db_fetch_row($subresult);
     114    }
     115  }
     116
    123117
    124118  if (isset($image_id))
     
    130124
    131125    $row['representative_picture_id'] = $image_id;
    132     array_push($image_ids, $image_id);
    133     array_push($categories, $row);
    134     array_push($category_ids, $row['id']);
     126    $image_ids[] = $image_id;
     127    $categories[] = $row;
     128    $category_ids[] = $row['id'];
    135129  }
    136130  unset($image_id);
Note: See TracChangeset for help on using the changeset viewer.