1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Dimsav\Translatable\Test\Model\City; |
4
|
|
|
use Dimsav\Translatable\Test\Model\CityTranslation; |
5
|
|
|
use Dimsav\Translatable\Test\Model\Country; |
6
|
|
|
use Dimsav\Translatable\Test\Model\CountryTranslation; |
7
|
|
|
|
8
|
|
|
class AddFreshSeeds |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
public function run() |
11
|
|
|
{ |
12
|
|
|
$countries = [ |
13
|
|
|
['id' => 1, 'code' => 'gr'], |
14
|
|
|
['id' => 2, 'code' => 'fr'], |
15
|
|
|
['id' => 3, 'code' => 'en'], |
16
|
|
|
['id' => 4, 'code' => 'de'], |
17
|
|
|
]; |
18
|
|
|
|
19
|
|
|
$this->createCountries($countries); |
20
|
|
|
|
21
|
|
|
$countryTranslations = [ |
22
|
|
|
['country_id' => 1, 'locale' => 'el', 'name' => 'Ελλάδα'], |
23
|
|
|
['country_id' => 1, 'locale' => 'fr', 'name' => 'Grèce'], |
24
|
|
|
['country_id' => 1, 'locale' => 'en', 'name' => 'Greece'], |
25
|
|
|
['country_id' => 1, 'locale' => 'de', 'name' => 'Griechenland'], |
26
|
|
|
['country_id' => 2, 'locale' => 'en', 'name' => 'France'], |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
$this->createCountryTranslations($countryTranslations); |
30
|
|
|
|
31
|
|
|
$cities = [ |
32
|
|
|
['id' => 1, 'country_id' => 1], |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
$this->createCities($cities); |
36
|
|
|
|
37
|
|
|
$cityTranslations = [ |
38
|
|
|
['city_id' => 1, 'locale' => 'el', 'name' => 'Αθήνα'], |
39
|
|
|
['city_id' => 1, 'locale' => 'fr', 'name' => 'Athènes'], |
40
|
|
|
['city_id' => 1, 'locale' => 'en', 'name' => 'Athens'], |
41
|
|
|
['city_id' => 1, 'locale' => 'de', 'name' => 'Athen'], |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
$this->createCityTranslations($cityTranslations); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
private function createCountries($countries) |
48
|
|
|
{ |
49
|
|
|
foreach ($countries as $data) { |
50
|
|
|
$country = new Country(); |
51
|
|
|
$country->id = $data['id']; |
|
|
|
|
52
|
|
|
$country->code = $data['code']; |
|
|
|
|
53
|
|
|
$country->save(); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
View Code Duplication |
private function createCountryTranslations($translations) |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
foreach ($translations as $data) { |
60
|
|
|
$translation = new CountryTranslation(); |
61
|
|
|
$translation->country_id = $data['country_id']; |
|
|
|
|
62
|
|
|
$translation->locale = $data['locale']; |
|
|
|
|
63
|
|
|
$translation->name = $data['name']; |
|
|
|
|
64
|
|
|
$translation->save(); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
private function createCities($cities) |
69
|
|
|
{ |
70
|
|
|
foreach ($cities as $data) { |
71
|
|
|
$city = new City(); |
72
|
|
|
$city->id = $data['id']; |
|
|
|
|
73
|
|
|
$city->country_id = $data['country_id']; |
|
|
|
|
74
|
|
|
$city->save(); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
View Code Duplication |
private function createCityTranslations($translations) |
|
|
|
|
79
|
|
|
{ |
80
|
|
|
foreach ($translations as $data) { |
81
|
|
|
$translation = new CityTranslation(); |
82
|
|
|
$translation->city_id = $data['city_id']; |
|
|
|
|
83
|
|
|
$translation->locale = $data['locale']; |
|
|
|
|
84
|
|
|
$translation->name = $data['name']; |
|
|
|
|
85
|
|
|
$translation->save(); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.