intermediate commit
This commit is contained in:
@ -2,6 +2,10 @@
|
||||
|
||||
namespace backend\modules\document\controllers;
|
||||
|
||||
use common\models\DocumentField;
|
||||
use PhpOffice\PhpWord\PhpWord;
|
||||
use PhpOffice\PhpWord\Shared\ZipArchive;
|
||||
use PhpOffice\PhpWord\TemplateProcessor;
|
||||
use Yii;
|
||||
use backend\modules\document\models\Document;
|
||||
use backend\modules\document\models\DocumentSearch;
|
||||
@ -10,6 +14,8 @@ use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
|
||||
use common\services\DocumentService;
|
||||
|
||||
/**
|
||||
* DocumentController implements the CRUD actions for Document model.
|
||||
*/
|
||||
@ -138,4 +144,70 @@ class DocumentController extends Controller
|
||||
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
|
||||
|
||||
public function actionCreateDocument($id)
|
||||
{
|
||||
$model = Document::findOne($id);
|
||||
|
||||
$file_title = $model->title;
|
||||
$template_title = $model->template->template_file_name;
|
||||
|
||||
|
||||
|
||||
$fieldaValueArr = $model->documentFieldValues;
|
||||
|
||||
foreach ($fieldaValueArr as $tmp) {
|
||||
echo $tmp['value'];
|
||||
}
|
||||
|
||||
die();
|
||||
|
||||
|
||||
// var_dump($file_title);
|
||||
// var_dump($template_title);
|
||||
// var_dump($fieldsArray);
|
||||
// die;
|
||||
// //, $template_name, [] $fields
|
||||
|
||||
|
||||
$documentService = new DocumentService($file_title, $template_title, $fieldsArray);
|
||||
$documentService->save();
|
||||
|
||||
|
||||
// $outputFile = 'review_full222.docx';
|
||||
//
|
||||
//
|
||||
// $PhpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||
// $document = $PhpWord->loadTemplate('/var/www/guild.loc/backend/web/upload/templates/tets template.docx'); //шаблон
|
||||
// $document->setValue('FIO', '8888888888' );
|
||||
// $document->setValue('INN', '999999999999999999');
|
||||
//
|
||||
// $document->saveAs($outputFile);
|
||||
//
|
||||
// // Имя скачиваемого файла
|
||||
// $downloadFile = $outputFile;
|
||||
//
|
||||
// // Контент-тип означающий скачивание
|
||||
// header("Content-Type: application/octet-stream");
|
||||
//
|
||||
// // Размер в байтах
|
||||
// header("Accept-Ranges: bytes");
|
||||
//
|
||||
// // Размер файла
|
||||
// header("Content-Length: ".filesize($downloadFile));
|
||||
//
|
||||
// // Расположение скачиваемого файла
|
||||
// header("Content-Disposition: attachment; filename=".$downloadFile);
|
||||
//
|
||||
// // Прочитать файл
|
||||
// readfile($downloadFile);
|
||||
//
|
||||
//
|
||||
//
|
||||
// unlink($outputFile);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace backend\modules\document\controllers;
|
||||
|
||||
use common\helpers\TransliteratorHelper;
|
||||
use Yii;
|
||||
use backend\modules\document\models\DocumentField;
|
||||
use backend\modules\document\models\DocumentFieldSearch;
|
||||
|
@ -83,21 +83,8 @@ class TemplateController extends Controller
|
||||
{
|
||||
$model = new Template();
|
||||
|
||||
if ($model->load(Yii::$app->request->post())) {
|
||||
$model->template = UploadedFile::getInstance($model, 'template');
|
||||
|
||||
if (!empty($model->template)) {
|
||||
$pathToTemplates = Yii::getAlias('@templates');
|
||||
$model->template_file_name = date('mdyHis') . '_' . $model->template->name;
|
||||
|
||||
if ($model->save()) {
|
||||
if (FileHelper::createDirectory($pathToTemplates, $mode = 0775, $recursive = true)) {
|
||||
$model->template->saveAs($pathToTemplates . '/' . $model->template_file_name);
|
||||
}
|
||||
return $this->redirect(['template-document-field/create', 'template_id' => $model->id]);
|
||||
}
|
||||
return $this->render('create', ['model' => $model]);
|
||||
}
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['template-document-field/create', 'template_id' => $model->id]);
|
||||
}
|
||||
|
||||
return $this->render('create', [
|
||||
@ -115,34 +102,11 @@ class TemplateController extends Controller
|
||||
public function actionUpdate($id)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
// $pathToFile = Yii::getAlias('@templates') . '/' . $model->template_file_name;
|
||||
|
||||
// if ($model->load(Yii::$app->request->post())) {
|
||||
// $template = UploadedFile::getInstance($model, 'template');
|
||||
//
|
||||
// if (!empty($template)) {
|
||||
// $path = Yii::getAlias('@frontend') . '/web/upload/documents/templates';
|
||||
//
|
||||
// $model->template = $template;
|
||||
// $model->template_file_name = $model->template->name;
|
||||
// $model->template_path = $path . '/' . $model->template->name;
|
||||
//
|
||||
// if (!$model->template->saveAs($path . '/' . $model->template->name)) {
|
||||
// return $this->render('update', [
|
||||
// 'model' => $model,
|
||||
// ]);
|
||||
// }
|
||||
// }
|
||||
// if ($model->save()) {
|
||||
// return $this->redirect(['view', 'id' => $model->id]);
|
||||
// }
|
||||
// }
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
// $model->template = UploadedFile::getInstance($model, $pathToFile); // file($pathToFile);
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
]);
|
||||
|
@ -18,7 +18,7 @@ class DocumentFieldSearch extends DocumentField
|
||||
{
|
||||
return [
|
||||
[['id'], 'integer'],
|
||||
[['title'], 'safe'],
|
||||
[['title', 'field_template'], 'safe'],
|
||||
];
|
||||
}
|
||||
|
||||
@ -61,7 +61,8 @@ class DocumentFieldSearch extends DocumentField
|
||||
'id' => $this->id,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'title', $this->title]);
|
||||
$query->andFilterWhere(['like', 'title', $this->title])
|
||||
->andFilterWhere(['like', 'field_template', $this->field_template]);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ use yii\widgets\ActiveForm;
|
||||
|
||||
<?= $form->field($model, 'title') ?>
|
||||
|
||||
<?= $form->field($model, 'field_template') ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
|
||||
|
@ -12,8 +12,10 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="document-field-index">
|
||||
|
||||
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
|
||||
|
||||
<p>
|
||||
<?= Html::a('Создать поле документа', ['create'], ['class' => 'btn btn-success']) ?>
|
||||
<?= Html::a('Создать новое поле', ['create'], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
|
||||
<?= GridView::widget([
|
||||
@ -23,6 +25,12 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
['class' => 'yii\grid\SerialColumn'],
|
||||
|
||||
'title',
|
||||
[
|
||||
'attribute' => 'field_template',
|
||||
'value' => function($model) {
|
||||
return '${' . $model->field_template . '}';
|
||||
},
|
||||
],
|
||||
|
||||
['class' => 'yii\grid\ActionColumn'],
|
||||
],
|
||||
|
@ -30,6 +30,10 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'attributes' => [
|
||||
'id',
|
||||
'title',
|
||||
[
|
||||
'attribute' => 'field_template',
|
||||
'value' => '${' . $model->field_template . '}',
|
||||
],
|
||||
],
|
||||
]) ?>
|
||||
|
||||
|
@ -91,4 +91,12 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
) ?>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<?= Html::a(
|
||||
'Файл',
|
||||
['document/create-document', 'id' => $model->id],
|
||||
['class' => 'btn btn-primary']
|
||||
) ?>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
|
@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
use kartik\file\FileInput;
|
||||
use mihaildev\elfinder\InputFile;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
@ -17,12 +16,20 @@ use yii\widgets\ActiveForm;
|
||||
|
||||
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'template')->widget(FileInput::classname(), [
|
||||
'options' => ['accept' => 'text/*'],
|
||||
'pluginOptions' => [
|
||||
'allowedFileExtensions'=>['doc','docx','txt'],'showUpload' => true
|
||||
],
|
||||
]); ?>
|
||||
<?= InputFile::widget([
|
||||
'language' => 'ru',
|
||||
'controller' => 'elfinder',
|
||||
// вставляем название контроллера, по умолчанию равен elfinder
|
||||
//'filter' => ['image', 'application/zip', 'application/csv', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'],
|
||||
// фильтр файлов, можно задать массив фильтров https://github.com/Studio-42/elFinder/wiki/Client-con..
|
||||
'name' => 'Template[template_file_name]',
|
||||
'id' => 'template-doc',
|
||||
'template' => '<label>Шаблон</label><div class="input-group">{input}<span class="span-btn">{button}</span></div>',
|
||||
'options' => ['class' => 'form-control', 'maxlength' => '255'],
|
||||
'buttonOptions' => ['class' => 'btn btn-primary'],
|
||||
'value' => $model->template_file_name,
|
||||
'buttonName' => 'Выбрать шаблон',
|
||||
]);?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
|
||||
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
use kartik\file\FileInput;
|
||||
use mihaildev\elfinder\InputFile;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\document\models\Template */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div class="template-form">
|
||||
|
||||
<?php $form = ActiveForm::begin([
|
||||
'options' => ['enctype'=>'multipart/form-data']]); ?>
|
||||
|
||||
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'template')->widget(FileInput::classname(), [
|
||||
'options' => ['accept' => 'text/*'],
|
||||
'pluginOptions' => [
|
||||
'allowedFileExtensions'=>['doc','docx','txt'],'showUpload' => true
|
||||
],
|
||||
]); ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
@ -5,10 +5,18 @@ use yii\helpers\Html;
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\document\models\Template */
|
||||
|
||||
$this->title = 'Изменить шаблон: ' . $model->title;
|
||||
$this->title = 'Изменить шаблон: ' . cut_title($model->title);
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Templates', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]];
|
||||
$this->params['breadcrumbs'][] = 'Update';
|
||||
|
||||
function cut_title($str)
|
||||
{
|
||||
if(strlen($str) > 35){
|
||||
return mb_substr($str, 0, 25, 'UTF-8') . '...';
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
?>
|
||||
<div class="template-update">
|
||||
|
||||
|
@ -11,11 +11,20 @@ use yii\grid\GridView;
|
||||
/* @var $templateFieldDataProvider yii\data\ActiveDataProvider */
|
||||
/* @var $model backend\modules\document\models\Template */
|
||||
|
||||
$this->title = $model->title;
|
||||
$this->title = cut_title($model->title);
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Templates', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
YiiAsset::register($this);
|
||||
|
||||
function cut_title($str)
|
||||
{
|
||||
if(strlen($str) > 35){
|
||||
return mb_substr($str, 0, 35, 'UTF-8') . '...';
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="template-view">
|
||||
|
||||
<p>
|
||||
@ -35,34 +44,19 @@ YiiAsset::register($this);
|
||||
|
||||
'attributes' => [
|
||||
'id',
|
||||
[
|
||||
'attribute'=>'title',
|
||||
'format'=>'raw',
|
||||
'value' => function($model){
|
||||
return $model->title . Html::a(
|
||||
'<i class="glyphicon glyphicon-pencil"></i>', ['update', 'id' => $model->id],
|
||||
[
|
||||
'title' => 'Update',
|
||||
'class' => 'pull-right detail-button',
|
||||
]
|
||||
);
|
||||
}
|
||||
],
|
||||
'title',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
|
||||
[
|
||||
'label'=>'template_file_name',
|
||||
'format'=>'raw',
|
||||
'value' => function($model){
|
||||
|
||||
return $model->template_file_name . Html::a('<i class="glyphicon glyphicon-pencil"></i>', Url::to(['actualizar', 'id' => $model->id]), [
|
||||
'title' => 'Actualizar',
|
||||
// 'class' => 'pull-right detail-button',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
'label'=>'template_file_name',
|
||||
'format'=>'raw',
|
||||
'value' => function($model){
|
||||
return $model->template_file_name . Html::a(' <i class="glyphicon glyphicon-pencil"></i>',
|
||||
Url::to(['actualizar', 'id' => $model->id]), [
|
||||
'title' => 'Actualizar',
|
||||
// 'class' => 'pull-right detail-button',
|
||||
]);
|
||||
}
|
||||
]
|
||||
],
|
||||
]) ?>
|
||||
@ -95,9 +89,13 @@ YiiAsset::register($this);
|
||||
|
||||
[
|
||||
'attribute' => 'field_id',
|
||||
'filter' => DocumentField::find()->select(['title', 'id'])->indexBy('id')->column(),
|
||||
'value' => 'field.title',
|
||||
],
|
||||
[
|
||||
'attribute' => 'field.field_template',
|
||||
'value' => 'field.field_template',
|
||||
],
|
||||
|
||||
[
|
||||
'class' => 'yii\grid\ActionColumn',
|
||||
'template' => '{view}{delete}',
|
||||
|
@ -4,6 +4,7 @@ use backend\modules\questionnaire\models\Questionnaire;
|
||||
use backend\modules\questionnaire\models\QuestionType;
|
||||
use common\helpers\StatusHelper;
|
||||
use common\helpers\TimeHelper;
|
||||
use common\helpers\TransliteratorHelper;
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
use backend\modules\questionnaire\models\QuestionnaireCategory;
|
||||
use common\helpers\StatusHelper;
|
||||
use common\helpers\TimeHelper;
|
||||
use common\helpers\TransliteratorHelper;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
|
Reference in New Issue
Block a user