/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $this->scenario = 'search'; $query = Template::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'path', $this->path]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Template::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
public static function GenerateRandomLayout($num = 1) { $data = ['label' => Yii::t('app', 'Группа макетов {num}', ['num' => $num]), 'background_color' => '#FFFFFF', 'background_image' => null, 'template_ids' => []]; $templates = Template::find()->orderBy(['count_placeholder' => SORT_DESC])->all(); if (!empty($templates)) { Yii::getLogger()->log('tmple:' . print_r($templates, true), YII_DEBUG); $max_count_placeholder = $templates[0]->count_placeholder; for ($i = 1; $i <= $max_count_placeholder; $i++) { $templates = Template::find()->where(['count_placeholder' => $i])->all(); $index = rand(0, count($templates) - 1); $data['template_ids']['ph_count_' . $i] = $templates[$index]->id; } return $data; } else { return $data; } }
/** * 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.'); } }
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', 'Не удалось записать в базу-данных')]]; } }
<?php for ($i = 1; $i <= Template::OPTIONS_COUNT; $i++) { ?> <div class="row hidden-block" id="ex-<?php echo $i; ?> "> <div class="col-sm-3"> <?php echo $form->field($model, 'option_' . $i . '_name')->textInput(['maxlength' => true]); ?> </div> <div class="col-sm-3"> <?php echo $form->field($model, 'option_' . $i . '_type')->dropDownList([''] + Template::getTypesField(), ['class' => 'ex-field-type form-control']); ?> </div> <div class="col-sm-3"> <?php echo $form->field($model, 'option_' . $i . '_param')->textInput(['maxlength' => true]); ?> </div> <div class="col-sm-3"> <?php echo $form->field($model, 'option_' . $i . '_require')->widget(SwitchInput::classname(), ['pluginOptions' => ['onText' => 'Да', 'offText' => 'Нет']]); ?> </div> </div> <?php }
/** * @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; }
/** * @return \yii\db\ActiveQuery */ public function getTemplate() { return $this->hasOne(Template::className(), array('id' => 'template_id')); }
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; }
} else { $class_require = 'form-group hidden-block'; $class_is_reqire = 'form-group'; } ?> <div class="row"> <div class="col-sm-6"> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> </div> <div class="col-sm-6"> <?php echo $form->field($model, 'template_id')->dropDownList(Template::getAll()); ?> </div> </div> <div class="row"> <div class="col-sm-6"> <?php echo $form->field($model, 'type')->dropDownList(Option::getTypesField()); ?> </div> <div class="col-sm-6"> <?php echo $form->field($model, 'param')->textInput(['maxlength' => true]); ?> </div>
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]]; } }
/** * @return array */ public static function getAll() { $templates = []; $model = Template::find()->all(); if ($model) { foreach ($model as $m) { $templates[$m->id] = $m->name . " (" . $m->id . ")"; } } return $templates; }
</div> <div class="col-sm-6"> <?php echo $form->field($model, 'alias', ['addon' => ['append' => ['content' => ButtonDropdown::widget(['label' => 'Сформировать', 'dropdown' => ['items' => [['label' => 'Из названия', 'url' => '#', 'options' => ['class' => 'translate-name']], ['label' => 'Из заголовка', 'url' => '#', 'options' => ['class' => 'translate-title']]]], 'options' => ['class' => 'btn-default']]), 'asButton' => true], 'groupOptions' => ['id' => 'aliast-btn']]]); ?> </div> </div> <div class="row"> <div class="col-sm-6"> <?php echo $form->field($model, 'parent_id')->widget(Select2::classname(), ['language' => 'ru', 'data' => Document::getAll(), 'options' => ['placeholder' => ''], 'pluginOptions' => ['allowClear' => true]]); ?> </div> <div class="col-sm-6"> <?php echo $form->field($model, 'template_id')->widget(Select2::classname(), ['language' => 'ru', 'data' => Template::getAll(), 'options' => ['placeholder' => '', 'class' => 'template_id'], 'pluginOptions' => ['allowClear' => true]]); ?> </div> </div> <div class="row"> <div class="col-sm-6"> <?php echo $form->field($model, 'meta_description')->textarea(['maxlength' => true]); ?> </div> <div class="col-sm-6"> <?php echo $form->field($model, 'meta_keywords')->textarea(['maxlength' => true]); ?> </div> </div>
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]); }
/** * @return \yii\db\ActiveQuery */ public function getTemplate() { return $this->hasOne(Template::className(), ['id' => 'template']); }
/* @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">