/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $this->load($params);
     $query = Location::find();
     $query->select(['*', 'uid' => 'location.uid', 'name' => 'city_translation.name', 'language' => 'city.language_id']);
     $query->innerJoin('city', 'location.city_id=city.id');
     $query->leftJoin('city_translation', 'city_translation.city_id=city.id');
     //$query->andWhere(['city.language_id' => 'city_translation.language_id']);
     //   $query->joinWith('city');
     //    $query->joinWith('city.localisedIdentification');
     if (isset($this->uid)) {
         $this->pageSize = 1;
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => $this->pagination ? ['pageSize' => $this->pageSize] : FALSE, 'sort' => ['attributes' => ['name', 'postcode', 'language']]]);
     if (isset($this->uid)) {
         // uncomment the following line if you do not want to return any records when validation fails
         $query->where(['location.uid' => $this->uid]);
         return $dataProvider;
     }
     if (!$this->validate() || !isset($this->country_id)) {
         // uncomment the following line if you do not want to return any records when validation fails
         $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['country_id' => $this->country_id]);
     $query->andFilterWhere(['NOT IN', 'postcode', ['-1', '0']]);
     $query->andFilterWhere(['or', ['like', 'postcode', $this->q], ['like', 'city_translation.name', $this->q]]);
     return $dataProvider;
 }
Beispiel #2
0
 public static function findRemote($uid)
 {
     $model = self::findOne(['uid' => $uid]);
     if (!isset($model)) {
         $model = new Location(['uid' => $uid]);
         $model->download();
     }
     return $model;
 }
Beispiel #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getLocations()
 {
     return $this->hasMany(Location::className(), ['country_id' => 'iso_2']);
 }
Beispiel #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getLocation()
 {
     return $this->hasOne(Location::className(), ['id' => 'location_id']);
 }
 /**
  * Finds the Location model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Location the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Location::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getLocations()
 {
     return $this->hasMany(Location::className(), ['city_id' => 'id']);
 }
 private function _dummyLocation($countryId, $name, $postCode)
 {
     //CityTranslation::find()->where(['language_id' => 'EN', 'name' => $name])->queryScalar();
     $dummyCity = new \humanized\location\models\location\City(['language_id' => 'EN']);
     try {
         $dummyCity->save();
         try {
             $dummyCityTranslation = new \humanized\location\models\translation\CityTranslation(['language_id' => 'EN', 'city_id' => $dummyCity->id, 'name' => $name]);
             $dummyCityTranslation->save();
             try {
                 $dummyLocation = new \humanized\location\models\location\Location(['postcode' => $postCode, 'city_id' => $dummyCity->id, 'country_id' => $countryId]);
                 $dummyLocation->save();
             } catch (Exception $ex) {
             }
         } catch (Exception $ex) {
         }
     } catch (\Exception $ex) {
     }
 }
 public function actionMatchNuts()
 {
     Location::find()->all();
 }