Ejemplo n.º 1
0
 public function beforeAction($action)
 {
     //$css_file_id='';
     $test = 11;
     $ref = Yii::$app->request->get('ref', '');
     $id = Yii::$app->request->get('id', '');
     $user_id = 0;
     if (!\Yii::$app->user->isGuest) {
         $user_id = \Yii::$app->user->identity->getId();
     }
     if (!empty($ref)) {
         $user_id = AlphaId::id($ref, true);
     }
     $user_setting = UserSetting::findByUserId($user_id);
     if ($user_setting) {
         $this->getView()->params['css_file_id'] = $user_setting->css_file_id;
         $this->getView()->params['logo_url'] = $user_setting->logo_url;
         $this->getView()->params['ref_user_id'] = $user_id;
         $this->getView()->params['id'] = $id;
         $this->getView()->params['ref'] = $ref;
     } else {
         $this->getView()->params['css_file_id'] = '';
         $this->getView()->params['logo_url'] = '';
     }
     if ($user_id != 0) {
         $cartForm = new CartForm();
         $rows = $cartForm->getUserCart($user_id, true);
         $this->getView()->params['cart_count'] = count($rows);
         $invoicies = Invoice::find()->where(['user_id' => $user_id, 'status' => Invoice::STATUS_NEW])->all();
         $invoice = Invoice::findOne(['user_id' => $user_id, 'status' => Invoice::STATUS_NEW]);
         $invoice_id = 0;
         if ($invoice) {
             $invoice_id = $invoice->id;
         }
         $this->getView()->params['invoice_count'] = count($invoicies);
         $this->getView()->params['invoice_id'] = $invoice_id;
         if (!Yii::$app->user->isGuest && Yii::$app->user && Yii::$app->user->identity) {
             $this->getView()->params['demo'] = Yii::$app->user->identity->role == User::ROLE_DEMO ? true : false;
         }
     } else {
         $this->getView()->params['demo'] = 0;
     }
     return parent::beforeAction($action);
 }
Ejemplo n.º 2
0
 public function updateBackgroundImage($group_index, $save = false)
 {
     if (isset($this->data['layouts'][$group_index])) {
         $group = $this->data['layouts'][$group_index];
         //Если есть старый фон удаляем его
         if (!empty($group['background_image'])) {
             $file_id = $group['background_image'];
             $file_path = UserUrl::styleBackground(false, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, UserUrl::IMAGE_ORIGINAL);
             if (file_exists($file_path)) {
                 unlink($file_path);
             }
             foreach (UserUrl::$IMAGE_SIZE as $key => $size) {
                 if ($key != UserUrl::IMAGE_ORIGINAL) {
                     $file_resize_path = UserUrl::styleBackground(false, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, $key);
                     if (file_exists($file_resize_path)) {
                         unlink($file_resize_path);
                     }
                 }
             }
         }
         $file = UploadedFile::getInstance($this, 'photo');
         if ($file) {
             if ($file->size !== 0) {
                 $file_id = AlphaId::id(rand(10000000000, 9999999999999));
                 $file_path = UserUrl::styleBackground(false, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, UserUrl::IMAGE_ORIGINAL);
                 $file->saveAs($file_path);
                 $paths = [];
                 $paths[] = $file_path;
                 foreach (UserUrl::$IMAGE_SIZE as $key => $size) {
                     if ($key != UserUrl::IMAGE_ORIGINAL) {
                         $image = Yii::$app->image->load($file_path);
                         $type = Yii\image\drivers\Image::HEIGHT;
                         if ($size['width'] > 0 && $size['height'] > 0) {
                             $type = Yii\image\drivers\Image::AUTO;
                         }
                         if ($size['width'] > 0 && $size['height'] == 0) {
                             $type = Yii\image\drivers\Image::WIDTH;
                         }
                         $file_resize_path = UserUrl::styleBackground(false, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, $key);
                         $image->resize($size['width'], $size['height'], $type);
                         $image->save($file_resize_path);
                         $paths[] = $file_resize_path;
                     }
                 }
                 $group['background_image'] = $file_id;
                 $this->data['layouts'][$group_index] = $group;
                 if (!$this->save()) {
                     //Удаляем все файлы если не получилось сохранить
                     if (!empty($result['error'])) {
                         foreach ($paths as $path) {
                             if (file_exists($path)) {
                                 unlink($path);
                             }
                         }
                     }
                     $result = ['error' => ['msg' => Yii::t('app', 'Ошибка записи в базу-данных')]];
                 } else {
                     $result = ['response' => ['status' => true, 'background_image' => UserUrl::styleBackground(true, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, UserUrl::IMAGE_THUMB)]];
                 }
             } else {
                 $result = ['error' => ['msg' => Yii::t('app', 'Данные не получены')]];
             }
         } else {
             $result = ['error' => ['msg' => Yii::t('app', 'Данные не получены')]];
         }
     } else {
         $result = ['error' => ['msg' => Yii::t('app', 'Группа не существует')]];
     }
     return $result;
 }
Ejemplo n.º 3
0
 public static function css($url = false, $user_id = null)
 {
     if (Yii::$app->user->isGuest && $user_id == null) {
         return Yii::getAlias('@web') . '/css';
     }
     if ($user_id == null) {
         $user_id = Yii::$app->user->identity->getId();
     }
     $alpha_id = AlphaId::id($user_id);
     if ($url) {
         $base_url = Yii::getAlias('@web') . '/' . 'uploads';
         return $base_url . '/' . $alpha_id . '/css';
     } else {
         $base_path = Yii::getAlias('@webroot') . DIRECTORY_SEPARATOR . 'uploads';
         return UserUrl::createNonexistentDirInPath($base_path, $alpha_id . DIRECTORY_SEPARATOR . 'css');
     }
 }
Ejemplo n.º 4
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']));
     }
 }
Ejemplo n.º 5
0
 public function changeText($page_index, $text)
 {
     $style = Style::findOne(['id' => $this->style_id, 'delete' => 0]);
     $style->data = json_decode($style->data, true);
     $layouts = $style->data['layouts'];
     $templates = [];
     foreach ($layouts as $key => $layout) {
         foreach ($layout['template_ids'] as $key2 => $template_id) {
             $template = Template::findOne(['id' => $template_id]);
             $data = json_decode($template->json, true);
             if ($template->text_object) {
                 $data_text = json_decode($template->json_text, true);
                 $templates[$template_id] = ['json' => $data, 'json_text' => $data_text, 'count_placeholder' => $template->count_placeholder, 'text_object' => $template->text_object, 'passepartout' => $template->passepartout, 'svg' => $template->svg, 'svg_text' => $template->svg_text, 'pb' => $template->pb];
             } else {
                 $templates[$template_id] = ['json' => $data, 'count_placeholder' => $template->count_placeholder, 'text_object' => $template->text_object, 'passepartout' => $template->passepartout, 'svg' => $template->svg, 'pb' => $template->pb];
             }
         }
     }
     $count_photos = count($this->data['pages'][$page_index]['photos']);
     $template_id = $this->data['pages'][$page_index]['layout']['template_ids']['ph_count_' . $count_photos];
     if (!$templates[$template_id]['text_object']) {
         return ['error' => ['msg' => Yii::t('app', 'Макет не поддерживает текстовый блок')]];
     }
     $page = $this->data['pages'][$page_index];
     if (!empty($page['text']) && $page['text']['text'] != $text || empty($page['text'])) {
         if (!empty($page['text']) && !empty($page['text']['file_id'])) {
             $file_id = $page['text']['file_id'];
             //$file_path=UserUrl::photobookTexts(false, $this->id, $this->user_id ).DIRECTORY_SEPARATOR. UserUrl::imageFile($file_id, UserUrl::IMAGE_ORIGINAL);
             foreach (UserUrl::$IMAGE_SIZE as $key => $size) {
                 $file_delete_path = UserUrl::photobookTexts(false, $this->id, $this->user_id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, $key, 'png');
                 if (file_exists($file_delete_path)) {
                     unlink($file_delete_path);
                 }
             }
         }
         $file_id = AlphaId::id(rand(10000000000, 9999999999999));
         $file_path = UserUrl::photobookTexts(false, $this->id, $this->user_id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, UserUrl::IMAGE_ORIGINAL, 'png');
         $this->data['pages'][$page_index]['text'] = ['text' => $text, 'file_id' => $file_id];
         //$json_text=$templates[$template_id]['json_text'];
     }
     $mapTemplates = $this->getMapTemplates();
     $this->data['pages'][$page_index]['json'] = $this->renderJsonPage($this->data['pages'][$page_index], $mapTemplates, $style);
     $this->data['pages'][$page_index]['svg'] = $this->renderSvgPage($this->data['pages'][$page_index], $mapTemplates, $style);
     $this->data['pages'][$page_index]['svg_thumb'] = $this->renderSvgPage($this->data['pages'][$page_index], $mapTemplates, $style, UserUrl::IMAGE_SMALL);
     if ($this->save()) {
         return ['response' => ['status' => true, 'page' => $this->data['pages'][$page_index]]];
     } else {
         return ['error' => ['msg' => Yii::t('app', 'Не удалось записать в базу-данных')]];
     }
 }
Ejemplo n.º 6
0
" class="btn btn-intro">Пробывать демо</a>
                                <a  href="<?php 
if ($this->params['demo'] == 1) {
    echo Url::toRoute('user/signup-demo');
} else {
    echo '#';
}
?>
" class="btn btn-intro <?php 
if ($this->params['demo'] != 1) {
    echo 'btnAddPhotobook';
}
?>
">Создать альбом</a>
                                <a   href="<?php 
echo Yii::$app->urlManager->createUrl(['photobooks/index', 'ref' => AlphaId::id(Yii::$app->user->identity->getId())]);
?>
" class="btn btn-intro">Мои проекты</a>
                            </div>
                        </div>
                    </div>


            </div>
        </div>





Ejemplo n.º 7
0
 private function saveCss($css)
 {
     $css_file_path = UserUrl::css(false, $this->user_id);
     $css_file_id = rand(10000000000, 99999999999999);
     $css_file_id = AlphaId::id($css_file_id);
     file_put_contents($css_file_path . DIRECTORY_SEPARATOR . $css_file_id . '.css', $css);
     return $css_file_id;
 }
Ejemplo n.º 8
0
 public function actionSettings()
 {
     if (Yii::$app->user->isGuest) {
         $this->redirect(Url::toRoute(['intro/index']));
         return;
     }
     if (Yii::$app->user->identity->role == User::ROLE_DEMO) {
         $this->redirect(Url::toRoute(['user/signup-demo']));
         return;
     }
     $this->layout = 'default';
     $less_content = file_get_contents(Yii::getAlias('@webroot') . DIRECTORY_SEPARATOR . 'less' . DIRECTORY_SEPARATOR . 'pb-color-template.less');
     $model = new UserSettingForm();
     if ($model->load(Yii::$app->request->post(), 'UserSettingForm')) {
         if ($model->validate()) {
             $model->user_id = Yii::$app->user->identity->getId();
             $file = UploadedFile::getInstance($model, 'logo_url');
             if ($file) {
                 if ($file->size !== 0) {
                     $model->logo_url = $file;
                 } else {
                     $model->logo_url = null;
                 }
                 if ($file->size !== 0) {
                     $old_file_id = '';
                     $user_setting = UserSetting::findByUserId($model->user_id);
                     if ($user_setting) {
                         $old_file_id = $user_setting->logo_url;
                     }
                     $file_id = AlphaId::id(rand(10000000000, 9999999999999));
                     $file_path = UserUrl::logo() . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, UserUrl::IMAGE_ORIGINAL, 'png');
                     $file->saveAs($file_path);
                     $image = Yii::$app->image->load($file_path);
                     $image->resize(0, 49, Yii\image\drivers\Image::HEIGHT);
                     $image->save(UserUrl::logo() . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, UserUrl::IMAGE_SMALL, 'png'));
                     $model->logo_url = $file_id;
                     if (!empty($old_file_id)) {
                         if (file_exists(UserUrl::logo() . DIRECTORY_SEPARATOR . UserUrl::imageFile($old_file_id, UserUrl::IMAGE_ORIGINAL, 'png'))) {
                             unlink(UserUrl::logo() . DIRECTORY_SEPARATOR . UserUrl::imageFile($old_file_id, UserUrl::IMAGE_ORIGINAL, 'png'));
                         }
                         if (file_exists(UserUrl::logo() . DIRECTORY_SEPARATOR . UserUrl::imageFile($old_file_id, UserUrl::IMAGE_SMALL, 'png'))) {
                             unlink(UserUrl::logo() . DIRECTORY_SEPARATOR . UserUrl::imageFile($old_file_id, UserUrl::IMAGE_SMALL, 'png'));
                         }
                     }
                 }
             } else {
                 $model->logo_url = null;
             }
             if (Yii::$app->request->post('defaultLogo', 0) == 1) {
                 $model->logo_url = 'default-logo';
             }
             if ($setting = $model->save()) {
                 Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Настройки успешно сохранены.'));
                 return $this->redirect(Url::toRoute('user/settings'));
             }
         }
     } else {
         if (!$model->loadByUserId(Yii::$app->user->identity->getId())) {
         }
     }
     return $this->render('settings', ['model' => $model, 'less_content' => $less_content]);
 }
Ejemplo n.º 9
0
 public function actionImageRotate()
 {
     $result = [];
     $this->layout = 'json';
     $ref = Yii::$app->request->get('ref');
     $id = Yii::$app->request->get('id');
     $photo_id = Yii::$app->request->get('photo_id', '');
     $deg = intval(Yii::$app->request->get('deg', 0));
     $page = Yii::$app->request->get('page', -1);
     $place_num = intval(Yii::$app->request->get('place_num', -1));
     if (!empty($id)) {
         $model = new PhotobookForm();
         $user_id = AlphaId::id($ref, true);
         $pb_id = AlphaId::id($id, true);
         if ($model->loadById($pb_id)) {
             $file_path = UserUrl::photobookPhotos(false, $pb_id, $user_id);
             $paths = [];
             $paths[] = $file_path;
             $ext = 'jpg';
             if ($model->isText($photo_id)) {
                 $ext = 'png';
             }
             $photo_o_path = $file_path . DIRECTORY_SEPARATOR . UserUrl::imageFile($photo_id, UserUrl::IMAGE_ORIGINAL, $ext);
             $image = Yii::$app->image->load($photo_o_path);
             $image->rotate($deg);
             $image->save($photo_o_path);
             foreach (UserUrl::$IMAGE_SIZE as $key => $size) {
                 if ($key != UserUrl::IMAGE_ORIGINAL) {
                     $image = Yii::$app->image->load($photo_o_path);
                     $type = Yii\image\drivers\Image::HEIGHT;
                     if ($size['width'] > 0 && $size['height'] > 0) {
                         $type = Yii\image\drivers\Image::AUTO;
                     }
                     if ($size['width'] > 0 && $size['height'] == 0) {
                         $type = Yii\image\drivers\Image::WIDTH;
                     }
                     $file_resize_path = UserUrl::photobookPhotos(false, $pb_id, $user_id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($photo_id, $key, $ext);
                     $image->resize($size['width'], $size['height'], $type);
                     $image->save($file_resize_path);
                     unset($image);
                     $image = null;
                 }
             }
             if ($page < 0 || $place_num < 0) {
                 $result = ['response' => ['status' => true, 'photo_id' => $photo_id]];
             } else {
                 $result = $model->setImagePosAndScale($page, $place_num, 0, 0, 1);
             }
             $last_modified = filemtime($photo_o_path);
             if (!empty($result['response'])) {
                 $result['response']['photo_id'] = $photo_id;
                 $result['response']['page_index'] = $page;
                 $result['response']['place_num'] = $place_num;
                 $result['response']['last_modified'] = $last_modified;
             }
         } else {
             $result = ['error' => ['msg' => Yii::t('app', 'Фотокнига не найдена')]];
         }
     } else {
         $result = ['error' => ['msg' => Yii::t('app', 'Фотокнига не найдена')]];
     }
     return $this->render('json', ['result' => $result]);
 }
Ejemplo n.º 10
0



                <?php 
}
?>


                <?php 
if ($model->status == Photobook::STATUS_NEW || $model->status == Photobook::STATUS_READY_SENT_TO_CLIENT || $model->status == Photobook::STATUS_WAIT_EDIT_FROM_CUSTOMER) {
    ?>

                    <div class="btn-group" style="" >
                        <a class="btn btn-primary button-2-line "  href="<?php 
    echo Url::toRoute(['photobooks/edit', 'ref' => AlphaId::id($model->user_id), 'id' => AlphaId::id($model->id)]);
    ?>
"  >
                            <div class="button-col button-icon ">
                                <i class="fa fa-edit"></i>
                            </div>
                            <div class="button-col" style="padding-top: 7px;">
                                <?php 
    echo Yii::t('app', 'Редактировать');
    ?>
                            </div>
                        </a>
                    </div>


Ejemplo n.º 11
0
            echo AlphaId::id($order->id);
            ?>
"  >
                                                        <?php 
            echo Yii::t('app', 'Отправить в архив');
            ?>
                                                    </a><br/>

                                                     <?php 
        }
        ?>



                                                    <a class="pull-right tooltips btnPhotobookCopy"  href="#" data-url="<?php 
        echo Url::toRoute(['photobook-api/copy-to-user', 'id' => AlphaId::id($order->id), 'ref' => AlphaId::id($order->user_id), 'user_id' => $order->user_id]);
        ?>
"   >
                                                        <?php 
        echo Yii::t('app', 'Копировать');
        ?>
                                                    </a><br/>




                                                    <?php 
        if ($order->status == Photobook::STATUS_NEW || $order->status == Photobook::STATUS_READY_SENT_TO_CLIENT || $order->status == Photobook::STATUS_WAIT_EDIT_FROM_CUSTOMER) {
            ?>

                                                    <a href="<?php 
Ejemplo n.º 12
0
 public function updateCoverBack()
 {
     //Удаляем старую подложку обложки
     foreach (UserUrl::$IMAGE_SIZE as $image_size => $value) {
         $file_path = UserUrl::coverBack(false, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($this->cover_back, $image_size, 'png');
         if (file_exists($file_path)) {
             unlink($file_path);
         }
     }
     $file = UploadedFile::getInstance($this, 'photo');
     if ($file) {
         if ($file->size !== 0) {
             $file_id = AlphaId::id(rand(10000000000, 9999999999999));
             $file_path = UserUrl::coverBack(false, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, UserUrl::IMAGE_ORIGINAL, 'png');
             $file->saveAs($file_path);
             foreach (UserUrl::$IMAGE_SIZE as $image_size => $param) {
                 if ($image_size == UserUrl::IMAGE_ORIGINAL) {
                     continue;
                 }
                 $image = Yii::$app->image->load($file_path);
                 $type = Yii\image\drivers\Image::WIDTH;
                 $file_resize_path = UserUrl::coverBack(false, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, $image_size, 'png');
                 $image->resize($param['width'], $param['height'], $type);
                 $image->save($file_resize_path);
             }
             $this->cover_back = $file_id;
             if (!$this->save()) {
                 return ['error' => ['msg' => Yii::t('app', 'Ошибка записи в базу-данных')]];
             } else {
                 return ['response' => ['status' => true, 'cover_back' => $file_id, 'cover_back_thumb_url' => UserUrl::coverBack(true, $this->id) . DIRECTORY_SEPARATOR . UserUrl::imageFile($file_id, UserUrl::IMAGE_THUMB, 'png')]];
             }
         } else {
             return ['error' => ['msg' => Yii::t('app', 'Данные не получены')]];
         }
     } else {
         return ['error' => ['msg' => Yii::t('app', 'Данные не получены')]];
     }
 }