/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/ItemIngredientGroupController.php (11105B)
render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $searchModel->search(Yii::$app->request->queryParams) ] ); } /** * * @return string * * @Title("Create") */ public function actionCreate() { $model = new ItemIngredientGroup(); $model->setScenario($model::SCENARIO_CREATE); $modelLang = new ItemIngredientGroupLang(); $modelMap = new ItemIngredientMapping(); $post = Yii::$app->getRequest()->post(); $appLanguages = Language::getAppLanguages(); $model->load($post); $modelLang->vendor_id = $model->vendor_id; if ($model->load($post) && $modelLang->load($post) && $modelLang->vendor_id = $model->vendor_id && $modelLang->validate()) { if ($model->save()) { ItemIngredientMapping::deleteAll(['item_ingredient_group_id' => $model->getPrimaryKey()]); foreach($appLanguages as $langCode => $langName) { $modelTranslation = new ItemIngredientGroupLang(); $modelTranslation->loadTranslationAttribute($post, $langCode); $modelTranslation->item_ingredient_group_id = $model->getPrimaryKey(); $modelTranslation->save(); } foreach (explode(',', $post['ItemIngredientGroup']['mapping']) as $mappingKey => $mappingValue) { $modelMapmodel = new ItemIngredientMapping(); $modelMapmodel->item_ingredient_group_id = $model->getPrimaryKey(); $modelMapmodel->ingredient_id = $mappingValue; $modelMapmodel->default_status = (isset($post['ingredient_default'][$mappingValue])) ? 2 : 0; $modelMapmodel->price = (isset($post['price_default'][$mappingValue])) ? $post['price_default'][$mappingValue] : 0; $modelMapmodel->load($post); $modelMapmodel->save(); } Com::successFlash('Created Successfully'); return $this->redirect(['index']); } } return $this->render('create', [ 'model' => $model, 'modelLang' => $modelLang, 'mappedIds' => '', 'appLanguages' => $appLanguages ]); } /** * * @param type $id * @return string * * @Title("Update") */ public function actionUpdate($id) { $model = $this->findModel($id); $model->setScenario($model::SCENARIO_CREATE); $modelLang = new ItemIngredientGroupLang(); $modelMap = ItemIngredientMapping::find()->where(['item_ingredient_group_id' => $model->getPrimaryKey()])->all(); $mappedIds = ''; foreach ($modelMap as $modelMapKey => $modelMapValue) { $mappedIds .= $modelMapValue['ingredient_id'].","; } $mappedIds = rtrim($mappedIds, ','); $post = Yii::$app->getRequest()->post(); $appLanguages = Language::getAppLanguages(); ItemIngredientGroupLang::updateTranslationAttribute($modelLang, $model->getPrimaryKey()); $model->load($post); //sprint_r($model); die; $modelLang->vendor_id = $model->vendor_id; if ($model->load($post) && $model->validate() && $modelLang->load($post) && $modelLang->validate()) { //; //print_r($modelLang->validate()); die; // if( $modelLang->load($post)) if ($model->save()) { foreach ($appLanguages as $langCode => $langName) { $modelTranslation = ItemIngredientGroupLang::findOne([ 'item_ingredient_group_id' => $model->getPrimaryKey(), 'language_code' => $langCode ]); if ($modelTranslation === null) { $modelTranslation = new ItemIngredientGroupLang(); $modelTranslation->item_ingredient_group_id = $model->getPrimaryKey(); } $modelTranslation->loadTranslationAttribute($post, $langCode); $modelTranslation->save(); } ItemIngredientMapping::deleteAll(['item_ingredient_group_id' => $model->getPrimaryKey()]); $mappingArray = explode(',', $post['ItemIngredientGroup']['mapping']); foreach ($mappingArray as $mappingKey => $mappingValue) { $modelMapping = ItemIngredientMapping::find()->where([ 'item_ingredient_group_id' => $model->getPrimaryKey(), 'ingredient_id' => $mappingValue, ])->one(); if ($modelMapping === null) { $modelMapping = new ItemIngredientMapping(); $modelMapping->item_ingredient_group_id = $model->getPrimaryKey(); $modelMapping->ingredient_id = $mappingValue; } $modelMapping->default_status = (isset($post['ingredient_default'][$mappingValue])) ? 2 : 1; $modelMapping->price = (isset($post['price_default'][$mappingValue])) ? $post['price_default'][$mappingValue] : 0; if (!$modelMapping->save()) { echo"
";print_r($modelMapping->getErrors());
                        exit;
                    }
                }
            }
                       
            Com::successFlash('Updated Successfully');
            return $this->redirect(['index']);
        }

        return $this->render('update', [
            'model' => $model,
            'modelLang' => $modelLang,
            'mappedIds' => $mappedIds,
            '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 Item Ingredient Group');
            return $this->redirect(['index']);
        }
        $model->item_ingredient_status = ItemIngredientGroup::DELETE;
        $model->save();

        $adminUserData = Yii::$app->getUser()->getIdentity();
        $adminUserName = $adminUserData->attributes['user_name'];
        $branchName = ItemIngredientGroupLang::find()->where(['item_ingredient_group_id' => $model->item_ingredient_group_id,'language_code' => Yii::$app->language])->one();
        ActivityLog::log($adminUserName.' '. 'deleted item ingredient group '.' '. $branchName->group_name);

        Com::successFlash('Deleted Successfully');

        return $this->redirect(['index']);
    }

   /**
    * 
    * @param type $id
    * @return $model
    * @throws NotFoundHttpException
    */
    protected function findModel($id)
    {
        if (($model = ItemIngredientGroup::findOne(['item_ingredient_group_key' => $id])) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
    
    /**
     * 
     * @return Json
     * @throws \yii\base\InvalidParamException
     * 
     * @Title("Item Ingredient Group 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 = ItemIngredientGroup::findOne(['item_ingredient_group_key' => $post['key']]);
        if ($model === null) {
            $result['msg'] = 'Unable to find the Item';
            goto skip;
        }
        $model->item_ingredient_status = $post['status'];
        $model->save(false);

        $result['msg'] = 'Ingredient group deactivated successfully';
        if ((int)$model->item_ingredient_status === $model::ACTIVE) {
            $result['msg'] = 'Ingredient group activated successfully';
        }

        $result['status'] = STATUS_SUCCESS;

        skip:
        return $this->asJson($result);
    }
    
    /**
     * 
     * @param type $id
     * @return $model
     * @throws NotFoundHttpException
     */
    protected function findImageModel($id)
    {
        $model = ItemImage::find()
            ->alias('IM')
            ->select('IM.item_image_path')
            ->leftJoin(['I' => Item::tableName()], 'IM.item_id = I.item_id')
            ->where(['I.item_key' => $id])
            ->one();
        return $model;
       
        if ($model === null) {
             throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
    
    /**
     * @return string
     */
    public function actionGetBranch()
    {
        $post = Yii::$app->request->post();
        $vendorId = $post['id'];
        $branches = Branch::find()
            ->alias('B')
            ->select('BL.branch_name')
            ->leftJoin(['BL' => BranchLang::tableName()], 'BL.branch_id = B.branch_id')
            ->where(['B.vendor_id' => $vendorId])
            ->all();
        $option = Html::tag('option', 'Please Select', ['value' => '']);#'';
        
        foreach ($branches as $branch) {
            $option .= Html::tag('option', $branch->branch_name, ['value' => $branch->branch_id]);
            
        }
        echo $option;  
    }  

    public function actionVendorIng()
    {
        $post = Yii::$app->request->post();

        $model = ItemIngredientGroup::getIngredients('','NOT IN','', $post['id']);
        
        $html = $this->renderPartial('ingredient_group_ajax',['ingredientData' => $model]);
        
        return $this->asJson($html);
    }  
}