You are here

function Image::add_to_gallery in Node Gallery 6

1 call to Image::add_to_gallery()
Image::save in ./node_gallery.model.inc

File

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

Class

Image

Code

function add_to_gallery() {

  //update
  if (db_result(db_query("SELECT nid FROM {ng_images} WHERE gid = %d AND nid = %d", $this->gid, $this->nid))) {
    return drupal_write_record('ng_images', $this, array(
      'gid',
      'nid',
    ));
  }
  else {
    $has_images = db_result(db_query("SELECT nid FROM {ng_images} WHERE gid = %d", $this->gid));

    //the first upload image is set to default cover;
    if (!$has_images) {
      $this->is_cover = 1;
    }
    else {

      //only one image can be set to cover;
      if ($this->is_cover) {
        db_query("UPDATE {ng_images} SET is_cover = %d WHERE is_cover = 1 AND gid = %d", $this->gid);
      }
    }
    return drupal_write_record('ng_images', $this);
  }
}