You are here

class gallery_gateway in Node Gallery 6

Hierarchy

Expanded class hierarchy of gallery_gateway

File

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

View source
class gallery_gateway {
  static function find_by($uid = NULL, $type = NULL) {
    $gallery_types = empty($type) ? array_keys(gallery_config_gateway::get_types()) : $type;
    $args = $gallery_types;
    $sql = "SELECT n.nid, n.title, n.type, n.created, n.uid FROM {node} n \n    WHERE n.type IN (" . db_placeholders($gallery_types, 'varchar') . ") AND n.status = 1";
    if ($uid) {
      $sql .= " AND n.uid = %d";
      $args[] = $uid;
    }
    $result = db_query($sql, $args);
    while ($r = db_fetch_array($result)) {
      $items[$r['nid']] = new Gallery($r);
    }
    return $items;
  }
  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;
  }
  static function count_images($gids) {
    $gids1 = is_numeric($gids) ? array(
      $gids,
    ) : (array) $gids;
    $result = db_query("SELECT COUNT(nid) AS count, gid FROM {ng_images} WHERE gid IN (" . db_placeholders($gids1) . ")\n     GROUP BY gid", $gids1);
    while ($r = db_fetch_array($result)) {
      $items[$r['gid']] = empty($r['count']) ? 0 : $r['count'];
    }
    return is_numeric($gids) ? $items[$gids] : $items;
  }
  static function delete($gids) {
    $gids = is_numeric($gids) ? array(
      $gids,
    ) : (array) $gids;
    return db_query("DELETE FROM {ng_images} WHERE gid IN (" . db_placeholders($gids) . ")", $gids);
  }
  static function get_images($gid) {
    $result = db_query("SELECT nid FROM {ng_images} WHERE gid = %d", $gid);
    while ($r = db_fetch_array($result)) {
      $nids[] = $r['nid'];
    }
    if (!empty($nids)) {
      return ImageGateway::find_details($nids);
    }
  }

}

Members