guild/backend/modules/employee/controllers/ManagerEmployeeController.php

154 lines
4.2 KiB
PHP
Raw Permalink Normal View History

2021-11-16 13:14:28 +03:00
<?php
namespace backend\modules\employee\controllers;
2023-05-04 15:10:56 +03:00
use common\classes\Debug;
2021-11-16 13:14:28 +03:00
use Yii;
use backend\modules\employee\models\ManagerEmployee;
use backend\modules\employee\models\ManagerEmployeeSearch;
use yii\helpers\ArrayHelper;
2021-11-16 13:14:28 +03:00
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* ManagerEmployeeController implements the CRUD actions for ManagerEmployee model.
*/
class ManagerEmployeeController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
2022-12-28 11:45:57 +03:00
'as AccessBehavior' => [
'class' => \developeruz\db_rbac\behaviors\AccessBehavior::className(),
],
2021-11-16 13:14:28 +03:00
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all ManagerEmployee models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new ManagerEmployeeSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single ManagerEmployee model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new ManagerEmployee model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
2022-11-03 17:46:36 +03:00
$post = \Yii::$app->request->post('ManagerEmployee');
if (!empty($post)) {
2023-05-04 15:10:56 +03:00
$user_card_id_arr = ArrayHelper::getValue($post, 'employee_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,
]);
}
2023-05-04 15:10:56 +03:00
return $this->redirect(['index']);
2021-11-16 13:14:28 +03:00
}
$model = new ManagerEmployee();
2021-11-16 13:14:28 +03:00
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing ManagerEmployee model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
2021-11-22 15:34:46 +03:00
public function actionUpdate($id, $manager_id = null)
2021-11-16 13:14:28 +03:00
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
2023-05-04 15:10:56 +03:00
if ($manager_id !== null) {
2021-11-22 15:34:46 +03:00
return $this->redirect(['manager/view', 'id' => $manager_id]);
}
2021-11-16 13:14:28 +03:00
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing ManagerEmployee model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
2021-11-22 15:34:46 +03:00
public function actionDelete($id, $manager_id = null)
2021-11-16 13:14:28 +03:00
{
$this->findModel($id)->delete();
2023-05-04 15:10:56 +03:00
if ($manager_id !== null) {
2021-11-22 15:34:46 +03:00
return $this->redirect(['manager/view', 'id' => $manager_id]);
}
2021-11-16 13:14:28 +03:00
return $this->redirect(['index']);
}
/**
* Finds the ManagerEmployee model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return ManagerEmployee the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = ManagerEmployee::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}