/var/www/vhosts/nabawater/backend/controllers
NameSizeModeActions
ActivityLogController.php16500644editdlrm
AddressTypeController.php64660644editdlrm
AdminOrderReportController.php35920644editdlrm
AdminUserController.php125230644editdlrm
AdsController.php97430644editdlrm
AreaController.php70190644editdlrm
BannerController.php71000644editdlrm
BranchController.php339890644editdlrm
BranchReviewController.php22090644editdlrm
CashBackPromotionsController.php120510644editdlrm
CategoryController.php87950644editdlrm
CityController.php55180644editdlrm
CmsController.php60260644editdlrm
ConfigurationController.php105640644editdlrm
CountryController.php52340644editdlrm
CouponController.php152450644editdlrm
CuisineController.php82070644editdlrm
DashboardController.php58050644editdlrm
DeliveryAreaController.php75060644editdlrm
DeliveryboyController.php76620644editdlrm
DeliveryChargeSettingsController.php45560644editdlrm
DriverOrderController.php35850644editdlrm
EnquiryController.php25410644editdlrm
FaqController.php65710644editdlrm
IngredientController.php69540644editdlrm
ItemController.php341500644editdlrm
ItemImportController.php38480644editdlrm
ItemIngredientGroupController.php111050644editdlrm
ItemMappingController.php121600644editdlrm
ItemTypeController.php74450644editdlrm
LanguageController.php38470644editdlrm
LoginController.php16840644editdlrm
LoyalityPointController.php66550644editdlrm
MallProductController.php63980644editdlrm
MetaTagController.php50390644editdlrm
MobileTranslationController.php44510644editdlrm
NewsLetterController.php52070664editdlrm
NewsletterController.php52070644editdlrm
NewsletterSubscriberController.php17470644editdlrm
NotificationController.php83820644editdlrm
OrderController.php937130644editdlrm
OrderMallProductController.php76610644editdlrm
OrderParcelController.php27520644editdlrm
OrderReportController.php39040644editdlrm
ParcelItemTypeController.php43570644editdlrm
PromotionController.php67100644editdlrm
PushNotificationController.php29900644editdlrm
RatingController.php6230644editdlrm
RefundRequestController.php29640644editdlrm
reject-index.php429310644editdlrm
RejectedOrderReportController.php5660644editdlrm
ReportController.php422320644editdlrm
RoleController.php52300644editdlrm
SiteController.php3570644editdlrm
StockController.php20670644editdlrm
TaxController.php45680644editdlrm
TodaySpecialController.php74730644editdlrm
TopOrderItemReportController.php38660644editdlrm
TopupController.php46190644editdlrm
UnitController.php71150644editdlrm
UserController.php135660644editdlrm
UserLevelController.php37870644editdlrm
VendorBankController.php28800644editdlrm
VendorController.php244910644editdlrm
VendorOrderReportController.php51460644editdlrm
VendorPaymentController.php60940644editdlrm
VendorTypeController.php84280644editdlrm
WalletController.php17910644editdlrm
WalletTranscationController.php22820644editdlrm
WebpushNotificationController.php25630644editdlrm
Edit: /var/www/vhosts/nabawater/backend/controllers/CashBackPromotionsController.php (12051B)
render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $searchModel->search(Yii::$app->request->queryParams) ] ); } /** * * @return string * * @Title("Create") */ public function actionCreate() { $model = new UserPromotion(); $modelLang = new UserPromotionLang(); $modelUploadForm = new PromotionUploadForm(); $modelUser = new UserPromotionUser(); $modelBranch = new UserPromotionBranch(); $modelUploadForm->setScenario($modelUploadForm::SCENARIO_CREATE); $appLanguages = Language::getAppLanguages(); return $this->render('create', [ 'model' => $model, 'modelLang' => $modelLang, 'appLanguages' => $appLanguages, 'modelUploadForm' => $modelUploadForm, 'modelBranch' => $modelBranch, 'modelUser' => $modelUser, ]); } /** * Save City * * @return Array * */ public function actionSave($id = NULL) { $response = ['status' => STATUS_FAIL, 'msg' => '', 'error' => []]; $transaction = UserPromotion::getDb()->beginTransaction(); $model = new UserPromotion(); $modelLang = new UserPromotionLang(); $modelUploadForm = new PromotionUploadForm(); $modelBranch = new UserPromotionBranch(); $modelUser = new UserPromotionUser(); if ($id !== null) { $model = $this->findModel($id); $modelLang->user_promotion_id = $model->getPrimaryKey(); } $appLanguages = Language::getAppLanguages(); $request = Yii::$app->getRequest()->post(); $model->load($request); $modelLang->load($request); $modelUser->load($request); $modelBranch->load($request); $modelLang->user_promotion_type = $model->user_promotion_type; if ($modelLang->validate()) { $model->payment_type = implode(',', $model->payment_type); if (!$model->save()) { $response['error'] = $this->prepareErrors($model); goto skip; } $modelPromUserDel = []; if($modelUser->user_id != null) { foreach ($modelUser->user_id as $key => $value) { $modelPromUser = UserPromotionUser::find() ->where([ 'user_promotion_id' => $model->getPrimaryKey(), 'user_id' => $value ])->one(); if($modelPromUser == null) { $modelPromUser = new UserPromotionUser(); } $modelPromUser->user_id = $value; $modelPromUser->user_promotion_id = $model->getPrimaryKey(); $modelPromUser->save(false); $modelPromUserDel[] = $modelPromUser->getPrimaryKey(); } } UserPromotionUser::deleteAll( [ 'AND', [ 'not in', 'user_promotion_user_id', $modelPromUserDel ], [ 'user_promotion_id' => $model->getPrimaryKey() ] ]); $modelPromBranchDel = []; if($modelBranch->branch_id != null) { foreach ($modelBranch->branch_id as $key => $value) { $modelPromBranch = UserPromotionBranch::find() ->where([ 'user_promotion_id' => $model->getPrimaryKey(), 'branch_id' => $value ])->one(); if($modelPromBranch == null) { $modelPromBranch = new UserPromotionBranch(); } //$modelPromBranch = new UserPromotionBranch(); $modelPromBranch->branch_id = $value; $modelPromBranch->user_promotion_id = $model->getPrimaryKey(); $modelPromBranch->save(false); $modelPromBranchDel[] = $modelPromBranch->getPrimaryKey(); } } UserPromotionBranch::deleteAll( [ 'AND', [ 'not in', 'user_promotion_branch_id', $modelPromBranchDel ], [ 'user_promotion_id' => $model->getPrimaryKey() ] ]); $fileHelper = FileUploadHelper::getInstance()->convertFileArray(); foreach ($appLanguages as $langCode => $langName) { $modelLang = UserPromotionLang::findOne([ 'user_promotion_id' => $model->getPrimaryKey(), 'language_code' => $langCode ]); if ($modelLang === null) { $modelLang = new UserPromotionLang(); $modelLang->user_promotion_id = $model->getPrimaryKey(); } $modelLang->loadTranslationAttribute($request, $langCode); $modelLang->user_promotion_id = $model->getPrimaryKey(); $uploadedFile = $fileHelper->getFileInstance($modelUploadForm, 'promotion_image_path', $langCode); if (!empty($uploadedFile)) { $uploadHelper = UploadHelper::getInstance(); $uploadHelper->setPath($uploadHelper::PROMOTION); $uploadHelper->setUploadedFile($uploadedFile); $path = $uploadHelper->getPath(true); $uploadedFile->saveAs($path); $realpath = $uploadHelper->getRealPath($path); $modelLang->user_promation_banner_path = '/'. $realpath ; } if (!$modelLang->save()) { $response['error'] = $this->prepareErrors($modelLang); goto skip; } else { $response['url'] = Url::to(['index']); if ($id !== null) { $adminUserData = Yii::$app->getUser()->getIdentity(); $adminUserName = $adminUserData->user_name; ActivityLog::log($adminUserName.' '. 'Edited Promotion'); Com::successFlash(Yii::t('backend', "Updated Successfully")); } else { $adminUserData = Yii::$app->getUser()->getIdentity(); $adminUserName = $adminUserData->user_name; ActivityLog::log($adminUserName.' '. 'created New Promotion'); Com::successFlash(Yii::t('backend', "Created Successfully")); } $response['status'] = STATUS_SUCCESS; } } $transaction->commit(); } else { $response['error'] = $this->prepareErrors($modelLang); goto skip; } skip: return $this->asJson($response); } /** * * @return string * * @Title("Update") */ public function actionUpdate($id) { $model = $this->findModel($id); $modelLang = UserPromotionLang::find()->where(['user_promotion_id' => $model->getPrimaryKey()])->one(); $modelUploadForm = new PromotionUploadForm(); $model->payment_type = explode(',', $model->payment_type); $modelUser = new UserPromotionUser(); $modelUserData = UserPromotionUser::find() ->select('GROUP_CONCAT(user_id) AS user_id') ->where(['user_promotion_id' => $model->getPrimaryKey()]) ->asArray() ->one(); $modelUser->user_id = explode(',', isset($modelUserData['user_id']) ? $modelUserData['user_id'] : ''); $modelBranch = new UserPromotionBranch(); $modelBranchData = UserPromotionBranch::find() ->select('GROUP_CONCAT(branch_id) AS branch_id') ->where(['user_promotion_id' => $model->getPrimaryKey()]) ->asArray() ->one(); $modelBranch->branch_id = explode(',', isset($modelBranchData['branch_id']) ? $modelBranchData['branch_id'] : ''); UserPromotionLang::updateTranslationAttribute($modelLang, $model->getPrimaryKey()); $appLanguages = Language::getAppLanguages(); return $this->render('update', [ 'model' => $model, 'modelLang' => $modelLang, 'appLanguages' => $appLanguages, 'modelUploadForm' => $modelUploadForm, 'modelBranch' => $modelBranch, 'modelUser' => $modelUser, ]); } /** * Finds the Category model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Category the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = UserPromotion::findOne(['user_promotion_key' => $id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } /** * * @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->user_promotion_status = $model::DELETE; $model->save(false); Com::successFlash(Yii::t('backend', 'Deleted Successfully')); return $this->redirect(['index']); } /** * * @return Json * @throws \yii\base\InvalidParamException * * * @Title("Change 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 = $this->findModel($post['key']); if ($model === null) { $result['msg'] = 'Unable to find the Area'; goto skip; } $model->user_promotion_status = $post['status']; $model->save(false); $result['msg'] = Yii::t('backend', 'Deactivated successfully'); if ((int)$model->user_promotion_status === $model::ACTIVE) { $result['msg'] = Yii::t('backend','Activated successfully'); } $result['status'] = STATUS_SUCCESS; skip: return $this->asJson($result); } }