/**
  * insert/update/replace object
  *
  * @access public
  * @param object $obj
  * @param bool $force force operation
  * @return bool FALSE if failed
  */
 function insert(&$obj, $force = false)
 {
     if ($obj->isNew() && !$obj->doReplace()) {
         // set cvitae_order
         $uid = $obj->get('uid');
         $criteria = new Criteria('uid', $uid);
         $tmp =& $this->getObjects($criteria, false, 'MAX(`cvitae_order`) AS `max`');
         if (is_object($tmp)) {
             $max = $tmp->getExtraVar('max');
         } else {
             $max = 0;
         }
         $obj->set('cvitae_order', $max + 1);
     }
     return parent::insert($obj, $force);
 }
 /**
  * set sort_number automatically before insert.
  * @see TableObject::insert
  */
 function insert(&$obj, $force = false)
 {
     if (!is_null($obj->get('sort_number'))) {
         return parent::insert($obj, $force);
     }
     // for regular index
     $row = $this->getObjects(new Criteria('parent_index_id', $obj->get('parent_index_id')), false, 'MAX(sort_number) as max_value');
     if ($row) {
         $obj->set('sort_number', $row[0]->getExtraVar('max_value') + 1);
     } else {
         $obj->set('sort_number', 1);
     }
     return parent::insert($obj, $force);
 }
 function insert(&$obj, $force = false)
 {
     if ($obj->isNew()) {
         $obj->set('user_regdate', time());
     }
     return parent::insert($obj, $force);
 }
 function insert(&$obj, $force = false)
 {
     if (strtolower(get_class($obj)) != strtolower($this->__class_name)) {
         return false;
     }
     if (!$obj->isDirty()) {
         return true;
     }
     $cc = $this->get_cc($obj);
     if ($cc) {
         $obj->set('rights', $cc);
     }
     return parent::insert($obj, $force);
 }
 /**
  * insert a metadata of file and move a file to sysytem's upload_dir
  *
  * @param XooNIpsOrmFile $file file to be inserted
  * @param bool $force force insertion flag
  * @return boolean false if failure
  */
 function insert(&$file, $force = false)
 {
     if (!$file->isDirty()) {
         // nothing to do
         return true;
     }
     // fill thumbnail field if empty
     if ($file->isNew()) {
         $thumbnail = $file->get('thumbnail_file');
         if (empty($thumbnail)) {
             $file_path = $file->getFilepath();
             $mimetype = $file->get('mime_type');
             $fileutil =& xoonips_getutility('file');
             $thumbnail = $fileutil->get_thumbnail($file_path, $mimetype);
             if (!empty($thumbnail)) {
                 $file->set('thumbnail_file', $thumbnail);
             }
         }
     }
     if (parent::insert($file, $force)) {
         if (!$file->isNew()) {
             // no need to move file if update
             return true;
         }
         if (!$file->get('is_deleted')) {
             // move file in the only case of not deleted file
             return $this->moveFile($file);
         } else {
             return true;
         }
     }
     return false;
 }
 /**
  * @brief set current time to creation_date and last_update_date if these are not initialized and call parent::insert.
  *
  */
 function insert(&$obj, $force = false)
 {
     $date = $obj->get('creation_date');
     if ($obj->isNew() && !isset($date)) {
         $obj->set('creation_date', time());
     }
     $date = $obj->get('last_update_date');
     if ($obj->isDirty() && !isset($date)) {
         // update last_update_date
         $obj->set('last_update_date', time());
     }
     return parent::insert($obj, $force);
 }