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; = $form->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; ], ]) ?> - = $form->field($model, 'user_card_id')->widget(Select2::className(), + = $form->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 ], - ]) ?> + ] + ); ?>