From f9c732852934e6d1d05af6c5c660daf819615de9 Mon Sep 17 00:00:00 2001 From: Kavalar Date: Thu, 4 May 2023 15:10:56 +0300 Subject: [PATCH] manager employee fix --- .../controllers/ManagerController.php | 2 +- .../controllers/ManagerEmployeeController.php | 26 +++++++++---------- .../employee/models/ManagerEmployeeSearch.php | 6 ++--- .../modules/employee/models/ManagerSearch.php | 6 ++--- .../employee/views/manager-employee/_form.php | 20 +++++++------- .../employee/views/manager-employee/index.php | 12 +++------ .../modules/employee/views/manager/_form.php | 12 ++++----- .../modules/employee/views/manager/index.php | 5 ++-- .../modules/employee/views/manager/view.php | 7 +++-- common/models/ManagerEmployee.php | 4 +-- 10 files changed, 44 insertions(+), 56 deletions(-) diff --git a/backend/modules/employee/controllers/ManagerController.php b/backend/modules/employee/controllers/ManagerController.php index 33bee91..dacb6e6 100644 --- a/backend/modules/employee/controllers/ManagerController.php +++ b/backend/modules/employee/controllers/ManagerController.php @@ -60,7 +60,7 @@ class ManagerController extends Controller $model = $this->findModel($id); $managerEmployeeSearchModel = new ManagerEmployeeSearch(); $managerEmployeeDataProvider = new ActiveDataProvider([ - 'query' => $model->getManagerEmployees()->with('userCard'), + 'query' => $model->getManagerEmployees()->with('employee'), 'pagination' => [ 'pageSize' => 20, ], diff --git a/backend/modules/employee/controllers/ManagerEmployeeController.php b/backend/modules/employee/controllers/ManagerEmployeeController.php index a8de30a..b522832 100644 --- a/backend/modules/employee/controllers/ManagerEmployeeController.php +++ b/backend/modules/employee/controllers/ManagerEmployeeController.php @@ -2,6 +2,7 @@ namespace backend\modules\employee\controllers; +use common\classes\Debug; use Yii; use backend\modules\employee\models\ManagerEmployee; use backend\modules\employee\models\ManagerEmployeeSearch; @@ -71,20 +72,19 @@ class ManagerEmployeeController extends Controller $post = \Yii::$app->request->post('ManagerEmployee'); if (!empty($post)) { - $user_card_id_arr = ArrayHelper::getValue($post,'user_card_id'); + $user_card_id_arr = ArrayHelper::getValue($post, 'employee_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; + $emtModel = new ManagerEmployee(); + $emtModel->manager_id = $post['manager_id']; + $emtModel->employee_id = $user_card_id_arr; - if (!$emtModel->save()) { - return $this->render('create', [ - 'model' => $emtModel, - ]); - } + if (!$emtModel->save()) { + return $this->render('create', [ + 'model' => $emtModel, + ]); } + return $this->redirect(['index']); } @@ -106,8 +106,7 @@ class ManagerEmployeeController extends Controller $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { - if ($manager_id !== null) - { + if ($manager_id !== null) { return $this->redirect(['manager/view', 'id' => $manager_id]); } return $this->redirect(['view', 'id' => $model->id]); @@ -129,8 +128,7 @@ class ManagerEmployeeController extends Controller { $this->findModel($id)->delete(); - if ($manager_id !== null) - { + if ($manager_id !== null) { return $this->redirect(['manager/view', 'id' => $manager_id]); } diff --git a/backend/modules/employee/models/ManagerEmployeeSearch.php b/backend/modules/employee/models/ManagerEmployeeSearch.php index 0ca1463..f377dc3 100644 --- a/backend/modules/employee/models/ManagerEmployeeSearch.php +++ b/backend/modules/employee/models/ManagerEmployeeSearch.php @@ -17,7 +17,7 @@ class ManagerEmployeeSearch extends ManagerEmployee public function rules() { return [ - [['id', 'manager_id', 'user_card_id'], 'integer'], + [['id', 'manager_id', 'employee_id'], 'integer'], ]; } @@ -39,7 +39,7 @@ class ManagerEmployeeSearch extends ManagerEmployee */ public function search($params) { - $query = ManagerEmployee::find()->joinWith(['userCard', 'manager']); + $query = ManagerEmployee::find()->joinWith(['employee', 'manager']); // add conditions that should always apply here @@ -59,7 +59,7 @@ class ManagerEmployeeSearch extends ManagerEmployee $query->andFilterWhere([ 'id' => $this->id, 'manager_id' => $this->manager_id, - 'user_card_id' => $this->user_card_id, + 'user_card_id' => $this->employee_id, ]); return $dataProvider; diff --git a/backend/modules/employee/models/ManagerSearch.php b/backend/modules/employee/models/ManagerSearch.php index 9421b7f..f1dbf59 100644 --- a/backend/modules/employee/models/ManagerSearch.php +++ b/backend/modules/employee/models/ManagerSearch.php @@ -17,7 +17,7 @@ class ManagerSearch extends Manager public function rules() { return [ - [['id', 'user_card_id'], 'integer'], + [['id', 'user_id'], 'integer'], ]; } @@ -39,7 +39,7 @@ class ManagerSearch extends Manager */ public function search($params) { - $query = Manager::find()->with('userCard'); + $query = Manager::find()->with('user'); // add conditions that should always apply here @@ -58,7 +58,7 @@ class ManagerSearch extends Manager // grid filtering conditions $query->andFilterWhere([ 'id' => $this->id, - 'user_card_id' => $this->user_card_id, + 'user_id' => $this->user_id, ]); return $dataProvider; diff --git a/backend/modules/employee/views/manager-employee/_form.php b/backend/modules/employee/views/manager-employee/_form.php index ee4685d..b9ad8e0 100644 --- a/backend/modules/employee/views/manager-employee/_form.php +++ b/backend/modules/employee/views/manager-employee/_form.php @@ -17,8 +17,8 @@ use yii\widgets\ActiveForm; field($model, 'manager_id')->widget(Select2::className(), [ - 'data' => Manager::find()->select(['fio', 'manager.id']) - ->joinWith('userCard')->indexBy('manager.id')->column(), + 'data' => Manager::find()->select(['email', 'manager.id']) + ->joinWith('user')->indexBy('manager.id')->column(), 'options' => ['placeholder' => '...','class' => 'form-control'], 'hideSearch' => false, 'pluginOptions' => [ @@ -26,18 +26,16 @@ use yii\widgets\ActiveForm; ], ]) ?> - field($model, 'user_card_id')->widget(Select2::className(), + field($model, 'employee_id')->widget( + Select2::class, [ - 'data' => UserCard::find()->select(['fio', 'user_card.id']) - ->joinWith('manager')->where(['manager.user_card_id' => null])->indexBy('user_card.id')->column(), - 'options' => ['placeholder' => '...','class' => 'form-control'], - 'hideSearch' => false, + 'data' => \common\models\UserCard::getListUserWithUserId(), + 'options' => ['placeholder' => '...', 'class' => 'form-control'], 'pluginOptions' => [ - 'allowClear' => true, - 'multiple' => true, - 'closeOnSelect' => false + 'allowClear' => true ], - ]) ?> + ] + ); ?>
'btn btn-success']) ?> diff --git a/backend/modules/employee/views/manager-employee/index.php b/backend/modules/employee/views/manager-employee/index.php index b7334f5..385a887 100644 --- a/backend/modules/employee/views/manager-employee/index.php +++ b/backend/modules/employee/views/manager-employee/index.php @@ -26,17 +26,11 @@ $this->params['breadcrumbs'][] = $this->title; ['class' => 'yii\grid\SerialColumn'], [ 'attribute' => 'manager_id', - 'filter' => UserCard::find()->select(['fio', 'user_card.id']) - ->joinWith('manager')->where(['not',['manager.user_card_id' => null]]) - ->indexBy('user_card.id')->column(), - 'value' => 'manager.userCard.fio', + 'value' => 'manager.user.userCard.fio', ], [ - 'attribute' => 'user_card_id', - 'filter' => ManagerEmployee::find()->select(['fio', 'manager_employee.id']) - ->joinWith('userCard') - ->indexBy('manager_employee.id')->column(), - 'value' => 'userCard.fio', + 'attribute' => 'employee_id', + 'value' => 'employee.email', ], ['class' => 'yii\grid\ActionColumn'], ], diff --git a/backend/modules/employee/views/manager/_form.php b/backend/modules/employee/views/manager/_form.php index 394c154..42683eb 100644 --- a/backend/modules/employee/views/manager/_form.php +++ b/backend/modules/employee/views/manager/_form.php @@ -15,16 +15,16 @@ use kartik\select2\Select2; - field($model, 'user_card_id')->widget(Select2::className(), + field($model, 'user_id')->widget( + Select2::class, [ - 'data' => UserCard::find()->select(['user_card.fio', 'user_card.id']) - ->joinWith('manager')->where(['manager.user_card_id' => null]) - ->indexBy('user_card.id')->column(), - 'options' => ['placeholder' => '...','class' => 'form-control'], + 'data' => \common\models\UserCard::getListUserWithUserId(), + 'options' => ['placeholder' => '...', 'class' => 'form-control'], 'pluginOptions' => [ 'allowClear' => true ], - ]) ?> + ] + ); ?>
'btn btn-success']) ?> diff --git a/backend/modules/employee/views/manager/index.php b/backend/modules/employee/views/manager/index.php index 041e084..3433203 100644 --- a/backend/modules/employee/views/manager/index.php +++ b/backend/modules/employee/views/manager/index.php @@ -24,9 +24,8 @@ $this->params['breadcrumbs'][] = $this->title; 'columns' => [ ['class' => 'yii\grid\SerialColumn'], [ - 'attribute' => 'user_card_id', - 'filter' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(), - 'value' => 'userCard.fio', + 'attribute' => 'user_id', + 'value' => 'user.email', ], ['class' => 'yii\grid\ActionColumn'], diff --git a/backend/modules/employee/views/manager/view.php b/backend/modules/employee/views/manager/view.php index 02794ef..0b4a76c 100644 --- a/backend/modules/employee/views/manager/view.php +++ b/backend/modules/employee/views/manager/view.php @@ -38,7 +38,7 @@ YiiAsset::register($this); 'id', [ 'attribute' => 'user_id', - 'value' => ArrayHelper::getValue($model,'userCard.fio'), + 'value' => ArrayHelper::getValue($model,'user.email'), ], ], ]) ?> @@ -52,9 +52,8 @@ YiiAsset::register($this); 'columns' => [ ['class' => 'yii\grid\SerialColumn'], [ - 'attribute' => 'user_card_id', - 'filter' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(), - 'value' => 'userCard.fio', + 'attribute' => 'employee_id', + 'value' => 'employee.email', ], [ 'class' => 'yii\grid\ActionColumn', diff --git a/common/models/ManagerEmployee.php b/common/models/ManagerEmployee.php index 336f1a8..cc5331e 100644 --- a/common/models/ManagerEmployee.php +++ b/common/models/ManagerEmployee.php @@ -32,8 +32,8 @@ class ManagerEmployee extends \yii\db\ActiveRecord return [ [['manager_id', 'employee_id'], 'required'], [['manager_id'], 'integer'], - ['employee_id', 'unique', 'targetAttribute' => ['manager_id', 'user_card_id'], 'message' => 'Этот сотрудник уже закреплён за менеджером'], - [['employee_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['user_card_id' => 'id']], + ['employee_id', 'unique', 'targetAttribute' => ['manager_id', 'employee_id'], 'message' => 'Этот сотрудник уже закреплён за менеджером'], + [['employee_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['employee_id' => 'id']], [['manager_id'], 'exist', 'skipOnError' => true, 'targetClass' => Manager::className(), 'targetAttribute' => ['manager_id' => 'id']], ]; }