manager employee fix

This commit is contained in:
Kavalar 2023-05-04 15:10:56 +03:00
parent b2f482e10b
commit f9c7328529
10 changed files with 44 additions and 56 deletions

View File

@ -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,
],

View File

@ -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,19 +72,18 @@ 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->employee_id = $user_card_id_arr;
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]);
}

View File

@ -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;

View File

@ -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;

View File

@ -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(),
'data' => \common\models\UserCard::getListUserWithUserId(),
'options' => ['placeholder' => '...', 'class' => 'form-control'],
'hideSearch' => false,
'pluginOptions' => [
'allowClear' => true,
'multiple' => true,
'closeOnSelect' => false
'allowClear' => true
],
]) ?>
]
); ?>
<div class="form-group">
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>

View File

@ -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'],
],

View File

@ -15,16 +15,16 @@ use kartik\select2\Select2;
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'user_card_id')->widget(Select2::className(),
<?= $form->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(),
'data' => \common\models\UserCard::getListUserWithUserId(),
'options' => ['placeholder' => '...', 'class' => 'form-control'],
'pluginOptions' => [
'allowClear' => true
],
]) ?>
]
); ?>
<div class="form-group">
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>

View File

@ -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'],

View File

@ -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',

View File

@ -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']],
];
}