public function deletePlaceholder($page, $place_num, $photo_id) { $style = Style::findOne(['id' => $this->style_id, 'delete' => 0]); $mapTemplates = $this->getMapTemplates(); $new_photos = array(); $photos = $this->data['pages'][$page]['photos']; if (count($photos) == 1) { return ['response' => ['status' => true, 'page' => $this->data['pages'][$page]]]; } $place_index = intval($place_num) - 1; $i = 0; foreach ($photos as $index => $photo) { if ($index != $place_index) { $new_photos[$i] = $photo; $i++; } } $this->data['pages'][$page]['photos'] = $new_photos; $this->data['pages'][$page]['json'] = $this->renderJsonPage($this->data['pages'][$page], $mapTemplates, $style); $this->data['pages'][$page]['svg'] = $this->renderSvgPage($this->data['pages'][$page], $mapTemplates, $style); $this->data['pages'][$page]['svg_thumb'] = $this->renderSvgPage($this->data['pages'][$page], $mapTemplates, $style, UserUrl::IMAGE_SMALL); if ($this->save()) { return ['response' => ['status' => true, 'page' => $this->data['pages'][$page]]]; } else { return ['error' => ['msg' => Yii::t('app', 'Не удалось записать в базу-данных')]]; } }
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; }
public function actionEdit() { $this->layout = 'default'; $id = Yii::$app->request->get('id', -1); $style = Style::findOne(['id' => $id]); if (!$style) { Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Стиль не найден')); $this->redirect(Url::toRoute(['styles/index'])); } $fonts = Font::find()->all(); $fonts = ArrayHelper::map($fonts, 'id', 'name'); $style->data = json_decode($style->data, true); return $this->render('edit', ['style' => $style, 'fonts' => $fonts]); }