1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class BrowseRegionsPage extends BrowseAbstractPage |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Standard SS Static |
8
|
|
|
**/ |
9
|
|
|
public static $icon = "geobrowser/images/treeicons/BrowseRegionsPage"; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Standard SS Static |
13
|
|
|
**/ |
14
|
|
|
public static $allowed_children = array("BrowseCitiesPage"); |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Standard SS Static |
18
|
|
|
**/ |
19
|
|
|
public static $default_child = "BrowseCitiesPage"; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Standard SS Static |
23
|
|
|
**/ |
24
|
|
|
public static $default_parent = "BrowseCountriesPage"; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Standard SS Static |
28
|
|
|
**/ |
29
|
|
|
public static $can_be_root = false; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Standard SS Static |
33
|
|
|
**/ |
34
|
|
|
public static $db = array( |
35
|
|
|
"Code" => "Varchar(8)", |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Standard SS Static |
40
|
|
|
**/ |
41
|
|
|
public static $defaults = array( |
42
|
|
|
"ShowInMenus" => false |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Standard SS Static |
47
|
|
|
**/ |
48
|
|
|
public function getCMSFields() |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
$fields = parent::getCMSFields(); |
51
|
|
|
return $fields; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Name of the level |
57
|
|
|
**/ |
58
|
|
|
public function GeoLevelName() |
59
|
|
|
{ |
60
|
|
|
return "Regions"; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Number of the level |
65
|
|
|
**/ |
66
|
|
|
public function GeoLevelNumber() |
67
|
|
|
{ |
68
|
|
|
return 2; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Setup pages... |
74
|
|
|
**/ |
75
|
|
|
public function requireDefaultRecords() |
|
|
|
|
76
|
|
|
{ |
77
|
|
|
parent::requireDefaultRecords(); |
78
|
|
|
$bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`"; |
79
|
|
|
$parents = DataObject::get("BrowseRegionsPage"); |
80
|
|
|
if ($parents && isset($_GET["geobuild"]) && $_GET["geobuild"] && $this->allowBrowseChildren()) { |
81
|
|
View Code Duplication |
foreach ($parents as $parent) { |
|
|
|
|
82
|
|
|
if ($parent->CreateChildren && $parent->HiddenDataID) { |
83
|
|
|
echo "<li>creating cities for ".$parent->Title."<ul>"; |
84
|
|
|
$cities = $this->getDataFromTable("cities", "RegionID = ".$parent->HiddenDataID, "City"); |
85
|
|
|
foreach ($cities as $city) { |
86
|
|
|
if (!DataObject::get_one("BrowseCitiesPage", "{$bt}BrowseAbstractPage{$bt}.{$bt}HiddenDataID{$bt} = ".$city["CityID"])) { |
87
|
|
|
$page = new BrowseCitiesPage(); |
88
|
|
|
$page->CreateCity($city, $parent); |
89
|
|
|
$page->destroy(); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
echo "</ul></li>"; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
$parents->destroy(); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Creates a region... called from BrowseCountriesPage |
101
|
|
|
* |
102
|
|
|
*@param Array $region - array of region details |
103
|
|
|
*@param Object $parent - a BrowseCountriesPage object |
104
|
|
|
* |
105
|
|
|
**/ |
106
|
|
|
public function CreateRegion(array $region, BrowseCountriesPage $parent) |
|
|
|
|
107
|
|
|
{ |
108
|
|
|
if ($parent && isset($region["Region"])) { |
109
|
|
|
$name = htmlentities($region["Region"]); |
110
|
|
|
if ($name) { |
111
|
|
|
if (isset($_GET["geobuild"])) { |
112
|
|
|
echo "<li>creating ".$name."</li>"; |
113
|
|
|
} |
114
|
|
|
$this->ParentID = $parent->ID; |
115
|
|
|
$this->Title = $name; |
116
|
|
|
$this->MetaTitle = $name; |
117
|
|
|
$this->MenuTitle = $name; |
118
|
|
|
$this->HiddenDataID = $region["RegionID"]; |
119
|
|
|
|
120
|
|
|
$this->Code = $region["Code"]; |
121
|
|
|
|
122
|
|
|
$this->CreateChildren = $parent->CreateAllChildren; |
123
|
|
|
$this->CreateAllChildren = $parent->CreateAllChildren; |
124
|
|
|
|
125
|
|
|
$this->URLSegment = $this->generateURLSegment($this->Title); |
126
|
|
|
|
127
|
|
|
$this->writeToStage('Stage'); |
128
|
|
|
$this->publish('Stage', 'Live'); |
129
|
|
|
$this->flushCache(); |
130
|
|
|
} else { |
131
|
|
|
if (isset($_GET["geobuild"])) { |
132
|
|
|
debug::show("region does not exist"); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
} else { |
136
|
|
|
if (isset($_GET["geobuild"])) { |
137
|
|
|
debug::show("Parent does not exist"); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
class BrowseRegionsPage_Controller extends BrowseAbstractPage_Controller |
|
|
|
|
144
|
|
|
{ |
145
|
|
|
} |
146
|
|
|
|
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.