Дипломная работа: Автоматизация обработки заявок в АО «ТЭК-Торг»

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам
131
}
}
/**
* Updates an existing Request model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
Yii::$app->user->identity->accessAdminManagerClient;
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save())
{
if (!Yii::$app->user->identity->isClient)
{
if (empty($model->id_user))
{
$model->id_user = Yii::$app->user->identity-
>id;
$model->save();
}
}
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render(Yii::$app->user->identity->isClient ?
'client_update' : 'update', [
'model' => $model,
]);
}
132
}
/**
* Deletes an existing Request model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
{
Yii::$app->user->identity->accessAdminManagerClient;
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the Request model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return Request the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Request::findOne($id)) !== null)
{
if (Yii::$app->user->identity->isClient)
{
if ($model->id_client <> Yii::$app->user->identity-
>id)
{
133
Yii::$app->user->getAccess ([]);
}
}
return $model;
} else {
throw new NotFoundHttpException('The requested page does not
exist.');
}
}
}
ServiceController.php
<?php
namespace app\controllers;
use Yii;
use app\models\Service;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
/**
* ServiceController implements the CRUD actions for Service model.
*/
class ServiceController extends Controller
134
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['index', 'view', 'create', 'update',
'delete'],
'allow' => true,
'roles' => ['@'],
],
],
],
];
}
/**
* Lists all Service models.
* @return mixed
*/
public function actionIndex()
135
{
Yii::$app->user->identity->accessAdminOnly;
$dataProvider = new ActiveDataProvider([
'query' => Service::find(),
]);
return $this->render('index', [
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Service model.
* @param integer $id
* @return mixed
*/
public function actionView($id)
{
Yii::$app->user->identity->accessAdminOnly;
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new Service model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
Yii::$app->user->identity->accessAdminOnly;
Источник: https://baza.diplomsite.ru/previewfile/1859