intermediate commit

This commit is contained in:
iIronside 2022-01-07 15:04:11 +03:00
parent e16e72dcc1
commit d31a4757ff
32 changed files with 5163 additions and 270 deletions

View File

@ -78,7 +78,7 @@ return [
'components' => [ 'components' => [
'request' => [ 'request' => [
'csrfParam' => '_csrf-backend', 'csrfParam' => '_csrf-backend',
'baseUrl' => '/secure', 'baseUrl' => '', // /secure
'parsers' => [ 'parsers' => [
'application/json' => 'yii\web\JsonParser', 'application/json' => 'yii\web\JsonParser',
'text/xml' => 'yii/web/XmlParser', 'text/xml' => 'yii/web/XmlParser',

View File

@ -2,6 +2,10 @@
namespace backend\modules\document\controllers; 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 Yii;
use backend\modules\document\models\Document; use backend\modules\document\models\Document;
use backend\modules\document\models\DocumentSearch; use backend\modules\document\models\DocumentSearch;
@ -10,6 +14,8 @@ use yii\web\Controller;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use common\services\DocumentService;
/** /**
* DocumentController implements the CRUD actions for Document model. * 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.'); 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);
}
} }

View File

@ -2,6 +2,7 @@
namespace backend\modules\document\controllers; namespace backend\modules\document\controllers;
use common\helpers\TransliteratorHelper;
use Yii; use Yii;
use backend\modules\document\models\DocumentField; use backend\modules\document\models\DocumentField;
use backend\modules\document\models\DocumentFieldSearch; use backend\modules\document\models\DocumentFieldSearch;

View File

@ -83,21 +83,8 @@ class TemplateController extends Controller
{ {
$model = new Template(); $model = new Template();
if ($model->load(Yii::$app->request->post())) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->template = UploadedFile::getInstance($model, 'template'); return $this->redirect(['template-document-field/create', 'template_id' => $model->id]);
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', [ return $this->render('create', [
@ -115,34 +102,11 @@ class TemplateController extends Controller
public function actionUpdate($id) public function actionUpdate($id)
{ {
$model = $this->findModel($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()) { if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]); return $this->redirect(['view', 'id' => $model->id]);
} }
// $model->template = UploadedFile::getInstance($model, $pathToFile); // file($pathToFile);
return $this->render('update', [ return $this->render('update', [
'model' => $model, 'model' => $model,
]); ]);

View File

@ -18,7 +18,7 @@ class DocumentFieldSearch extends DocumentField
{ {
return [ return [
[['id'], 'integer'], [['id'], 'integer'],
[['title'], 'safe'], [['title', 'field_template'], 'safe'],
]; ];
} }
@ -61,7 +61,8 @@ class DocumentFieldSearch extends DocumentField
'id' => $this->id, 'id' => $this->id,
]); ]);
$query->andFilterWhere(['like', 'title', $this->title]); $query->andFilterWhere(['like', 'title', $this->title])
->andFilterWhere(['like', 'field_template', $this->field_template]);
return $dataProvider; return $dataProvider;
} }

View File

@ -19,6 +19,8 @@ use yii\widgets\ActiveForm;
<?= $form->field($model, 'title') ?> <?= $form->field($model, 'title') ?>
<?= $form->field($model, 'field_template') ?>
<div class="form-group"> <div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?> <?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?> <?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>

View File

@ -12,8 +12,10 @@ $this->params['breadcrumbs'][] = $this->title;
?> ?>
<div class="document-field-index"> <div class="document-field-index">
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p> <p>
<?= Html::a('Создать поле документа', ['create'], ['class' => 'btn btn-success']) ?> <?= Html::a('Создать новое поле', ['create'], ['class' => 'btn btn-success']) ?>
</p> </p>
<?= GridView::widget([ <?= GridView::widget([
@ -23,6 +25,12 @@ $this->params['breadcrumbs'][] = $this->title;
['class' => 'yii\grid\SerialColumn'], ['class' => 'yii\grid\SerialColumn'],
'title', 'title',
[
'attribute' => 'field_template',
'value' => function($model) {
return '${' . $model->field_template . '}';
},
],
['class' => 'yii\grid\ActionColumn'], ['class' => 'yii\grid\ActionColumn'],
], ],

View File

@ -30,6 +30,10 @@ $this->params['breadcrumbs'][] = $this->title;
'attributes' => [ 'attributes' => [
'id', 'id',
'title', 'title',
[
'attribute' => 'field_template',
'value' => '${' . $model->field_template . '}',
],
], ],
]) ?> ]) ?>

View File

@ -91,4 +91,12 @@ $this->params['breadcrumbs'][] = $this->title;
) ?> ) ?>
</p> </p>
<p>
<?= Html::a(
'Файл',
['document/create-document', 'id' => $model->id],
['class' => 'btn btn-primary']
) ?>
</p>
</div> </div>

View File

@ -1,6 +1,5 @@
<?php <?php
use kartik\file\FileInput;
use mihaildev\elfinder\InputFile; use mihaildev\elfinder\InputFile;
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
@ -17,12 +16,20 @@ use yii\widgets\ActiveForm;
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'template')->widget(FileInput::classname(), [ <?= InputFile::widget([
'options' => ['accept' => 'text/*'], 'language' => 'ru',
'pluginOptions' => [ 'controller' => 'elfinder',
'allowedFileExtensions'=>['doc','docx','txt'],'showUpload' => true // вставляем название контроллера, по умолчанию равен 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"> <div class="form-group">
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?> <?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>

View File

@ -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>

View File

@ -5,10 +5,18 @@ use yii\helpers\Html;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $model backend\modules\document\models\Template */ /* @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' => 'Templates', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]]; $this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Update'; $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"> <div class="template-update">

View File

@ -11,11 +11,20 @@ use yii\grid\GridView;
/* @var $templateFieldDataProvider yii\data\ActiveDataProvider */ /* @var $templateFieldDataProvider yii\data\ActiveDataProvider */
/* @var $model backend\modules\document\models\Template */ /* @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' => 'Templates', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
YiiAsset::register($this); 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"> <div class="template-view">
<p> <p>
@ -35,34 +44,19 @@ YiiAsset::register($this);
'attributes' => [ 'attributes' => [
'id', 'id',
[ 'title',
'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',
]
);
}
],
'created_at', 'created_at',
'updated_at', 'updated_at',
[ [
'label'=>'template_file_name', 'label'=>'template_file_name',
'format'=>'raw', 'format'=>'raw',
'value' => function($model){ 'value' => function($model){
return $model->template_file_name . Html::a(' <i class="glyphicon glyphicon-pencil"></i>',
return $model->template_file_name . Html::a('<i class="glyphicon glyphicon-pencil"></i>', Url::to(['actualizar', 'id' => $model->id]), [ Url::to(['actualizar', 'id' => $model->id]), [
'title' => 'Actualizar', 'title' => 'Actualizar',
// 'class' => 'pull-right detail-button', // 'class' => 'pull-right detail-button',
]); ]);
} }
] ]
], ],
]) ?> ]) ?>
@ -95,9 +89,13 @@ YiiAsset::register($this);
[ [
'attribute' => 'field_id', 'attribute' => 'field_id',
'filter' => DocumentField::find()->select(['title', 'id'])->indexBy('id')->column(),
'value' => 'field.title', 'value' => 'field.title',
], ],
[
'attribute' => 'field.field_template',
'value' => 'field.field_template',
],
[ [
'class' => 'yii\grid\ActionColumn', 'class' => 'yii\grid\ActionColumn',
'template' => '{view}{delete}', 'template' => '{view}{delete}',

View File

@ -4,6 +4,7 @@ use backend\modules\questionnaire\models\Questionnaire;
use backend\modules\questionnaire\models\QuestionType; use backend\modules\questionnaire\models\QuestionType;
use common\helpers\StatusHelper; use common\helpers\StatusHelper;
use common\helpers\TimeHelper; use common\helpers\TimeHelper;
use common\helpers\TransliteratorHelper;
use yii\helpers\Html; use yii\helpers\Html;
use yii\grid\GridView; use yii\grid\GridView;

View File

@ -3,6 +3,7 @@
use backend\modules\questionnaire\models\QuestionnaireCategory; use backend\modules\questionnaire\models\QuestionnaireCategory;
use common\helpers\StatusHelper; use common\helpers\StatusHelper;
use common\helpers\TimeHelper; use common\helpers\TimeHelper;
use common\helpers\TransliteratorHelper;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use yii\helpers\Html; use yii\helpers\Html;
use yii\grid\GridView; use yii\grid\GridView;

View File

@ -27,7 +27,7 @@
['label' => 'Должность', 'icon' => 'spotify', 'url' => ['/settings/position'], 'active' => \Yii::$app->controller->id == 'position'], ['label' => 'Должность', 'icon' => 'spotify', 'url' => ['/settings/position'], 'active' => \Yii::$app->controller->id == 'position'],
['label' => 'Навыки', 'icon' => 'flask', 'url' => ['/settings/skill'], 'active' => \Yii::$app->controller->id == 'skill'], ['label' => 'Навыки', 'icon' => 'flask', 'url' => ['/settings/skill'], 'active' => \Yii::$app->controller->id == 'skill'],
], ],
'visible' => Yii::$app->user->can('confidential_information') //TODO 'visible' => Yii::$app->user->can('confidential_information')
], ],
[ [
'label' => 'Профили', 'icon' => 'address-book-o', 'url' => '#', 'active' => \Yii::$app->controller->id == 'user-card', 'label' => 'Профили', 'icon' => 'address-book-o', 'url' => '#', 'active' => \Yii::$app->controller->id == 'user-card',
@ -39,7 +39,7 @@
['label' => 'Менеджеры', 'icon' => 'user-circle-o', 'url' => ['/employee/manager'], 'active' => \Yii::$app->controller->id == 'manager'], ['label' => 'Менеджеры', 'icon' => 'user-circle-o', 'url' => ['/employee/manager'], 'active' => \Yii::$app->controller->id == 'manager'],
['label' => 'Работники', 'icon' => 'user', 'url' => ['/employee/manager-employee'], 'active' => \Yii::$app->controller->id == 'manager-employee'], ['label' => 'Работники', 'icon' => 'user', 'url' => ['/employee/manager-employee'], 'active' => \Yii::$app->controller->id == 'manager-employee'],
], ],
'visible' => Yii::$app->user->can('confidential_information') //TODO 'visible' => Yii::$app->user->can('confidential_information')
], ],
[ [
'label' => 'Документы', 'icon' => 'archive', 'url' => '#', 'label' => 'Документы', 'icon' => 'archive', 'url' => '#',
@ -56,12 +56,12 @@
] ]
] ]
], ],
'visible' => Yii::$app->user->can('confidential_information') //TODO 'visible' => Yii::$app->user->can('confidential_information')
], ],
[ [
'label' => 'Проекты', 'icon' => 'cubes', 'url' => ['#'], //'active' => \Yii::$app->controller->id == 'project', 'label' => 'Проекты', 'icon' => 'cubes', 'url' => ['#'], //'active' => \Yii::$app->controller->id == 'project',
'items' => $projectItems, 'items' => $projectItems,
'visible' => Yii::$app->user->can('confidential_information') //TODO 'visible' => Yii::$app->user->can('confidential_information')
], ],
[ [
'label' => 'Задачи', 'icon' => 'tasks', 'url' => '#', 'label' => 'Задачи', 'icon' => 'tasks', 'url' => '#',
@ -70,7 +70,7 @@
['label' => 'Исполнители задачи', 'icon' => 'users', 'url' => ['/task/task-user'], 'active' => \Yii::$app->controller->id == 'task-user'], ['label' => 'Исполнители задачи', 'icon' => 'users', 'url' => ['/task/task-user'], 'active' => \Yii::$app->controller->id == 'task-user'],
], ],
'visible' => Yii::$app->user->can('confidential_information') //TODO 'visible' => Yii::$app->user->can('confidential_information')
], ],
['label' => 'Компании', 'icon' => 'building', 'url' => ['/company/company'], 'active' => \Yii::$app->controller->id == 'company', 'visible' => Yii::$app->user->can('confidential_information')], ['label' => 'Компании', 'icon' => 'building', 'url' => ['/company/company'], 'active' => \Yii::$app->controller->id == 'company', 'visible' => Yii::$app->user->can('confidential_information')],
[ [
@ -79,7 +79,7 @@
['label' => 'Компании', 'icon' => 'building', 'url' => ['/hh/hh'], 'active' => \Yii::$app->controller->id == 'hh'], ['label' => 'Компании', 'icon' => 'building', 'url' => ['/hh/hh'], 'active' => \Yii::$app->controller->id == 'hh'],
['label' => 'Вакансии', 'icon' => 'user-md', 'url' => ['/hh/hh-job'], 'active' => \Yii::$app->controller->id == 'hh-job'], ['label' => 'Вакансии', 'icon' => 'user-md', 'url' => ['/hh/hh-job'], 'active' => \Yii::$app->controller->id == 'hh-job'],
], ],
'visible' => Yii::$app->user->can('confidential_information') //TODO 'visible' => Yii::$app->user->can('confidential_information')
], ],
['label' => 'Баланс', 'icon' => 'dollar', 'url' => ['/balance/balance'], 'active' => \Yii::$app->controller->id == 'balance', 'visible' => Yii::$app->user->can('confidential_information')], ['label' => 'Баланс', 'icon' => 'dollar', 'url' => ['/balance/balance'], 'active' => \Yii::$app->controller->id == 'balance', 'visible' => Yii::$app->user->can('confidential_information')],
['label' => 'Отпуска', 'icon' => 'plane', 'url' => ['/holiday/holiday'], 'active' => \Yii::$app->controller->id == 'holiday', 'visible' => Yii::$app->user->can('confidential_information')], ['label' => 'Отпуска', 'icon' => 'plane', 'url' => ['/holiday/holiday'], 'active' => \Yii::$app->controller->id == 'holiday', 'visible' => Yii::$app->user->can('confidential_information')],
@ -94,7 +94,7 @@
'icon' => 'list-alt', 'icon' => 'list-alt',
'url' => ['/interview/interview'], 'url' => ['/interview/interview'],
'active' => \Yii::$app->controller->id == 'interview', 'active' => \Yii::$app->controller->id == 'interview',
'visible' => Yii::$app->user->can('confidential_information'), //TODO 'visible' => Yii::$app->user->can('confidential_information'),
'badge' => '<span class="badge badge-info right">4</span>' 'badge' => '<span class="badge badge-info right">4</span>'
], ],
[ [
@ -108,7 +108,7 @@
['label' => 'Анкеты пользователей', 'icon' => 'drivers-license', 'url' => ['/questionnaire/user-questionnaire'], 'active' => \Yii::$app->controller->id == 'user-questionnaire'], ['label' => 'Анкеты пользователей', 'icon' => 'drivers-license', 'url' => ['/questionnaire/user-questionnaire'], 'active' => \Yii::$app->controller->id == 'user-questionnaire'],
['label' => 'Ответы пользователей', 'icon' => 'comments', 'url' => ['/questionnaire/user-response'], 'active' => \Yii::$app->controller->id == 'user-response'], ['label' => 'Ответы пользователей', 'icon' => 'comments', 'url' => ['/questionnaire/user-response'], 'active' => \Yii::$app->controller->id == 'user-response'],
], ],
'visible' => Yii::$app->user->can('confidential_information') //TODO 'visible' => Yii::$app->user->can('confidential_information')
], ],
/*['label' => 'Gii', 'icon' => 'file-code-o', 'url' => ['/gii']], /*['label' => 'Gii', 'icon' => 'file-code-o', 'url' => ['/gii']],

View File

@ -2,3 +2,4 @@
/index-test.php /index-test.php
/robots.txt /robots.txt
/log.txt /log.txt
/upload

View File

@ -3,4 +3,5 @@ Yii::setAlias('@common', dirname(__DIR__));
Yii::setAlias('@frontend', dirname(dirname(__DIR__)) . '/frontend'); Yii::setAlias('@frontend', dirname(dirname(__DIR__)) . '/frontend');
Yii::setAlias('@backend', dirname(dirname(__DIR__)) . '/backend'); Yii::setAlias('@backend', dirname(dirname(__DIR__)) . '/backend');
Yii::setAlias('@console', dirname(dirname(__DIR__)) . '/console'); Yii::setAlias('@console', dirname(dirname(__DIR__)) . '/console');
Yii::setAlias('@templates', dirname(dirname(__DIR__)) . '/frontend/web/upload/templates'); Yii::setAlias('@templates', dirname(dirname(__DIR__)) . '/backend/web/upload/templates');
Yii::setAlias('@documents', dirname(dirname(__DIR__)) . '/backend/web/upload/documents');

View File

@ -28,6 +28,10 @@ return [
'path' => 'media/upload', 'path' => 'media/upload',
'name' => 'Изображения', 'name' => 'Изображения',
], ],
[
'basePath' => '@templates',
'name' => 'Шаблоны документов' //перевод Yii::t($category, $message)
],
], ],
'watermark' => [ 'watermark' => [
'source' => __DIR__ . '/logo.png', // Path to Water mark image 'source' => __DIR__ . '/logo.png', // Path to Water mark image

View File

@ -3,7 +3,6 @@
namespace common\helpers; namespace common\helpers;
use Yii; use Yii;
use yii\helpers\ArrayHelper;
use yii\helpers\Html; use yii\helpers\Html;
class TimeHelper class TimeHelper

View File

@ -0,0 +1,28 @@
<?php
namespace common\helpers;
class TransliteratorHelper
{
private static $rus = [
'А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У',
'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я', 'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з',
'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы', 'ь',
'э', 'ю', 'я'
];
private static $lat = [
'A', 'B', 'V', 'G', 'D', 'E', 'Yo', 'Zh', 'Z', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U',
'F', 'H', 'C', 'Ch', 'Sh', 'Shch', 'Y', 'Y', 'Y', 'E', 'Yu', 'Ya','a', 'b', 'v', 'g', 'd', 'e', 'yo', 'zh',
'z', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'h', 'c', 'ch', 'sh', 'shch', 'y',
'y', 'y', 'e', 'yu', 'ya'
];
public static function transliterate($source)
{
if ($source) {
return str_replace(self::$rus, self::$lat, $source);
}
return null;
}
}

View File

@ -4,6 +4,7 @@ namespace common\models;
use Yii; use Yii;
use yii\behaviors\TimestampBehavior; use yii\behaviors\TimestampBehavior;
use yii\db\ActiveQuery;
use yii\db\Expression; use yii\db\Expression;
use yii\db\StaleObjectException; use yii\db\StaleObjectException;
@ -87,7 +88,7 @@ class Document extends \yii\db\ActiveRecord
} }
/** /**
* @return \yii\db\ActiveQuery * @return ActiveQuery
*/ */
public function getManager() public function getManager()
{ {
@ -95,7 +96,7 @@ class Document extends \yii\db\ActiveRecord
} }
/** /**
* @return \yii\db\ActiveQuery * @return ActiveQuery
*/ */
public function getTemplate() public function getTemplate()
{ {
@ -103,9 +104,9 @@ class Document extends \yii\db\ActiveRecord
} }
/** /**
* @return \yii\db\ActiveQuery * @return ActiveQuery
*/ */
public function getDocumentFieldValues() public function getDocumentFieldValues(): ActiveQuery
{ {
return $this->hasMany(DocumentFieldValue::className(), ['document_id' => 'id']); return $this->hasMany(DocumentFieldValue::className(), ['document_id' => 'id']);
} }

View File

@ -2,6 +2,7 @@
namespace common\models; namespace common\models;
use common\helpers\TransliteratorHelper;
use Yii; use Yii;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
@ -10,6 +11,7 @@ use yii\helpers\ArrayHelper;
* *
* @property int $id * @property int $id
* @property string $title * @property string $title
* @property string $field_template
* *
* @property DocumentFieldValue[] $documentFieldValues * @property DocumentFieldValue[] $documentFieldValues
* @property TemplateDocumentField[] $templateDocumentFields * @property TemplateDocumentField[] $templateDocumentFields
@ -30,10 +32,16 @@ class DocumentField extends \yii\db\ActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['title'], 'string', 'max' => 255], [['title', 'field_template'], 'string', 'max' => 255],
]; ];
} }
public function beforeSave($insert)
{
$this->field_template = TransliteratorHelper::transliterate($this->title);
return true;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -42,6 +50,7 @@ class DocumentField extends \yii\db\ActiveRecord
return [ return [
'id' => 'ID', 'id' => 'ID',
'title' => 'Название', 'title' => 'Название',
'field_template' => 'Шаблон поля',
]; ];
} }

View File

@ -3,6 +3,7 @@
namespace common\models; namespace common\models;
use Yii; use Yii;
use yii\db\ActiveQuery;
/** /**
* This is the model class for table "document_field_value". * This is the model class for table "document_field_value".
@ -54,7 +55,7 @@ class DocumentFieldValue extends \yii\db\ActiveRecord
} }
/** /**
* @return \yii\db\ActiveQuery * @return ActiveQuery
*/ */
public function getDocument() public function getDocument()
{ {
@ -62,10 +63,17 @@ class DocumentFieldValue extends \yii\db\ActiveRecord
} }
/** /**
* @return \yii\db\ActiveQuery * @return ActiveQuery
*/ */
public function getField() public function getField(): ActiveQuery
{ {
return $this->hasOne(DocumentField::className(), ['id' => 'field_id']); return $this->hasOne(DocumentField::className(), ['id' => 'field_id']);
} }
public function getFieldsArray()
{
return '44';
// self::find()->select(['value', 'document_field.title', 'document_field.template'])
// ->joinWith('field')->asArray()->all();
}
} }

View File

@ -3,7 +3,9 @@
namespace common\models; namespace common\models;
use Yii; use Yii;
use yii\base\InvalidConfigException;
use yii\behaviors\TimestampBehavior; use yii\behaviors\TimestampBehavior;
use yii\db\ActiveQuery;
use yii\db\Expression; use yii\db\Expression;
/** /**
@ -20,7 +22,7 @@ use yii\db\Expression;
*/ */
class Template extends \yii\db\ActiveRecord class Template extends \yii\db\ActiveRecord
{ {
public $template; // public $template;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
@ -50,9 +52,9 @@ class Template extends \yii\db\ActiveRecord
[['created_at', 'updated_at'], 'safe'], [['created_at', 'updated_at'], 'safe'],
[['title'], 'unique'], [['title'], 'unique'],
[['template_file_name', 'title'], 'required'], [['template_file_name', 'title'], 'required'],
[['template'], 'required', 'message'=>'Укажите путь к файлу'], // [['template'], 'required', 'message'=>'Укажите путь к файлу'],
[['template'], 'file', 'maxSize' => '10000'], // [['template'], 'file', 'maxSize' => '10000'],
[['template'], 'file', 'skipOnEmpty' => false, 'extensions' => 'doc, docx, txt'], // [['template'], 'file', 'skipOnEmpty' => false, 'extensions' => 'doc, docx, txt'],
[['title', 'template_file_name'], 'string', 'max' => 255], [['title', 'template_file_name'], 'string', 'max' => 255],
]; ];
} }
@ -78,7 +80,7 @@ class Template extends \yii\db\ActiveRecord
} }
if (!empty($this->template_file_name)) { if (!empty($this->template_file_name)) {
$template_path = Yii::getAlias('@templates') . '/' . $this->template_file_name; $template_path = Yii::getAlias('@templates') . $this->template_file_name;
if(file_exists($template_path)) { if(file_exists($template_path)) {
unlink($template_path); unlink($template_path);
@ -88,7 +90,7 @@ class Template extends \yii\db\ActiveRecord
} }
/** /**
* @return \yii\db\ActiveQuery * @return ActiveQuery
*/ */
public function getDocuments() public function getDocuments()
{ {
@ -96,10 +98,27 @@ class Template extends \yii\db\ActiveRecord
} }
/** /**
* @return \yii\db\ActiveQuery * @return ActiveQuery
*/ */
public function getTemplateDocumentFields() public function getTemplateDocumentFields()
{ {
return $this->hasMany(TemplateDocumentField::className(), ['template_id' => 'id']); return $this->hasMany(TemplateDocumentField::className(), ['template_id' => 'id']);
} }
public function getTitle()
{
return $this->title;
}
//TODO no need, delete
public function getDocumentFields()
{
$fieldsArray = [];
foreach ($this->templateDocumentFields as $templateDocField) {
$fieldsArray[] = $templateDocField->field;
}
return $fieldsArray;
}
} }

View File

@ -56,7 +56,7 @@ class TemplateDocumentField extends \yii\db\ActiveRecord
*/ */
public function getField() public function getField()
{ {
return $this->hasOne(DocumentField::className(), ['id' => 'field_id']); return $this->hasOne(DocumentField::className(), ['id' => 'field_id'])->asArray();
} }
/** /**

View File

@ -0,0 +1,43 @@
<?php
namespace common\services;
use PhpOffice\PhpWord\Exception\CopyFileException;
use PhpOffice\PhpWord\Exception\CreateTemporaryFileException;
use PhpOffice\PhpWord\TemplateProcessor;
use Yii;
class DocumentService
{
private $file_title;
private $document;
private $template_title;
private [] $fields;
/**
* @throws CopyFileException
* @throws CreateTemporaryFileException
*/
public function __construct($file_title, $template_name, [] $fields)
{
$this->file_title = $file_title . 'docx';
$this->document = new TemplateProcessor(Yii::getAlias('@templates') . "/$template_name");
}
public function setFields($fields )
{
foreach ($fields as $field) {
$this->document->setValue('FIO', '8888888888' );
}
}
public function save()
{
$this->document->saveAs($this->file_title);
}
public function creat3e()
{}
}

View File

@ -24,7 +24,6 @@
"kartik-v/yii2-widget-select2": "@dev", "kartik-v/yii2-widget-select2": "@dev",
"kavalar/hhapi": "@dev", "kavalar/hhapi": "@dev",
"mirocow/yii2-eav": "*", "mirocow/yii2-eav": "*",
"kartik-v/yii2-widget-fileinput": "dev-master",
"2amigos/yii2-file-upload-widget": "~1.0", "2amigos/yii2-file-upload-widget": "~1.0",
"kartik-v/yii2-grid": "dev-master", "kartik-v/yii2-grid": "dev-master",
"edofre/yii2-fullcalendar-scheduler": "V1.1.12", "edofre/yii2-fullcalendar-scheduler": "V1.1.12",
@ -33,7 +32,8 @@
"kavalar/yii2-telegram-bot": "^0.1.0", "kavalar/yii2-telegram-bot": "^0.1.0",
"2amigos/yii2-transliterator-helper": "*", "2amigos/yii2-transliterator-helper": "*",
"ext-json": "*", "ext-json": "*",
"kartik-v/yii2-widget-depdrop": "dev-master" "kartik-v/yii2-widget-depdrop": "dev-master",
"phpoffice/phpword": "^0.18.2"
}, },
"require-dev": { "require-dev": {
"yiisoft/yii2-debug": "~2.0.0", "yiisoft/yii2-debug": "~2.0.0",

306
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "216b806f0c05ea29213238c495fe568f", "content-hash": "15270a1b8febac6d9099b06491c22de1",
"packages": [ "packages": [
{ {
"name": "2amigos/yii2-file-upload-widget", "name": "2amigos/yii2-file-upload-widget",
@ -959,69 +959,6 @@
}, },
"time": "2016-10-24T15:52:54+00:00" "time": "2016-10-24T15:52:54+00:00"
}, },
{
"name": "kartik-v/bootstrap-fileinput",
"version": "v5.2.6",
"source": {
"type": "git",
"url": "https://github.com/kartik-v/bootstrap-fileinput.git",
"reference": "642849327db63231922558b580e985e27beddfc1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/kartik-v/bootstrap-fileinput/zipball/642849327db63231922558b580e985e27beddfc1",
"reference": "642849327db63231922558b580e985e27beddfc1",
"shasum": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "5.2.x-dev"
}
},
"autoload": {
"psr-4": {
"kartik\\plugins\\fileinput\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Kartik Visweswaran",
"email": "kartikv2@gmail.com",
"homepage": "http://www.krajee.com/"
}
],
"description": "An enhanced HTML 5 file input for Bootstrap 5.x, 4.x, and 3.x with features for file preview for many file types, multiple selection, ajax uploads, and more.",
"homepage": "https://github.com/kartik-v/bootstrap-fileinput",
"keywords": [
"ajax",
"bootstrap",
"delete",
"file",
"image",
"input",
"jquery",
"multiple",
"preview",
"progress",
"upload"
],
"support": {
"issues": "https://github.com/kartik-v/bootstrap-fileinput/issues",
"source": "https://github.com/kartik-v/bootstrap-fileinput/tree/v5.2.6"
},
"funding": [
{
"url": "https://opencollective.com/bootstrap-fileinput",
"type": "open_collective"
}
],
"time": "2021-09-23T15:32:41+00:00"
},
{ {
"name": "kartik-v/dependent-dropdown", "name": "kartik-v/dependent-dropdown",
"version": "v1.4.9", "version": "v1.4.9",
@ -1424,72 +1361,6 @@
}, },
"time": "2019-05-25T07:32:15+00:00" "time": "2019-05-25T07:32:15+00:00"
}, },
{
"name": "kartik-v/yii2-widget-fileinput",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/kartik-v/yii2-widget-fileinput.git",
"reference": "d3caa4911ecd8125a5f87865807fa1de7f6cdba7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/kartik-v/yii2-widget-fileinput/zipball/d3caa4911ecd8125a5f87865807fa1de7f6cdba7",
"reference": "d3caa4911ecd8125a5f87865807fa1de7f6cdba7",
"shasum": ""
},
"require": {
"kartik-v/bootstrap-fileinput": ">=5.0.0",
"kartik-v/yii2-krajee-base": ">=3.0.1"
},
"default-branch": true,
"type": "yii2-extension",
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev"
}
},
"autoload": {
"psr-4": {
"kartik\\file\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Kartik Visweswaran",
"email": "kartikv2@gmail.com",
"homepage": "http://www.krajee.com/"
}
],
"description": "An enhanced FileInput widget for Bootstrap 3.x, 4.x & 5.x with file preview, multiple selection, and more features (sub repo split from yii2-widgets)",
"homepage": "https://github.com/kartik-v/yii2-widget-fileinput",
"keywords": [
"extension",
"file",
"form",
"input",
"jquery",
"plugin",
"upload",
"widget",
"yii2"
],
"support": {
"issues": "https://github.com/kartik-v/yii2-widget-fileinput/issues",
"source": "https://github.com/kartik-v/yii2-widget-fileinput/tree/master"
},
"funding": [
{
"url": "https://opencollective.com/yii2-widget-fileinput",
"type": "open_collective"
}
],
"time": "2021-09-03T10:14:31+00:00"
},
{ {
"name": "kartik-v/yii2-widget-select2", "name": "kartik-v/yii2-widget-select2",
"version": "dev-master", "version": "dev-master",
@ -1673,6 +1544,68 @@
}, },
"time": "2021-08-26T13:08:14+00:00" "time": "2021-08-26T13:08:14+00:00"
}, },
{
"name": "laminas/laminas-escaper",
"version": "2.9.0",
"source": {
"type": "git",
"url": "https://github.com/laminas/laminas-escaper.git",
"reference": "891ad70986729e20ed2e86355fcf93c9dc238a5f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laminas/laminas-escaper/zipball/891ad70986729e20ed2e86355fcf93c9dc238a5f",
"reference": "891ad70986729e20ed2e86355fcf93c9dc238a5f",
"shasum": ""
},
"require": {
"php": "^7.3 || ~8.0.0 || ~8.1.0"
},
"conflict": {
"zendframework/zend-escaper": "*"
},
"require-dev": {
"laminas/laminas-coding-standard": "~2.3.0",
"phpunit/phpunit": "^9.3",
"psalm/plugin-phpunit": "^0.12.2",
"vimeo/psalm": "^3.16"
},
"suggest": {
"ext-iconv": "*",
"ext-mbstring": "*"
},
"type": "library",
"autoload": {
"psr-4": {
"Laminas\\Escaper\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"description": "Securely and safely escape HTML, HTML attributes, JavaScript, CSS, and URLs",
"homepage": "https://laminas.dev",
"keywords": [
"escaper",
"laminas"
],
"support": {
"chat": "https://laminas.dev/chat",
"docs": "https://docs.laminas.dev/laminas-escaper/",
"forum": "https://discourse.laminas.dev",
"issues": "https://github.com/laminas/laminas-escaper/issues",
"rss": "https://github.com/laminas/laminas-escaper/releases.atom",
"source": "https://github.com/laminas/laminas-escaper"
},
"funding": [
{
"url": "https://funding.communitybridge.org/projects/laminas-project",
"type": "community_bridge"
}
],
"time": "2021-09-02T17:10:53+00:00"
},
{ {
"name": "mihaildev/yii2-elfinder", "name": "mihaildev/yii2-elfinder",
"version": "1.4.0", "version": "1.4.0",
@ -1897,6 +1830,118 @@
}, },
"time": "2020-10-15T08:29:30+00:00" "time": "2020-10-15T08:29:30+00:00"
}, },
{
"name": "phpoffice/phpword",
"version": "0.18.2",
"source": {
"type": "git",
"url": "https://github.com/PHPOffice/PHPWord.git",
"reference": "aca10785cf68dc95d7f6fac4fe854979fef3f8db"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHPOffice/PHPWord/zipball/aca10785cf68dc95d7f6fac4fe854979fef3f8db",
"reference": "aca10785cf68dc95d7f6fac4fe854979fef3f8db",
"shasum": ""
},
"require": {
"ext-xml": "*",
"laminas/laminas-escaper": "^2.2",
"php": "^5.3.3 || ^7.0 || ^8.0"
},
"require-dev": {
"dompdf/dompdf": "0.8.* || 1.0.*",
"ext-gd": "*",
"ext-zip": "*",
"friendsofphp/php-cs-fixer": "^2.2",
"mpdf/mpdf": "5.7.4 || 6.* || 7.* || 8.*",
"php-coveralls/php-coveralls": "1.1.0 || ^2.0",
"phploc/phploc": "2.* || 3.* || 4.* || 5.* || 6.* || 7.*",
"phpmd/phpmd": "2.*",
"phpunit/phpunit": "^4.8.36 || ^7.0",
"squizlabs/php_codesniffer": "^2.9 || ^3.5",
"tecnickcom/tcpdf": "6.*"
},
"suggest": {
"dompdf/dompdf": "Allows writing PDF",
"ext-gd2": "Allows adding images",
"ext-xmlwriter": "Allows writing OOXML and ODF",
"ext-xsl": "Allows applying XSL style sheet to headers, to main document part, and to footers of an OOXML template",
"ext-zip": "Allows writing OOXML and ODF"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-develop": "0.19-dev"
}
},
"autoload": {
"psr-4": {
"PhpOffice\\PhpWord\\": "src/PhpWord"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-3.0"
],
"authors": [
{
"name": "Mark Baker"
},
{
"name": "Gabriel Bull",
"email": "me@gabrielbull.com",
"homepage": "http://gabrielbull.com/"
},
{
"name": "Franck Lefevre",
"homepage": "https://rootslabs.net/blog/"
},
{
"name": "Ivan Lanin",
"homepage": "http://ivan.lanin.org"
},
{
"name": "Roman Syroeshko",
"homepage": "http://ru.linkedin.com/pub/roman-syroeshko/34/a53/994/"
},
{
"name": "Antoine de Troostembergh"
}
],
"description": "PHPWord - A pure PHP library for reading and writing word processing documents (OOXML, ODF, RTF, HTML, PDF)",
"homepage": "http://phpoffice.github.io",
"keywords": [
"ISO IEC 29500",
"OOXML",
"Office Open XML",
"OpenDocument",
"OpenXML",
"PhpOffice",
"PhpWord",
"Rich Text Format",
"WordprocessingML",
"doc",
"docx",
"html",
"odf",
"odt",
"office",
"pdf",
"php",
"reader",
"rtf",
"template",
"template processor",
"word",
"writer"
],
"support": {
"issues": "https://github.com/PHPOffice/PHPWord/issues",
"source": "https://github.com/PHPOffice/PHPWord/tree/0.18.2"
},
"time": "2021-06-04T20:58:45+00:00"
},
{ {
"name": "rmrevin/yii2-fontawesome", "name": "rmrevin/yii2-fontawesome",
"version": "2.17.1", "version": "2.17.1",
@ -6498,7 +6543,6 @@
"stability-flags": { "stability-flags": {
"kartik-v/yii2-widget-select2": 20, "kartik-v/yii2-widget-select2": 20,
"kavalar/hhapi": 20, "kavalar/hhapi": 20,
"kartik-v/yii2-widget-fileinput": 20,
"kartik-v/yii2-grid": 20, "kartik-v/yii2-grid": 20,
"kartik-v/yii2-widget-depdrop": 20 "kartik-v/yii2-widget-depdrop": 20
}, },

View File

@ -0,0 +1,40 @@
<?php
use yii\db\Migration;
/**
* Class m220106_092252_add_column_field_template_document_field_table
*/
class m220106_092252_add_column_field_template_document_field_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('document_field', 'field_template', $this->string());
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('document_field', 'field_template');
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m220106_092252_add_column_field_template_document_field_table cannot be reverted.\n";
return false;
}
*/
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff