You are here

function node_gallery_get_image_nids in Node Gallery 6.3

Parameters

$gid: The NID of the parent gallery.

boolean $sorted: Whether to apply the sorts specified by the view

boolean $filtered: Whether to apply the filters specified by the view

Return value

An array of nids representing the images of the gallery

7 calls to node_gallery_get_image_nids()
node_gallery_get_images in ./node_gallery.inc
Retrieves image properties sorted by the image sort view in a gallery, the returned objects are NOT complete nodes.
node_gallery_manage_images_form in ./node_gallery.pages.inc
Displays the content for our "Manage Images" tab, which is a VBO view.
node_gallery_nodeapi in ./node_gallery.module
Implements hook_nodeapi().
_node_gallery_cache_sorted_image_nids in ./node_gallery.inc
Builds the caches for a gallery and saves them to the db.
_node_gallery_delete in ./node_gallery.module
Deletes the child image nodes when deleting a gallery.

... See full list

File

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

Code

function node_gallery_get_image_nids($gid, $sorted = TRUE, $filtered = TRUE, $fallback = FALSE, $reset = FALSE) {
  static $nids = array();
  $cache_keys[] = 'node_gallery';
  $cache_keys[] = $gid;
  $cache_keys[] = 'image_nids';
  $cache_keys[] = $sorted ? 'sort-true' : 'sort-false';
  $cache_keys[] = $filtered ? 'filtered-true' : 'filtered-false';
  $cache_keys[] = $fallback ? 'fallback-true' : 'fallback-false';
  $cache_key = implode(':', $cache_keys);
  if (!isset($nids[$cache_key]) || $reset) {
    if (!$reset && ($cache = cache_get($cache_key)) && !empty($cache->data)) {
      $nids[$cache_key] = $cache->data;
    }
    else {
      if (!$fallback) {
        $gallery = node_load($gid);
        $relationship = node_gallery_get_relationship($gallery->type);
        $viewkey = unserialize($relationship['settings']['view_navigator_image_display']);
        if (isset($viewkey['name'])) {
          $view = views_get_view($viewkey['name']);
          if (!isset($view->display[$viewkey['display_id']])) {
            $message = t('Unable to find the sort view specified in the !relationship, maybe you need to !revert your view?', array(
              '!revert' => l(t('revert'), 'admin/build/views/delete/' . $viewkey['name']),
              '!relationship' => l(t('relationship settings'), 'admin/settings/node-gallery/relationship/settings/' . $relationship['rid']),
            ));
          }
          else {
            $view
              ->set_display($viewkey['display_id']);
            $view
              ->set_arguments(array(
              $gallery->nid,
            ));
            if (!$sorted) {
              $sorts = $view
                ->get_items('sort', $viewkey['display_id']);
              foreach ($sorts as $sort) {
                $view
                  ->set_item($viewkey['display_id'], 'sort', $sort['id'], NULL);
              }
            }
            if (!$filtered) {
              $filters = $view
                ->get_items('filter', $viewkey['display_id']);
              foreach ($filters as $filter) {
                $view
                  ->set_item($viewkey['display_id'], 'filter', $filter['id'], NULL);
              }
            }
            $view
              ->build();
            if (isset($view->query->fields['nid'])) {

              // This is for Views2 and Views3 compatability: http://drupal.org/node/1029840
              $sql = isset($view->query->final_query) ? $view->query->final_query : $view->build_info['query'];
            }
            else {
              $message = t('Found the image sort view, but the \'Node: Nid\' field wasn\'t found.', array());
            }
          }
        }
        else {
          $message = t('Unable to find a navigator image sort view.  Please revisit your !rellink.', array(
            '!rellink' => l(t('Node Gallery relationship settings'), 'admin/settings/node-gallery/relationship/settings/' . $relationship['rid']),
          ));
        }
      }
      if (isset($message) || $fallback) {

        // Use our default sql
        if (isset($message)) {
          if (user_access('administer node gallery')) {
            drupal_set_message($message, 'warning');
          }
          watchdog('node_gallery', $message, NULL, WATCHDOG_WARNING);
        }
        if ($filtered) {
          $where = 'n.status = 1 AND';
        }
        if ($sorted) {
          $orderby = 'ORDER BY weight ASC, n.nid DESC';
        }
        $sql = "SELECT ngi.nid FROM {node_gallery_images} ngi JOIN {node} n on ngi.nid = n.nid WHERE {$where} gid = %d {$orderby}";
      }
      $result = db_query($sql, $gid);
      $nids[$cache_key] = array();
      while ($r = db_fetch_array($result)) {
        $nids[$cache_key][] = $r['nid'];
      }
      cache_set($cache_key, $nids[$cache_key], 'cache', CACHE_TEMPORARY);
    }
  }
  return $nids[$cache_key];
}