You are here

function Gallery::get_image_navigator in Node Gallery 6

File

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

Class

Gallery

Code

function get_image_navigator($nid) {
  $result = db_query("SELECT nid FROM {ng_images} WHERE gid = %d ORDER BY weight, nid", $this->nid);
  while ($r = db_fetch_array($result)) {
    $items[] = $r['nid'];
  }
  $navigator['total'] = count($items);
  $navigator['parent'] = $this->nid;
  for ($i = 0; $i < $navigator['total']; $i++) {
    if ($items[$i] == $nid) {
      $navigator['current'] = $i + 1;
      $navigator['prev_nid'] = $i == 0 ? $items[$navigator['total'] - 1] : $items[$i - 1];
      $navigator['next_nid'] = $i == $navigator['total'] - 1 ? $items[0] : $items[$i + 1];
    }
  }
  return $navigator;
}