You are here

function node_gallery_get_images in Node Gallery 6.3

Retrieves image properties sorted by the image sort view in a gallery, the returned objects are NOT complete nodes.

Parameters

object $gallery The node object of the gallery.:

boolean $sorted Whether to keep the order as effective in the UI. Defaults to true.:

boolean $filtered Whether to filter down the resulting images by publish status.:

Return value

array An array of image objects with the basic properties nid, title, status, created, changed, filepath and weight.

4 calls to node_gallery_get_images()
node_gallery_get_images_slice in ./node_gallery.inc
Returns a specific slice of the node_gallery_get_images() array. If both $to_left and $to_right are not set or are 0, this returns only 1 element.
node_gallery_get_image_nids_sorted_by in ./node_gallery.inc
Get image nids sorted by a custom field, such as title or filepath.
node_gallery_json_get_images in ./node_gallery.pages.inc
Page callback for json image object requests.
node_gallery_sort_images_form in ./node_gallery.pages.inc
Form function for the "Sort Images" tab.

File

./node_gallery.inc, line 372
Shared functions for node_gallery

Code

function node_gallery_get_images($gallery, $sorted = TRUE, $filtered = TRUE, $reset = FALSE) {
  static $images = array();
  $cache_keys[] = 'node_gallery';
  $cache_keys[] = $gallery->nid;
  $cache_keys[] = 'images';
  $cache_keys[] = $sorted ? 'sort-true' : 'sort-false';
  $cache_keys[] = $filtered ? 'filtered-true' : 'filtered-false';
  $cache_key = implode(':', $cache_keys);
  if (!isset($images[$cache_key]) || $reset) {
    if (!$reset && ($cache = cache_get($cache_key)) && !empty($cache->data)) {
      return $cache->data;
    }
    else {
      $images[$cache_key] = array();

      // get the order currently in effect; the criteria is unknown here because the user can change the view.
      $image_nids = node_gallery_get_image_nids($gallery->nid, $sorted, $filtered);
      if (count($image_nids) == 0) {
        cache_set($cache_key, $images[$cache_key], 'cache', CACHE_TEMPORARY);
        return $images[$cache_key];
      }

      // get CCK information for retrieving the filepath
      $relationship = node_gallery_get_relationship($gallery->type);
      $field = content_fields($relationship['imagefield_name']);
      $field_db_info = content_database_info($field);
      $field_db_table = $field_db_info['table'];
      $field_db_column = $field_db_info['columns']['fid']['column'];
      $sql = 'SELECT n.nid,n.title,n.status,n.created,n.changed,f.filepath,ngi.weight FROM {node} n' . ' INNER JOIN {node_revisions} r ON r.vid = n.vid' . ' INNER JOIN {' . $field_db_table . '} cck ON cck.nid = n.nid' . ' INNER JOIN {files} f ON f.fid = cck.' . $field_db_column . ' INNER JOIN {node_gallery_images} ngi ON ngi.nid = n.nid' . ' WHERE n.nid IN (' . db_placeholders($image_nids) . ')';
      if ($filtered) {
        $sql .= ' AND n.status = 1';
      }
      $result = db_query($sql, $image_nids);
      $unordered = array();
      while ($image = db_fetch_object($result)) {
        $unordered[$image->nid] = $image;
      }
      if ($sorted) {
        foreach ($image_nids as $nid) {
          $images[$cache_key][] = $unordered[$nid];
        }
      }
      else {
        $images[$cache_key] = array_values($unordered);
      }
      cache_set($cache_key, $images[$cache_key], 'cache', CACHE_TEMPORARY);
    }
  }
  return $images[$cache_key];
}