aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorrub <rub@piwigo.org>2006-12-13 00:05:16 +0000
committerrub <rub@piwigo.org>2006-12-13 00:05:16 +0000
commit5046b3c2105bdfae23d6835c110606ea9e7ff055 (patch)
treea6b497463d1b83edfe7f53d90d356765a5d4d0fd /include
parent5e9a4b02be26994e7d49a7d1ece7595a50b28c4b (diff)
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 git-svn-id: http://piwigo.org/svn/trunk@1651 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include')
-rw-r--r--include/category_cats.inc.php8
-rw-r--r--include/category_default.inc.php2
-rw-r--r--include/functions_category.inc.php6
-rw-r--r--include/functions_user.inc.php91
-rw-r--r--include/user.inc.php14
5 files changed, 99 insertions, 22 deletions
diff --git a/include/category_cats.inc.php b/include/category_cats.inc.php
index 36f19ca49..c84bdf6e9 100644
--- a/include/category_cats.inc.php
+++ b/include/category_cats.inc.php
@@ -55,7 +55,7 @@ SELECT
ON id = cat_id and user_id = '.$user['id'].'
WHERE id_uppercat '.
(!isset($page['category']) ? 'is NULL' : '= '.$page['category']);
- if ($page['filter_mode'])
+ if ($page['filter_local_mode'])
{
$query.= '
AND max_date_last > SUBDATE(
@@ -85,7 +85,7 @@ while ($row = mysql_fetch_assoc($result))
SELECT image_id
FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
ON ic.category_id = c.id';
- if ($page['filter_mode'])
+ if ($page['filter_local_mode'] or $user['filter_global_mode'])
{
$query.= '
INNER JOIN '.IMAGES_TABLE.' AS i on ic.image_id = i.id ';
@@ -93,7 +93,7 @@ SELECT image_id
$query.= '
WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
AND c.id NOT IN ('.$user['forbidden_categories'].')';
- if ($page['filter_mode'])
+ if ($page['filter_local_mode'] or $user['filter_global_mode'])
{
$query.= '
AND i.date_available > SUBDATE(
@@ -117,7 +117,7 @@ SELECT representative_picture_id
ON id = cat_id and user_id = '.$user['id'].'
WHERE uppercats REGEXP \'(^|,)'.$row['id'].'(,|$)\'
AND representative_picture_id IS NOT NULL';
- if ($page['filter_mode'])
+ if ($page['filter_local_mode'] or $user['filter_global_mode'])
{
$query.= '
AND max_date_last > SUBDATE(
diff --git a/include/category_default.inc.php b/include/category_default.inc.php
index ae2dc4dce..1fff71956 100644
--- a/include/category_default.inc.php
+++ b/include/category_default.inc.php
@@ -47,7 +47,7 @@ if (count($selection) > 0)
SELECT *
FROM '.IMAGES_TABLE.'
WHERE id IN ('.implode(',', $selection).')';
- if ($page['filter_mode'])
+ if ($page['filter_local_mode'] or $user['filter_global_mode'])
{
$query.= '
AND date_available > SUBDATE(
diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php
index 8113064d6..4ae2b126c 100644
--- a/include/functions_category.inc.php
+++ b/include/functions_category.inc.php
@@ -67,7 +67,7 @@ SELECT ';
$query.= '
FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
ON id = cat_id and user_id = '.$user['id'];
- if ($page['filter_mode'])
+ if ($page['filter_local_mode'])
{
$query.= '
where max_date_last > SUBDATE(
@@ -75,8 +75,8 @@ where max_date_last > SUBDATE(
}
else
{
- // Always expand when filter_mode is activated
- if (!$user['expand'])
+ // Always expand when filter_local_mode is activated
+ if (!$user['expand'] and !$user['filter_global_mode'])
{
$query.= '
WHERE (id_uppercat is NULL';
diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php
index 362679f51..d59a97e4d 100644
--- a/include/functions_user.inc.php
+++ b/include/functions_user.inc.php
@@ -143,11 +143,12 @@ function setup_style($style)
return new Template(PHPWG_ROOT_PATH.'template/'.$style);
}
-function build_user( $user_id, $use_cache )
+function build_user( $user_id, $use_cache, $filter_global_mode = false )
{
global $conf;
+
$user['id'] = $user_id;
- $user = array_merge( $user, getuserdata($user_id, $use_cache) );
+ $user = array_merge( $user, getuserdata($user_id, $use_cache, $filter_global_mode) );
if ( $user['id'] == $conf['guest_id'])
{
$user['is_the_guest']=true;
@@ -166,6 +167,7 @@ function build_user( $user_id, $use_cache )
{
$user['is_the_guest']=false;
}
+
// calculation of the number of picture to display per page
$user['nb_image_page'] = $user['nb_image_line'] * $user['nb_line_page'];
@@ -196,7 +198,7 @@ function build_user( $user_id, $use_cache )
* @param boolean use_cache
* @param array
*/
-function getuserdata($user_id, $use_cache)
+function getuserdata($user_id, $use_cache, $filter_global_mode = false )
{
global $conf;
@@ -265,17 +267,21 @@ SELECT ui.*, uc.*
if ($use_cache)
{
+ $userdata['filter_global_mode'] = $filter_global_mode;
+
if (!isset($userdata['need_update'])
or !is_bool($userdata['need_update'])
- or $userdata['need_update'] == true)
+ or $userdata['need_update'] == true
+ or $filter_global_mode // not optimize condition RubTag
+ )
{
$userdata['forbidden_categories'] =
calculate_permissions($userdata['id'], $userdata['status']);
- update_user_cache_categories($userdata['id'], $userdata['forbidden_categories']);
+ update_user_cache_categories($userdata);
// Set need update are done
- $userdata['need_update'] = false;
+ $userdata['need_update'] = $userdata['filter_global_mode']; // for draft always update RubTag
$query = '
SELECT COUNT(DISTINCT(image_id)) as total
@@ -492,25 +498,58 @@ function compute_branch_cat_data(&$cats, &$list_cat_id, &$level, &$ref_level)
/**
* update data of user_cache_categories
*
- * @param int user_id
+ * @param array userdata
* @return null
*/
-function update_user_cache_categories($user_id, $user_forbidden_categories)
+function update_user_cache_categories(&$userdata)
{
// delete user cache
$query = '
DELETE FROM '.USER_CACHE_CATEGORIES_TABLE.'
- WHERE user_id = '.$user_id.'
+ WHERE user_id = '.$userdata['id'].'
;';
pwg_query($query);
- $query = '
+ /*$query = '
SELECT id cat_id, date_last max_date_last, nb_images count_images, global_rank
FROM '.CATEGORIES_TABLE;
- if ($user_forbidden_categories != '')
+ if ($userdata['forbidden_categories'] != '')
+ {
+ $query.= '
+ WHERE id NOT IN ('.$userdata['forbidden_categories'].')';
+ }
+ $query.= ';';*/
+
+
+ $query = '
+SELECT c.id cat_id, date_last max_date_last, nb_images count_images, global_rank';
+
+ if (!$userdata['filter_global_mode'])
+ {
+ $query.= '
+ FROM '.CATEGORIES_TABLE.' as C';
+ }
+ else
+ {
+ // Count by date_available to avoid count null
+ $query.= ', count(date_available) filtered_count_images, max(date_available) max_date_available
+ FROM '.CATEGORIES_TABLE.' as C
+ LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
+ ON ic.category_id = c.id LEFT JOIN '.IMAGES_TABLE.' AS i
+ ON ic.image_id = i.id AND i.date_available > SUBDATE(
+ CURRENT_DATE,INTERVAL '.$userdata['recent_period'].' DAY)';
+ }
+
+ if ($userdata['forbidden_categories'] != '')
+ {
+ $query.= '
+ WHERE C.id NOT IN ('.$userdata['forbidden_categories'].')';
+ }
+
+ if ($userdata['filter_global_mode'])
{
$query.= '
- WHERE id NOT IN ('.$user_forbidden_categories.')';
+ GROUP BY c.id';
}
$query.= ';';
@@ -519,8 +558,13 @@ SELECT id cat_id, date_last max_date_last, nb_images count_images, global_rank
$cats = array();
while ($row = mysql_fetch_assoc($result))
{
- $row['user_id'] = $user_id;
+ $row['user_id'] = $userdata['id'];
$row['count_categories'] = 0;
+ if ($userdata['filter_global_mode'])
+ {
+ $row['count_images'] = $row['filtered_count_images'];
+ $row['max_date_last'] = $row['max_date_available'];
+ }
$cats += array($row['cat_id'] => $row);
}
usort($cats, 'global_rank_compare');
@@ -548,6 +592,27 @@ SELECT id cat_id, date_last max_date_last, nb_images count_images, global_rank
$level = 1;
compute_branch_cat_data($cats, $list_cat_id, $level, $ref_level);
+ if ($userdata['filter_global_mode'])
+ {
+ $forbidden_cats = array();
+ $forbidden_cats = explode(',', $userdata['forbidden_categories']);
+ $cat_tmp = $cats;
+ $cats = array();
+
+ foreach ($cat_tmp as $cat_id => $category)
+ {
+ if (empty($category['max_date_last']))
+ {
+ array_push($forbidden_cats, $category['cat_id']);
+ }
+ else
+ {
+ array_push($cats, $category);
+ }
+ }
+ $userdata['forbidden_categories'] = implode(',', array_unique($forbidden_cats));
+ }
+
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
mass_inserts
(
diff --git a/include/user.inc.php b/include/user.inc.php
index 103052ad2..6f75ac962 100644
--- a/include/user.inc.php
+++ b/include/user.inc.php
@@ -69,8 +69,20 @@ if ($conf['apache_authentication'] and isset($_SERVER['REMOTE_USER']))
$user['id'] = get_userid($_SERVER['REMOTE_USER']);
}
}
+
+if (isset($_GET['filter_global_mode']))
+{
+ $user['filter_global_mode'] = ($_GET['filter_global_mode'] == 'start');
+ pwg_set_session_var('filter_global_mode', $user['filter_global_mode']);
+}
+else
+{
+ $user['filter_global_mode'] = pwg_get_session_var('filter_global_mode', false);
+}
+
$user = build_user( $user['id'],
- ( defined('IN_ADMIN') and IN_ADMIN ) ? false : true // use cache ?
+ ( defined('IN_ADMIN') and IN_ADMIN ) ? false : true, // use cache ?
+ $user['filter_global_mode'] // filter_global_mode ?
);
?> \ No newline at end of file