manager employee fix
This commit is contained in:
parent
b2f482e10b
commit
f9c7328529
@ -60,7 +60,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('userCard'),
|
'query' => $model->getManagerEmployees()->with('employee'),
|
||||||
'pagination' => [
|
'pagination' => [
|
||||||
'pageSize' => 20,
|
'pageSize' => 20,
|
||||||
],
|
],
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace backend\modules\employee\controllers;
|
namespace backend\modules\employee\controllers;
|
||||||
|
|
||||||
|
use common\classes\Debug;
|
||||||
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;
|
||||||
@ -71,20 +72,19 @@ class ManagerEmployeeController extends Controller
|
|||||||
$post = \Yii::$app->request->post('ManagerEmployee');
|
$post = \Yii::$app->request->post('ManagerEmployee');
|
||||||
|
|
||||||
if (!empty($post)) {
|
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 = new ManagerEmployee();
|
$emtModel->manager_id = $post['manager_id'];
|
||||||
$emtModel->manager_id = $post['manager_id'];
|
$emtModel->employee_id = $user_card_id_arr;
|
||||||
$emtModel->user_card_id = $user_card_id;
|
|
||||||
|
|
||||||
if (!$emtModel->save()) {
|
if (!$emtModel->save()) {
|
||||||
return $this->render('create', [
|
return $this->render('create', [
|
||||||
'model' => $emtModel,
|
'model' => $emtModel,
|
||||||
]);
|
]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return $this->redirect(['index']);
|
return $this->redirect(['index']);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,8 +106,7 @@ class ManagerEmployeeController extends Controller
|
|||||||
$model = $this->findModel($id);
|
$model = $this->findModel($id);
|
||||||
|
|
||||||
if ($model->load(Yii::$app->request->post()) && $model->save()) {
|
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(['manager/view', 'id' => $manager_id]);
|
||||||
}
|
}
|
||||||
return $this->redirect(['view', 'id' => $model->id]);
|
return $this->redirect(['view', 'id' => $model->id]);
|
||||||
@ -129,8 +128,7 @@ class ManagerEmployeeController extends Controller
|
|||||||
{
|
{
|
||||||
$this->findModel($id)->delete();
|
$this->findModel($id)->delete();
|
||||||
|
|
||||||
if ($manager_id !== null)
|
if ($manager_id !== null) {
|
||||||
{
|
|
||||||
return $this->redirect(['manager/view', 'id' => $manager_id]);
|
return $this->redirect(['manager/view', 'id' => $manager_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ class ManagerEmployeeSearch extends ManagerEmployee
|
|||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
return [
|
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)
|
public function search($params)
|
||||||
{
|
{
|
||||||
$query = ManagerEmployee::find()->joinWith(['userCard', 'manager']);
|
$query = ManagerEmployee::find()->joinWith(['employee', '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,
|
||||||
'user_card_id' => $this->user_card_id,
|
'user_card_id' => $this->employee_id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $dataProvider;
|
return $dataProvider;
|
||||||
|
@ -17,7 +17,7 @@ class ManagerSearch extends Manager
|
|||||||
public function rules()
|
public function rules()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[['id', 'user_card_id'], 'integer'],
|
[['id', 'user_id'], 'integer'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ class ManagerSearch extends Manager
|
|||||||
*/
|
*/
|
||||||
public function search($params)
|
public function search($params)
|
||||||
{
|
{
|
||||||
$query = Manager::find()->with('userCard');
|
$query = Manager::find()->with('user');
|
||||||
|
|
||||||
// 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_card_id' => $this->user_card_id,
|
'user_id' => $this->user_id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $dataProvider;
|
return $dataProvider;
|
||||||
|
@ -17,8 +17,8 @@ use yii\widgets\ActiveForm;
|
|||||||
|
|
||||||
<?= $form->field($model, 'manager_id')->widget(Select2::className(),
|
<?= $form->field($model, 'manager_id')->widget(Select2::className(),
|
||||||
[
|
[
|
||||||
'data' => Manager::find()->select(['fio', 'manager.id'])
|
'data' => Manager::find()->select(['email', 'manager.id'])
|
||||||
->joinWith('userCard')->indexBy('manager.id')->column(),
|
->joinWith('user')->indexBy('manager.id')->column(),
|
||||||
'options' => ['placeholder' => '...','class' => 'form-control'],
|
'options' => ['placeholder' => '...','class' => 'form-control'],
|
||||||
'hideSearch' => false,
|
'hideSearch' => false,
|
||||||
'pluginOptions' => [
|
'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'])
|
'data' => \common\models\UserCard::getListUserWithUserId(),
|
||||||
->joinWith('manager')->where(['manager.user_card_id' => null])->indexBy('user_card.id')->column(),
|
'options' => ['placeholder' => '...', 'class' => 'form-control'],
|
||||||
'options' => ['placeholder' => '...','class' => 'form-control'],
|
|
||||||
'hideSearch' => false,
|
|
||||||
'pluginOptions' => [
|
'pluginOptions' => [
|
||||||
'allowClear' => true,
|
'allowClear' => true
|
||||||
'multiple' => true,
|
|
||||||
'closeOnSelect' => false
|
|
||||||
],
|
],
|
||||||
]) ?>
|
]
|
||||||
|
); ?>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
|
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
|
||||||
|
@ -26,17 +26,11 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
['class' => 'yii\grid\SerialColumn'],
|
['class' => 'yii\grid\SerialColumn'],
|
||||||
[
|
[
|
||||||
'attribute' => 'manager_id',
|
'attribute' => 'manager_id',
|
||||||
'filter' => UserCard::find()->select(['fio', 'user_card.id'])
|
'value' => 'manager.user.userCard.fio',
|
||||||
->joinWith('manager')->where(['not',['manager.user_card_id' => null]])
|
|
||||||
->indexBy('user_card.id')->column(),
|
|
||||||
'value' => 'manager.userCard.fio',
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'attribute' => 'user_card_id',
|
'attribute' => 'employee_id',
|
||||||
'filter' => ManagerEmployee::find()->select(['fio', 'manager_employee.id'])
|
'value' => 'employee.email',
|
||||||
->joinWith('userCard')
|
|
||||||
->indexBy('manager_employee.id')->column(),
|
|
||||||
'value' => 'userCard.fio',
|
|
||||||
],
|
],
|
||||||
['class' => 'yii\grid\ActionColumn'],
|
['class' => 'yii\grid\ActionColumn'],
|
||||||
],
|
],
|
||||||
|
@ -15,16 +15,16 @@ use kartik\select2\Select2;
|
|||||||
|
|
||||||
<?php $form = ActiveForm::begin(); ?>
|
<?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'])
|
'data' => \common\models\UserCard::getListUserWithUserId(),
|
||||||
->joinWith('manager')->where(['manager.user_card_id' => null])
|
'options' => ['placeholder' => '...', 'class' => 'form-control'],
|
||||||
->indexBy('user_card.id')->column(),
|
|
||||||
'options' => ['placeholder' => '...','class' => 'form-control'],
|
|
||||||
'pluginOptions' => [
|
'pluginOptions' => [
|
||||||
'allowClear' => true
|
'allowClear' => true
|
||||||
],
|
],
|
||||||
]) ?>
|
]
|
||||||
|
); ?>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
|
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
|
||||||
|
@ -24,9 +24,8 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
'columns' => [
|
'columns' => [
|
||||||
['class' => 'yii\grid\SerialColumn'],
|
['class' => 'yii\grid\SerialColumn'],
|
||||||
[
|
[
|
||||||
'attribute' => 'user_card_id',
|
'attribute' => 'user_id',
|
||||||
'filter' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
|
'value' => 'user.email',
|
||||||
'value' => 'userCard.fio',
|
|
||||||
],
|
],
|
||||||
|
|
||||||
['class' => 'yii\grid\ActionColumn'],
|
['class' => 'yii\grid\ActionColumn'],
|
||||||
|
@ -38,7 +38,7 @@ YiiAsset::register($this);
|
|||||||
'id',
|
'id',
|
||||||
[
|
[
|
||||||
'attribute' => 'user_id',
|
'attribute' => 'user_id',
|
||||||
'value' => ArrayHelper::getValue($model,'userCard.fio'),
|
'value' => ArrayHelper::getValue($model,'user.email'),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
]) ?>
|
]) ?>
|
||||||
@ -52,9 +52,8 @@ YiiAsset::register($this);
|
|||||||
'columns' => [
|
'columns' => [
|
||||||
['class' => 'yii\grid\SerialColumn'],
|
['class' => 'yii\grid\SerialColumn'],
|
||||||
[
|
[
|
||||||
'attribute' => 'user_card_id',
|
'attribute' => 'employee_id',
|
||||||
'filter' => UserCard::find()->select(['fio', 'id'])->indexBy('id')->column(),
|
'value' => 'employee.email',
|
||||||
'value' => 'userCard.fio',
|
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'class' => 'yii\grid\ActionColumn',
|
'class' => 'yii\grid\ActionColumn',
|
||||||
|
@ -32,8 +32,8 @@ class ManagerEmployee extends \yii\db\ActiveRecord
|
|||||||
return [
|
return [
|
||||||
[['manager_id', 'employee_id'], 'required'],
|
[['manager_id', 'employee_id'], 'required'],
|
||||||
[['manager_id'], 'integer'],
|
[['manager_id'], 'integer'],
|
||||||
['employee_id', 'unique', 'targetAttribute' => ['manager_id', 'user_card_id'], 'message' => 'Этот сотрудник уже закреплён за менеджером'],
|
['employee_id', 'unique', 'targetAttribute' => ['manager_id', 'employee_id'], 'message' => 'Этот сотрудник уже закреплён за менеджером'],
|
||||||
[['employee_id'], 'exist', 'skipOnError' => true, 'targetClass' => UserCard::className(), 'targetAttribute' => ['user_card_id' => 'id']],
|
[['employee_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['employee_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']],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user