You are here

static function gallery_gateway::find_covers in Node Gallery 6

1 call to gallery_gateway::find_covers()
node_gallery_list in ./node_gallery.pages.inc
@file Node gallery pages.

File

./node_gallery.model.inc, line 100
Node gallery module.

Class

gallery_gateway

Code

static function find_covers($gids) {
  $gids = is_numeric($gids) ? array(
    $gids,
  ) : (array) $gids;
  $result = db_query("SELECT gid, nid FROM {ng_images} WHERE gid IN (" . db_placeholders($gids) . ") AND is_cover = 1", $gids);
  while ($r = db_fetch_array($result)) {
    $covers[$r['gid']] = $r['nid'];
  }

  //if no cover was set, get the first image;
  foreach ($gids as $gid) {
    if (empty($covers[$gid])) {
      $gids2[] = $gid;
    }
  }
  if (!empty($gids2)) {
    $result = db_query("SELECT gid, nid FROM {ng_images} WHERE gid IN (" . db_placeholders($gids2) . ") GROUP BY gid", $gids2);
    while ($r = db_fetch_array($result)) {
      $covers[$r['gid']] = $r['nid'];
    }
  }
  return $covers;
}