/** * Authenticates the locality. * This is the 'checkValidLocality' validator as declared in rules(). * returning true false does not stops proceeding to action. to stop add error to attribute. */ public function checkValidLocality($attribute, $params) { if (isset($this->address2bangalore_localities) && !$this->isEmpty($this->address2bangalore_localities)) { $modelArr = ABangaloreLocalities::model()->findAll(array('condition' => 'is_deleted = "no" and id = ' . $this->address2bangalore_localities)); } if (!isset($modelArr) || count($modelArr) < 1) { // no such record for locality exists $this->addError("address2bangalore_localities", CHtml::encode("Kindly select a valid locality.")); } }
/** * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. */ public function actionIndex() { $modelArr = ABangaloreLocalities::model()->findAll(array('condition' => 'is_deleted = "no"', 'order' => 'locality_name ASC')); $locality_arr = array(); foreach ($modelArr as $singleModel) { $locality_arr[] = $singleModel->locality_name; } // renders the view file 'protected/views/site/index.php' // using the default layout 'protected/views/layouts/main.php' $this->render('index', array('locality_arr' => $locality_arr)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { if (Yii::app()->getRequest()->getIsAjaxRequest() and $_GET['ajax'] == 1) { $response = array(); $model = new AAddress(); $model->city = 'Bengaluru'; //get localities list -start $modelArr = ABangaloreLocalities::model()->findAll(array('condition' => 'is_deleted = "no"', 'order' => 'locality_name ASC')); $locality_array = array(); foreach ($modelArr as $singleModel) { $locality_array[$singleModel->id] = $singleModel->locality_name; } $locality_array[""] = "Select any area"; //get localities list -stop // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['AAddress'])) { $model->attributes = $_POST['AAddress']; $currDateTime = new DateTime(); $model->creation_time = $currDateTime->format('Y-m-d H:i:s'); $model->link = AppCommon::getUserDetailsId(); $model->link_table = "user_details"; if ($model->save()) { //$this->redirect(array('view','id'=>$model->id)); //sending row html code with checked radio button $response["isRecordSaved"] = 1; $id_temp = $model->id; $Loc_name_temp = $model->address2bangaloreLocalities->locality_name; $address_temp = $model->getAddressString(); $response["html"] = '<tr><td>' . CHtml::activeRadioButton(new CheckoutFirstStageForm(), 'address', array('value' => $id_temp, 'required' => true, 'checked' => true, 'data-locality_name' => $Loc_name_temp, 'uncheckValue' => NULL)) . '</td><td>' . $address_temp . '</td><td>' . $Loc_name_temp . '</td><tr>'; $response["locality"] = $Loc_name_temp; echo CJSON::encode($response); Yii::app()->end(); } } $response["html"] = $this->renderPartial('create', array('model' => $model, 'locality_array' => $locality_array), true, false); $response["isRecordSaved"] = 0; echo CJSON::encode($response); Yii::app()->end(); } }
/** * Lists all models. * location=abc,xyz|date-start=2014-09-25 00:59:20|date-end=2014-09-26 00:59:20|tags=spicy,punjabi|chefs=c1,c2|sort=rating */ public function actionIndex($filters) { $currDateTime = new DateTime(); $currDateTime = $currDateTime->format('Y-m-d H:i:s'); $filters = $this->sanitizeInputString($filters); $arrayArgs = $this->getArgumentsFromString($filters); $orderByString = $this->getOrderByString($arrayArgs['sort'][0]); $tagsCondition = ""; $chefsCondition = ""; if (isset($arrayArgs['tags'])) { $tagsCondition = $this->getConditionString($arrayArgs['tags'], 'aFoodTags.tag_name'); } if (isset($arrayArgs['chefs'])) { $chefsCondition = $this->getConditionString($arrayArgs['chefs'], 'tiffin2userDetails.unique_name'); } $selectedTiffins = null; $modelArr = ABangaloreLocalities::model()->findAll('is_deleted = "no"'); $locality_arr = array(); foreach ($modelArr as $singleModel) { $locality_arr[strtolower($singleModel->locality_name)] = strtolower($singleModel->locality_name); } if ($tagsCondition != '') { $selectedTiffins = ATiffin::model()->findAll(array('select' => 't.id, t.name, t.contents, t.rating_of_tiffin, t.num_of_reviews, t.image', 'condition' => 't.verified_by != "not verified" AND t.is_deleted = "no"', 'order' => $orderByString, 'with' => array('tiffin2userDetails' => array('select' => 'tiffin2userDetails.id, tiffin2userDetails.first_name, tiffin2userDetails.last_name, tiffin2userDetails.rating_of_tiffinwala, tiffin2userDetails.unique_name', 'on' => 'tiffin2userDetails.is_active=1 AND tiffin2userDetails.user_type = 1', 'condition' => $chefsCondition, 'with' => array('aBangaloreLocalities' => array('select' => false, 'on' => 'aBangaloreLocalities.locality_name=' . '"' . $arrayArgs['location'][0] . '"', 'condition' => 'aBangaloreLocalities.is_deleted = "no" '))), 'aPriceTimes' => array('select' => 'aPriceTimes.price_after_discount, aPriceTimes.order_end_time, aPriceTimes.order_delivery_time, aPriceTimes.quantity_currently_available, aPriceTimes.orderType, aPriceTimes.discount', 'on' => 'aPriceTimes.order_start_time <= ' . '"' . $currDateTime . '"' . ' AND aPriceTimes.order_end_time >= ' . '"' . $currDateTime . '"' . ' AND aPriceTimes.order_delivery_time >= ' . '"' . $arrayArgs['date-start'][0] . '"' . ' AND aPriceTimes.order_delivery_time <= ' . '"' . $arrayArgs['date-end'][0] . '"', 'condition' => 'aPriceTimes.verified_by != "not verified" AND aPriceTimes.is_deleted = "no"'), 'aFoodTags' => array('select' => false, 'on' => $tagsCondition, 'condition' => 'aFoodTags.is_deleted = "no"'), 'aFoodTagsAll' => array('select' => 'aFoodTagsAll.tag_name', 'on' => 'aFoodTagsAll.is_deleted = "no"')))); } else { $selectedTiffins = ATiffin::model()->findAll(array('select' => 't.id, t.name, t.contents, t.rating_of_tiffin, t.num_of_reviews, t.image', 'condition' => 't.verified_by != "not verified" AND t.is_deleted = "no"', 'order' => $orderByString, 'with' => array('tiffin2userDetails' => array('select' => 'tiffin2userDetails.id, tiffin2userDetails.first_name, tiffin2userDetails.last_name, tiffin2userDetails.rating_of_tiffinwala, tiffin2userDetails.unique_name', 'on' => 'tiffin2userDetails.is_active=1 AND tiffin2userDetails.user_type = 1', 'condition' => $chefsCondition, 'with' => array('aBangaloreLocalities' => array('select' => false, 'on' => 'aBangaloreLocalities.locality_name=' . '"' . $arrayArgs['location'][0] . '"', 'condition' => 'aBangaloreLocalities.is_deleted = "no" '))), 'aPriceTimes' => array('select' => 'aPriceTimes.price_after_discount, aPriceTimes.order_end_time, aPriceTimes.order_delivery_time, aPriceTimes.quantity_currently_available, aPriceTimes.orderType, aPriceTimes.discount', 'on' => 'aPriceTimes.order_start_time <= ' . '"' . $currDateTime . '"' . ' AND aPriceTimes.order_end_time >= ' . '"' . $currDateTime . '"' . ' AND aPriceTimes.order_delivery_time >= ' . '"' . $arrayArgs['date-start'][0] . '"' . ' AND aPriceTimes.order_delivery_time <= ' . '"' . $arrayArgs['date-end'][0] . '"', 'condition' => 'aPriceTimes.verified_by != "not verified" AND aPriceTimes.is_deleted = "no"'), 'aFoodTagsAll' => array('select' => 'aFoodTagsAll.tag_name', 'on' => 'aFoodTagsAll.is_deleted = "no"')))); } $chefsfiltersArr = $this->getChefsFiltersWithNumbers($currDateTime, $arrayArgs['date-start'][0], $arrayArgs['date-end'][0], $tagsCondition, $arrayArgs['location'][0]); $tagsfiltersArr = $this->getTagsFiltersWithNumbers($currDateTime, $arrayArgs['date-start'][0], $arrayArgs['date-end'][0], $chefsCondition, $arrayArgs['location'][0]); //$selectedTiffins= ATiffin::model()->findAll( array( // 'condition'=>'id < 100', 'order'=>'id DESC',)); if (Yii::app()->getRequest()->getIsAjaxRequest() and $_GET['ajax'] == 1) { Yii::app()->getClientScript()->enableRenderingForAjaxResponse = true; //datetimepicker js and css should be stopped from loading again.As intitial page load of //tiffin/index does it. $assetUrl1 = Yii::app()->assetManager->publish(Yii::getPathOfAlias('ext.YiiDateTimePicker.assets')); Yii::app()->getClientScript()->bannedCoreScripts[] = 'jquery'; Yii::app()->getClientScript()->bannedJsFiles[] = $assetUrl1 . '/jquery.datetimepicker.js'; Yii::app()->getClientScript()->bannedCssFiles[] = $assetUrl1 . '/jquery.datetimepicker.css'; $html_code = $this->renderPartial('results_grid', array('selectedTiffins' => $selectedTiffins, 'chefsfiltersArr' => $chefsfiltersArr, 'tagsfiltersArr' => $tagsfiltersArr, 'arrayArgs' => $arrayArgs, 'locality_arr' => $locality_arr), true, true); $ajaxResponse = Yii::app()->getClientScript()->returnScriptStore(); $ajaxResponse["html_code"] = $html_code; Yii::app()->getClientScript()->bannedCoreScripts = array(); Yii::app()->getClientScript()->bannedJsFiles = array(); Yii::app()->getClientScript()->bannedCssFiles = array(); Yii::app()->getClientScript()->enableRenderingForAjaxResponse = false; echo CJSON::encode($ajaxResponse); return; } $this->render('index', array('selectedTiffins' => $selectedTiffins, 'chefsfiltersArr' => $chefsfiltersArr, 'tagsfiltersArr' => $tagsfiltersArr, 'arrayArgs' => $arrayArgs, 'locality_arr' => $locality_arr)); }