/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $this->load($params); $query = City::find(); $query->select(['*', 'name' => 'city_translation.name', 'language' => 'city.language_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(['uid' => $this->uid]); return $dataProvider; } 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; } return $dataProvider; }
public function beforeValidate() { if (!parent::beforeValidate()) { return false; } //Remote Settings Empty --> Master Mode if (!isset($this->uid)) { //echo "Generating UID"; $this->uid = uniqid(); } if (isset($this->name) && isset($this->language)) { $params = ['city_translation.name' => $this->name, 'city.language_id' => strtoupper($this->language)]; $model = City::find()->where($params)->joinWith('name')->one(); if (!isset($model)) { $model = new City(['local_name' => $this->name, 'language_id' => strtoupper($this->language)]); $model->save(); } $this->city_id = $model->id; } return true; }
public static function getCityList($params) { return City::find()->asArray()->all(); }