complete the manager module

This commit is contained in:
iIronside 2021-11-22 15:34:46 +03:00
parent 957e777da5
commit 12648f16f8
4 changed files with 46 additions and 14 deletions

View File

@ -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([

View File

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

View File

@ -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(
'<span class="glyphicon glyphicon-pencil"></span>',
['manager-employee/update', 'id' => $model['id'], 'manager_id' => $model['manager_id']]);
},
'delete' => function ($url,$model) {
return Html::a(
'<span class="glyphicon glyphicon-trash"></span>',
[
'manager-employee/delete', 'id' => $model['id'], 'manager_id' => $model['manager_id']
],
[
'data' => ['confirm' => 'Вы уверены, что хотите удалить этого сотрудника?', 'method' => 'post']
]
);
},
],
],
],
]); ?>

View File

@ -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()
{