function ml_image_get_images in Media Library 6
Load existing images according to filters
Parameters
terms - array of tids for filtering: source - image source for filtering
Return value
array of images
1 call to ml_image_get_images()
- ml_image_basic_search in ml_image/
ml_image_basic/ ml_image_basic.module - Search the images
File
- ml_image/
ml_image.module, line 581 - Media Library Image module.
Code
function ml_image_get_images($terms = array(), $source = 0, $limit = 10, $page = 0) {
// Base query
$query = '
SELECT
metadata.*,
files.filepath,
files.uid,
files.timestamp,
GROUP_CONCAT(tags.tid) as tags
FROM {ml_image_metadata} metadata
INNER JOIN {files} files ON metadata.fid = files.fid
LEFT JOIN {ml_image_term} tags ON metadata.fid = tags.fid';
$count_query = '
SELECT
COUNT(metadata.fid)
FROM {ml_image_metadata} metadata
INNER JOIN {files} files ON metadata.fid = files.fid';
// Terms filtering
if (!empty($terms)) {
$term_filter = '';
foreach ($terms as $tid) {
$term_filter .= ' INNER JOIN ml_image_term tags_filter' . $tid . ' ON metadata.fid = tags_filter' . $tid . '.fid AND tags_filter' . $tid . '.tid = ' . $tid;
}
$query .= $term_filter;
$count_query .= $term_filter;
}
// Source filtering
if ($source) {
$query .= ' WHERE source = "%s" ';
$count_query .= ' WHERE source = "%s" ';
}
// Group multiple terms
$query .= ' GROUP BY metadata.fid';
// Prepare range
//$from = $page * $limit;
//$result = db_query_range($query, $from, $limit);
$result = pager_query($query, $limit, 0, $count_query, $source);
$images = array();
while ($item = db_fetch_object($result)) {
$item->tags = explode(',', $item->tags);
$images[] = $item;
}
return $images;
}