Example #1
0
 public function save()
 {
     //Yii::getLogger()->log('start save photobook:'.$this->id, YII_DEBUG);
     $style = Style::findOne(['id' => $this->id]);
     if (empty($style)) {
         $style = new Style();
         $style->name = $this->name;
         $style->status = $this->status;
         $style->data = $this->photosEncode($this->data);
         $style->weight = $this->weight;
         $style->thumb_key = $this->thumb_key;
         $style->delete = $this->delete;
         /*
                      *
                      *  public $text_for_icon='';
         
             public $placeholder_border_color_top_left='#000000';
         
             public $placeholder_border_color_bottom_right='#FFFFFF';
         
             public $padded_passepartout_key='style_default';
         
             public $padded_cover_key='style_default';
         */
         $style->text_for_icon = $this->text_for_icon;
         $style->placeholder_border_color_top_left = $this->placeholder_border_color_top_left;
         $style->placeholder_border_color_bottom_right = $this->placeholder_border_color_bottom_right;
         $style->padded_passepartout_key = $this->padded_passepartout_key;
         $style->padded_cover_key = $this->padded_cover_key;
         $style->max_spread = $this->max_spread;
         $style->font_id = $this->font_id;
         $style->cover_back_key = $this->cover_back_key;
         $style->cover_front_key = $this->cover_front_key;
         $style->price_spread = $this->price_spread;
         Yii::getLogger()->log('save:', YII_DEBUG);
         if ($style->save()) {
             $this->id = $style->id;
             return $style;
         } else {
             Yii::getLogger()->log('save error', YII_DEBUG);
         }
     } else {
         $style->name = $this->name;
         $style->status = $this->status;
         $style->data = $this->photosEncode($this->data);
         $style->weight = $this->weight;
         $style->thumb_key = $this->thumb_key;
         $style->delete = $this->delete;
         $style->text_for_icon = $this->text_for_icon;
         $style->placeholder_border_color_top_left = $this->placeholder_border_color_top_left;
         $style->placeholder_border_color_bottom_right = $this->placeholder_border_color_bottom_right;
         $style->padded_passepartout_key = $this->padded_passepartout_key;
         $style->padded_cover_key = $this->padded_cover_key;
         $style->max_spread = $this->max_spread;
         $style->font_id = $this->font_id;
         $style->cover_back_key = $this->cover_back_key;
         $style->cover_front_key = $this->cover_front_key;
         $style->price_spread = $this->price_spread;
         Yii::getLogger()->log('update:', YII_DEBUG);
         if ($style->update()) {
             return $style;
         } else {
             Yii::getLogger()->log('update error:' . print_r($style, true), YII_DEBUG);
         }
     }
     return null;
 }