public function up()
 {
     $tableOptions = null;
     if ($this->db->driverName === 'mysql') {
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
     }
     $this->createTable(Timezone::tableName(), ['id' => Schema::TYPE_PK, 'title' => Schema::TYPE_STRING . '(255) DEFAULT NULL', 'country' => Schema::TYPE_STRING . '(2) NOT NULL', 'timezone' => Schema::TYPE_STRING . '(255) NOT NULL', 'offset_gmt' => Schema::TYPE_DECIMAL . '(3,1) NOT NULL', 'offset_dst' => Schema::TYPE_DECIMAL . '(3,1) NOT NULL', 'offset_raw' => Schema::TYPE_DECIMAL . '(3,1) NOT NULL', 'order_popular' => Schema::TYPE_SMALLINT . ' NOT NULL DEFAULT 0', 'created_at' => Schema::TYPE_INTEGER . ' NOT NULL', 'updated_at' => Schema::TYPE_INTEGER . ' NOT NULL', 'UNIQUE (country, timezone)', 'FOREIGN KEY (country) REFERENCES ' . Country::tableName() . ' (iso) ON DELETE CASCADE ON UPDATE CASCADE'], $tableOptions);
 }
 public function up()
 {
     $tableOptions = null;
     if ($this->db->driverName === 'mysql') {
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
     }
     $this->createTable(Country\Translation::tableName(), ['country_id' => Schema::TYPE_INTEGER . ' NOT NULL', 'language' => $this->string(16)->notNull(), 'name' => $this->string(255)->notNull(), 'capital' => $this->string(255)->notNull(), 'currency_name' => $this->string(255)->notNull(), 'CONSTRAINT fk_countries_country_translations_country_id FOREIGN KEY (country_id) REFERENCES ' . Country::tableName() . ' (id) ON DELETE CASCADE ON UPDATE CASCADE', 'PRIMARY KEY(country_id, language)'], $tableOptions);
 }
Exemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Country::find();
     // add conditions that should always apply here
     $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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'iso_numeric' => $this->iso_numeric, 'area' => $this->area, 'population' => $this->population, 'geoname_id' => $this->geoname_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'iso', $this->iso])->andFilterWhere(['like', 'iso3', $this->iso3])->andFilterWhere(['like', 'fips', $this->fips])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'capital', $this->capital])->andFilterWhere(['like', 'continent', $this->continent])->andFilterWhere(['like', 'tld', $this->tld])->andFilterWhere(['like', 'currency_code', $this->currency_code])->andFilterWhere(['like', 'currency_name', $this->currency_name])->andFilterWhere(['like', 'phone_code', $this->phone_code])->andFilterWhere(['like', 'postal_code_format', $this->postal_code_format])->andFilterWhere(['like', 'postal_code_regex', $this->postal_code_regex])->andFilterWhere(['like', 'languages', $this->languages])->andFilterWhere(['like', 'neighbours', $this->neighbours])->andFilterWhere(['like', 'equivalent_fips_code', $this->equivalent_fips_code]);
     return $dataProvider;
 }
 /**
  * @see https://github.com/debuggable/php_arrays/tree/master/generators
  * @param type $file
  */
 protected function applyCsv($file)
 {
     if (($handle = fopen($file, 'r')) === false) {
         return;
     }
     for ($i = 0; ($data = fgetcsv($handle, 1000, "\t")) !== false; $i++) {
         if ($i === 0) {
             continue;
         }
         $country = Country::find()->with('translations')->where(['iso' => $data[0]])->one();
         if ($country === null) {
             continue;
         }
         $country->translate($this->language)->name = $data[4];
         $country->translate($this->language)->capital = $data[5];
         $country->translate($this->language)->currency_name = $data[10];
         if (!$country->save()) {
             throw new \yii\base\InvalidParamException('Unable to update country.');
         }
     }
     fclose($handle);
 }
 public function down()
 {
     $this->dropTable(Country::tableName());
 }