@@ -23,7 +23,7 @@ |
||
| 23 | 23 | public function testGetCoords() |
| 24 | 24 | { |
| 25 | 25 | $location = $this->objFromFixture(Location::class, 'dynamic'); |
| 26 | - $coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false'; |
|
| 26 | + $coords = ((int) $location->Lat != 0 && (int) $location->Lng != 0) ? 'true' : 'false'; |
|
| 27 | 27 | $this->assertEquals($coords, $location->getCoords()); |
| 28 | 28 | } |
| 29 | 29 | |
@@ -14,172 +14,172 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class LocationTest extends SapphireTest |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 20 | - protected static $fixture_file = '../fixtures.yml'; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * |
|
| 24 | - */ |
|
| 25 | - public function testGetCoords() |
|
| 26 | - { |
|
| 27 | - $location = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 28 | - $coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false'; |
|
| 29 | - $this->assertEquals($coords, $location->getCoords()); |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * |
|
| 34 | - */ |
|
| 35 | - public function testFieldLabels() |
|
| 36 | - { |
|
| 37 | - $this->markTestSkipped(); |
|
| 38 | - // Link and File tracking display as "Tracking" in SS 4.2 & 4.3, "Tracking" in 4.4 |
|
| 39 | - $location = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 40 | - $labels = $location->FieldLabels(); |
|
| 41 | - $expected = array( |
|
| 42 | - 'Title' => 'Name', |
|
| 43 | - 'Featured' => 'Featured', |
|
| 44 | - 'Website' => 'Website', |
|
| 45 | - 'Phone' => 'Phone', |
|
| 46 | - 'Email' => 'Email', |
|
| 47 | - 'Fax' => 'Fax', |
|
| 48 | - 'Address' => 'Address', |
|
| 49 | - 'City' => 'City', |
|
| 50 | - 'State' => 'State', |
|
| 51 | - 'PostalCode' => 'Postal Code', |
|
| 52 | - 'Country' => 'Country', |
|
| 53 | - 'Lat' => 'Lat', |
|
| 54 | - 'Lng' => 'Lng', |
|
| 55 | - 'Categories' => 'Categories', |
|
| 56 | - 'Category.Name' => 'Category', |
|
| 57 | - 'Category.ID' => 'Category', |
|
| 58 | - 'Featured.NiceAsBoolean' => 'Featured', |
|
| 59 | - 'Import_ID' => 'Import_ID', |
|
| 60 | - 'Version' => 'Version', |
|
| 61 | - 'Versions' => 'Versions', |
|
| 62 | - 'Address2' => 'Address2', |
|
| 63 | - 'LinkTracking' => 'Link tracking', |
|
| 64 | - 'FileTracking' => 'File tracking', |
|
| 65 | - ); |
|
| 66 | - $this->assertEquals($expected, $labels); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * |
|
| 71 | - */ |
|
| 72 | - public function testGetCMSFields() |
|
| 73 | - { |
|
| 74 | - $object = new Location(); |
|
| 75 | - $fieldset = $object->getCMSFields(); |
|
| 76 | - $this->assertinstanceOf(FieldList::class, $fieldset); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * |
|
| 81 | - */ |
|
| 82 | - public function testCanView() |
|
| 83 | - { |
|
| 84 | - $object = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 85 | - $object->write(); |
|
| 86 | - |
|
| 87 | - $this->assertTrue($object->canView()); |
|
| 88 | - |
|
| 89 | - $nullMember = Member::create(); |
|
| 90 | - $nullMember->write(); |
|
| 91 | - |
|
| 92 | - $this->assertTrue($object->canView($nullMember)); |
|
| 93 | - |
|
| 94 | - $nullMember->delete(); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * |
|
| 99 | - */ |
|
| 100 | - public function testCanEdit() |
|
| 101 | - { |
|
| 102 | - $object = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 103 | - $object->write(); |
|
| 104 | - |
|
| 105 | - $objectID = $object->ID; |
|
| 106 | - |
|
| 107 | - //test permissions per permission setting |
|
| 108 | - $create = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 109 | - $edit = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 110 | - $delete = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 111 | - |
|
| 112 | - $originalTitle = $object->Title; |
|
| 113 | - $this->assertEquals($originalTitle, 'Dynamic, Inc.'); |
|
| 114 | - |
|
| 115 | - $this->assertTrue($object->canEdit($edit)); |
|
| 116 | - $this->assertFalse($object->canEdit($create)); |
|
| 117 | - $this->assertFalse($object->canEdit($delete)); |
|
| 118 | - |
|
| 119 | - $object->Title = 'Changed Title'; |
|
| 120 | - $object->write(); |
|
| 121 | - |
|
| 122 | - $testEdit = Location::get()->byID($objectID); |
|
| 123 | - $this->assertEquals($testEdit->Title, 'Changed Title'); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * |
|
| 128 | - */ |
|
| 129 | - public function testCanDelete() |
|
| 130 | - { |
|
| 131 | - $object = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 132 | - $object->write(); |
|
| 133 | - |
|
| 134 | - //test permissions per permission setting |
|
| 135 | - $create = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 136 | - $edit = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 137 | - $delete = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 138 | - |
|
| 139 | - $this->assertTrue($object->canDelete($delete)); |
|
| 140 | - $this->assertFalse($object->canDelete($create)); |
|
| 141 | - $this->assertFalse($object->canDelete($edit)); |
|
| 142 | - |
|
| 143 | - $checkObject = $object; |
|
| 144 | - $object->delete(); |
|
| 145 | - |
|
| 146 | - $this->assertEquals($checkObject->ID, 0); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * |
|
| 151 | - */ |
|
| 152 | - public function testCanCreate() |
|
| 153 | - { |
|
| 154 | - $object = singleton(Location::class); |
|
| 155 | - |
|
| 156 | - //test permissions per permission setting |
|
| 157 | - $create = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 158 | - $edit = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 159 | - $delete = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 160 | - |
|
| 161 | - $this->assertTrue($object->canCreate($create)); |
|
| 162 | - $this->assertFalse($object->canCreate($edit)); |
|
| 163 | - $this->assertFalse($object->canCreate($delete)); |
|
| 164 | - |
|
| 165 | - $nullMember = Member::create(); |
|
| 166 | - $nullMember->write(); |
|
| 167 | - $this->assertFalse($object->canCreate($nullMember)); |
|
| 168 | - |
|
| 169 | - $nullMember->delete(); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * |
|
| 174 | - */ |
|
| 175 | - public function testProvidePermissions() |
|
| 176 | - { |
|
| 177 | - $object = Location::create(); |
|
| 178 | - $expected = array( |
|
| 179 | - 'Location_EDIT' => 'Edit a Location', |
|
| 180 | - 'Location_DELETE' => 'Delete a Location', |
|
| 181 | - 'Location_CREATE' => 'Create a Location', |
|
| 182 | - ); |
|
| 183 | - $this->assertEquals($expected, $object->providePermissions()); |
|
| 184 | - } |
|
| 17 | + /** |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | + protected static $fixture_file = '../fixtures.yml'; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * |
|
| 24 | + */ |
|
| 25 | + public function testGetCoords() |
|
| 26 | + { |
|
| 27 | + $location = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 28 | + $coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false'; |
|
| 29 | + $this->assertEquals($coords, $location->getCoords()); |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * |
|
| 34 | + */ |
|
| 35 | + public function testFieldLabels() |
|
| 36 | + { |
|
| 37 | + $this->markTestSkipped(); |
|
| 38 | + // Link and File tracking display as "Tracking" in SS 4.2 & 4.3, "Tracking" in 4.4 |
|
| 39 | + $location = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 40 | + $labels = $location->FieldLabels(); |
|
| 41 | + $expected = array( |
|
| 42 | + 'Title' => 'Name', |
|
| 43 | + 'Featured' => 'Featured', |
|
| 44 | + 'Website' => 'Website', |
|
| 45 | + 'Phone' => 'Phone', |
|
| 46 | + 'Email' => 'Email', |
|
| 47 | + 'Fax' => 'Fax', |
|
| 48 | + 'Address' => 'Address', |
|
| 49 | + 'City' => 'City', |
|
| 50 | + 'State' => 'State', |
|
| 51 | + 'PostalCode' => 'Postal Code', |
|
| 52 | + 'Country' => 'Country', |
|
| 53 | + 'Lat' => 'Lat', |
|
| 54 | + 'Lng' => 'Lng', |
|
| 55 | + 'Categories' => 'Categories', |
|
| 56 | + 'Category.Name' => 'Category', |
|
| 57 | + 'Category.ID' => 'Category', |
|
| 58 | + 'Featured.NiceAsBoolean' => 'Featured', |
|
| 59 | + 'Import_ID' => 'Import_ID', |
|
| 60 | + 'Version' => 'Version', |
|
| 61 | + 'Versions' => 'Versions', |
|
| 62 | + 'Address2' => 'Address2', |
|
| 63 | + 'LinkTracking' => 'Link tracking', |
|
| 64 | + 'FileTracking' => 'File tracking', |
|
| 65 | + ); |
|
| 66 | + $this->assertEquals($expected, $labels); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * |
|
| 71 | + */ |
|
| 72 | + public function testGetCMSFields() |
|
| 73 | + { |
|
| 74 | + $object = new Location(); |
|
| 75 | + $fieldset = $object->getCMSFields(); |
|
| 76 | + $this->assertinstanceOf(FieldList::class, $fieldset); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * |
|
| 81 | + */ |
|
| 82 | + public function testCanView() |
|
| 83 | + { |
|
| 84 | + $object = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 85 | + $object->write(); |
|
| 86 | + |
|
| 87 | + $this->assertTrue($object->canView()); |
|
| 88 | + |
|
| 89 | + $nullMember = Member::create(); |
|
| 90 | + $nullMember->write(); |
|
| 91 | + |
|
| 92 | + $this->assertTrue($object->canView($nullMember)); |
|
| 93 | + |
|
| 94 | + $nullMember->delete(); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * |
|
| 99 | + */ |
|
| 100 | + public function testCanEdit() |
|
| 101 | + { |
|
| 102 | + $object = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 103 | + $object->write(); |
|
| 104 | + |
|
| 105 | + $objectID = $object->ID; |
|
| 106 | + |
|
| 107 | + //test permissions per permission setting |
|
| 108 | + $create = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 109 | + $edit = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 110 | + $delete = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 111 | + |
|
| 112 | + $originalTitle = $object->Title; |
|
| 113 | + $this->assertEquals($originalTitle, 'Dynamic, Inc.'); |
|
| 114 | + |
|
| 115 | + $this->assertTrue($object->canEdit($edit)); |
|
| 116 | + $this->assertFalse($object->canEdit($create)); |
|
| 117 | + $this->assertFalse($object->canEdit($delete)); |
|
| 118 | + |
|
| 119 | + $object->Title = 'Changed Title'; |
|
| 120 | + $object->write(); |
|
| 121 | + |
|
| 122 | + $testEdit = Location::get()->byID($objectID); |
|
| 123 | + $this->assertEquals($testEdit->Title, 'Changed Title'); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * |
|
| 128 | + */ |
|
| 129 | + public function testCanDelete() |
|
| 130 | + { |
|
| 131 | + $object = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 132 | + $object->write(); |
|
| 133 | + |
|
| 134 | + //test permissions per permission setting |
|
| 135 | + $create = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 136 | + $edit = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 137 | + $delete = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 138 | + |
|
| 139 | + $this->assertTrue($object->canDelete($delete)); |
|
| 140 | + $this->assertFalse($object->canDelete($create)); |
|
| 141 | + $this->assertFalse($object->canDelete($edit)); |
|
| 142 | + |
|
| 143 | + $checkObject = $object; |
|
| 144 | + $object->delete(); |
|
| 145 | + |
|
| 146 | + $this->assertEquals($checkObject->ID, 0); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * |
|
| 151 | + */ |
|
| 152 | + public function testCanCreate() |
|
| 153 | + { |
|
| 154 | + $object = singleton(Location::class); |
|
| 155 | + |
|
| 156 | + //test permissions per permission setting |
|
| 157 | + $create = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 158 | + $edit = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 159 | + $delete = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 160 | + |
|
| 161 | + $this->assertTrue($object->canCreate($create)); |
|
| 162 | + $this->assertFalse($object->canCreate($edit)); |
|
| 163 | + $this->assertFalse($object->canCreate($delete)); |
|
| 164 | + |
|
| 165 | + $nullMember = Member::create(); |
|
| 166 | + $nullMember->write(); |
|
| 167 | + $this->assertFalse($object->canCreate($nullMember)); |
|
| 168 | + |
|
| 169 | + $nullMember->delete(); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * |
|
| 174 | + */ |
|
| 175 | + public function testProvidePermissions() |
|
| 176 | + { |
|
| 177 | + $object = Location::create(); |
|
| 178 | + $expected = array( |
|
| 179 | + 'Location_EDIT' => 'Edit a Location', |
|
| 180 | + 'Location_DELETE' => 'Delete a Location', |
|
| 181 | + 'Location_CREATE' => 'Create a Location', |
|
| 182 | + ); |
|
| 183 | + $this->assertEquals($expected, $object->providePermissions()); |
|
| 184 | + } |
|
| 185 | 185 | } |
@@ -14,69 +14,69 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class LocationCategoryTest extends SapphireTest |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 20 | - protected static $fixture_file = '../fixtures.yml'; |
|
| 17 | + /** |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | + protected static $fixture_file = '../fixtures.yml'; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * |
|
| 24 | - */ |
|
| 25 | - public function testGetCMSFields() |
|
| 26 | - { |
|
| 27 | - $object = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 28 | - $fieldset = $object->getCMSFields(); |
|
| 29 | - $this->assertInstanceOf(FieldList::class, $fieldset); |
|
| 30 | - } |
|
| 22 | + /** |
|
| 23 | + * |
|
| 24 | + */ |
|
| 25 | + public function testGetCMSFields() |
|
| 26 | + { |
|
| 27 | + $object = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 28 | + $fieldset = $object->getCMSFields(); |
|
| 29 | + $this->assertInstanceOf(FieldList::class, $fieldset); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * |
|
| 34 | - */ |
|
| 35 | - public function testCanView() |
|
| 36 | - { |
|
| 37 | - $object = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 38 | - $this->assertTrue($object->canView()); |
|
| 39 | - } |
|
| 32 | + /** |
|
| 33 | + * |
|
| 34 | + */ |
|
| 35 | + public function testCanView() |
|
| 36 | + { |
|
| 37 | + $object = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 38 | + $this->assertTrue($object->canView()); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * |
|
| 43 | - */ |
|
| 44 | - public function testCanEdit() |
|
| 45 | - { |
|
| 46 | - $object = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 41 | + /** |
|
| 42 | + * |
|
| 43 | + */ |
|
| 44 | + public function testCanEdit() |
|
| 45 | + { |
|
| 46 | + $object = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 47 | 47 | |
| 48 | - $admin = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 49 | - $this->assertTrue($object->canEdit($admin)); |
|
| 48 | + $admin = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 49 | + $this->assertTrue($object->canEdit($admin)); |
|
| 50 | 50 | |
| 51 | - $member = $this->objFromFixture(Member::class, 'default'); |
|
| 52 | - $this->assertFalse($object->canEdit($member)); |
|
| 53 | - } |
|
| 51 | + $member = $this->objFromFixture(Member::class, 'default'); |
|
| 52 | + $this->assertFalse($object->canEdit($member)); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * |
|
| 57 | - */ |
|
| 58 | - public function testCanDelete() |
|
| 59 | - { |
|
| 60 | - $object = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 55 | + /** |
|
| 56 | + * |
|
| 57 | + */ |
|
| 58 | + public function testCanDelete() |
|
| 59 | + { |
|
| 60 | + $object = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 61 | 61 | |
| 62 | - $admin = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 63 | - $this->assertTrue($object->canDelete($admin)); |
|
| 62 | + $admin = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 63 | + $this->assertTrue($object->canDelete($admin)); |
|
| 64 | 64 | |
| 65 | - $member = $this->objFromFixture(Member::class, 'default'); |
|
| 66 | - $this->assertFalse($object->canDelete($member)); |
|
| 67 | - } |
|
| 65 | + $member = $this->objFromFixture(Member::class, 'default'); |
|
| 66 | + $this->assertFalse($object->canDelete($member)); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * |
|
| 71 | - */ |
|
| 72 | - public function testCanCreate() |
|
| 73 | - { |
|
| 74 | - $object = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 69 | + /** |
|
| 70 | + * |
|
| 71 | + */ |
|
| 72 | + public function testCanCreate() |
|
| 73 | + { |
|
| 74 | + $object = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 75 | 75 | |
| 76 | - $admin = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 77 | - $this->assertTrue($object->canCreate($admin)); |
|
| 76 | + $admin = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 77 | + $this->assertTrue($object->canCreate($admin)); |
|
| 78 | 78 | |
| 79 | - $member = $this->objFromFixture(Member::class, 'default'); |
|
| 80 | - $this->assertFalse($object->canCreate($member)); |
|
| 81 | - } |
|
| 79 | + $member = $this->objFromFixture(Member::class, 'default'); |
|
| 80 | + $this->assertFalse($object->canCreate($member)); |
|
| 81 | + } |
|
| 82 | 82 | } |
@@ -148,7 +148,7 @@ |
||
| 148 | 148 | */ |
| 149 | 149 | public function getCMSFields() |
| 150 | 150 | { |
| 151 | - $this->beforeUpdateCMSFields(function ($fields) { |
|
| 151 | + $this->beforeUpdateCMSFields(function($fields) { |
|
| 152 | 152 | $fields->removeByName(array( |
| 153 | 153 | 'Import_ID', |
| 154 | 154 | 'LinkTracking', |
@@ -28,242 +28,242 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class Location extends DataObject implements PermissionProvider |
| 30 | 30 | { |
| 31 | - /** |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - private static $singular_name = 'Location'; |
|
| 31 | + /** |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + private static $singular_name = 'Location'; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - private static $plural_name = 'Locations'; |
|
| 36 | + /** |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + private static $plural_name = 'Locations'; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var array |
|
| 43 | - */ |
|
| 44 | - private static $db = array( |
|
| 45 | - 'Title' => 'Varchar(255)', |
|
| 46 | - 'Featured' => 'Boolean', |
|
| 47 | - 'Website' => 'Varchar(255)', |
|
| 48 | - 'Phone' => 'Varchar(40)', |
|
| 49 | - 'Email' => 'Varchar(255)', |
|
| 50 | - 'Fax' => 'Varchar(45)', |
|
| 51 | - 'Import_ID' => 'Int', |
|
| 52 | - ); |
|
| 41 | + /** |
|
| 42 | + * @var array |
|
| 43 | + */ |
|
| 44 | + private static $db = array( |
|
| 45 | + 'Title' => 'Varchar(255)', |
|
| 46 | + 'Featured' => 'Boolean', |
|
| 47 | + 'Website' => 'Varchar(255)', |
|
| 48 | + 'Phone' => 'Varchar(40)', |
|
| 49 | + 'Email' => 'Varchar(255)', |
|
| 50 | + 'Fax' => 'Varchar(45)', |
|
| 51 | + 'Import_ID' => 'Int', |
|
| 52 | + ); |
|
| 53 | 53 | |
| 54 | - private static $many_many = [ |
|
| 55 | - 'Categories' => LocationCategory::class, |
|
| 56 | - ]; |
|
| 54 | + private static $many_many = [ |
|
| 55 | + 'Categories' => LocationCategory::class, |
|
| 56 | + ]; |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @var string |
|
| 60 | - */ |
|
| 61 | - private static $table_name = 'Location'; |
|
| 58 | + /** |
|
| 59 | + * @var string |
|
| 60 | + */ |
|
| 61 | + private static $table_name = 'Location'; |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @var array |
|
| 65 | - */ |
|
| 66 | - private static $casting = array( |
|
| 67 | - 'distance' => 'Decimal(9,3)', |
|
| 68 | - ); |
|
| 63 | + /** |
|
| 64 | + * @var array |
|
| 65 | + */ |
|
| 66 | + private static $casting = array( |
|
| 67 | + 'distance' => 'Decimal(9,3)', |
|
| 68 | + ); |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @var string |
|
| 72 | - */ |
|
| 73 | - private static $default_sort = 'Title'; |
|
| 70 | + /** |
|
| 71 | + * @var string |
|
| 72 | + */ |
|
| 73 | + private static $default_sort = 'Title'; |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * api access via Restful Server module |
|
| 77 | - * |
|
| 78 | - * @var bool |
|
| 79 | - */ |
|
| 80 | - private static $api_access = true; |
|
| 75 | + /** |
|
| 76 | + * api access via Restful Server module |
|
| 77 | + * |
|
| 78 | + * @var bool |
|
| 79 | + */ |
|
| 80 | + private static $api_access = true; |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * search fields for Model Admin |
|
| 84 | - * |
|
| 85 | - * @var array |
|
| 86 | - */ |
|
| 87 | - private static $searchable_fields = array( |
|
| 88 | - 'Title', |
|
| 89 | - 'Address', |
|
| 90 | - 'City', |
|
| 91 | - 'State', |
|
| 92 | - 'PostalCode', |
|
| 93 | - 'Country', |
|
| 94 | - 'Website', |
|
| 95 | - 'Phone', |
|
| 96 | - 'Email', |
|
| 97 | - 'Featured', |
|
| 98 | - ); |
|
| 82 | + /** |
|
| 83 | + * search fields for Model Admin |
|
| 84 | + * |
|
| 85 | + * @var array |
|
| 86 | + */ |
|
| 87 | + private static $searchable_fields = array( |
|
| 88 | + 'Title', |
|
| 89 | + 'Address', |
|
| 90 | + 'City', |
|
| 91 | + 'State', |
|
| 92 | + 'PostalCode', |
|
| 93 | + 'Country', |
|
| 94 | + 'Website', |
|
| 95 | + 'Phone', |
|
| 96 | + 'Email', |
|
| 97 | + 'Featured', |
|
| 98 | + ); |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * columns for grid field |
|
| 102 | - * |
|
| 103 | - * @var array |
|
| 104 | - */ |
|
| 105 | - private static $summary_fields = array( |
|
| 106 | - 'Title', |
|
| 107 | - 'Address', |
|
| 108 | - 'Address2', |
|
| 109 | - 'City', |
|
| 110 | - 'State', |
|
| 111 | - 'PostalCode', |
|
| 112 | - 'CountryCode', |
|
| 113 | - 'Phone' => 'Phone', |
|
| 114 | - 'Fax' => 'Fax', |
|
| 115 | - 'Email' => 'Email', |
|
| 116 | - 'Website' => 'Website', |
|
| 117 | - 'Featured', |
|
| 118 | - 'CategoryList', |
|
| 119 | - 'Lat', |
|
| 120 | - 'Lng', |
|
| 121 | - 'Import_ID', |
|
| 122 | - ); |
|
| 100 | + /** |
|
| 101 | + * columns for grid field |
|
| 102 | + * |
|
| 103 | + * @var array |
|
| 104 | + */ |
|
| 105 | + private static $summary_fields = array( |
|
| 106 | + 'Title', |
|
| 107 | + 'Address', |
|
| 108 | + 'Address2', |
|
| 109 | + 'City', |
|
| 110 | + 'State', |
|
| 111 | + 'PostalCode', |
|
| 112 | + 'CountryCode', |
|
| 113 | + 'Phone' => 'Phone', |
|
| 114 | + 'Fax' => 'Fax', |
|
| 115 | + 'Email' => 'Email', |
|
| 116 | + 'Website' => 'Website', |
|
| 117 | + 'Featured', |
|
| 118 | + 'CategoryList', |
|
| 119 | + 'Lat', |
|
| 120 | + 'Lng', |
|
| 121 | + 'Import_ID', |
|
| 122 | + ); |
|
| 123 | 123 | |
| 124 | - /** |
|
| 125 | - * Coords status for $summary_fields |
|
| 126 | - * |
|
| 127 | - * @return string |
|
| 128 | - */ |
|
| 129 | - public function getCoords() |
|
| 130 | - { |
|
| 131 | - return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false'; |
|
| 132 | - } |
|
| 124 | + /** |
|
| 125 | + * Coords status for $summary_fields |
|
| 126 | + * |
|
| 127 | + * @return string |
|
| 128 | + */ |
|
| 129 | + public function getCoords() |
|
| 130 | + { |
|
| 131 | + return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false'; |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - /** |
|
| 135 | - * @return string |
|
| 136 | - */ |
|
| 137 | - public function getCategoryList() |
|
| 138 | - { |
|
| 139 | - if ($this->Categories()->count()) { |
|
| 140 | - return implode(', ', $this->Categories()->column('Name')); |
|
| 141 | - } |
|
| 134 | + /** |
|
| 135 | + * @return string |
|
| 136 | + */ |
|
| 137 | + public function getCategoryList() |
|
| 138 | + { |
|
| 139 | + if ($this->Categories()->count()) { |
|
| 140 | + return implode(', ', $this->Categories()->column('Name')); |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - return ''; |
|
| 144 | - } |
|
| 143 | + return ''; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * @return bool|string |
|
| 148 | - */ |
|
| 149 | - public function getCountryCode() |
|
| 150 | - { |
|
| 151 | - if ($this->Country) { |
|
| 152 | - return strtoupper($this->Country); |
|
| 153 | - } |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 146 | + /** |
|
| 147 | + * @return bool|string |
|
| 148 | + */ |
|
| 149 | + public function getCountryCode() |
|
| 150 | + { |
|
| 151 | + if ($this->Country) { |
|
| 152 | + return strtoupper($this->Country); |
|
| 153 | + } |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * custom labels for fields |
|
| 159 | - * |
|
| 160 | - * @param bool $includerelations |
|
| 161 | - * @return array|string |
|
| 162 | - */ |
|
| 163 | - public function fieldLabels($includerelations = true) |
|
| 164 | - { |
|
| 165 | - $labels = parent::fieldLabels($includerelations); |
|
| 166 | - $labels['Title'] = 'Name'; |
|
| 167 | - $labels['Address2'] = 'Address 2'; |
|
| 168 | - $labels['PostalCode'] = 'Postal Code'; |
|
| 169 | - $labels['Categories.Name'] = 'Categories'; |
|
| 170 | - $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
| 171 | - return $labels; |
|
| 172 | - } |
|
| 157 | + /** |
|
| 158 | + * custom labels for fields |
|
| 159 | + * |
|
| 160 | + * @param bool $includerelations |
|
| 161 | + * @return array|string |
|
| 162 | + */ |
|
| 163 | + public function fieldLabels($includerelations = true) |
|
| 164 | + { |
|
| 165 | + $labels = parent::fieldLabels($includerelations); |
|
| 166 | + $labels['Title'] = 'Name'; |
|
| 167 | + $labels['Address2'] = 'Address 2'; |
|
| 168 | + $labels['PostalCode'] = 'Postal Code'; |
|
| 169 | + $labels['Categories.Name'] = 'Categories'; |
|
| 170 | + $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
| 171 | + return $labels; |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - /** |
|
| 175 | - * @return FieldList |
|
| 176 | - */ |
|
| 177 | - public function getCMSFields() |
|
| 178 | - { |
|
| 179 | - $this->beforeUpdateCMSFields(function ($fields) { |
|
| 180 | - $fields->removeByName(array( |
|
| 181 | - 'Import_ID', |
|
| 182 | - 'LinkTracking', |
|
| 183 | - 'FileTracking', |
|
| 184 | - )); |
|
| 174 | + /** |
|
| 175 | + * @return FieldList |
|
| 176 | + */ |
|
| 177 | + public function getCMSFields() |
|
| 178 | + { |
|
| 179 | + $this->beforeUpdateCMSFields(function ($fields) { |
|
| 180 | + $fields->removeByName(array( |
|
| 181 | + 'Import_ID', |
|
| 182 | + 'LinkTracking', |
|
| 183 | + 'FileTracking', |
|
| 184 | + )); |
|
| 185 | 185 | |
| 186 | - $fields->dataFieldByName('Website') |
|
| 187 | - ->setAttribute('placeholder', 'http://'); |
|
| 186 | + $fields->dataFieldByName('Website') |
|
| 187 | + ->setAttribute('placeholder', 'http://'); |
|
| 188 | 188 | |
| 189 | - $fields->replaceField('Email', EmailField::create('Email')); |
|
| 189 | + $fields->replaceField('Email', EmailField::create('Email')); |
|
| 190 | 190 | |
| 191 | - $featured = $fields->dataFieldByName('Featured') |
|
| 192 | - ->setDescription('Location will display near the top of the results list'); |
|
| 193 | - $fields->insertAfter( |
|
| 194 | - 'Fax', |
|
| 195 | - $featured |
|
| 196 | - ); |
|
| 191 | + $featured = $fields->dataFieldByName('Featured') |
|
| 192 | + ->setDescription('Location will display near the top of the results list'); |
|
| 193 | + $fields->insertAfter( |
|
| 194 | + 'Fax', |
|
| 195 | + $featured |
|
| 196 | + ); |
|
| 197 | 197 | |
| 198 | - if ($this->ID) { |
|
| 199 | - $categories = $fields->dataFieldByName('Categories'); |
|
| 200 | - $config = $categories->getConfig(); |
|
| 201 | - $config->removeComponentsByType([ |
|
| 202 | - GridFieldAddExistingAutocompleter::class |
|
| 203 | - ]) |
|
| 204 | - ->addComponents([ |
|
| 205 | - new GridFieldAddExistingSearchButton() |
|
| 206 | - ]); |
|
| 207 | - } |
|
| 208 | - }); |
|
| 198 | + if ($this->ID) { |
|
| 199 | + $categories = $fields->dataFieldByName('Categories'); |
|
| 200 | + $config = $categories->getConfig(); |
|
| 201 | + $config->removeComponentsByType([ |
|
| 202 | + GridFieldAddExistingAutocompleter::class |
|
| 203 | + ]) |
|
| 204 | + ->addComponents([ |
|
| 205 | + new GridFieldAddExistingSearchButton() |
|
| 206 | + ]); |
|
| 207 | + } |
|
| 208 | + }); |
|
| 209 | 209 | |
| 210 | - $fields = parent::getCMSFields(); |
|
| 210 | + $fields = parent::getCMSFields(); |
|
| 211 | 211 | |
| 212 | - // allow to be extended via DataExtension |
|
| 213 | - $this->extend('updateLocationFields', $fields); |
|
| 212 | + // allow to be extended via DataExtension |
|
| 213 | + $this->extend('updateLocationFields', $fields); |
|
| 214 | 214 | |
| 215 | - return $fields; |
|
| 216 | - } |
|
| 215 | + return $fields; |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - /** |
|
| 219 | - * @param null $member |
|
| 220 | - * @param array $context |
|
| 221 | - * @return bool |
|
| 222 | - */ |
|
| 223 | - public function canView($member = null, $context = []) |
|
| 224 | - { |
|
| 225 | - return true; |
|
| 226 | - } |
|
| 218 | + /** |
|
| 219 | + * @param null $member |
|
| 220 | + * @param array $context |
|
| 221 | + * @return bool |
|
| 222 | + */ |
|
| 223 | + public function canView($member = null, $context = []) |
|
| 224 | + { |
|
| 225 | + return true; |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - /** |
|
| 229 | - * @param null $member |
|
| 230 | - * @param array $context |
|
| 231 | - * @return bool|int |
|
| 232 | - */ |
|
| 233 | - public function canEdit($member = null, $context = []) |
|
| 234 | - { |
|
| 235 | - return Permission::check('Location_EDIT', 'any', $member); |
|
| 236 | - } |
|
| 228 | + /** |
|
| 229 | + * @param null $member |
|
| 230 | + * @param array $context |
|
| 231 | + * @return bool|int |
|
| 232 | + */ |
|
| 233 | + public function canEdit($member = null, $context = []) |
|
| 234 | + { |
|
| 235 | + return Permission::check('Location_EDIT', 'any', $member); |
|
| 236 | + } |
|
| 237 | 237 | |
| 238 | - /** |
|
| 239 | - * @param null $member |
|
| 240 | - * @param array $context |
|
| 241 | - * @return bool|int |
|
| 242 | - */ |
|
| 243 | - public function canDelete($member = null, $context = []) |
|
| 244 | - { |
|
| 245 | - return Permission::check('Location_DELETE', 'any', $member); |
|
| 246 | - } |
|
| 238 | + /** |
|
| 239 | + * @param null $member |
|
| 240 | + * @param array $context |
|
| 241 | + * @return bool|int |
|
| 242 | + */ |
|
| 243 | + public function canDelete($member = null, $context = []) |
|
| 244 | + { |
|
| 245 | + return Permission::check('Location_DELETE', 'any', $member); |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - /** |
|
| 249 | - * @param null $member |
|
| 250 | - * @param array $context |
|
| 251 | - * @return bool|int |
|
| 252 | - */ |
|
| 253 | - public function canCreate($member = null, $context = []) |
|
| 254 | - { |
|
| 255 | - return Permission::check('Location_CREATE', 'any', $member); |
|
| 256 | - } |
|
| 248 | + /** |
|
| 249 | + * @param null $member |
|
| 250 | + * @param array $context |
|
| 251 | + * @return bool|int |
|
| 252 | + */ |
|
| 253 | + public function canCreate($member = null, $context = []) |
|
| 254 | + { |
|
| 255 | + return Permission::check('Location_CREATE', 'any', $member); |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - /** |
|
| 259 | - * @return array |
|
| 260 | - */ |
|
| 261 | - public function providePermissions() |
|
| 262 | - { |
|
| 263 | - return array( |
|
| 264 | - 'Location_EDIT' => 'Edit a Location', |
|
| 265 | - 'Location_DELETE' => 'Delete a Location', |
|
| 266 | - 'Location_CREATE' => 'Create a Location', |
|
| 267 | - ); |
|
| 268 | - } |
|
| 258 | + /** |
|
| 259 | + * @return array |
|
| 260 | + */ |
|
| 261 | + public function providePermissions() |
|
| 262 | + { |
|
| 263 | + return array( |
|
| 264 | + 'Location_EDIT' => 'Edit a Location', |
|
| 265 | + 'Location_DELETE' => 'Delete a Location', |
|
| 266 | + 'Location_CREATE' => 'Create a Location', |
|
| 267 | + ); |
|
| 268 | + } |
|
| 269 | 269 | } |
@@ -59,7 +59,7 @@ |
||
| 59 | 59 | */ |
| 60 | 60 | public function getCMSFields() |
| 61 | 61 | { |
| 62 | - $this->beforeUpdateCMSFields(function ($fields) { |
|
| 62 | + $this->beforeUpdateCMSFields(function($fields) { |
|
| 63 | 63 | $fields->removeByName([ |
| 64 | 64 | 'Locations', |
| 65 | 65 | 'LocationSet', |
@@ -20,125 +20,125 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class LocationCategory extends DataObject |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 26 | - private static $singular_name = 'Category'; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - private static $plural_name = 'Categories'; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var array |
|
| 35 | - */ |
|
| 36 | - private static $db = array( |
|
| 37 | - 'Name' => 'Varchar(100)', |
|
| 38 | - ); |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var array |
|
| 42 | - */ |
|
| 43 | - private static $belongs_many_many = array( |
|
| 44 | - 'Locators' => Locator::class, |
|
| 45 | - 'LocationSet' => Location::class, |
|
| 46 | - ); |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var string |
|
| 50 | - */ |
|
| 51 | - private static $table_name = 'LocationCategory'; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 56 | - private static $default_sort = 'Name'; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @return \SilverStripe\Forms\FieldList |
|
| 60 | - */ |
|
| 61 | - public function getCMSFields() |
|
| 62 | - { |
|
| 63 | - $this->beforeUpdateCMSFields(function ($fields) { |
|
| 64 | - $fields->removeByName([ |
|
| 65 | - 'Locations', |
|
| 66 | - 'LocationSet', |
|
| 67 | - 'Locators', |
|
| 68 | - 'LinkTracking', |
|
| 69 | - 'FileTracking', |
|
| 70 | - ]); |
|
| 71 | - |
|
| 72 | - if ($this->ID) { |
|
| 73 | - // Locations |
|
| 74 | - $config = GridFieldConfig_RelationEditor::create(); |
|
| 75 | - $config->removeComponentsByType([ |
|
| 76 | - GridFieldAddExistingAutocompleter::class, |
|
| 77 | - GridFieldAddNewButton::class |
|
| 78 | - ]) |
|
| 79 | - ->addComponents([ |
|
| 80 | - new GridFieldAddExistingSearchButton(), |
|
| 81 | - ]); |
|
| 82 | - $locations = $this->Locations(); |
|
| 83 | - $locationField = GridField::create('Locations', 'Locations', $locations, $config); |
|
| 84 | - |
|
| 85 | - $fields->addFieldsToTab('Root.Main', array( |
|
| 86 | - $locationField, |
|
| 87 | - )); |
|
| 88 | - } |
|
| 89 | - }); |
|
| 90 | - |
|
| 91 | - $fields = parent::getCMSFields(); |
|
| 92 | - |
|
| 93 | - return $fields; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * For backwards compatability |
|
| 98 | - * @return Locations|ManyManyList |
|
| 99 | - */ |
|
| 100 | - public function Locations() |
|
| 101 | - { |
|
| 102 | - return $this->LocationSet(); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @param null $member |
|
| 107 | - * @param array $context |
|
| 108 | - * @return bool |
|
| 109 | - */ |
|
| 110 | - public function canView($member = null, $context = []) |
|
| 111 | - { |
|
| 112 | - return true; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @param null $member |
|
| 117 | - * @param array $context |
|
| 118 | - * @return bool|int |
|
| 119 | - */ |
|
| 120 | - public function canEdit($member = null, $context = []) |
|
| 121 | - { |
|
| 122 | - return Permission::check('Location_EDIT', 'any', $member); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @param null $member |
|
| 127 | - * @param array $context |
|
| 128 | - * @return bool|int |
|
| 129 | - */ |
|
| 130 | - public function canDelete($member = null, $context = []) |
|
| 131 | - { |
|
| 132 | - return Permission::check('Location_DELETE', 'any', $member); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @param null $member |
|
| 137 | - * @param array $context |
|
| 138 | - * @return bool|int |
|
| 139 | - */ |
|
| 140 | - public function canCreate($member = null, $context = []) |
|
| 141 | - { |
|
| 142 | - return Permission::check('Location_CREATE', 'any', $member); |
|
| 143 | - } |
|
| 23 | + /** |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | + private static $singular_name = 'Category'; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + private static $plural_name = 'Categories'; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var array |
|
| 35 | + */ |
|
| 36 | + private static $db = array( |
|
| 37 | + 'Name' => 'Varchar(100)', |
|
| 38 | + ); |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var array |
|
| 42 | + */ |
|
| 43 | + private static $belongs_many_many = array( |
|
| 44 | + 'Locators' => Locator::class, |
|
| 45 | + 'LocationSet' => Location::class, |
|
| 46 | + ); |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var string |
|
| 50 | + */ |
|
| 51 | + private static $table_name = 'LocationCategory'; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | + private static $default_sort = 'Name'; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @return \SilverStripe\Forms\FieldList |
|
| 60 | + */ |
|
| 61 | + public function getCMSFields() |
|
| 62 | + { |
|
| 63 | + $this->beforeUpdateCMSFields(function ($fields) { |
|
| 64 | + $fields->removeByName([ |
|
| 65 | + 'Locations', |
|
| 66 | + 'LocationSet', |
|
| 67 | + 'Locators', |
|
| 68 | + 'LinkTracking', |
|
| 69 | + 'FileTracking', |
|
| 70 | + ]); |
|
| 71 | + |
|
| 72 | + if ($this->ID) { |
|
| 73 | + // Locations |
|
| 74 | + $config = GridFieldConfig_RelationEditor::create(); |
|
| 75 | + $config->removeComponentsByType([ |
|
| 76 | + GridFieldAddExistingAutocompleter::class, |
|
| 77 | + GridFieldAddNewButton::class |
|
| 78 | + ]) |
|
| 79 | + ->addComponents([ |
|
| 80 | + new GridFieldAddExistingSearchButton(), |
|
| 81 | + ]); |
|
| 82 | + $locations = $this->Locations(); |
|
| 83 | + $locationField = GridField::create('Locations', 'Locations', $locations, $config); |
|
| 84 | + |
|
| 85 | + $fields->addFieldsToTab('Root.Main', array( |
|
| 86 | + $locationField, |
|
| 87 | + )); |
|
| 88 | + } |
|
| 89 | + }); |
|
| 90 | + |
|
| 91 | + $fields = parent::getCMSFields(); |
|
| 92 | + |
|
| 93 | + return $fields; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * For backwards compatability |
|
| 98 | + * @return Locations|ManyManyList |
|
| 99 | + */ |
|
| 100 | + public function Locations() |
|
| 101 | + { |
|
| 102 | + return $this->LocationSet(); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @param null $member |
|
| 107 | + * @param array $context |
|
| 108 | + * @return bool |
|
| 109 | + */ |
|
| 110 | + public function canView($member = null, $context = []) |
|
| 111 | + { |
|
| 112 | + return true; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @param null $member |
|
| 117 | + * @param array $context |
|
| 118 | + * @return bool|int |
|
| 119 | + */ |
|
| 120 | + public function canEdit($member = null, $context = []) |
|
| 121 | + { |
|
| 122 | + return Permission::check('Location_EDIT', 'any', $member); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @param null $member |
|
| 127 | + * @param array $context |
|
| 128 | + * @return bool|int |
|
| 129 | + */ |
|
| 130 | + public function canDelete($member = null, $context = []) |
|
| 131 | + { |
|
| 132 | + return Permission::check('Location_DELETE', 'any', $member); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @param null $member |
|
| 137 | + * @param array $context |
|
| 138 | + * @return bool|int |
|
| 139 | + */ |
|
| 140 | + public function canCreate($member = null, $context = []) |
|
| 141 | + { |
|
| 142 | + return Permission::check('Location_CREATE', 'any', $member); |
|
| 143 | + } |
|
| 144 | 144 | } |
@@ -70,7 +70,7 @@ |
||
| 70 | 70 | */ |
| 71 | 71 | public function getCMSFields() |
| 72 | 72 | { |
| 73 | - $this->beforeUpdateCMSFields(function ($fields) { |
|
| 73 | + $this->beforeUpdateCMSFields(function($fields) { |
|
| 74 | 74 | // Settings |
| 75 | 75 | $fields->addFieldsToTab('Root.Settings', array( |
| 76 | 76 | HeaderField::create('DisplayOptions', 'Display Options', 3), |
@@ -26,246 +26,246 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class Locator extends \Page |
| 28 | 28 | { |
| 29 | - /** |
|
| 30 | - * @var string |
|
| 31 | - */ |
|
| 32 | - private static $singular_name = 'Locator'; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 37 | - private static $plural_name = 'Locators'; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var string |
|
| 41 | - */ |
|
| 42 | - private static $description = 'Display locations on a map'; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var array |
|
| 46 | - */ |
|
| 47 | - private static $db = array( |
|
| 48 | - 'Unit' => 'Enum("m,km","m")', |
|
| 49 | - ); |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var array |
|
| 53 | - */ |
|
| 54 | - private static $many_many = array( |
|
| 55 | - 'Categories' => LocationCategory::class, |
|
| 56 | - ); |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var string |
|
| 60 | - */ |
|
| 61 | - private static $table_name = 'Locator'; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @var string |
|
| 65 | - */ |
|
| 66 | - private static $location_class = Location::class; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * @return FieldList |
|
| 70 | - */ |
|
| 71 | - public function getCMSFields() |
|
| 72 | - { |
|
| 73 | - $this->beforeUpdateCMSFields(function ($fields) { |
|
| 74 | - // Settings |
|
| 75 | - $fields->addFieldsToTab('Root.Settings', array( |
|
| 76 | - HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
| 77 | - OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')), |
|
| 78 | - )); |
|
| 79 | - |
|
| 80 | - // Filter categories |
|
| 81 | - $config = GridFieldConfig_RelationEditor::create(); |
|
| 82 | - $config->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
|
| 83 | - $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
| 84 | - $categories = $this->Categories(); |
|
| 85 | - $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
| 86 | - ->setDescription('only show locations from the selected category'); |
|
| 87 | - |
|
| 88 | - // Filter |
|
| 89 | - $fields->addFieldsToTab('Root.Filter', array( |
|
| 90 | - HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
| 91 | - $categoriesField, |
|
| 92 | - )); |
|
| 93 | - }); |
|
| 94 | - |
|
| 95 | - return parent::getCMSFields(); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @param array $filter |
|
| 100 | - * @param array $filterAny |
|
| 101 | - * @param array $exclude |
|
| 102 | - * @param null|callable $callback |
|
| 103 | - * |
|
| 104 | - * @return DataList|ArrayList |
|
| 105 | - */ |
|
| 106 | - public static function get_locations( |
|
| 107 | - $filter = [], |
|
| 108 | - $filterAny = [], |
|
| 109 | - $exclude = [], |
|
| 110 | - $callback = null |
|
| 111 | - ) { |
|
| 112 | - $locationClass = Config::inst()->get(Locator::class, 'location_class'); |
|
| 113 | - $locations = $locationClass::get()->filter($filter)->exclude($exclude); |
|
| 114 | - |
|
| 115 | - if (!empty($filterAny)) { |
|
| 116 | - $locations = $locations->filterAny($filterAny); |
|
| 117 | - } |
|
| 118 | - if (!empty($exclude)) { |
|
| 119 | - $locations = $locations->exclude($exclude); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - if ($callback !== null && is_callable($callback)) { |
|
| 123 | - $locations->filterByCallback($callback); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - return $locations; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @return DataList |
|
| 131 | - */ |
|
| 132 | - public static function get_all_categories() |
|
| 133 | - { |
|
| 134 | - return LocationCategory::get(); |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @return bool |
|
| 139 | - */ |
|
| 140 | - public function getPageCategories() |
|
| 141 | - { |
|
| 142 | - return self::locator_categories_by_locator($this->ID); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * @param int $id |
|
| 147 | - * |
|
| 148 | - * @return bool| |
|
| 149 | - */ |
|
| 150 | - public static function locator_categories_by_locator($id = 0) |
|
| 151 | - { |
|
| 152 | - if ($id == 0) { |
|
| 153 | - return false; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - return Locator::get()->byID($id)->getUsedCategories(); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Gets the list of radii |
|
| 161 | - * |
|
| 162 | - * @return ArrayList |
|
| 163 | - */ |
|
| 164 | - public function getRadii() |
|
| 165 | - { |
|
| 166 | - $radii = [ |
|
| 167 | - '0' => '25', |
|
| 168 | - '1' => '50', |
|
| 169 | - '2' => '75', |
|
| 170 | - '3' => '100', |
|
| 171 | - ]; |
|
| 172 | - $config_radii = $this->config()->get('radii'); |
|
| 173 | - if ($config_radii) { |
|
| 174 | - $radii = $config_radii; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return $radii; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - public function getRadiiArrayList() |
|
| 181 | - { |
|
| 182 | - $list = []; |
|
| 183 | - |
|
| 184 | - foreach ($this->getRadii() as $radius) { |
|
| 185 | - $list[] = new ArrayData(array( |
|
| 186 | - 'Radius' => $radius, |
|
| 187 | - )); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - return new ArrayList($list); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Gets the limit of locations |
|
| 195 | - * @return mixed |
|
| 196 | - */ |
|
| 197 | - public function getLimit() |
|
| 198 | - { |
|
| 199 | - return $this->config()->get('limit'); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Gets if the radius drop down should be shown |
|
| 204 | - * @return mixed |
|
| 205 | - */ |
|
| 206 | - public function getShowRadius() |
|
| 207 | - { |
|
| 208 | - return $this->config()->get('show_radius'); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * @return mixed |
|
| 213 | - */ |
|
| 214 | - public function getUsedCategories() |
|
| 215 | - { |
|
| 216 | - return $this->Categories()->filter([ |
|
| 217 | - 'LocationSet.ID:GreaterThan' => 0, |
|
| 218 | - ]); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Gets the path of the info window template |
|
| 223 | - * |
|
| 224 | - * @return string |
|
| 225 | - */ |
|
| 226 | - public function getInfoWindowTemplate() |
|
| 227 | - { |
|
| 228 | - return ModuleResourceLoader::singleton()->resolveURL( |
|
| 229 | - Config::inst()->get( |
|
| 230 | - Locator::class, |
|
| 231 | - 'infoWindowTemplate' |
|
| 232 | - ) |
|
| 233 | - ); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * Gets the path of the list template |
|
| 238 | - * |
|
| 239 | - * @return string |
|
| 240 | - */ |
|
| 241 | - public function getListTemplate() |
|
| 242 | - { |
|
| 243 | - return ModuleResourceLoader::singleton()->resolveURL( |
|
| 244 | - Config::inst()->get( |
|
| 245 | - Locator::class, |
|
| 246 | - 'listTemplate' |
|
| 247 | - ) |
|
| 248 | - ); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * @return null|string |
|
| 253 | - */ |
|
| 254 | - public function getMapStyle() |
|
| 255 | - { |
|
| 256 | - return AddressDataExtension::getMapStyleJSON(); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - public function getMapStyleJSONPath() |
|
| 260 | - { |
|
| 261 | - return AddressDataExtension::getMapStyleJSONPath(); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * @return null|string |
|
| 266 | - */ |
|
| 267 | - public function getMarkerIcon() |
|
| 268 | - { |
|
| 269 | - return AddressDataExtension::getIconImage(); |
|
| 270 | - } |
|
| 29 | + /** |
|
| 30 | + * @var string |
|
| 31 | + */ |
|
| 32 | + private static $singular_name = 'Locator'; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | + private static $plural_name = 'Locators'; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var string |
|
| 41 | + */ |
|
| 42 | + private static $description = 'Display locations on a map'; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var array |
|
| 46 | + */ |
|
| 47 | + private static $db = array( |
|
| 48 | + 'Unit' => 'Enum("m,km","m")', |
|
| 49 | + ); |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var array |
|
| 53 | + */ |
|
| 54 | + private static $many_many = array( |
|
| 55 | + 'Categories' => LocationCategory::class, |
|
| 56 | + ); |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var string |
|
| 60 | + */ |
|
| 61 | + private static $table_name = 'Locator'; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @var string |
|
| 65 | + */ |
|
| 66 | + private static $location_class = Location::class; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * @return FieldList |
|
| 70 | + */ |
|
| 71 | + public function getCMSFields() |
|
| 72 | + { |
|
| 73 | + $this->beforeUpdateCMSFields(function ($fields) { |
|
| 74 | + // Settings |
|
| 75 | + $fields->addFieldsToTab('Root.Settings', array( |
|
| 76 | + HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
| 77 | + OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')), |
|
| 78 | + )); |
|
| 79 | + |
|
| 80 | + // Filter categories |
|
| 81 | + $config = GridFieldConfig_RelationEditor::create(); |
|
| 82 | + $config->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
|
| 83 | + $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
| 84 | + $categories = $this->Categories(); |
|
| 85 | + $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
| 86 | + ->setDescription('only show locations from the selected category'); |
|
| 87 | + |
|
| 88 | + // Filter |
|
| 89 | + $fields->addFieldsToTab('Root.Filter', array( |
|
| 90 | + HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
| 91 | + $categoriesField, |
|
| 92 | + )); |
|
| 93 | + }); |
|
| 94 | + |
|
| 95 | + return parent::getCMSFields(); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @param array $filter |
|
| 100 | + * @param array $filterAny |
|
| 101 | + * @param array $exclude |
|
| 102 | + * @param null|callable $callback |
|
| 103 | + * |
|
| 104 | + * @return DataList|ArrayList |
|
| 105 | + */ |
|
| 106 | + public static function get_locations( |
|
| 107 | + $filter = [], |
|
| 108 | + $filterAny = [], |
|
| 109 | + $exclude = [], |
|
| 110 | + $callback = null |
|
| 111 | + ) { |
|
| 112 | + $locationClass = Config::inst()->get(Locator::class, 'location_class'); |
|
| 113 | + $locations = $locationClass::get()->filter($filter)->exclude($exclude); |
|
| 114 | + |
|
| 115 | + if (!empty($filterAny)) { |
|
| 116 | + $locations = $locations->filterAny($filterAny); |
|
| 117 | + } |
|
| 118 | + if (!empty($exclude)) { |
|
| 119 | + $locations = $locations->exclude($exclude); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + if ($callback !== null && is_callable($callback)) { |
|
| 123 | + $locations->filterByCallback($callback); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + return $locations; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @return DataList |
|
| 131 | + */ |
|
| 132 | + public static function get_all_categories() |
|
| 133 | + { |
|
| 134 | + return LocationCategory::get(); |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @return bool |
|
| 139 | + */ |
|
| 140 | + public function getPageCategories() |
|
| 141 | + { |
|
| 142 | + return self::locator_categories_by_locator($this->ID); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * @param int $id |
|
| 147 | + * |
|
| 148 | + * @return bool| |
|
| 149 | + */ |
|
| 150 | + public static function locator_categories_by_locator($id = 0) |
|
| 151 | + { |
|
| 152 | + if ($id == 0) { |
|
| 153 | + return false; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + return Locator::get()->byID($id)->getUsedCategories(); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Gets the list of radii |
|
| 161 | + * |
|
| 162 | + * @return ArrayList |
|
| 163 | + */ |
|
| 164 | + public function getRadii() |
|
| 165 | + { |
|
| 166 | + $radii = [ |
|
| 167 | + '0' => '25', |
|
| 168 | + '1' => '50', |
|
| 169 | + '2' => '75', |
|
| 170 | + '3' => '100', |
|
| 171 | + ]; |
|
| 172 | + $config_radii = $this->config()->get('radii'); |
|
| 173 | + if ($config_radii) { |
|
| 174 | + $radii = $config_radii; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return $radii; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + public function getRadiiArrayList() |
|
| 181 | + { |
|
| 182 | + $list = []; |
|
| 183 | + |
|
| 184 | + foreach ($this->getRadii() as $radius) { |
|
| 185 | + $list[] = new ArrayData(array( |
|
| 186 | + 'Radius' => $radius, |
|
| 187 | + )); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + return new ArrayList($list); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Gets the limit of locations |
|
| 195 | + * @return mixed |
|
| 196 | + */ |
|
| 197 | + public function getLimit() |
|
| 198 | + { |
|
| 199 | + return $this->config()->get('limit'); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Gets if the radius drop down should be shown |
|
| 204 | + * @return mixed |
|
| 205 | + */ |
|
| 206 | + public function getShowRadius() |
|
| 207 | + { |
|
| 208 | + return $this->config()->get('show_radius'); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * @return mixed |
|
| 213 | + */ |
|
| 214 | + public function getUsedCategories() |
|
| 215 | + { |
|
| 216 | + return $this->Categories()->filter([ |
|
| 217 | + 'LocationSet.ID:GreaterThan' => 0, |
|
| 218 | + ]); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * Gets the path of the info window template |
|
| 223 | + * |
|
| 224 | + * @return string |
|
| 225 | + */ |
|
| 226 | + public function getInfoWindowTemplate() |
|
| 227 | + { |
|
| 228 | + return ModuleResourceLoader::singleton()->resolveURL( |
|
| 229 | + Config::inst()->get( |
|
| 230 | + Locator::class, |
|
| 231 | + 'infoWindowTemplate' |
|
| 232 | + ) |
|
| 233 | + ); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * Gets the path of the list template |
|
| 238 | + * |
|
| 239 | + * @return string |
|
| 240 | + */ |
|
| 241 | + public function getListTemplate() |
|
| 242 | + { |
|
| 243 | + return ModuleResourceLoader::singleton()->resolveURL( |
|
| 244 | + Config::inst()->get( |
|
| 245 | + Locator::class, |
|
| 246 | + 'listTemplate' |
|
| 247 | + ) |
|
| 248 | + ); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * @return null|string |
|
| 253 | + */ |
|
| 254 | + public function getMapStyle() |
|
| 255 | + { |
|
| 256 | + return AddressDataExtension::getMapStyleJSON(); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + public function getMapStyleJSONPath() |
|
| 260 | + { |
|
| 261 | + return AddressDataExtension::getMapStyleJSONPath(); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * @return null|string |
|
| 266 | + */ |
|
| 267 | + public function getMarkerIcon() |
|
| 268 | + { |
|
| 269 | + return AddressDataExtension::getIconImage(); |
|
| 270 | + } |
|
| 271 | 271 | } |
@@ -18,78 +18,78 @@ |
||
| 18 | 18 | class LocatorControllerTest extends FunctionalTest |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected static $fixture_file = '../fixtures.yml'; |
|
| 21 | + /** |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected static $fixture_file = '../fixtures.yml'; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var bool |
|
| 28 | - */ |
|
| 29 | - protected static $use_draft_site = true; |
|
| 26 | + /** |
|
| 27 | + * @var bool |
|
| 28 | + */ |
|
| 29 | + protected static $use_draft_site = true; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * |
|
| 33 | - */ |
|
| 34 | - public function testIndex() |
|
| 35 | - { |
|
| 36 | - $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 37 | - $controller = LocatorController::create($locator); |
|
| 38 | - $this->assertInstanceOf(ViewableData::class, $controller->index($controller->getRequest())); |
|
| 39 | - } |
|
| 31 | + /** |
|
| 32 | + * |
|
| 33 | + */ |
|
| 34 | + public function testIndex() |
|
| 35 | + { |
|
| 36 | + $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 37 | + $controller = LocatorController::create($locator); |
|
| 38 | + $this->assertInstanceOf(ViewableData::class, $controller->index($controller->getRequest())); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * |
|
| 43 | - */ |
|
| 44 | - public function testXml() |
|
| 45 | - { |
|
| 46 | - /** @var Locator $locator */ |
|
| 47 | - $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 48 | - $page = $this->get($locator->Link('xml')); |
|
| 41 | + /** |
|
| 42 | + * |
|
| 43 | + */ |
|
| 44 | + public function testXml() |
|
| 45 | + { |
|
| 46 | + /** @var Locator $locator */ |
|
| 47 | + $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 48 | + $page = $this->get($locator->Link('xml')); |
|
| 49 | 49 | |
| 50 | - $this->assertEquals(200, $page->getStatusCode()); |
|
| 51 | - $this->assertEquals('application/xml', $page->getHeader('content-type')); |
|
| 50 | + $this->assertEquals(200, $page->getStatusCode()); |
|
| 51 | + $this->assertEquals('application/xml', $page->getHeader('content-type')); |
|
| 52 | 52 | |
| 53 | - $dom = new DOMDocument(); |
|
| 54 | - // true if it loads, false if it doesn't |
|
| 55 | - $valid = $dom->loadXML($page->getBody()); |
|
| 56 | - $this->assertTrue($valid); |
|
| 57 | - } |
|
| 53 | + $dom = new DOMDocument(); |
|
| 54 | + // true if it loads, false if it doesn't |
|
| 55 | + $valid = $dom->loadXML($page->getBody()); |
|
| 56 | + $this->assertTrue($valid); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * |
|
| 61 | - */ |
|
| 62 | - public function testJson() |
|
| 63 | - { |
|
| 64 | - /** @var Locator $locator */ |
|
| 65 | - $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 66 | - $page = $this->get($locator->Link('json')); |
|
| 59 | + /** |
|
| 60 | + * |
|
| 61 | + */ |
|
| 62 | + public function testJson() |
|
| 63 | + { |
|
| 64 | + /** @var Locator $locator */ |
|
| 65 | + $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 66 | + $page = $this->get($locator->Link('json')); |
|
| 67 | 67 | |
| 68 | - $this->assertEquals(200, $page->getStatusCode()); |
|
| 69 | - $this->assertEquals('application/json', $page->getHeader('content-type')); |
|
| 68 | + $this->assertEquals(200, $page->getStatusCode()); |
|
| 69 | + $this->assertEquals('application/json', $page->getHeader('content-type')); |
|
| 70 | 70 | |
| 71 | - $json = json_decode($page->getBody()); |
|
| 72 | - // if it is null its not valid |
|
| 73 | - $this->assertNotNull($json); |
|
| 74 | - } |
|
| 71 | + $json = json_decode($page->getBody()); |
|
| 72 | + // if it is null its not valid |
|
| 73 | + $this->assertNotNull($json); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * |
|
| 78 | - */ |
|
| 79 | - public function testLocationSearch() |
|
| 80 | - { |
|
| 81 | - $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 82 | - $object = LocatorController::create($locator); |
|
| 83 | - $form = $object->LocationSearch(); |
|
| 84 | - $this->assertInstanceOf(Form::class, $form); |
|
| 76 | + /** |
|
| 77 | + * |
|
| 78 | + */ |
|
| 79 | + public function testLocationSearch() |
|
| 80 | + { |
|
| 81 | + $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 82 | + $object = LocatorController::create($locator); |
|
| 83 | + $form = $object->LocationSearch(); |
|
| 84 | + $this->assertInstanceOf(Form::class, $form); |
|
| 85 | 85 | |
| 86 | - $category = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 87 | - $category2 = $this->objFromFixture(LocationCategory::class, 'manufacturing'); |
|
| 88 | - $locator->Categories()->add($category); |
|
| 89 | - $locator->Categories()->add($category2); |
|
| 86 | + $category = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 87 | + $category2 = $this->objFromFixture(LocationCategory::class, 'manufacturing'); |
|
| 88 | + $locator->Categories()->add($category); |
|
| 89 | + $locator->Categories()->add($category2); |
|
| 90 | 90 | |
| 91 | - $form = $object->LocationSearch(); |
|
| 92 | - $fields = $form->Fields(); |
|
| 93 | - $this->assertInstanceOf(FieldList::class, $fields); |
|
| 94 | - } |
|
| 91 | + $form = $object->LocationSearch(); |
|
| 92 | + $fields = $form->Fields(); |
|
| 93 | + $this->assertInstanceOf(FieldList::class, $fields); |
|
| 94 | + } |
|
| 95 | 95 | } |
@@ -21,158 +21,158 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class LocatorTest extends FunctionalTest |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * @var string |
|
| 26 | - */ |
|
| 27 | - protected static $fixture_file = '../fixtures.yml'; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * |
|
| 31 | - */ |
|
| 32 | - public function testGetCMSFields() |
|
| 33 | - { |
|
| 34 | - /** @var Locator $locator */ |
|
| 35 | - $locator = Injector::inst()->create(Locator::class); |
|
| 36 | - $this->assertInstanceOf(FieldList::class, $locator->getCMSFields()); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * |
|
| 41 | - */ |
|
| 42 | - public function testLocations() |
|
| 43 | - { |
|
| 44 | - $filter = Config::inst()->get(LocatorController::class, 'base_filter'); |
|
| 45 | - $filterAny = Config::inst()->get(LocatorController::class, 'base_filter_any'); |
|
| 46 | - $exclude = Config::inst()->get(LocatorController::class, 'base_exclude'); |
|
| 47 | - $locations = Locator::get_locations($filter, $filterAny, $exclude); |
|
| 48 | - $locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude); |
|
| 49 | - $this->assertEquals($locations->count(), $locations2->count()); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * |
|
| 54 | - */ |
|
| 55 | - public function testGetAllCategories() |
|
| 56 | - { |
|
| 57 | - $this->assertEquals(Locator::get_all_categories()->count(), 4); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * |
|
| 62 | - */ |
|
| 63 | - public function testGetPageCategories() |
|
| 64 | - { |
|
| 65 | - $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 66 | - $this->assertEquals($locator->getPageCategories()->count(), 1); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * |
|
| 71 | - */ |
|
| 72 | - public function testLocator_categories_by_locator() |
|
| 73 | - { |
|
| 74 | - $categories = Locator::locator_categories_by_locator(0); |
|
| 75 | - $this->assertFalse($categories); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * |
|
| 80 | - */ |
|
| 81 | - public function testLocatorCategoriesByLocator() |
|
| 82 | - { |
|
| 83 | - |
|
| 84 | - $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 85 | - $this->assertEquals(Locator::locator_categories_by_locator($locator->ID)->count(), 1); |
|
| 86 | - |
|
| 87 | - $newLocator = Locator::create(); |
|
| 88 | - $newLocator->Title = 'Locator 2'; |
|
| 89 | - $newLocator->write(); |
|
| 90 | - |
|
| 91 | - $this->assertEquals(Locator::locator_categories_by_locator($newLocator->ID)->count(), 0); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * |
|
| 96 | - */ |
|
| 97 | - public function testGetRadii() |
|
| 98 | - { |
|
| 99 | - /** @var Locator $locator */ |
|
| 100 | - $locator = Injector::inst()->create(Locator::class); |
|
| 101 | - $radii = [ |
|
| 102 | - '0' => '5', |
|
| 103 | - '1' => '10', |
|
| 104 | - '2' => '15', |
|
| 105 | - '3' => '100', |
|
| 106 | - ]; |
|
| 107 | - Config::modify()->set(Locator::class, 'radii', $radii); |
|
| 108 | - $this->assertEquals($radii, $locator->getRadii()); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * |
|
| 113 | - */ |
|
| 114 | - public function testGetRadiiArrayList() |
|
| 115 | - { |
|
| 116 | - /** @var Locator $locator */ |
|
| 117 | - $locator = Injector::inst()->create(Locator::class); |
|
| 118 | - $this->assertInstanceOf(ArrayList::class, $locator->getRadiiArrayList()); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * |
|
| 123 | - */ |
|
| 124 | - public function testGetLimit() |
|
| 125 | - { |
|
| 126 | - /** @var Locator $locator */ |
|
| 127 | - $locator = Injector::inst()->create(Locator::class); |
|
| 128 | - $this->assertEquals(50, $locator->getLimit()); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * |
|
| 133 | - */ |
|
| 134 | - public function testGetShowRadius() |
|
| 135 | - { |
|
| 136 | - /** @var Locator $locator */ |
|
| 137 | - $locator = Injector::inst()->create(Locator::class); |
|
| 138 | - $this->assertTrue($locator->getShowRadius()); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * |
|
| 143 | - */ |
|
| 144 | - public function testGetUsedCategories() |
|
| 145 | - { |
|
| 146 | - /** @var Locator $locator */ |
|
| 147 | - $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 148 | - |
|
| 149 | - $categories = $locator->getUsedCategories()->toArray(); |
|
| 150 | - $this->assertEquals(1, count($categories)); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * |
|
| 155 | - */ |
|
| 156 | - public function testGetInfoWindowTemplate() |
|
| 157 | - { |
|
| 158 | - /** @var Locator $object */ |
|
| 159 | - $object = Injector::inst()->create(Locator::class); |
|
| 160 | - $template = $object->getInfoWindowTemplate(); |
|
| 161 | - // get rid of cache ending |
|
| 162 | - $template = preg_replace('/\?.*$/', '', $template); |
|
| 163 | - $this->assertStringEndsWith('client/infowindow-description.html', $template); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * |
|
| 168 | - */ |
|
| 169 | - public function testGetListTemplate() |
|
| 170 | - { |
|
| 171 | - /** @var Locator $object */ |
|
| 172 | - $object = Injector::inst()->create(Locator::class); |
|
| 173 | - $template = $object->getListTemplate(); |
|
| 174 | - // get rid of cache ending |
|
| 175 | - $template = preg_replace('/\?.*$/', '', $template); |
|
| 176 | - $this->assertStringEndsWith('client/location-list-description.html', $template); |
|
| 177 | - } |
|
| 24 | + /** |
|
| 25 | + * @var string |
|
| 26 | + */ |
|
| 27 | + protected static $fixture_file = '../fixtures.yml'; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * |
|
| 31 | + */ |
|
| 32 | + public function testGetCMSFields() |
|
| 33 | + { |
|
| 34 | + /** @var Locator $locator */ |
|
| 35 | + $locator = Injector::inst()->create(Locator::class); |
|
| 36 | + $this->assertInstanceOf(FieldList::class, $locator->getCMSFields()); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * |
|
| 41 | + */ |
|
| 42 | + public function testLocations() |
|
| 43 | + { |
|
| 44 | + $filter = Config::inst()->get(LocatorController::class, 'base_filter'); |
|
| 45 | + $filterAny = Config::inst()->get(LocatorController::class, 'base_filter_any'); |
|
| 46 | + $exclude = Config::inst()->get(LocatorController::class, 'base_exclude'); |
|
| 47 | + $locations = Locator::get_locations($filter, $filterAny, $exclude); |
|
| 48 | + $locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude); |
|
| 49 | + $this->assertEquals($locations->count(), $locations2->count()); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * |
|
| 54 | + */ |
|
| 55 | + public function testGetAllCategories() |
|
| 56 | + { |
|
| 57 | + $this->assertEquals(Locator::get_all_categories()->count(), 4); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * |
|
| 62 | + */ |
|
| 63 | + public function testGetPageCategories() |
|
| 64 | + { |
|
| 65 | + $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 66 | + $this->assertEquals($locator->getPageCategories()->count(), 1); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * |
|
| 71 | + */ |
|
| 72 | + public function testLocator_categories_by_locator() |
|
| 73 | + { |
|
| 74 | + $categories = Locator::locator_categories_by_locator(0); |
|
| 75 | + $this->assertFalse($categories); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * |
|
| 80 | + */ |
|
| 81 | + public function testLocatorCategoriesByLocator() |
|
| 82 | + { |
|
| 83 | + |
|
| 84 | + $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 85 | + $this->assertEquals(Locator::locator_categories_by_locator($locator->ID)->count(), 1); |
|
| 86 | + |
|
| 87 | + $newLocator = Locator::create(); |
|
| 88 | + $newLocator->Title = 'Locator 2'; |
|
| 89 | + $newLocator->write(); |
|
| 90 | + |
|
| 91 | + $this->assertEquals(Locator::locator_categories_by_locator($newLocator->ID)->count(), 0); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * |
|
| 96 | + */ |
|
| 97 | + public function testGetRadii() |
|
| 98 | + { |
|
| 99 | + /** @var Locator $locator */ |
|
| 100 | + $locator = Injector::inst()->create(Locator::class); |
|
| 101 | + $radii = [ |
|
| 102 | + '0' => '5', |
|
| 103 | + '1' => '10', |
|
| 104 | + '2' => '15', |
|
| 105 | + '3' => '100', |
|
| 106 | + ]; |
|
| 107 | + Config::modify()->set(Locator::class, 'radii', $radii); |
|
| 108 | + $this->assertEquals($radii, $locator->getRadii()); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * |
|
| 113 | + */ |
|
| 114 | + public function testGetRadiiArrayList() |
|
| 115 | + { |
|
| 116 | + /** @var Locator $locator */ |
|
| 117 | + $locator = Injector::inst()->create(Locator::class); |
|
| 118 | + $this->assertInstanceOf(ArrayList::class, $locator->getRadiiArrayList()); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * |
|
| 123 | + */ |
|
| 124 | + public function testGetLimit() |
|
| 125 | + { |
|
| 126 | + /** @var Locator $locator */ |
|
| 127 | + $locator = Injector::inst()->create(Locator::class); |
|
| 128 | + $this->assertEquals(50, $locator->getLimit()); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * |
|
| 133 | + */ |
|
| 134 | + public function testGetShowRadius() |
|
| 135 | + { |
|
| 136 | + /** @var Locator $locator */ |
|
| 137 | + $locator = Injector::inst()->create(Locator::class); |
|
| 138 | + $this->assertTrue($locator->getShowRadius()); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * |
|
| 143 | + */ |
|
| 144 | + public function testGetUsedCategories() |
|
| 145 | + { |
|
| 146 | + /** @var Locator $locator */ |
|
| 147 | + $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 148 | + |
|
| 149 | + $categories = $locator->getUsedCategories()->toArray(); |
|
| 150 | + $this->assertEquals(1, count($categories)); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * |
|
| 155 | + */ |
|
| 156 | + public function testGetInfoWindowTemplate() |
|
| 157 | + { |
|
| 158 | + /** @var Locator $object */ |
|
| 159 | + $object = Injector::inst()->create(Locator::class); |
|
| 160 | + $template = $object->getInfoWindowTemplate(); |
|
| 161 | + // get rid of cache ending |
|
| 162 | + $template = preg_replace('/\?.*$/', '', $template); |
|
| 163 | + $this->assertStringEndsWith('client/infowindow-description.html', $template); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * |
|
| 168 | + */ |
|
| 169 | + public function testGetListTemplate() |
|
| 170 | + { |
|
| 171 | + /** @var Locator $object */ |
|
| 172 | + $object = Injector::inst()->create(Locator::class); |
|
| 173 | + $template = $object->getListTemplate(); |
|
| 174 | + // get rid of cache ending |
|
| 175 | + $template = preg_replace('/\?.*$/', '', $template); |
|
| 176 | + $this->assertStringEndsWith('client/location-list-description.html', $template); |
|
| 177 | + } |
|
| 178 | 178 | } |
@@ -18,131 +18,131 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class LocatorController extends \PageController |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - private static $allowed_actions = [ |
|
| 25 | - 'xml', |
|
| 26 | - 'json', |
|
| 27 | - ]; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - private static $base_filter = []; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var array |
|
| 36 | - */ |
|
| 37 | - private static $base_exclude = [ |
|
| 38 | - 'Lat' => 0, |
|
| 39 | - 'Lng' => 0, |
|
| 40 | - ]; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var array |
|
| 44 | - */ |
|
| 45 | - private static $base_filter_any = []; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var bool |
|
| 49 | - */ |
|
| 50 | - private static $bootstrapify = true; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * ID of map container |
|
| 54 | - * |
|
| 55 | - * @var string |
|
| 56 | - */ |
|
| 57 | - private static $map_container = 'map'; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * class of location list container |
|
| 61 | - * |
|
| 62 | - * @var string |
|
| 63 | - */ |
|
| 64 | - private static $list_container = 'loc-list'; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * GET variable which, if isset, will trigger storeLocator init and return XML |
|
| 68 | - * |
|
| 69 | - * @var string |
|
| 70 | - */ |
|
| 71 | - private static $query_trigger = 'action_doFilterLocations'; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @var DataList|ArrayList |
|
| 75 | - */ |
|
| 76 | - protected $locations; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Set Requirements based on input from CMS |
|
| 80 | - */ |
|
| 81 | - public function init() |
|
| 82 | - { |
|
| 83 | - parent::init(); |
|
| 84 | - // google maps api key |
|
| 85 | - $key = Config::inst()->get(GoogleGeocoder::class, 'map_api_key'); |
|
| 86 | - Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key); |
|
| 87 | - |
|
| 88 | - // prevent init of map if no query |
|
| 89 | - $request = Controller::curr()->getRequest(); |
|
| 90 | - |
|
| 91 | - if ($this->getTrigger($request)) { |
|
| 92 | - $locations = $this->getLocations(); |
|
| 93 | - |
|
| 94 | - if ($locations) { |
|
| 95 | - $featuredInList = ($locations->filter('Featured', true)->count() > 0); |
|
| 96 | - $defaultCoords = $this->getAddressSearchCoords() ? |
|
| 97 | - $this->getAddressSearchCoords() : |
|
| 98 | - new ArrayData([ |
|
| 99 | - "Lat" => 0, |
|
| 100 | - "Lng" => 0, |
|
| 101 | - ]); |
|
| 102 | - |
|
| 103 | - $featured = $featuredInList |
|
| 104 | - ? 'featuredLocations: true' |
|
| 105 | - : 'featuredLocations: false'; |
|
| 106 | - |
|
| 107 | - // map config based on user input in Settings tab |
|
| 108 | - $limit = Config::inst()->get(LocatorController::class, 'limit'); |
|
| 109 | - if ($limit < 1) { |
|
| 110 | - $limit = -1; |
|
| 111 | - } |
|
| 112 | - $load = 'fullMapStart: true, storeLimit: ' . $limit . ', maxDistance: true,'; |
|
| 113 | - |
|
| 114 | - $listTemplatePath = $this->getListTemplate(); |
|
| 115 | - $infowindowTemplatePath = $this->getInfoWindowTemplate(); |
|
| 116 | - |
|
| 117 | - $kilometer = ($this->data()->Unit == 'km') ? "lengthUnit: 'km'" : "lengthUnit: 'm'"; |
|
| 118 | - |
|
| 119 | - // pass GET variables to xml action |
|
| 120 | - $vars = $this->request->getVars(); |
|
| 121 | - unset($vars['url']); |
|
| 122 | - $url = ''; |
|
| 123 | - if (count($vars)) { |
|
| 124 | - $url .= '?' . http_build_query($vars); |
|
| 125 | - } |
|
| 126 | - $link = Controller::join_links($this->Link(), 'xml.xml', $url); |
|
| 127 | - |
|
| 128 | - // containers |
|
| 129 | - $map_id = Config::inst()->get(LocatorController::class, 'map_container'); |
|
| 130 | - $list_class = Config::inst()->get(LocatorController::class, 'list_container'); |
|
| 131 | - |
|
| 132 | - $mapStyle = ''; |
|
| 133 | - if ($stylePath = $this->getMapStyleJSONPath()) { |
|
| 134 | - if ($style = file_get_contents($stylePath)) { |
|
| 135 | - $mapStyle = "styles: {$style},"; |
|
| 136 | - } |
|
| 137 | - }; |
|
| 138 | - |
|
| 139 | - $markerImage = ''; |
|
| 140 | - if ($imagePath = $this->getMarkerIcon()) { |
|
| 141 | - $markerImage = "markerImg: '{$imagePath}',"; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - // init map |
|
| 145 | - Requirements::customScript(" |
|
| 21 | + /** |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + private static $allowed_actions = [ |
|
| 25 | + 'xml', |
|
| 26 | + 'json', |
|
| 27 | + ]; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + private static $base_filter = []; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var array |
|
| 36 | + */ |
|
| 37 | + private static $base_exclude = [ |
|
| 38 | + 'Lat' => 0, |
|
| 39 | + 'Lng' => 0, |
|
| 40 | + ]; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var array |
|
| 44 | + */ |
|
| 45 | + private static $base_filter_any = []; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var bool |
|
| 49 | + */ |
|
| 50 | + private static $bootstrapify = true; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * ID of map container |
|
| 54 | + * |
|
| 55 | + * @var string |
|
| 56 | + */ |
|
| 57 | + private static $map_container = 'map'; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * class of location list container |
|
| 61 | + * |
|
| 62 | + * @var string |
|
| 63 | + */ |
|
| 64 | + private static $list_container = 'loc-list'; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * GET variable which, if isset, will trigger storeLocator init and return XML |
|
| 68 | + * |
|
| 69 | + * @var string |
|
| 70 | + */ |
|
| 71 | + private static $query_trigger = 'action_doFilterLocations'; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @var DataList|ArrayList |
|
| 75 | + */ |
|
| 76 | + protected $locations; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Set Requirements based on input from CMS |
|
| 80 | + */ |
|
| 81 | + public function init() |
|
| 82 | + { |
|
| 83 | + parent::init(); |
|
| 84 | + // google maps api key |
|
| 85 | + $key = Config::inst()->get(GoogleGeocoder::class, 'map_api_key'); |
|
| 86 | + Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key); |
|
| 87 | + |
|
| 88 | + // prevent init of map if no query |
|
| 89 | + $request = Controller::curr()->getRequest(); |
|
| 90 | + |
|
| 91 | + if ($this->getTrigger($request)) { |
|
| 92 | + $locations = $this->getLocations(); |
|
| 93 | + |
|
| 94 | + if ($locations) { |
|
| 95 | + $featuredInList = ($locations->filter('Featured', true)->count() > 0); |
|
| 96 | + $defaultCoords = $this->getAddressSearchCoords() ? |
|
| 97 | + $this->getAddressSearchCoords() : |
|
| 98 | + new ArrayData([ |
|
| 99 | + "Lat" => 0, |
|
| 100 | + "Lng" => 0, |
|
| 101 | + ]); |
|
| 102 | + |
|
| 103 | + $featured = $featuredInList |
|
| 104 | + ? 'featuredLocations: true' |
|
| 105 | + : 'featuredLocations: false'; |
|
| 106 | + |
|
| 107 | + // map config based on user input in Settings tab |
|
| 108 | + $limit = Config::inst()->get(LocatorController::class, 'limit'); |
|
| 109 | + if ($limit < 1) { |
|
| 110 | + $limit = -1; |
|
| 111 | + } |
|
| 112 | + $load = 'fullMapStart: true, storeLimit: ' . $limit . ', maxDistance: true,'; |
|
| 113 | + |
|
| 114 | + $listTemplatePath = $this->getListTemplate(); |
|
| 115 | + $infowindowTemplatePath = $this->getInfoWindowTemplate(); |
|
| 116 | + |
|
| 117 | + $kilometer = ($this->data()->Unit == 'km') ? "lengthUnit: 'km'" : "lengthUnit: 'm'"; |
|
| 118 | + |
|
| 119 | + // pass GET variables to xml action |
|
| 120 | + $vars = $this->request->getVars(); |
|
| 121 | + unset($vars['url']); |
|
| 122 | + $url = ''; |
|
| 123 | + if (count($vars)) { |
|
| 124 | + $url .= '?' . http_build_query($vars); |
|
| 125 | + } |
|
| 126 | + $link = Controller::join_links($this->Link(), 'xml.xml', $url); |
|
| 127 | + |
|
| 128 | + // containers |
|
| 129 | + $map_id = Config::inst()->get(LocatorController::class, 'map_container'); |
|
| 130 | + $list_class = Config::inst()->get(LocatorController::class, 'list_container'); |
|
| 131 | + |
|
| 132 | + $mapStyle = ''; |
|
| 133 | + if ($stylePath = $this->getMapStyleJSONPath()) { |
|
| 134 | + if ($style = file_get_contents($stylePath)) { |
|
| 135 | + $mapStyle = "styles: {$style},"; |
|
| 136 | + } |
|
| 137 | + }; |
|
| 138 | + |
|
| 139 | + $markerImage = ''; |
|
| 140 | + if ($imagePath = $this->getMarkerIcon()) { |
|
| 141 | + $markerImage = "markerImg: '{$imagePath}',"; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + // init map |
|
| 145 | + Requirements::customScript(" |
|
| 146 | 146 | $(function(){ |
| 147 | 147 | $('#map-container').storeLocator({ |
| 148 | 148 | {$load} |
@@ -171,194 +171,194 @@ discard block |
||
| 171 | 171 | }); |
| 172 | 172 | }); |
| 173 | 173 | ", 'jquery-locator'); |
| 174 | - } |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * @param HTTPRequest $request |
|
| 180 | - * |
|
| 181 | - * @return bool |
|
| 182 | - */ |
|
| 183 | - public function getTrigger(HTTPRequest $request = null) |
|
| 184 | - { |
|
| 185 | - if ($request === null) { |
|
| 186 | - $request = $this->getRequest(); |
|
| 187 | - } |
|
| 188 | - $trigger = $request->getVar(Config::inst()->get(LocatorController::class, 'query_trigger')); |
|
| 189 | - |
|
| 190 | - return isset($trigger); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * @return ArrayList|DataList |
|
| 195 | - */ |
|
| 196 | - public function getLocations() |
|
| 197 | - { |
|
| 198 | - if (!$this->locations) { |
|
| 199 | - $this->setLocations($this->request); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return $this->locations; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * @param HTTPRequest|null $request |
|
| 207 | - * |
|
| 208 | - * @return $this |
|
| 209 | - */ |
|
| 210 | - public function setLocations(HTTPRequest $request = null) |
|
| 211 | - { |
|
| 212 | - |
|
| 213 | - if ($request === null) { |
|
| 214 | - $request = $this->request; |
|
| 215 | - } |
|
| 216 | - $filter = $this->config()->get('base_filter'); |
|
| 217 | - |
|
| 218 | - $categoryVar = Config::inst()->get(Locator::class, 'category_var'); |
|
| 219 | - if ($request->getVar($categoryVar)) { |
|
| 220 | - $filter['Categories.ID'] = $request->getVar($categoryVar); |
|
| 221 | - } else { |
|
| 222 | - if ($this->getPageCategories()->exists()) { |
|
| 223 | - foreach ($this->getPageCategories() as $category) { |
|
| 224 | - $filter['Categories.ID'][] = $category->ID; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - $this->extend('updateLocatorFilter', $filter, $request); |
|
| 230 | - |
|
| 231 | - $filterAny = $this->config()->get('base_filter_any'); |
|
| 232 | - $this->extend('updateLocatorFilterAny', $filterAny, $request); |
|
| 233 | - |
|
| 234 | - $exclude = $this->config()->get('base_exclude'); |
|
| 235 | - $this->extend('updateLocatorExclude', $exclude, $request); |
|
| 236 | - |
|
| 237 | - $locations = Locator::get_locations($filter, $filterAny, $exclude); |
|
| 238 | - $locations = DataToArrayListHelper::to_array_list($locations); |
|
| 239 | - |
|
| 240 | - //allow for adjusting list post possible distance calculation |
|
| 241 | - $this->extend('updateLocationList', $locations); |
|
| 242 | - |
|
| 243 | - if ($locations->canSortBy('Distance')) { |
|
| 244 | - $locations = $locations->sort('Distance'); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - if ($this->getShowRadius()) { |
|
| 248 | - $radiusVar = Config::inst()->get(Locator::class, 'radius_var'); |
|
| 249 | - |
|
| 250 | - if ($radius = (int)$request->getVar($radiusVar)) { |
|
| 251 | - $locations = $locations->filterByCallback(function ($location) use (&$radius) { |
|
| 252 | - return $location->Distance <= $radius; |
|
| 253 | - }); |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - //allow for returning list to be set as |
|
| 258 | - $this->extend('updateListType', $locations); |
|
| 259 | - |
|
| 260 | - $limit = $this->getLimit(); |
|
| 261 | - if ($limit > 0) { |
|
| 262 | - $locations = $locations->limit($limit); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - $this->locations = $locations; |
|
| 266 | - |
|
| 267 | - return $this; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * @return ArrayData|boolean |
|
| 272 | - */ |
|
| 273 | - public function getAddressSearchCoords() |
|
| 274 | - { |
|
| 275 | - $addressVar = Config::inst()->get(DistanceDataExtension::class, 'address_var'); |
|
| 276 | - if (!$this->request->getVar($addressVar)) { |
|
| 277 | - return false; |
|
| 278 | - } |
|
| 279 | - if (class_exists(GoogleGeocoder::class)) { |
|
| 280 | - $geocoder = new GoogleGeocoder($this->request->getVar($addressVar)); |
|
| 281 | - $response = $geocoder->getResult(); |
|
| 282 | - $lat = $response->getLatitude(); |
|
| 283 | - $lng = $response->getLongitude(); |
|
| 284 | - |
|
| 285 | - return new ArrayData([ |
|
| 286 | - "Lat" => $lat, |
|
| 287 | - "Lng" => $lng, |
|
| 288 | - ]); |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * @param HTTPRequest $request |
|
| 294 | - * |
|
| 295 | - * @return \SilverStripe\View\ViewableData_Customised |
|
| 296 | - */ |
|
| 297 | - public function index(HTTPRequest $request) |
|
| 298 | - { |
|
| 299 | - if ($this->getTrigger($request)) { |
|
| 300 | - $locations = $this->getLocations(); |
|
| 301 | - } else { |
|
| 302 | - $locations = ArrayList::create(); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - return $this->customise(array( |
|
| 306 | - 'Locations' => $locations, |
|
| 307 | - )); |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * Renders locations in xml format |
|
| 312 | - * |
|
| 313 | - * @return \SilverStripe\ORM\FieldType\DBHTMLText |
|
| 314 | - */ |
|
| 315 | - public function xml() |
|
| 316 | - { |
|
| 317 | - $this->getResponse()->addHeader("Content-Type", "application/xml"); |
|
| 318 | - $data = new ArrayData(array( |
|
| 319 | - "Locations" => $this->getLocations(), |
|
| 320 | - "AddressCoords" => $this->getAddressSearchCoords(), |
|
| 321 | - )); |
|
| 322 | - |
|
| 323 | - return $data->renderWith('Dynamic/Locator/Data/XML'); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Renders locations in json format |
|
| 328 | - * |
|
| 329 | - * @return \SilverStripe\ORM\FieldType\DBHTMLText |
|
| 330 | - */ |
|
| 331 | - public function json() |
|
| 332 | - { |
|
| 333 | - $this->getResponse()->addHeader("Content-Type", "application/json"); |
|
| 334 | - $data = new ArrayData(array( |
|
| 335 | - "Locations" => $this->getLocations(), |
|
| 336 | - "AddressCoords" => $this->getAddressSearchCoords(), |
|
| 337 | - )); |
|
| 338 | - |
|
| 339 | - return $data->renderWith('Dynamic/Locator/Data/JSON'); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * LocationSearch form. |
|
| 344 | - * |
|
| 345 | - * Search form for locations, updates map and results list via AJAX |
|
| 346 | - * |
|
| 347 | - * @return \SilverStripe\Forms\Form |
|
| 348 | - */ |
|
| 349 | - public function LocationSearch() |
|
| 350 | - { |
|
| 351 | - |
|
| 352 | - $form = LocatorForm::create($this, 'LocationSearch'); |
|
| 353 | - if (class_exists(BootstrapForm::class) && $this->config()->get('bootstrapify')) { |
|
| 354 | - $form->Fields()->bootstrapify(); |
|
| 355 | - $form->Actions()->bootstrapify(); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - return $form |
|
| 359 | - ->setFormMethod('GET') |
|
| 360 | - ->setFormAction($this->Link()) |
|
| 361 | - ->disableSecurityToken() |
|
| 362 | - ->loadDataFrom($this->request->getVars()); |
|
| 363 | - } |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * @param HTTPRequest $request |
|
| 180 | + * |
|
| 181 | + * @return bool |
|
| 182 | + */ |
|
| 183 | + public function getTrigger(HTTPRequest $request = null) |
|
| 184 | + { |
|
| 185 | + if ($request === null) { |
|
| 186 | + $request = $this->getRequest(); |
|
| 187 | + } |
|
| 188 | + $trigger = $request->getVar(Config::inst()->get(LocatorController::class, 'query_trigger')); |
|
| 189 | + |
|
| 190 | + return isset($trigger); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * @return ArrayList|DataList |
|
| 195 | + */ |
|
| 196 | + public function getLocations() |
|
| 197 | + { |
|
| 198 | + if (!$this->locations) { |
|
| 199 | + $this->setLocations($this->request); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return $this->locations; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * @param HTTPRequest|null $request |
|
| 207 | + * |
|
| 208 | + * @return $this |
|
| 209 | + */ |
|
| 210 | + public function setLocations(HTTPRequest $request = null) |
|
| 211 | + { |
|
| 212 | + |
|
| 213 | + if ($request === null) { |
|
| 214 | + $request = $this->request; |
|
| 215 | + } |
|
| 216 | + $filter = $this->config()->get('base_filter'); |
|
| 217 | + |
|
| 218 | + $categoryVar = Config::inst()->get(Locator::class, 'category_var'); |
|
| 219 | + if ($request->getVar($categoryVar)) { |
|
| 220 | + $filter['Categories.ID'] = $request->getVar($categoryVar); |
|
| 221 | + } else { |
|
| 222 | + if ($this->getPageCategories()->exists()) { |
|
| 223 | + foreach ($this->getPageCategories() as $category) { |
|
| 224 | + $filter['Categories.ID'][] = $category->ID; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + $this->extend('updateLocatorFilter', $filter, $request); |
|
| 230 | + |
|
| 231 | + $filterAny = $this->config()->get('base_filter_any'); |
|
| 232 | + $this->extend('updateLocatorFilterAny', $filterAny, $request); |
|
| 233 | + |
|
| 234 | + $exclude = $this->config()->get('base_exclude'); |
|
| 235 | + $this->extend('updateLocatorExclude', $exclude, $request); |
|
| 236 | + |
|
| 237 | + $locations = Locator::get_locations($filter, $filterAny, $exclude); |
|
| 238 | + $locations = DataToArrayListHelper::to_array_list($locations); |
|
| 239 | + |
|
| 240 | + //allow for adjusting list post possible distance calculation |
|
| 241 | + $this->extend('updateLocationList', $locations); |
|
| 242 | + |
|
| 243 | + if ($locations->canSortBy('Distance')) { |
|
| 244 | + $locations = $locations->sort('Distance'); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + if ($this->getShowRadius()) { |
|
| 248 | + $radiusVar = Config::inst()->get(Locator::class, 'radius_var'); |
|
| 249 | + |
|
| 250 | + if ($radius = (int)$request->getVar($radiusVar)) { |
|
| 251 | + $locations = $locations->filterByCallback(function ($location) use (&$radius) { |
|
| 252 | + return $location->Distance <= $radius; |
|
| 253 | + }); |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + //allow for returning list to be set as |
|
| 258 | + $this->extend('updateListType', $locations); |
|
| 259 | + |
|
| 260 | + $limit = $this->getLimit(); |
|
| 261 | + if ($limit > 0) { |
|
| 262 | + $locations = $locations->limit($limit); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + $this->locations = $locations; |
|
| 266 | + |
|
| 267 | + return $this; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * @return ArrayData|boolean |
|
| 272 | + */ |
|
| 273 | + public function getAddressSearchCoords() |
|
| 274 | + { |
|
| 275 | + $addressVar = Config::inst()->get(DistanceDataExtension::class, 'address_var'); |
|
| 276 | + if (!$this->request->getVar($addressVar)) { |
|
| 277 | + return false; |
|
| 278 | + } |
|
| 279 | + if (class_exists(GoogleGeocoder::class)) { |
|
| 280 | + $geocoder = new GoogleGeocoder($this->request->getVar($addressVar)); |
|
| 281 | + $response = $geocoder->getResult(); |
|
| 282 | + $lat = $response->getLatitude(); |
|
| 283 | + $lng = $response->getLongitude(); |
|
| 284 | + |
|
| 285 | + return new ArrayData([ |
|
| 286 | + "Lat" => $lat, |
|
| 287 | + "Lng" => $lng, |
|
| 288 | + ]); |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * @param HTTPRequest $request |
|
| 294 | + * |
|
| 295 | + * @return \SilverStripe\View\ViewableData_Customised |
|
| 296 | + */ |
|
| 297 | + public function index(HTTPRequest $request) |
|
| 298 | + { |
|
| 299 | + if ($this->getTrigger($request)) { |
|
| 300 | + $locations = $this->getLocations(); |
|
| 301 | + } else { |
|
| 302 | + $locations = ArrayList::create(); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + return $this->customise(array( |
|
| 306 | + 'Locations' => $locations, |
|
| 307 | + )); |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * Renders locations in xml format |
|
| 312 | + * |
|
| 313 | + * @return \SilverStripe\ORM\FieldType\DBHTMLText |
|
| 314 | + */ |
|
| 315 | + public function xml() |
|
| 316 | + { |
|
| 317 | + $this->getResponse()->addHeader("Content-Type", "application/xml"); |
|
| 318 | + $data = new ArrayData(array( |
|
| 319 | + "Locations" => $this->getLocations(), |
|
| 320 | + "AddressCoords" => $this->getAddressSearchCoords(), |
|
| 321 | + )); |
|
| 322 | + |
|
| 323 | + return $data->renderWith('Dynamic/Locator/Data/XML'); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Renders locations in json format |
|
| 328 | + * |
|
| 329 | + * @return \SilverStripe\ORM\FieldType\DBHTMLText |
|
| 330 | + */ |
|
| 331 | + public function json() |
|
| 332 | + { |
|
| 333 | + $this->getResponse()->addHeader("Content-Type", "application/json"); |
|
| 334 | + $data = new ArrayData(array( |
|
| 335 | + "Locations" => $this->getLocations(), |
|
| 336 | + "AddressCoords" => $this->getAddressSearchCoords(), |
|
| 337 | + )); |
|
| 338 | + |
|
| 339 | + return $data->renderWith('Dynamic/Locator/Data/JSON'); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * LocationSearch form. |
|
| 344 | + * |
|
| 345 | + * Search form for locations, updates map and results list via AJAX |
|
| 346 | + * |
|
| 347 | + * @return \SilverStripe\Forms\Form |
|
| 348 | + */ |
|
| 349 | + public function LocationSearch() |
|
| 350 | + { |
|
| 351 | + |
|
| 352 | + $form = LocatorForm::create($this, 'LocationSearch'); |
|
| 353 | + if (class_exists(BootstrapForm::class) && $this->config()->get('bootstrapify')) { |
|
| 354 | + $form->Fields()->bootstrapify(); |
|
| 355 | + $form->Actions()->bootstrapify(); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + return $form |
|
| 359 | + ->setFormMethod('GET') |
|
| 360 | + ->setFormAction($this->Link()) |
|
| 361 | + ->disableSecurityToken() |
|
| 362 | + ->loadDataFrom($this->request->getVars()); |
|
| 363 | + } |
|
| 364 | 364 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | parent::init(); |
| 84 | 84 | // google maps api key |
| 85 | 85 | $key = Config::inst()->get(GoogleGeocoder::class, 'map_api_key'); |
| 86 | - Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key); |
|
| 86 | + Requirements::javascript('https://maps.google.com/maps/api/js?key='.$key); |
|
| 87 | 87 | |
| 88 | 88 | // prevent init of map if no query |
| 89 | 89 | $request = Controller::curr()->getRequest(); |
@@ -94,8 +94,7 @@ discard block |
||
| 94 | 94 | if ($locations) { |
| 95 | 95 | $featuredInList = ($locations->filter('Featured', true)->count() > 0); |
| 96 | 96 | $defaultCoords = $this->getAddressSearchCoords() ? |
| 97 | - $this->getAddressSearchCoords() : |
|
| 98 | - new ArrayData([ |
|
| 97 | + $this->getAddressSearchCoords() : new ArrayData([ |
|
| 99 | 98 | "Lat" => 0, |
| 100 | 99 | "Lng" => 0, |
| 101 | 100 | ]); |
@@ -109,7 +108,7 @@ discard block |
||
| 109 | 108 | if ($limit < 1) { |
| 110 | 109 | $limit = -1; |
| 111 | 110 | } |
| 112 | - $load = 'fullMapStart: true, storeLimit: ' . $limit . ', maxDistance: true,'; |
|
| 111 | + $load = 'fullMapStart: true, storeLimit: '.$limit.', maxDistance: true,'; |
|
| 113 | 112 | |
| 114 | 113 | $listTemplatePath = $this->getListTemplate(); |
| 115 | 114 | $infowindowTemplatePath = $this->getInfoWindowTemplate(); |
@@ -121,7 +120,7 @@ discard block |
||
| 121 | 120 | unset($vars['url']); |
| 122 | 121 | $url = ''; |
| 123 | 122 | if (count($vars)) { |
| 124 | - $url .= '?' . http_build_query($vars); |
|
| 123 | + $url .= '?'.http_build_query($vars); |
|
| 125 | 124 | } |
| 126 | 125 | $link = Controller::join_links($this->Link(), 'xml.xml', $url); |
| 127 | 126 | |
@@ -247,8 +246,8 @@ discard block |
||
| 247 | 246 | if ($this->getShowRadius()) { |
| 248 | 247 | $radiusVar = Config::inst()->get(Locator::class, 'radius_var'); |
| 249 | 248 | |
| 250 | - if ($radius = (int)$request->getVar($radiusVar)) { |
|
| 251 | - $locations = $locations->filterByCallback(function ($location) use (&$radius) { |
|
| 249 | + if ($radius = (int) $request->getVar($radiusVar)) { |
|
| 250 | + $locations = $locations->filterByCallback(function($location) use (&$radius) { |
|
| 252 | 251 | return $location->Distance <= $radius; |
| 253 | 252 | }); |
| 254 | 253 | } |
@@ -19,88 +19,88 @@ |
||
| 19 | 19 | class LocatorForm extends Form |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * LocatorForm constructor. |
|
| 24 | - * @param Controller $controller |
|
| 25 | - * @param string $name |
|
| 26 | - */ |
|
| 27 | - public function __construct(Controller $controller, $name) |
|
| 28 | - { |
|
| 22 | + /** |
|
| 23 | + * LocatorForm constructor. |
|
| 24 | + * @param Controller $controller |
|
| 25 | + * @param string $name |
|
| 26 | + */ |
|
| 27 | + public function __construct(Controller $controller, $name) |
|
| 28 | + { |
|
| 29 | 29 | |
| 30 | - $fields = FieldList::create( |
|
| 31 | - TextField::create('Address') |
|
| 32 | - ->setTitle('') |
|
| 33 | - ->setAttribute('placeholder', 'address or zip code') |
|
| 34 | - ); |
|
| 30 | + $fields = FieldList::create( |
|
| 31 | + TextField::create('Address') |
|
| 32 | + ->setTitle('') |
|
| 33 | + ->setAttribute('placeholder', 'address or zip code') |
|
| 34 | + ); |
|
| 35 | 35 | |
| 36 | - $pageCategories = Locator::locator_categories_by_locator($controller->data()->ID); |
|
| 37 | - if ($pageCategories && $pageCategories->count() > 0) { |
|
| 38 | - $categories = false; |
|
| 39 | - } else { |
|
| 40 | - $categories = Locator::get_all_categories(); |
|
| 41 | - if ($categories->count() < 1) { |
|
| 42 | - $categories = false; |
|
| 43 | - } |
|
| 44 | - } |
|
| 36 | + $pageCategories = Locator::locator_categories_by_locator($controller->data()->ID); |
|
| 37 | + if ($pageCategories && $pageCategories->count() > 0) { |
|
| 38 | + $categories = false; |
|
| 39 | + } else { |
|
| 40 | + $categories = Locator::get_all_categories(); |
|
| 41 | + if ($categories->count() < 1) { |
|
| 42 | + $categories = false; |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - if ($categories) { |
|
| 47 | - $categoriesField = DropdownField::create('CategoryID') |
|
| 48 | - ->setTitle('') |
|
| 49 | - ->setEmptyString('all categories') |
|
| 50 | - ->setSource($categories->map()); |
|
| 51 | - $fields->push($categoriesField); |
|
| 52 | - } |
|
| 46 | + if ($categories) { |
|
| 47 | + $categoriesField = DropdownField::create('CategoryID') |
|
| 48 | + ->setTitle('') |
|
| 49 | + ->setEmptyString('all categories') |
|
| 50 | + ->setSource($categories->map()); |
|
| 51 | + $fields->push($categoriesField); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - if ($controller->getShowRadius()) { |
|
| 55 | - $radiusArray = array_values($controller->getRadii()); |
|
| 56 | - $this->extend('overrideRadiusArray', $radiusArray); |
|
| 57 | - $fields->push(DropdownField::create('Radius', '', ArrayLib::valuekey($radiusArray)) |
|
| 58 | - ->setEmptyString('radius')); |
|
| 59 | - } |
|
| 54 | + if ($controller->getShowRadius()) { |
|
| 55 | + $radiusArray = array_values($controller->getRadii()); |
|
| 56 | + $this->extend('overrideRadiusArray', $radiusArray); |
|
| 57 | + $fields->push(DropdownField::create('Radius', '', ArrayLib::valuekey($radiusArray)) |
|
| 58 | + ->setEmptyString('radius')); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $actions = FieldList::create( |
|
| 62 | - FormAction::create('doFilterLocations') |
|
| 63 | - ->setTitle('Search') |
|
| 64 | - ); |
|
| 61 | + $actions = FieldList::create( |
|
| 62 | + FormAction::create('doFilterLocations') |
|
| 63 | + ->setTitle('Search') |
|
| 64 | + ); |
|
| 65 | 65 | |
| 66 | - $validator = $this->getValidator(); |
|
| 66 | + $validator = $this->getValidator(); |
|
| 67 | 67 | |
| 68 | - parent::__construct($controller, $name, $fields, $actions, $validator); |
|
| 69 | - } |
|
| 68 | + parent::__construct($controller, $name, $fields, $actions, $validator); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @return null|RequiredFields|\SilverStripe\Forms\Validator |
|
| 73 | - */ |
|
| 74 | - public function getValidator() |
|
| 75 | - { |
|
| 76 | - $validator = parent::getValidator(); |
|
| 77 | - if (empty($validator)) { |
|
| 78 | - if (!$this->validator instanceof RequiredFields) { |
|
| 79 | - $this->setValidator(RequiredFields::create('Address')); |
|
| 80 | - } |
|
| 81 | - $validator = $this->validator; |
|
| 82 | - } |
|
| 83 | - $this->extend('updateRequiredFields', $validator); |
|
| 84 | - return $validator; |
|
| 85 | - } |
|
| 71 | + /** |
|
| 72 | + * @return null|RequiredFields|\SilverStripe\Forms\Validator |
|
| 73 | + */ |
|
| 74 | + public function getValidator() |
|
| 75 | + { |
|
| 76 | + $validator = parent::getValidator(); |
|
| 77 | + if (empty($validator)) { |
|
| 78 | + if (!$this->validator instanceof RequiredFields) { |
|
| 79 | + $this->setValidator(RequiredFields::create('Address')); |
|
| 80 | + } |
|
| 81 | + $validator = $this->validator; |
|
| 82 | + } |
|
| 83 | + $this->extend('updateRequiredFields', $validator); |
|
| 84 | + return $validator; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * @return FieldList |
|
| 89 | - */ |
|
| 90 | - public function Fields() |
|
| 91 | - { |
|
| 92 | - $fields = parent::Fields(); |
|
| 93 | - $this->extend('updateLocatorFormFields', $fields); |
|
| 94 | - return $fields; |
|
| 95 | - } |
|
| 87 | + /** |
|
| 88 | + * @return FieldList |
|
| 89 | + */ |
|
| 90 | + public function Fields() |
|
| 91 | + { |
|
| 92 | + $fields = parent::Fields(); |
|
| 93 | + $this->extend('updateLocatorFormFields', $fields); |
|
| 94 | + return $fields; |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * @return \SilverStripe\Forms\FieldList |
|
| 99 | - */ |
|
| 100 | - public function Actions() |
|
| 101 | - { |
|
| 102 | - $actions = parent::Actions(); |
|
| 103 | - $this->extend('updateLocatorActions', $actions); |
|
| 104 | - return $actions; |
|
| 105 | - } |
|
| 97 | + /** |
|
| 98 | + * @return \SilverStripe\Forms\FieldList |
|
| 99 | + */ |
|
| 100 | + public function Actions() |
|
| 101 | + { |
|
| 102 | + $actions = parent::Actions(); |
|
| 103 | + $this->extend('updateLocatorActions', $actions); |
|
| 104 | + return $actions; |
|
| 105 | + } |
|
| 106 | 106 | } |