Exemple #1
0
 public function updateCoverWindowImageText($field_name, $value)
 {
     $this->{$field_name} = $value;
     /*if(!$this->save()){
     
                 return ['error'=>['msg'=>Yii::t('app', 'Ошибка записи в базу-данных')]];
             }*/
     //$this->loadById($this->id);
     $style = Style::findOne(['id' => $this->style_id]);
     if (empty($style)) {
         return ['error' => ['msg' => Yii::t('app', 'Стиль для фотокниги не найден')]];
     }
     $font = Font::findOne(['id' => $style->font_id]);
     if (empty($font)) {
         return ['error' => ['msg' => Yii::t('app', 'Шрифт для фотокниги не найден')]];
     }
     $cover = Cover::findOne(['id' => $this->cover_id]);
     if (empty($cover)) {
         return ['error' => ['msg' => Yii::t('app', 'Обложка для фотокниги не найден')]];
     }
     $font_path = UserUrl::font(false) . DIRECTORY_SEPARATOR . UserUrl::fontFile($font->file);
     $line_1 = !empty($this->title_line_1) ? $this->title_line_1 : ' ';
     $line_2 = !empty($this->title_line_2) ? $this->title_line_2 : ' ';
     $line_3 = !empty($this->title_line_3) ? $this->title_line_3 : ' ';
     $line_4 = !empty($this->title_line_3) ? $this->title_line_4 : ' ';
     $this->name = $line_1 . " " . $line_2 . " " . $line_3;
     $this->save();
     $text = $line_1 . "\n" . $line_2 . "\n" . $line_3;
     $text_image_content = Utils::makeTextImage($text, $cover->window_width, $cover->window_height, '#000000', $font_path, 2, 72);
     $text_image_path = UserUrl::photobookWindowText(false, $this->id, $this->user_id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($this->id, UserUrl::IMAGE_ORIGINAL, 'png');
     $text_image_url = UserUrl::photobookWindowText(true, $this->id, $this->user_id) . "/" . UserUrl::imageFile($this->id, UserUrl::IMAGE_ORIGINAL, 'png');
     $user_pb_path = UserUrl::photobook(false, $this->id, $this->user_id);
     if (file_exists($user_pb_path)) {
         Yii::getLogger()->log('updateCoverWindowImageText exists user_pb_path:' . $user_pb_path, YII_DEBUG);
     } else {
         Yii::getLogger()->log('updateCoverWindowImageText NOT exists user_pb_path:' . $user_pb_path, YII_DEBUG);
     }
     // UserUrl::createNonexistentDirInPath(UserUrl::photobookWindowText(, 'pb'.DIRECTORY_SEPARATOR.$photobook_id)
     file_put_contents($text_image_path, $text_image_content);
     $file_tmp = new UploadedFile();
     $file_tmp->tempName = $text_image_path;
     $name = AlphaId::id($this->user_id) . '/pb/' . AlphaId::id($this->id) . '/window_text/' . UserUrl::imageFile($this->id, UserUrl::IMAGE_ORIGINAL, 'png');
     Yii::$app->resourceManager->save($file_tmp, $name);
     unlink($text_image_path);
     $tracing_text = $line_1 . "\n" . $line_2 . "\n" . $line_3 . "\n" . " " . "\n" . " " . "\n" . " " . "\n" . " " . "\n" . " " . $line_4;
     $tracing_text_image_content = Utils::makeTextImage($tracing_text, 350, 250, '#000000', $font_path, 15, 72);
     $tracing_text_image_path = UserUrl::photobookTracingText(false, $this->id, $this->user_id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($this->id, UserUrl::IMAGE_ORIGINAL, 'png');
     $tracing_text_image_url = UserUrl::photobookTracingText(true, $this->id, $this->user_id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($this->id, UserUrl::IMAGE_ORIGINAL, 'png');
     file_put_contents($tracing_text_image_path, $tracing_text_image_content);
     $file_tmp = new UploadedFile();
     $file_tmp->tempName = $tracing_text_image_path;
     $name = AlphaId::id($this->user_id) . '/pb/' . AlphaId::id($this->id) . '/tracing/' . UserUrl::imageFile($this->id, UserUrl::IMAGE_ORIGINAL, 'png');
     Yii::$app->resourceManager->save($file_tmp, $name);
     unlink($tracing_text_image_path);
     return ['response' => ['status' => true, 'value' => $value, 'text_image_url' => $text_image_url, 'tracing_text_image_url' => $tracing_text_image_url, 'window_offset_x' => $cover->window_offset_x, 'window_offset_y' => $cover->window_offset_y, 'window_width' => $cover->window_width, 'window_height' => $cover->window_height, 'font_path' => $font_path, 'text' => $text, 'name' => $this->name]];
 }
 public function actionEdit()
 {
     $this->layout = 'default';
     $id = Yii::$app->request->get('id', -1);
     $cover = Cover::findOne(['id' => $id]);
     if (!$cover) {
         Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Обложка не найдена'));
         $this->redirect(Url::toRoute(['covers/index']));
     }
     $material_types = ['кожа' => 'кожа', 'лен' => 'лен'];
     $price_signs = ['=' => Yii::t('app', 'Заменить базовую цену'), '+' => Yii::t('app', 'Добавить к базовой цене'), '-' => Yii::t('app', 'Отнять от базовой цены')];
     return $this->render('edit', ['cover' => $cover, 'material_types' => $material_types, 'price_signs' => $price_signs]);
 }
Exemple #3
0
 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;
 }