Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = AdRealEstate::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'property' => $this->property, 'deal_type' => $this->deal_type, 'type_of_property' => $this->type_of_property, 'place_address_id' => $this->place_address_id, 'rooms_in_the_apartment' => $this->rooms_in_the_apartment, 'material_housing' => $this->material_housing, 'floor' => $this->floor, 'floors_in_the_house' => $this->floors_in_the_house, 'area_of_property' => $this->area_of_property, 'measurement_of_property' => $this->measurement_of_property, 'area_of_land' => $this->area_of_land, 'measurement_of_land' => $this->measurement_of_land, 'lease_term' => $this->lease_term, 'price' => $this->price, 'price_for_the_period' => $this->price_for_the_period, 'necessary_furniture' => $this->necessary_furniture, 'internet' => $this->internet, 'pets_allowed' => $this->pets_allowed, 'condition' => $this->condition, 'images_label' => $this->images_label]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 /**
  * Returns the array of possible user status values.
  *
  * @return array
  *
  */
 public function checkForm($scenario, $modelAdRealEstate)
 {
     /* @var $modelAdRealEstate \common\models\AdRealEstate */
     $modelAdRealEstate->setScenario($scenario);
     if (isset(Yii::$app->request->post('AdRealEstate')['appliances'])) {
         $modelAdRealEstate->appliances = Yii::$app->request->post('AdRealEstate')['appliances'];
     }
     /* Проверям заполненные поля для полученного сценария */
     if ($modelAdRealEstate->validate()) {
         /* Находит введенный город */
         $modelAdRealEstate = $this->findCity($modelAdRealEstate);
         /* Находит введенную улицу, если город найден */
         if (!$modelAdRealEstate->errors) {
             /* Сценарии для поиска улицы, с номером дома */
             if ($modelAdRealEstate->scenario == 'sellingRoom' || $modelAdRealEstate->scenario == 'rentARoom' || $modelAdRealEstate->scenario == 'sellingApatrment' || $modelAdRealEstate->scenario == 'rentApatrment' || $modelAdRealEstate->scenario == 'sellingHouse' || $modelAdRealEstate->scenario == 'rentHouse' || $modelAdRealEstate->scenario == 'sellingLand' || $modelAdRealEstate->scenario == 'sellingGarage' || $modelAdRealEstate->scenario == 'rentGarage' || $modelAdRealEstate->scenario == 'sellingComercial' || $modelAdRealEstate->scenario == 'rentComercial') {
                 if ($this->place_street != '' || $this->place_house != '') {
                     $modelAdRealEstate = $this->findAddress($modelAdRealEstate);
                 } else {
                     $modelAdRealEstate->place_address_id = '';
                 }
             }
         }
         if (!$modelAdRealEstate->errors) {
             /* Для определенных сценариев проверяем объявления на дублирование  */
             if ($modelAdRealEstate->scenario == 'buyRoom' || $modelAdRealEstate->scenario == 'rentingARoom' || $modelAdRealEstate->scenario == 'buyApatrment' || $modelAdRealEstate->scenario == 'rentingApatrment' || $modelAdRealEstate->scenario == 'buyHouse' || $modelAdRealEstate->scenario == 'rentingHouse' || $modelAdRealEstate->scenario == 'buyLand' || $modelAdRealEstate->scenario == 'buyGarage' || $modelAdRealEstate->scenario == 'rentingGarage' || $modelAdRealEstate->scenario == 'buyComercial' || $modelAdRealEstate->scenario == 'rentingComercial') {
                 $modelAdRealEstateIs = AdRealEstate::find()->where($this->getAttributesArray($modelAdRealEstate->attributes))->joinWith(['adCategory.adMain' => function ($query) {
                     $query->andWhere(['user_id' => Yii::$app->user->id]);
                     $query->andWhere(['phone_temp_ad' => $this->phone_temp_ad]);
                     $query->andWhere(['place_city_id' => $this->place_city_id]);
                 }])->one();
                 if ($modelAdRealEstateIs) {
                     // Если такаяже запись найдена, направляем на ее редактирование
                     $modelAdRealEstateIs->addError('model_is');
                     return $modelAdRealEstateIs;
                 }
             }
             $modelAdRealEstate = $this->saveAd($modelAdRealEstate);
         }
     }
     //dd($modelAdRealEstate->errors);
     return $modelAdRealEstate;
 }