Complex classes like GoogleMapLocationsDOD_Controller often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use GoogleMapLocationsDOD_Controller, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | class GoogleMapLocationsDOD_Controller extends Extension |
||
| 11 | { |
||
| 12 | |||
| 13 | |||
| 14 | |||
| 15 | |||
| 16 | |||
| 17 | ##################### |
||
| 18 | # INITS |
||
| 19 | ##################### |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @inherited |
||
| 23 | */ |
||
| 24 | private static $allowed_actions = array( |
||
|
|
|||
| 25 | "AddressFinderForm", |
||
| 26 | "doAddressFinderForm", |
||
| 27 | "SearchByAddressForm", |
||
| 28 | "loadmap" |
||
| 29 | ); |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var GoogleMap |
||
| 33 | */ |
||
| 34 | protected $googleMap = null; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var String |
||
| 38 | */ |
||
| 39 | protected $googleMapAddress = ""; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * look for address |
||
| 43 | * |
||
| 44 | */ |
||
| 45 | public function onAfterInit() |
||
| 54 | |||
| 55 | |||
| 56 | /** |
||
| 57 | * initialise GoogleMap |
||
| 58 | * @return GoogleMap |
||
| 59 | */ |
||
| 60 | public function MyGoogleMap() |
||
| 67 | |||
| 68 | |||
| 69 | |||
| 70 | |||
| 71 | |||
| 72 | |||
| 73 | |||
| 74 | ##################### |
||
| 75 | # ACTIONS |
||
| 76 | ##################### |
||
| 77 | |||
| 78 | |||
| 79 | /** |
||
| 80 | * provides a link to any map you like. |
||
| 81 | * e.g. mysite.com/mypage/mysub-page/loadmap/optionsHereURLEncoded/ |
||
| 82 | * optionsHereURLEncoded are basically the link to the map. |
||
| 83 | * you can use this to link through to a page and provide a specific map |
||
| 84 | * |
||
| 85 | * @param HTTPRequest |
||
| 86 | */ |
||
| 87 | public function loadmap($request) |
||
| 95 | |||
| 96 | /** |
||
| 97 | * returns encoded link for the loadmap function |
||
| 98 | * |
||
| 99 | * @param SiteTree $page |
||
| 100 | * @param String $action |
||
| 101 | * @param String $title |
||
| 102 | * @param Int $lng |
||
| 103 | * @param Int $lat |
||
| 104 | * @param String $filterCode |
||
| 105 | * |
||
| 106 | * @return String |
||
| 107 | */ |
||
| 108 | public function LoadmapLink($page = null, $action = "", $title = "", $lng = 0, $lat = 0, $filterCode = "") |
||
| 117 | |||
| 118 | |||
| 119 | |||
| 120 | |||
| 121 | |||
| 122 | |||
| 123 | |||
| 124 | ##################### |
||
| 125 | # TEMPLATE METHODS |
||
| 126 | ##################### |
||
| 127 | |||
| 128 | |||
| 129 | /** |
||
| 130 | * @return GoogleMap |
||
| 131 | */ |
||
| 132 | public function GoogleMapController() |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @return Boolean |
||
| 140 | */ |
||
| 141 | public function HasGoogleMap() |
||
| 149 | |||
| 150 | |||
| 151 | /** |
||
| 152 | * @param array (optional) $classNamesSearchedFor e.g. StockistPage |
||
| 153 | * |
||
| 154 | * @return Form |
||
| 155 | */ |
||
| 156 | public function AddressFinderForm($classNamesSearchedFor = array()) |
||
| 160 | |||
| 161 | public function doAddressFinderForm($data, $form) |
||
| 165 | |||
| 166 | |||
| 167 | /** |
||
| 168 | * @param array (optional) $classNamesSearchedFor e.g. StockistPage |
||
| 169 | * |
||
| 170 | * @return Form |
||
| 171 | */ |
||
| 172 | public function SearchByAddressForm($classNamesSearchedFor = array()) |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @param array (optional) $classNamesSearchedFor e.g. StockistPage |
||
| 184 | * |
||
| 185 | * @return Form |
||
| 186 | */ |
||
| 187 | public function AddAddressFinder() |
||
| 191 | |||
| 192 | |||
| 193 | |||
| 194 | |||
| 195 | ##################### |
||
| 196 | # CREATE MAPS |
||
| 197 | ##################### |
||
| 198 | |||
| 199 | |||
| 200 | /** |
||
| 201 | * add a layer to a Google Map |
||
| 202 | * |
||
| 203 | * @param String $action - see GoogleMapDataResponse::allowed_actions to get a list of actions |
||
| 204 | * @param String $title |
||
| 205 | * @param float $lng - default LATITUDE |
||
| 206 | * @param float $lat - default LONGITUDE |
||
| 207 | * @param String $filterCode - can be a SiteTree class name, e.g. "ProductPage" |
||
| 208 | * filter depends on the type of action |
||
| 209 | * |
||
| 210 | */ |
||
| 211 | public function addMap($action = "", $title = "", $lng = 0, $lat = 0, $filterCode = "") |
||
| 226 | |||
| 227 | /** |
||
| 228 | * add a layer to a Google Map |
||
| 229 | * |
||
| 230 | * @param String $action - see GoogleMapDataResponse::allowed_actions to get a list of actions |
||
| 231 | * @param String $title |
||
| 232 | * @param String $filterCode - can be a SiteTree class name, e.g. "ProductPage" |
||
| 233 | * filter depends on the type of action |
||
| 234 | * |
||
| 235 | */ |
||
| 236 | public function addMapUsingRawLink($link = "", $title = "", $filterCode = "") |
||
| 243 | |||
| 244 | /** |
||
| 245 | * add an additional layer to an existing map |
||
| 246 | * |
||
| 247 | * @param String $action |
||
| 248 | * @param String $title |
||
| 249 | * @param Int $lng |
||
| 250 | * @param Int $lat |
||
| 251 | * @param String $filter |
||
| 252 | */ |
||
| 253 | public function addExtraLayer($action = "", $title = "", $lng = 0, $lat = 0, $filter = "") |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Make up your own link and add this as a layer |
||
| 261 | * |
||
| 262 | * @param String $title |
||
| 263 | * @param String $link |
||
| 264 | */ |
||
| 265 | public function addExtraLayerUsingRawLink($title, $link) |
||
| 269 | |||
| 270 | |||
| 271 | /** |
||
| 272 | * add an address to the map |
||
| 273 | * |
||
| 274 | * @param String $address |
||
| 275 | * @param Boolean $addShowAroundAdress |
||
| 276 | * @param String $filter - usually a SiteTree ClassName (e.g. ProductPage) |
||
| 277 | * @param array $params - params for the Google Server |
||
| 278 | */ |
||
| 279 | public function addAddress($address, $addShowAroundAdress = false, $filter = "", $params = []) |
||
| 294 | |||
| 295 | |||
| 296 | |||
| 297 | /** |
||
| 298 | * @param DataList $pagesOrGoogleMapLocationsObjects |
||
| 299 | * @param Boolean $retainOldSessionData |
||
| 300 | * @param string $title |
||
| 301 | * @param string $filterCode |
||
| 302 | * |
||
| 303 | * @param String $title |
||
| 304 | */ |
||
| 305 | public function addCustomMap($pagesOrGoogleMapLocationsObjects, $retainOldSessionData = false, $title = '', $filterCode = "") |
||
| 337 | |||
| 338 | |||
| 339 | |||
| 340 | |||
| 341 | |||
| 342 | |||
| 343 | |||
| 344 | |||
| 345 | |||
| 346 | ##################### |
||
| 347 | # MAP SETTINGS |
||
| 348 | ##################### |
||
| 349 | |||
| 350 | |||
| 351 | /** |
||
| 352 | * @param String $updateServerUrlAddPoint |
||
| 353 | */ |
||
| 354 | public function addUpdateServerUrlAddressSearchPoint($updateServerUrlAddPoint = "/googlemap/showaroundmexml/") |
||
| 359 | |||
| 360 | /** |
||
| 361 | * @param String $updateServerUrlDragend |
||
| 362 | */ |
||
| 363 | public function addUpdateServerUrlDragend($updateServerUrlDragend = "googlemap/updatemexml/") |
||
| 368 | |||
| 369 | /** |
||
| 370 | * make the map editable |
||
| 371 | */ |
||
| 372 | public function addAllowAddingAndDeletingPoints() |
||
| 376 | |||
| 377 | /** |
||
| 378 | * removes user settings for map |
||
| 379 | * a custom map is a bunch of points that are customised via a session |
||
| 380 | * |
||
| 381 | * @param string $filterCode |
||
| 382 | */ |
||
| 383 | public function clearCustomMaps($filterCode = "") |
||
| 387 | |||
| 388 | |||
| 389 | /** |
||
| 390 | * @param String $action |
||
| 391 | * @param String $title |
||
| 392 | * @param Int $lng |
||
| 393 | * @param Int $lat |
||
| 394 | * @param String $filter |
||
| 395 | * |
||
| 396 | * @return String |
||
| 397 | */ |
||
| 398 | protected function getLinkForData($pageID = 0, $action = "", $title = "", $lng = 0, $lat = 0, $filterCode = "") |
||
| 413 | } |
||
| 414 |