You are here

function node_gallery_get_gallery_images in Node Gallery 6.2

1 call to node_gallery_get_gallery_images()
node_gallery_nodeapi in ./node_gallery.module
Implementation of hook_nodeapi().

File

./node_gallery.inc, line 128
Node gallery models

Code

function node_gallery_get_gallery_images(&$node, $ignore_pager = FALSE) {
  if (in_array($node->type, node_gallery_get_types())) {
    $sql = "SELECT n.nid, n.vid, n.title, n.type, n.created, nr.body, ng.*, f.* FROM {node} n \n      INNER JOIN {node_revisions} nr ON n.vid = nr.vid INNER JOIN {node_galleries} ng \n      ON n.nid = ng.nid INNER JOIN {files} f ON ng.fid = f.fid WHERE n.nid IN (SELECT g.nid FROM {node_galleries} g WHERE g.gid = %d) AND n.status = 1\n      ORDER BY ng.weight, ng.nid";
    if ($ignore_pager == FALSE) {
      $result = pager_query(db_rewrite_sql($sql), variable_get('node_images_page_number', 20), NODE_GALLERY_IMAGE_PAGER_ELEMENT, NULL, $node->nid);
    }
    else {
      $result = db_query(db_rewrite_sql($sql), $node->nid);
    }
    $record_counter = 0;
    $images = array();
    while ($object = db_fetch_object($result)) {
      $record_counter++;
      if ($record_counter % 50 == 0) {

        #Clear the cache every 50 nodes
        node_load(FALSE, NULL, TRUE);
      }
      $image = node_load($object->nid);
      $images[$image->fid] = $image;
    }

    //get the cck field content;
    if (module_exists('content') && !empty($images) && is_array($images)) {
      foreach ($images as &$item) {
        $content_type = content_types($item->type);
        if (!empty($content_type['fields'])) {
          content_load($item);
        }
      }
    }
    return $images;
  }
}