public function save() { Yii::getLogger()->log('start save photobook:' . $this->id, YII_DEBUG); $photobook = Photobook::findOne(['id' => $this->id]); if (empty($photobook)) { $photobook = new Photobook(); $photobook->user_id = $this->user_id; $photobook->name = $this->name; $photobook->status = $this->status; $photobook->data = PhotobookForm::photosEncode($this->data); $photobook->template = $this->template; $photobook->style_id = $this->style_id; $photobook->cover_id = $this->cover_id; $photobook->title_line_1 = $this->title_line_1; $photobook->title_line_2 = $this->title_line_2; $photobook->title_line_3 = $this->title_line_3; $photobook->title_line_4 = $this->title_line_4; $photobook->photos_zip_hash = $this->photos_zip_hash; $photobook->change_status_at = $this->change_status_at; $photobook->view_access_key = $this->view_access_key; $photobook->invoice_id = $this->invoice_id; $this->photos = $this->addTextGroupIfNotExists($this->photos); $photobook->photos = PhotobookForm::photosEncode($this->photos); Yii::getLogger()->log('save:', YII_DEBUG); if ($photobook->save()) { $this->id = $photobook->id; return $photobook; } else { Yii::getLogger()->log('save error', YII_DEBUG); } } else { $photobook->user_id = $this->user_id; $photobook->name = $this->name; $photobook->status = $this->status; $photobook->data = PhotobookForm::photosEncode($this->data); $photobook->template = $this->template; $this->photos = $this->addTextGroupIfNotExists($this->photos); $photobook->photos = PhotobookForm::photosEncode($this->photos); $photobook->style_id = $this->style_id; $photobook->cover_id = $this->cover_id; $photobook->title_line_1 = $this->title_line_1; $photobook->title_line_2 = $this->title_line_2; $photobook->title_line_3 = $this->title_line_3; $photobook->title_line_4 = $this->title_line_4; $photobook->photos_zip_hash = $this->photos_zip_hash; $photobook->change_status_at = $this->change_status_at; $photobook->view_access_key = $this->view_access_key; $photobook->invoice_id = $this->invoice_id; Yii::getLogger()->log('update:', YII_DEBUG); //$photobook->id=$this->id; if ($photobook->update()) { return $photobook; } else { Yii::getLogger()->log('update error:' . print_r($photobook, true), YII_DEBUG); } } return null; }
public function actionSaveCustomerComments() { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $key = Yii::$app->request->get('key'); $index = Yii::$app->request->post('index'); $comment = Yii::$app->request->post('comment'); if (!empty($key)) { $photobookState = PhotobookState::findOne(['view_access_key' => $key]); if (!$photobookState) { return ['error' => ['msg' => Yii::t('app', 'Состояние не найдено')]]; } $comments = PhotobookForm::photosDecode($photobookState->comments); if (empty($comments[$index])) { return ['error' => ['msg' => Yii::t('app', 'Индекс не найден ' . $index)]]; } $comments[$index]['comment'] = $comment; $photobookState->comments = PhotobookForm::photosEncode($comments); if (!$photobookState->update()) { return ['error' => ['msg' => Yii::t('app', 'Не удалось записать в базу')]]; } else { return ['response' => ['status' => true]]; } } else { return ['error' => ['msg' => Yii::t('app', 'Состояние не найдено')]]; } }