/var/www/vhosts/nabawater/backend/controllers
Edit: /var/www/vhosts/nabawater/backend/controllers/UserLevelController.php (3787B)
render('index',
[
'searchModel' => $searchModel,
'dataProvider' => $searchModel->search(Yii::$app->request->queryParams)
]
);
}
/**
*
* @return string
*
* @Title("Create")
*/
public function actionCreate()
{
$model = new UserLevel();
$post = Yii::$app->getRequest()->post();
if ($model->load($post) && $model->validate()) {
$model->save();
Com::successFlash('Created Successfully');
return $this->redirect(['index']);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
*
* @param type $id
* @return string
*
* @Title("Update")
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$post = Yii::$app->getRequest()->post();
if ($model->load($post) && $model->validate()) {
$model->save();
Com::successFlash('Updated Successfully');
return $this->redirect(['index']);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* @return string
* @param type $id
*
* @Title("Delete")
*/
public function actionDelete($id)
{
$model = $this->findModel($id);
if ($model === null) {
Com::failureFlash('Unable to find the Customer Level Details');
return $this->redirect(['index']);
}
$model->status = UserLevel::DELETE;
$model->save();
Com::successFlash('Deleted Successfully');
return $this->redirect(['index']);
}
/**
*
* @param type $id
* @return $model
* @throws NotFoundHttpException
*/
protected function findModel($id)
{
if (($model = UserLevel::findOne(['user_level_key' => $id])) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
/**
* @return string
* @throws \yii\base\InvalidParamException
*
* @Title("User Level Status")
*/
public function actionChangeStatus()
{
$params = ['key', 'status'];
$post = Yii::$app->getRequest()->post();
$result = ['status' => STATUS_FAIL, 'msg' => ''];
foreach ($params as $param) {
if (!array_key_exists($param, $post)) {
$result['msg'] = 'Required param missing';
goto skip;
}
}
$model = UserLevel::findOne(['user_level_key' => $post['key']]);
if ($model === null) {
$result['msg'] = 'Unable to find the Customer Level Details';
goto skip;
}
$model->status = $post['status'];
$model->save(false);
$result['msg'] = 'Customer Level deactivated successfully';
if ((int)$model->status === $model::ACTIVE) {
$result['msg'] = 'Customer Level activated successfully';
}
$result['status'] = STATUS_SUCCESS;
skip:
return $this->asJson($result);
}
}