You are here

function node_gallery_api_get_items in Node Gallery 7

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.

3 calls to node_gallery_api_get_items()
node_gallery_api_manage_items_form in ./node_gallery_api.pages.inc
Displays the content for our "Manage Images" tab, which is a VBO view.
node_gallery_api_sort_items_form in ./node_gallery_api.pages.inc
Form function for the "Sort Items" tab.
node_gallery_api_sort_items_form_set_chronological_sorting in ./node_gallery_api.pages.inc
Submit function to set image weights reflecting chronological order of their making

File

./node_gallery_api.inc, line 203
Node Gallery API function

Code

function node_gallery_api_get_items($gallery, $sorted = TRUE, $filtered = TRUE, $reset = FALSE) {
  $items =& drupal_static(__FUNCTION__, array(), $reset);
  $cache_keys[] = 'node_gallery';
  $cache_keys[] = $gallery->nid;
  $cache_keys[] = 'items';
  $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 {
      $items[$cache_key] = array();

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

      // Get CCK information for retrieving the filepath.
      $relationship_type = node_gallery_api_get_relationship_type($gallery->type);
      $field = field_info_field($relationship_type->filefield_name);
      foreach ($item_nids as $nid) {
        $item = node_load($nid);
        if (!empty($relationship_type->filefield_name)) {
          $files = field_get_items('node', $item, $relationship_type->filefield_name);
          if (!empty($files)) {
            $item->node_gallery['item_file'] = $files[0];
            $item->node_gallery['item_file_url'] = file_create_url($files[0]['uri']);
          }
        }
        $items[$cache_key][] = $item;
      }
      cache_set($cache_key, $items[$cache_key], 'cache', CACHE_TEMPORARY);
    }
  }
  return $items[$cache_key];
}