/**
  * Saves object to databse.
  * @access protected.
  */
 public function save()
 {
     if ($this->is_active == 0) {
         Logger::log(CONTENT_HAS_BEEN_DELETED, "Attempt to save a deleted content with content_id = {$this->content_id}");
         throw new CNException(CONTENT_HAS_BEEN_DELETED, "Object you are trying to save has been deleted");
     }
     Logger::log(" Enter: CNContent::save()", LOGGER_INFO);
     try {
         if (empty($this->active)) {
             $this->active = 1;
         }
         // before saving, check if content already exists or not.
         if ($this->content_id) {
             // UPDATE if exists
             if ($this->parent_collection_id != -1) {
                 //FIXME: do we need to make the distinction here?  Should probably always be able to set collection_id, even if -1.
                 $sql = "UPDATE {contents} SET title = ?, is_active = ?, body = ?, allow_comments =?, changed = ?, trackbacks = ?, collection_id = ?, is_html = ? WHERE content_id = ? AND is_active = ?";
                 $res = Dal::query($sql, array($this->title, $this->is_active, $this->body, $this->allow_comments, time(), $this->trackbacks, $this->parent_collection_id, $this->is_html, $this->content_id, $this->is_active));
             } else {
                 $sql = "UPDATE {contents} SET title = ?, is_active = ?, body = ?, allow_comments =?, changed = ?, trackbacks = ?, is_html = ? WHERE content_id = ? AND is_active = ?";
                 $res = Dal::query($sql, array($this->title, $this->is_active, $this->body, $this->allow_comments, time(), $this->trackbacks, $this->is_html, $this->content_id, $this->is_active));
             }
         } else {
             // get next ID for content.
             $this->content_id = Dal::next_id('ContentCollection');
             $this->created = time();
             $this->changed = $this->created;
             if (!$this->allow_comments) {
                 $this->allow_comments = 0;
             }
             $sql = "INSERT INTO {contents} (content_id, author_id, type, title, is_active, body, allow_comments, collection_id, created, changed, trackbacks, display_on, is_html) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
             $res = Dal::query($sql, array($this->content_id, $this->author_id, $this->type, $this->title, $this->is_active, $this->body, $this->allow_comments, $this->parent_collection_id, $this->created, $this->changed, $this->trackbacks, $this->display_on, $this->is_html));
         }
         if ($this->is_default_content == FALSE) {
             // fix the Type of SB media here so they show in Recent Media
             $type = $this->type;
             if (!empty($this->sb_mc_type)) {
                 if (preg_match('/video/', $this->sb_mc_type)) {
                     $type = VIDEO;
                 }
                 if (preg_match('/image/', $this->sb_mc_type)) {
                     $type = IMAGE;
                 }
                 if (preg_match('/audio/', $this->sb_mc_type)) {
                     $type = AUDIO;
                 }
             }
             CNContent::save_recent_content($this->content_id, $type);
         }
         // if everything succeeded, commit
         Dal::commit();
     } catch (Exception $e) {
         Logger::log("Exception occurred inside CNContent::save(); rolling back", LOGGER_INFO);
         Dal::rollback();
         throw $e;
     }
     Logger::log("Exit: CNContent::save()", LOGGER_INFO);
     return $this->content_id;
 }