function node_gallery_get_image_nids_sorted_by in Node Gallery 6.3
Get image nids sorted by a custom field, such as title or filepath.
Parameters
object $gallery The node object of a gallery.:
string $op The entry to sort after; one of title, created, changed, filepath, weight or current.:
boolean $reverse If the order should be reversed; defaults to FALSE.:
Return value
array Array of image nids.
1 call to node_gallery_get_image_nids_sorted_by()
- node_gallery_json_get_sorted_images in ./
node_gallery.pages.inc - Page callback for the sort image page, when it retrieves image nids ordered by a specified field.
File
- ./
node_gallery.inc, line 460 - Shared functions for node_gallery
Code
function node_gallery_get_image_nids_sorted_by(&$gallery, $op = '', $reverse = FALSE) {
// get detailed image infos to be able to sort by arbitrary fields
$images = node_gallery_get_images($gallery, TRUE, FALSE);
$sort_function = NULL;
switch ($op) {
case 'title':
$sort_function = create_function('$a,$b', 'return strnatcasecmp($a->title, $b->title);');
break;
case 'filename':
$sort_function = create_function('$a,$b', 'return strnatcasecmp(basename($a->filepath), basename($b->filepath));');
break;
case 'created':
case 'changed':
case 'weight':
$sort_function = create_function('$a,$b', 'return ($a->' . $op . ' <= $b->' . $op . ') ? -1 : 1;');
break;
case 'current':
default:
}
if ($sort_function && uasort($images, $sort_function) === FALSE) {
$image_nids = FALSE;
}
else {
$image_nids = array();
foreach ($images as $image) {
$image_nids[] = $image->nid;
}
if ($reverse && $op != 'current') {
$image_nids = array_reverse($image_nids);
}
}
return $image_nids;
}