1 | <?php |
||
15 | class MultilanguageMigration extends \yii\db\Migration |
||
16 | { |
||
17 | /** |
||
18 | * Postfix for translate table name. |
||
19 | */ |
||
20 | const TRANSLATE_TABLE_POSTFIX = 'language'; |
||
21 | |||
22 | /** |
||
23 | * Table name to contain the project languages. |
||
24 | */ |
||
25 | const LANGUAGE_TABLE_NAME = 'language'; |
||
26 | |||
27 | /** |
||
28 | * Creates table with timestamp fields: created_at and updated_at. |
||
29 | * |
||
30 | * @param string $table - table name. |
||
31 | * @param array $columns - array with names and types of columns. |
||
32 | * @param string|null $options - additional SQL code. |
||
33 | * |
||
34 | * @return void |
||
35 | */ |
||
36 | public function createTableWithTimestamps(string $table, array $columns, string $options = null): void |
||
44 | |||
45 | /** |
||
46 | * Creates two tables: main table and translate table. |
||
47 | * For example: |
||
48 | * catalog: |
||
49 | * - id |
||
50 | * - created_at |
||
51 | * - updated_at |
||
52 | * |
||
53 | * catalog_language: |
||
54 | * - catalog_id |
||
55 | * - language_id |
||
56 | * - title |
||
57 | * - text |
||
58 | * |
||
59 | * @param string $table - table name which needs to be translated. |
||
60 | * @param array $multiLanguageColumns - list of multilanguage fields. |
||
61 | * @param array $columns - list of simple fields. |
||
62 | * @param string|null $options - additional SQL code. |
||
63 | * |
||
64 | * @return void |
||
65 | */ |
||
66 | public function createMultiLanguageTable( |
||
115 | |||
116 | /** |
||
117 | * Drop main table with translate table. |
||
118 | * |
||
119 | * @param string $table - main table name. |
||
120 | * |
||
121 | * @return void |
||
122 | */ |
||
123 | public function dropMultiLanguageTable(string $table): void |
||
136 | |||
137 | /** |
||
138 | * Returns key name for link translate table with languages table. |
||
139 | * |
||
140 | * @return string |
||
141 | */ |
||
142 | public static function getKeyToLanguageTable(): string |
||
146 | |||
147 | /** |
||
148 | * Returns foreign key to other table. |
||
149 | * |
||
150 | * @param string $table |
||
151 | * @param string $column |
||
152 | * |
||
153 | * @return string |
||
154 | */ |
||
155 | private function createFkName(string $table, string $column): string |
||
159 | |||
160 | /** |
||
161 | * Returns table name for translates. |
||
162 | * |
||
163 | * @param string $table - main table name. |
||
164 | * |
||
165 | * @return string |
||
166 | */ |
||
167 | private function getTranslateTableName(string $table): string |
||
171 | |||
172 | /** |
||
173 | * Returns key name for link translate table with main table. |
||
174 | * |
||
175 | * @param string $table - main table name. |
||
176 | * |
||
177 | * @return string |
||
178 | */ |
||
179 | private function getKeyToPrimaryTable(string $table): string |
||
183 | } |
||
184 |