Esempio n. 1
0
 /**
  * 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;
 }
Esempio n. 2
0
 /**
  * 
  */
 protected function _queryCountry()
 {
     $query = Location::find();
     /*
      $language = Translation::current();
      $exp = new Expression("'$language'");
      $query->leftJoin('city', '`location`.`city_id` = `city`.`id`');
      $query->leftJoin('city_translation default_label', '(`city`.`id` = `default_label`.`city_id` AND `city`.`language_id` = `default_label`.`language_id`)');
      $query->leftJoin('city_translation localised_label', "(`city`.`id`=`localised_label`.`city_id` AND $exp =`localised_label`.`language_id`)");
     
      $query->select = [
      'id' => 'location.id',
      'name' => 'IF(localised_label.name IS NULL, default_label.name, localised_label.name)',
      'label' => 'CONCAT(IF(localised_label.name IS NULL, default_label.name, localised_label.name), \' (\',postcode,\')\')',
      'postcode' => 'location.postcode',
      'language' => 'city.language_id'
      ];
     *
     */
     $query->andWhere(['country_id' => $this->country_id]);
     return $query;
 }
 public function actionMatchNuts()
 {
     Location::find()->all();
 }