Completed
Push — master ( 9b3671...78fc19 )
by Jason
03:15
created
code/Locator.php 2 patches
Spacing   +15 added lines, -19 removed lines patch added patch discarded remove patch
@@ -86,44 +86,40 @@  discard block
 block discarded – undo
86 86
         Requirements::css('locator/css/map.css');
87 87
 
88 88
         $featured = (Locator::getLocations(array('Featured' => 1))->count() > 0) ?
89
-            'featuredLocations: true' :
90
-            'featuredLocations: false';
89
+            'featuredLocations: true' : 'featuredLocations: false';
91 90
 
92 91
         // map config based on user input in Settings tab
93 92
         // AutoGeocode or Full Map
94 93
         $load = ($this->data()->AutoGeocode) ?
95
-            'autoGeocode: true, fullMapStart: false,' :
96
-            'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
94
+            'autoGeocode: true, fullMapStart: false,' : 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
97 95
 
98 96
         $base = Director::baseFolder();
99
-        $themePath = $base.'/'.$themeDir;
97
+        $themePath = $base . '/' . $themeDir;
100 98
 
101
-        $listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ?
102
-            $themeDir.'/templates/location-list-description.html' :
103
-            'locator/templates/location-list-description.html';
104
-        $infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ?
105
-            $themeDir.'/templates/infowindow-description.html' :
106
-            'locator/templates/infowindow-description.html';
99
+        $listTemplatePath = (file_exists($themePath . '/templates/location-list-description.html')) ?
100
+            $themeDir . '/templates/location-list-description.html' : 'locator/templates/location-list-description.html';
101
+        $infowindowTemplatePath = (file_exists($themePath . '/templates/infowindow-description.html')) ?
102
+            $themeDir . '/templates/infowindow-description.html' : 'locator/templates/infowindow-description.html';
107 103
 
108 104
         // in page or modal
109 105
         $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
110 106
 
111 107
         $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
112 108
 
113
-        $link = $this->Link().'xml.xml';
109
+        $link = $this->Link() . 'xml.xml';
114 110
 
115 111
         // init map
116 112
         if (Locator::getLocations()) {
117 113
             Requirements::customScript("
118 114
                 $(function($) {
119 115
                     $('#map-container').storeLocator({
120
-                        ".$load."
121
-                        dataLocation: '".$link."',
122
-                        listTemplatePath: '".$listTemplatePath."',
123
-                        infowindowTemplatePath: '".$infowindowTemplatePath."',
116
+                        ".$load . "
117
+                        dataLocation: '".$link . "',
118
+                        listTemplatePath: '".$listTemplatePath . "',
119
+                        infowindowTemplatePath: '".$infowindowTemplatePath . "',
124 120
                         originMarker: true,
125
-                        ".$modal.',
126
-                        '.$featured.",
121
+                        ".$modal . ',
122
+                        '.$featured . ",
127 123
                         slideMap: false,
128 124
                         zoomLevel: 0,
129 125
                         distanceAlert: 120,
@@ -131,7 +127,7 @@  discard block
 block discarded – undo
131 127
                         inputID: 'Form_LocationSearch_address',
132 128
                         categoryID: 'Form_LocationSearch_category',
133 129
                         distanceAlert: -1,
134
-                        ".$kilometer.'
130
+                        ".$kilometer . '
135 131
                     });
136 132
                 });
137 133
             ');
Please login to merge, or discard this patch.
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -2,119 +2,119 @@  discard block
 block discarded – undo
2 2
 
3 3
 class Locator extends Page
4 4
 {
5
-    private static $db = array(
6
-        'AutoGeocode' => 'Boolean',
7
-        'ModalWindow' => 'Boolean',
8
-        'Unit' => 'Enum("m,km","m")',
9
-    );
10
-
11
-    private static $defaults = array(
12
-        'AutoGeocode' => true,
13
-    );
14
-
15
-    private static $singular_name = 'Locator';
16
-    private static $plural_name = 'Locators';
17
-    private static $description = 'Show locations on a map';
18
-
19
-    public function getCMSFields()
20
-    {
21
-        $fields = parent::getCMSFields();
22
-
23
-        // Locations Grid Field
24
-        $config = GridFieldConfig_RecordEditor::create();
25
-        $locations = Location::get();
26
-        $fields->addFieldToTab('Root.Locations', GridField::create('Locations', 'Locations', $locations, $config));
27
-
28
-        // Location categories
29
-        $config = GridFieldConfig_RecordEditor::create();
30
-        $fields->addFieldToTab('Root.Categories', GridField::create('Categories', 'Categories', LocationCategory::get(), $config));
31
-
32
-        // Settings
33
-        $fields->addFieldsToTab('Root.Settings', array(
34
-            HeaderField::create('DisplayOptions', 'Display Options', 3),
35
-            OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')),
36
-            CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location')
37
-                ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'),
38
-            CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'),
39
-        ));
40
-
41
-        $this->extend('updateCMSFields', $fields);
42
-
43
-        return $fields;
44
-    }
45
-
46
-    public static function getLocations($filter = array(), $exclude = array())
47
-    {
48
-        $filter['ShowInLocator'] = true;
49
-
50
-        return Location::get()
51
-            ->exclude($exclude)
52
-            ->exclude('Lat', 0)
53
-            ->filter($filter);
54
-    }
55
-
56
-    public function getAreLocations()
57
-    {
58
-        return self::getLocations();
59
-    }
60
-
61
-    public function getAllCategories()
62
-    {
63
-        return LocationCategory::get();
64
-    }
5
+	private static $db = array(
6
+		'AutoGeocode' => 'Boolean',
7
+		'ModalWindow' => 'Boolean',
8
+		'Unit' => 'Enum("m,km","m")',
9
+	);
10
+
11
+	private static $defaults = array(
12
+		'AutoGeocode' => true,
13
+	);
14
+
15
+	private static $singular_name = 'Locator';
16
+	private static $plural_name = 'Locators';
17
+	private static $description = 'Show locations on a map';
18
+
19
+	public function getCMSFields()
20
+	{
21
+		$fields = parent::getCMSFields();
22
+
23
+		// Locations Grid Field
24
+		$config = GridFieldConfig_RecordEditor::create();
25
+		$locations = Location::get();
26
+		$fields->addFieldToTab('Root.Locations', GridField::create('Locations', 'Locations', $locations, $config));
27
+
28
+		// Location categories
29
+		$config = GridFieldConfig_RecordEditor::create();
30
+		$fields->addFieldToTab('Root.Categories', GridField::create('Categories', 'Categories', LocationCategory::get(), $config));
31
+
32
+		// Settings
33
+		$fields->addFieldsToTab('Root.Settings', array(
34
+			HeaderField::create('DisplayOptions', 'Display Options', 3),
35
+			OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')),
36
+			CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location')
37
+				->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'),
38
+			CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'),
39
+		));
40
+
41
+		$this->extend('updateCMSFields', $fields);
42
+
43
+		return $fields;
44
+	}
45
+
46
+	public static function getLocations($filter = array(), $exclude = array())
47
+	{
48
+		$filter['ShowInLocator'] = true;
49
+
50
+		return Location::get()
51
+			->exclude($exclude)
52
+			->exclude('Lat', 0)
53
+			->filter($filter);
54
+	}
55
+
56
+	public function getAreLocations()
57
+	{
58
+		return self::getLocations();
59
+	}
60
+
61
+	public function getAllCategories()
62
+	{
63
+		return LocationCategory::get();
64
+	}
65 65
 }
66 66
 
67 67
 class Locator_Controller extends Page_Controller
68 68
 {
69
-    // allowed actions
70
-    private static $allowed_actions = array('xml');
69
+	// allowed actions
70
+	private static $allowed_actions = array('xml');
71 71
 
72
-    // Set Requirements based on input from CMS
73
-    public function init()
74
-    {
75
-        parent::init();
72
+	// Set Requirements based on input from CMS
73
+	public function init()
74
+	{
75
+		parent::init();
76 76
 
77
-        $themeDir = SSViewer::get_theme_folder();
77
+		$themeDir = SSViewer::get_theme_folder();
78 78
 
79
-        Requirements::javascript('framework/thirdparty/jquery/jquery.js');
80
-        if (Locator::getLocations()) {
81
-            Requirements::javascript('http://maps.google.com/maps/api/js?sensor=false');
82
-            Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
83
-            Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
84
-        }
79
+		Requirements::javascript('framework/thirdparty/jquery/jquery.js');
80
+		if (Locator::getLocations()) {
81
+			Requirements::javascript('http://maps.google.com/maps/api/js?sensor=false');
82
+			Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
83
+			Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');
84
+		}
85 85
 
86
-        Requirements::css('locator/css/map.css');
86
+		Requirements::css('locator/css/map.css');
87 87
 
88
-        $featured = (Locator::getLocations(array('Featured' => 1))->count() > 0) ?
89
-            'featuredLocations: true' :
90
-            'featuredLocations: false';
88
+		$featured = (Locator::getLocations(array('Featured' => 1))->count() > 0) ?
89
+			'featuredLocations: true' :
90
+			'featuredLocations: false';
91 91
 
92
-        // map config based on user input in Settings tab
93
-        // AutoGeocode or Full Map
94
-        $load = ($this->data()->AutoGeocode) ?
95
-            'autoGeocode: true, fullMapStart: false,' :
96
-            'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
92
+		// map config based on user input in Settings tab
93
+		// AutoGeocode or Full Map
94
+		$load = ($this->data()->AutoGeocode) ?
95
+			'autoGeocode: true, fullMapStart: false,' :
96
+			'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';
97 97
 
98
-        $base = Director::baseFolder();
99
-        $themePath = $base.'/'.$themeDir;
98
+		$base = Director::baseFolder();
99
+		$themePath = $base.'/'.$themeDir;
100 100
 
101
-        $listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ?
102
-            $themeDir.'/templates/location-list-description.html' :
103
-            'locator/templates/location-list-description.html';
104
-        $infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ?
105
-            $themeDir.'/templates/infowindow-description.html' :
106
-            'locator/templates/infowindow-description.html';
101
+		$listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ?
102
+			$themeDir.'/templates/location-list-description.html' :
103
+			'locator/templates/location-list-description.html';
104
+		$infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ?
105
+			$themeDir.'/templates/infowindow-description.html' :
106
+			'locator/templates/infowindow-description.html';
107 107
 
108
-        // in page or modal
109
-        $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
108
+		// in page or modal
109
+		$modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';
110 110
 
111
-        $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
111
+		$kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"';
112 112
 
113
-        $link = $this->Link().'xml.xml';
113
+		$link = $this->Link().'xml.xml';
114 114
 
115
-        // init map
116
-        if (Locator::getLocations()) {
117
-            Requirements::customScript("
115
+		// init map
116
+		if (Locator::getLocations()) {
117
+			Requirements::customScript("
118 118
                 $(function($) {
119 119
                     $('#map-container').storeLocator({
120 120
                         ".$load."
@@ -135,66 +135,66 @@  discard block
 block discarded – undo
135 135
                     });
136 136
                 });
137 137
             ');
138
-        }
139
-    }
140
-
141
-    /**
142
-     * Find all locations for map.
143
-     *
144
-     * Will return a XML feed of all locations marked "show in locator".
145
-     *
146
-     * @return XML file
147
-     *
148
-     * @todo rename/refactor to allow for json/xml
149
-     * @todo allow $filter to run off of getVars key/val pair
150
-     */
151
-    public function xml(SS_HTTPRequest $request)
152
-    {
153
-        $filter = array();
154
-        $Locations = Locator::getLocations($filter);
155
-
156
-        return $this->customise(array(
157
-            'Locations' => $Locations,
158
-        ))->renderWith('LocationXML');
159
-    }
160
-
161
-    /**
162
-     * LocationSearch form.
163
-     *
164
-     * Search form for locations, updates map and results list via AJAX
165
-     *
166
-     * @return Form
167
-     */
168
-    public function LocationSearch()
169
-    {
170
-        $fields = FieldList::create(
171
-            $address = TextField::create('address', '')
172
-        );
173
-        $address->setAttribute('placeholder', 'address or zip code');
174
-
175
-        if (LocationCategory::get()->Count() > 0) {
176
-            $filter = array();
177
-            $locals = Locator::getLocations($filter, $exclude = array('CategoryID' => 0));
178
-            $categories = ArrayList::create();
179
-
180
-            foreach ($locals as $local) {
181
-                $categories->add($local->Category());
182
-            }
183
-
184
-            if ($categories->count() > 0) {
185
-                $fields->push(
186
-                    DropdownField::create(
187
-                        'category',
188
-                        '',
189
-                        $categories->map('Title', 'Title')
190
-                    )->setEmptyString('Select Category'));
191
-            }
192
-        }
193
-
194
-        $actions = FieldList::create(
195
-            FormAction::create('', 'Search')
196
-        );
197
-
198
-        return Form::create($this, 'LocationSearch', $fields, $actions);
199
-    }
138
+		}
139
+	}
140
+
141
+	/**
142
+	 * Find all locations for map.
143
+	 *
144
+	 * Will return a XML feed of all locations marked "show in locator".
145
+	 *
146
+	 * @return XML file
147
+	 *
148
+	 * @todo rename/refactor to allow for json/xml
149
+	 * @todo allow $filter to run off of getVars key/val pair
150
+	 */
151
+	public function xml(SS_HTTPRequest $request)
152
+	{
153
+		$filter = array();
154
+		$Locations = Locator::getLocations($filter);
155
+
156
+		return $this->customise(array(
157
+			'Locations' => $Locations,
158
+		))->renderWith('LocationXML');
159
+	}
160
+
161
+	/**
162
+	 * LocationSearch form.
163
+	 *
164
+	 * Search form for locations, updates map and results list via AJAX
165
+	 *
166
+	 * @return Form
167
+	 */
168
+	public function LocationSearch()
169
+	{
170
+		$fields = FieldList::create(
171
+			$address = TextField::create('address', '')
172
+		);
173
+		$address->setAttribute('placeholder', 'address or zip code');
174
+
175
+		if (LocationCategory::get()->Count() > 0) {
176
+			$filter = array();
177
+			$locals = Locator::getLocations($filter, $exclude = array('CategoryID' => 0));
178
+			$categories = ArrayList::create();
179
+
180
+			foreach ($locals as $local) {
181
+				$categories->add($local->Category());
182
+			}
183
+
184
+			if ($categories->count() > 0) {
185
+				$fields->push(
186
+					DropdownField::create(
187
+						'category',
188
+						'',
189
+						$categories->map('Title', 'Title')
190
+					)->setEmptyString('Select Category'));
191
+			}
192
+		}
193
+
194
+		$actions = FieldList::create(
195
+			FormAction::create('', 'Search')
196
+		);
197
+
198
+		return Form::create($this, 'LocationSearch', $fields, $actions);
199
+	}
200 200
 }
Please login to merge, or discard this patch.
code/LocationAdmin.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -2,41 +2,41 @@
 block discarded – undo
2 2
 
3 3
 class LocationAdmin extends ModelAdmin
4 4
 {
5
-    private static $managed_models = array(
6
-        'Location',
7
-        'LocationCategory',
8
-    );
5
+	private static $managed_models = array(
6
+		'Location',
7
+		'LocationCategory',
8
+	);
9 9
 
10
-    private static $model_importers = array(
11
-        'Location' => 'LocationCsvBulkLoader',
12
-        'LocationCategory' => 'CsvBulkLoader',
13
-    );
10
+	private static $model_importers = array(
11
+		'Location' => 'LocationCsvBulkLoader',
12
+		'LocationCategory' => 'CsvBulkLoader',
13
+	);
14 14
 
15
-    private static $menu_title = 'Locator';
16
-    private static $url_segment = 'locator';
15
+	private static $menu_title = 'Locator';
16
+	private static $url_segment = 'locator';
17 17
 
18
-    public function getExportFields()
19
-    {
20
-        if ($this->modelClass == 'Location') {
21
-            return array(
22
-                'Title' => 'Name',
23
-                'Address' => 'Address',
24
-                'Suburb' => 'City',
25
-                'State' => 'State',
26
-                'Postcode' => 'Postcode',
27
-                'Country' => 'Country',
28
-                'Website' => 'Website',
29
-                'Phone' => 'Phone',
30
-                'Fax' => 'Fax',
31
-                'Email' => 'Email',
32
-                'Category.Name' => 'Category',
33
-                'ShowInLocator' => 'ShowInLocator',
34
-                'Featured' => 'Featured',
35
-                'Lat' => 'Lat',
36
-                'Lng' => 'Lng',
37
-            );
38
-        }
18
+	public function getExportFields()
19
+	{
20
+		if ($this->modelClass == 'Location') {
21
+			return array(
22
+				'Title' => 'Name',
23
+				'Address' => 'Address',
24
+				'Suburb' => 'City',
25
+				'State' => 'State',
26
+				'Postcode' => 'Postcode',
27
+				'Country' => 'Country',
28
+				'Website' => 'Website',
29
+				'Phone' => 'Phone',
30
+				'Fax' => 'Fax',
31
+				'Email' => 'Email',
32
+				'Category.Name' => 'Category',
33
+				'ShowInLocator' => 'ShowInLocator',
34
+				'Featured' => 'Featured',
35
+				'Lat' => 'Lat',
36
+				'Lng' => 'Lng',
37
+			);
38
+		}
39 39
 
40
-        return parent::getExportFields();
41
-    }
40
+		return parent::getExportFields();
41
+	}
42 42
 }
Please login to merge, or discard this patch.
code/Location.php 1 patch
Indentation   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -2,177 +2,177 @@
 block discarded – undo
2 2
 
3 3
 class Location extends DataObject implements PermissionProvider
4 4
 {
5
-    private static $db = array(
6
-        'Title' => 'Varchar(255)',
7
-        'Featured' => 'Boolean',
8
-        'Website' => 'Varchar(255)',
9
-        'Phone' => 'Varchar(40)',
10
-        'Email' => 'Varchar(255)',
11
-        'EmailAddress' => 'Varchar(255)',
12
-        'ShowInLocator' => 'Boolean',
13
-    );
14
-
15
-    private static $has_one = array(
16
-        'Category' => 'LocationCategory',
17
-    );
18
-
19
-    private static $casting = array(
20
-        'distance' => 'Int',
21
-    );
22
-
23
-    private static $default_sort = 'Title';
24
-
25
-    private static $defaults = array(
26
-        'ShowInLocator' => true,
27
-    );
28
-
29
-    private static $singular_name = 'Location';
30
-    private static $plural_name = 'Locations';
31
-
32
-    // api access via Restful Server module
33
-    private static $api_access = true;
34
-
35
-    // search fields for Model Admin
36
-    private static $searchable_fields = array(
37
-        'Title',
38
-        'Address',
39
-        'Suburb',
40
-        'State',
41
-        'Postcode',
42
-        'Country',
43
-        'Website',
44
-        'Phone',
45
-        'Email',
46
-        'Category.ID',
47
-        'ShowInLocator',
48
-        'Featured',
49
-    );
50
-
51
-    // columns for grid field
52
-    private static $summary_fields = array(
53
-        'Title',
54
-        'Address',
55
-        'Suburb',
56
-        'State',
57
-        'Postcode',
58
-        'Country',
59
-        'Category.Name',
60
-        'ShowInLocator.NiceAsBoolean',
61
-        'Featured.NiceAsBoolean',
62
-        'Coords',
63
-    );
64
-
65
-    // Coords status for $summary_fields
66
-    public function getCoords()
67
-    {
68
-        return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
69
-    }
70
-
71
-    // custom labels for fields
72
-    public function fieldLabels($includerelations = true)
73
-    {
74
-        $labels = parent::fieldLabels();
75
-
76
-        $labels['Title'] = 'Name';
77
-        $labels['Suburb'] = 'City';
78
-        $labels['Postcode'] = 'Postal Code';
79
-        $labels['ShowInLocator'] = 'Show';
80
-        $labels['ShowInLocator.NiceAsBoolean'] = 'Show';
81
-        $labels['Category.Name'] = 'Category';
82
-        $labels['Email'] = 'Email';
83
-        $labels['Featured.NiceAsBoolean'] = 'Featured';
84
-        $labels['Coords'] = 'Coords';
85
-
86
-        return $labels;
87
-    }
88
-
89
-    public function getCMSFields()
90
-    {
91
-        $fields = FieldList::create(
92
-            new TabSet(
93
-                $name = 'Root',
94
-                new Tab(
95
-                    $title = 'Main',
96
-                    HeaderField::create('ContactHD', 'Contact Information'),
97
-                    TextField::create('Title', 'Name'),
98
-                    TextField::create('Phone'),
99
-                    EmailField::create('Email', 'Email'),
100
-                    TextField::create('Website')
101
-                        ->setAttribute('placeholder', 'http://'),
102
-                    DropDownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title'))
103
-                        ->setEmptyString('-- select --'),
104
-                    CheckboxField::create('ShowInLocator', 'Show in results')
105
-                        ->setDescription('Location will be included in results list'),
106
-                    CheckboxField::create('Featured')
107
-                        ->setDescription('Location will show at/near the top of the results list')
108
-                )
109
-            )
110
-        );
111
-
112
-        // allow to be extended via DataExtension
113
-        $this->extend('updateCMSFields', $fields);
114
-
115
-        // override Suburb field name
116
-        $fields->dataFieldByName('Suburb')->setTitle('City');
117
-
118
-        return $fields;
119
-    }
120
-
121
-    public function validate()
122
-    {
123
-        $result = parent::validate();
124
-
125
-        return $result;
126
-    }
127
-
128
-    public function EmailAddress()
129
-    {
130
-        Deprecation::notice('3.0', 'Use "$Email" instead.');
131
-        if ($this->Email) {
132
-            return $this->Email;
133
-        } elseif ($this->EmailAddress) {
134
-            return $this->EmailAddress;
135
-        }
136
-
137
-        return false;
138
-    }
139
-
140
-    /**
141
-     * @param Member $member
142
-     *
143
-     * @return bool
144
-     */
145
-    public function canView($member = false)
146
-    {
147
-        return true;
148
-    }
149
-
150
-    public function canEdit($member = false)
151
-    {
152
-        return Permission::check('Location_EDIT');
153
-    }
154
-
155
-    public function canDelete($member = false)
156
-    {
157
-        return Permission::check('Location_DELETE');
158
-    }
159
-
160
-    public function canCreate($member = false)
161
-    {
162
-        return Permission::check('Location_CREATE');
163
-    }
164
-
165
-    public function providePermissions()
166
-    {
167
-        return array(
168
-            'Location_EDIT' => 'Edit a Location',
169
-            'Location_DELETE' => 'Delete a Location',
170
-            'Location_CREATE' => 'Create a Location',
171
-        );
172
-    }
173
-
174
-    public function onBeforeWrite()
175
-    {
176
-        parent::onBeforeWrite();
177
-    }
5
+	private static $db = array(
6
+		'Title' => 'Varchar(255)',
7
+		'Featured' => 'Boolean',
8
+		'Website' => 'Varchar(255)',
9
+		'Phone' => 'Varchar(40)',
10
+		'Email' => 'Varchar(255)',
11
+		'EmailAddress' => 'Varchar(255)',
12
+		'ShowInLocator' => 'Boolean',
13
+	);
14
+
15
+	private static $has_one = array(
16
+		'Category' => 'LocationCategory',
17
+	);
18
+
19
+	private static $casting = array(
20
+		'distance' => 'Int',
21
+	);
22
+
23
+	private static $default_sort = 'Title';
24
+
25
+	private static $defaults = array(
26
+		'ShowInLocator' => true,
27
+	);
28
+
29
+	private static $singular_name = 'Location';
30
+	private static $plural_name = 'Locations';
31
+
32
+	// api access via Restful Server module
33
+	private static $api_access = true;
34
+
35
+	// search fields for Model Admin
36
+	private static $searchable_fields = array(
37
+		'Title',
38
+		'Address',
39
+		'Suburb',
40
+		'State',
41
+		'Postcode',
42
+		'Country',
43
+		'Website',
44
+		'Phone',
45
+		'Email',
46
+		'Category.ID',
47
+		'ShowInLocator',
48
+		'Featured',
49
+	);
50
+
51
+	// columns for grid field
52
+	private static $summary_fields = array(
53
+		'Title',
54
+		'Address',
55
+		'Suburb',
56
+		'State',
57
+		'Postcode',
58
+		'Country',
59
+		'Category.Name',
60
+		'ShowInLocator.NiceAsBoolean',
61
+		'Featured.NiceAsBoolean',
62
+		'Coords',
63
+	);
64
+
65
+	// Coords status for $summary_fields
66
+	public function getCoords()
67
+	{
68
+		return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
69
+	}
70
+
71
+	// custom labels for fields
72
+	public function fieldLabels($includerelations = true)
73
+	{
74
+		$labels = parent::fieldLabels();
75
+
76
+		$labels['Title'] = 'Name';
77
+		$labels['Suburb'] = 'City';
78
+		$labels['Postcode'] = 'Postal Code';
79
+		$labels['ShowInLocator'] = 'Show';
80
+		$labels['ShowInLocator.NiceAsBoolean'] = 'Show';
81
+		$labels['Category.Name'] = 'Category';
82
+		$labels['Email'] = 'Email';
83
+		$labels['Featured.NiceAsBoolean'] = 'Featured';
84
+		$labels['Coords'] = 'Coords';
85
+
86
+		return $labels;
87
+	}
88
+
89
+	public function getCMSFields()
90
+	{
91
+		$fields = FieldList::create(
92
+			new TabSet(
93
+				$name = 'Root',
94
+				new Tab(
95
+					$title = 'Main',
96
+					HeaderField::create('ContactHD', 'Contact Information'),
97
+					TextField::create('Title', 'Name'),
98
+					TextField::create('Phone'),
99
+					EmailField::create('Email', 'Email'),
100
+					TextField::create('Website')
101
+						->setAttribute('placeholder', 'http://'),
102
+					DropDownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title'))
103
+						->setEmptyString('-- select --'),
104
+					CheckboxField::create('ShowInLocator', 'Show in results')
105
+						->setDescription('Location will be included in results list'),
106
+					CheckboxField::create('Featured')
107
+						->setDescription('Location will show at/near the top of the results list')
108
+				)
109
+			)
110
+		);
111
+
112
+		// allow to be extended via DataExtension
113
+		$this->extend('updateCMSFields', $fields);
114
+
115
+		// override Suburb field name
116
+		$fields->dataFieldByName('Suburb')->setTitle('City');
117
+
118
+		return $fields;
119
+	}
120
+
121
+	public function validate()
122
+	{
123
+		$result = parent::validate();
124
+
125
+		return $result;
126
+	}
127
+
128
+	public function EmailAddress()
129
+	{
130
+		Deprecation::notice('3.0', 'Use "$Email" instead.');
131
+		if ($this->Email) {
132
+			return $this->Email;
133
+		} elseif ($this->EmailAddress) {
134
+			return $this->EmailAddress;
135
+		}
136
+
137
+		return false;
138
+	}
139
+
140
+	/**
141
+	 * @param Member $member
142
+	 *
143
+	 * @return bool
144
+	 */
145
+	public function canView($member = false)
146
+	{
147
+		return true;
148
+	}
149
+
150
+	public function canEdit($member = false)
151
+	{
152
+		return Permission::check('Location_EDIT');
153
+	}
154
+
155
+	public function canDelete($member = false)
156
+	{
157
+		return Permission::check('Location_DELETE');
158
+	}
159
+
160
+	public function canCreate($member = false)
161
+	{
162
+		return Permission::check('Location_CREATE');
163
+	}
164
+
165
+	public function providePermissions()
166
+	{
167
+		return array(
168
+			'Location_EDIT' => 'Edit a Location',
169
+			'Location_DELETE' => 'Delete a Location',
170
+			'Location_CREATE' => 'Create a Location',
171
+		);
172
+	}
173
+
174
+	public function onBeforeWrite()
175
+	{
176
+		parent::onBeforeWrite();
177
+	}
178 178
 }
Please login to merge, or discard this patch.
code/LocationCsvBulkLoader.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -2,30 +2,30 @@
 block discarded – undo
2 2
 
3 3
 class LocationCsvBulkLoader extends CsvBulkLoader
4 4
 {
5
-    public $columnMap = array(
6
-        'Name' => 'Title',
7
-        'City' => 'Suburb',
8
-        'EmailAddress' => 'Email',
9
-        'Category' => 'Category.Name',
10
-    );
5
+	public $columnMap = array(
6
+		'Name' => 'Title',
7
+		'City' => 'Suburb',
8
+		'EmailAddress' => 'Email',
9
+		'Category' => 'Category.Name',
10
+	);
11 11
 
12
-    public $relationCallbacks = array(
13
-       'Category.Name' => array(
14
-           'relationname' => 'Category',
15
-           'callback' => 'getCategoryByName',
16
-        ),
17
-    );
12
+	public $relationCallbacks = array(
13
+	   'Category.Name' => array(
14
+		   'relationname' => 'Category',
15
+		   'callback' => 'getCategoryByName',
16
+		),
17
+	);
18 18
 
19
-    public static function getCategoryByName(&$obj, $val, $record)
20
-    {
21
-        $val = Convert::raw2sql($val);
22
-        $category = LocationCategory::get()->filter(array('Name' => $val))->First();
23
-        if (!$category) {
24
-            $category = LocationCategory::create();
25
-            $category->Name = $val;
26
-            $category->write();
27
-        }
19
+	public static function getCategoryByName(&$obj, $val, $record)
20
+	{
21
+		$val = Convert::raw2sql($val);
22
+		$category = LocationCategory::get()->filter(array('Name' => $val))->First();
23
+		if (!$category) {
24
+			$category = LocationCategory::create();
25
+			$category->Name = $val;
26
+			$category->write();
27
+		}
28 28
 
29
-        return $category;
30
-    }
29
+		return $category;
30
+	}
31 31
 }
Please login to merge, or discard this patch.
code/LocationCategory.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -2,16 +2,16 @@
 block discarded – undo
2 2
 
3 3
 class LocationCategory extends DataObject
4 4
 {
5
-    private static $db = array(
6
-        'Name' => 'Varchar(100)',
7
-    );
5
+	private static $db = array(
6
+		'Name' => 'Varchar(100)',
7
+	);
8 8
 
9
-    private static $has_many = array(
10
-        'Locations' => 'Location',
11
-    );
9
+	private static $has_many = array(
10
+		'Locations' => 'Location',
11
+	);
12 12
 
13
-    private static $singular_name = 'Category';
14
-    private static $plural_name = 'Categories';
13
+	private static $singular_name = 'Category';
14
+	private static $plural_name = 'Categories';
15 15
 
16
-    private static $default_sort = 'Name';
16
+	private static $default_sort = 'Name';
17 17
 }
Please login to merge, or discard this patch.
tests/Locator_Test.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -2,26 +2,26 @@
 block discarded – undo
2 2
 
3 3
 class Locator_Test extends FunctionalTest
4 4
 {
5
-    protected static $fixture_file = 'locator/tests/Locator_Test.yml';
6
-    protected static $disable_themes = true;
7
-    protected static $use_draft_site = false;
5
+	protected static $fixture_file = 'locator/tests/Locator_Test.yml';
6
+	protected static $disable_themes = true;
7
+	protected static $use_draft_site = false;
8 8
 
9
-    public function setUp()
10
-    {
11
-        parent::setUp();
9
+	public function setUp()
10
+	{
11
+		parent::setUp();
12 12
 
13
-        ini_set('display_errors', 1);
14
-        ini_set('log_errors', 1);
15
-        error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
16
-    }
13
+		ini_set('display_errors', 1);
14
+		ini_set('log_errors', 1);
15
+		error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
16
+	}
17 17
 
18
-    public function logOut()
19
-    {
20
-        $this->session()->clear('loggedInAs');
21
-        $this->session()->clear('logInWithPermission');
22
-    }
18
+	public function logOut()
19
+	{
20
+		$this->session()->clear('loggedInAs');
21
+		$this->session()->clear('logInWithPermission');
22
+	}
23 23
 
24
-    public function testLocator_Test()
25
-    {
26
-    }
24
+	public function testLocator_Test()
25
+	{
26
+	}
27 27
 }
Please login to merge, or discard this patch.
tests/LocationTest.php 1 patch
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -2,117 +2,117 @@
 block discarded – undo
2 2
 
3 3
 class LocationTest extends Locator_Test
4 4
 {
5
-    public function testGetCoords()
6
-    {
7
-        $location = $this->objFromFixture('Location', 'dynamic');
8
-        $location->write();
5
+	public function testGetCoords()
6
+	{
7
+		$location = $this->objFromFixture('Location', 'dynamic');
8
+		$location->write();
9 9
 
10
-        $coords = ($location->Lat && $location->Lng) ? 'true' : 'false';
11
-        $geoCodable = Location::get()->byID($location->ID);
10
+		$coords = ($location->Lat && $location->Lng) ? 'true' : 'false';
11
+		$geoCodable = Location::get()->byID($location->ID);
12 12
 
13
-        $this->assertEquals($coords, $geoCodable->getCoords());
14
-    }
13
+		$this->assertEquals($coords, $geoCodable->getCoords());
14
+	}
15 15
 
16
-    public function testFieldLabels()
17
-    {
18
-        $location = $this->objFromFixture('Location', 'dynamic');
19
-        $labels = $location->FieldLabels();
20
-        $expected = array(
21
-            'Title' => 'Name',
22
-            'Featured' => 'Featured',
23
-            'Website' => 'Website',
24
-            'Phone' => 'Phone',
25
-            'Email' => 'Email',
26
-            'EmailAddress' => 'Email Address',
27
-            'ShowInLocator' => 'Show',
28
-            'Address' => 'Address',
29
-            'Suburb' => 'City',
30
-            'State' => 'State',
31
-            'Postcode' => 'Postal Code',
32
-            'Country' => 'Country',
33
-            'Lat' => 'Lat',
34
-            'Lng' => 'Lng',
35
-            'Category' => 'Category',
36
-            'ShowInLocator.NiceAsBoolean' => 'Show',
37
-            'Category.Name' => 'Category',
38
-            'Featured.NiceAsBoolean' => 'Featured',
39
-            'Coords' => 'Coords',
40
-        );
41
-        $this->assertEquals($expected, $labels);
42
-    }
16
+	public function testFieldLabels()
17
+	{
18
+		$location = $this->objFromFixture('Location', 'dynamic');
19
+		$labels = $location->FieldLabels();
20
+		$expected = array(
21
+			'Title' => 'Name',
22
+			'Featured' => 'Featured',
23
+			'Website' => 'Website',
24
+			'Phone' => 'Phone',
25
+			'Email' => 'Email',
26
+			'EmailAddress' => 'Email Address',
27
+			'ShowInLocator' => 'Show',
28
+			'Address' => 'Address',
29
+			'Suburb' => 'City',
30
+			'State' => 'State',
31
+			'Postcode' => 'Postal Code',
32
+			'Country' => 'Country',
33
+			'Lat' => 'Lat',
34
+			'Lng' => 'Lng',
35
+			'Category' => 'Category',
36
+			'ShowInLocator.NiceAsBoolean' => 'Show',
37
+			'Category.Name' => 'Category',
38
+			'Featured.NiceAsBoolean' => 'Featured',
39
+			'Coords' => 'Coords',
40
+		);
41
+		$this->assertEquals($expected, $labels);
42
+	}
43 43
 
44
-    public function testGetCMSFields()
45
-    {
46
-        $object = new Location();
47
-        $fieldset = $object->getCMSFields();
48
-        $this->assertTrue(is_a($fieldset, 'FieldList'));
49
-    }
44
+	public function testGetCMSFields()
45
+	{
46
+		$object = new Location();
47
+		$fieldset = $object->getCMSFields();
48
+		$this->assertTrue(is_a($fieldset, 'FieldList'));
49
+	}
50 50
 
51
-    public function testValidate()
52
-    {
53
-    }
51
+	public function testValidate()
52
+	{
53
+	}
54 54
 
55
-    public function testEmailAddress()
56
-    {
57
-    }
55
+	public function testEmailAddress()
56
+	{
57
+	}
58 58
 
59
-    public function testCanView()
60
-    {
61
-        $object = $this->objFromFixture('Location', 'dynamic');
62
-        $object->write();
63
-        $this->logInWithPermission('ADMIN');
64
-        $this->assertTrue($object->canView());
65
-        $this->logOut();
66
-        $nullMember = Member::create();
67
-        $nullMember->write();
68
-        $this->assertTrue($object->canView($nullMember));
69
-        $nullMember->delete();
70
-    }
59
+	public function testCanView()
60
+	{
61
+		$object = $this->objFromFixture('Location', 'dynamic');
62
+		$object->write();
63
+		$this->logInWithPermission('ADMIN');
64
+		$this->assertTrue($object->canView());
65
+		$this->logOut();
66
+		$nullMember = Member::create();
67
+		$nullMember->write();
68
+		$this->assertTrue($object->canView($nullMember));
69
+		$nullMember->delete();
70
+	}
71 71
 
72
-    public function testCanEdit()
73
-    {
74
-        $object = $this->objFromFixture('Location', 'dynamic');
75
-        $object->write();
76
-        $objectID = $object->ID;
77
-        $this->logInWithPermission('Location_EDIT');
78
-        $originalTitle = $object->Title;
79
-        $this->assertEquals($originalTitle, 'Dynamic, Inc.');
80
-        $this->assertTrue($object->canEdit());
81
-        $object->Title = 'Changed Title';
82
-        $object->write();
83
-        $testEdit = Location::get()->byID($objectID);
84
-        $this->assertEquals($testEdit->Title, 'Changed Title');
85
-        $this->logOut();
86
-    }
72
+	public function testCanEdit()
73
+	{
74
+		$object = $this->objFromFixture('Location', 'dynamic');
75
+		$object->write();
76
+		$objectID = $object->ID;
77
+		$this->logInWithPermission('Location_EDIT');
78
+		$originalTitle = $object->Title;
79
+		$this->assertEquals($originalTitle, 'Dynamic, Inc.');
80
+		$this->assertTrue($object->canEdit());
81
+		$object->Title = 'Changed Title';
82
+		$object->write();
83
+		$testEdit = Location::get()->byID($objectID);
84
+		$this->assertEquals($testEdit->Title, 'Changed Title');
85
+		$this->logOut();
86
+	}
87 87
 
88
-    public function testCanDelete()
89
-    {
90
-        $object = $this->objFromFixture('Location', 'dynamic');
91
-        $object->write();
92
-        $this->logInWithPermission('Location_DELETE');
93
-        $this->assertTrue($object->canDelete());
94
-        $checkObject = $object;
95
-        $object->delete();
96
-        $this->assertEquals($checkObject->ID, 0);
97
-    }
88
+	public function testCanDelete()
89
+	{
90
+		$object = $this->objFromFixture('Location', 'dynamic');
91
+		$object->write();
92
+		$this->logInWithPermission('Location_DELETE');
93
+		$this->assertTrue($object->canDelete());
94
+		$checkObject = $object;
95
+		$object->delete();
96
+		$this->assertEquals($checkObject->ID, 0);
97
+	}
98 98
 
99
-    public function testCanCreate()
100
-    {
101
-        $object = singleton('Location');
102
-        $this->logInWithPermission('Location_CREATE');
103
-        $this->assertTrue($object->canCreate());
104
-        $this->logOut();
105
-        $nullMember = Member::create();
106
-        $nullMember->write();
107
-        $this->assertFalse($object->canCreate($nullMember));
108
-        $nullMember->delete();
109
-    }
99
+	public function testCanCreate()
100
+	{
101
+		$object = singleton('Location');
102
+		$this->logInWithPermission('Location_CREATE');
103
+		$this->assertTrue($object->canCreate());
104
+		$this->logOut();
105
+		$nullMember = Member::create();
106
+		$nullMember->write();
107
+		$this->assertFalse($object->canCreate($nullMember));
108
+		$nullMember->delete();
109
+	}
110 110
 
111
-    public function testProvidePermissions()
112
-    {
113
-    }
111
+	public function testProvidePermissions()
112
+	{
113
+	}
114 114
 
115
-    public function testOnBeforeWrite()
116
-    {
117
-    }
115
+	public function testOnBeforeWrite()
116
+	{
117
+	}
118 118
 }
Please login to merge, or discard this patch.
tests/LocatorTest.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -2,63 +2,63 @@
 block discarded – undo
2 2
 
3 3
 class LocatorTest extends Locator_Test
4 4
 {
5
-    public function testGetCMSFields()
6
-    {
7
-        $object = new Locator();
8
-        $fieldset = $object->getCMSFields();
9
-        $this->assertTrue(is_a($fieldset, 'FieldList'));
10
-    }
5
+	public function testGetCMSFields()
6
+	{
7
+		$object = new Locator();
8
+		$fieldset = $object->getCMSFields();
9
+		$this->assertTrue(is_a($fieldset, 'FieldList'));
10
+	}
11 11
 
12
-    public function testGetLocations()
13
-    {
14
-        $object = $this->objFromFixture('Location', 'dynamic');
15
-        $object->write();
12
+	public function testGetLocations()
13
+	{
14
+		$object = $this->objFromFixture('Location', 'dynamic');
15
+		$object->write();
16 16
 
17
-        $object2 = $this->objFromFixture('Location', 'silverstripe');
18
-        $object2->write();
17
+		$object2 = $this->objFromFixture('Location', 'silverstripe');
18
+		$object2->write();
19 19
 
20
-        $object3 = $this->objFromFixture('Location', '3sheeps');
21
-        $object3->write();
20
+		$object3 = $this->objFromFixture('Location', '3sheeps');
21
+		$object3->write();
22 22
 
23
-        $locator = singleton('Locator');
24
-        $count = Location::get()->filter('ShowInLocator', 1)->exclude('Lat', 0)->Count();
23
+		$locator = singleton('Locator');
24
+		$count = Location::get()->filter('ShowInLocator', 1)->exclude('Lat', 0)->Count();
25 25
 
26
-        $this->assertEquals($locator->getLocations()->Count(), $count);
27
-    }
26
+		$this->assertEquals($locator->getLocations()->Count(), $count);
27
+	}
28 28
 
29
-    public function testGetAreLocations()
30
-    {
31
-        $locator = singleton('Locator');
32
-        $this->assertEquals($locator->getLocations(), $locator->getAreLocations());
33
-    }
29
+	public function testGetAreLocations()
30
+	{
31
+		$locator = singleton('Locator');
32
+		$this->assertEquals($locator->getLocations(), $locator->getAreLocations());
33
+	}
34 34
 
35
-    public function testGetAllCategories()
36
-    {
37
-        $locator = singleton('Locator');
35
+	public function testGetAllCategories()
36
+	{
37
+		$locator = singleton('Locator');
38 38
 
39
-        $object = $this->objFromFixture('LocationCategory', 'service');
40
-        $object->write();
39
+		$object = $this->objFromFixture('LocationCategory', 'service');
40
+		$object->write();
41 41
 
42
-        $object2 = $this->objFromFixture('LocationCategory', 'manufacturing');
43
-        $object2->write();
42
+		$object2 = $this->objFromFixture('LocationCategory', 'manufacturing');
43
+		$object2->write();
44 44
 
45
-        $count = LocationCategory::get();
45
+		$count = LocationCategory::get();
46 46
 
47
-        $this->assertEquals($locator->getAllCategories(), $count);
48
-    }
47
+		$this->assertEquals($locator->getAllCategories(), $count);
48
+	}
49 49
 
50
-    public function testInit()
51
-    {
52
-    }
50
+	public function testInit()
51
+	{
52
+	}
53 53
 
54
-    public function testXml()
55
-    {
56
-    }
54
+	public function testXml()
55
+	{
56
+	}
57 57
 
58
-    public function testLocationSearch()
59
-    {
60
-        $object = Locator_Controller::create();
61
-        $form = $object->LocationSearch();
62
-        $this->assertTrue(is_a($form, 'Form'));
63
-    }
58
+	public function testLocationSearch()
59
+	{
60
+		$object = Locator_Controller::create();
61
+		$form = $object->LocationSearch();
62
+		$this->assertTrue(is_a($form, 'Form'));
63
+	}
64 64
 }
Please login to merge, or discard this patch.