You are here

class Image in Node Gallery 6

Hierarchy

Expanded class hierarchy of Image

File

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

View source
class Image extends base {
  function delete() {
    node_delete($this->nid);
    db_query("DELETE FROM {ng_images} WHERE nid = %d", $this->nid);
    db_query("DELETE FROM {files} WHERE fid = %d", $this->fid);
    file_delete($this->filepath);

    // Make sure to flush out the old imagecache images
    if (function_exists(imagecache_image_flush)) {
      imagecache_image_flush($this->filepath);
    }
  }
  function save($form) {
    module_load_include('inc', 'node', 'node.pages');
    $form_state['values'] = (array) $this;
    node_form_submit($form, $form_state);

    //insert node;
    if (empty($this->nid)) {
      $this->nid = $form_state['nid'];
    }
    file_set_status($this, FILE_STATUS_PERMANENT);
    if ($this->gid && $this->nid) {
      $this
        ->add_to_gallery();
    }
  }
  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);
    }
  }

}

Members