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)
+ {
+ $result = [
+ 'id' => FALSE,
+ 'error' => Yii::t('status', 'Status: Key field "status" missing: ') . print_r($options, TRUE),
+ ];
+ if (is_array($options) && isset($options[ 'status' ]))
+ $model = Status::find()
+ ->where([ 'like', 'name', $options[ 'status' ]])
+ ->all();
+ if (count($model) > 0)
+ {
+ $result[ 'id' ] = $model[0]->id;
+ $result [ 'error' ] = '';
+ }
+ else
+ {
+ $model = new Status();
+ $model->name = $options[ 'status' ];
+ if ($model->validate() && $model->save())
+ {
+ $result[ 'id' ] = $model->id;
+ $result[ 'error' ] = '';
+ }
+ else
+ {
+ $result[ 'error' ] = Yii::t('status', 'Failed to add entry "{status}": ', $options) . print_r($model->errors, TRUE);
+ }
+ }
+ return $result;
+ }
+
+ /**
+ * Показ всех состояний предметов/оборудования.
* @return mixed
*/
public function actionIndex()
{
+ if (! User::canPermission('createRecord'))
+ {
+ return $this->redirect(['site/index']);
+ }
$searchModel = new StatusSearch();
+ if (isset(Yii::$app->request->queryParams['id'])) {
+ $id = Yii::$app->request->queryParams['id'];
+ $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
+ //$dataProvider->query->select(Status::tableName() . '.id');
+ $pageSize = $dataProvider->pagination->pageSize;
+ $dataProvider->pagination = FALSE;
+ $rows = $dataProvider->getModels();
+ $page = 0;
+ foreach ($rows as $key => $val) {
+ if ($id == $val->id) {
+ $page = ceil(($key + 1) / $pageSize);
+ break;
+ }
+ }
+ return $this->redirect(['index', 'page' => $page]);
+ }
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
}
/**
- * 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()) {
}
/**
- * 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()) {
/**
* 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']);