1 | <?php |
||
2 | |||
3 | namespace SilverCommerce\GeoZones\Model; |
||
4 | |||
5 | use RegionMigrationTask; |
||
6 | use SilverStripe\ORM\DB; |
||
7 | use SilverStripe\ORM\DataObject; |
||
8 | use SilverStripe\Control\Controller; |
||
9 | |||
10 | /** |
||
11 | * Subdivisions of a country, based on ISO-3166-2 standards. |
||
12 | * |
||
13 | * Thanks to debian (https://salsa.debian.org/iso-codes-team/iso-codes/blob/master/data/iso_3166-2.json) |
||
14 | * for the base data set |
||
15 | */ |
||
16 | class Region extends DataObject |
||
17 | { |
||
18 | /** |
||
19 | * Syncronise codes on dev/build |
||
20 | */ |
||
21 | private static $create_on_build = true; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
22 | |||
23 | private static $table_name = "GeoZoneRegion"; |
||
0 ignored issues
–
show
|
|||
24 | |||
25 | private static $db = [ |
||
0 ignored issues
–
show
|
|||
26 | "Name" => "Varchar", |
||
27 | "Type" => "Varchar", |
||
28 | "Code" => "Varchar(3)", |
||
29 | "CountryCode" => "Varchar(2)" |
||
30 | ]; |
||
31 | |||
32 | private static $belongs_many_many = [ |
||
0 ignored issues
–
show
|
|||
33 | 'Zones' => Zone::class |
||
34 | ]; |
||
35 | |||
36 | private static $summary_fields = [ |
||
0 ignored issues
–
show
|
|||
37 | "CountryCode", |
||
38 | "Name", |
||
39 | "Type", |
||
40 | "Code" |
||
41 | ]; |
||
42 | |||
43 | private static $default_sort = [ |
||
0 ignored issues
–
show
|
|||
44 | "CountryCode" => "ASC", |
||
45 | "Name" => "ASC" |
||
46 | ]; |
||
47 | |||
48 | public function requireDefaultRecords() |
||
49 | { |
||
50 | parent::requireDefaultRecords(); |
||
51 | |||
52 | if (RegionMigrationTask::config()->run_during_dev_build) { |
||
53 | $task = new RegionMigrationTask(); |
||
54 | $task->up(); |
||
55 | } |
||
56 | } |
||
57 | } |