use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
+use app\models\User;
/**
* StatusController implements the CRUD actions for Status model.
}
/**
- * Lists all Status models.
+ * Добавление в случае необходимости состояния
+ * @param array $options
+ * string 'name' - Наименование состояния
+ * @return mixed
+ */
+ public function addIfNeed($options)
+ {
+ if (is_array($options) && isset($options[ 'name' ]))
+ $status = Status::find()
+ ->where([ 'like', 'name', $options[ 'name' ]])
+ ->all();
+ if (count($status) > 0)
+ {
+ return $status[0]->id;
+ }
+ $status = new Status();
+ $status->name = $options[ 'name' ];
+ if ($status->validate() && $status->save())
+ {
+ return $status->id;
+ }
+ return FALSE;
+ }
+
+ /**
+ * Показ всех состояний предметов/оборудования.
* @return mixed
*/
public function actionIndex()
{
+ if (! User::canPermission('createRecord'))
+ {
+ return $this->redirect(['site/index']);
+ }
$searchModel = new StatusSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
}
/**
- * Displays a single Status model.
+ * Показ одного состояния предмета/оборудования (не используется).
* @param integer $id
* @return mixed
- * @throws NotFoundHttpException if the model cannot be found
+ * @throws NotFoundHttpException если отсутствует состояние
*/
public function actionView($id)
{
+ if (! User::canPermission('updateRecord'))
+ {
+ return $this->redirect(['index']);
+ }
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
- * Creates a new Status model.
- * If creation is successful, the browser will be redirected to the 'view' page.
+ * Создание новго состояния предмета/оборудования.
+ * В случае успешного создания, переход осуществляется к списку всех состояний предметов/оборудования.
* @return mixed
*/
public function actionCreate()
{
+ if (! User::canPermission('createRecord'))
+ {
+ return $this->redirect(['site/index']);
+ }
$model = new Status();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['view', 'id' => $model->id]);
+ return $this->redirect(['index', 'id' => $model->id]);
}
return $this->render('create', [
}
/**
- * Updates an existing Status 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
+ * @throws NotFoundHttpException если отсутствует состояние предмета/оборудования
*/
public function actionUpdate($id)
{
+ if (! User::canPermission('updateRecord'))
+ {
+ return $this->redirect(['index']);
+ }
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['view', 'id' => $model->id]);
+ return $this->redirect(['index', 'id' => $model->id]);
}
return $this->render('update', [
/**
* Deletes an existing Status 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
+ * @throws NotFoundHttpException если отсутствует состояние предмета/оборудования
*/
public function actionDelete($id)
{
+ if (! User::canPermission('updateRecord'))
+ {
+ return $this->redirect(['index']);
+ }
$this->findModel($id)->delete();
return $this->redirect(['index']);