commit
7081961bce
@ -78,7 +78,7 @@ return [
|
||||
'components' => [
|
||||
'request' => [
|
||||
'csrfParam' => '_csrf-backend',
|
||||
'baseUrl' => '/secure',
|
||||
'baseUrl' => '', // /secure
|
||||
'parsers' => [
|
||||
'application/json' => 'yii\web\JsonParser',
|
||||
'text/xml' => 'yii/web/XmlParser',
|
||||
|
@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace backend\modules\document\controllers;
|
||||
|
||||
use Yii;
|
||||
use backend\modules\document\models\AccompanyingDocument;
|
||||
use backend\modules\document\models\AccompanyingDocumentSearch;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
|
||||
/**
|
||||
* AccompanyingDocumentController implements the CRUD actions for AccompanyingDocument model.
|
||||
*/
|
||||
class AccompanyingDocumentController extends Controller
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className(),
|
||||
'actions' => [
|
||||
'delete' => ['POST'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all AccompanyingDocument models.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$searchModel = new AccompanyingDocumentSearch();
|
||||
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
||||
|
||||
return $this->render('index', [
|
||||
'searchModel' => $searchModel,
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a single AccompanyingDocument model.
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionView($id)
|
||||
{
|
||||
return $this->render('view', [
|
||||
'model' => $this->findModel($id),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AccompanyingDocument model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionCreate()
|
||||
{
|
||||
$model = new AccompanyingDocument();
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing AccompanyingDocument 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,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an existing AccompanyingDocument model.
|
||||
* If deletion is successful, the browser will be redirected to the 'index' page.
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionDelete($id)
|
||||
{
|
||||
$this->findModel($id)->delete();
|
||||
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the AccompanyingDocument model based on its primary key value.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
* @param integer $id
|
||||
* @return AccompanyingDocument the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id)
|
||||
{
|
||||
if (($model = AccompanyingDocument::findOne($id)) !== null) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
}
|
@ -10,6 +10,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 +140,15 @@ class DocumentController extends Controller
|
||||
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
|
||||
|
||||
public function actionCreateDocument($id)
|
||||
{
|
||||
if(!empty($this->findModel($id)->template->template_file_name)){
|
||||
$documentService = new DocumentService($id);
|
||||
$documentService->setFields();
|
||||
$documentService->downloadDocument();
|
||||
}
|
||||
return $this->redirect(['view', 'id' => $id]);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -97,7 +97,10 @@ class DocumentFieldValueController extends Controller
|
||||
$documentFieldValues = [];
|
||||
|
||||
if (empty($fieldsIdTitleList)) {
|
||||
$documentFieldValues = [new DocumentFieldValue()];
|
||||
return $this->redirect([
|
||||
'document/view',
|
||||
'id' => $document_id,
|
||||
]);
|
||||
}
|
||||
else {
|
||||
foreach ($fieldsIdTitleList as $fieldsIdTitle){
|
||||
|
@ -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' => [
|
||||
@ -105,45 +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);
|
||||
// $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]);
|
||||
// }
|
||||
// }
|
||||
$model->scenario = Template::SCENARIO_UPDATE_TITLE;
|
||||
|
||||
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', [
|
||||
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,
|
||||
]);
|
||||
}
|
||||
|
10
backend/modules/document/models/AccompanyingDocument.php
Normal file
10
backend/modules/document/models/AccompanyingDocument.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace backend\modules\document\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
class AccompanyingDocument extends \common\models\AccompanyingDocument
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace backend\modules\document\models;
|
||||
|
||||
use yii\base\Model;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use backend\modules\document\models\AccompanyingDocument;
|
||||
|
||||
/**
|
||||
* AccompanyingDocumentSearch represents the model behind the search form of `backend\modules\document\models\AccompanyingDocument`.
|
||||
*/
|
||||
class AccompanyingDocumentSearch extends AccompanyingDocument
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id', 'document_id'], 'integer'],
|
||||
[['title'], 'safe'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function scenarios()
|
||||
{
|
||||
// bypass scenarios() implementation in the parent class
|
||||
return Model::scenarios();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates data provider instance with search query applied
|
||||
*
|
||||
* @param array $params
|
||||
*
|
||||
* @return ActiveDataProvider
|
||||
*/
|
||||
public function search($params)
|
||||
{
|
||||
$query = AccompanyingDocument::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,
|
||||
'document_id' => $this->document_id,
|
||||
]);
|
||||
|
||||
$query->andFilterWhere(['like', 'title', $this->title]);
|
||||
|
||||
return $dataProvider;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\document\models\Document;
|
||||
use kartik\file\FileInput;
|
||||
use kartik\select2\Select2;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\document\models\AccompanyingDocument */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div class="accompanying-document-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'document_id')->widget(Select2::className(),
|
||||
[
|
||||
'data' => Document::find()->select(['title', 'id'])
|
||||
->indexBy('id')->column(),
|
||||
'options' => ['placeholder' => 'Выберите документ','class' => 'form-control'],
|
||||
'pluginOptions' => [
|
||||
'allowClear' => true
|
||||
],
|
||||
]) ?>
|
||||
|
||||
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'accompanying_document')->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>
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\document\models\AccompanyingDocumentSearch */
|
||||
/* @var $form yii\widgets\ActiveForm */
|
||||
?>
|
||||
|
||||
<div class="accompanying-document-search">
|
||||
|
||||
<?php $form = ActiveForm::begin([
|
||||
'action' => ['index'],
|
||||
'method' => 'get',
|
||||
]); ?>
|
||||
|
||||
<?= $form->field($model, 'id') ?>
|
||||
|
||||
<?= $form->field($model, 'document_id') ?>
|
||||
|
||||
<?= $form->field($model, 'title') ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\document\models\AccompanyingDocument */
|
||||
|
||||
$this->title = 'Добавить сопроводительный документ';
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Accompanying Documents', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="accompanying-document-create">
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use backend\modules\document\models\Document;
|
||||
use yii\helpers\Html;
|
||||
use yii\grid\GridView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $searchModel backend\modules\document\models\AccompanyingDocumentSearch */
|
||||
/* @var $dataProvider yii\data\ActiveDataProvider */
|
||||
|
||||
$this->title = 'Сопроводительные бумги';
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="accompanying-document-index">
|
||||
|
||||
<p>
|
||||
<?= Html::a('Добавить сопроводительный документ', ['create'], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'filterModel' => $searchModel,
|
||||
'columns' => [
|
||||
['class' => 'yii\grid\SerialColumn'],
|
||||
|
||||
[
|
||||
'attribute' => 'document_id',
|
||||
'filter' => Document::find()->select(['title', 'id'])->indexBy('id')->column(),
|
||||
'value' => 'document.title'
|
||||
],
|
||||
'title',
|
||||
|
||||
['class' => 'yii\grid\ActionColumn'],
|
||||
],
|
||||
]); ?>
|
||||
</div>
|
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\document\models\AccompanyingDocument */
|
||||
|
||||
$this->title = 'Update Accompanying Document: ' . $model->title;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Accompanying Documents', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]];
|
||||
$this->params['breadcrumbs'][] = 'Update';
|
||||
?>
|
||||
<div class="accompanying-document-update">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\DetailView;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\document\models\AccompanyingDocument */
|
||||
|
||||
$this->title = $model->title;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Accompanying Documents', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
\yii\web\YiiAsset::register($this);
|
||||
?>
|
||||
<div class="accompanying-document-view">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>
|
||||
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::a('Delete', ['delete', 'id' => $model->id], [
|
||||
'class' => 'btn btn-danger',
|
||||
'data' => [
|
||||
'confirm' => 'Are you sure you want to delete this item?',
|
||||
'method' => 'post',
|
||||
],
|
||||
]) ?>
|
||||
</p>
|
||||
|
||||
<?= DetailView::widget([
|
||||
'model' => $model,
|
||||
'attributes' => [
|
||||
'id',
|
||||
'document_id',
|
||||
'title',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
</div>
|
@ -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 . '}',
|
||||
],
|
||||
],
|
||||
]) ?>
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use yii\grid\GridView;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\DetailView;
|
||||
|
||||
@ -15,6 +16,8 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="document-view">
|
||||
|
||||
<!-- --><?php // \common\models\Document::getDocumentWitchAndFieldValues(31); die?>
|
||||
|
||||
<p>
|
||||
<?= Html::a('Список', ['index', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::a('Изменить', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
|
||||
@ -34,11 +37,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>
|
||||
<?= 'Поля документа:'?>
|
||||
|
@ -20,7 +20,7 @@ use yii\widgets\ActiveForm;
|
||||
<?= $form->field($model, 'template')->widget(FileInput::classname(), [
|
||||
'options' => ['accept' => 'text/*'],
|
||||
'pluginOptions' => [
|
||||
'allowedFileExtensions'=>['doc','docx','txt'],'showUpload' => true
|
||||
'allowedFileExtensions'=>['docx'],'showUpload' => true
|
||||
],
|
||||
]); ?>
|
||||
|
||||
|
@ -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>
|
@ -1,7 +1,5 @@
|
||||
<?php
|
||||
|
||||
use kartik\file\FileInput;
|
||||
use mihaildev\elfinder\InputFile;
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
@ -17,13 +15,6 @@ 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
|
||||
],
|
||||
]); ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
@ -1,7 +1,5 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/* @var $this yii\web\View */
|
||||
/* @var $model backend\modules\document\models\Template */
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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,16 +11,24 @@ 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>
|
||||
<?= 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' => [
|
||||
@ -36,33 +44,28 @@ YiiAsset::register($this);
|
||||
'attributes' => [
|
||||
'id',
|
||||
[
|
||||
'attribute'=>'title',
|
||||
'label'=>'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',
|
||||
]
|
||||
);
|
||||
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',
|
||||
|
||||
[
|
||||
'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(['template/update-file', 'id' => $model->id]), [
|
||||
'title' => 'update-file',
|
||||
// 'class' => 'pull-right detail-button',
|
||||
]);
|
||||
}
|
||||
]
|
||||
],
|
||||
]) ?>
|
||||
@ -95,9 +98,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;
|
||||
|
@ -69,7 +69,6 @@
|
||||
['label' => 'Задачи', 'icon' => 'minus', 'url' => ['/task/task'], 'active' => \Yii::$app->controller->id == 'task'],
|
||||
['label' => 'Исполнители задачи', 'icon' => 'users', 'url' => ['/task/task-user'], 'active' => \Yii::$app->controller->id == 'task-user'],
|
||||
],
|
||||
|
||||
'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')],
|
||||
|
3
backend/web/.gitignore
vendored
3
backend/web/.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
/index.php
|
||||
/index-test.php
|
||||
/robots.txt
|
||||
/log.txt
|
||||
/log.txt
|
||||
/upload
|
@ -3,4 +3,5 @@ Yii::setAlias('@common', dirname(__DIR__));
|
||||
Yii::setAlias('@frontend', dirname(dirname(__DIR__)) . '/frontend');
|
||||
Yii::setAlias('@backend', dirname(dirname(__DIR__)) . '/backend');
|
||||
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');
|
||||
|
@ -28,6 +28,10 @@ return [
|
||||
'path' => 'media/upload',
|
||||
'name' => 'Изображения',
|
||||
],
|
||||
[
|
||||
'basePath' => '@templates',
|
||||
'name' => 'Шаблоны документов' //перевод Yii::t($category, $message)
|
||||
],
|
||||
],
|
||||
'watermark' => [
|
||||
'source' => __DIR__ . '/logo.png', // Path to Water mark image
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace common\helpers;
|
||||
|
||||
use Yii;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\helpers\Html;
|
||||
|
||||
class TimeHelper
|
||||
|
28
common/helpers/TransliteratorHelper.php
Normal file
28
common/helpers/TransliteratorHelper.php
Normal 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;
|
||||
}
|
||||
}
|
65
common/models/AccompanyingDocument.php
Normal file
65
common/models/AccompanyingDocument.php
Normal file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "accompanying_document".
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $document_id
|
||||
* @property string $title
|
||||
*
|
||||
* @property Document $document
|
||||
*/
|
||||
class AccompanyingDocument extends \yii\db\ActiveRecord
|
||||
{
|
||||
public $accompanying_document;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'accompanying_document';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['document_id'], 'integer'],
|
||||
[['title'], 'required'],
|
||||
[['title'], 'string', 'max' => 255],
|
||||
[['template_file_name', 'title'], 'required'],
|
||||
[['accompanying_document'], 'required', 'message'=>'Укажите путь к файлу'],
|
||||
[['accompanying_document'], 'file', 'maxSize' => '100000'],
|
||||
[['accompanying_document'], 'file', 'skipOnEmpty' => true, 'extensions' => 'docx'],
|
||||
[['document_id'], 'exist', 'skipOnError' => true, 'targetClass' => Document::className(), 'targetAttribute' => ['document_id' => 'id']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'document_id' => 'Документ',
|
||||
'title' => 'Название',
|
||||
'accompanying_document' => 'Сопроводительный документ'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
*/
|
||||
public function getDocument()
|
||||
{
|
||||
return $this->hasOne(Document::className(), ['id' => 'document_id']);
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\db\ActiveQuery;
|
||||
use yii\db\Expression;
|
||||
use yii\db\StaleObjectException;
|
||||
|
||||
@ -87,7 +88,7 @@ class Document extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getManager()
|
||||
{
|
||||
@ -95,7 +96,7 @@ class Document extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getTemplate()
|
||||
{
|
||||
@ -103,10 +104,19 @@ 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']);
|
||||
}
|
||||
|
||||
public static function getDocument($document_id)
|
||||
{
|
||||
return self::find()
|
||||
->joinWith(['documentFieldValues.field'])
|
||||
->where(['document.id' => $document_id])
|
||||
->asArray()
|
||||
->all();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use common\helpers\TransliteratorHelper;
|
||||
use Yii;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
@ -10,6 +11,7 @@ use yii\helpers\ArrayHelper;
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $title
|
||||
* @property string $field_template
|
||||
*
|
||||
* @property DocumentFieldValue[] $documentFieldValues
|
||||
* @property TemplateDocumentField[] $templateDocumentFields
|
||||
@ -30,10 +32,16 @@ class DocumentField extends \yii\db\ActiveRecord
|
||||
public function rules()
|
||||
{
|
||||
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}
|
||||
*/
|
||||
@ -42,6 +50,7 @@ class DocumentField extends \yii\db\ActiveRecord
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'title' => 'Название',
|
||||
'field_template' => 'Шаблон поля',
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\db\ActiveQuery;
|
||||
|
||||
/**
|
||||
* 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()
|
||||
{
|
||||
@ -62,9 +63,9 @@ 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']);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\db\ActiveQuery;
|
||||
use yii\db\StaleObjectException;
|
||||
|
||||
/**
|
||||
* This is the model class for table "manager".
|
||||
@ -48,6 +49,10 @@ class Manager extends \yii\db\ActiveRecord
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws StaleObjectException
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function beforeDelete()
|
||||
{
|
||||
foreach ($this->managerEmployees as $employee){
|
||||
|
@ -3,7 +3,9 @@
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\db\ActiveQuery;
|
||||
use yii\db\Expression;
|
||||
|
||||
/**
|
||||
@ -20,6 +22,9 @@ use yii\db\Expression;
|
||||
*/
|
||||
class Template extends \yii\db\ActiveRecord
|
||||
{
|
||||
const SCENARIO_UPDATE_TITLE = 'update';
|
||||
const SCENARIO_UPDATE_FILE = 'update';
|
||||
|
||||
public $template;
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@ -51,12 +56,20 @@ class Template extends \yii\db\ActiveRecord
|
||||
[['title'], 'unique'],
|
||||
[['template_file_name', 'title'], 'required'],
|
||||
[['template'], 'required', 'message'=>'Укажите путь к файлу'],
|
||||
[['template'], 'file', 'maxSize' => '10000'],
|
||||
[['template'], 'file', 'skipOnEmpty' => false, 'extensions' => 'doc, docx, txt'],
|
||||
[['template'], 'file', 'maxSize' => '100000'],
|
||||
[['template'], 'file', 'skipOnEmpty' => true, 'extensions' => 'docx'],
|
||||
[['title', 'template_file_name'], 'string', 'max' => 255],
|
||||
];
|
||||
}
|
||||
|
||||
public function scenarios()
|
||||
{
|
||||
$scenarios = parent::scenarios();
|
||||
$scenarios[static::SCENARIO_UPDATE_TITLE] = ['created_at', 'updated_at', 'title', 'template_file_name'];
|
||||
$scenarios[static::SCENARIO_UPDATE_FILE] = ['template'];
|
||||
return $scenarios;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -88,7 +101,7 @@ class Template extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getDocuments()
|
||||
{
|
||||
@ -96,10 +109,15 @@ class Template extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getTemplateDocumentFields()
|
||||
{
|
||||
return $this->hasMany(TemplateDocumentField::className(), ['template_id' => 'id']);
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class TemplateDocumentField extends \yii\db\ActiveRecord
|
||||
*/
|
||||
public function getField()
|
||||
{
|
||||
return $this->hasOne(DocumentField::className(), ['id' => 'field_id']);
|
||||
return $this->hasOne(DocumentField::className(), ['id' => 'field_id'])->asArray();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -221,16 +221,6 @@ class User extends ActiveRecord implements IdentityInterface
|
||||
return $this->hasOne(UserCard::class, ['id_user' => 'id']);
|
||||
}
|
||||
|
||||
// public function getManager()
|
||||
// {
|
||||
// return $this->hasOne(Manager::class, ['user_id' => 'id']);
|
||||
// }
|
||||
//
|
||||
// public function getManagerEmployee()
|
||||
// {
|
||||
// return $this->hasMany(ManagerEmployee::className(), ['employee_id' => 'id']);
|
||||
// }
|
||||
|
||||
public function getProjectUser()
|
||||
{
|
||||
return $this->hasMany(ProjectUser::className(), ['user_id' => 'id']);
|
||||
|
74
common/services/DocumentService.php
Normal file
74
common/services/DocumentService.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace common\services;
|
||||
|
||||
|
||||
use common\models\Document;
|
||||
use PhpOffice\PhpWord\Exception\CopyFileException;
|
||||
use PhpOffice\PhpWord\Exception\CreateTemporaryFileException;
|
||||
use PhpOffice\PhpWord\TemplateProcessor;
|
||||
use Yii;
|
||||
|
||||
class DocumentService
|
||||
{
|
||||
private $model;
|
||||
private $document;
|
||||
private $file_title;
|
||||
private $documentFieldValuesArr;
|
||||
|
||||
/**
|
||||
* @throws CopyFileException
|
||||
* @throws CreateTemporaryFileException
|
||||
*/
|
||||
public function __construct($modelID)
|
||||
{
|
||||
$this->model = Document::findOne($modelID);
|
||||
|
||||
$this->initDocument();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws CopyFileException
|
||||
* @throws CreateTemporaryFileException
|
||||
*/
|
||||
private function initDocument()
|
||||
{
|
||||
$this->file_title = $this->model->title . '.docx';
|
||||
|
||||
$template_title = $this->model->template->template_file_name;
|
||||
$this->document = new TemplateProcessor(
|
||||
Yii::getAlias('@templates') . "/$template_title");
|
||||
|
||||
$this->documentFieldValuesArr = $this->model->documentFieldValues;
|
||||
}
|
||||
|
||||
public function setFields()
|
||||
{
|
||||
foreach ($this->documentFieldValuesArr as $docFieldValue) {
|
||||
$this->document->setValue(
|
||||
$docFieldValue->field->field_template,
|
||||
$docFieldValue->value
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function downloadDocument()
|
||||
{
|
||||
$this->document->saveAs($this->file_title);
|
||||
|
||||
// Имя скачиваемого файла
|
||||
$downloadFile = $this->file_title;
|
||||
// Контент-тип означающий скачивание
|
||||
header("Content-Type: application/octet-stream");
|
||||
// Размер в байтах
|
||||
header("Accept-Ranges: bytes");
|
||||
// Размер файла
|
||||
header("Content-Length: ".filesize($downloadFile));
|
||||
// Расположение скачиваемого файла
|
||||
header("Content-Disposition: attachment; filename=".$downloadFile);
|
||||
|
||||
// Прочитать файл
|
||||
readfile($downloadFile);
|
||||
unlink($this->file_title);
|
||||
}
|
||||
}
|
70
common/services/ProfileService.php
Normal file
70
common/services/ProfileService.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace common\services;
|
||||
|
||||
use common\models\Manager;
|
||||
use common\models\ManagerEmployee;
|
||||
|
||||
class ProfileService
|
||||
{
|
||||
private $searcherID;
|
||||
private $id;
|
||||
|
||||
public function __construct($searcherID, $id)
|
||||
{
|
||||
$this->searcherID = $searcherID;
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
public function checkReportePermission()
|
||||
{
|
||||
if ($this->isMyProfile() or $this->isMyEmployee()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function isMyProfile()
|
||||
{
|
||||
if ($this->id == $this->searcherID) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function isMyEmployee()
|
||||
{
|
||||
if (!$this->amIManager()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->isMyEmploee()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function amIManager()
|
||||
{
|
||||
if (Manager::find()->where(['user_card_id' => $this->searcherID])->exists()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private function isMyEmploee()
|
||||
{
|
||||
$manager = Manager::find()->where(['user_card_id' => $this->searcherID])->one();
|
||||
$exist = ManagerEmployee::find()
|
||||
->where(['manager_id' => $manager->id, 'user_card_id' => $this->id])
|
||||
->exists();
|
||||
|
||||
if ($exist) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -24,7 +24,6 @@
|
||||
"kartik-v/yii2-widget-select2": "@dev",
|
||||
"kavalar/hhapi": "@dev",
|
||||
"mirocow/yii2-eav": "*",
|
||||
"kartik-v/yii2-widget-fileinput": "dev-master",
|
||||
"2amigos/yii2-file-upload-widget": "~1.0",
|
||||
"kartik-v/yii2-grid": "dev-master",
|
||||
"edofre/yii2-fullcalendar-scheduler": "V1.1.12",
|
||||
@ -33,7 +32,9 @@
|
||||
"kavalar/yii2-telegram-bot": "^0.1.0",
|
||||
"2amigos/yii2-transliterator-helper": "*",
|
||||
"ext-json": "*",
|
||||
"kartik-v/yii2-widget-depdrop": "dev-master"
|
||||
"kartik-v/yii2-widget-depdrop": "dev-master",
|
||||
"phpoffice/phpword": "^0.18.2",
|
||||
"kartik-v/yii2-widget-fileinput": "@dev"
|
||||
},
|
||||
"require-dev": {
|
||||
"yiisoft/yii2-debug": "~2.0.0",
|
||||
|
192
composer.lock
generated
192
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "216b806f0c05ea29213238c495fe568f",
|
||||
"content-hash": "26a8d9eb3ba346644b24ddee0391c211",
|
||||
"packages": [
|
||||
{
|
||||
"name": "2amigos/yii2-file-upload-widget",
|
||||
@ -961,16 +961,16 @@
|
||||
},
|
||||
{
|
||||
"name": "kartik-v/bootstrap-fileinput",
|
||||
"version": "v5.2.6",
|
||||
"version": "v5.2.7",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/kartik-v/bootstrap-fileinput.git",
|
||||
"reference": "642849327db63231922558b580e985e27beddfc1"
|
||||
"reference": "02e2e6bccad31373bb2224fccdb8e9a3166124b9"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/kartik-v/bootstrap-fileinput/zipball/642849327db63231922558b580e985e27beddfc1",
|
||||
"reference": "642849327db63231922558b580e985e27beddfc1",
|
||||
"url": "https://api.github.com/repos/kartik-v/bootstrap-fileinput/zipball/02e2e6bccad31373bb2224fccdb8e9a3166124b9",
|
||||
"reference": "02e2e6bccad31373bb2224fccdb8e9a3166124b9",
|
||||
"shasum": ""
|
||||
},
|
||||
"type": "library",
|
||||
@ -1012,7 +1012,7 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/kartik-v/bootstrap-fileinput/issues",
|
||||
"source": "https://github.com/kartik-v/bootstrap-fileinput/tree/v5.2.6"
|
||||
"source": "https://github.com/kartik-v/bootstrap-fileinput/tree/v5.2.7"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@ -1020,7 +1020,7 @@
|
||||
"type": "open_collective"
|
||||
}
|
||||
],
|
||||
"time": "2021-09-23T15:32:41+00:00"
|
||||
"time": "2021-12-17T16:05:03+00:00"
|
||||
},
|
||||
{
|
||||
"name": "kartik-v/dependent-dropdown",
|
||||
@ -1673,6 +1673,68 @@
|
||||
},
|
||||
"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",
|
||||
"version": "1.4.0",
|
||||
@ -1897,6 +1959,118 @@
|
||||
},
|
||||
"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",
|
||||
"version": "2.17.1",
|
||||
@ -6498,9 +6672,9 @@
|
||||
"stability-flags": {
|
||||
"kartik-v/yii2-widget-select2": 20,
|
||||
"kavalar/hhapi": 20,
|
||||
"kartik-v/yii2-widget-fileinput": 20,
|
||||
"kartik-v/yii2-grid": 20,
|
||||
"kartik-v/yii2-widget-depdrop": 20
|
||||
"kartik-v/yii2-widget-depdrop": 20,
|
||||
"kartik-v/yii2-widget-fileinput": 20
|
||||
},
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
|
@ -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;
|
||||
}
|
||||
*/
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Handles the creation of table `{{%accompanying_document}}`.
|
||||
*/
|
||||
class m220110_205045_create_accompanying_document_table extends Migration
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeUp()
|
||||
{
|
||||
$this->createTable('{{%accompanying_document}}', [
|
||||
'id' => $this->primaryKey(),
|
||||
'document_id' => $this->integer(11),
|
||||
'title' => $this->string()->notNull(),
|
||||
]);
|
||||
$this->addForeignKey('document_accompanying_document', 'accompanying_document', 'document_id', 'document', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeDown()
|
||||
{
|
||||
$this->dropForeignKey('document_accompanying_document', 'accompanying_document');
|
||||
$this->dropTable('{{%accompanying_document}}');
|
||||
}
|
||||
}
|
63
console/migrations/m220111_082339_add_default_templates.php
Normal file
63
console/migrations/m220111_082339_add_default_templates.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Class m220111_082339_add_default_templates
|
||||
*/
|
||||
class m220111_082339_add_default_templates extends Migration
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeUp()
|
||||
{
|
||||
$time = new \yii\db\Expression('NOW()');
|
||||
Yii::$app->db->createCommand()->batchInsert('template', [ 'title', 'created_at' ],
|
||||
[
|
||||
['Акт', $time],
|
||||
['Акт сверки', $time],
|
||||
['Детализация', $time],
|
||||
['Доверенность', $time],
|
||||
['Договор', $time],
|
||||
['Доп соглашение к договору', $time],
|
||||
['Транспортная накладная', $time],
|
||||
['Ценовой лист', $time],
|
||||
])->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeDown()
|
||||
{
|
||||
Yii::$app->db->createCommand()->delete('template',
|
||||
[
|
||||
'in', 'title', [
|
||||
'Акт',
|
||||
'Акт сверки',
|
||||
'Детализация',
|
||||
'Доверенность',
|
||||
'Договор',
|
||||
'Доп соглашение к договору',
|
||||
'Транспортная накладная',
|
||||
'Ценовой лист',
|
||||
]
|
||||
])->execute();
|
||||
}
|
||||
|
||||
/*
|
||||
// Use up()/down() to run migration code without a transaction.
|
||||
public function up()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
echo "m220111_082339_add_default_templates cannot be reverted.\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Class m220111_084946_add_default_document_field
|
||||
*/
|
||||
class m220111_084946_add_default_document_field extends Migration
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeUp()
|
||||
{
|
||||
Yii::$app->db->createCommand()->batchInsert('document_field', [ 'title', 'field_template'],
|
||||
[
|
||||
['№ документа', '№ dokumenta'],
|
||||
['от', 'ot'],
|
||||
['Сумма с НДС', 'Summa s NDS'],
|
||||
['НДС', 'NDS'],
|
||||
['Основание', 'Osnovaniye'],
|
||||
['Цена', 'Tsena'],
|
||||
['К договору', 'K dogovoru'],
|
||||
['№', '№']
|
||||
])->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeDown()
|
||||
{
|
||||
Yii::$app->db->createCommand()->delete('document_field',
|
||||
[
|
||||
'in', 'title', [
|
||||
'№ документа',
|
||||
'от',
|
||||
'Сумма с НДС',
|
||||
'НДС',
|
||||
'Основание',
|
||||
'Цена',
|
||||
'К договору',
|
||||
'№',
|
||||
]
|
||||
])->execute();
|
||||
}
|
||||
|
||||
/*
|
||||
// Use up()/down() to run migration code without a transaction.
|
||||
public function up()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
echo "m220111_084946_add_default_document_field cannot be reverted.\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
}
|
8192
frontend-access.log
8192
frontend-access.log
File diff suppressed because it is too large
Load Diff
4862
frontend-error.log
4862
frontend-error.log
File diff suppressed because it is too large
Load Diff
123
frontend/modules/api/controllers/DocumentController.php
Normal file
123
frontend/modules/api/controllers/DocumentController.php
Normal file
@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\modules\api\controllers;
|
||||
|
||||
use common\models\Document;
|
||||
use common\models\DocumentFieldValue;
|
||||
use common\models\Template;
|
||||
use common\models\TemplateDocumentField;
|
||||
use Exception;
|
||||
use Yii;
|
||||
use yii\filters\auth\HttpBearerAuth;
|
||||
use yii\web\BadRequestHttpException;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\rest\Controller;
|
||||
use yii\web\ServerErrorHttpException;
|
||||
|
||||
class DocumentController extends Controller
|
||||
{
|
||||
public function behaviors(): array
|
||||
{
|
||||
$behaviors = parent::behaviors();
|
||||
|
||||
$behaviors['authenticator']['authMethods'] = [
|
||||
HttpBearerAuth::className(),
|
||||
];
|
||||
|
||||
return $behaviors;
|
||||
}
|
||||
|
||||
public function verbs(): array
|
||||
{
|
||||
return [
|
||||
// 'get-task' => ['get'],
|
||||
'get-document-list' => ['get'],
|
||||
'create-document' => ['post'],
|
||||
// 'update-task' => ['put', 'patch'],
|
||||
];
|
||||
}
|
||||
|
||||
public function actionGetDocumentList(): array
|
||||
{
|
||||
$documents = Document::find()->select(['id','title', 'manager_id'])->all();
|
||||
|
||||
if(empty($documents)) {
|
||||
throw new NotFoundHttpException('Documents are not assigned');
|
||||
}
|
||||
|
||||
return $documents;
|
||||
}
|
||||
|
||||
public function actionGetDocument(): array
|
||||
{
|
||||
$document_id = Yii::$app->request->get('document_id');
|
||||
if(empty($document_id) or !is_numeric($document_id))
|
||||
{
|
||||
throw new NotFoundHttpException('Incorrect document ID');
|
||||
}
|
||||
|
||||
$document = Document::getDocument($document_id);
|
||||
|
||||
if(empty($document)) {
|
||||
throw new NotFoundHttpException('There is no such document');
|
||||
}
|
||||
|
||||
return $document;
|
||||
}
|
||||
|
||||
public function actionCreateDocument()
|
||||
{
|
||||
$document = Yii::$app->getRequest()->getBodyParams();
|
||||
$documentFieldValues = Yii::$app->getRequest()->getBodyParams()['documentFieldValues'];
|
||||
|
||||
$tmp = TemplateDocumentField::find()->select('field_id')
|
||||
->where(['template_id' => 94])->asArray()->all();
|
||||
|
||||
$modelDocument = new Document();
|
||||
if ($modelDocument->load($document, '') && $modelDocument->save()) {
|
||||
|
||||
try {
|
||||
$this->createDocimentFields($documentFieldValues, $modelDocument->id, $modelDocument->template_id);
|
||||
}
|
||||
catch (ServerErrorHttpException $e) {
|
||||
$modelDocument->delete();
|
||||
throw new BadRequestHttpException(json_encode($e->getMessage()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new BadRequestHttpException(json_encode($modelDocument->errors));
|
||||
}
|
||||
|
||||
Yii::$app->getResponse()->setStatusCode(201);
|
||||
return Document::getDocument($modelDocument->id);
|
||||
}
|
||||
|
||||
private function createDocimentFields($documentFieldValues , $document_id, $template_id)
|
||||
{
|
||||
if (!empty($documentFieldValues)) {
|
||||
|
||||
$modelFieldsArray = array();
|
||||
|
||||
foreach ($documentFieldValues as $docFieldValue) {
|
||||
$tmpModelField = new DocumentFieldValue();
|
||||
|
||||
if ($tmpModelField->load($docFieldValue, '')) {
|
||||
$modelFieldsArray[] = $tmpModelField;
|
||||
}
|
||||
else {
|
||||
throw new ServerErrorHttpException(
|
||||
'Failed to load document field value where modelField: field_id=' . $tmpModelField->field_id . ' value=' . $tmpModelField->value);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($modelFieldsArray as $modelField) {
|
||||
|
||||
$modelField->document_id = $document_id;
|
||||
if (!$modelField->save()) {
|
||||
throw new ServerErrorHttpException(
|
||||
'Failed to save document field value where modelField: field_id=' . $modelField->field_id . ' value=' . $modelField->value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\modules\api\controllers;
|
||||
|
||||
use common\models\DocumentFieldValue;
|
||||
use Yii;
|
||||
use yii\filters\auth\HttpBearerAuth;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\rest\Controller;
|
||||
use yii\web\ServerErrorHttpException;
|
||||
|
||||
class DocumentFieldValueController extends Controller
|
||||
{
|
||||
public function behaviors(): array
|
||||
{
|
||||
$behaviors = parent::behaviors();
|
||||
|
||||
$behaviors['authenticator']['authMethods'] = [
|
||||
HttpBearerAuth::className(),
|
||||
];
|
||||
|
||||
return $behaviors;
|
||||
}
|
||||
|
||||
public function verbs(): array
|
||||
{
|
||||
return [
|
||||
// 'get-task' => ['get'],
|
||||
'document-field-value-list' => ['get'],
|
||||
// 'create-task' => ['post'],
|
||||
'update' => ['post'],
|
||||
];
|
||||
}
|
||||
|
||||
public function actionDocumentFieldValueList(): array
|
||||
{
|
||||
$document_id = Yii::$app->request->get('document_id');
|
||||
if(empty($document_id) or !is_numeric($document_id))
|
||||
{
|
||||
throw new NotFoundHttpException('Incorrect document ID');
|
||||
}
|
||||
|
||||
$fieldValues = DocumentFieldValue::find()
|
||||
->where(['document_id' => $document_id])
|
||||
->all();
|
||||
|
||||
if(empty($fieldValues)) {
|
||||
throw new NotFoundHttpException('There is no such fields');
|
||||
}
|
||||
|
||||
return $fieldValues;
|
||||
}
|
||||
|
||||
public function actionUpdate()
|
||||
{
|
||||
$model = $this->findModelDocumentFieldValue(Yii::$app->request->post('document_field_value_id'));
|
||||
if(empty($model)) {
|
||||
throw new NotFoundHttpException('The document field value does not exist');
|
||||
}
|
||||
|
||||
$model->load(Yii::$app->request->getBodyParams(), '');
|
||||
if ($model->save() === false && !$model->hasErrors()) {
|
||||
throw new ServerErrorHttpException('Failed to update the object for unknown reason.');
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
private function findModelDocumentFieldValue($document_field_value_id)
|
||||
{
|
||||
return DocumentFieldValue::findOne($document_field_value_id);
|
||||
}
|
||||
}
|
@ -9,8 +9,9 @@ use Yii;
|
||||
use yii\filters\auth\HttpBearerAuth;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\rest\Controller;
|
||||
|
||||
class ManagerController extends \yii\rest\Controller
|
||||
class ManagerController extends Controller
|
||||
{
|
||||
public function behaviors(): array
|
||||
{
|
||||
|
@ -6,15 +6,21 @@ use common\behaviors\GsCors;
|
||||
use common\classes\Debug;
|
||||
use common\models\InterviewRequest;
|
||||
use common\models\User;
|
||||
use common\models\UserCard;
|
||||
use common\services\ProfileService;
|
||||
use frontend\modules\api\models\ProfileSearchForm;
|
||||
use kavalar\BotNotificationTemplateProcessor;
|
||||
use kavalar\TelegramBotService;
|
||||
use Yii;
|
||||
use yii\filters\auth\CompositeAuth;
|
||||
use yii\filters\auth\HttpBearerAuth;
|
||||
use yii\filters\auth\QueryParamAuth;
|
||||
use yii\filters\ContentNegotiator;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\web\BadRequestHttpException;
|
||||
use yii\web\Response;
|
||||
|
||||
|
||||
class ProfileController extends ApiController
|
||||
{
|
||||
|
||||
@ -51,6 +57,35 @@ class ProfileController extends ApiController
|
||||
return $searchModel->byParams();
|
||||
}
|
||||
|
||||
public function actionProfileWithReportPermission($id)
|
||||
{
|
||||
$searchModel = new ProfileSearchForm();
|
||||
$searchModel->attributes = \Yii::$app->request->get();
|
||||
|
||||
$searcherUser = Yii::$app->user->getId();
|
||||
$searcherProfileId = UserCard::findOne($searcherUser)->id;
|
||||
|
||||
if ($id && $searcherProfileId) {
|
||||
if(!UserCard::find()->where(['id' => $id])->exists())
|
||||
{
|
||||
throw new BadRequestHttpException(json_encode('There is no user with this id'));
|
||||
}
|
||||
$profile = $searchModel->byId();
|
||||
|
||||
$profileService = new ProfileService($searcherProfileId, $id);
|
||||
|
||||
if($profileService->checkReportePermission()) {
|
||||
$profile += ['report_permission' => '1'];
|
||||
}
|
||||
else {
|
||||
$profile += ['report_permission' => '0'];
|
||||
}
|
||||
return $profile;
|
||||
}
|
||||
|
||||
throw new BadRequestHttpException(json_encode('Missing required parameter'));
|
||||
}
|
||||
|
||||
public function actionAddToInterview()
|
||||
{
|
||||
if (\Yii::$app->request->isPost) {
|
||||
|
64
frontend/modules/api/controllers/TemplateController.php
Normal file
64
frontend/modules/api/controllers/TemplateController.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\modules\api\controllers;
|
||||
|
||||
use common\models\Document;
|
||||
use common\models\Template;
|
||||
use Yii;
|
||||
use yii\filters\auth\HttpBearerAuth;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\rest\Controller;
|
||||
|
||||
class TemplateController extends Controller
|
||||
{
|
||||
public function behaviors(): array
|
||||
{
|
||||
$behaviors = parent::behaviors();
|
||||
|
||||
$behaviors['authenticator']['authMethods'] = [
|
||||
HttpBearerAuth::className(),
|
||||
];
|
||||
|
||||
return $behaviors;
|
||||
}
|
||||
|
||||
public function verbs(): array
|
||||
{
|
||||
return [
|
||||
'get-template-list' => ['get'],
|
||||
'get-template-fields' => ['get'],
|
||||
];
|
||||
}
|
||||
|
||||
public function actionGetTemplateList(): array
|
||||
{
|
||||
$template = Template::find()->asArray()->all();
|
||||
|
||||
if(empty($template)) {
|
||||
throw new NotFoundHttpException('Documents are not assigned');
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
public function actionGetTemplateFields(): array
|
||||
{
|
||||
$template_id = Yii::$app->request->get('template_id');
|
||||
if(empty($template_id) or !is_numeric($template_id))
|
||||
{
|
||||
throw new NotFoundHttpException('Incorrect template ID');
|
||||
}
|
||||
|
||||
$templates = Template::find()
|
||||
->joinWith('templateDocumentFields.field')
|
||||
->where(['template.id' => $template_id])
|
||||
->asArray()
|
||||
->all();
|
||||
|
||||
if(empty($templates)) {
|
||||
throw new NotFoundHttpException('Documents are not assigned');
|
||||
}
|
||||
|
||||
return $templates;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user