Completed
Pull Request — master (#74)
by Jason
02:43
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.
tasks/EmailAddressTask.php 2 patches
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -2,22 +2,22 @@
 block discarded – undo
2 2
 
3 3
 class EmailAddressTask extends BuildTask
4 4
 {
5
-    protected $title = 'Email Address Task'; // title of the script
6
-    protected $description = "Convert depreciated 'Email Address' field to new 'Email' field."; // description of what it does
5
+	protected $title = 'Email Address Task'; // title of the script
6
+	protected $description = "Convert depreciated 'Email Address' field to new 'Email' field."; // description of what it does
7 7
 
8
-    public function run($request)
9
-    {
10
-        Config::inst()->update('DataObject', 'validation_enabled', false);
11
-        $ct = 0;
12
-        $updateEmail = function ($location) use (&$ct) {
13
-            if (!$location->Email && $location->EmailAddress) {
14
-                $location->Email = $location->EmailAddress;
15
-                $location->write();
16
-                ++$ct;
17
-            }
18
-        };
19
-        Location::get()->each($updateEmail);
20
-        Config::inst()->update('DataObject', 'validation_enabled', true);
21
-        echo '<p>'.$ct.' Locations updated</p>';
22
-    }
8
+	public function run($request)
9
+	{
10
+		Config::inst()->update('DataObject', 'validation_enabled', false);
11
+		$ct = 0;
12
+		$updateEmail = function ($location) use (&$ct) {
13
+			if (!$location->Email && $location->EmailAddress) {
14
+				$location->Email = $location->EmailAddress;
15
+				$location->write();
16
+				++$ct;
17
+			}
18
+		};
19
+		Location::get()->each($updateEmail);
20
+		Config::inst()->update('DataObject', 'validation_enabled', true);
21
+		echo '<p>'.$ct.' Locations updated</p>';
22
+	}
23 23
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
     {
10 10
         Config::inst()->update('DataObject', 'validation_enabled', false);
11 11
         $ct = 0;
12
-        $updateEmail = function ($location) use (&$ct) {
12
+        $updateEmail = function($location) use (&$ct) {
13 13
             if (!$location->Email && $location->EmailAddress) {
14 14
                 $location->Email = $location->EmailAddress;
15 15
                 $location->write();
@@ -18,6 +18,6 @@  discard block
 block discarded – undo
18 18
         };
19 19
         Location::get()->each($updateEmail);
20 20
         Config::inst()->update('DataObject', 'validation_enabled', true);
21
-        echo '<p>'.$ct.' Locations updated</p>';
21
+        echo '<p>' . $ct . ' Locations updated</p>';
22 22
     }
23 23
 }
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
@@ -3,17 +3,17 @@
 block discarded – undo
3 3
 class LocationCategory extends DataObject
4 4
 {
5 5
 
6
-    private static $db = array(
7
-        'Name' => 'Varchar(100)'
8
-    );
6
+	private static $db = array(
7
+		'Name' => 'Varchar(100)'
8
+	);
9 9
 
10
-    private static $has_many = array(
11
-        'Locations' => 'Location'
12
-    );
10
+	private static $has_many = array(
11
+		'Locations' => 'Location'
12
+	);
13 13
 
14
-    private static $singular_name = "Category";
15
-    Private static $plural_name = "Categories";
14
+	private static $singular_name = "Category";
15
+	Private static $plural_name = "Categories";
16 16
 
17
-    private static $default_sort = 'Name';
17
+	private static $default_sort = 'Name';
18 18
 
19 19
 }
20 20
\ No newline at end of file
Please login to merge, or discard this patch.