/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/AdsController.php (9743B)
[ 'class' => VerbFilter::className(), 'actions' => [ 'delete' => ['POST'], ], ], ]; } /** * Lists all Ads models. * @return mixed */ public function actionIndex() { $searchModel = new AdsSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } /** * Displays a single Ads model. * @param integer $id * @return mixed * @throws NotFoundHttpException if the model cannot be found */ public function actionView($id) { return $this->render('view', [ 'model' => $this->findModel($id), ]); } /** * Creates a new Ads model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Ads(); $modelLang = new AdsLang(); $appLanguages = Language::getAppLanguages(); if ($model->load(Yii::$app->request->post())) { // Handle file upload $uploadedFile = \yii\web\UploadedFile::getInstance($model, 'image_path'); if ($uploadedFile) { $uploadHelper = UploadHelper::getInstance(); $uploadHelper->setpath($uploadHelper->join([$uploadHelper::TEMP, $uploadHelper::ADS])); $uploadHelper->setUploadedFile($uploadedFile); $path = $uploadHelper->getPath(true); $realpath = $uploadHelper->getRealPath($path); $uploadedFile->saveAs($path); $model->image_path = DIRECTORY_SEPARATOR . $realpath; } // Set title from first language to pass validation $langData = Yii::$app->request->post('AdsLang', []); $firstLang = array_key_first($appLanguages); $model->title = isset($langData['title'][$firstLang]) ? $langData['title'][$firstLang] : ''; if ($model->save()) { // Save language data for all languages foreach ($appLanguages as $langCode => $langName) { $adsLang = new AdsLang(); $adsLang->ads_id = $model->ads_id; $adsLang->language_code = $langCode; $adsLang->title = isset($langData['title'][$langCode]) ? $langData['title'][$langCode] : ''; $adsLang->description = isset($langData['description'][$langCode]) ? $langData['description'][$langCode] : ''; $adsLang->save(); } Yii::$app->session->setFlash('success', Yii::t('backend', 'Ad created successfully')); return $this->redirect(['index']); } else { // Show validation errors Yii::$app->session->setFlash('error', 'Validation failed: ' . json_encode($model->errors)); } } return $this->render('create', [ 'model' => $model, 'modelLang' => $modelLang, 'appLanguages' => $appLanguages, ]); } /** * Updates an existing Ads 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 */ public function actionUpdate($id) { $model = $this->findModel($id); $appLanguages = Language::getAppLanguages(); // Load existing translation data for all languages $modelLang = []; foreach ($appLanguages as $langCode => $langName) { $langModel = AdsLang::findOne(['ads_id' => $id, 'language_code' => $langCode]); if ($langModel) { $modelLang[$langCode] = $langModel; } } if ($model->load(Yii::$app->request->post())) { // Handle file upload $uploadedFile = \yii\web\UploadedFile::getInstance($model, 'image_path'); if ($uploadedFile) { $uploadHelper = UploadHelper::getInstance(); $uploadHelper->setpath($uploadHelper->join([$uploadHelper::TEMP, $uploadHelper::ADS])); $uploadHelper->setUploadedFile($uploadedFile); $path = $uploadHelper->getPath(true); $realpath = $uploadHelper->getRealPath($path); $uploadedFile->saveAs($path); $model->image_path = DIRECTORY_SEPARATOR . $realpath; } // Set title from first language to pass validation $langData = Yii::$app->request->post('AdsLang', []); $firstLang = array_key_first($appLanguages); $model->title = isset($langData['title'][$firstLang]) ? $langData['title'][$firstLang] : $model->title; if ($model->save()) { // Update language data for all languages foreach ($appLanguages as $langCode => $langName) { $adsLang = AdsLang::findOne(['ads_id' => $model->ads_id, 'language_code' => $langCode]); if (!$adsLang) { $adsLang = new AdsLang(); $adsLang->ads_id = $model->ads_id; $adsLang->language_code = $langCode; } $adsLang->title = isset($langData['title'][$langCode]) ? $langData['title'][$langCode] : ''; $adsLang->description = isset($langData['description'][$langCode]) ? $langData['description'][$langCode] : ''; $adsLang->save(); } Yii::$app->session->setFlash('success', Yii::t('backend', 'Ad updated successfully')); return $this->redirect(['index']); } else { // Show validation errors Yii::$app->session->setFlash('error', 'Validation failed: ' . json_encode($model->errors)); } } return $this->render('update', [ 'model' => $model, 'modelLang' => $modelLang, 'appLanguages' => $appLanguages, ]); } /** * Change status * @return \yii\web\Response */ public function actionChangeStatus() { $post = Yii::$app->request->post(); $result = ['status' => STATUS_FAIL, 'msg' => '']; if (!isset($post['key']) || !isset($post['status'])) { $result['msg'] = Yii::t('backend', 'PARAM_MISSING'); return $this->asJson($result); } $model = $this->findModel($post['key']); $model->status = $post['status']; if ($model->save()) { $result['status'] = STATUS_SUCCESS; $result['msg'] = Yii::t('backend', 'Status updated successfully'); } else { $result['msg'] = Yii::t('backend', 'Failed to update status'); } return $this->asJson($result); } /** * Deletes an existing Ads 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 */ public function actionDelete($id) { $this->findModel($id)->delete(); return $this->redirect(['index']); } /** * Publish the ad and send push notification. * @param integer $id * @return mixed */ public function actionPublish($id) { $model = $this->findModel($id); $model->status = Ads::STATUS_ACTIVE; $model->save(); // Send push notification $oneSignal = OneSignal::getInstance(); $oneSignal->sendCustomerNotification( ['en' => Configuration::get(Configuration::APP_NAME)], ['en' => 'New Ad: ' . $model->title], 1 // Assuming app_type 1 for all ); // Save notification $notification = new Notification(); $notification->notification_title = 'New Advertisement'; $notification->notification_description = 'Check out our new ad: ' . $model->title; $notification->is_all_user = Notification::GLOBAL_NOTIFICATION; $notification->save(); Yii::$app->session->setFlash('success', 'Ad published and notification sent.'); return $this->redirect(['view', 'id' => $model->ads_id]); } /** * Finds the Ads model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Ads the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Ads::findOne($id)) !== null) { return $model; } throw new NotFoundHttpException('The requested page does not exist.'); } }