3 namespace app\controllers;
7 use app\models\StatusSearch;
8 use yii\web\Controller;
9 use yii\web\NotFoundHttpException;
10 use yii\filters\VerbFilter;
14 * StatusController implements the CRUD actions for Status model.
16 class StatusController extends Controller
21 public function behaviors()
25 'class' => VerbFilter::className(),
34 * Добавление в случае необходимости состояния
35 * @param array $options
36 * string 'name' - Наименование состояния
39 public function addIfNeed($options)
41 if (is_array($options) && isset($options[ 'name' ]))
42 $status = Status::find()
43 ->where([ 'like', 'name', $options[ 'name' ]])
45 if (count($status) > 0)
47 return $status[0]->id;
49 $status = new Status();
50 $status->name = $options[ 'name' ];
51 if ($status->validate() && $status->save())
59 * Показ всех состояний предметов/оборудования.
62 public function actionIndex()
64 if (! User::canPermission('createRecord'))
66 return $this->redirect(['site/index']);
68 $searchModel = new StatusSearch();
69 $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
71 return $this->render('index', [
72 'searchModel' => $searchModel,
73 'dataProvider' => $dataProvider,
78 * Показ одного состояния предмета/оборудования (не используется).
81 * @throws NotFoundHttpException если отсутствует состояние
83 public function actionView($id)
85 if (! User::canPermission('updateRecord'))
87 return $this->redirect(['index']);
89 return $this->render('view', [
90 'model' => $this->findModel($id),
95 * Создание новго состояния предмета/оборудования.
96 * В случае успешного создания, переход осуществляется к списку всех состояний предметов/оборудования.
99 public function actionCreate()
101 if (! User::canPermission('createRecord'))
103 return $this->redirect(['site/index']);
105 $model = new Status();
107 if ($model->load(Yii::$app->request->post()) && $model->save()) {
108 return $this->redirect(['index', 'id' => $model->id]);
111 return $this->render('create', [
117 * Изменение состояния предмета/оборудования.
118 * В случае успешного изменения, переход осуществляется к списку всех состояний предметов/оборудования.
121 * @throws NotFoundHttpException если отсутствует состояние предмета/оборудования
123 public function actionUpdate($id)
125 if (! User::canPermission('updateRecord'))
127 return $this->redirect(['index']);
129 $model = $this->findModel($id);
131 if ($model->load(Yii::$app->request->post()) && $model->save()) {
132 return $this->redirect(['index', 'id' => $model->id]);
135 return $this->render('update', [
141 * Deletes an existing Status model.
142 * В случае успешного удаления, переход осуществляется к списку всех состояний предметов/оборудования.
145 * @throws NotFoundHttpException если отсутствует состояние предмета/оборудования
147 public function actionDelete($id)
149 if (! User::canPermission('updateRecord'))
151 return $this->redirect(['index']);
153 $this->findModel($id)->delete();
155 return $this->redirect(['index']);
159 * Finds the Status model based on its primary key value.
160 * If the model is not found, a 404 HTTP exception will be thrown.
162 * @return Status the loaded model
163 * @throws NotFoundHttpException if the model cannot be found
165 protected function findModel($id)
167 if (($model = Status::findOne($id)) !== null) {
171 throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));