completion of the document module

This commit is contained in:
iIronside
2022-01-10 15:22:51 +03:00
parent d31a4757ff
commit 9cabf3e7f8
17 changed files with 2409 additions and 146 deletions

View File

@ -2,10 +2,6 @@
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;
@ -148,66 +144,8 @@ class DocumentController extends Controller
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);
$documentService = new DocumentService($id);
$documentService->setFields();
$documentService->downloadDocument();
}
}

View File

@ -2,7 +2,6 @@
namespace backend\modules\document\controllers;
use backend\modules\document\models\TemplateDocumentField;
use Yii;
use backend\modules\document\models\Template;
use backend\modules\document\models\TemplateSearch;
@ -59,7 +58,6 @@ class TemplateController extends Controller
public function actionView($id)
{
$model = $this->findModel($id);
$templateDocumentField = new TemplateDocumentField();
$templateFieldDataProvider = new ActiveDataProvider([
'query' => $model->getTemplateDocumentFields(),
'pagination' => [
@ -83,8 +81,21 @@ class TemplateController extends Controller
{
$model = new Template();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['template-document-field/create', 'template_id' => $model->id]);
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]);
}
}
return $this->render('create', [
@ -92,22 +103,66 @@ class TemplateController extends Controller
]);
}
/**
* Updates an existing Template model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
// /**
// * Updates an existing Template model.
// * If update is successful, the browser will be redirected to the 'view' page.
// * @param integer $id
// * @return mixed
// * @throws NotFoundHttpException if the model cannot be found
// */
// public function actionUpdate($id)
// {
// $model = $this->findModel($id);
//
// if ($model->load(Yii::$app->request->post()) && $model->save()) {
// return $this->redirect(['view', 'id' => $model->id]);
// }
//
// return $this->render('update', [
// 'model' => $model,
// ]);
// }
public function actionUpdateTitle($id)
{
$model = $this->findModel($id);
$model->scenario = Template::SCENARIO_UPDATE_TITLE;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
return $this->render('_form_update_title', [
'model' => $model,
]);
}
public function actionUpdateFile($id)
{
$model = $this->findModel($id);
$model->scenario = Template::SCENARIO_UPDATE_FILE;
if ($model->load(Yii::$app->request->post())) {
$model->template = UploadedFile::getInstance($model, 'template');
if (!empty($model->template)) {
$pathToTemplates = Yii::getAlias('@templates');
unlink($pathToTemplates . '/' . $model->template_file_name);
$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(['view', 'id' => $model->id]);
}
return $this->render('_form_update_file', ['model' => $model]);
}
}
return $this->render('_form_update_file', [
'model' => $model,
]);
}

View File

@ -1,6 +1,7 @@
<?php
use yii\grid\GridView;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\widgets\DetailView;
@ -34,11 +35,25 @@ $this->params['breadcrumbs'][] = $this->title;
'title',
'created_at',
'updated_at',
'template_id',
'manager_id',
[
'attribute' => 'template_id',
'value' => ArrayHelper::getValue($model,'template.title'),
],
[
'attribute' => 'manager_id',
'value' => ArrayHelper::getValue($model,'manager.userCard.fio')
],
],
]) ?>
<p>
<?= Html::a(
'Скачать файл',
['document/create-document', 'id' => $model->id],
['class' => 'btn btn-primary']
) ?>
</p>
<div>
<h2>
<?= 'Поля документа:'?>
@ -91,12 +106,4 @@ $this->params['breadcrumbs'][] = $this->title;
) ?>
</p>
<p>
<?= Html::a(
'Файл',
['document/create-document', 'id' => $model->id],
['class' => 'btn btn-primary']
) ?>
</p>
</div>

View File

@ -1,5 +1,6 @@
<?php
use kartik\file\FileInput;
use mihaildev\elfinder\InputFile;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
@ -16,20 +17,12 @@ use yii\widgets\ActiveForm;
<?= $form->field($model, 'title')->textInput(['maxlength' => 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' => 'Выбрать шаблон',
]);?>
<?= $form->field($model, 'template')->widget(FileInput::classname(), [
'options' => ['accept' => 'text/*'],
'pluginOptions' => [
'allowedFileExtensions'=>['docx'],'showUpload' => true
],
]); ?>
<div class="form-group">
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>

View File

@ -0,0 +1,30 @@
<?php
use kartik\file\FileInput;
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, 'template')->widget(FileInput::classname(), [
'options' => ['accept' => 'text/*'],
'pluginOptions' => [
'allowedFileExtensions'=>['docx'],'showUpload' => true
],
]); ?>
<div class="form-group">
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,24 @@
<?php
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]) ?>
<div class="form-group">
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -23,11 +23,14 @@ $this->params['breadcrumbs'][] = $this->title;
['class' => 'yii\grid\SerialColumn'],
'title',
// 'template_path',
'created_at',
'updated_at',
['class' => 'yii\grid\ActionColumn'],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{view} {delete}',
],
],
]); ?>
</div>

View File

@ -29,7 +29,6 @@ function cut_title($str)
<p>
<?= Html::a('Список', ['index', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Изменить', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Удалить', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
@ -44,7 +43,17 @@ function cut_title($str)
'attributes' => [
'id',
'title',
[
'label'=>'title',
'format'=>'raw',
'value' => function($model){
return $model->title . Html::a(' <i class="glyphicon glyphicon-pencil"></i>',
Url::to(['template/update-title', 'id' => $model->id]), [
'title' => 'update-title',
// 'class' => 'pull-right detail-button',
]);
}
],
'created_at',
'updated_at',
[
@ -52,8 +61,8 @@ function cut_title($str)
'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',
Url::to(['template/update-file', 'id' => $model->id]), [
'title' => 'update-file',
// 'class' => 'pull-right detail-button',
]);
}