Skip to content

Commit

Permalink
Resolved Issue ID 0000299:
Browse files Browse the repository at this point in the history
  o Add (new) icon of parent category with children categories including new images
  o Improved display text for images count
  o Improved (a little) mass_* functions

More explications on the forum.
You must call directly upgrade_feep.php (http://127.0.0.1/BSF/upgrade_feed.php for example)

git-svn-id: http://piwigo.org/svn/trunk@1624 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
rub committed Dec 1, 2006
1 parent b2de3c3 commit 63638b9
Show file tree
Hide file tree
Showing 12 changed files with 463 additions and 170 deletions.
258 changes: 136 additions & 122 deletions admin/include/functions.php
Expand Up @@ -257,6 +257,13 @@ function delete_user($user_id)
;';
pwg_query($query);

// deletion of computed cache data linked to the user
$query = '
DELETE FROM '.USER_CACHE_CATEGORIES_TABLE.'
WHERE user_id = '.$user_id.'
;';
pwg_query($query);

// deletion of phpwebgallery specific informations
$query = '
DELETE FROM '.USER_INFOS_TABLE.'
Expand Down Expand Up @@ -514,41 +521,44 @@ function get_fs_directories($path, $recursive = true)
*/
function mass_inserts($table_name, $dbfields, $datas)
{
// inserts all found categories
$query = '
INSERT INTO '.$table_name.'
('.implode(',', $dbfields).')
VALUES';
foreach ($datas as $insert_id => $insert)
if (count($datas) != 0)
{
$query.= '
';
if ($insert_id > 0)
{
$query.= ',';
}
$query.= '(';
foreach ($dbfields as $field_id => $dbfield)
// inserts all found categories
$query = '
INSERT INTO '.$table_name.'
('.implode(',', $dbfields).')
VALUES';
foreach ($datas as $insert_id => $insert)
{
if ($field_id > 0)
$query.= '
';
if ($insert_id > 0)
{
$query.= ',';
}

if (!isset($insert[$dbfield]) or $insert[$dbfield] === '')
{
$query.= 'NULL';
}
else
$query.= '(';
foreach ($dbfields as $field_id => $dbfield)
{
$query.= "'".$insert[$dbfield]."'";
if ($field_id > 0)
{
$query.= ',';
}

if (!isset($insert[$dbfield]) or $insert[$dbfield] === '')
{
$query.= 'NULL';
}
else
{
$query.= "'".$insert[$dbfield]."'";
}
}
$query.=')';
}
$query.=')';
}
$query.= '
$query.= '
;';
pwg_query($query);
pwg_query($query);
}
}

/**
Expand All @@ -561,119 +571,122 @@ function mass_inserts($table_name, $dbfields, $datas)
*/
function mass_updates($tablename, $dbfields, $datas)
{
// depending on the MySQL version, we use the multi table update or N
// update queries
$query = 'SELECT VERSION() AS version;';
list($mysql_version) = mysql_fetch_array(pwg_query($query));
if (count($datas) < 10 or version_compare($mysql_version, '4.0.4') < 0)
{
// MySQL is prior to version 4.0.4, multi table update feature is not
// available
foreach ($datas as $data)
if (count($datas) != 0)
{
// depending on the MySQL version, we use the multi table update or N
// update queries
$query = 'SELECT VERSION() AS version;';
list($mysql_version) = mysql_fetch_array(pwg_query($query));
if (count($datas) < 10 or version_compare($mysql_version, '4.0.4') < 0)
{
$query = '
UPDATE '.$tablename.'
SET ';
$is_first = true;
foreach ($dbfields['update'] as $num => $key)
// MySQL is prior to version 4.0.4, multi table update feature is not
// available
foreach ($datas as $data)
{
if (!$is_first)
{
$query.= ",\n ";
}
$query.= $key.' = ';
if (isset($data[$key]) and $data[$key] != '')
$query = '
UPDATE '.$tablename.'
SET ';
$is_first = true;
foreach ($dbfields['update'] as $num => $key)
{
$query.= '\''.$data[$key].'\'';
if (!$is_first)
{
$query.= ",\n ";
}
$query.= $key.' = ';
if (isset($data[$key]) and $data[$key] != '')
{
$query.= '\''.$data[$key].'\'';
}
else
{
$query.= 'NULL';
}
$is_first = false;
}
else
$query.= '
WHERE ';
foreach ($dbfields['primary'] as $num => $key)
{
$query.= 'NULL';
}
$is_first = false;
}
$query.= '
WHERE ';
foreach ($dbfields['primary'] as $num => $key)
{
if ($num > 1)
{
$query.= ' AND ';
if ($num > 1)
{
$query.= ' AND ';
}
$query.= $key.' = \''.$data[$key].'\'';
}
$query.= $key.' = \''.$data[$key].'\'';
$query.= '
;';
pwg_query($query);
}
$query.= '
;';
pwg_query($query);
}
}
else
{
// creation of the temporary table
$query = '
SHOW FULL COLUMNS FROM '.$tablename.'
;';
$result = pwg_query($query);
$columns = array();
$all_fields = array_merge($dbfields['primary'], $dbfields['update']);
while ($row = mysql_fetch_array($result))
else
{
if (in_array($row['Field'], $all_fields))
// creation of the temporary table
$query = '
SHOW FULL COLUMNS FROM '.$tablename.'
;';
$result = pwg_query($query);
$columns = array();
$all_fields = array_merge($dbfields['primary'], $dbfields['update']);
while ($row = mysql_fetch_array($result))
{
$column = $row['Field'];
$column.= ' '.$row['Type'];
if (!isset($row['Null']) or $row['Null'] == '')
if (in_array($row['Field'], $all_fields))
{
$column.= ' NOT NULL';
}
if (isset($row['Default']))
{
$column.= " default '".$row['Default']."'";
}
if (isset($row['Collation']) and $row['Collation'] != 'NULL')
{
$column.= " collate '".$row['Collation']."'";
$column = $row['Field'];
$column.= ' '.$row['Type'];
if (!isset($row['Null']) or $row['Null'] == '')
{
$column.= ' NOT NULL';
}
if (isset($row['Default']))
{
$column.= " default '".$row['Default']."'";
}
if (isset($row['Collation']) and $row['Collation'] != 'NULL')
{
$column.= " collate '".$row['Collation']."'";
}
array_push($columns, $column);
}
array_push($columns, $column);
}
}

$temporary_tablename = $tablename.'_'.micro_seconds();
$temporary_tablename = $tablename.'_'.micro_seconds();

$query = '
CREATE TABLE '.$temporary_tablename.'
(
'.implode(",\n", $columns).',
PRIMARY KEY ('.implode(',', $dbfields['primary']).')
)
;';
pwg_query($query);
mass_inserts($temporary_tablename, $all_fields, $datas);
// update of images table by joining with temporary table
$query = '
UPDATE '.$tablename.' AS t1, '.$temporary_tablename.' AS t2
SET '.
implode(
"\n , ",
array_map(
create_function('$s', 'return "t1.$s = t2.$s";'),
$dbfields['update']
)
).'
WHERE '.
implode(
"\n AND ",
array_map(
create_function('$s', 'return "t1.$s = t2.$s";'),
$dbfields['primary']
)
).'
$query = '
CREATE TABLE '.$temporary_tablename.'
(
'.implode(",\n", $columns).',
PRIMARY KEY ('.implode(',', $dbfields['primary']).')
)
;';
pwg_query($query);
$query = '
DROP TABLE '.$temporary_tablename.'
pwg_query($query);
mass_inserts($temporary_tablename, $all_fields, $datas);
// update of images table by joining with temporary table
$query = '
UPDATE '.$tablename.' AS t1, '.$temporary_tablename.' AS t2
SET '.
implode(
"\n , ",
array_map(
create_function('$s', 'return "t1.$s = t2.$s";'),
$dbfields['update']
)
).'
WHERE '.
implode(
"\n AND ",
array_map(
create_function('$s', 'return "t1.$s = t2.$s";'),
$dbfields['primary']
)
).'
;';
pwg_query($query);
$query = '
DROP TABLE '.$temporary_tablename.'
;';
pwg_query($query);
pwg_query($query);
}
}
}

Expand Down Expand Up @@ -1159,6 +1172,7 @@ function sync_users()
USER_INFOS_TABLE,
USER_ACCESS_TABLE,
USER_CACHE_TABLE,
USER_CACHE_CATEGORIES_TABLE,
USER_GROUP_TABLE
);

Expand Down
33 changes: 23 additions & 10 deletions include/category_cats.inc.php
Expand Up @@ -33,22 +33,28 @@

if ($page['section']=='recent_cats')
{
// $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
$query = '
SELECT id,name,date_last,representative_picture_id,comment,nb_images,uppercats
FROM '.CATEGORIES_TABLE.'
SELECT
id,name, representative_picture_id, comment, nb_images, uppercats,
max_date_last, is_child_date_last, count_images, count_categories
FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
ON id = cat_id and user_id = '.$user['id'].'
WHERE date_last > SUBDATE(
CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY
)
AND id NOT IN ('.$user['forbidden_categories'].')';
);';
}
else
{
// $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
$query = '
SELECT id,name,date_last,representative_picture_id,comment,nb_images
FROM '.CATEGORIES_TABLE.'
SELECT
id,name, representative_picture_id, comment, nb_images,
max_date_last, is_child_date_last, count_images, count_categories
FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
ON id = cat_id and user_id = '.$user['id'].'
WHERE id_uppercat '.
(!isset($page['category']) ? 'is NULL' : '= '.$page['category']).'
AND id NOT IN ('.$user['forbidden_categories'].')
ORDER BY rank
;';
}
Expand All @@ -59,6 +65,8 @@

while ($row = mysql_fetch_assoc($result))
{
$row['is_child_date_last'] = get_boolean($row['is_child_date_last']);

if (isset($row['representative_picture_id'])
and is_numeric($row['representative_picture_id']))
{ // if a representative picture is set, it has priority
Expand Down Expand Up @@ -145,7 +153,7 @@
else
{
$name = $category['name'];
$icon_ts = get_icon(@$category['date_last']);
$icon_ts = get_icon($category['max_date_last'], $category['is_child_date_last']);
}

$template->assign_block_vars(
Expand All @@ -162,7 +170,12 @@
'cat_name' => $category['name'],
)
),
'CAPTION_NB_IMAGES' => (($category['nb_images'] == 0) ? '' : sprintf("%d ".l10n('pictures'), $category['nb_images'])),
'CAPTION_NB_IMAGES' => get_display_images_count
(
$category['nb_images'],
$category['count_images'],
$category['count_categories']
),
'DESCRIPTION' => @$comment,
'NAME' => $name,
)
Expand Down Expand Up @@ -213,7 +226,7 @@
$template->merge_block_vars(
'thumbnails.line.thumbnail',
array(
'IMAGE_TS' => get_icon(@$category['date_last']),
'IMAGE_TS' => get_icon($category['max_date_last'], $category['is_child_date_last']),
)
);
}
Expand Down
1 change: 1 addition & 0 deletions include/constants.php
Expand Up @@ -65,6 +65,7 @@
define('IMAGE_METADATA_TABLE', $prefixeTable.'image_metadata');
define('RATE_TABLE', $prefixeTable.'rate');
define('USER_CACHE_TABLE', $prefixeTable.'user_cache');
define('USER_CACHE_CATEGORIES_TABLE', $prefixeTable.'user_cache_categories');
define('CADDIE_TABLE', $prefixeTable.'caddie');
define('UPGRADE_TABLE', $prefixeTable.'upgrade');
define('SEARCH_TABLE', $prefixeTable.'search');
Expand Down

0 comments on commit 63638b9

Please sign in to comment.