update api for manager

This commit is contained in:
iIronside 2022-01-05 17:11:31 +03:00
parent dccf3c012e
commit f9d3b654f6
18 changed files with 5080 additions and 49 deletions

View File

@ -6,10 +6,14 @@ use backend\modules\document\models\TemplateDocumentField;
use Yii;
use backend\modules\document\models\Template;
use backend\modules\document\models\TemplateSearch;
use yii\base\Exception;
use yii\data\ActiveDataProvider;
use yii\helpers\FileHelper;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\Response;
use yii\web\UploadedFile;
/**
* TemplateController implements the CRUD actions for Template model.
@ -72,14 +76,28 @@ class TemplateController extends Controller
/**
* Creates a new Template model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
* @return string|Response
* @throws Exception
*/
public function actionCreate()
{
$model = new Template();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
if ($model->load(Yii::$app->request->post())) {
$model->template = UploadedFile::getInstance($model, 'template');
if (!empty($model->template)) {
$pathToTemplates = Yii::getAlias('@templates');
$model->template_file_name = date('mdyHis') . '_' . $model->template->name;
if ($model->save()) {
if (FileHelper::createDirectory($pathToTemplates, $mode = 0775, $recursive = true)) {
$model->template->saveAs($pathToTemplates . '/' . $model->template_file_name);
}
return $this->redirect(['template-document-field/create', 'template_id' => $model->id]);
}
return $this->render('create', ['model' => $model]);
}
}
return $this->render('create', [
@ -97,11 +115,34 @@ class TemplateController extends Controller
public function actionUpdate($id)
{
$model = $this->findModel($id);
// $pathToFile = Yii::getAlias('@templates') . '/' . $model->template_file_name;
// if ($model->load(Yii::$app->request->post())) {
// $template = UploadedFile::getInstance($model, 'template');
//
// if (!empty($template)) {
// $path = Yii::getAlias('@frontend') . '/web/upload/documents/templates';
//
// $model->template = $template;
// $model->template_file_name = $model->template->name;
// $model->template_path = $path . '/' . $model->template->name;
//
// if (!$model->template->saveAs($path . '/' . $model->template->name)) {
// return $this->render('update', [
// 'model' => $model,
// ]);
// }
// }
// if ($model->save()) {
// return $this->redirect(['view', 'id' => $model->id]);
// }
// }
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
// $model->template = UploadedFile::getInstance($model, $pathToFile); // file($pathToFile);
return $this->render('update', [
'model' => $model,
]);

View File

@ -2,7 +2,6 @@
namespace backend\modules\document\models;
use Yii;
class Template extends \common\models\Template
{

View File

@ -18,7 +18,7 @@ class TemplateSearch extends Template
{
return [
[['id'], 'integer'],
[['title', 'created_at', 'updated_at'], 'safe'],
[['title', 'created_at', 'updated_at', 'template_file_name'], 'safe'],
];
}
@ -63,7 +63,8 @@ class TemplateSearch extends Template
'updated_at' => $this->updated_at,
]);
$query->andFilterWhere(['like', 'title', $this->title]);
$query->andFilterWhere(['like', 'title', $this->title])
->andFilterWhere(['like', 'template_file_name', $this->template_file_name]);
return $dataProvider;
}

View File

@ -1,5 +1,7 @@
<?php
use kartik\file\FileInput;
use mihaildev\elfinder\InputFile;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
@ -10,10 +12,18 @@ use yii\widgets\ActiveForm;
<div class="template-form">
<?php $form = ActiveForm::begin(); ?>
<?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>

View File

@ -0,0 +1,33 @@
<?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

@ -23,6 +23,7 @@ $this->params['breadcrumbs'][] = $this->title;
['class' => 'yii\grid\SerialColumn'],
'title',
// 'template_path',
'created_at',
'updated_at',

View File

@ -1,8 +1,9 @@
<?php
use backend\modules\document\models\DocumentField;
use backend\modules\document\models\Template;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\web\YiiAsset;
use yii\widgets\DetailView;
use yii\grid\GridView;
@ -13,7 +14,7 @@ use yii\grid\GridView;
$this->title = $model->title;
$this->params['breadcrumbs'][] = ['label' => 'Templates', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
YiiAsset::register($this);
?>
<div class="template-view">
@ -31,14 +32,56 @@ $this->params['breadcrumbs'][] = $this->title;
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'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',
'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',
]);
}
]
],
]) ?>
<?php
$button1 = Html::a('<i class="glyphicon glyphicon-trash"></i>', Url::to(['delete', 'id' => $model->id]), [
'title' => 'Eliminar',
'class' => 'pull-right detail-button',
'data' => [
'confirm' => '¿Realmente deseas eliminar este elemento?',
'method' => 'post',
]
]);
$button2 = Html::a('<i class="glyphicon glyphicon-pencil"></i>', Url::to(['actualizar', 'id' => $model->id]), [
'title' => 'Actualizar',
'class' => 'pull-right detail-button',
]);
?>
<div>
<h2>
<?= 'Поля шаблона:'?>

View File

@ -44,12 +44,17 @@
[
'label' => 'Документы', 'icon' => 'archive', 'url' => '#',
'items' => [
['label' => 'Документы', 'icon' => 'file', 'url' => ['/document/document'], 'active' => \Yii::$app->controller->id == 'document'],
['label' => 'Шаблоны', 'icon' => 'file-o', 'url' => ['/document/template'], 'active' => \Yii::$app->controller->id == 'template'],
['label' => 'Поля в шаблоне', 'icon' => 'file-text-o', 'url' => ['/document/template-document-field'], 'active' => \Yii::$app->controller->id == 'template-document-field'],
['label' => 'Поля документов', 'icon' => 'file-text', 'url' => ['/document/document-field'], 'active' => \Yii::$app->controller->id == 'document-field'],
['label' => 'Значения полей', 'icon' => 'bars', 'url' => ['/document/document-field-value'], 'active' => \Yii::$app->controller->id == 'document-field-value'],
['label' => 'Документы', 'icon' => 'file-text', 'url' => ['/document/document'], 'active' => \Yii::$app->controller->id == 'document'],
['label' => 'Шаблоны', 'icon' => 'file', 'url' => ['/document/template'], 'active' => \Yii::$app->controller->id == 'template'],
['label' => 'Поля документов', 'icon' => 'file-text-o', 'url' => ['/document/document-field'], 'active' => \Yii::$app->controller->id == 'document-field'],
[
'label' => 'Сохранённые значения', 'icon' => 'info-circle', 'url' => '#',
'items' => [
['label' => 'Поля в шаблоне', 'icon' => 'file-text-o', 'url' => ['/document/template-document-field'], 'active' => \Yii::$app->controller->id == 'template-document-field'],
['label' => 'Значения полей', 'icon' => 'bars', 'url' => ['/document/document-field-value'], 'active' => \Yii::$app->controller->id == 'document-field-value'],
]
]
],
'visible' => Yii::$app->user->can('confidential_information')
],

View File

@ -3,3 +3,4 @@ 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');

View File

@ -5,7 +5,6 @@ namespace common\models;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\Expression;
use yii\helpers\ArrayHelper;
/**
* This is the model class for table "template".
@ -14,12 +13,14 @@ use yii\helpers\ArrayHelper;
* @property string $title
* @property string $created_at
* @property string $updated_at
* @property string $template_file_name
*
* @property Document[] $documents
* @property TemplateDocumentField[] $templateDocumentFields
*/
class Template extends \yii\db\ActiveRecord
{
public $template;
/**
* {@inheritdoc}
*/
@ -47,7 +48,12 @@ class Template extends \yii\db\ActiveRecord
{
return [
[['created_at', 'updated_at'], 'safe'],
[['title'], 'string', 'max' => 255],
[['title'], 'unique'],
[['template_file_name', 'title'], 'required'],
[['template'], 'required', 'message'=>'Укажите путь к файлу'],
[['template'], 'file', 'maxSize' => '10000'],
[['template'], 'file', 'skipOnEmpty' => false, 'extensions' => 'doc, docx, txt'],
[['title', 'template_file_name'], 'string', 'max' => 255],
];
}
@ -61,6 +67,7 @@ class Template extends \yii\db\ActiveRecord
'title' => 'Название',
'created_at' => 'Дата создания',
'updated_at' => 'Дата изменения',
'template_file_name' => 'Файл шаблона',
];
}
@ -69,6 +76,14 @@ class Template extends \yii\db\ActiveRecord
foreach ($this->templateDocumentFields as $templateDocumentField){
$templateDocumentField->delete();
}
if (!empty($this->template_file_name)) {
$template_path = Yii::getAlias('@templates') . '/' . $this->template_file_name;
if(file_exists($template_path)) {
unlink($template_path);
}
}
return parent::beforeDelete();
}

View File

@ -225,6 +225,11 @@ class UserCard extends \yii\db\ActiveRecord
return $this->hasOne(Manager::class, ['user_card_id' => 'id']);
}
public function getManagerEmployee()
{
return $this->hasMany(ManagerEmployee::class, ['user_card_id' => 'id']);
}
public static function generateUserForUserCard($card_id = null)
{
$userCardQuery = self::find();

View File

@ -24,7 +24,7 @@
"kartik-v/yii2-widget-select2": "@dev",
"kavalar/hhapi": "@dev",
"mirocow/yii2-eav": "*",
"kartik-v/yii2-widget-fileinput": "^1.0",
"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",

20
composer.lock generated
View File

@ -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": "c1b5c9ed14985108b90f2db9fa60d08b",
"content-hash": "216b806f0c05ea29213238c495fe568f",
"packages": [
{
"name": "2amigos/yii2-file-upload-widget",
@ -1426,22 +1426,23 @@
},
{
"name": "kartik-v/yii2-widget-fileinput",
"version": "v1.1.0",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/kartik-v/yii2-widget-fileinput.git",
"reference": "d43bb9d9638ba117bbaa0045250645dc843fcf7f"
"reference": "d3caa4911ecd8125a5f87865807fa1de7f6cdba7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/kartik-v/yii2-widget-fileinput/zipball/d43bb9d9638ba117bbaa0045250645dc843fcf7f",
"reference": "d43bb9d9638ba117bbaa0045250645dc843fcf7f",
"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": ">=2.0.0"
"kartik-v/yii2-krajee-base": ">=3.0.1"
},
"default-branch": true,
"type": "yii2-extension",
"extra": {
"branch-alias": {
@ -1464,7 +1465,7 @@
"homepage": "http://www.krajee.com/"
}
],
"description": "An enhanced FileInput widget for Bootstrap 3.x & 4.x with file preview, multiple selection, and more features (sub repo split from yii2-widgets)",
"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",
@ -1479,7 +1480,7 @@
],
"support": {
"issues": "https://github.com/kartik-v/yii2-widget-fileinput/issues",
"source": "https://github.com/kartik-v/yii2-widget-fileinput/tree/v1.1.0"
"source": "https://github.com/kartik-v/yii2-widget-fileinput/tree/master"
},
"funding": [
{
@ -1487,7 +1488,7 @@
"type": "open_collective"
}
],
"time": "2020-10-23T19:54:51+00:00"
"time": "2021-09-03T10:14:31+00:00"
},
{
"name": "kartik-v/yii2-widget-select2",
@ -6497,6 +6498,7 @@
"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
},

View File

@ -0,0 +1,22 @@
<?php
use yii\db\Migration;
/**
* Class m211228_123343_add_column_template_file_to_template_table
*/
class m211228_123343_add_column_template_file_to_template_table extends Migration
{
public function safeUp()
{
$this->addColumn('template', 'template_file_name', $this->string(255));
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('template', 'template_file_name');
}
}

View File

@ -1023,12 +1023,12 @@
```json5
[
{
"username": "testUser",
"fio": "testUser",
"id": 1,
"email": "admin@admin.com"
},
{
"username": "workerTest22",
"fio": "workerTest22",
"id": 2,
"email": "awdsdse@njbhj.com"
}
@ -1056,10 +1056,10 @@
</tr>
<tr>
<td>
username
fio
</td>
<td>
Имя пользователя(логин)(varchar(255))
ФИО пользователя(varchar(255))
</td>
</tr>
<tr>
@ -1127,12 +1127,12 @@
[
{
"id": 2,
"username": "workerTest",
"fio": "workerTest",
"email": "testUseweewer@testUser.com",
},
{
"id": 4,
"username": "worker1",
"fio": "worker1",
"email": "sdfsdvdworker2",
},
]
@ -1154,15 +1154,15 @@
id
</td>
<td>
ID пользователя(работника)(int)
ID пользователя(работника) у менеджера(int)
</td>
</tr>
<tr>
<td>
username
fio
</td>
<td>
Логин(varchar(255))
ФИО сотрудника(varchar(255))
</td>
</tr>
<tr>
@ -1229,9 +1229,11 @@
```json5
[
{
"id": 1,
"username": "testUser",
"email": "admin@admin.com",
"id": 5,
"fio": "Иванов Иван Иванович",
"email": "testmail@mail.com",
"photo": "",
"gender": 0
}
]
```
@ -1252,15 +1254,15 @@
id
</td>
<td>
ID как пользователя(int)
ID пользователя(работника) у менеджера(int)
</td>
</tr>
<tr>
<td>
username
fio
</td>
<td>
Логин(varchar(255))
ФИО сотрудника(varchar(255))
</td>
</tr>
<tr>
@ -1268,7 +1270,7 @@
email
</td>
<td>
Электронная почта(string)
Почтовый адрес(string)
</td>
</tr>
</table>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -2,9 +2,9 @@
namespace frontend\modules\api\controllers;
use common\models\Manager;
use common\models\ManagerEmployee;
use common\models\User;
use common\models\UserCard;
use Yii;
use yii\filters\auth\HttpBearerAuth;
use yii\helpers\ArrayHelper;
@ -34,8 +34,8 @@ class ManagerController extends \yii\rest\Controller
public function actionGetManagerList(): array
{
$managers = User::find()->select(['username','manager.id' , 'email'])
->joinWith('manager')->where(['NOT',['manager.user_id' => null]])->all();
$managers = UserCard::find()->select(['fio','manager.id' , 'email'])
->joinWith('manager')->where(['NOT',['manager.user_card_id' => null]])->all();
if(empty($managers)) {
throw new NotFoundHttpException('Managers are not assigned');
@ -55,7 +55,8 @@ class ManagerController extends \yii\rest\Controller
throw new NotFoundHttpException('Incorrect manager ID');
}
$users_list = User::find()->select(['user.id', 'user.username', 'user.email'])
$users_list = UserCard::find()
->select(['manager_employee.id', 'user_card.fio', 'user_card.email'])
->joinWith('managerEmployee')
->where(['manager_employee.manager_id' => $manager_id])
->all();
@ -78,8 +79,8 @@ class ManagerController extends \yii\rest\Controller
throw new NotFoundHttpException('Incorrect manager ID');
}
$manager = User::find()
->select(['user.id', 'user.username', 'user.email'])
$manager = UserCard::find()
->select(['manager.id', 'fio', 'email', 'photo', 'gender'])
->joinWith('manager')->where(['manager.id' => $manager_id])
->all();