Completed
Push — master ( 266f95...b28ac4 )
by Nicolaas
01:40
created

GoogleMap::createDataPoints()   D

Complexity

Conditions 18
Paths 33

Size

Total Lines 84
Code Lines 65

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 84
rs 4.837
c 0
b 0
f 0
cc 18
eloc 65
nc 33
nop 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * This is the basic engine for the Google Map
4
 *
5
 * There are three options
6
 * 1. setAddress: set address
7
 * 2. setPageDataObjectSet: set Page Data List (who have geo points as children)
8
 * 3. setPoints: set Points Directly Class = GoogleMapLocationsObject
9
 *
10
 * Extras include:
11
 * 1. setTitleOfMap: set title
12
 * 2. setWhereStatementDescription: set where statement
13
 * 3. setFilteredClassNameArray: set an array of classnames
14
 *
15
 * The static configs are explained in googlemap/_config/googlemap.yml.example
16
 *
17
 *
18
 **/
19
class GoogleMap extends ViewableData
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
20
{
21
22
23
24
    ################################
25
    # SETTINGS
26
    ################################
27
28
29
    /* BASIC MAP SETTINGS */
30
    private static $api_version = '3';
0 ignored issues
show
Unused Code introduced by
The property $api_version is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
31
    private static $google_map_api_key = "";
0 ignored issues
show
Unused Code introduced by
The property $google_map_api_key is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
32
    private static $default_latitude = 0.000000001; //MOVE TO SITECONFIG
0 ignored issues
show
Unused Code introduced by
The property $default_latitude is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
33
    private static $default_longitude = 0.0000000001; //MOVE TO SITECONFIG
0 ignored issues
show
Unused Code introduced by
The property $default_longitude is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
34
    private static $default_zoom = 2; //MOVE TO SITECONFIG
0 ignored issues
show
Unused Code introduced by
The property $default_zoom is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
35
    private static $google_map_width = 0;
0 ignored issues
show
Unused Code introduced by
The property $google_map_width is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
36
    private static $google_map_height = 0;
0 ignored issues
show
Unused Code introduced by
The property $google_map_height is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
37
38
    /* MAP CONTROLS*/
39
    private static $map_type_default = 0; //MOVE TO SITECONFIG
0 ignored issues
show
Unused Code introduced by
The property $map_type_default is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
40
    private static $view_finder_size = 100; //MOVE TO SITECONFIG
0 ignored issues
show
Unused Code introduced by
The property $view_finder_size is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
41
    private static $map_add_type_control = false; //MOVE TO SITECONFIG
0 ignored issues
show
Unused Code introduced by
The property $map_add_type_control is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
42
    private static $map_control_size_one_to_three = 3; //MOVE TO SITECONFIG
0 ignored issues
show
Unused Code introduced by
The property $map_control_size_one_to_three is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
43
    private static $map_scale_info_size_in_pixels = 100; //MOVE TO SITECONFIG
0 ignored issues
show
Unused Code introduced by
The property $map_scale_info_size_in_pixels is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
44
45
    /* INFORMATION AROUND THE MAP */
46
    private static $default_title = ""; //MOVE TO SITECONFIG
0 ignored issues
show
Unused Code introduced by
The property $default_title is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
47
    private static $default_where_statement_description = ""; //MOVE TO SITECONFIG
0 ignored issues
show
Unused Code introduced by
The property $default_where_statement_description is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
48
    private static $no_status_at_all = true; //MOVE TO SITECONFIG
0 ignored issues
show
Unused Code introduced by
The property $no_status_at_all is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
49
    private static $add_kml_link = false; //MOVE TO SITECONFIG
0 ignored issues
show
Unused Code introduced by
The property $add_kml_link is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
50
    private static $hidden_layers_removed_from_list = false;
0 ignored issues
show
Unused Code introduced by
The property $hidden_layers_removed_from_list is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
51
    private static $change_page_title = false; //MOVE TO SITECONFIG
0 ignored issues
show
Unused Code introduced by
The property $change_page_title is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
52
    private static $number_of_items_before_showing_list = 1; //MOVE TO SITECONFIG
0 ignored issues
show
Unused Code introduced by
The property $number_of_items_before_showing_list is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
53
    private static $main_div_id = "GoogleMapDiv";
0 ignored issues
show
Unused Code introduced by
The property $main_div_id is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
54
    private static $title_div_id = "";
0 ignored issues
show
Unused Code introduced by
The property $title_div_id is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
55
    private static $side_bar_div_id = "";
0 ignored issues
show
Unused Code introduced by
The property $side_bar_div_id is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
56
    private static $drop_down_div_id    ="";
0 ignored issues
show
Unused Code introduced by
The property $drop_down_div_id is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
57
    private static $layer_list_div_id = "";
0 ignored issues
show
Unused Code introduced by
The property $layer_list_div_id is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
58
    private static $directions_div_id = "";
0 ignored issues
show
Unused Code introduced by
The property $directions_div_id is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
59
    private static $status_div_id = "";
0 ignored issues
show
Unused Code introduced by
The property $status_div_id is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
60
61
    /* INFOWINDOW*/
62
    private static $info_window_options = "{maxWidth:280, zoomLevel:17, mapTypeId: google.maps.MapTypeId.HYBRID}";
0 ignored issues
show
Unused Code introduced by
The property $info_window_options is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
63
    private static $add_antipodean = false; //MOVE TO SITECONFIG
0 ignored issues
show
Unused Code introduced by
The property $add_antipodean is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
64
    private static $add_directions = false; //MOVE TO SITECONFIG
0 ignored issues
show
Unused Code introduced by
The property $add_directions is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
65
    private static $add_current_address_finder_in_marker = false; //MOVE TO SITECONFIG
0 ignored issues
show
Unused Code introduced by
The property $add_current_address_finder_in_marker is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
66
    private static $add_zoom_in_button = true; //MOVE TO SITECONFIG
0 ignored issues
show
Unused Code introduced by
The property $add_zoom_in_button is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
67
    private static $ajax_info_window_text = "View Details"; //MOVE TO SITECONFIG
0 ignored issues
show
Unused Code introduced by
The property $ajax_info_window_text is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
68
69
    /* MARKERS */
70
    private static $add_points_to_map = false;
0 ignored issues
show
Unused Code introduced by
The property $add_points_to_map is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
71
    private static $add_delete_marker_button = "";
0 ignored issues
show
Unused Code introduced by
The property $add_delete_marker_button is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
72
    private static $marker_options = "{bouncy:true,title: \"click me\"}";
0 ignored issues
show
Unused Code introduced by
The property $marker_options is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
73
    private static $preload_images = false;
0 ignored issues
show
Unused Code introduced by
The property $preload_images is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
74
75
    /* ICONS */
76
    private static $default_icon_url = "";
0 ignored issues
show
Unused Code introduced by
The property $default_icon_url is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
77
    private static $icon_folder = "/googlemap/images/icons/";
0 ignored issues
show
Unused Code introduced by
The property $icon_folder is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
78
    private static $icon_width = 20;
0 ignored issues
show
Unused Code introduced by
The property $icon_width is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
79
    private static $icon_height = 34;
0 ignored issues
show
Unused Code introduced by
The property $icon_height is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
80
    private static $icon_extension = "png";
0 ignored issues
show
Unused Code introduced by
The property $icon_extension is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
81
    private static $icon_max_count = 12;
0 ignored issues
show
Unused Code introduced by
The property $icon_max_count is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
82
83
    /* POLYS */
84
    private static $line_colour = "#000";
0 ignored issues
show
Unused Code introduced by
The property $line_colour is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
85
    private static $line_width = 12;
0 ignored issues
show
Unused Code introduced by
The property $line_width is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
86
    private static $line_opacity = 0.5;
0 ignored issues
show
Unused Code introduced by
The property $line_opacity is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
87
    private static $fill_colour = "#ffccff";
0 ignored issues
show
Unused Code introduced by
The property $fill_colour is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
88
    private static $fill_opacity = 0.5;
0 ignored issues
show
Unused Code introduced by
The property $fill_opacity is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
89
    private static $poly_icon = "";
0 ignored issues
show
Unused Code introduced by
The property $poly_icon is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
90
91
    /* STATIC MAP */
92
    private static $static_map_settings = "maptype=roadmap";
0 ignored issues
show
Unused Code introduced by
The property $static_map_settings is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
93
    private static $static_icon = "";
0 ignored issues
show
Unused Code introduced by
The property $static_icon is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
94
    private static $save_static_map_locally = false;
0 ignored issues
show
Unused Code introduced by
The property $save_static_map_locally is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
95
96
    /* ADDRESS FINDER */
97
    private static $add_address_finder = false; //MOVE TO SITECONFIG
0 ignored issues
show
Unused Code introduced by
The property $add_address_finder is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
98
    private static $default_country_code = "nz"; // see https://developers.google.com/maps/documentation/geocoding/#RegionCodes
0 ignored issues
show
Unused Code introduced by
The property $default_country_code is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
99
    private static $number_shown_in_around_me = 7; //MOVE TO SITECONFIG
0 ignored issues
show
Unused Code introduced by
The property $number_shown_in_around_me is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
100
    private static $max_radius_for_show_around_me = 20000;
0 ignored issues
show
Unused Code introduced by
The property $max_radius_for_show_around_me is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
101
        
102
    /* DIRECTIONS SETTINGS */
103
    private static $style_sheet_url = "";
0 ignored issues
show
Unused Code introduced by
The property $style_sheet_url is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
104
    private static $locale_for_results = "en_NZ";
0 ignored issues
show
Unused Code introduced by
The property $locale_for_results is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
105
106
    /* SERVER SETTINGS */
107
    private static $lng_form_field_id = "";
0 ignored issues
show
Unused Code introduced by
The property $lng_form_field_id is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
108
    private static $lat_form_field_id = "";
0 ignored issues
show
Unused Code introduced by
The property $lat_form_field_id is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
109
110
111
112
113
114
115
116
117
118
119
    ################################
120
    # TEMPATE METHODS
121
    ################################
122
123
    /**
124
     * @return String
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
125
     */
126
    public function Link()
127
    {
128
        $page = Controller::curr();
129
        if ($page) {
130
            return $page->Link();
131
        }
132
    }
133
134
135
    /**
136
     * function name for map...
137
     * @var String
138
     */
139
    protected $myMapFunctionName = "GMO";
140
    public function setMyMapFunctionName($a)
0 ignored issues
show
Unused Code introduced by
The parameter $a is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
141
    {
142
        $this->myMapFunctionName = $s;
0 ignored issues
show
Bug introduced by
The variable $s does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
143
    }
144
    public function MyMapFunctionName()
145
    {
146
        return $this->getMyMapFunctionName(false);
147
    }
148
    public function MyInstanceName()
149
    {
150
        return $this->getMyMapFunctionName(true);
151
    }
152
    public function getMyMapFunctionName($instanceName = false)
153
    {
154
        if ($instanceName) {
155
            $var = 'load_my_map_'.$this->myMapFunctionName;
156
        } else {
157
            $var = $this->myMapFunctionName;
158
        }
159
        return $var;
160
    }
161
162
    /**
163
     * title of map
164
     * @var string
165
     */
166
    protected $titleOfMap = "";
167
168
    public function setTitleOfMap($s)
169
    {
170
        $this->titleOfMap = $s;
171
    }
172
    public function TitleOfMap()
173
    {
174
        return $this->getTitleOfMap();
175
    }
176
    public function getTitleOfMap()
177
    {
178
        return $this->titleOfMap;
179
    }
180
181
    /**
182
     * title of map
183
     * @var string
184
     */
185
    protected $noDataPointsMessage = "";
186
187
    public function setNoDataPointsMessage($s)
188
    {
189
        $this->noDataPointsMessage = $s;
190
    }
191
    public function NoDataPointsMessage()
192
    {
193
        return $this->getNoDataPointsMessage();
194
    }
195
    public function getNoDataPointsMessage()
196
    {
197
        return $this->noDataPointsMessage;
198
    }
199
200
201
    /**
202
     * used for static and non-static maps, hence defined only once.
203
     * @return Int
0 ignored issues
show
Documentation introduced by
Should the return type not be array|integer|double|string|boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
204
     */
205
    public function GoogleMapWidth()
206
    {
207
        return Config::inst()->get("GoogleMap", "google_map_width");
208
    }
209
210
    /**
211
     * used for static and non-static maps, hence defined only once.
212
     * @return Int
0 ignored issues
show
Documentation introduced by
Should the return type not be array|integer|double|string|boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
213
     */
214
    public function GoogleMapHeight()
215
    {
216
        return Config::inst()->get("GoogleMap", "google_map_height");
217
    }
218
219
    /**
220
     * @return Boolean
0 ignored issues
show
Documentation introduced by
Should the return type not be array|integer|double|string|boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
221
     */
222
    public function AddAddressFinder()
223
    {
224
        return Config::inst()->get("GoogleMap", "add_address_finder");
225
    }
226
227
    /**
228
     * @return Boolean
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
229
     */
230
    public function CanEdit($member = null)
231
    {
232
        if ($this->getUpdateServerUrlDragend()) {
233
            if (Injector::inst()->get("GoogleMapLocationsObject")->canEdit($member)) {
234
                return true;
235
            }
236
        }
237
    }
238
239
    /**
240
     * @return String
0 ignored issues
show
Documentation introduced by
Should the return type not be array|integer|double|string|boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
241
     */
242
    public function TitleDivID()
243
    {
244
        return Config::inst()->get("GoogleMap", "title_div_id");
245
    }
246
247
    /**
248
     * @return String
0 ignored issues
show
Documentation introduced by
Should the return type not be array|integer|double|string|boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
249
     */
250
    public function SideBarDivId()
251
    {
252
        return Config::inst()->get("GoogleMap", "side_bar_div_id");
253
    }
254
255
    /**
256
     * @return String
0 ignored issues
show
Documentation introduced by
Should the return type not be array|integer|double|string|boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
257
     */
258
    public function DropDownDivId()
259
    {
260
        return Config::inst()->get("GoogleMap", "drop_down_div_id");
261
    }
262
263
    /**
264
     * @return String
0 ignored issues
show
Documentation introduced by
Should the return type not be array|integer|double|string|boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
265
     */
266
    public function LayerListDivId()
267
    {
268
        return Config::inst()->get("GoogleMap", "layer_list_div_id");
269
    }
270
271
    /**
272
     * @return String
0 ignored issues
show
Documentation introduced by
Should the return type not be array|integer|double|string|boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
273
     */
274
    public function DirectionsDivId()
275
    {
276
        return Config::inst()->get("GoogleMap", "directions_div_id");
277
    }
278
279
    /**
280
     * @return String
0 ignored issues
show
Documentation introduced by
Should the return type not be array|integer|double|string|boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
281
     */
282
    public function StatusDivId()
283
    {
284
        return Config::inst()->get("GoogleMap", "status_div_id");
285
    }
286
287
    /**
288
     *
289
     * @var Boolean
290
     */
291
    public function AllowAddPointsToMap()
292
    {
293
        $this->Config()->update("add_points_to_map", true);
0 ignored issues
show
Bug introduced by
The method update() does not seem to exist on object<Config_ForClass>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
294
    }
295
296
    /**
297
     * @var ArrayList
298
     */
299
    protected $processedDataPointsForTemplate = null;
300
    public function setProcessedDataPointsForTemplate($s)
301
    {
302
        $this->processedDataPointsForTemplate = $s;
303
    }
304
    public function ProcessedDataPointsForTemplate()
305
    {
306
        return $this->getProcessedDataPointsForTemplate();
307
    }
308
    public function getProcessedDataPointsForTemplate()
309
    {
310
        return $this->processedDataPointsForTemplate;
311
    }
312
313
    /**
314
     * @var string
315
     */
316
    protected $dataPointsXML = '';
317
    protected function DataPointsXML()
318
    {
319
        return $this->getDataPointsXML();
320
    }
321
    protected function getDataPointsXML()
322
    {
323
        $this->createDataPoints();
324
        return $this->dataPointsXML;
325
    }
326
327
328
329
330
331
332
333
334
335
336
337
    ################################
338
    # SETUP: LAYER MANAGEMENT
339
    ################################
340
341
342
343
344
    /**
345
     * @var ArrayList
346
     */
347
    protected $extraLayers = null;
348
    public function setExtraLayer($a)
349
    {
350
        $this->extraLayers = $a;
351
    }
352
    public function getExtraLayers()
353
    {
354
        return $this->extraLayers;
355
    }
356
357
    /**
358
     * @param String $title
359
     * @param String $link
360
     */
361
    public function addExtraLayer($title, $link)
362
    {
363
        if (!$this->getExtraLayers()) {
364
            $this->extraLayers = new ArrayList();
365
        }
366
        $this->extraLayers->push(
367
                new ArrayData(
368
                    array(
369
                        "Title" => $title,
370
                        "Link" => $link,
371
                        "MyInstanceName" => $this->MyInstanceName()
372
                    )
373
                )
374
            );
375
    }
376
377
    /**
378
     *
379
     * @return ArrayList
380
     */
381
    public function AllExtraLayers()
382
    {
383
        return $this->getExtraLayers();
384
    }
385
386
    /**
387
     * @var Array
388
     *    Link => Title
389
     */
390
    protected $linksForData = array();
391
    public function setLinksForData($a)
392
    {
393
        $this->linksForData = $a;
394
    }
395
    public function getLinksForData()
396
    {
397
        return $this->linksForData;
398
    }
399
400
    /**
401
     * @param string $linkForData
402
     * @param string $title
403
     */
404
    public function addLayer($linkForData, $title)
405
    {
406
        $this->linksForData[$linkForData] = $title;
407
    }
408
409
410
411
412
413
414
415
    ################################
416
    # SETUP: FILTERS AND POINTS PROVIDERS
417
    ################################
418
419
    /**
420
     * address being searched for
421
     * @var String
422
     */
423
    protected $address = "";
424
    public function setAddress($v)
425
    {
426
        $this->address = Convert::raw2js($v);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Convert::raw2js($v) can also be of type array. However, the property $address is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
427
    }
428
    public function getAddress($v)
0 ignored issues
show
Unused Code introduced by
The parameter $v is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
429
    {
430
        return $this->address;
431
    }
432
433
    /**
434
     * sets the list of points through a list of parent pages
435
     * affected variable is: points
436
     * @param DataList | ArrayList $pageDataList
437
     */
438
    public function setPageDataObjectSet($pageDataList)
439
    {
440
        if ($pageDataList->count()) {
441
            if ($pageDataList instanceof ArrayList) {
442
                $array = $pageDataList->map("ID", "ID");
443
            } elseif ($pageDataList instanceof DataList) {
444
                $array = $pageDataList->map("ID", "ID")->toArray();
445
            } else {
446
                user_error("Wrong format for pageDataList");
447
            }
448
            $this->points = GoogleMapLocationsObject::get()->filter(array("ParentID" => $array));
0 ignored issues
show
Bug introduced by
The variable $array does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
449
            $pageDataList = null;
0 ignored issues
show
Unused Code introduced by
$pageDataList is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
450
        }
451
    }
452
453
454
    /**
455
     * @var DataList
456
     */
457
    protected $points = null;
458
    public function setPoints($s)
459
    {
460
        $this->points = $s;
461
    }
462
    public function getPoints()
463
    {
464
        return $this->points;
465
    }
466
467
468
469
    /**
470
     * a description of how the points were selected ...
471
     * @var String
472
     */
473
    protected $whereStatementDescription = "";
474
    public function setWhereStatementDescription($s)
475
    {
476
        $this->whereStatementDescription = $s;
477
    }
478
    public function getWhereStatementDescription()
479
    {
480
        return $this->whereStatementDescription;
481
    }
482
483
    /**
484
     * filter for class names
485
     * @var Array
486
     */
487
    protected $filteredClassNameArray = array();
488
    public function setFilteredClassNameArray($a)
0 ignored issues
show
Unused Code introduced by
The parameter $a is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
489
    {
490
        $this->filteredClassNameArray = $s;
0 ignored issues
show
Bug introduced by
The variable $s does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
491
    }
492
    public function getFilteredClassNameArray()
493
    {
494
        return $this->filteredClassNameArray;
495
    }
496
497
498
499
500
501
502
503
    ################################
504
    # MAP CHANGES
505
    ################################
506
507
    /**
508
     * @var String
509
     */
510
    protected $updateServerUrlAddressSearchPoint = "/googlemap/showaroundmexml/";
511
    public function setUpdateServerUrlAddressSearchPoint($v)
512
    {
513
        $this->updateServerUrlAddressSearchPoint = Director::absoluteBaseURL().$v;
514
    }
515
    public function getUpdateServerURLAddressSearchPoint()
516
    {
517
        return $this->updateServerUrlAddressSearchPoint;
518
    }
519
520
    /**
521
     * @var String
522
     */
523
    protected $updateServerUrlDragend = "";
524
    public function setUpdateServerUrlDragend($v)
525
    {
526
        $this->updateServerUrlDragend = Director::absoluteBaseURL().$v;
527
    }
528
    public function getUpdateServerUrlDragend()
529
    {
530
        return $this->updateServerUrlDragend;
531
    }
532
533
534
535
536
537
538
539
540
541
542
    ################################
543
    # LOADING
544
    ################################
545
    /**
546
     * this is a hack to avoid having multiple includes
547
     * @var Boolean
548
     */
549
    private static $_includes_are_done = false;
550
551
    public function loadGoogleMap()
552
    {
553
        $js = '';
554
        $this->loadDefaults();
555
        if (!self::$_includes_are_done) {
556
            Requirements::themedCSS("googleMap", 'googlemap');
557
            Requirements::javascript(THIRDPARTY_DIR."/jquery/jquery.js");
558
            $variableName = $this->getMyMapFunctionName(false);
0 ignored issues
show
Unused Code introduced by
$variableName is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
559
            $instanceName = $this->getMyMapFunctionName(true);
0 ignored issues
show
Unused Code introduced by
$instanceName is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
560
            Requirements::javascript("googlemap/javascript/loadAjaxInfoWindow.js");
561
            Requirements::insertHeadTags('<style type="text/css">v\:* {behavior:url(#default#VML);}</style>', "GoogleMapCustomHeadTag");
562
            Requirements::javascript(
563
                "//maps.googleapis.com/maps/api/js"
564
                ."?v=".Config::inst()->get("GoogleMap", "api_version")
565
                ."&libraries=places"
566
                ."&key=".Config::inst()->get('GoogleMap', 'google_map_api_key')
567
            );
568
            Requirements::javascript(THIRDPARTY_DIR.'/jquery-form/jquery.form.js');
569
            Requirements::javascript("googlemap/javascript/googleMaps.js");
570
            $js .= $this->createJavascript();
571
            Requirements::customScript($js, "GoogleMapCustomScript");
572
            self::$_includes_are_done = true;
573
        }
574
        return $this;
575
    }
576
577
578
579
580
581
582
583
    ################################
584
    # DATA POINTS MASSAGE
585
    ################################
586
587
    /**
588
     * sorts points by Latitude
589
     * @param boolean $reverse
590
     *
591
     * @return ArrayList
592
     */
593
    protected function orderItemsByLatitude($reverse = false)
594
    {
595
        $unsortedSet = $this->getProcessedDataPointsForTemplate();
596
        $sortedSet = new ArrayList();
597
        if ($unsortedSet->count()) {
598
            foreach ($unsortedSet as $item) {
599
                $tempArray[$item->Latitude] = $item;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$tempArray was never initialized. Although not strictly required by PHP, it is generally a good practice to add $tempArray = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
600
            }
601
        }
602
        ksort($tempArray);
603
        //not sure why this is a bit counter intuitive.
604
        //north to south is from high to low ...
605
        if (!$reverse) {
606
            $tempArray = array_reverse($tempArray);
607
        }
608
        foreach ($tempArray as $item) {
609
            $sortedSet->push($item);
610
        }
611
        return $sortedSet;
612
    }
613
614
    /**
615
     *
616
     * @return Int
617
     */
618
    public function getPointCount()
619
    {
620
        if ($processedPoints = $this->getProcessedDataPointsForTemplate()) {
621
            return $processedPoints->count();
622
        } elseif ($points = $this->getPoints()) {
623
            return $points->count();
624
        }
625
        return 0;
626
    }
627
628
    /**
629
     * @return Boolean
630
     */
631
    public function EnoughPointsForAList()
632
    {
633
        return $this->getPointCount() >= $this->Config()->get("number_of_items_before_showing_list") ? true : false;
634
    }
635
636
637
    /**
638
     * must be public
639
     * does not return the datapoints XML
640
     * but loads it into variables...
641
     * @return Boolean
642
     */
643
    public function createDataPoints()
644
    {
645
        if($this->dataPointsXML === '') {
646
            $this->loadDefaults();
647
            $idArray = array();
648
            $bestZoom = $this->Config()->get("default_zoom");
649
            $averageLatitude = 0;
650
            $averageLongitude = 0;
651
            $count = 0;
652
            $pointsXml = '';
653
            //width
654
            $totalCount = $this->getPointCount();
655
            $filterFree = count($this->filteredClassNameArray) ? false : true;
656
            $averageLongitudeArray = array();
657
            $averageLatitudeArray = array();
658
            if ($totalCount > 0  && $totalCount < 10000) {
659
                $this->processedDataPointsForTemplate = new ArrayList();
660
                foreach ($this->getPoints() as $dataPoint) {
661
                    $dataPoint->addParentData();
662
                    if ($filterFree || in_array($dataPoint->ClassName, $this->filteredClassNameArray)) {
663
                        if (! in_array($dataPoint->ID, $idArray)) {
664
                            if ($dataPoint->Longitude && $dataPoint->Latitude) {
665
                                $dataLine = '<Point><coordinates>'.$dataPoint->Longitude.','.$dataPoint->Latitude.'</coordinates></Point>';
666
                                $link = '';
0 ignored issues
show
Unused Code introduced by
$link is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
667
                                if ($dataPoint->Link) {
668
                                    $link = $dataPoint->getAjaxInfoWindowLink();
0 ignored issues
show
Unused Code introduced by
$link is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
669
                                }
670
                                $staticIcon = '';
0 ignored issues
show
Unused Code introduced by
$staticIcon is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
671
                                if ($dataPoint->staticIcon) {
672
                                    $staticIcon = $dataPoint->staticIcon;
0 ignored issues
show
Unused Code introduced by
$staticIcon is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
673
                                } else {
674
                                    $staticIcon = $this->Config()->get("static_icon");
0 ignored issues
show
Unused Code introduced by
$staticIcon is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
675
                                }
676
                                $center = round($dataPoint->Latitude, 6).",".round($dataPoint->Longitude, 6);
677
                                //get the center IF there is only one point...
678
                                if (!$count) {
679
                                    $defaultCenter = $center;
0 ignored issues
show
Unused Code introduced by
$defaultCenter is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
680
                                }
681
                                if (!$dataPoint->Name) {
682
                                    $dataPoint->Name = "no name";
683
                                }
684
                                $pointsXml .=
685
                                            '<Placemark>'.
686
                                            '<id>'.$dataPoint->ID.'</id>'.
687
                                            '<name>'.Convert::raw2xml($dataPoint->Name).'</name>'.
688
                                            $dataLine.
689
                                            '<description><![CDATA[ '.$dataPoint->getAjaxInfoWindowLink().']]></description>'.
690
                                            '</Placemark>';
691
                                $this->processedDataPointsForTemplate->push($dataPoint);
692
                                $averageLatitudeArray[] = $dataPoint->Longitude;
693
                                $averageLongitudeArray[] = $dataPoint->Latitude;
694
                                $count++;
695
                            }
696
                        }
697
                    }
698
                    $idArray[$dataPoint->ID] = $dataPoint->ID;
699
                }
700
                $averageLongitude = array_sum($averageLongitudeArray) / count($averageLongitudeArray);
701
                $averageLatitude = array_sum($averageLatitudeArray) / count($averageLatitudeArray);
702
703
                $this->processedDataPointsForTemplate = $this->orderItemsByLatitude($this->processedDataPointsForTemplate);
0 ignored issues
show
Documentation introduced by
$this->processedDataPointsForTemplate is of type object<ArrayList>, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
704
            }
705
            if(! $pointsXml) {
706
                $pointsXml = '<errormessage>'.$this->getNoDataPointsMessage().'</errormessage>';
707
            }
708
            if (!$averageLongitude) {
709
                $averageLongitude = $this->config()->get("default_longitude");
710
            }
711
            if (!$averageLatitude) {
712
                $averageLatitude = $this->config()->get("default_latitude");
713
            }
714
            $this->dataPointsXML =
715
                        '<mapinfo>'.'<title>'.$this->getTitleOfMap().'</title>'
716
                        .'<longitude>'.number_format($averageLongitude - 0, 12, ".", "").'</longitude>'
717
                        .'<latitude>'.number_format($averageLatitude - 0, 9, ".", "").'</latitude>'
718
                        .'<zoom>'.$bestZoom.'</zoom>'
719
                        .'<pointcount>'.$count.'</pointcount>'
720
                        .'<info>'.$this->getWhereStatementDescription().'</info>'
721
                        .'</mapinfo>'
722
                        .$pointsXml;
723
        }
724
725
        return true;
726
    }
727
728
    /**
729
     * @param String staticVariablename
730
     * @return String (Javascript)
731
     */
732
    protected function createJavascript()
733
    {
734
        $variableName = $this->getMyMapFunctionName(false);
0 ignored issues
show
Unused Code introduced by
$variableName is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
735
        $instanceName = $this->getMyMapFunctionName(true);
0 ignored issues
show
Unused Code introduced by
$instanceName is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
736
        $js = '
737
            if(typeof GoogleMapConstructors === "undefined"){
738
                GoogleMapConstructors = [];
739
            }
740
            GoogleMapConstructors.push(
741
                {
742
                    divID: "'.$this->config()->get("main_div_id").'",
743
                    layers: [],
744
                    address: "",
745
                    options: {
746
                        /* HELPDIVS */
747
                        sideBarId:"'.$this->config()->get("side_bar_div_id").'",
748
                        dropBoxId:"'.$this->config()->get("drop_down_div_id").'",
749
                        titleId:"'.$this->config()->get("title_div_id").'",
750
                        layerListId:"'.$this->config()->get("layer_list_div_id").'",
751
                        directionsDivId:"'.$this->config()->get("directions_div_id").'",
752
                        statusDivId:"'.$this->config()->get("status_div_id").'",
753
                        noStatusAtAll:'.$this->showFalseOrTrue($this->config()->get("no_status_at_all")).',
754
                        addKmlLink:'.$this->showFalseOrTrue($this->config()->get("add_kml_link")).',
755
                        hiddenLayersRemovedFromList:'.$this->showFalseOrTrue($this->config()->get("hidden_layers_removed_from_list")).',
756
757
                        /* PAGE*/
758
                        changePageTitle:'.$this->showFalseOrTrue($this->config()->get("change_page_title")).',
759
                        defaultTitle:"'.$this->config()->get("default_title").'",
760
761
                        /* INFOWINDOW*/
762
                        infoWindowOptions:'.$this->config()->get("info_window_options").',
763
                        addAntipodean:'.$this->showFalseOrTrue($this->config()->get("add_antipodean")).',
764
                        addDirections:'.$this->showFalseOrTrue($this->config()->get("add_directions")).',
765
                        addCurrentAddressFinder:'.$this->showFalseOrTrue($this->config()->get("add_current_address_finder_in_marker")).',
766
                        addZoomInButton:"'.$this->config()->get("add_zoom_in_button").'",
767
768
                        /* MARKER */
769
                        addPointsToMap:'.$this->showFalseOrTrue($this->config()->get("add_points_to_map")).',
770
                        addDeleteMarkerButton:"'.$this->config()->get("add_delete_marker_button").'",
771
                        markerOptions: '.$this->config()->get("marker_options").',
772
                        preloadImages:'.$this->showFalseOrTrue($this->config()->get("preload_images")).',
773
774
                        /* ICONS */
775
                        defaultIconUrl: "'.$this->config()->get("default_icon_url").'",
776
                        iconFolder: "'.$this->config()->get("icon_folder").'",
777
                        iconWidth:'.$this->config()->get("icon_width").',
778
                        iconHeight:'.$this->config()->get("icon_height").',
779
                        iconExtension:"'.$this->config()->get("icon_extension").'",
780
                        iconMaxCount:'.$this->config()->get("icon_max_count").',
781
782
                        /* POLYS */
783
                        lineColour: "'.$this->config()->get("line_colour").'",
784
                        lineWidth: "'.$this->config()->get("line_width").'",
785
                        lineOpacity: "'.$this->config()->get("line_opacity").'",
786
                        fillColour: "'.$this->config()->get("fill_colour").'",
787
                        fillOpacity: "'.$this->config()->get("fill_opacity").'",
788
                        polyIcon: "'.$this->config()->get("poly_icon").'",
789
790
                        /* MAP*/
791
                        mapTypeDefault: '.intval($this->config()->get("map_type_default")-0).',
792
                        viewFinderSize:'.intval($this->config()->get("view_finder_size") - 0).',
793
                        mapAddTypeControl:'.$this->showFalseOrTrue($this->config()->get("map_add_type_control")).',
794
                        mapControlSizeOneToThree:'.$this->config()->get("map_control_size_one_to_three").',
795
                        mapScaleInfoSizeInPixels:'.intval($this->config()->get("map_scale_info_size_in_pixels") - 0).',
796
797
                        /* START POSITION */
798
                        defaultLatitude:'.number_format($this->config()->get("default_latitude") - 0, 9, ".", "").',
799
                        defaultLongitude:'.number_format($this->config()->get("default_longitude") - 0, 12, ".", "").',
800
                        defaultZoom:'.intval($this->config()->get("default_zoom")  - 0).',
801
802
                        /* SERVER INTERACTION */
803
                        updateServerUrlAddressSearchPoint: "'.$this->getUpdateServerUrlAddressSearchPoint(). '",
804
                        updateServerUrlDragend: "'.$this->getUpdateServerUrlDragend().'",
805
                        latFormFieldId:"'.$this->config()->get("lat_form_field_id").'",
806
                        lngFormFieldId:"'.$this->config()->get("lng_form_field_id").'",
807
808
                        /* ADDRESS FORM */
809
                        addAddressFinder:'.$this->showFalseOrTrue($this->config()->get("add_address_finder")).',
810
                        defaultCountryCode:"'.$this->config()->get("default_country_code").'",
811
812
                        /* DIRECTIONS */
813
                        styleSheetUrl: "'.$this->config()->get("style_sheet_url").'",
814
                        localeForResults: "'.$this->config()->get("locale_for_results").'"
815
                    }
816
                }
817
            );';
818
        if ($this->linksForData && count($this->linksForData)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->linksForData of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
819
            foreach ($this->linksForData as $link => $title) {
820
                $js .= '
821
                GoogleMapConstructors[GoogleMapConstructors.length-1].layers.push(
822
                    {
823
                        link: '.Convert::raw2json(Director::absoluteURL($link)).',
824
                        title:  '.Convert::raw2json($title).'
825
                    }
826
                );';
827
            }
828
        } elseif ($this->address) {
829
            $js .= '
830
                GoogleMapConstructors[GoogleMapConstructors.length-1].address = \''.$this->address.'\'';
831
        }
832
        return $js;
833
    }
834
835
    /**
836
     * turns 0 into false and 1 into true
837
     * @param Mixed
838
     * @return string (true|false)
839
     */
840
    protected function showFalseOrTrue($v)
841
    {
842
        if ($v && $v !== "false" && $v !== "0" && $v !== 0) {
843
            return "true";
844
        } else {
845
            return "false";
846
        }
847
    }
848
849
    /**
850
     * load some defaults
851
     */
852
    protected function loadDefaults()
853
    {
854
        if (!isset($this->whereStatementDescription)) {
855
            $this->whereStatementDescription = $this->Config()->get("default_where_statement_description");
856
        }
857
        if (!isset($this->titleOfMap) || !$this->titleOfMap) {
858
            $this->titleOfMap = $this->Config()->get("default_title");
859
        }
860
    }
861
}
862