Esempio n. 1
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', 'Не удалось записать в базу-данных')]];
     }
 }
Esempio n. 2
0
 public function actionViewSvg()
 {
     $this->layout = 'empty';
     $id = Yii::$app->request->get('id', -1);
     $template = Template::findOne(['id' => $id]);
     if (!$template) {
         Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Макет не найден'));
         $this->redirect(Url::toRoute(['templates/index']));
     }
     $update_flag = false;
     $svg_path = UserUrl::templateThumb(false, $id) . '.svg';
     $png_path = UserUrl::template(false) . DIRECTORY_SEPARATOR . 'thumbs';
     if (!file_exists(UserUrl::templateThumb(false, $id) . '.svg')) {
         $update_flag = true;
     } else {
         $svg_update_time = filectime($svg_path);
         if ($template->updated_at > $svg_update_time) {
             $update_flag = true;
         }
     }
     // $update_flag=true;
     if ($update_flag) {
         $svg = str_replace('fill: transparent;', 'fill-opacity:0;', $template->svg);
         file_put_contents($svg_path, $svg);
         $batik_path = Yii::getAlias('@app') . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'batik' . DIRECTORY_SEPARATOR;
         // $cmds[]="java -d64 -Xms512m -Xmx4g -jar ".$batik_path."batik-rasterizer.jar -m image/jpg -w 350 -h 125 -q 0.99 -dpi 72 -d ".$png_path." ".$svg_path;
         exec("java -d64 -Xms512m -Xmx4g -jar " . $batik_path . "batik-rasterizer-1.8.jar -m image/jpg -w 350 -h 125 -q 0.65 -dpi 72 -d " . $png_path . " " . $svg_path);
     }
     $png = file_get_contents(UserUrl::templateThumb(false, $id) . '.jpg');
     header('Content-type:image/png');
     echo $png;
 }
Esempio n. 3
0
 /**
  * @param bool $insert
  * @return bool
  */
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         /**
          * Очистка старых значений "быстрых" полей
          * при смене шаблона документа.
          */
         if ($this->last_template_id !== $this->template_id) {
             $template = Template::findOne($this->template_id);
             if ($template) {
                 for ($i = 1; $i <= Template::OPTIONS_COUNT; $i++) {
                     $option_type = 'option_' . $i . '_type';
                     $option = 'option_' . $i;
                     if (!$template->{$option_type}) {
                         $this->{$option} = null;
                     }
                 }
             }
         }
         return true;
     }
     return false;
 }
Esempio n. 4
0
 /**
  * Finds the Template model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Template the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Template::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 5
0
 public function actionViewSvg()
 {
     header('Content-type: image/svg+xml');
     $this->layout = 'empty';
     $id = Yii::$app->request->get('id', -1);
     $template = Template::findOne(['id' => $id]);
     if (!$template) {
         Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Макет не найден'));
         $this->redirect(Url::toRoute(['templates/index']));
     }
     echo $template->svg;
     //return $this->render('edit', ['template'=>$template]);
 }
 /**
  * Отображение дополнительных полей
  * Используется при имземении шаблона
  * @return mixed
  */
 public function actionAjaxoptions()
 {
     $id = Yii::$app->request->post('id');
     if ($id) {
         $model = Document::findOne($id);
     } else {
         $model = new Document();
     }
     /**
      * Не используем функцию findModel, т.к.
      * в данном случае важно изменение шаблона
      * перед инициализацией для установления
      * новых дополнительных полей, соотвествующих
      * новому выбранному шаблону
      */
     $model->last_parent_id = $model->parent_id;
     $model->last_template_id = $model->template_id;
     $model->template_id = Yii::$app->request->post('template_id');
     $model->initialization();
     $template = Template::findOne($model->template_id);
     $empty_value = $model->last_template_id != $model->template_id ? true : false;
     return $this->renderAjax('_options_fields', ['model' => $model, 'template' => $template, 'empty_value' => $empty_value]);
 }
Esempio n. 7
0
/* @var $this yii\web\View */
/* @var $model common\models\Option */
$this->title = 'Создание опции';
?>
<div class="option-create">

    <div class="box box-panel">
        <div class="box-header with-border">
            <h3 class="box-title">
                <i class="glyphicon glyphicon-th-list"></i> <?php 
echo Html::a('Шаблоны', ['/template']);
?>
 →
                <?php 
if ($model->template_id) {
    $template = Template::findOne($model->template_id);
    /** @var \common\models\Template $template  */
    if ($template) {
        echo Html::a($template->name, ['/template/update', 'id' => $template->id]) . " →";
    }
}
?>
                Создание дополнительного поля
            </h3>
            <div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" data-widget="collapse">
                    <i class="glyphicon glyphicon-minus"></i>
                </button>
            </div>
        </div>
        <div class="box-body">
 public function actionPublish()
 {
     //$result=[];
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $id = Yii::$app->request->get('id', 0);
     $publish = Yii::$app->request->post('publish', 0);
     if (\Yii::$app->user->isGuest) {
         return ['error' => ['msg' => Yii::t('app', 'Ошибка авторизации.')]];
     }
     if (\Yii::$app->user->identity->role != \common\models\User::ROLE_ADMIN) {
         return ['error' => ['msg' => Yii::t('app', 'Необходимы права администратора.')]];
     }
     $template = Template::findOne(['id' => $id]);
     if (!$template) {
         return ['error' => ['msg' => Yii::t('app', 'Шаблон не найден.')]];
     }
     $template->id = $id;
     $template->publish = $publish;
     if (!$template->update(false)) {
         return ['error' => ['msg' => Yii::t('app', 'Ошибка сохранения шаблона.')]];
     } else {
         return ['response' => ['status' => true]];
     }
 }