Changeset 1651


Ignore:
Timestamp:
Dec 13, 2006, 1:05:16 AM (17 years ago)
Author:
rub
Message:

Feature Issue ID 0000601: Filter all public pages with only recent elements

Last draft before final development.
There a icon for global mode and one other for local mode.

Counters are not good, filter on images are not everywhere applied, moment to update cache are not optimized, ...

Go to http://forum.phpwebgallery.net/viewtopic.php?id=9490

Location:
trunk
Files:
10 edited

Legend:

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

    r1648 r1651  
    5656  WHERE id_uppercat '.
    5757  (!isset($page['category']) ? 'is NULL' : '= '.$page['category']);
    58   if ($page['filter_mode'])
     58  if ($page['filter_local_mode'])
    5959  {
    6060    $query.= '
     
    8686  FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
    8787    ON ic.category_id = c.id';
    88     if ($page['filter_mode'])
     88    if ($page['filter_local_mode'] or $user['filter_global_mode'])
    8989    {
    9090      $query.= '
     
    9494  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
    9595    AND c.id NOT IN ('.$user['forbidden_categories'].')';
    96     if ($page['filter_mode'])
     96    if ($page['filter_local_mode'] or $user['filter_global_mode'])
    9797    {
    9898      $query.= '
     
    118118  WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
    119119    AND representative_picture_id IS NOT NULL';
    120     if ($page['filter_mode'])
     120    if ($page['filter_local_mode'] or $user['filter_global_mode'])
    121121    {
    122122      $query.= '
  • trunk/include/category_default.inc.php

    r1648 r1651  
    4848  FROM '.IMAGES_TABLE.'
    4949  WHERE id IN ('.implode(',', $selection).')';
    50   if ($page['filter_mode'])
     50  if ($page['filter_local_mode'] or $user['filter_global_mode'])
    5151  {
    5252    $query.= '
  • trunk/include/functions_category.inc.php

    r1648 r1651  
    6868  FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
    6969  ON id = cat_id and user_id = '.$user['id'];
    70   if ($page['filter_mode'])
     70  if ($page['filter_local_mode'])
    7171  {
    7272    $query.= '
     
    7676  else
    7777  {
    78     // Always expand when filter_mode is activated
    79     if (!$user['expand'])
     78    // Always expand when filter_local_mode is activated
     79    if (!$user['expand'] and !$user['filter_global_mode'])
    8080    {
    8181      $query.= '
  • trunk/include/functions_user.inc.php

    r1641 r1651  
    144144}
    145145
    146 function build_user( $user_id, $use_cache )
     146function build_user( $user_id, $use_cache, $filter_global_mode = false )
    147147{
    148148  global $conf;
     149
    149150  $user['id'] = $user_id;
    150   $user = array_merge( $user, getuserdata($user_id, $use_cache) );
     151  $user = array_merge( $user, getuserdata($user_id, $use_cache, $filter_global_mode) );
    151152  if ( $user['id'] == $conf['guest_id'])
    152153  {
     
    167168    $user['is_the_guest']=false;
    168169  }
     170
    169171  // calculation of the number of picture to display per page
    170172  $user['nb_image_page'] = $user['nb_image_line'] * $user['nb_line_page'];
     
    197199 * @param array
    198200 */
    199 function getuserdata($user_id, $use_cache)
     201function getuserdata($user_id, $use_cache, $filter_global_mode = false )
    200202{
    201203  global $conf;
     
    266268  if ($use_cache)
    267269  {
     270    $userdata['filter_global_mode'] = $filter_global_mode;
     271
    268272    if (!isset($userdata['need_update'])
    269273        or !is_bool($userdata['need_update'])
    270         or $userdata['need_update'] == true)
     274        or $userdata['need_update'] == true
     275        or $filter_global_mode  // not optimize condition RubTag
     276       )
    271277    {
    272278      $userdata['forbidden_categories'] =
    273279        calculate_permissions($userdata['id'], $userdata['status']);
    274280
    275       update_user_cache_categories($userdata['id'], $userdata['forbidden_categories']);
     281      update_user_cache_categories($userdata);
    276282
    277283      // Set need update are done
    278       $userdata['need_update'] = false;
     284      $userdata['need_update'] = $userdata['filter_global_mode']; // for draft always update RubTag
    279285
    280286      $query = '
     
    493499 * update data of user_cache_categories
    494500 *
    495  * @param int user_id
     501 * @param array userdata
    496502 * @return null
    497503 */
    498 function update_user_cache_categories($user_id, $user_forbidden_categories)
     504function update_user_cache_categories(&$userdata)
    499505{
    500506  // delete user cache
    501507  $query = '
    502508DELETE FROM '.USER_CACHE_CATEGORIES_TABLE.'
    503   WHERE user_id = '.$user_id.'
     509  WHERE user_id = '.$userdata['id'].'
    504510;';
    505511  pwg_query($query);
    506512
    507   $query = '
     513  /*$query = '
    508514SELECT id cat_id, date_last max_date_last, nb_images count_images, global_rank
    509515  FROM '.CATEGORIES_TABLE;
    510   if ($user_forbidden_categories != '')
     516  if ($userdata['forbidden_categories'] != '')
    511517  {
    512518    $query.= '
    513     WHERE id NOT IN ('.$user_forbidden_categories.')';
     519    WHERE id NOT IN ('.$userdata['forbidden_categories'].')';
     520  }
     521  $query.= ';';*/
     522
     523
     524  $query = '
     525SELECT c.id cat_id, date_last max_date_last, nb_images count_images, global_rank';
     526
     527  if (!$userdata['filter_global_mode'])
     528  {
     529    $query.= '
     530  FROM '.CATEGORIES_TABLE.' as C';
     531  }
     532  else
     533  {
     534    // Count by date_available to avoid count null
     535    $query.= ', count(date_available) filtered_count_images, max(date_available) max_date_available
     536  FROM '.CATEGORIES_TABLE.' as C
     537    LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
     538    ON ic.category_id = c.id LEFT JOIN '.IMAGES_TABLE.' AS i
     539    ON ic.image_id = i.id AND i.date_available  > SUBDATE(
     540      CURRENT_DATE,INTERVAL '.$userdata['recent_period'].' DAY)';
     541  }
     542
     543  if ($userdata['forbidden_categories'] != '')
     544  {
     545    $query.= '
     546    WHERE C.id NOT IN ('.$userdata['forbidden_categories'].')';
     547  }
     548
     549  if ($userdata['filter_global_mode'])
     550  {
     551    $query.= '
     552  GROUP BY c.id';
    514553  }
    515554  $query.= ';';
     
    520559  while ($row = mysql_fetch_assoc($result))
    521560  {
    522     $row['user_id'] = $user_id;
     561    $row['user_id'] = $userdata['id'];
    523562    $row['count_categories'] = 0;
     563    if ($userdata['filter_global_mode'])
     564    {
     565      $row['count_images'] = $row['filtered_count_images'];
     566      $row['max_date_last'] = $row['max_date_available'];
     567    }
    524568    $cats += array($row['cat_id'] => $row);
    525569  }
     
    548592  $level = 1;
    549593  compute_branch_cat_data($cats, $list_cat_id, $level, $ref_level);
     594
     595  if ($userdata['filter_global_mode'])
     596  {
     597    $forbidden_cats = array();
     598    $forbidden_cats = explode(',', $userdata['forbidden_categories']);
     599    $cat_tmp = $cats;
     600    $cats = array();
     601 
     602    foreach ($cat_tmp as $cat_id => $category)
     603    {
     604      if (empty($category['max_date_last']))
     605      {
     606        array_push($forbidden_cats, $category['cat_id']);
     607      }
     608      else
     609      {
     610        array_push($cats, $category);
     611      }
     612    }
     613    $userdata['forbidden_categories'] = implode(',', array_unique($forbidden_cats));
     614  }
    550615
    551616  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
  • trunk/include/user.inc.php

    r1623 r1651  
    7070  }
    7171}
     72
     73if (isset($_GET['filter_global_mode']))
     74{
     75  $user['filter_global_mode'] = ($_GET['filter_global_mode'] == 'start');
     76  pwg_set_session_var('filter_global_mode', $user['filter_global_mode']);
     77}
     78else
     79{
     80  $user['filter_global_mode'] = pwg_get_session_var('filter_global_mode', false);
     81}
     82
    7283$user = build_user( $user['id'],
    73           ( defined('IN_ADMIN') and IN_ADMIN ) ? false : true // use cache ?
     84          ( defined('IN_ADMIN') and IN_ADMIN ) ? false : true, // use cache ?
     85          $user['filter_global_mode'] // filter_global_mode ?
    7486         );
    7587
  • trunk/index.php

    r1648 r1651  
    107107}
    108108
    109 if (isset($_GET['filter_mode']))
    110 {
    111   $page['filter_mode'] = ($_GET['filter_mode'] == 'start');
    112   pwg_set_session_var('filter_mode', $page['filter_mode']);
    113 }
    114 else
    115 {
    116   $page['filter_mode'] = pwg_get_session_var('filter_mode', false);
    117 }
    118 
    119 if ($page['filter_mode'])
    120 {
    121   $template->assign_block_vars(
    122     'stop_filter_mode',
    123     array(
    124       'URL' => add_url_params(duplicate_index_url(array(), array('start')), array('filter_mode' => 'stop'))
    125       )
    126     );
    127 }
    128 else
    129 {
    130   $template->assign_block_vars(
    131     'start_filter_mode',
    132     array(
    133       'URL' => add_url_params(duplicate_index_url(array(), array('start')), array('filter_mode' => 'start'))
     109if (isset($_GET['filter_local_mode']))
     110{
     111  $page['filter_local_mode'] = ($_GET['filter_local_mode'] == 'start');
     112}
     113else
     114{
     115  $page['filter_local_mode'] = pwg_get_session_var('filter_local_mode', false);
     116}
     117
     118$page['filter_local_mode'] = (($page['filter_local_mode']) and
     119                              ($page['section'] == 'categories') and
     120                              (!isset($page['chronology_field'])));
     121pwg_set_session_var('filter_local_mode', $page['filter_local_mode']);
     122
     123if ($page['filter_local_mode'])
     124{
     125  $template->assign_block_vars(
     126    'stop_filter_local_mode',
     127    array(
     128      'URL' => add_url_params(duplicate_index_url(array(), array('start')), array('filter_local_mode' => 'stop'))
     129      )
     130    );
     131}
     132else
     133{
     134  $template->assign_block_vars(
     135    'start_filter_local_mode',
     136    array(
     137      'URL' => add_url_params(duplicate_index_url(array(), array('start')), array('filter_local_mode' => 'start'))
     138      )
     139    );
     140}
     141
     142if (isset($_GET['filter_global_mode']))
     143{
     144  $user['filter_global_mode'] = ($_GET['filter_global_mode'] == 'start');
     145  pwg_set_session_var('filter_global_mode', $user['filter_global_mode']);
     146}
     147else
     148{
     149  $user['filter_global_mode'] = pwg_get_session_var('filter_global_mode', false);
     150}
     151
     152if ($user['filter_global_mode'])
     153{
     154  $template->assign_block_vars(
     155    'stop_filter_global_mode',
     156    array(
     157      'URL' => add_url_params(duplicate_index_url(array(), array('start')), array('filter_global_mode' => 'stop'))
     158      )
     159    );
     160}
     161else
     162{
     163  $template->assign_block_vars(
     164    'start_filter_global_mode',
     165    array(
     166      'URL' => add_url_params(duplicate_index_url(array(), array('start')), array('filter_global_mode' => 'start'))
    134167      )
    135168    );
  • trunk/language/en_UK.iso-8859-1/common.lang.php

    r1648 r1651  
    491491$lang['maxwidth'] = 'Maximum width of the pictures';
    492492$lang['maxwidth_error'] = 'Maximum width must be a number superior to 50';
    493 $lang['start_filter_mode_hint'] = 'displays only recent elements';
    494 $lang['stop_filter_mode_hint'] = 'return to display all elements';
     493$lang['start_filter_local_mode_hint'] = '[local] displays only recent elements';
     494$lang['stop_filter_local_mode_hint'] = '[local] return to display all elements';
     495$lang['start_filter_global_mode_hint'] = '[global] displays only recent elements';
     496$lang['stop_filter_global_mode_hint'] = '[global] return to display all elements';
    495497$lang['mode_created_hint'] = 'displays a calendar by creation date';
    496498$lang['mode_normal_hint'] = 'return to normal view mode';
  • trunk/language/fr_FR.iso-8859-1/common.lang.php

    r1648 r1651  
    491491$lang['maxwidth'] = 'Largeur maximum des images';
    492492$lang['maxwidth_error'] = 'La largeur des images doit être supérieure à 50';
     493$lang['start_filter_local_mode_hint'] = '[local] afficher que les éléments récents';
     494$lang['stop_filter_local_mode_hint'] = '[local] retourner à l\'affichage de tous les éléments';
     495$lang['start_filter_global_mode_hint'] = '[global] afficher que les éléments récents';
     496$lang['stop_filter_global_mode_hint'] = '[global] retourner à l\'affichage de tous les éléments';
    493497$lang['mode_created_hint'] = 'afficher un calendrier par date de création';
    494 $lang['start_filter_mode_hint'] = 'afficher que les éléments récents';
    495 $lang['stop_filter_mode_hint'] = 'retourner à l\'affichage de tous les éléments';
    496498$lang['mode_normal_hint'] = 'retourner à la vue normale';
    497499$lang['mode_posted_hint'] = 'afficher un calendrier par date d\'ajout';
  • trunk/template/yoga/index.tpl

    r1648 r1651  
    2828      <!-- END search_rules -->
    2929
    30       <!-- BEGIN start_filter_mode -->
    31       <li><a href="{start_filter_mode.URL}" title="{lang:start_filter_mode_hint}"><img src="{pwg_root}{themeconf:icon_dir}/start_filter_mode.png" class="button" alt="{lang:start_filter_mode_hint}"></a></li>
    32       <!-- END start_filter_mode -->
    33       <!-- BEGIN stop_filter_mode -->
    34       <li><a href="{stop_filter_mode.URL}" title="{lang:stop_filter_mode_hint}"><img src="{pwg_root}{themeconf:icon_dir}/stop_filter_mode.png" class="button" alt="{lang:stop_filter_mode_hint}"></a></li>
    35       <!-- END stop_filter_mode -->
     30      <!-- BEGIN start_filter_local_mode -->
     31      <li><a href="{start_filter_local_mode.URL}" title="{lang:start_filter_local_mode_hint}"><img src="{pwg_root}{themeconf:icon_dir}/start_filter_mode.png" class="button" alt="{lang:start_filter_local_mode_hint}"></a></li>
     32      <!-- END start_filter_local_mode -->
     33      <!-- BEGIN stop_filter_local_mode -->
     34      <li><a href="{stop_filter_local_mode.URL}" title="{lang:stop_filter_local_mode_hint}"><img src="{pwg_root}{themeconf:icon_dir}/stop_filter_mode.png" class="button" alt="{lang:stop_filter_local_mode_hint}"></a></li>
     35      <!-- END stop_filter_local_mode -->
    3636
    3737      <!-- BEGIN mode_normal -->
  • trunk/template/yoga/menubar.tpl

    r1650 r1651  
    1414<!-- END links -->
    1515<dl id="mbCategories">
    16   <!-- BEGIN start_filter_mode -->
    17   <a href="{start_filter_mode.URL}" title="{lang:start_filter_mode_hint}"><img src="{pwg_root}{themeconf:icon_dir}/start_filter_mode.png" class="buttonmenu" alt="{lang:start_filter_mode_hint}"></a>
    18   <!-- END start_filter_mode -->
    19   <!-- BEGIN stop_filter_mode -->
    20   <a href="{stop_filter_mode.URL}" title="{lang:stop_filter_mode_hint}"><img src="{pwg_root}{themeconf:icon_dir}/stop_filter_mode.png" class="buttonmenu" alt="{lang:stop_filter_mode_hint}"></a>
    21   <!-- END stop_filter_mode -->
     16  <!-- BEGIN start_filter_global_mode -->
     17  <a href="{start_filter_global_mode.URL}" title="{lang:start_filter_global_mode_hint}"><img src="{pwg_root}{themeconf:icon_dir}/start_filter_mode.png" class="buttonmenu" alt="{lang:start_filter_global_mode_hint}"></a>
     18  <!-- END start_filter_global_mode -->
     19  <!-- BEGIN stop_filter_global_mode -->
     20  <a href="{stop_filter_global_mode.URL}" title="{lang:stop_filter_global_mode_hint}"><img src="{pwg_root}{themeconf:icon_dir}/stop_filter_mode.png" class="buttonmenu" alt="{lang:stop_filter_global_mode_hint}"></a>
     21  <!-- END stop_filter_global_mode -->
    2222  <dt><a href="{U_HOME}">{lang:Categories}</a></dt>
    2323  <dd>
Note: See TracChangeset for help on using the changeset viewer.