1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Dimsav\Translatable\Test\Model\City; |
4
|
|
|
use Dimsav\Translatable\Test\Model\Country; |
5
|
|
|
use Dimsav\Translatable\Test\Model\Vegetable; |
6
|
|
|
use Dimsav\Translatable\Test\Model\CityTranslation; |
7
|
|
|
use Dimsav\Translatable\Test\Model\CountryTranslation; |
8
|
|
|
use Dimsav\Translatable\Test\Model\VegetableTranslation; |
9
|
|
|
|
10
|
|
|
class AddFreshSeeds |
|
|
|
|
11
|
|
|
{ |
12
|
|
|
public function run() |
13
|
|
|
{ |
14
|
|
|
$countries = [ |
15
|
|
|
['id' => 1, 'code' => 'gr'], |
16
|
|
|
['id' => 2, 'code' => 'fr'], |
17
|
|
|
['id' => 3, 'code' => 'en'], |
18
|
|
|
['id' => 4, 'code' => 'de'], |
19
|
|
|
]; |
20
|
|
|
|
21
|
|
|
$this->createCountries($countries); |
22
|
|
|
|
23
|
|
|
$countryTranslations = [ |
24
|
|
|
['country_id' => 1, 'locale' => 'el', 'name' => 'Ελλάδα'], |
25
|
|
|
['country_id' => 1, 'locale' => 'fr', 'name' => 'Grèce'], |
26
|
|
|
['country_id' => 1, 'locale' => 'en', 'name' => 'Greece'], |
27
|
|
|
['country_id' => 1, 'locale' => 'de', 'name' => 'Griechenland'], |
28
|
|
|
['country_id' => 2, 'locale' => 'en', 'name' => 'France'], |
29
|
|
|
]; |
30
|
|
|
|
31
|
|
|
$this->createCountryTranslations($countryTranslations); |
32
|
|
|
|
33
|
|
|
$cities = [ |
34
|
|
|
['id' => 1, 'country_id' => 1], |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
$this->createCities($cities); |
38
|
|
|
|
39
|
|
|
$cityTranslations = [ |
40
|
|
|
['city_id' => 1, 'locale' => 'el', 'name' => 'Αθήνα'], |
41
|
|
|
['city_id' => 1, 'locale' => 'fr', 'name' => 'Athènes'], |
42
|
|
|
['city_id' => 1, 'locale' => 'en', 'name' => 'Athens'], |
43
|
|
|
['city_id' => 1, 'locale' => 'de', 'name' => 'Athen'], |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
$this->createCityTranslations($cityTranslations); |
47
|
|
|
|
48
|
|
|
$vegetables = [ |
49
|
|
|
['vegetable_identity' => 1], |
50
|
|
|
['vegetable_identity' => 2], |
51
|
|
|
]; |
52
|
|
|
|
53
|
|
|
$this->createVegetables($vegetables); |
54
|
|
|
|
55
|
|
|
$vegetableTranslations = [ |
56
|
|
|
['vegetable_identity' => 1, 'locale' => 'en', 'name' => 'zucchini'], |
57
|
|
|
['vegetable_identity' => 1, 'locale' => 'en-GB', 'name' => 'courgette'], |
58
|
|
|
['vegetable_identity' => 1, 'locale' => 'en-US', 'name' => 'zucchini'], |
59
|
|
|
['vegetable_identity' => 1, 'locale' => 'de', 'name' => 'Zucchini'], |
60
|
|
|
['vegetable_identity' => 1, 'locale' => 'de-CH', 'name' => 'Zucchetti'], |
61
|
|
|
['vegetable_identity' => 2, 'locale' => 'en', 'name' => 'aubergine'], |
62
|
|
|
['vegetable_identity' => 2, 'locale' => 'en-US', 'name' => 'eggplant'], |
63
|
|
|
]; |
64
|
|
|
|
65
|
|
|
$this->createVegetableTranslations($vegetableTranslations); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
private function createCountries($countries) |
69
|
|
|
{ |
70
|
|
|
foreach ($countries as $data) { |
71
|
|
|
$country = new Country(); |
72
|
|
|
$country->id = $data['id']; |
|
|
|
|
73
|
|
|
$country->code = $data['code']; |
|
|
|
|
74
|
|
|
$country->save(); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
View Code Duplication |
private function createCountryTranslations($translations) |
|
|
|
|
79
|
|
|
{ |
80
|
|
|
foreach ($translations as $data) { |
81
|
|
|
$translation = new CountryTranslation(); |
82
|
|
|
$translation->country_id = $data['country_id']; |
|
|
|
|
83
|
|
|
$translation->locale = $data['locale']; |
|
|
|
|
84
|
|
|
$translation->name = $data['name']; |
|
|
|
|
85
|
|
|
$translation->save(); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
private function createCities($cities) |
90
|
|
|
{ |
91
|
|
|
foreach ($cities as $data) { |
92
|
|
|
$city = new City(); |
93
|
|
|
$city->id = $data['id']; |
|
|
|
|
94
|
|
|
$city->country_id = $data['country_id']; |
|
|
|
|
95
|
|
|
$city->save(); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
View Code Duplication |
private function createCityTranslations($translations) |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
foreach ($translations as $data) { |
102
|
|
|
$translation = new CityTranslation(); |
103
|
|
|
$translation->city_id = $data['city_id']; |
|
|
|
|
104
|
|
|
$translation->locale = $data['locale']; |
|
|
|
|
105
|
|
|
$translation->name = $data['name']; |
|
|
|
|
106
|
|
|
$translation->save(); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
private function createVegetables($vegetables) |
111
|
|
|
{ |
112
|
|
|
foreach ($vegetables as $vegetable) { |
113
|
|
|
$vegetable = new Vegetable(); |
114
|
|
|
$vegetable->identity = $vegetable['identity']; |
|
|
|
|
115
|
|
|
$vegetable->save(); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
View Code Duplication |
private function createVegetableTranslations($translations) |
|
|
|
|
120
|
|
|
{ |
121
|
|
|
foreach ($translations as $data) { |
122
|
|
|
$translation = new VegetableTranslation(); |
123
|
|
|
$translation->vegetable_identity = $data['vegetable_identity']; |
|
|
|
|
124
|
|
|
$translation->locale = $data['locale']; |
|
|
|
|
125
|
|
|
$translation->name = $data['name']; |
|
|
|
|
126
|
|
|
$translation->save(); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
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.