add company-manager role

This commit is contained in:
iIronside 2022-12-01 14:11:29 +03:00
parent 1f349aec84
commit 8cd2eebfee
28 changed files with 812 additions and 82 deletions

View File

@ -43,4 +43,5 @@ environments/ contains environment-based overrides
php yii migrate --migrationPath=@yii/rbac/migrations <br> php yii migrate --migrationPath=@yii/rbac/migrations <br>
и выполнить консольный скрипт <br> и выполнить консольный скрипт <br>
php yii rbac/init <br> php yii rbac/init <br>
php yii rbac/create-company-manager-role
</p> </p>

View File

@ -14,6 +14,12 @@ return [
'bootstrap' => ['log'], 'bootstrap' => ['log'],
'modules' => [ 'modules' => [
'permit' => [
'class' => 'developeruz\db_rbac\Yii2DbRbac',
'params' => [
'userClass' => 'common\models\User'
]
],
'accesses' => [ 'accesses' => [
'class' => 'backend\modules\accesses\Accesses', 'class' => 'backend\modules\accesses\Accesses',
], ],
@ -129,6 +135,8 @@ return [
'controller' => 'user-questionnaire', 'controller' => 'user-questionnaire',
'except' => ['delete', 'update'], 'except' => ['delete', 'update'],
], ],
'<module:\w+>/<controller:\w+>/<action:(\w|-)+>' => '<module>/<controller>/<action>',
'<module:\w+>/<controller:\w+>/<action:(\w|-)+>/<id:\d+>' => '<module>/<controller>/<action>',
], ],
], ],

View File

@ -1,8 +1,8 @@
<?php <?php
use asmoday74\ckeditor5\EditorClassic;
use backend\modules\card\models\ResumeTemplate; use backend\modules\card\models\ResumeTemplate;
use common\helpers\StatusHelper; use common\helpers\StatusHelper;
use mihaildev\ckeditor\CKEditor;
use mihaildev\elfinder\InputFile; use mihaildev\elfinder\InputFile;
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
@ -27,10 +27,11 @@ use yii\widgets\ActiveForm;
] ]
) ?> ) ?>
<?= $form->field($model, 'template_body')->widget(EditorClassic::className(), [ <?= $form->field($model, 'template_body')->widget(CKEditor::className(),[
'clientOptions' => [ 'editorOptions' => [
'language' => 'ru', 'preset' => 'full',
] 'inline' => false,
],
]); ?> ]); ?>
<?= $form->field($model, 'header_text')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'header_text')->textInput(['maxlength' => true]) ?>

View File

@ -1,9 +1,8 @@
<?php <?php
use yii\helpers\Html;
use yii\grid\GridView; use yii\grid\GridView;
use yii\helpers\Html;
use yii\helpers\Url; use yii\helpers\Url;
use yii\widgets\ListView;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $searchModel backend\modules\card\models\UserCardSearch */ /* @var $searchModel backend\modules\card\models\UserCardSearch */
@ -84,7 +83,16 @@ $this->params['breadcrumbs'][] = $this->title;
]), ]),
], ],
['class' => 'yii\grid\ActionColumn'], ['class' => 'yii\grid\ActionColumn',
'template' => '{view}&nbsp;&nbsp;{update}&nbsp;&nbsp;{permit}&nbsp;&nbsp;{delete}',
'buttons' =>
[
'permit' => function ($url, $model) {
return Html::a('<span class="glyphicon glyphicon-wrench"></span>', Url::to(['/permit/user/view', 'id' => $model->id_user]), [
'title' => Yii::t('yii', 'Change user role')
]); },
]
],
], ],
]); ]);
echo "<h3>Сумма зарплат: " . $searchModel->total . "</h3>"; echo "<h3>Сумма зарплат: " . $searchModel->total . "</h3>";

View File

@ -0,0 +1,145 @@
<?php
namespace backend\modules\company\controllers;
use common\classes\Debug;
use Yii;
use backend\modules\company\models\CompanyManager;
use backend\modules\company\models\CompanyManagerSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* CompanyManagerController implements the CRUD actions for CompanyManager model.
*/
class CompanyManagerController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all CompanyManager models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new CompanyManagerSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single CompanyManager 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 CompanyManager model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new CompanyManager();
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 CompanyManager 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 CompanyManager 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 CompanyManager model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return CompanyManager the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = CompanyManager::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
/**
* Deletes an existing CompanyManager 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 actionDismiss($id)
{
// Debug::dd('fff');
$model = $this->findModel($id);
$model->company_id = null;
$model->update(false);
return $this->redirect(['index']);
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace backend\modules\company\models;
use Yii;
class CompanyManager extends \common\models\CompanyManager
{
}

View File

@ -0,0 +1,67 @@
<?php
namespace backend\modules\company\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\company\models\CompanyManager;
/**
* CompanyManagerSearch represents the model behind the search form of `backend\modules\company\models\CompanyManager`.
*/
class CompanyManagerSearch extends CompanyManager
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id', 'company_id', 'user_card_id'], 'integer'],
];
}
/**
* {@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 = CompanyManager::find()->where(['not', ['company_id' => null]]);
// 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,
'company_id' => $this->company_id,
'user_card_id' => $this->user_card_id,
]);
return $dataProvider;
}
}

View File

@ -0,0 +1,38 @@
<?php
use backend\modules\card\models\UserCard;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\company\models\CompanyManager */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="company-manager-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'company_id')->dropDownList(
ArrayHelper::map(\backend\modules\company\models\Company::find()->all(), 'id', 'name'),
[
'prompt' => 'Выберите'
]
) ?>
<?= $form->field($model, 'user_card_id')->dropDownList(
ArrayHelper::map(UserCard::getCardByUserRole('company_manager'), 'id', 'fio'),
[
'prompt' => 'Выберите'
]
)
?>
<div class="form-group">
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,31 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\company\models\CompanyManagerSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="company-manager-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'company_id') ?>
<?= $form->field($model, 'user_card_id') ?>
<div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,18 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model backend\modules\company\models\CompanyManager */
$this->title = 'Добавить нового менеджера компании';
$this->params['breadcrumbs'][] = ['label' => 'Company Managers', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="company-manager-create">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,64 @@
<?php
use backend\modules\card\models\UserCard;
use backend\modules\company\models\Company;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $searchModel backend\modules\company\models\CompanyManagerSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Менеджеры компании';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="company-manager-index">
<p>
<?= Html::a('Добавить компании менеджера', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
// 'id',
[
'attribute' => 'company_id',
'filter' => Company::find()->select(['name', 'id'])->indexBy('id')->column(),
'value' => 'company.name',
],
[
'attribute' => 'user_card_id',
'filter' => ArrayHelper::map(UserCard::getCardByUserRole('company_manager'), 'id', 'fio'),
'value' => 'userCard.fio',
],
['class' => 'yii\grid\ActionColumn',
'template' => '{view}&nbsp;&nbsp;{update}&nbsp;&nbsp;{delete}',
'buttons' =>
[
// 'delete' => function ($url, $model) {
// return Html::a('<span class="glyphicon glyphicon-wrench"></span>', Url::to(['/company/company-manager/dismiss', 'id' => $model->id]), [
// 'title' => Yii::t('yii', 'Уволить менеджера из компании?')
// ]); },
'delete' => function ($url,$model) {
return Html::a(
'<span class="glyphicon glyphicon-trash"></span>',
[
'/company/company-manager/dismiss', 'id' => $model->id,
],
[
'data' => ['confirm' => 'Вы уверены, что хотите удалить этого менеджера?', 'method' => 'post']
]
);
},
]
],
]
]); ?>
</div>

View File

@ -0,0 +1,19 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model backend\modules\company\models\CompanyManager */
$this->title = 'Изменить менеджера компании: ' . $model->userCard->fio;
$this->params['breadcrumbs'][] = ['label' => 'Company Managers', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Update';
?>
<div class="company-manager-update">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,44 @@
<?php
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model backend\modules\company\models\CompanyManager */
$this->title = 'Менеджер: ' . $model->userCard->fio;
$this->params['breadcrumbs'][] = ['label' => 'Company Managers', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="company-manager-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' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
[
'attribute' => 'company_id',
'value' => ArrayHelper::getValue($model, 'company.name'),
],
[
'attribute' => 'user_card_id',
'value' => ArrayHelper::getValue($model, 'userCard.fio'),
],
],
]) ?>
</div>

View File

@ -2,6 +2,7 @@
namespace backend\modules\document\controllers; namespace backend\modules\document\controllers;
use backend\modules\company\models\CompanyManager;
use backend\modules\document\models\Document; use backend\modules\document\models\Document;
use backend\modules\document\models\DocumentSearch; use backend\modules\document\models\DocumentSearch;
use common\services\DocumentService; use common\services\DocumentService;
@ -9,6 +10,7 @@ use Yii;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
use yii\web\Controller; use yii\web\Controller;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\web\Response;
/** /**
* DocumentController implements the CRUD actions for Document model. * DocumentController implements the CRUD actions for Document model.
@ -175,7 +177,7 @@ class DocumentController extends Controller
$model->scenario = $model::SCENARIO_DOWNLOAD_DOCUMENT; $model->scenario = $model::SCENARIO_DOWNLOAD_DOCUMENT;
if ($model->validate()) { if ($model->validate()) {
DocumentService::downloadPdf($id); DocumentService::downloadDocx($id);
} }
Yii::$app->session->setFlash('error', $model->getFirstError('body')); Yii::$app->session->setFlash('error', $model->getFirstError('body'));
@ -183,4 +185,26 @@ class DocumentController extends Controller
'model' => Document::findOne($id) 'model' => Document::findOne($id)
]); ]);
} }
public function actionManagers(): array
{
Yii::$app->response->format = Response::FORMAT_JSON;
if (isset($_POST['depdrop_parents'])) {
$parents = $_POST['depdrop_parents'];
if ($parents != null) {
$company_id = $parents[0];
/** @var CompanyManager[] $managers */
$managers = CompanyManager::getManagersByCompany($company_id);
$formattedManagersArr = array();
foreach ($managers as $manager){
$formattedManagersArr[] = array('id' => $manager->id, 'name' => $manager->userCard->fio);
}
return ['output'=>$formattedManagersArr, 'selected'=>''];
}
}
return ['output'=>'', 'selected'=>''];
}
} }

View File

@ -1,6 +1,5 @@
<?php <?php
use asmoday74\ckeditor5\EditorClassic;
use backend\modules\document\models\DocumentField; use backend\modules\document\models\DocumentField;
use common\helpers\StatusHelper; use common\helpers\StatusHelper;
use mihaildev\ckeditor\CKEditor; use mihaildev\ckeditor\CKEditor;
@ -27,12 +26,6 @@ use yii\widgets\ActiveForm;
] ]
) ?> ) ?>
<!-- --><?//= $form->field($model, 'template_body')->widget(EditorClassic::className(), [
// 'clientOptions' => [
// 'language' => 'ru',
// ]
// ]); ?>
<?= $form->field($model, 'template_body')->widget(CKEditor::className(),[ <?= $form->field($model, 'template_body')->widget(CKEditor::className(),[
'editorOptions' => [ 'editorOptions' => [
'preset' => 'full', //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать 'preset' => 'full', //разработанны стандартные настройки basic, standard, full данную возможность не обязательно использовать
@ -51,6 +44,7 @@ use yii\widgets\ActiveForm;
<div class="col-md-4"> <div class="col-md-4">
<div class="table-responsive"> <div class="table-responsive">
<h2>Поля договоров</h2>
<table class="table" id="fieldNameTable"> <table class="table" id="fieldNameTable">
<thead> <thead>
<tr> <tr>

View File

@ -2,9 +2,10 @@
use backend\modules\company\models\Company; use backend\modules\company\models\Company;
use backend\modules\document\models\DocumentTemplate; use backend\modules\document\models\DocumentTemplate;
use backend\modules\employee\models\Manager; use kartik\depdrop\DepDrop;
use kartik\select2\Select2; use kartik\select2\Select2;
use yii\helpers\Html; use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
@ -16,48 +17,6 @@ use yii\widgets\ActiveForm;
<?php $form = ActiveForm::begin(); ?> <?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'company_id')->widget(Select2::class,
[
'data' => Company::find()->select(['name', 'id'])->indexBy('id')->column(),
'options' => ['placeholder' => '...','class' => 'form-control'],
'pluginOptions' => [
'allowClear' => true
],
]
); ?>
<?= $form->field($model, 'manager_id')->widget(Select2::class,
[
'data' => Manager::find()->select(['fio', 'manager.id'])
->joinWith('userCard')->indexBy('manager.id')->column(),
'options' => ['placeholder' => '...','class' => 'form-control'],
'pluginOptions' => [
'allowClear' => true
],
]
); ?>
<?= $form->field($model, 'contractor_company_id')->widget(Select2::class,
[
'data' => Company::find()->select(['name', 'id'])->indexBy('id')->column(),
'options' => ['placeholder' => '...','class' => 'form-control'],
'pluginOptions' => [
'allowClear' => true
],
]
); ?>
<?= $form->field($model, 'contractor_manager_id')->widget(Select2::class,
[
'data' => Manager::find()->select(['fio', 'manager.id'])
->joinWith('userCard')->indexBy('manager.id')->column(),
'options' => ['placeholder' => '...','class' => 'form-control'],
'pluginOptions' => [
'allowClear' => true
],
]
); ?>
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?> <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'template_id')->widget(Select2::class, <?= $form->field($model, 'template_id')->widget(Select2::class,
@ -70,6 +29,52 @@ use yii\widgets\ActiveForm;
] ]
); ?> ); ?>
<div>
<p>Не обязательные поля:</p>
</div>
<?= $form->field($model, 'company_id')->dropDownList(
Company::find()->select(['name', 'id'])->indexBy('id')->column(),
[
'id' => 'company-id',
'prompt' => 'Выберите'
]
);
?>
<?= $form->field($model, 'manager_id')->widget(DepDrop::className(),
[
'options' => ['id' => 'manager-id'],
'pluginOptions' => [
'depends' => ['company-id'],
'placeholder' => 'Выберите',
'url' => Url::to(['/document/document/managers'])
]
]
); ?>
<?= $form->field($model, 'contractor_company_id')->widget(Select2::class,
[
'data' => Company::find()->select(['name', 'id'])->indexBy('id')->column(),
'options' => ['id' => 'contractor-company-id','placeholder' => '...','class' => 'form-control'],
'pluginOptions' => [
'allowClear' => true
],
]
); ?>
<?= $form->field($model, 'contractor_manager_id')->widget(DepDrop::className(),
[
'options' => ['id' => 'contractor-manager-id'],
'pluginOptions' => [
'depends' => ['contractor-company-id'],
'placeholder' => 'Выберите',
'url' => Url::to(['/document/document/managers']),
'params' => ['contractor-company-id']
]
]
); ?>
<div class="form-group"> <div class="form-group">
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?> <?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
</div> </div>

View File

@ -1,6 +1,6 @@
<?php <?php
use asmoday74\ckeditor5\EditorClassic; use mihaildev\ckeditor\CKEditor;
use yii\helpers\Html; use yii\helpers\Html;
use yii\helpers\Url; use yii\helpers\Url;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
@ -27,11 +27,13 @@ $this->params['breadcrumbs'][] = 'Загрузить';
'action' => Url::to(['document/update-document-body', 'id' => $model->id]), 'action' => Url::to(['document/update-document-body', 'id' => $model->id]),
'options' => ['method' => 'post']]) 'options' => ['method' => 'post']])
?> ?>
<?= $form->field($model, 'body')->widget(EditorClassic::className(), [
'clientOptions' => [ <?= $form->field($model, 'body')->widget(CKEditor::className(),[
'language' => 'ru', 'editorOptions' => [
] 'preset' => 'full',
]); ?> 'inline' => false,
],
]); ?>
<div class="form-group"> <div class="form-group">
<?= Html::submitButton('Сохраниить изменения', ['class' => 'btn btn-primary']) ?> <?= Html::submitButton('Сохраниить изменения', ['class' => 'btn btn-primary']) ?>

View File

@ -30,6 +30,13 @@
['label' => 'Шаблоны резюме', 'icon' => 'address-card ', 'url' => ['/card/resume-template'], 'active' => \Yii::$app->controller->id == 'resume-template'], ['label' => 'Шаблоны резюме', 'icon' => 'address-card ', 'url' => ['/card/resume-template'], 'active' => \Yii::$app->controller->id == 'resume-template'],
['label' => 'Шаблоны документов', 'icon' => 'file', 'url' => ['/document/document-template'], 'active' => \Yii::$app->controller->id == 'document-template'], ['label' => 'Шаблоны документов', 'icon' => 'file', 'url' => ['/document/document-template'], 'active' => \Yii::$app->controller->id == 'document-template'],
['label' => 'Поля документов', 'icon' => 'file-text', 'url' => ['/document/document-field'], 'active' => \Yii::$app->controller->id == 'document-field'], ['label' => 'Поля документов', 'icon' => 'file-text', 'url' => ['/document/document-field'], 'active' => \Yii::$app->controller->id == 'document-field'],
[
'label' => 'Роли', 'icon' => 'users', 'url' => '#',
'items' => [
['label' => 'Управление ролями', 'icon' => ' fa-sort-amount-asc', 'url' => ['/permit/access/role'], 'active' => \Yii::$app->controller->id == 'access'],
['label' => 'Правила доступа', 'icon' => 'list-alt', 'url' => ['/permit/access/permission'], 'active' => \Yii::$app->controller->id == 'access'],
]
]
], ],
'visible' => Yii::$app->user->can('confidential_information') 'visible' => Yii::$app->user->can('confidential_information')
], ],
@ -60,7 +67,14 @@
], ],
'visible' => Yii::$app->user->can('confidential_information') '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' => '#',
'items' => [
['label' => 'Компании', 'icon' => 'building-o', 'url' => ['/company/company'], 'active' => \Yii::$app->controller->id == 'company'],
['label' => 'Менеджеры компаний', 'icon' => 'user-circle-o', 'url' => ['/company/company-manager'], 'active' => \Yii::$app->controller->id == 'company-manager'],
],
'visible' => Yii::$app->user->can('confidential_information')
],
[ [
'label' => 'Hh.ru', 'icon' => 'user-circle', 'url' => '#', 'label' => 'Hh.ru', 'icon' => 'user-circle', 'url' => '#',
'items' => [ 'items' => [

View File

@ -0,0 +1,74 @@
<?php
namespace common\models;
use Yii;
use yii\helpers\ArrayHelper;
/**
* This is the model class for table "company_manager".
*
* @property int $id
* @property int $company_id
* @property int $user_card_id
*
* @property Company $company
* @property UserCard $userCard
*/
class CompanyManager extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'company_manager';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['company_id', 'user_card_id'], 'required'],
[['company_id', 'user_card_id'], 'integer'],
['user_card_id', 'unique', 'targetAttribute' => ['company_id', 'user_card_id'], 'message'=>'Этот менеджер уже закреплён за компанией'],
[['company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::className(), 'targetAttribute' => ['company_id' => 'id']],
[['user_card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['user_card_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'company_id' => 'Компания',
'user_card_id' => 'Менеджер',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getCompany()
{
return $this->hasOne(Company::className(), ['id' => 'company_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUserCard()
{
return $this->hasOne(UserCard::className(), ['id' => 'user_card_id']);
}
public static function getManagersByCompany($company_id): array
{
return self::find()->where(['company_id' => $company_id])->all();
}
}

View File

@ -21,9 +21,9 @@ use yii\db\Expression;
* *
* @property Company $company * @property Company $company
* @property Company $contractorCompany * @property Company $contractorCompany
* @property Manager $contractorManager * @property CompanyManager $contractorManager
* @property DocumentTemplate $template * @property DocumentTemplate $template
* @property Manager $manager * @property CompanyManager $manager
*/ */
class Document extends \yii\db\ActiveRecord class Document extends \yii\db\ActiveRecord
{ {
@ -56,19 +56,19 @@ class Document extends \yii\db\ActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['company_id', 'contractor_company_id', 'manager_id', 'contractor_manager_id', 'title', 'template_id'], 'required'], [['title', 'template_id'], 'required'],
[['company_id', 'contractor_company_id', 'manager_id', 'contractor_manager_id', 'template_id'], 'integer'], [['company_id', 'contractor_company_id', 'manager_id', 'contractor_manager_id', 'template_id'], 'integer'],
[['body'], 'string'], [['body'], 'string'],
[['created_at', 'updated_at'], 'safe'], [['created_at', 'updated_at'], 'safe'],
[['title'], 'string', 'max' => 255], [['title'], 'string', 'max' => 255],
[['company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::className(), 'targetAttribute' => ['company_id' => 'id']], [['company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::className(), 'targetAttribute' => ['company_id' => 'id']],
[['contractor_company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::className(), 'targetAttribute' => ['contractor_company_id' => 'id']], [['contractor_company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::className(), 'targetAttribute' => ['contractor_company_id' => 'id']],
[['contractor_manager_id'], 'exist', 'skipOnError' => true, 'targetClass' => Manager::className(), 'targetAttribute' => ['contractor_manager_id' => 'id']], [['contractor_manager_id'], 'exist', 'skipOnError' => true, 'targetClass' => CompanyManager::className(), 'targetAttribute' => ['contractor_manager_id' => 'id']],
[['template_id'], 'exist', 'skipOnError' => true, 'targetClass' => DocumentTemplate::className(), 'targetAttribute' => ['template_id' => 'id']], [['template_id'], 'exist', 'skipOnError' => true, 'targetClass' => DocumentTemplate::className(), 'targetAttribute' => ['template_id' => 'id']],
[['manager_id'], 'exist', 'skipOnError' => true, 'targetClass' => Manager::className(), 'targetAttribute' => ['manager_id' => 'id']], [['manager_id'], 'exist', 'skipOnError' => true, 'targetClass' => CompanyManager::className(), 'targetAttribute' => ['manager_id' => 'id']],
['body', 'required', 'on' => self::SCENARIO_UPDATE_DOCUMENT_BODY], ['body', 'required', 'on' => self::SCENARIO_UPDATE_DOCUMENT_BODY],
['body', function ($attribute, $params) { ['body', function ($attribute, $params) {
preg_match_all('/(\${\w+|№|№+w})/', $this->$attribute,$out); preg_match_all('/\${(\w+|№|№+w)}/', $this->$attribute,$out);
if (!empty($out[0])) { if (!empty($out[0])) {
$this->addError('body', 'В теле документа все переменные должны быть заменены!'); $this->addError('body', 'В теле документа все переменные должны быть заменены!');
} }
@ -125,7 +125,7 @@ class Document extends \yii\db\ActiveRecord
*/ */
public function getContractorManager() public function getContractorManager()
{ {
return $this->hasOne(Manager::className(), ['id' => 'contractor_manager_id']); return $this->hasOne(CompanyManager::className(), ['id' => 'contractor_manager_id']);
} }
/** /**
@ -133,6 +133,6 @@ class Document extends \yii\db\ActiveRecord
*/ */
public function getManager() public function getManager()
{ {
return $this->hasOne(Manager::className(), ['id' => 'manager_id']); return $this->hasOne(CompanyManager::className(), ['id' => 'manager_id']);
} }
} }

View File

@ -2,6 +2,7 @@
namespace common\models; namespace common\models;
use developeruz\db_rbac\interfaces\UserRbacInterface;
use Yii; use Yii;
use yii\behaviors\TimestampBehavior; use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord; use yii\db\ActiveRecord;
@ -23,7 +24,7 @@ use yii\web\UnauthorizedHttpException;
* @property $access_token_expired_at * @property $access_token_expired_at
* @property string $password write-only password * @property string $password write-only password
*/ */
class User extends ActiveRecord implements IdentityInterface class User extends ActiveRecord implements IdentityInterface, UserRbacInterface
{ {
const STATUS_DELETED = 0; const STATUS_DELETED = 0;
const STATUS_ACTIVE = 10; const STATUS_ACTIVE = 10;
@ -76,6 +77,11 @@ class User extends ActiveRecord implements IdentityInterface
return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]); return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]);
} }
public function getUserName()
{
return $this->username;
}
public function generateAccessToken() public function generateAccessToken()
{ {
$this->access_token = Yii::$app->security->generateRandomString(); $this->access_token = Yii::$app->security->generateRandomString();

View File

@ -63,7 +63,6 @@ class UserCard extends \yii\db\ActiveRecord
const SCENARIO_UPDATE_RESUME_TEXT = 'update_resume_text'; const SCENARIO_UPDATE_RESUME_TEXT = 'update_resume_text';
const SCENARIO_DOWNLOAD_RESUME = 'download_resume_text'; const SCENARIO_DOWNLOAD_RESUME = 'download_resume_text';
// public $resumeTemplateId;
/** /**
* @return string[] * @return string[]
@ -251,6 +250,14 @@ class UserCard extends \yii\db\ActiveRecord
return $this->hasMany(ManagerEmployee::class, ['user_card_id' => 'id']); return $this->hasMany(ManagerEmployee::class, ['user_card_id' => 'id']);
} }
/**
* @return \yii\db\ActiveQuery
*/
public function getCompanyManagers()
{
return $this->hasMany(CompanyManager::className(), ['user_card_id' => 'id']);
}
public static function generateUserForUserCard($card_id = null) public static function generateUserForUserCard($card_id = null)
{ {
$userCardQuery = self::find(); $userCardQuery = self::find();
@ -327,4 +334,12 @@ class UserCard extends \yii\db\ActiveRecord
return $userCard['id']; return $userCard['id'];
} }
public static function getCardByUserRole($role): array
{
$auth = Yii::$app->authManager;
$usersId = $auth->getUserIdsByRole($role);
return UserCard::find()->where([ 'IN', 'id_user', $usersId])->all();
}
} }

View File

@ -54,7 +54,6 @@ class DocumentService
$pdf = new Pdf(); // or new Pdf(); $pdf = new Pdf(); // or new Pdf();
$mpdf = $pdf->api; // fetches mpdf api $mpdf = $pdf->api; // fetches mpdf api
$mpdf->SetFooter('{PAGENO}');
$mpdf->WriteHtml($model->body); // call mpdf write html $mpdf->WriteHtml($model->body); // call mpdf write html
echo $mpdf->Output("{$model->title}", 'D'); // call the mpdf api output as needed echo $mpdf->Output("{$model->title}", 'D'); // call the mpdf api output as needed
} }
@ -67,11 +66,11 @@ class DocumentService
// (B) ADD HTML CONTENT // (B) ADD HTML CONTENT
$section = $pw->addSection(); $section = $pw->addSection();
$documentText = str_replace(array('<br/>', '<br>', '</br>'), ' ', $model->body);
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $documentText, false, false);
// (C) SAVE TO DOCX ON SERVER $html = str_replace(array('<br/>', '<br>', '</br>'), ' ', $model->body);
// $pw->save("convert.docx", "Word2007"); \PhpOffice\PhpWord\Shared\Html::addHtml($section, $html, false, false);
$section->setStyle();
// (D) OR FORCE DOWNLOAD // (D) OR FORCE DOWNLOAD
header("Content-Type: application/octet-stream"); header("Content-Type: application/octet-stream");

View File

@ -36,7 +36,8 @@
"phpoffice/phpword": "^0.18.2", "phpoffice/phpword": "^0.18.2",
"kartik-v/yii2-widget-fileinput": "@dev", "kartik-v/yii2-widget-fileinput": "@dev",
"kartik-v/yii2-mpdf": "dev-master", "kartik-v/yii2-mpdf": "dev-master",
"mihaildev/yii2-ckeditor": "*" "mihaildev/yii2-ckeditor": "*",
"developeruz/yii2-db-rbac": "*"
}, },
"require-dev": { "require-dev": {
"yiisoft/yii2-debug": "~2.0.0", "yiisoft/yii2-debug": "~2.0.0",

View File

@ -35,6 +35,20 @@ class RbacController extends Controller
$auth->assign($admin, 1); $auth->assign($admin, 1);
} }
/**
* Add company manager role
*/
public function actionCreateCompanyManagerRole()
{
$auth = Yii::$app->getAuthManager();
$role = $auth->createRole('company_manager');
$role->description = 'Менеджер компании контр агента';
$auth->add($role);
$this->stdout('Done!' . PHP_EOL);
}
public function actionCreateEditor() public function actionCreateEditor()
{ {
$auth = Yii::$app->authManager; $auth = Yii::$app->authManager;

View File

@ -0,0 +1,47 @@
<?php
use yii\db\Migration;
/**
* Class m221128_114458_make_nullable_company_id_contractor_company_id_manager_id_columns_in_document_table
*/
class m221128_114458_make_nullable_company_id_contractor_company_id_manager_id_columns_in_document_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->alterColumn('document', 'company_id', $this->integer(11)->null());
$this->alterColumn('document', 'contractor_company_id', $this->integer(11)->null());
$this->alterColumn('document', 'manager_id', $this->integer(11)->null());
$this->alterColumn('document', 'contractor_manager_id', $this->integer(11)->null());
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->alterColumn('document', 'company_id', $this->integer(11)->notNull());
$this->alterColumn('document', 'contractor_company_id', $this->integer(11)->notNull());
$this->alterColumn('document', 'manager_id', $this->integer(11)->notNull());
$this->alterColumn('document', 'contractor_manager_id', $this->integer(11)->notNull());
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m221128_114458_make_nullable_company_id_contractor_company_id_manager_id_columns_in_document_table cannot be reverted.\n";
return false;
}
*/
}

View File

@ -0,0 +1,33 @@
<?php
use yii\db\Migration;
/**
* Handles the creation of table `{{%company_manager}}`.
*/
class m221129_100558_create_company_manager_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->createTable('{{%company_manager}}', [
'id' => $this->primaryKey(),
'company_id' => $this->integer(),
'user_card_id' => $this->integer(),
]);
$this->addForeignKey('company_company_manager', 'company_manager', 'company_id', 'company', 'id');
$this->addForeignKey('user_card_company_manager', 'company_manager', 'user_card_id', 'user_card', 'id');
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropForeignKey('company_company_manager', 'company_manager');
$this->dropForeignKey('user_card_company_manager', 'company_manager');
$this->dropTable('{{%company_manager}}');
}
}

View File

@ -0,0 +1,48 @@
<?php
use yii\db\Migration;
/**
* Class m221130_090104_change_keys_in_document_table_from_manager_to_company_manager
*/
class m221130_090104_change_keys_in_document_table_from_manager_to_company_manager extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->dropForeignKey('manager_document', 'document');
$this->dropForeignKey('contractor_manager_document', 'document');
$this->addForeignKey('company_manager_document', 'document', 'manager_id', 'company_manager', 'id');
$this->addForeignKey('contractor_company_manager_document', 'document', 'contractor_manager_id', 'company_manager', 'id');
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropForeignKey('company_manager_document', 'document');
$this->dropForeignKey('contractor_company_manager_document', 'document');
$this->addForeignKey('manager_document', 'document', 'manager_id','manager', 'id');
$this->addForeignKey('contractor_manager_document', 'document', 'contractor_manager_id','manager', 'id');
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m221130_090104_change_keys_in_document_table_from_manager_to_company_manager cannot be reverted.\n";
return false;
}
*/
}