Merge pull request #81 from apuc/add_task

Add task
This commit is contained in:
kavalar 2021-12-23 11:51:56 +03:00 committed by GitHub
commit 164771dc89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 3797 additions and 148 deletions

View File

@ -57,7 +57,7 @@ class ManagerController extends Controller
$model = $this->findModel($id); $model = $this->findModel($id);
$managerEmployeeSearchModel = new ManagerEmployeeSearch(); $managerEmployeeSearchModel = new ManagerEmployeeSearch();
$managerEmployeeDataProvider = new ActiveDataProvider([ $managerEmployeeDataProvider = new ActiveDataProvider([
'query' => $model->getManagerEmployees()->with('user'), 'query' => $model->getManagerEmployees()->with('userCard'),
'pagination' => [ 'pagination' => [
'pageSize' => 20, 'pageSize' => 20,
], ],

View File

@ -5,6 +5,7 @@ namespace backend\modules\employee\controllers;
use Yii; use Yii;
use backend\modules\employee\models\ManagerEmployee; use backend\modules\employee\models\ManagerEmployee;
use backend\modules\employee\models\ManagerEmployeeSearch; use backend\modules\employee\models\ManagerEmployeeSearch;
use yii\helpers\ArrayHelper;
use yii\web\Controller; use yii\web\Controller;
use yii\web\NotFoundHttpException; use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter; use yii\filters\VerbFilter;
@ -64,12 +65,31 @@ class ManagerEmployeeController extends Controller
*/ */
public function actionCreate() public function actionCreate()
{ {
$model = new ManagerEmployee();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
$post = $post = \Yii::$app->request->post('ManagerEmployee');
if (!empty($post)) {
$user_card_id_arr = ArrayHelper::getValue($post,'user_card_id');
foreach ($user_card_id_arr as $user_card_id) {
$emtModel = new ManagerEmployee();
$emtModel->manager_id = $post['manager_id'];
$emtModel->user_card_id = $user_card_id;
if (!$emtModel->save()) {
return $this->render('create', [
'model' => $emtModel,
]);
}
}
return $this->redirect(['index']);
} }
$model = new ManagerEmployee();
return $this->render('create', [ return $this->render('create', [
'model' => $model, 'model' => $model,
]); ]);

View File

@ -17,7 +17,7 @@ class ManagerEmployeeSearch extends ManagerEmployee
public function rules() public function rules()
{ {
return [ return [
[['id', 'manager_id', 'employee_id'], 'integer'], [['id', 'manager_id', 'user_card_id'], 'integer'],
]; ];
} }
@ -39,7 +39,7 @@ class ManagerEmployeeSearch extends ManagerEmployee
*/ */
public function search($params) public function search($params)
{ {
$query = ManagerEmployee::find()->joinWith(['user', 'manager']); $query = ManagerEmployee::find()->joinWith(['userCard', 'manager']);
// add conditions that should always apply here // add conditions that should always apply here
@ -59,7 +59,7 @@ class ManagerEmployeeSearch extends ManagerEmployee
$query->andFilterWhere([ $query->andFilterWhere([
'id' => $this->id, 'id' => $this->id,
'manager_id' => $this->manager_id, 'manager_id' => $this->manager_id,
'employee_id' => $this->employee_id, 'user_card_id' => $this->user_card_id,
]); ]);
return $dataProvider; return $dataProvider;

View File

@ -17,7 +17,7 @@ class ManagerSearch extends Manager
public function rules() public function rules()
{ {
return [ return [
[['id', 'user_id'], 'integer'], [['id', 'user_card_id'], 'integer'],
]; ];
} }
@ -39,7 +39,7 @@ class ManagerSearch extends Manager
*/ */
public function search($params) public function search($params)
{ {
$query = Manager::find()->with('user'); $query = Manager::find()->with('userCard');
// add conditions that should always apply here // add conditions that should always apply here
@ -58,7 +58,7 @@ class ManagerSearch extends Manager
// grid filtering conditions // grid filtering conditions
$query->andFilterWhere([ $query->andFilterWhere([
'id' => $this->id, 'id' => $this->id,
'user_id' => $this->user_id, 'user_card_id' => $this->user_card_id,
]); ]);
return $dataProvider; return $dataProvider;

View File

@ -1,7 +1,7 @@
<?php <?php
use backend\modules\card\models\UserCard;
use backend\modules\employee\models\Manager; use backend\modules\employee\models\Manager;
use common\models\User;
use kartik\select2\Select2; use kartik\select2\Select2;
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
@ -17,26 +17,27 @@ use yii\widgets\ActiveForm;
<?= $form->field($model, 'manager_id')->widget(Select2::className(), <?= $form->field($model, 'manager_id')->widget(Select2::className(),
[ [
'data' => Manager::find()->select(['username', 'manager.id']) 'data' => Manager::find()->select(['fio', 'manager.id'])
->joinWith('user')->indexBy('manager.id')->column(), ->joinWith('userCard')->indexBy('manager.id')->column(),
'options' => ['placeholder' => '...','class' => 'form-control'], 'options' => ['placeholder' => '...','class' => 'form-control'],
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true 'allowClear' => true
], ],
]) ?> ]) ?>
<?= $form->field($model, 'employee_id')->widget(Select2::className(), <?= $form->field($model, 'user_card_id')->widget(Select2::className(),
[ [
'data' => User::find()->select(['username', 'user.id']) 'data' => UserCard::find()->select(['fio', 'user_card.id'])
->joinWith('manager')->where(['manager.user_id' => null])->indexBy('user.id')->column(), ->joinWith('manager')->where(['manager.user_card_id' => null])->indexBy('user_card.id')->column(),
'options' => ['placeholder' => '...','class' => 'form-control'], 'options' => ['placeholder' => '...','class' => 'form-control'],
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true 'allowClear' => true,
'multiple' => true,
], ],
]) ?> ]) ?>
<div class="form-group"> <div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?> <?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
</div> </div>
<?php ActiveForm::end(); ?> <?php ActiveForm::end(); ?>

View File

@ -1,5 +1,7 @@
<?php <?php
use backend\modules\card\models\UserCard;
use common\models\ManagerEmployee;
use common\models\User; use common\models\User;
use yii\helpers\Html; use yii\helpers\Html;
use yii\grid\GridView; use yii\grid\GridView;
@ -24,15 +26,17 @@ $this->params['breadcrumbs'][] = $this->title;
['class' => 'yii\grid\SerialColumn'], ['class' => 'yii\grid\SerialColumn'],
[ [
'attribute' => 'manager_id', 'attribute' => 'manager_id',
'filter' => User::find()->select(['username', 'user.id']) 'filter' => UserCard::find()->select(['fio', 'user_card.id'])
->joinWith('manager')->where(['not',['manager.user_id' => null]])->indexBy('user.id')->column(), ->joinWith('manager')->where(['not',['manager.user_card_id' => null]])
'value' => 'manager.user.username', ->indexBy('user_card.id')->column(),
'value' => 'manager.userCard.fio',
], ],
[ [
'attribute' => 'employee_id', 'attribute' => 'user_card_id',
'filter' => User::find()->select(['username', 'user.id']) 'filter' => ManagerEmployee::find()->select(['fio', 'manager_employee.id'])
->joinWith('manager')->where(['manager.user_id' => null])->indexBy('user.id')->column(), ->joinWith('userCard')
'value' => 'user.username', ->indexBy('manager_employee.id')->column(),
'value' => 'userCard.fio',
], ],
['class' => 'yii\grid\ActionColumn'], ['class' => 'yii\grid\ActionColumn'],
], ],

View File

@ -36,11 +36,11 @@ YiiAsset::register($this);
'id', 'id',
[ [
'attribute' => 'manager_id', 'attribute' => 'manager_id',
'value' => ArrayHelper::getValue($model,'manager.user.username'), 'value' => ArrayHelper::getValue($model,'manager.userCard.fio'),
], ],
[ [
'attribute' => 'employee_id', 'attribute' => 'employee_id',
'value' => ArrayHelper::getValue($model,'user.username'), 'value' => ArrayHelper::getValue($model,'userCard.fio'),
], ],
], ],
]) ?> ]) ?>

View File

@ -1,5 +1,6 @@
<?php <?php
use backend\modules\card\models\UserCard;
use common\models\User; use common\models\User;
use yii\helpers\Html; use yii\helpers\Html;
use yii\widgets\ActiveForm; use yii\widgets\ActiveForm;
@ -14,10 +15,11 @@ use kartik\select2\Select2;
<?php $form = ActiveForm::begin(); ?> <?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'user_id')->widget(Select2::className(), <?= $form->field($model, 'user_card_id')->widget(Select2::className(),
[ [
'data' => User::find()->select(['username', 'user.id']) 'data' => UserCard::find()->select(['user_card.fio', 'user_card.id'])
->joinWith('manager')->where(['manager.user_id' => null])->indexBy('user.id')->column(), ->joinWith('manager')->where(['manager.user_card_id' => null])
->indexBy('user_card.id')->column(),
'options' => ['placeholder' => '...','class' => 'form-control'], 'options' => ['placeholder' => '...','class' => 'form-control'],
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true 'allowClear' => true

View File

@ -1,5 +1,6 @@
<?php <?php
use backend\modules\card\models\UserCard;
use common\models\User; use common\models\User;
use yii\helpers\Html; use yii\helpers\Html;
use yii\grid\GridView; use yii\grid\GridView;
@ -23,9 +24,9 @@ $this->params['breadcrumbs'][] = $this->title;
'columns' => [ 'columns' => [
['class' => 'yii\grid\SerialColumn'], ['class' => 'yii\grid\SerialColumn'],
[ [
'attribute' => 'user_id', 'attribute' => 'user_card_id',
'filter' => User::find()->select(['username', 'id'])->indexBy('id')->column(), 'filter' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
'value' => 'user.username', 'value' => 'userCard.fio',
], ],

View File

@ -1,5 +1,6 @@
<?php <?php
use backend\modules\card\models\UserCard;
use common\models\User; use common\models\User;
use kartik\grid\GridView; use kartik\grid\GridView;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
@ -37,7 +38,7 @@ YiiAsset::register($this);
'id', 'id',
[ [
'attribute' => 'user_id', 'attribute' => 'user_id',
'value' => ArrayHelper::getValue($model,'user.username'), 'value' => ArrayHelper::getValue($model,'userCard.fio'),
], ],
], ],
]) ?> ]) ?>
@ -47,9 +48,9 @@ YiiAsset::register($this);
'columns' => [ 'columns' => [
['class' => 'yii\grid\SerialColumn'], ['class' => 'yii\grid\SerialColumn'],
[ [
'attribute' => 'user_id', 'attribute' => 'user_card_id',
'filter' => User::find()->select(['username', 'id'])->indexBy('id')->column(), 'filter' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
'value' => 'user.username', 'value' => 'userCard.fio',
], ],
[ [
'class' => 'yii\grid\ActionColumn', 'class' => 'yii\grid\ActionColumn',

View File

@ -72,22 +72,20 @@ class ProjectUserController extends Controller
$post = \Yii::$app->request->post('ProjectUser'); $post = \Yii::$app->request->post('ProjectUser');
if (!empty($post)) { if (!empty($post)) {
$user_id_arr = ArrayHelper::getValue($post, 'user_id'); $card_id_arr = ArrayHelper::getValue($post, 'card_id');
$project_id = $post['project_id']; $project_id = $post['project_id'];
foreach ($user_id_arr as $user_id) { foreach ($card_id_arr as $card_id) {
$emtModel = new ProjectUser(); $emtModel = new ProjectUser();
$emtModel->project_id = $project_id; $emtModel->project_id = $project_id;
$emtModel->user_id = $user_id; $emtModel->card_id = $card_id;
$emtModel->card_id = UserCard::getIdByUserId($user_id); $emtModel->user_id = UserCard::getUserIdByCardId($card_id);
$emtModel->save(); if (!$emtModel->save()) {
return $this->render('create', [
// if (!$emtModel->save()) { 'model' => $emtModel,
// return $this->render('create', [ ]);
// 'model' => $emtModel, }
// ]);
// }
} }
return $this->redirect(['index']); return $this->redirect(['index']);
} }
@ -110,7 +108,7 @@ class ProjectUserController extends Controller
$model = $this->findModel($id); $model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) ) { if ($model->load(Yii::$app->request->post()) ) {
$model->card_id = UserCard::getIdByUserId($model->user_id); $model->user_id = UserCard::getUserIdByCardId($model->card_id);//UserCard::getIdByUserId($model->user_id);
if ($model->save()) { if ($model->save()) {
return $this->redirect(['view', 'id' => $model->id]); return $this->redirect(['view', 'id' => $model->id]);
} }

View File

@ -1,5 +1,6 @@
<?php <?php
use backend\modules\card\models\UserCard;
use backend\modules\project\models\Project; use backend\modules\project\models\Project;
use common\models\User; use common\models\User;
use kartik\select2\Select2; use kartik\select2\Select2;
@ -25,9 +26,9 @@ use yii\widgets\ActiveForm;
] ]
) ?> ) ?>
<?= $form->field($model, 'user_id')->widget(Select2::className(), <?= $form->field($model, 'card_id')->widget(Select2::className(),
[ [
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(), 'data' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
'options' => ['placeholder' => '...','class' => 'form-control'], 'options' => ['placeholder' => '...','class' => 'form-control'],
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true, 'allowClear' => true,

View File

@ -1,5 +1,6 @@
<?php <?php
use backend\modules\card\models\UserCard;
use backend\modules\project\models\Project; use backend\modules\project\models\Project;
use common\models\User; use common\models\User;
use kartik\select2\Select2; use kartik\select2\Select2;
@ -25,9 +26,9 @@ use yii\widgets\ActiveForm;
] ]
) ?> ) ?>
<?= $form->field($model, 'user_id')->widget(Select2::className(), <?= $form->field($model, 'card_id')->widget(Select2::className(),
[ [
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(), 'data' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
'options' => ['placeholder' => '...','class' => 'form-control'], 'options' => ['placeholder' => '...','class' => 'form-control'],
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true, 'allowClear' => true,

View File

@ -2,6 +2,7 @@
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use yii\helpers\Html; use yii\helpers\Html;
use yii\web\YiiAsset;
use yii\widgets\DetailView; use yii\widgets\DetailView;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
@ -10,7 +11,7 @@ use yii\widgets\DetailView;
$this->title = 'Сотрудник проекта: ' . $model->project->name; $this->title = 'Сотрудник проекта: ' . $model->project->name;
$this->params['breadcrumbs'][] = ['label' => 'Project Users', 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => 'Project Users', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title; $this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this); YiiAsset::register($this);
?> ?>
<div class="project-user-view"> <div class="project-user-view">
@ -38,6 +39,10 @@ $this->params['breadcrumbs'][] = $this->title;
'attribute' => 'user_id', 'attribute' => 'user_id',
'value' => ArrayHelper::getValue($model, 'user.username' ), 'value' => ArrayHelper::getValue($model, 'user.username' ),
], ],
[
'attribute' => 'card_id',
'value' => ArrayHelper::getValue($model, 'card.fio' ),
],
], ],
]) ?> ]) ?>

View File

@ -21,8 +21,9 @@ use yii\widgets\ActiveForm;
->where(['!=', 'question_type_id', '1']) ->where(['!=', 'question_type_id', '1'])
->indexBy('id') ->indexBy('id')
->column(), ->column(),
'options' => ['placeholder' => 'Выберите проект'],
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => false 'allowClear' => false,
], ],
]) ?> ]) ?>

View File

@ -173,7 +173,7 @@ class TaskUserController extends Controller
$parents = $_POST['depdrop_parents']; $parents = $_POST['depdrop_parents'];
if ($parents != null) { if ($parents != null) {
$task_id = $parents[0]; $task_id = $parents[0];
$users = ProjectUser::usersByTaskArr($task_id); $users = ProjectUser::userCardByTaskArr($task_id);
$formattedUsersArr = array(); $formattedUsersArr = array();
foreach ($users as $key => $value){ foreach ($users as $key => $value){
@ -185,9 +185,4 @@ class TaskUserController extends Controller
} }
return ['output'=>'', 'selected'=>'']; return ['output'=>'', 'selected'=>''];
} }
public function actionDynamicProjectUser()
{
var_dump('hhh'); die;
}
} }

View File

@ -18,7 +18,7 @@ class TaskSearch extends Task
public function rules() public function rules()
{ {
return [ return [
[['id', 'project_id', 'status', 'user_id_creator', 'user_id'], 'integer'], [['id', 'project_id', 'status', 'card_id_creator', 'card_id'], 'integer'], // 'card_id_creator', 'card_id'
[['title', 'created_at', 'updated_at', 'description'], 'safe'], [['title', 'created_at', 'updated_at', 'description'], 'safe'],
]; ];
} }
@ -41,10 +41,7 @@ class TaskSearch extends Task
*/ */
public function search($params) public function search($params)
{ {
$query = Task::find()->joinWith(['user', 'project']); $query = Task::find();//->joinWith(['user_card', 'project']);
// => function($query){
// $query->from(ProjectUser::tableName() . ' pt');
// }]); //,
// add conditions that should always apply here // add conditions that should always apply here
@ -67,8 +64,8 @@ class TaskSearch extends Task
'task.status' => $this->status, 'task.status' => $this->status,
'task.created_at' => $this->created_at, 'task.created_at' => $this->created_at,
'task.updated_at' => $this->updated_at, 'task.updated_at' => $this->updated_at,
'user_id_creator' => $this->user_id_creator, 'task.card_id_creator' => $this->card_id_creator,
'task.user_id' => $this->user_id, 'task.card_id' => $this->card_id,
]); ]);
$query->andFilterWhere(['like', 'title', $this->title]) $query->andFilterWhere(['like', 'title', $this->title])

View File

@ -29,7 +29,7 @@ use yii\widgets\ActiveForm;
<?= $form->field($model, 'project_user_id')->widget(DepDrop::className(), <?= $form->field($model, 'project_user_id')->widget(DepDrop::className(),
[ [
'type' => DepDrop::TYPE_SELECT2, 'type' => DepDrop::TYPE_SELECT2,
'options' => ['id' => 'project-user-id', 'allowClear' => true, 'multiple' => true], // , 'multiple' => true 'options' => ['id' => 'project-user-id', 'allowClear' => true, 'multiple' => true],
'select2Options' => [ 'select2Options' => [
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true, 'allowClear' => true,

View File

@ -2,6 +2,7 @@
use backend\modules\project\models\ProjectUser; use backend\modules\project\models\ProjectUser;
use backend\modules\task\models\Task; use backend\modules\task\models\Task;
use backend\modules\task\models\TaskUser;
use kartik\select2\Select2; use kartik\select2\Select2;
use yii\helpers\Html; use yii\helpers\Html;
use yii\grid\GridView; use yii\grid\GridView;
@ -35,7 +36,8 @@ $this->params['breadcrumbs'][] = $this->title;
'filter' => Select2::widget([ 'filter' => Select2::widget([
'model' => $searchModel, 'model' => $searchModel,
'attribute' => 'task_id', 'attribute' => 'task_id',
'data' => Task::find()->select(['title', 'id'])->indexBy('id')->column(), 'data' => TaskUser::find()->joinWith('task')
->select(['task.title', 'task.id'])->indexBy('task.id')->column(),
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true, 'allowClear' => true,
'width' => '250px', 'width' => '250px',
@ -48,12 +50,12 @@ $this->params['breadcrumbs'][] = $this->title;
], ],
[ [
'attribute' => 'project_user_id', 'attribute' => 'project_user_id',
'value' => 'projectUser.user.username', 'value' => 'projectUser.card.fio',
'filter' => Select2::widget([ 'filter' => Select2::widget([
'model' => $searchModel, 'model' => $searchModel,
'attribute' => 'project_user_id', 'attribute' => 'project_user_id',
'data' => ProjectUser::find()->select(['user.username', 'project_user.id']) 'data' => TaskUser::find()->joinWith('projectUser.card')
->joinWith('user')->indexBy('project_user.id')->column(), ->select(['user_card.fio', 'task_user.id'])->column(),
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true, 'allowClear' => true,
'width' => '250px', 'width' => '250px',

View File

@ -36,7 +36,7 @@ $this->params['breadcrumbs'][] = $this->title;
], ],
[ [
'attribute' => 'project_user_id', 'attribute' => 'project_user_id',
'value' => ArrayHelper::getValue($model, 'projectUser.user.username'), 'value' => ArrayHelper::getValue($model, 'projectUser.card.fio'),
], ],
], ],
]) ?> ]) ?>

View File

@ -1,13 +1,10 @@
<?php <?php
use backend\modules\card\models\UserCard;
use backend\modules\project\models\Project; use backend\modules\project\models\Project;
use backend\modules\project\models\ProjectUser;
use common\helpers\StatusHelper; use common\helpers\StatusHelper;
use common\models\User;
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 */
@ -27,9 +24,9 @@ use yii\widgets\ActiveForm;
); );
?> ?>
<?= $form->field($model, 'user_id_creator')->widget(Select2::class, <?= $form->field($model, 'card_id_creator')->widget(Select2::class,
[ [
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(), 'data' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
'options' => ['placeholder' => '...','class' => 'form-control', 'value' => Yii::$app->user->id], 'options' => ['placeholder' => '...','class' => 'form-control', 'value' => Yii::$app->user->id],
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true, 'allowClear' => true,
@ -47,9 +44,9 @@ use yii\widgets\ActiveForm;
] ]
) ?> ) ?>
<?= $form->field($model, 'user_id')->widget(Select2::class, <?= $form->field($model, 'card_id')->widget(Select2::class,
[ [
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(), 'data' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
'options' => ['placeholder' => '...','class' => 'form-control'], 'options' => ['placeholder' => '...','class' => 'form-control'],
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true, 'allowClear' => true,

View File

@ -1,5 +1,6 @@
<?php <?php
use backend\modules\card\models\UserCard;
use backend\modules\project\models\Project; use backend\modules\project\models\Project;
use backend\modules\project\models\ProjectUser; use backend\modules\project\models\ProjectUser;
use backend\modules\task\models\Task; use backend\modules\task\models\Task;
@ -35,7 +36,8 @@ $this->params['breadcrumbs'][] = $this->title;
'filter' => Select2::widget([ 'filter' => Select2::widget([
'model' => $searchModel, 'model' => $searchModel,
'attribute' => 'project_id', 'attribute' => 'project_id',
'data' => Project::find()->select(['name', 'id'])->indexBy('id')->column(), 'data' => Task::find()->joinWith('project')
->select(['project.name', 'project.id'])->indexBy('project.id')->column(),
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true, 'allowClear' => true,
'width' => '150px', 'width' => '150px',
@ -48,12 +50,13 @@ $this->params['breadcrumbs'][] = $this->title;
], ],
'title', 'title',
[ [
'attribute' => 'user_id_creator', 'attribute' => 'card_id_creator',
'value' => 'userIdCreator.username', 'value' => 'userCardCreator.fio',
'filter' => Select2::widget([ 'filter' => Select2::widget([
'model' => $searchModel, 'model' => $searchModel,
'attribute' => 'user_id_creator', 'attribute' => 'card_id_creator',
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(), 'data' => Task::find()->joinWith('userCardCreator')
->select(['user_card.fio', 'user_card.id'])->indexBy('user_card.id')->column(),
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true, 'allowClear' => true,
'width' => '150px', 'width' => '150px',
@ -65,12 +68,13 @@ $this->params['breadcrumbs'][] = $this->title;
]) ])
], ],
[ [
'attribute' => 'user_id', 'attribute' => 'card_id',
'value' => 'user.username', 'value' => 'userCard.fio',
'filter' => Select2::widget([ 'filter' => Select2::widget([
'model' => $searchModel, 'model' => $searchModel,
'attribute' => 'user_id', 'attribute' => 'card_id',
'data' => User::find()->select(['username', 'id'])->indexBy('id')->column(), 'data' => Task::find()->joinWith('userCard')
->select(['user_card.fio', 'user_card.id'])->indexBy('user_card.id')->column(),
'pluginOptions' => [ 'pluginOptions' => [
'allowClear' => true, 'allowClear' => true,
'width' => '150px', 'width' => '150px',

View File

@ -47,12 +47,12 @@ YiiAsset::register($this);
'created_at', 'created_at',
'updated_at', 'updated_at',
[ [
'attribute' => 'project_user_id', 'attribute' => 'card_id_creator',
'value' => ArrayHelper::getValue($model, 'projectUser.user.username'), 'value' => ArrayHelper::getValue($model, 'userCardCreator.fio'),
], ],
[ [
'attribute' => 'user_id', 'attribute' => 'card_id',
'value' => ArrayHelper::getValue($model, 'user.username'), 'value' => ArrayHelper::getValue($model, 'userCard.fio'),
], ],
'description', 'description',
], ],
@ -71,7 +71,7 @@ YiiAsset::register($this);
[ [
'attribute' => 'project_user_id', 'attribute' => 'project_user_id',
'value' => 'projectUser.user.username' 'value' => 'projectUser.card.fio'
], ],
[ [

View File

@ -62,7 +62,7 @@
['label' => 'Компании', 'icon' => 'building', 'url' => ['/hh/hh'], 'active' => \Yii::$app->controller->id == 'hh'], ['label' => 'Компании', 'icon' => 'building', 'url' => ['/hh/hh'], 'active' => \Yii::$app->controller->id == 'hh'],
['label' => 'Вакансии', 'icon' => 'user-md', 'url' => ['/hh/hh-job'], 'active' => \Yii::$app->controller->id == 'hh-job'], ['label' => 'Вакансии', 'icon' => 'user-md', 'url' => ['/hh/hh-job'], 'active' => \Yii::$app->controller->id == 'hh-job'],
], ],
'visible' => Yii::$app->user->can('confidential_information') 'visible' => Yii::$app->user->can('confidential_information')
], ],
['label' => 'Баланс', 'icon' => 'dollar', 'url' => ['/balance/balance'], 'active' => \Yii::$app->controller->id == 'balance', 'visible' => Yii::$app->user->can('confidential_information')], ['label' => 'Баланс', 'icon' => 'dollar', 'url' => ['/balance/balance'], 'active' => \Yii::$app->controller->id == 'balance', 'visible' => Yii::$app->user->can('confidential_information')],
['label' => 'Отпуска', 'icon' => 'plane', 'url' => ['/holiday/holiday'], 'active' => \Yii::$app->controller->id == 'holiday', 'visible' => Yii::$app->user->can('confidential_information')], ['label' => 'Отпуска', 'icon' => 'plane', 'url' => ['/holiday/holiday'], 'active' => \Yii::$app->controller->id == 'holiday', 'visible' => Yii::$app->user->can('confidential_information')],

View File

@ -9,9 +9,9 @@ use yii\db\ActiveQuery;
* This is the model class for table "manager". * This is the model class for table "manager".
* *
* @property int $id * @property int $id
* @property int $user_id * @property int $user_card_id
* *
* @property User $user * @property UserCard $userCard
* @property ManagerEmployee[] $managerEmployees * @property ManagerEmployee[] $managerEmployees
*/ */
class Manager extends \yii\db\ActiveRecord class Manager extends \yii\db\ActiveRecord
@ -30,8 +30,10 @@ class Manager extends \yii\db\ActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['user_id'], 'integer'], [['user_card_id'], 'integer'],
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']], [['user_card_id'], 'required'],
['user_card_id', 'unique', 'message'=>'Уже является менеджером'],
[['user_card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['user_card_id' => 'id']],
]; ];
} }
@ -42,7 +44,7 @@ class Manager extends \yii\db\ActiveRecord
{ {
return [ return [
'id' => 'ID', 'id' => 'ID',
'user_id' => 'Пользователь', 'user_card_id' => 'Карточка менеджера',
]; ];
} }
@ -57,9 +59,9 @@ class Manager extends \yii\db\ActiveRecord
/** /**
* @return ActiveQuery * @return ActiveQuery
*/ */
public function getUser() public function getUserCard()
{ {
return $this->hasOne(User::className(), ['id' => 'user_id']); return $this->hasOne(UserCard::className(), ['id' => 'user_card_id']);
} }
/** /**

View File

@ -9,10 +9,10 @@ use yii\db\ActiveQuery;
* *
* @property int $id * @property int $id
* @property int $manager_id * @property int $manager_id
* @property int $employee_id * @property int $user_card_id
* *
* @property User $user
* @property Manager $manager * @property Manager $manager
* @property UserCard $userCard
*/ */
class ManagerEmployee extends \yii\db\ActiveRecord class ManagerEmployee extends \yii\db\ActiveRecord
{ {
@ -30,9 +30,10 @@ class ManagerEmployee extends \yii\db\ActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['manager_id', 'employee_id'], 'required'], [['manager_id', 'user_card_id'], 'required'],
[['manager_id', 'employee_id'], 'integer'], [['manager_id'], 'integer'],
[['employee_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['employee_id' => 'id']], ['user_card_id', 'unique', 'targetAttribute' => ['manager_id', 'user_card_id'], 'message'=>'Этот сотрудник уже закреплён за менеджером'],
[['user_card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['user_card_id' => 'id']],
[['manager_id'], 'exist', 'skipOnError' => true, 'targetClass' => Manager::className(), 'targetAttribute' => ['manager_id' => 'id']], [['manager_id'], 'exist', 'skipOnError' => true, 'targetClass' => Manager::className(), 'targetAttribute' => ['manager_id' => 'id']],
]; ];
} }
@ -45,16 +46,16 @@ class ManagerEmployee extends \yii\db\ActiveRecord
return [ return [
'id' => 'ID', 'id' => 'ID',
'manager_id' => 'Менеджер', 'manager_id' => 'Менеджер',
'employee_id' => 'Работник', 'user_card_id' => 'Карточка работника',
]; ];
} }
/** /**
* @return ActiveQuery * @return ActiveQuery
*/ */
public function getUser() public function getUserCard(): ActiveQuery
{ {
return $this->hasOne(User::className(), ['id' => 'employee_id']); return $this->hasOne(UserCard::className(), ['id' => 'user_card_id']);
} }
/** /**

View File

@ -36,9 +36,10 @@ class ProjectUser extends \yii\db\ActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['user_id', 'project_id'], 'required'], [['user_id', 'project_id', 'card_id'], 'required'],
['user_id', 'unique', 'targetAttribute' => ['user_id', 'project_id'], 'message'=>'Сотрудник уже назначен на этот проект'], ['user_id', 'unique', 'targetAttribute' => ['user_id', 'project_id'], 'message'=>'Сотрудник уже назначен на этот проект'],
// [['card_id', 'project_id', 'user_id'], 'integer'], ['card_id', 'unique', 'targetAttribute' => ['card_id', 'project_id'], 'message'=>'Сотрудник уже назначен на этот проект'],
[['card_id', 'project_id', 'user_id'], 'integer'],
[['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']], [['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']],
[['card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['card_id' => 'id']], [['card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['card_id' => 'id']],
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']], [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
@ -118,6 +119,12 @@ class ProjectUser extends \yii\db\ActiveRecord
self::find()->joinWith(['tasksByProject', 'user'])->where(['task.id' => $task_id])->all(), 'id', 'user.username'); self::find()->joinWith(['tasksByProject', 'user'])->where(['task.id' => $task_id])->all(), 'id', 'user.username');
} }
public static function userCardByTaskArr($task_id): array
{
return ArrayHelper::map(
self::find()->joinWith(['tasksByProject', 'card'])->where(['task.id' => $task_id])->all(), 'id', 'card.fio');
}
public static function setUsersByCardId() public static function setUsersByCardId()
{ {
$projectUserModels = self::findAll(['user_id' => null]); $projectUserModels = self::findAll(['user_id' => null]);

View File

@ -2,10 +2,9 @@
namespace common\models; namespace common\models;
use phpDocumentor\Reflection\Types\This;
use Yii;
use yii\behaviors\TimestampBehavior; use yii\behaviors\TimestampBehavior;
use yii\db\ActiveQuery; use yii\db\ActiveQuery;
use yii\db\ActiveRecord;
use yii\db\Expression; use yii\db\Expression;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
@ -18,16 +17,16 @@ use yii\helpers\ArrayHelper;
* @property int $status * @property int $status
* @property string $created_at * @property string $created_at
* @property string $updated_at * @property string $updated_at
* @property int $user_id_creator * @property int $card_id_creator
* @property int $user_id * @property int $card_id
* @property string $description * @property string $description
* *
* @property Project $project * @property Project $project
* @property User $userIdCreator * @property UserCard $card
* @property User $user * @property UserCard $cardIdCreator
* @property TaskUser[] $taskUsers * @property TaskUser[] $taskUsers
*/ */
class Task extends \yii\db\ActiveRecord class Task extends ActiveRecord
{ {
/** /**
* {@inheritdoc} * {@inheritdoc}
@ -55,14 +54,15 @@ class Task extends \yii\db\ActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['project_id', 'status', 'title', 'description', 'user_id_creator',], 'required'], [['project_id', 'status', 'title', 'description', 'card_id_creator',], 'required'],
[['project_id', 'status', 'user_id_creator', 'user_id'], 'integer'], [['project_id', 'status', 'card_id_creator', 'card_id'], 'integer'],
[['created_at', 'updated_at'], 'safe'], [['created_at', 'updated_at'], 'safe'],
['title', 'unique', 'targetAttribute' => ['title', 'project_id'], 'message'=>'Такая задача уже создана'],
[['title'], 'string', 'max' => 255], [['title'], 'string', 'max' => 255],
[['description'], 'string', 'max' => 500], [['description'], 'string', 'max' => 500],
[['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']], [['project_id'], 'exist', 'skipOnError' => true, 'targetClass' => Project::className(), 'targetAttribute' => ['project_id' => 'id']],
[['user_id_creator'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id_creator' => 'id']], [['card_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['card_id' => 'id']],
[['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']], [['card_id_creator'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['card_id_creator' => 'id']],
]; ];
} }
@ -78,9 +78,9 @@ class Task extends \yii\db\ActiveRecord
'status' => 'Статус', 'status' => 'Статус',
'created_at' => 'Дата создания', 'created_at' => 'Дата создания',
'updated_at' => 'Дата обновления', 'updated_at' => 'Дата обновления',
'user_id_creator' => 'Создатель задачи',
'user_id' => 'Наблюдатель',
'description' => 'Описание', 'description' => 'Описание',
'card_id_creator' => 'Создатель задачи',
'card_id' => 'Наблюдатель',
]; ];
} }
@ -108,9 +108,14 @@ class Task extends \yii\db\ActiveRecord
return $this->hasOne(User::className(), ['id' => 'user_id']); return $this->hasOne(User::className(), ['id' => 'user_id']);
} }
public function getUserIdCreator() public function getUserCard()
{ {
return $this->hasOne(User::className(), ['id' => 'user_id_creator']); return $this->hasOne(UserCard::className(), ['id' => 'card_id']);
}
public function getUserCardCreator()
{
return $this->hasOne(UserCard::className(), ['id' => 'card_id_creator']);
} }
/** /**

View File

@ -3,6 +3,7 @@
namespace common\models; namespace common\models;
use Yii; use Yii;
use yii\base\InvalidConfigException;
use yii\db\ActiveQuery; use yii\db\ActiveQuery;
/** /**
@ -65,6 +66,4 @@ class TaskUser extends \yii\db\ActiveRecord
{ {
return $this->hasOne(Task::className(), ['id' => 'task_id']); return $this->hasOne(Task::className(), ['id' => 'task_id']);
} }
} }

View File

@ -221,15 +221,15 @@ class User extends ActiveRecord implements IdentityInterface
return $this->hasOne(UserCard::class, ['id_user' => 'id']); return $this->hasOne(UserCard::class, ['id_user' => 'id']);
} }
public function getManager() // public function getManager()
{ // {
return $this->hasOne(Manager::class, ['user_id' => 'id']); // return $this->hasOne(Manager::class, ['user_id' => 'id']);
} // }
//
public function getManagerEmployee() // public function getManagerEmployee()
{ // {
return $this->hasMany(ManagerEmployee::className(), ['employee_id' => 'id']); // return $this->hasMany(ManagerEmployee::className(), ['employee_id' => 'id']);
} // }
public function getProjectUser() public function getProjectUser()
{ {

View File

@ -104,6 +104,7 @@ class UserCard extends \yii\db\ActiveRecord
[['fio', 'status', 'gender', 'email', 'level', 'position_id'], 'required'], [['fio', 'status', 'gender', 'email', 'level', 'position_id'], 'required'],
[['gender', 'status', 'position_id', 'id_user', 'level', 'years_of_exp'], 'integer'], [['gender', 'status', 'position_id', 'id_user', 'level', 'years_of_exp'], 'integer'],
[['dob', 'created_at', 'updated_at', 'deleted_at', 'vc_text', 'vc_text_short'], 'safe'], [['dob', 'created_at', 'updated_at', 'deleted_at', 'vc_text', 'vc_text_short'], 'safe'],
['email', 'unique', 'message'=>'Почтовый адрес уже используется'],
[['fio', 'passport', 'photo', 'email', 'resume', 'city', 'link_vk', 'link_telegram', 'specification'], 'string', 'max' => 255], [['fio', 'passport', 'photo', 'email', 'resume', 'city', 'link_vk', 'link_telegram', 'specification'], 'string', 'max' => 255],
[['salary'], 'string', 'max' => 100], [['salary'], 'string', 'max' => 100],
[['position_id'], 'exist', 'skipOnError' => true, 'targetClass' => Position::class, 'targetAttribute' => ['position_id' => 'id']], [['position_id'], 'exist', 'skipOnError' => true, 'targetClass' => Position::class, 'targetAttribute' => ['position_id' => 'id']],
@ -214,19 +215,16 @@ class UserCard extends \yii\db\ActiveRecord
return $this->hasOne(User::class, ['id' => 'id_user']); return $this->hasOne(User::class, ['id' => 'id_user']);
} }
/**
* @throws Exception
*/
public static function getIdByUserId($user_id)
{
return ArrayHelper::getValue(self::find()->where(['id_user' => $user_id])->one(), 'id');
}
public static function getUserList() public static function getUserList()
{ {
return ArrayHelper::map(self::find()->all(), 'id', 'fio'); return ArrayHelper::map(self::find()->all(), 'id', 'fio');
} }
public function getManager()
{
return $this->hasOne(Manager::class, ['user_card_id' => 'id']);
}
public static function generateUserForUserCard($card_id = null) public static function generateUserForUserCard($card_id = null)
{ {
$userCardQuery = self::find(); $userCardQuery = self::find();

View File

@ -0,0 +1,52 @@
<?php
use yii\db\Migration;
/**
* Class m211220_105942_change_foreign_keys_in_task_from_user_id_to_user_card_id
*/
class m211220_105942_change_foreign_keys_in_task_from_user_id_to_user_card_id extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->dropForeignKey('creator_task', 'task');
$this->dropColumn('task', 'user_id_creator');
$this->dropForeignKey('task_user', 'task');
$this->dropColumn('task', 'user_id');
$this->addColumn('task', 'card_id_creator', $this->integer(11)->defaultValue(null));
$this->addForeignKey('task_user_card_creator', 'task', 'card_id_creator',
'user_card', 'id');
$this->addColumn('task', 'card_id', $this->integer(11)->defaultValue(null));
$this->addForeignKey('task_user_card', 'task', 'card_id', 'user_card', 'id');
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropForeignKey('task_user_card', 'task');
$this->dropColumn('task', 'card_id');
$this->dropForeignKey('task_user_card_creator', 'task');
$this->dropColumn('task', 'card_id_creator');
$this->addColumn('task', 'user_id_creator', $this->integer());
$this->addForeignKey('creator_task', 'task',
'user_id_creator', 'user', 'id');
$this->addColumn('task', 'user_id', $this->integer());
$this->addForeignKey('task_user', 'task',
'user_id', 'user', 'id');
}
}

View File

@ -0,0 +1,50 @@
<?php
use yii\db\Migration;
/**
* Class m211222_083459_change_foreign_key_in_manager_from_user_id_to_user_card_id
*/
class m211222_083459_change_foreign_key_in_manager_from_user_id_to_user_card_id extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->dropForeignKey('manager_user', 'manager');
$this->dropColumn('manager', 'user_id');
$this->addColumn('manager', 'user_card_id', $this->integer(11));
$this->addForeignKey('manager_user_card', 'manager', 'user_card_id',
'user_card', 'id');
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropForeignKey('manager_user_card', 'manager');
$this->dropColumn('manager', 'user_card_id');
$this->addColumn('manager', 'user_id', $this->integer(11));
$this->addForeignKey('manager_user', 'manager', 'user_id', 'user', 'id');
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m211222_083459_change_foreign_key_in_manager_from_user_id_to_user_card_id cannot be reverted.\n";
return false;
}
*/
}

View File

@ -0,0 +1,34 @@
<?php
use yii\db\Migration;
/**
* Class m211222_083709_change_foreign_key_in_manager_employee_from_user_id_to_user_card_id
*/
class m211222_083709_change_foreign_key_in_manager_employee_from_user_id_to_user_card_id extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->dropForeignKey('employee_user', 'manager_employee');
$this->dropColumn('manager_employee', 'employee_id');
$this->addColumn('manager_employee', 'user_card_id', $this->integer(11));
$this->addForeignKey('manager_employee_user_card', 'manager_employee', 'user_card_id',
'user_card', 'id');
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropForeignKey('manager_employee_user_card', 'manager_employee');
$this->dropColumn('manager_employee', 'user_card_id');
$this->addColumn('manager_employee', 'employee_id', $this->integer(11));
$this->addForeignKey('employee_user', 'manager_employee', 'employee_id', 'user', 'id');
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff