/var/www/vhosts/nabawater/backend/controllers
Edit: /var/www/vhosts/nabawater/backend/controllers/LanguageController.php (3847B)
render('index', [
'searchModel' => $searchModel,
'dataProvider' => $searchModel->search(Yii::$app->request->queryParams),
]);
}
/**
* @return string
* @throws \yii\base\InvalidParamException
*
* @Title("List/View Create")
* @author Senthil
*/
public function actionCreate()
{
$model = new Language();
$post = Yii::$app->getRequest()->post();
if( $model->load($post)) {
$model->status = Language::ACTIVE;
if($model->save(false)) {
Yii::$app->session->setFlash('success', Yii::t('backend', "Language created successfully"));
}
$this->redirect(['index']);
}
return $this->render('create', ['model' => $model]);
}
/**
* @param $id
* @return string
* @throws \yii\base\InvalidParamException
*
* @Title("List/View Update")
* @author Senthil
*/
public function actionUpdate($id)
{
$model = Language::findOne(['language_id' => $id]);
$post = Yii::$app->getRequest()->post();
if( $model->load($post) && $model->save(false)) {
Yii::$app->session->setFlash('success', Yii::t('backend', "Language updated successfully"));
$this->redirect(['index']);
}
return $this->render('update', ['model' => $model]);
}
/**
*
* @throws \yii\base\InvalidParamException
* @throws \yii\base\Exception
*
* @Assoc("actionUpdate")
* @author Senthil
*/
public function actionChangeStatus()
{
$params = ['id', 'status'];
$post = Yii::$app->getRequest()->post();
$result = ['status' => STATUS_FAIL, 'msg' => ''];
foreach ($params as $param) {
if ( !array_key_exists($param, $post) ) {
$result['msg'] = Yii::t('backend', 'Required param missing');
goto skip;
}
}
$model = Language::findOne(['language_id' => $post['id']]);
if ( $model === null ) {
$result['msg'] = Yii::t('backend', 'Unable to find the requested Language');
goto skip;
}
$model->status = $post['status'];
$model->save(false);
$result['msg'] = Yii::t('backend', 'Language deactivated successfully');
if ( (int)$model->status === $model::ACTIVE ) {
$result['msg'] = Yii::t('backend', 'Language activated successfully');
}
$result['status'] = STATUS_SUCCESS;
skip:
echo Json::encode($result);
}
/**
* @param $id
* @return string
* @throws \yii\base\InvalidParamException
*
* @Title("List/View Delete")
* @author Senthil
*/
public function actionDelete($id)
{
$model = Language::findOne(['language_id' => $id]);
if ( $model === null ) {
Yii::$app->session->setFlash('danger', Yii::t('backend', "Unable to find the requested Language"));
$this->redirect(['index']);
}
$model->status = $model::DELETE;
$model->save();
Yii::$app->session->setFlash('success', Yii::t('backend', "Language deleted successfully"));
$this->redirect(['index']);
}
}