예제 #1
0
 public function actionDelete()
 {
     $this->layout = 'default';
     $id = Yii::$app->request->get('id', 0);
     if (!empty($id)) {
         $model = new StyleForm();
         if ($model->loadById($id)) {
             if ($model->delete()) {
                 Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Стиль успешно удален.'));
                 $this->redirect(Url::toRoute(['styles/index']));
             } else {
                 Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Не удалось удалить.'));
                 $this->redirect(Url::toRoute(['styles/index']));
             }
         }
     } else {
         Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Не удалось удалить.'));
         $this->redirect(Url::toRoute(['styles/index']));
     }
 }
예제 #2
0
 public function addGroup($group_name = '', $after_group)
 {
     $group_index = count($this->data['layouts']);
     $group_data = StyleForm::GenerateRandomLayout($group_index);
     if (!empty($group_name)) {
         $group_data['label'] = $group_name;
     }
     $i = 0;
     $newlayouts = [];
     foreach ($this->data['layouts'] as $key => $group) {
         $newlayouts[$i] = $group;
         $i++;
         if ($key == $after_group) {
             $newlayouts[$i] = $group_data;
             $i++;
         }
     }
     $this->data['layouts'] = $newlayouts;
     if ($this->save()) {
         /* $current_group= StyleLayoutGroup::widget([
         
                             'group_name'=>$group_data['label'],
                             'change_group_name_template_url' => Url::toRoute(['styles-api/change-group-name', 'id'=>$this->id, 'group_index'=>$group_index, 'newgroup'=>'newgroupname']),
                             'upload_files_url'=>Url::toRoute(['styles-api/upload-background', 'id'=>$this->id, 'group_index'=>$group_index]),
                             'upload_files_template_url'=>Url::toRoute(['styles-api/upload-background', 'id'=>$this->id, 'group_index'=>'groupindex']),
                             'group_data'=>$group_data,
                             'style_id'=>$this->id,
                             'delete_url'=>Url::toRoute(['styles-api/delete-group', 'id'=>$this->id,  'group_index'=>$group_index]),
                             'change_background_color_url'=>Url::toRoute(['styles-api/change-group-background-color', 'id'=>$this->id,  'group_index'=>$group_index, 'color'=>'newcolor']),
                             'background_color'=>$group_data['background_color'],
                             'background_image'=>$group_data['background_image'],
                             'add_group_url'=>Url::toRoute(['styles-api/add-group',  'id'=>$this->id, 'after_group'=>$group_index])
         
                         ]);*/
         $groups = [];
         $i = 0;
         foreach ($newlayouts as $key => $group_data) {
             $i = $key;
             $groups[$i] = StyleLayoutGroup::widget(['group_name' => $group_data['label'], 'change_group_name_template_url' => Url::toRoute(['styles-api/change-group-name', 'id' => $this->id, 'group_index' => $i, 'newgroup' => 'newgroupname']), 'upload_files_url' => Url::toRoute(['styles-api/upload-background', 'id' => $this->id, 'group_index' => $i]), 'upload_files_template_url' => Url::toRoute(['styles-api/upload-background', 'id' => $this->id, 'group_index' => 'groupindex']), 'group_data' => $group_data, 'style_id' => $this->id, 'delete_url' => Url::toRoute(['styles-api/delete-group', 'id' => $this->id, 'group_index' => $i]), 'change_background_color_url' => Url::toRoute(['styles-api/change-group-background-color', 'id' => $this->id, 'group_index' => $i, 'color' => 'newcolor']), 'background_color' => $group_data['background_color'], 'background_image' => $group_data['background_image'], 'add_group_url' => Url::toRoute(['styles-api/add-group', 'id' => $this->id, 'after_group' => $i]), 'group_index' => $i]);
             $i++;
         }
         $result = ['response' => ['status' => true, 'groups' => $groups]];
     } else {
         $result = ['error' => ['msg' => Yii::t('app', 'Не удалось сохранить изменения')]];
     }
     return $result;
 }
예제 #3
0
 public function actionViewBook()
 {
     $this->layout = 'editor';
     $ref = Yii::$app->request->get('ref');
     $id = Yii::$app->request->get('id');
     $selected_style_id = Yii::$app->request->get('style_id', 0);
     if (!empty($ref) && !empty($id)) {
         $user_id = AlphaId::id($ref, true);
         $pb_id = AlphaId::id($id, true);
         if ($user_id != Yii::$app->user->identity->getId()) {
             Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Страница не найдена'));
             $this->redirect(Url::toRoute(['photobooks/index']));
             return;
         }
         $model = new PhotobookForm();
         if (!$model->loadById($pb_id)) {
             Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Фотокнига не найдена'));
             $this->redirect(Url::toRoute(['photobooks/index']));
             return;
         }
         if (empty($model->data['pages'])) {
             Yii::$app->getSession()->setFlash('error', Yii::t('app', 'В фотокниги нет ни одного разворота'));
             $this->redirect(Url::toRoute(['photobooks/index', 'status' => $model->status]));
             return;
         }
         $style_id = $model->style_id;
         $style = new StyleForm();
         if (!$style->loadById($style_id)) {
             Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Стиль для данной фотокниги не найден.'));
             $this->redirect(Url::toRoute(['photobooks/index']));
             return;
         }
         $selected_cover = new CoverForm();
         if (!$selected_cover->loadById($model->cover_id)) {
             Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Обложка для данной фотокниги не найден.'));
             $this->redirect(Url::toRoute(['photobooks/index']));
             return;
         }
         $covers = Cover::find()->where(['status' => 1])->all();
         $new_covers = [];
         foreach ($covers as $key => $cover) {
             $new_covers[$cover->material_type][] = $cover;
         }
         $pages = $model->data['pages'];
         $base_price = (count($pages) - 2) * $style->price_spread;
         $cover_price_sign = $selected_cover->price_sign;
         $selected_cover->price;
         $total_price = $base_price;
         if ($cover_price_sign == "=") {
             $total_price = $selected_cover->price;
         } else {
             if ($cover_price_sign == "+") {
                 $total_price += $selected_cover->price;
             } else {
                 if ($cover_price_sign == "-") {
                     $total_price -= $selected_cover->price;
                 }
             }
         }
         $user = User::findOne(['id' => $user_id]);
         $total_price = CurrencyConvertor::conv($total_price, $user->default_currency);
         $curse = CurrencyConvertor::getCurse($user->default_currency);
         return $this->render('viewBook', ['model' => $model, 'ref' => $ref, 'id' => $id, 'pb_id' => $pb_id, 'user_id' => $user_id, 'pages' => $pages, 'style' => $style, 'selected_cover' => $selected_cover, 'covers' => $new_covers, 'total_price' => $total_price, 'default_currency' => $user->default_currency, 'cover_price_sign' => $cover_price_sign, 'cover_price' => $selected_cover->price, 'price_spread' => $style->price_spread, 'curse' => $curse]);
     } else {
         Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Страница не найдена'));
         $this->redirect(Url::toRoute(['photobooks/index']));
     }
 }
예제 #4
0
 public function getProductInfo()
 {
     $cover = new CoverForm();
     if (!$cover->loadById($this->cover_id)) {
         return ['error' => ['msg' => Yii::t('app', 'Обложка для книги не найдена')]];
     }
     $style = new StyleForm();
     if (!$style->loadById($this->style_id)) {
         return ['error' => ['msg' => Yii::t('app', 'Стиль для книги не найдена')]];
     }
     if (empty($this->data)) {
         return ['error' => ['msg' => Yii::t('app', 'Ошибка данных')]];
     }
     if (empty($this->data['pages'])) {
         return ['error' => ['msg' => Yii::t('app', 'Страниц не найдено')]];
     }
     $pages = $this->data['pages'];
     $print_count = 0;
     foreach ($pages as $key => $page) {
         if ($key == 0 || $key == count($pages) - 1) {
             continue;
         }
         if ($page['action'] == 'print') {
             $print_count++;
         }
     }
     if ($print_count <= 0) {
         return ['error' => ['msg' => Yii::t('app', 'Разворотов для печати не найдено')]];
     }
     $base_price = (count($pages) - 2) * $style->price_spread;
     $cover_price_sign = $cover->price_sign;
     $total_price = $base_price;
     if ($cover_price_sign == "=") {
         $total_price = $cover->price;
     } else {
         if ($cover_price_sign == "+") {
             $total_price += $cover->price;
         } else {
             if ($cover_price_sign == "-") {
                 $total_price -= $cover->price;
             }
         }
     }
     $text_info = Yii::t('app', 'Код товара:') . ' ' . $this->id . '. ' . Yii::t('app', 'Фотокнига:') . ' ' . $this->name . ', ' . Yii::t('app', 'обложка:') . ' ' . $cover->material_type . '/' . $cover->name . ', ' . Yii::t('app', '1 калька') . ', ' . $print_count . ' ' . Utils::getInclinationByNumber($print_count, ['разворот', 'разворота', 'разворотов']);
     return ['response' => ['status' => true, 'price' => $total_price, 'text_info' => $text_info]];
 }
예제 #5
0
 public function actionChangeStyle()
 {
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $photobook_id = Yii::$app->request->get('photobook_id', 0);
     $style_id = Yii::$app->request->get('style_id', 0);
     $model = new PhotobookForm();
     if (empty($photobook_id)) {
         return ['error' => ['msg' => Yii::t('app', 'Не верный photobook_id')]];
     }
     if (!$model->loadById($photobook_id)) {
         return ['error' => ['msg' => Yii::t('app', 'Фотокнига не найдена')]];
     }
     $styleModel = new StyleForm();
     if (!$styleModel->loadById($style_id)) {
         return ['error' => ['msg' => Yii::t('app', 'Стиль не найден')]];
     }
     $model->style_id = $style_id;
     if (!$model->save()) {
         return ['error' => ['msg' => Yii::t('app', 'Ошибка записи в базу данных')]];
     }
     return ['response' => ['status' => true]];
 }