@@ -2,87 +2,87 @@ |
||
| 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 testLocations() |
|
| 13 | - { |
|
| 14 | - $filter = array('ShowInLocator' => 1); |
|
| 15 | - $filterAny = array('Suburb' => 'Sheboygan'); |
|
| 16 | - $exclude = array('Suburb' => 'Milwaukee'); |
|
| 17 | - $locations = Locator::locations($filter, $filterAny, $exclude); |
|
| 18 | - $locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude); |
|
| 19 | - $this->assertEquals($locations->Count(), $locations2->Count()); |
|
| 20 | - } |
|
| 12 | + public function testLocations() |
|
| 13 | + { |
|
| 14 | + $filter = array('ShowInLocator' => 1); |
|
| 15 | + $filterAny = array('Suburb' => 'Sheboygan'); |
|
| 16 | + $exclude = array('Suburb' => 'Milwaukee'); |
|
| 17 | + $locations = Locator::locations($filter, $filterAny, $exclude); |
|
| 18 | + $locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude); |
|
| 19 | + $this->assertEquals($locations->Count(), $locations2->Count()); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - public function testGetAllCategories() |
|
| 23 | - { |
|
| 24 | - $locator = singleton('Locator'); |
|
| 25 | - $count = LocationCategory::get(); |
|
| 26 | - $this->assertEquals($locator->getAllCategories(), $count); |
|
| 27 | - } |
|
| 22 | + public function testGetAllCategories() |
|
| 23 | + { |
|
| 24 | + $locator = singleton('Locator'); |
|
| 25 | + $count = LocationCategory::get(); |
|
| 26 | + $this->assertEquals($locator->getAllCategories(), $count); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - public function testGetPageCategories() |
|
| 30 | - { |
|
| 31 | - $locator = Locator::create(); |
|
| 32 | - $this->assertFalse($locator->getPageCategories()); |
|
| 29 | + public function testGetPageCategories() |
|
| 30 | + { |
|
| 31 | + $locator = Locator::create(); |
|
| 32 | + $this->assertFalse($locator->getPageCategories()); |
|
| 33 | 33 | |
| 34 | - $this->assertFalse($locator->getPageCategories(500)); |
|
| 34 | + $this->assertFalse($locator->getPageCategories(500)); |
|
| 35 | 35 | |
| 36 | - $locator->write(); |
|
| 37 | - $category = $this->objFromFixture('LocationCategory', 'service'); |
|
| 38 | - $locator->Categories()->add($category); |
|
| 39 | - $this->assertEquals($locator->getPageCategories($locator->ID), $locator->Categories()); |
|
| 40 | - } |
|
| 36 | + $locator->write(); |
|
| 37 | + $category = $this->objFromFixture('LocationCategory', 'service'); |
|
| 38 | + $locator->Categories()->add($category); |
|
| 39 | + $this->assertEquals($locator->getPageCategories($locator->ID), $locator->Categories()); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - public function testInit() |
|
| 43 | - { |
|
| 44 | - } |
|
| 42 | + public function testInit() |
|
| 43 | + { |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - public function testIndex() |
|
| 47 | - { |
|
| 48 | - $locator = $this->objFromFixture('Locator', 'locator1'); |
|
| 49 | - $controller = Locator_Controller::create($locator); |
|
| 50 | - $this->assertInstanceOf('ViewableData', $controller->index($controller->request)); |
|
| 51 | - } |
|
| 46 | + public function testIndex() |
|
| 47 | + { |
|
| 48 | + $locator = $this->objFromFixture('Locator', 'locator1'); |
|
| 49 | + $controller = Locator_Controller::create($locator); |
|
| 50 | + $this->assertInstanceOf('ViewableData', $controller->index($controller->request)); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - public function testXml() |
|
| 54 | - { |
|
| 55 | - $locator = $this->objFromFixture('Locator', 'locator1'); |
|
| 56 | - $controller = Locator_Controller::create($locator); |
|
| 57 | - $this->assertInstanceOf('HTMLText', $controller->xml($controller->request)); |
|
| 58 | - } |
|
| 53 | + public function testXml() |
|
| 54 | + { |
|
| 55 | + $locator = $this->objFromFixture('Locator', 'locator1'); |
|
| 56 | + $controller = Locator_Controller::create($locator); |
|
| 57 | + $this->assertInstanceOf('HTMLText', $controller->xml($controller->request)); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - public function testItems() |
|
| 61 | - { |
|
| 62 | - $locator = $this->objFromFixture('Locator', 'locator1'); |
|
| 63 | - $controller = Locator_Controller::create($locator); |
|
| 60 | + public function testItems() |
|
| 61 | + { |
|
| 62 | + $locator = $this->objFromFixture('Locator', 'locator1'); |
|
| 63 | + $controller = Locator_Controller::create($locator); |
|
| 64 | 64 | |
| 65 | - $filter = array('ShowInLocator' => 1); |
|
| 65 | + $filter = array('ShowInLocator' => 1); |
|
| 66 | 66 | |
| 67 | - $locations = $controller->Items($controller->request); |
|
| 68 | - $locations2 = Location::get()->filter($filter); |
|
| 69 | - $this->assertEquals($locations->Count(), $locations2->Count()); |
|
| 70 | - } |
|
| 67 | + $locations = $controller->Items($controller->request); |
|
| 68 | + $locations2 = Location::get()->filter($filter); |
|
| 69 | + $this->assertEquals($locations->Count(), $locations2->Count()); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - public function testLocationSearch() |
|
| 73 | - { |
|
| 74 | - $locator = $this->objFromFixture('Locator', 'locator1'); |
|
| 75 | - $object = Locator_Controller::create($locator); |
|
| 76 | - $form = $object->LocationSearch(); |
|
| 77 | - $this->assertTrue(is_a($form, 'Form')); |
|
| 72 | + public function testLocationSearch() |
|
| 73 | + { |
|
| 74 | + $locator = $this->objFromFixture('Locator', 'locator1'); |
|
| 75 | + $object = Locator_Controller::create($locator); |
|
| 76 | + $form = $object->LocationSearch(); |
|
| 77 | + $this->assertTrue(is_a($form, 'Form')); |
|
| 78 | 78 | |
| 79 | - $category = $this->objFromFixture('LocationCategory', 'service'); |
|
| 80 | - $category2 = $this->objFromFixture('LocationCategory', 'manufacturing'); |
|
| 81 | - $locator->Categories()->add($category); |
|
| 82 | - $locator->Categories()->add($category2); |
|
| 79 | + $category = $this->objFromFixture('LocationCategory', 'service'); |
|
| 80 | + $category2 = $this->objFromFixture('LocationCategory', 'manufacturing'); |
|
| 81 | + $locator->Categories()->add($category); |
|
| 82 | + $locator->Categories()->add($category2); |
|
| 83 | 83 | |
| 84 | - $form = $object->LocationSearch(); |
|
| 85 | - $fields = $form->Fields(); |
|
| 86 | - $this->assertNotNull($fields->fieldByName('CategoryID')); |
|
| 87 | - } |
|
| 84 | + $form = $object->LocationSearch(); |
|
| 85 | + $fields = $form->Fields(); |
|
| 86 | + $this->assertNotNull($fields->fieldByName('CategoryID')); |
|
| 87 | + } |
|
| 88 | 88 | } |
@@ -2,173 +2,173 @@ |
||
| 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['Category.ID'] = 'Category'; |
|
| 83 | - $labels['Email'] = 'Email'; |
|
| 84 | - $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
| 85 | - $labels['Coords'] = 'Coords'; |
|
| 86 | - |
|
| 87 | - return $labels; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - public function getCMSFields() |
|
| 91 | - { |
|
| 92 | - $fields = FieldList::create( |
|
| 93 | - new TabSet( |
|
| 94 | - $name = 'Root', |
|
| 95 | - new Tab( |
|
| 96 | - $title = 'Main', |
|
| 97 | - HeaderField::create('ContactHD', 'Contact Information'), |
|
| 98 | - TextField::create('Title', 'Name'), |
|
| 99 | - TextField::create('Phone'), |
|
| 100 | - EmailField::create('Email', 'Email'), |
|
| 101 | - TextField::create('Website') |
|
| 102 | - ->setAttribute('placeholder', 'http://'), |
|
| 103 | - DropDownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title')) |
|
| 104 | - ->setEmptyString('-- select --'), |
|
| 105 | - CheckboxField::create('ShowInLocator', 'Show in results') |
|
| 106 | - ->setDescription('Location will be included in results list'), |
|
| 107 | - CheckboxField::create('Featured') |
|
| 108 | - ->setDescription('Location will show at/near the top of the results list') |
|
| 109 | - ) |
|
| 110 | - ) |
|
| 111 | - ); |
|
| 112 | - |
|
| 113 | - // allow to be extended via DataExtension |
|
| 114 | - $this->extend('updateCMSFields', $fields); |
|
| 115 | - |
|
| 116 | - // override Suburb field name |
|
| 117 | - $fields->dataFieldByName('Suburb')->setTitle('City'); |
|
| 118 | - |
|
| 119 | - return $fields; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - public function validate() |
|
| 123 | - { |
|
| 124 | - $result = parent::validate(); |
|
| 125 | - |
|
| 126 | - return $result; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - public function EmailAddress() |
|
| 130 | - { |
|
| 131 | - Deprecation::notice('3.0', 'Use "$Email" instead.'); |
|
| 132 | - if ($this->Email) { |
|
| 133 | - return $this->Email; |
|
| 134 | - } elseif ($this->EmailAddress) { |
|
| 135 | - return $this->EmailAddress; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return false; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @param Member $member |
|
| 143 | - * |
|
| 144 | - * @return bool |
|
| 145 | - */ |
|
| 146 | - public function canView($member = false) |
|
| 147 | - { |
|
| 148 | - return true; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - public function canEdit($member = false) |
|
| 152 | - { |
|
| 153 | - return Permission::check('Location_EDIT'); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - public function canDelete($member = false) |
|
| 157 | - { |
|
| 158 | - return Permission::check('Location_DELETE'); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - public function canCreate($member = false) |
|
| 162 | - { |
|
| 163 | - return Permission::check('Location_CREATE'); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - public function providePermissions() |
|
| 167 | - { |
|
| 168 | - return array( |
|
| 169 | - 'Location_EDIT' => 'Edit a Location', |
|
| 170 | - 'Location_DELETE' => 'Delete a Location', |
|
| 171 | - 'Location_CREATE' => 'Create a Location', |
|
| 172 | - ); |
|
| 173 | - } |
|
| 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['Category.ID'] = 'Category'; |
|
| 83 | + $labels['Email'] = 'Email'; |
|
| 84 | + $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
| 85 | + $labels['Coords'] = 'Coords'; |
|
| 86 | + |
|
| 87 | + return $labels; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + public function getCMSFields() |
|
| 91 | + { |
|
| 92 | + $fields = FieldList::create( |
|
| 93 | + new TabSet( |
|
| 94 | + $name = 'Root', |
|
| 95 | + new Tab( |
|
| 96 | + $title = 'Main', |
|
| 97 | + HeaderField::create('ContactHD', 'Contact Information'), |
|
| 98 | + TextField::create('Title', 'Name'), |
|
| 99 | + TextField::create('Phone'), |
|
| 100 | + EmailField::create('Email', 'Email'), |
|
| 101 | + TextField::create('Website') |
|
| 102 | + ->setAttribute('placeholder', 'http://'), |
|
| 103 | + DropDownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title')) |
|
| 104 | + ->setEmptyString('-- select --'), |
|
| 105 | + CheckboxField::create('ShowInLocator', 'Show in results') |
|
| 106 | + ->setDescription('Location will be included in results list'), |
|
| 107 | + CheckboxField::create('Featured') |
|
| 108 | + ->setDescription('Location will show at/near the top of the results list') |
|
| 109 | + ) |
|
| 110 | + ) |
|
| 111 | + ); |
|
| 112 | + |
|
| 113 | + // allow to be extended via DataExtension |
|
| 114 | + $this->extend('updateCMSFields', $fields); |
|
| 115 | + |
|
| 116 | + // override Suburb field name |
|
| 117 | + $fields->dataFieldByName('Suburb')->setTitle('City'); |
|
| 118 | + |
|
| 119 | + return $fields; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + public function validate() |
|
| 123 | + { |
|
| 124 | + $result = parent::validate(); |
|
| 125 | + |
|
| 126 | + return $result; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + public function EmailAddress() |
|
| 130 | + { |
|
| 131 | + Deprecation::notice('3.0', 'Use "$Email" instead.'); |
|
| 132 | + if ($this->Email) { |
|
| 133 | + return $this->Email; |
|
| 134 | + } elseif ($this->EmailAddress) { |
|
| 135 | + return $this->EmailAddress; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return false; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @param Member $member |
|
| 143 | + * |
|
| 144 | + * @return bool |
|
| 145 | + */ |
|
| 146 | + public function canView($member = false) |
|
| 147 | + { |
|
| 148 | + return true; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + public function canEdit($member = false) |
|
| 152 | + { |
|
| 153 | + return Permission::check('Location_EDIT'); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + public function canDelete($member = false) |
|
| 157 | + { |
|
| 158 | + return Permission::check('Location_DELETE'); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + public function canCreate($member = false) |
|
| 162 | + { |
|
| 163 | + return Permission::check('Location_CREATE'); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + public function providePermissions() |
|
| 167 | + { |
|
| 168 | + return array( |
|
| 169 | + 'Location_EDIT' => 'Edit a Location', |
|
| 170 | + 'Location_DELETE' => 'Delete a Location', |
|
| 171 | + 'Location_CREATE' => 'Create a Location', |
|
| 172 | + ); |
|
| 173 | + } |
|
| 174 | 174 | } |
@@ -2,121 +2,121 @@ |
||
| 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 | - 'Category.ID' => 'Category', |
|
| 39 | - 'Featured.NiceAsBoolean' => 'Featured', |
|
| 40 | - 'Coords' => 'Coords', |
|
| 41 | - ); |
|
| 42 | - $this->assertEquals($expected, $labels); |
|
| 43 | - } |
|
| 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 | + 'Category.ID' => 'Category', |
|
| 39 | + 'Featured.NiceAsBoolean' => 'Featured', |
|
| 40 | + 'Coords' => 'Coords', |
|
| 41 | + ); |
|
| 42 | + $this->assertEquals($expected, $labels); |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - public function testGetCMSFields() |
|
| 46 | - { |
|
| 47 | - $object = new Location(); |
|
| 48 | - $fieldset = $object->getCMSFields(); |
|
| 49 | - $this->assertTrue(is_a($fieldset, 'FieldList')); |
|
| 50 | - } |
|
| 45 | + public function testGetCMSFields() |
|
| 46 | + { |
|
| 47 | + $object = new Location(); |
|
| 48 | + $fieldset = $object->getCMSFields(); |
|
| 49 | + $this->assertTrue(is_a($fieldset, 'FieldList')); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - public function testValidate() |
|
| 53 | - { |
|
| 54 | - } |
|
| 52 | + public function testValidate() |
|
| 53 | + { |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - public function testEmailAddress() |
|
| 57 | - { |
|
| 58 | - } |
|
| 56 | + public function testEmailAddress() |
|
| 57 | + { |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - public function testCanView() |
|
| 61 | - { |
|
| 62 | - $object = $this->objFromFixture('Location', 'dynamic'); |
|
| 63 | - $object->write(); |
|
| 64 | - $this->logInWithPermission('ADMIN'); |
|
| 65 | - $this->assertTrue($object->canView()); |
|
| 66 | - $this->logOut(); |
|
| 67 | - $nullMember = Member::create(); |
|
| 68 | - $nullMember->write(); |
|
| 69 | - $this->assertTrue($object->canView($nullMember)); |
|
| 70 | - $nullMember->delete(); |
|
| 71 | - } |
|
| 60 | + public function testCanView() |
|
| 61 | + { |
|
| 62 | + $object = $this->objFromFixture('Location', 'dynamic'); |
|
| 63 | + $object->write(); |
|
| 64 | + $this->logInWithPermission('ADMIN'); |
|
| 65 | + $this->assertTrue($object->canView()); |
|
| 66 | + $this->logOut(); |
|
| 67 | + $nullMember = Member::create(); |
|
| 68 | + $nullMember->write(); |
|
| 69 | + $this->assertTrue($object->canView($nullMember)); |
|
| 70 | + $nullMember->delete(); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - public function testCanEdit() |
|
| 74 | - { |
|
| 75 | - $object = $this->objFromFixture('Location', 'dynamic'); |
|
| 76 | - $object->write(); |
|
| 77 | - $objectID = $object->ID; |
|
| 78 | - $this->logInWithPermission('Location_EDIT'); |
|
| 79 | - $originalTitle = $object->Title; |
|
| 80 | - $this->assertEquals($originalTitle, 'Dynamic, Inc.'); |
|
| 81 | - $this->assertTrue($object->canEdit()); |
|
| 82 | - $object->Title = 'Changed Title'; |
|
| 83 | - $object->write(); |
|
| 84 | - $testEdit = Location::get()->byID($objectID); |
|
| 85 | - $this->assertEquals($testEdit->Title, 'Changed Title'); |
|
| 86 | - $this->logOut(); |
|
| 87 | - } |
|
| 73 | + public function testCanEdit() |
|
| 74 | + { |
|
| 75 | + $object = $this->objFromFixture('Location', 'dynamic'); |
|
| 76 | + $object->write(); |
|
| 77 | + $objectID = $object->ID; |
|
| 78 | + $this->logInWithPermission('Location_EDIT'); |
|
| 79 | + $originalTitle = $object->Title; |
|
| 80 | + $this->assertEquals($originalTitle, 'Dynamic, Inc.'); |
|
| 81 | + $this->assertTrue($object->canEdit()); |
|
| 82 | + $object->Title = 'Changed Title'; |
|
| 83 | + $object->write(); |
|
| 84 | + $testEdit = Location::get()->byID($objectID); |
|
| 85 | + $this->assertEquals($testEdit->Title, 'Changed Title'); |
|
| 86 | + $this->logOut(); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - public function testCanDelete() |
|
| 90 | - { |
|
| 91 | - $object = $this->objFromFixture('Location', 'dynamic'); |
|
| 92 | - $object->write(); |
|
| 93 | - $this->logInWithPermission('Location_DELETE'); |
|
| 94 | - $this->assertTrue($object->canDelete()); |
|
| 95 | - $checkObject = $object; |
|
| 96 | - $object->delete(); |
|
| 97 | - $this->assertEquals($checkObject->ID, 0); |
|
| 98 | - } |
|
| 89 | + public function testCanDelete() |
|
| 90 | + { |
|
| 91 | + $object = $this->objFromFixture('Location', 'dynamic'); |
|
| 92 | + $object->write(); |
|
| 93 | + $this->logInWithPermission('Location_DELETE'); |
|
| 94 | + $this->assertTrue($object->canDelete()); |
|
| 95 | + $checkObject = $object; |
|
| 96 | + $object->delete(); |
|
| 97 | + $this->assertEquals($checkObject->ID, 0); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - public function testCanCreate() |
|
| 101 | - { |
|
| 102 | - $object = singleton('Location'); |
|
| 103 | - $this->logInWithPermission('Location_CREATE'); |
|
| 104 | - $this->assertTrue($object->canCreate()); |
|
| 105 | - $this->logOut(); |
|
| 106 | - $nullMember = Member::create(); |
|
| 107 | - $nullMember->write(); |
|
| 108 | - $this->assertFalse($object->canCreate($nullMember)); |
|
| 109 | - $nullMember->delete(); |
|
| 110 | - } |
|
| 100 | + public function testCanCreate() |
|
| 101 | + { |
|
| 102 | + $object = singleton('Location'); |
|
| 103 | + $this->logInWithPermission('Location_CREATE'); |
|
| 104 | + $this->assertTrue($object->canCreate()); |
|
| 105 | + $this->logOut(); |
|
| 106 | + $nullMember = Member::create(); |
|
| 107 | + $nullMember->write(); |
|
| 108 | + $this->assertFalse($object->canCreate($nullMember)); |
|
| 109 | + $nullMember->delete(); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - public function testProvidePermissions() |
|
| 113 | - { |
|
| 114 | - $object = Location::create(); |
|
| 115 | - $expected = array( |
|
| 116 | - 'Location_EDIT' => 'Edit a Location', |
|
| 117 | - 'Location_DELETE' => 'Delete a Location', |
|
| 118 | - 'Location_CREATE' => 'Create a Location', |
|
| 119 | - ); |
|
| 120 | - $this->assertEquals($expected, $object->providePermissions()); |
|
| 121 | - } |
|
| 112 | + public function testProvidePermissions() |
|
| 113 | + { |
|
| 114 | + $object = Location::create(); |
|
| 115 | + $expected = array( |
|
| 116 | + 'Location_EDIT' => 'Edit a Location', |
|
| 117 | + 'Location_DELETE' => 'Delete a Location', |
|
| 118 | + 'Location_CREATE' => 'Create a Location', |
|
| 119 | + ); |
|
| 120 | + $this->assertEquals($expected, $object->providePermissions()); |
|
| 121 | + } |
|
| 122 | 122 | } |
@@ -2,197 +2,197 @@ discard block |
||
| 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 $many_many = array( |
|
| 12 | - 'Categories' => 'LocationCategory', |
|
| 13 | - ); |
|
| 14 | - |
|
| 15 | - private static $defaults = array( |
|
| 16 | - 'AutoGeocode' => true, |
|
| 17 | - ); |
|
| 18 | - |
|
| 19 | - private static $singular_name = 'Locator'; |
|
| 20 | - private static $plural_name = 'Locators'; |
|
| 21 | - private static $description = 'Find locations on a map'; |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @return FieldList |
|
| 25 | - */ |
|
| 26 | - public function getCMSFields() |
|
| 27 | - { |
|
| 28 | - $fields = parent::getCMSFields(); |
|
| 29 | - |
|
| 30 | - // Settings |
|
| 31 | - $fields->addFieldsToTab('Root.Settings', array( |
|
| 32 | - HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
| 33 | - OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')), |
|
| 34 | - CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location') |
|
| 35 | - ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'), |
|
| 36 | - CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'), |
|
| 37 | - )); |
|
| 38 | - |
|
| 39 | - // Filter categories |
|
| 40 | - $config = GridFieldConfig_RelationEditor::create(); |
|
| 41 | - if (class_exists('GridFieldAddExistingSearchButton')) { |
|
| 42 | - $config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
|
| 43 | - $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
| 44 | - } |
|
| 45 | - $categories = $this->Categories(); |
|
| 46 | - $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
| 47 | - ->setDescription('only show locations from the selected category'); |
|
| 48 | - |
|
| 49 | - // Filter |
|
| 50 | - $fields->addFieldsToTab('Root.Filter', array( |
|
| 51 | - HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
| 52 | - $categoriesField, |
|
| 53 | - )); |
|
| 54 | - |
|
| 55 | - $this->extend('updateCMSFields', $fields); |
|
| 56 | - |
|
| 57 | - return $fields; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @param array $filter |
|
| 62 | - * @param array $filterAny |
|
| 63 | - * @param array $exclude |
|
| 64 | - * @param null $filterByCallback |
|
| 65 | - * @return ArrayList |
|
| 66 | - */ |
|
| 67 | - public static function locations( |
|
| 68 | - $filter = array(), |
|
| 69 | - $filterAny = array(), |
|
| 70 | - $exclude = array(), |
|
| 71 | - $filterByCallback = null |
|
| 72 | - ) { |
|
| 73 | - $locationsList = ArrayList::create(); |
|
| 74 | - |
|
| 75 | - // filter by ShowInLocator |
|
| 76 | - $filter['ShowInLocator'] = 1; |
|
| 77 | - |
|
| 78 | - $locations = Location::get()->filter($filter); |
|
| 79 | - |
|
| 80 | - if (!empty($filterAny)) { |
|
| 81 | - $locations = $locations->filterAny($filterAny); |
|
| 82 | - } |
|
| 83 | - if (!empty($exclude)) { |
|
| 84 | - $locations = $locations->exclude($exclude); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - if ($filterByCallback !== null && is_callable($filterByCallback)) { |
|
| 88 | - $locations = $locations->filterByCallback($filterByCallback); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - if ($locations->exists()) { |
|
| 92 | - $locationsList->merge($locations); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return $locationsList; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @return DataList |
|
| 100 | - */ |
|
| 101 | - public static function getAllCategories() |
|
| 102 | - { |
|
| 103 | - return LocationCategory::get(); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @param null $id |
|
| 108 | - * @return bool |
|
| 109 | - */ |
|
| 110 | - public static function getPageCategories($id = null) |
|
| 111 | - { |
|
| 112 | - if ($id) { |
|
| 113 | - if ($locator = self::get()->byID($id)) { |
|
| 114 | - return $locator->Categories(); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return false; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - return false; |
|
| 121 | - } |
|
| 5 | + private static $db = array( |
|
| 6 | + 'AutoGeocode' => 'Boolean', |
|
| 7 | + 'ModalWindow' => 'Boolean', |
|
| 8 | + 'Unit' => 'Enum("m,km","m")', |
|
| 9 | + ); |
|
| 10 | + |
|
| 11 | + private static $many_many = array( |
|
| 12 | + 'Categories' => 'LocationCategory', |
|
| 13 | + ); |
|
| 14 | + |
|
| 15 | + private static $defaults = array( |
|
| 16 | + 'AutoGeocode' => true, |
|
| 17 | + ); |
|
| 18 | + |
|
| 19 | + private static $singular_name = 'Locator'; |
|
| 20 | + private static $plural_name = 'Locators'; |
|
| 21 | + private static $description = 'Find locations on a map'; |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @return FieldList |
|
| 25 | + */ |
|
| 26 | + public function getCMSFields() |
|
| 27 | + { |
|
| 28 | + $fields = parent::getCMSFields(); |
|
| 29 | + |
|
| 30 | + // Settings |
|
| 31 | + $fields->addFieldsToTab('Root.Settings', array( |
|
| 32 | + HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
| 33 | + OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')), |
|
| 34 | + CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location') |
|
| 35 | + ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'), |
|
| 36 | + CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'), |
|
| 37 | + )); |
|
| 38 | + |
|
| 39 | + // Filter categories |
|
| 40 | + $config = GridFieldConfig_RelationEditor::create(); |
|
| 41 | + if (class_exists('GridFieldAddExistingSearchButton')) { |
|
| 42 | + $config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
|
| 43 | + $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
| 44 | + } |
|
| 45 | + $categories = $this->Categories(); |
|
| 46 | + $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
| 47 | + ->setDescription('only show locations from the selected category'); |
|
| 48 | + |
|
| 49 | + // Filter |
|
| 50 | + $fields->addFieldsToTab('Root.Filter', array( |
|
| 51 | + HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
| 52 | + $categoriesField, |
|
| 53 | + )); |
|
| 54 | + |
|
| 55 | + $this->extend('updateCMSFields', $fields); |
|
| 56 | + |
|
| 57 | + return $fields; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @param array $filter |
|
| 62 | + * @param array $filterAny |
|
| 63 | + * @param array $exclude |
|
| 64 | + * @param null $filterByCallback |
|
| 65 | + * @return ArrayList |
|
| 66 | + */ |
|
| 67 | + public static function locations( |
|
| 68 | + $filter = array(), |
|
| 69 | + $filterAny = array(), |
|
| 70 | + $exclude = array(), |
|
| 71 | + $filterByCallback = null |
|
| 72 | + ) { |
|
| 73 | + $locationsList = ArrayList::create(); |
|
| 74 | + |
|
| 75 | + // filter by ShowInLocator |
|
| 76 | + $filter['ShowInLocator'] = 1; |
|
| 77 | + |
|
| 78 | + $locations = Location::get()->filter($filter); |
|
| 79 | + |
|
| 80 | + if (!empty($filterAny)) { |
|
| 81 | + $locations = $locations->filterAny($filterAny); |
|
| 82 | + } |
|
| 83 | + if (!empty($exclude)) { |
|
| 84 | + $locations = $locations->exclude($exclude); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + if ($filterByCallback !== null && is_callable($filterByCallback)) { |
|
| 88 | + $locations = $locations->filterByCallback($filterByCallback); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + if ($locations->exists()) { |
|
| 92 | + $locationsList->merge($locations); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return $locationsList; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @return DataList |
|
| 100 | + */ |
|
| 101 | + public static function getAllCategories() |
|
| 102 | + { |
|
| 103 | + return LocationCategory::get(); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @param null $id |
|
| 108 | + * @return bool |
|
| 109 | + */ |
|
| 110 | + public static function getPageCategories($id = null) |
|
| 111 | + { |
|
| 112 | + if ($id) { |
|
| 113 | + if ($locator = self::get()->byID($id)) { |
|
| 114 | + return $locator->Categories(); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return false; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + return false; |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | 123 | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | class Locator_Controller extends Page_Controller |
| 127 | 127 | { |
| 128 | - /** |
|
| 129 | - * @var array |
|
| 130 | - */ |
|
| 131 | - private static $allowed_actions = array( |
|
| 132 | - 'xml', |
|
| 133 | - ); |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Set Requirements based on input from CMS |
|
| 137 | - */ |
|
| 138 | - public function init() |
|
| 139 | - { |
|
| 140 | - parent::init(); |
|
| 141 | - |
|
| 142 | - $themeDir = SSViewer::get_theme_folder(); |
|
| 143 | - |
|
| 144 | - // google maps api key |
|
| 145 | - $key = Config::inst()->get('GoogleGeocoding', 'google_api_key'); |
|
| 146 | - |
|
| 147 | - $locations = $this->Items($this->request); |
|
| 148 | - |
|
| 149 | - Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
|
| 150 | - if ($locations) { |
|
| 151 | - Requirements::javascript('http://maps.google.com/maps/api/js?key='.$key); |
|
| 152 | - Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
|
| 153 | - Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - Requirements::css('locator/css/map.css'); |
|
| 157 | - |
|
| 158 | - $featured = ($locations->filter(array('Featured' => 1))->count() > 0) ? |
|
| 159 | - 'featuredLocations: true' : |
|
| 160 | - 'featuredLocations: false'; |
|
| 161 | - |
|
| 162 | - // map config based on user input in Settings tab |
|
| 163 | - // AutoGeocode or Full Map |
|
| 164 | - $load = ($this->data()->AutoGeocode) ? |
|
| 165 | - 'autoGeocode: true, fullMapStart: false,' : |
|
| 166 | - 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
| 167 | - |
|
| 168 | - $base = Director::baseFolder(); |
|
| 169 | - $themePath = $base.'/'.$themeDir; |
|
| 170 | - |
|
| 171 | - $listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ? |
|
| 172 | - $themeDir.'/templates/location-list-description.html' : |
|
| 173 | - 'locator/templates/location-list-description.html'; |
|
| 174 | - $infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ? |
|
| 175 | - $themeDir.'/templates/infowindow-description.html' : |
|
| 176 | - 'locator/templates/infowindow-description.html'; |
|
| 177 | - |
|
| 178 | - // in page or modal |
|
| 179 | - $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
|
| 180 | - |
|
| 181 | - $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
|
| 182 | - |
|
| 183 | - // pass GET variables to xml action |
|
| 184 | - $vars = $this->request->getVars(); |
|
| 185 | - unset($vars['url']); |
|
| 186 | - unset($vars['action_index']); |
|
| 187 | - $url = ''; |
|
| 188 | - if (count($vars)) { |
|
| 189 | - $url .= '?'.http_build_query($vars); |
|
| 190 | - } |
|
| 191 | - $link = $this->Link().'xml.xml'.$url; |
|
| 192 | - |
|
| 193 | - // init map |
|
| 194 | - if ($locations) { |
|
| 195 | - Requirements::customScript(" |
|
| 128 | + /** |
|
| 129 | + * @var array |
|
| 130 | + */ |
|
| 131 | + private static $allowed_actions = array( |
|
| 132 | + 'xml', |
|
| 133 | + ); |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Set Requirements based on input from CMS |
|
| 137 | + */ |
|
| 138 | + public function init() |
|
| 139 | + { |
|
| 140 | + parent::init(); |
|
| 141 | + |
|
| 142 | + $themeDir = SSViewer::get_theme_folder(); |
|
| 143 | + |
|
| 144 | + // google maps api key |
|
| 145 | + $key = Config::inst()->get('GoogleGeocoding', 'google_api_key'); |
|
| 146 | + |
|
| 147 | + $locations = $this->Items($this->request); |
|
| 148 | + |
|
| 149 | + Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
|
| 150 | + if ($locations) { |
|
| 151 | + Requirements::javascript('http://maps.google.com/maps/api/js?key='.$key); |
|
| 152 | + Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
|
| 153 | + Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + Requirements::css('locator/css/map.css'); |
|
| 157 | + |
|
| 158 | + $featured = ($locations->filter(array('Featured' => 1))->count() > 0) ? |
|
| 159 | + 'featuredLocations: true' : |
|
| 160 | + 'featuredLocations: false'; |
|
| 161 | + |
|
| 162 | + // map config based on user input in Settings tab |
|
| 163 | + // AutoGeocode or Full Map |
|
| 164 | + $load = ($this->data()->AutoGeocode) ? |
|
| 165 | + 'autoGeocode: true, fullMapStart: false,' : |
|
| 166 | + 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
| 167 | + |
|
| 168 | + $base = Director::baseFolder(); |
|
| 169 | + $themePath = $base.'/'.$themeDir; |
|
| 170 | + |
|
| 171 | + $listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ? |
|
| 172 | + $themeDir.'/templates/location-list-description.html' : |
|
| 173 | + 'locator/templates/location-list-description.html'; |
|
| 174 | + $infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ? |
|
| 175 | + $themeDir.'/templates/infowindow-description.html' : |
|
| 176 | + 'locator/templates/infowindow-description.html'; |
|
| 177 | + |
|
| 178 | + // in page or modal |
|
| 179 | + $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
|
| 180 | + |
|
| 181 | + $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
|
| 182 | + |
|
| 183 | + // pass GET variables to xml action |
|
| 184 | + $vars = $this->request->getVars(); |
|
| 185 | + unset($vars['url']); |
|
| 186 | + unset($vars['action_index']); |
|
| 187 | + $url = ''; |
|
| 188 | + if (count($vars)) { |
|
| 189 | + $url .= '?'.http_build_query($vars); |
|
| 190 | + } |
|
| 191 | + $link = $this->Link().'xml.xml'.$url; |
|
| 192 | + |
|
| 193 | + // init map |
|
| 194 | + if ($locations) { |
|
| 195 | + Requirements::customScript(" |
|
| 196 | 196 | $(function($) { |
| 197 | 197 | $('#map-container').storeLocator({ |
| 198 | 198 | ".$load." |
@@ -213,127 +213,127 @@ discard block |
||
| 213 | 213 | }); |
| 214 | 214 | }); |
| 215 | 215 | '); |
| 216 | - } |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * @param SS_HTTPRequest $request |
|
| 221 | - * |
|
| 222 | - * @return ViewableData_Customised |
|
| 223 | - */ |
|
| 224 | - public function index(SS_HTTPRequest $request) |
|
| 225 | - { |
|
| 226 | - $locations = $this->Items($request); |
|
| 227 | - |
|
| 228 | - return $this->customise(array( |
|
| 229 | - 'Locations' => $locations, |
|
| 230 | - )); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Return a XML feed of all locations marked "show in locator" |
|
| 235 | - * |
|
| 236 | - * @param SS_HTTPRequest $request |
|
| 237 | - * @return HTMLText |
|
| 238 | - */ |
|
| 239 | - public function xml(SS_HTTPRequest $request) |
|
| 240 | - { |
|
| 241 | - $locations = $this->Items($request); |
|
| 242 | - |
|
| 243 | - return $this->customise(array( |
|
| 244 | - 'Locations' => $locations, |
|
| 245 | - ))->renderWith('LocationXML'); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * @param array $searchCriteria |
|
| 250 | - * |
|
| 251 | - * @return ArrayList |
|
| 252 | - */ |
|
| 253 | - public function Items(SS_HTTPRequest $request) |
|
| 254 | - { |
|
| 255 | - $request = ($request) ? $request : $this->request; |
|
| 256 | - |
|
| 257 | - $filter = array(); |
|
| 258 | - $filterAny = array(); |
|
| 259 | - $exclude = array(); |
|
| 260 | - |
|
| 261 | - // only show locations marked as ShowInLocator |
|
| 262 | - $filter['ShowInLocator'] = 1; |
|
| 263 | - |
|
| 264 | - // search across all address related fields |
|
| 265 | - $address = ($request->getVar('Address')) ? $request->getVar('Address') : false; |
|
| 266 | - if ($address && $this->data()->AutoGeocode == 0) { |
|
| 267 | - $filterAny['Suburb:PartialMatch'] = $address; |
|
| 268 | - $filterAny['State:PartialMatch'] = $address; |
|
| 269 | - $filterAny['Postcode:PartialMatch'] = $address; |
|
| 270 | - $filterAny['Country:PartialMatch'] = $address; |
|
| 271 | - } else { |
|
| 272 | - unset($filter['Address']); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - $category = ($request->getVar('CategoryID')) ? $request->getVar('CategoryID') : false; |
|
| 276 | - if ($category) { |
|
| 277 | - $filter['CategoryID:ExactMatch'] = $category; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - $locations = Locator::locations($filter, $filterAny, $exclude); |
|
| 281 | - |
|
| 282 | - return $locations; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * LocationSearch form. |
|
| 287 | - * |
|
| 288 | - * Search form for locations, updates map and results list via AJAX |
|
| 289 | - * |
|
| 290 | - * @return Form |
|
| 291 | - */ |
|
| 292 | - public function LocationSearch() |
|
| 293 | - { |
|
| 294 | - $fields = FieldList::create( |
|
| 295 | - $address = TextField::create('Address', '') |
|
| 296 | - ->setAttribute('placeholder', 'address or zip code') |
|
| 297 | - ); |
|
| 298 | - |
|
| 299 | - $filterCategories = Locator::getPageCategories($this->ID); |
|
| 300 | - $allCategories = Locator::getAllCategories(); |
|
| 301 | - |
|
| 302 | - if ($allCategories->Count() > 0) { |
|
| 303 | - $categories = ArrayList::create(); |
|
| 304 | - if ($filterCategories->Count() > 0) { |
|
| 305 | - if ($filterCategories->Count() != 1) { |
|
| 306 | - $categories = $filterCategories; |
|
| 307 | - } |
|
| 308 | - } else { |
|
| 309 | - $categories = $allCategories; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - if ($categories->count() > 0) { |
|
| 313 | - $fields->push( |
|
| 314 | - DropdownField::create( |
|
| 315 | - 'CategoryID', |
|
| 316 | - '', |
|
| 317 | - $categories->map() |
|
| 318 | - )->setEmptyString('All Categories')); |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - $actions = FieldList::create( |
|
| 323 | - FormAction::create('index', 'Search') |
|
| 324 | - ); |
|
| 325 | - |
|
| 326 | - if (class_exists('BootstrapForm')) { |
|
| 327 | - $form = BootstrapForm::create($this, 'LocationSearch', $fields, $actions); |
|
| 328 | - } else { |
|
| 329 | - $form = Form::create($this, 'LocationSearch', $fields, $actions); |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - return $form |
|
| 333 | - ->setFormMethod('GET') |
|
| 334 | - ->setFormAction($this->Link()) |
|
| 335 | - ->disableSecurityToken() |
|
| 336 | - ->loadDataFrom($this->request->getVars()) |
|
| 337 | - ; |
|
| 338 | - } |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * @param SS_HTTPRequest $request |
|
| 221 | + * |
|
| 222 | + * @return ViewableData_Customised |
|
| 223 | + */ |
|
| 224 | + public function index(SS_HTTPRequest $request) |
|
| 225 | + { |
|
| 226 | + $locations = $this->Items($request); |
|
| 227 | + |
|
| 228 | + return $this->customise(array( |
|
| 229 | + 'Locations' => $locations, |
|
| 230 | + )); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Return a XML feed of all locations marked "show in locator" |
|
| 235 | + * |
|
| 236 | + * @param SS_HTTPRequest $request |
|
| 237 | + * @return HTMLText |
|
| 238 | + */ |
|
| 239 | + public function xml(SS_HTTPRequest $request) |
|
| 240 | + { |
|
| 241 | + $locations = $this->Items($request); |
|
| 242 | + |
|
| 243 | + return $this->customise(array( |
|
| 244 | + 'Locations' => $locations, |
|
| 245 | + ))->renderWith('LocationXML'); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * @param array $searchCriteria |
|
| 250 | + * |
|
| 251 | + * @return ArrayList |
|
| 252 | + */ |
|
| 253 | + public function Items(SS_HTTPRequest $request) |
|
| 254 | + { |
|
| 255 | + $request = ($request) ? $request : $this->request; |
|
| 256 | + |
|
| 257 | + $filter = array(); |
|
| 258 | + $filterAny = array(); |
|
| 259 | + $exclude = array(); |
|
| 260 | + |
|
| 261 | + // only show locations marked as ShowInLocator |
|
| 262 | + $filter['ShowInLocator'] = 1; |
|
| 263 | + |
|
| 264 | + // search across all address related fields |
|
| 265 | + $address = ($request->getVar('Address')) ? $request->getVar('Address') : false; |
|
| 266 | + if ($address && $this->data()->AutoGeocode == 0) { |
|
| 267 | + $filterAny['Suburb:PartialMatch'] = $address; |
|
| 268 | + $filterAny['State:PartialMatch'] = $address; |
|
| 269 | + $filterAny['Postcode:PartialMatch'] = $address; |
|
| 270 | + $filterAny['Country:PartialMatch'] = $address; |
|
| 271 | + } else { |
|
| 272 | + unset($filter['Address']); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + $category = ($request->getVar('CategoryID')) ? $request->getVar('CategoryID') : false; |
|
| 276 | + if ($category) { |
|
| 277 | + $filter['CategoryID:ExactMatch'] = $category; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + $locations = Locator::locations($filter, $filterAny, $exclude); |
|
| 281 | + |
|
| 282 | + return $locations; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * LocationSearch form. |
|
| 287 | + * |
|
| 288 | + * Search form for locations, updates map and results list via AJAX |
|
| 289 | + * |
|
| 290 | + * @return Form |
|
| 291 | + */ |
|
| 292 | + public function LocationSearch() |
|
| 293 | + { |
|
| 294 | + $fields = FieldList::create( |
|
| 295 | + $address = TextField::create('Address', '') |
|
| 296 | + ->setAttribute('placeholder', 'address or zip code') |
|
| 297 | + ); |
|
| 298 | + |
|
| 299 | + $filterCategories = Locator::getPageCategories($this->ID); |
|
| 300 | + $allCategories = Locator::getAllCategories(); |
|
| 301 | + |
|
| 302 | + if ($allCategories->Count() > 0) { |
|
| 303 | + $categories = ArrayList::create(); |
|
| 304 | + if ($filterCategories->Count() > 0) { |
|
| 305 | + if ($filterCategories->Count() != 1) { |
|
| 306 | + $categories = $filterCategories; |
|
| 307 | + } |
|
| 308 | + } else { |
|
| 309 | + $categories = $allCategories; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + if ($categories->count() > 0) { |
|
| 313 | + $fields->push( |
|
| 314 | + DropdownField::create( |
|
| 315 | + 'CategoryID', |
|
| 316 | + '', |
|
| 317 | + $categories->map() |
|
| 318 | + )->setEmptyString('All Categories')); |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + $actions = FieldList::create( |
|
| 323 | + FormAction::create('index', 'Search') |
|
| 324 | + ); |
|
| 325 | + |
|
| 326 | + if (class_exists('BootstrapForm')) { |
|
| 327 | + $form = BootstrapForm::create($this, 'LocationSearch', $fields, $actions); |
|
| 328 | + } else { |
|
| 329 | + $form = Form::create($this, 'LocationSearch', $fields, $actions); |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + return $form |
|
| 333 | + ->setFormMethod('GET') |
|
| 334 | + ->setFormAction($this->Link()) |
|
| 335 | + ->disableSecurityToken() |
|
| 336 | + ->loadDataFrom($this->request->getVars()) |
|
| 337 | + ; |
|
| 338 | + } |
|
| 339 | 339 | } |