more query2array

git-svn-id: http://piwigo.org/svn/trunk@27369 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
rvelices 2014-02-13 22:21:12 +00:00
parent d0733822ce
commit 2b81fbc4aa
6 changed files with 15 additions and 39 deletions

View file

@ -246,7 +246,7 @@ $this->inner_sql.
$this->get_date_where($level).'
GROUP BY period;';
$level_items = simple_hash_from_query($query, 'period', 'nb_images');
$level_items = query2array($query, 'period', 'nb_images');
if ( count($level_items)==1 and
count($page['chronology_date'])<count($this->calendar_levels)-1)
@ -317,7 +317,7 @@ AND ' . $this->date_field . ' IS NOT NULL
GROUP BY period';
$current = implode('-', $page['chronology_date'] );
$upper_items = array_from_query( $query, 'period');
$upper_items = query2array($query,null, 'period');
usort($upper_items, 'version_compare');
$upper_items_rank = array_flip($upper_items);

View file

@ -84,7 +84,7 @@ SELECT image_id, COUNT(*) AS nb_comments
AND image_id IN ('.implode(',', $selection).')
GROUP BY image_id
;';
$nb_comments_of = simple_hash_from_query($query, 'image_id', 'nb_comments');
$nb_comments_of = query2array($query, 'image_id', 'nb_comments');
}
}

View file

@ -1253,15 +1253,7 @@ function prepend_append_array_items($array, $prepend_str, $append_str)
*/
function simple_hash_from_query($query, $keyname, $valuename)
{
$array = array();
$result = pwg_query($query);
while ($row = pwg_db_fetch_assoc($result))
{
$array[ $row[$keyname] ] = $row[$valuename];
}
return $array;
return query2array($query, $keyname, $valuename);
}
/**
@ -1275,13 +1267,7 @@ function simple_hash_from_query($query, $keyname, $valuename)
*/
function hash_from_query($query, $keyname)
{
$array = array();
$result = pwg_query($query);
while ($row = pwg_db_fetch_assoc($result))
{
$array[ $row[$keyname] ] = $row;
}
return $array;
return query2array($query, $keyname);
}
/**
@ -1296,24 +1282,14 @@ function hash_from_query($query, $keyname)
*/
function array_from_query($query, $fieldname=false)
{
$array = array();
$result = pwg_query($query);
if (false === $fieldname)
{
while ($row = pwg_db_fetch_assoc($result))
{
$array[] = $row;
}
return query2array($query);
}
else
{
while ($row = pwg_db_fetch_assoc($result))
{
$array[] = $row[$fieldname];
}
return query2array($query, null, $fieldname);
}
return $array;
}
/**

View file

@ -205,7 +205,7 @@ SELECT *
FROM '.CATEGORIES_TABLE.'
WHERE id IN ('.$cat['uppercats'].')
;';
$names = hash_from_query($query, 'id');
$names = query2array($query, 'id');
// category names must be in the same order than uppercats list
$cat['upper_names'] = array();
@ -302,7 +302,7 @@ function display_select_cat_wrapper($query,
$blockname,
$fullname = true)
{
$categories = array_from_query($query);
$categories = query2array($query);
usort($categories, 'global_rank_compare');
display_select_categories($categories, $selecteds, $blockname, $fullname);
}
@ -362,7 +362,7 @@ SELECT id, permalink, 0 AS is_old
FROM '.CATEGORIES_TABLE.'
WHERE permalink IN ('.$in.')
;';
$perma_hash = hash_from_query($query, 'permalink');
$perma_hash = query2array($query, 'permalink');
if ( empty($perma_hash) )
return null;

View file

@ -113,7 +113,7 @@ function get_cat_display_name_cache($uppercats,
SELECT id, name, permalink
FROM '.CATEGORIES_TABLE.'
;';
$cache['cat_names'] = hash_from_query($query, 'id');
$cache['cat_names'] = query2array($query, 'id');
}
$output = '';

View file

@ -217,7 +217,7 @@ function custom_notification_query($action, $type, $start=null, $end=null)
break;
}
$query = 'SELECT DISTINCT '.$field_id.' '.$query.';';
$infos = array_from_query($query);
$infos = query2array($query);
return $infos;
break;
}
@ -456,7 +456,7 @@ SELECT
ORDER BY date_available DESC
LIMIT '.$max_dates.'
;';
$dates = array_from_query($query);
$dates = query2array($query);
for ($i=0; $i<count($dates); $i++)
{
@ -471,7 +471,7 @@ SELECT DISTINCT i.*
ORDER BY '.DB_RANDOM_FUNCTION.'()
LIMIT '.$max_elements.'
;';
$dates[$i]['elements'] = array_from_query($query);
$dates[$i]['elements'] = query2array($query);
}
if ($max_cats>0)
@ -489,7 +489,7 @@ SELECT
ORDER BY img_count DESC
LIMIT '.$max_cats.'
;';
$dates[$i]['categories'] = array_from_query($query);
$dates[$i]['categories'] = query2array($query);
}
}