diff --git a/backend/modules/employee/controllers/ManagerController.php b/backend/modules/employee/controllers/ManagerController.php
index b2ac0b6..99ee7d7 100644
--- a/backend/modules/employee/controllers/ManagerController.php
+++ b/backend/modules/employee/controllers/ManagerController.php
@@ -54,14 +54,6 @@ class ManagerController extends Controller
*/
public function actionView($id)
{
-// $model = $this->findModel($id);
-// $questionSearchModel = new QuestionSearch();
-// $questionDataProvider = new ActiveDataProvider([
-// 'query' => $model->getQuestions()->with('questionType'),
-// 'pagination' => [
-// 'pageSize' => 20,
-// ],
-// ]);
$model = $this->findModel($id);
$managerEmployeeSearchModel = new ManagerEmployeeSearch();
$managerEmployeeDataProvider = new ActiveDataProvider([
diff --git a/backend/modules/employee/controllers/ManagerEmployeeController.php b/backend/modules/employee/controllers/ManagerEmployeeController.php
index 400649d..61095a8 100644
--- a/backend/modules/employee/controllers/ManagerEmployeeController.php
+++ b/backend/modules/employee/controllers/ManagerEmployeeController.php
@@ -82,11 +82,15 @@ class ManagerEmployeeController extends Controller
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
- public function actionUpdate($id)
+ public function actionUpdate($id, $manager_id = null)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
+ if ($manager_id !== null)
+ {
+ return $this->redirect(['manager/view', 'id' => $manager_id]);
+ }
return $this->redirect(['view', 'id' => $model->id]);
}
@@ -102,10 +106,15 @@ class ManagerEmployeeController extends Controller
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
- public function actionDelete($id)
+ public function actionDelete($id, $manager_id = null)
{
$this->findModel($id)->delete();
+ if ($manager_id !== null)
+ {
+ return $this->redirect(['manager/view', 'id' => $manager_id]);
+ }
+
return $this->redirect(['index']);
}
diff --git a/backend/modules/employee/views/manager/view.php b/backend/modules/employee/views/manager/view.php
index a92ecf4..2b61816 100644
--- a/backend/modules/employee/views/manager/view.php
+++ b/backend/modules/employee/views/manager/view.php
@@ -44,7 +44,6 @@ YiiAsset::register($this);
= GridView::widget([
'dataProvider' => $managerEmployeeDataProvider,
-// 'filterModel' => $managerEmployeeSearchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
@@ -52,7 +51,30 @@ YiiAsset::register($this);
'filter' => User::find()->select(['username', 'id'])->indexBy('id')->column(),
'value' => 'user.username',
],
- ['class' => 'yii\grid\ActionColumn'],
+ [
+ 'class' => 'yii\grid\ActionColumn',
+ 'template' => '{view} {update} {delete}',
+ 'controller' => 'manager-employee',
+ 'buttons' => [
+
+ 'update' => function ($url,$model) {
+ return Html::a(
+ '',
+ ['manager-employee/update', 'id' => $model['id'], 'manager_id' => $model['manager_id']]);
+ },
+ 'delete' => function ($url,$model) {
+ return Html::a(
+ '',
+ [
+ 'manager-employee/delete', 'id' => $model['id'], 'manager_id' => $model['manager_id']
+ ],
+ [
+ 'data' => ['confirm' => 'Вы уверены, что хотите удалить этого сотрудника?', 'method' => 'post']
+ ]
+ );
+ },
+ ],
+ ],
],
]); ?>
diff --git a/common/models/Manager.php b/common/models/Manager.php
index 011c601..ae1740c 100644
--- a/common/models/Manager.php
+++ b/common/models/Manager.php
@@ -3,6 +3,7 @@
namespace common\models;
use Yii;
+use yii\db\ActiveQuery;
/**
* This is the model class for table "manager".
@@ -45,8 +46,16 @@ class Manager extends \yii\db\ActiveRecord
];
}
+ public function beforeDelete()
+ {
+ foreach ($this->managerEmployees as $employee){
+ $employee->delete();
+ }
+ return parent::beforeDelete();
+ }
+
/**
- * @return \yii\db\ActiveQuery
+ * @return ActiveQuery
*/
public function getUser()
{
@@ -54,7 +63,7 @@ class Manager extends \yii\db\ActiveRecord
}
/**
- * @return \yii\db\ActiveQuery
+ * @return ActiveQuery
*/
public function getManagerEmployees()
{