public function save() { //Yii::getLogger()->log('start save photobook:'.$this->id, YII_DEBUG); $cover = Cover::findOne(['id' => $this->id]); if (empty($cover)) { $cover = new Cover(); /* * * * public $id = null; public $name = 'Новая обложка'; public $material_type = "кожа"; public $padded_cover='style_default'; public $cover_front='style_default'; public $cover_back='style_default'; public $thumb='style_default'; public $price=0.0; public $price_sign="+"; public $status = Cover::STATUS_UNPUBLISHED; public $default=0; public $window_offset_x=0.0; public $window_offset_y=0.0; public $window_width=0.0; public $window_height=0.0; */ $cover->name = $this->name; $cover->material_type = $this->material_type; $cover->padded_cover = $this->padded_cover; $cover->cover_front = $this->cover_front; $cover->cover_back = $this->cover_back; $cover->thumb = $this->thumb; $cover->price = $this->price; $cover->price_sign = $this->price_sign; $cover->status = $this->status; $cover->default = $this->default; $cover->window_offset_x = $this->window_offset_x; $cover->window_offset_y = $this->window_offset_y; $cover->window_width = $this->window_width; $cover->window_height = $this->window_height; Yii::getLogger()->log('save:', YII_DEBUG); if ($cover->save()) { $this->id = $cover->id; return $cover; } else { Yii::getLogger()->log('save error', YII_DEBUG); } } else { $cover->name = $this->name; $cover->material_type = $this->material_type; $cover->padded_cover = $this->padded_cover; $cover->cover_front = $this->cover_front; $cover->cover_back = $this->cover_back; $cover->thumb = $this->thumb; $cover->price = $this->price; $cover->price_sign = $this->price_sign; $cover->status = $this->status; $cover->default = $this->default; $cover->window_offset_x = $this->window_offset_x; $cover->window_offset_y = $this->window_offset_y; $cover->window_width = $this->window_width; $cover->window_height = $this->window_height; Yii::getLogger()->log('update:', YII_DEBUG); if ($cover->update()) { return $cover; } else { Yii::getLogger()->log('update error:' . print_r($cover, true), YII_DEBUG); } } return null; }