/var/www/vhosts/nabawater/backend/controllers
Edit: /var/www/vhosts/nabawater/backend/controllers/AreaController.php (7019B)
render('index',
[
'searchModel' => $searchModel,
'dataProvider' => $searchModel->search(Yii::$app->request->queryParams)
]
);
}
/**
*
* @return string
*
* @Title("Create")
*/
public function actionCreate()
{
$model = new Area();
$modelLang = new AreaLang();
$modelCountry = $model->getCountryData();
$modelCity = $model->getCityData();
$post = Yii::$app->getRequest()->post();
$appLanguages = Language::getAppLanguages();
if ($model->load($post) && $model->validate()) {
$model->save();
foreach($appLanguages as $langCode => $langName) {
$modelTranslation = new AreaLang();
$modelTranslation->loadTranslationAttribute($post, $langCode);
$modelTranslation->area_id = $model->getPrimaryKey();
$modelTranslation->save();
}
Com::successFlash(Yii::t('backend','Created Successfully'));
return $this->redirect(['index']);
}
return $this->render('create', [
'model' => $model,
'modelLang' => $modelLang,
'modelCountry' => $modelCountry,
'modelCity' => $modelCity,
'appLanguages' => $appLanguages
]);
}
/**
*
* @param type $id
* @return string
*
* @Title("Update")
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$modelLang = new AreaLang();
$modelCountry = $model->getCountryData();
$modelCity = $model->getCityData();
$post = Yii::$app->getRequest()->post();
AreaLang::updateTranslationAttribute($modelLang, $model->getPrimaryKey());
$appLanguages = Language::getAppLanguages();
if ($model->load($post) && $model->validate()) {
$model->save();
foreach ($appLanguages as $langCode => $langName) {
$modelTranslation = AreaLang::findOne([
'area_id' => $model->getPrimaryKey(),
'language_code' => $langCode
]);
if ($modelTranslation === null) {
$modelTranslation = new AreaLang();
$modelTranslation->area_id = $model->getPrimaryKey();
}
$modelTranslation->loadTranslationAttribute($post, $langCode);
$modelTranslation->save();
}
Com::successFlash(Yii::t('backend','Updated Successfully'));
return $this->redirect(['index']);
}
return $this->render('update', [
'model' => $model,
'modelLang' => $modelLang,
'modelCountry' => $modelCountry,
'modelCity' => $modelCity,
'appLanguages' => $appLanguages
]);
}
/**
*
* @param type $id
* @return string
*
* @Title("Delete")
*/
public function actionDelete($id)
{
$model = $this->findModel($id);
if ($model === null) {
Com::failureFlash('Unable to find the Ingredient');
return $this->redirect(['index']);
}
$model->area_status = Area::DELETE;
$model->save();
Com::successFlash(Yii::t('backend','Deleted Successfully'));
return $this->redirect(['index']);
}
/**
*
* @param type $id
* @return type
* @throws NotFoundHttpException
*/
protected function findModel($id)
{
if (($model = Area::findOne(['area_key' => $id])) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
/**
*
* @return Json
* @throws \yii\base\InvalidParamException
*
*
* @Title("Area 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 = Area::findOne(['area_key' => $post['key']]);
if ($model === null) {
$result['msg'] = 'Unable to find the Area';
goto skip;
}
$model->area_status = $post['status'];
$model->save(false);
$result['msg'] = Yii::t('backend','Area deactivated successfully');
if ((int)$model->area_status === $model::ACTIVE) {
$result['msg'] = Yii::t('backend','Area activated successfully');
}
$result['status'] = STATUS_SUCCESS;
skip:
return $this->asJson($result);
}
public function actionGetCity()
{
$params = ['id'];
$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 = City::findOne(['area_key' => $post['id']]);
if ($model === null) {
$result['msg'] = 'Unable to find the Area';
goto skip;
}
$model->area_status = $post['status'];
$model->save(false);
$result['msg'] = 'Area deactivated successfully';
if ((int)$model->area_status === $model::ACTIVE) {
$result['msg'] = 'Area activated successfully';
}
$result['status'] = STATUS_SUCCESS;
skip:
return $this->asJson($result);
}
public function actionGetArea()
{
$request = Yii::$app->getRequest()->post();
$area = Area::GetAllAreaData($request['city']);
$option = Html::tag('option', 'Please Select', ['value' => '']);
foreach ($area as $value) {
$option .= Html::tag('option', $value['area_name'], ['value' => $value['area_id']]);
}
$result = $option;
return $this->asJson($result);
}
}