function afterSave(Model $Model, $created)
 {
     $saveActivity = false;
     $validateActivity = false;
     $primaryKey = null;
     if ($created) {
         if (empty($this->settings[$Model->alias]['saveOn']['conditions'])) {
             if ($this->settings[$Model->alias]['saveOn']['created']) {
                 //Use Case 1
                 $primaryKey = $Model->getLastInsertId();
                 $saveActivity = true;
             } else {
                 //Use Case 2
                 //do nothing
             }
         } else {
             if ($this->settings[$Model->alias]['saveOn']['created']) {
                 //Use Case 3
                 $primaryKey = $Model->getLastInsertId();
                 $validateActivity = true;
             } else {
                 //Use Case 4
                 $primaryKey = $Model->getLastInsertId();
                 $validateActivity = true;
             }
         }
     } else {
         if (empty($this->settings[$Model->alias]['saveOn']['conditions'])) {
             if ($this->settings[$Model->alias]['saveOn']['created']) {
                 //Use Case 5
                 //do noting
             } else {
                 //Use Case 6
                 //always happens - not implemented yet
                 //$saveActivity = true;
             }
         } else {
             if ($this->settings[$Model->alias]['saveOn']['created']) {
                 //Use Case 7
                 //do noting
             } else {
                 //Use Case 8
                 $primaryKey = $this->runtime[$Model->alias]['primaryKey'];
                 $validateActivity = true;
             }
         }
     }
     if ($validateActivity && $primaryKey != null) {
         if ($this->validateConditions($Model, $primaryKey)) {
             $saveActivity = true;
         }
     }
     if ($saveActivity) {
         $this->saveActivity($Model, $primaryKey);
     }
     unset($this->runtime[$Model->alias]);
 }
 /**
  * afterSave
  *
  * @param	Model	$model
  * @param Model $created
  * @return	void
  * @access	public
  */
 public function afterSave(Model $model, $created, $options = array())
 {
     // コンテンツIDを取得
     if ($created) {
         $contentId = $model->getLastInsertId();
     } else {
         $contentId = $model->data[$model->alias]['id'];
     }
     $pluginContent = $this->_generatePluginContentData($model, $contentId);
     /*		 * * データを保存 ** */
     if (isset($pluginContent['PluginContent']['id'])) {
         $this->PluginContent->set($pluginContent);
     } else {
         $this->PluginContent->create($pluginContent);
     }
     $this->PluginContent->save();
 }
 public function afterSave(Model $model, $created, $options = array())
 {
     if (!isset($model->id)) {
         $model->id = $model->getLastInsertId();
     }
     return $this->saveTranslation($model, $model->data, false);
 }
 /**
  *    Save Image
  * @param Model $model
  * @param $pict Image object
  * @param $edit_id Image ID (used for edit action)
  * @author Oleg
  * @return bool
  */
 function saveImage(Model $model, $pict, $edit_id = null)
 {
     $foo = new Upload($pict);
     $user_id = $_SESSION['loggedUser']['id'];
     if ($edit_id) {
         // If Edit action
         $objImage = new Image();
         $editFile = $objImage->field('filename', 'id=' . $edit_id);
         $id = $objImage->field('model_id', 'id=' . $edit_id);
         @unlink($this->settings['baseDir'] . $editFile);
         if ($this->settings['thumbs']['create']) {
             @unlink($this->settings['thumbsDir'] . $editFile);
         }
     } else {
         // If Add action
         $id = $model->getLastInsertId();
     }
     if (!$id && isset($model->{$model->primaryKey}) && $model->{$model->primaryKey}) {
         $id = $model->{$model->primaryKey};
     }
     $filename = $this->getNewFilename($pict['name'], $id);
     $foo->file_new_name_body = $filename;
     //$foo->image_convert = 'jpg';
     if ($foo->uploaded) {
         $foo->Process($this->settings['baseDir']);
         if ($foo->processed) {
             if (isset($pict['prop']) && !empty($pict['prop'])) {
                 $prop = $pict['prop'];
             } else {
                 $prop = 'All';
             }
             $this->ImageTableSave($filename . '.' . $this->format, $model, $id, $prop, $user_id, $edit_id);
         }
         if ($this->settings['thumbs']['create']) {
             $foo->file_new_name_body = $filename;
             //$foo->image_convert = 'jpg';
             $foo->image_resize = true;
             $foo->image_ratio_fill = 'C';
             if (isset($this->settings['thumbs']['height'])) {
                 $foo->image_y = $this->settings['thumbs']['height'];
             }
             if (isset($this->settings['thumbs']['width'])) {
                 $foo->image_x = $this->settings['thumbs']['width'];
             }
             if (isset($this->settings['thumbs']['bgcolor'])) {
                 $foo->image_background_color = $this->settings['thumbs']['bgcolor'];
             } else {
                 $foo->image_background_color = '#FFFFFF';
             }
             $foo->Process($this->settings['thumbsDir']);
         }
         if (isset($this->settings['watermark']) && !empty($this->settings['watermark']['image'])) {
             //Create watermark bpong
             $watermarked_image = $this->watermark(WWW_ROOT . "img/" . $model->name . "/{$filename}" . '.' . $this->format, WWW_ROOT . $this->settings['watermark']['image']);
             imagejpeg($watermarked_image, WWW_ROOT . "img/" . $model->name . "/{$filename}" . '.' . $this->format);
             unset($watermarked_image);
             //end of watermark create
         }
         if (isset($this->settings['versions']) && count($this->settings['versions'])) {
             foreach ($this->settings['versions'] as $version_name => $version) {
                 $foo->file_new_name_body = $filename;
                 //$foo->image_convert = 'jpg';
                 $foo->image_resize = true;
                 $foo->image_ratio_fill = 'C';
                 if (isset($version['height'])) {
                     $foo->image_y = $version['height'];
                 }
                 if (isset($version['width'])) {
                     $foo->image_x = $version['width'];
                 }
                 if (isset($version['bgcolor'])) {
                     $foo->image_background_color = $version['bgcolor'];
                 } else {
                     $foo->image_background_color = '#FFFFFF';
                 }
                 $foo->Process($this->settings['baseDir'] . $version_name . DS);
             }
         }
         return true;
     }
     return false;
 }