@@ -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 | |
@@ -18,206 +18,206 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class LocationTest extends SapphireTest |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected static $fixture_file = '../fixtures.yml'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var array |
|
| 28 | - */ |
|
| 29 | - protected static $extra_dataobjects = [ |
|
| 30 | - ExtendedLocation::class, |
|
| 31 | - ]; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var array |
|
| 35 | - */ |
|
| 36 | - protected static $required_extensions = [ |
|
| 37 | - ExtendedLocation::class => [ |
|
| 38 | - LocationExtension::class, |
|
| 39 | - ], |
|
| 40 | - ]; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * |
|
| 44 | - */ |
|
| 45 | - public function testGetCoords() |
|
| 46 | - { |
|
| 47 | - $location = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 48 | - $coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false'; |
|
| 49 | - $this->assertEquals($coords, $location->getCoords()); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * |
|
| 54 | - */ |
|
| 55 | - public function testFieldLabels() |
|
| 56 | - { |
|
| 57 | - $this->markTestSkipped(); |
|
| 58 | - // Link and File tracking display as "Tracking" in SS 4.2 & 4.3, "Tracking" in 4.4 |
|
| 59 | - $location = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 60 | - $labels = $location->FieldLabels(); |
|
| 61 | - $expected = [ |
|
| 62 | - 'Title' => 'Name', |
|
| 63 | - 'Featured' => 'Featured', |
|
| 64 | - 'Website' => 'Website', |
|
| 65 | - 'Phone' => 'Phone', |
|
| 66 | - 'Email' => 'Email', |
|
| 67 | - 'Fax' => 'Fax', |
|
| 68 | - 'Address' => 'Address', |
|
| 69 | - 'City' => 'City', |
|
| 70 | - 'State' => 'State', |
|
| 71 | - 'PostalCode' => 'Postal Code', |
|
| 72 | - 'Country' => 'Country', |
|
| 73 | - 'Lat' => 'Lat', |
|
| 74 | - 'Lng' => 'Lng', |
|
| 75 | - 'Categories' => 'Categories', |
|
| 76 | - 'Category.Name' => 'Category', |
|
| 77 | - 'Category.ID' => 'Category', |
|
| 78 | - 'Featured.NiceAsBoolean' => 'Featured', |
|
| 79 | - 'Import_ID' => 'Import_ID', |
|
| 80 | - 'Version' => 'Version', |
|
| 81 | - 'Versions' => 'Versions', |
|
| 82 | - 'Address2' => 'Address2', |
|
| 83 | - 'LinkTracking' => 'Link tracking', |
|
| 84 | - 'FileTracking' => 'File tracking', |
|
| 85 | - ]; |
|
| 86 | - $this->assertEquals($expected, $labels); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * |
|
| 91 | - */ |
|
| 92 | - public function testGetCMSFields() |
|
| 93 | - { |
|
| 94 | - $object = new Location(); |
|
| 95 | - $fieldset = $object->getCMSFields(); |
|
| 96 | - $this->assertinstanceOf(FieldList::class, $fieldset); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * |
|
| 101 | - */ |
|
| 102 | - public function testCanView() |
|
| 103 | - { |
|
| 104 | - $object = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 105 | - $object->write(); |
|
| 106 | - |
|
| 107 | - $this->assertTrue($object->canView()); |
|
| 108 | - |
|
| 109 | - $nullMember = Member::create(); |
|
| 110 | - $nullMember->write(); |
|
| 111 | - |
|
| 112 | - $this->assertTrue($object->canView($nullMember)); |
|
| 113 | - |
|
| 114 | - $nullMember->delete(); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * |
|
| 119 | - */ |
|
| 120 | - public function testCanEdit() |
|
| 121 | - { |
|
| 122 | - $object = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 123 | - $object->write(); |
|
| 124 | - |
|
| 125 | - $objectID = $object->ID; |
|
| 126 | - |
|
| 127 | - //test permissions per permission setting |
|
| 128 | - $create = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 129 | - $edit = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 130 | - $delete = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 131 | - |
|
| 132 | - $originalTitle = $object->Title; |
|
| 133 | - $this->assertEquals($originalTitle, 'Dynamic, Inc.'); |
|
| 134 | - |
|
| 135 | - $this->assertTrue($object->canEdit($edit)); |
|
| 136 | - $this->assertFalse($object->canEdit($create)); |
|
| 137 | - $this->assertFalse($object->canEdit($delete)); |
|
| 138 | - |
|
| 139 | - $object->Title = 'Changed Title'; |
|
| 140 | - $object->write(); |
|
| 141 | - |
|
| 142 | - $testEdit = Location::get()->byID($objectID); |
|
| 143 | - $this->assertEquals($testEdit->Title, 'Changed Title'); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * |
|
| 148 | - */ |
|
| 149 | - public function testCanDelete() |
|
| 150 | - { |
|
| 151 | - $object = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 152 | - $object->write(); |
|
| 153 | - |
|
| 154 | - //test permissions per permission setting |
|
| 155 | - $create = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 156 | - $edit = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 157 | - $delete = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 158 | - |
|
| 159 | - $this->assertTrue($object->canDelete($delete)); |
|
| 160 | - $this->assertFalse($object->canDelete($create)); |
|
| 161 | - $this->assertFalse($object->canDelete($edit)); |
|
| 162 | - |
|
| 163 | - $checkObject = $object; |
|
| 164 | - $object->delete(); |
|
| 165 | - |
|
| 166 | - $this->assertEquals($checkObject->ID, 0); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * |
|
| 171 | - */ |
|
| 172 | - public function testCanCreate() |
|
| 173 | - { |
|
| 174 | - $object = singleton(Location::class); |
|
| 175 | - |
|
| 176 | - //test permissions per permission setting |
|
| 177 | - $create = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 178 | - $edit = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 179 | - $delete = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 180 | - |
|
| 181 | - $this->assertTrue($object->canCreate($create)); |
|
| 182 | - $this->assertFalse($object->canCreate($edit)); |
|
| 183 | - $this->assertFalse($object->canCreate($delete)); |
|
| 184 | - |
|
| 185 | - $nullMember = Member::create(); |
|
| 186 | - $nullMember->write(); |
|
| 187 | - $this->assertFalse($object->canCreate($nullMember)); |
|
| 188 | - |
|
| 189 | - $nullMember->delete(); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * |
|
| 194 | - */ |
|
| 195 | - public function testProvidePermissions() |
|
| 196 | - { |
|
| 197 | - $object = Location::create(); |
|
| 198 | - $expected = [ |
|
| 199 | - 'Location_EDIT' => 'Edit a Location', |
|
| 200 | - 'Location_DELETE' => 'Delete a Location', |
|
| 201 | - 'Location_CREATE' => 'Create a Location', |
|
| 202 | - ]; |
|
| 203 | - $this->assertEquals($expected, $object->providePermissions()); |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * |
|
| 208 | - */ |
|
| 209 | - public function testUpdateWebsiteURL() |
|
| 210 | - { |
|
| 211 | - $location = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 212 | - |
|
| 213 | - // Create unsaved raw duplicate |
|
| 214 | - $map = $location->toMap(); |
|
| 215 | - unset($map['Created']); |
|
| 216 | - /** @var static $clone */ |
|
| 217 | - $clone = Injector::inst()->create(ExtendedLocation::class, $map); |
|
| 218 | - $clone->ID = 0; |
|
| 219 | - |
|
| 220 | - $this->assertEquals('http://www.dynamicagency.com', $location->getWebsiteURL()); |
|
| 221 | - $this->assertEquals('foo', $clone->getWebsiteURL()); |
|
| 222 | - } |
|
| 21 | + /** |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected static $fixture_file = '../fixtures.yml'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var array |
|
| 28 | + */ |
|
| 29 | + protected static $extra_dataobjects = [ |
|
| 30 | + ExtendedLocation::class, |
|
| 31 | + ]; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var array |
|
| 35 | + */ |
|
| 36 | + protected static $required_extensions = [ |
|
| 37 | + ExtendedLocation::class => [ |
|
| 38 | + LocationExtension::class, |
|
| 39 | + ], |
|
| 40 | + ]; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * |
|
| 44 | + */ |
|
| 45 | + public function testGetCoords() |
|
| 46 | + { |
|
| 47 | + $location = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 48 | + $coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false'; |
|
| 49 | + $this->assertEquals($coords, $location->getCoords()); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * |
|
| 54 | + */ |
|
| 55 | + public function testFieldLabels() |
|
| 56 | + { |
|
| 57 | + $this->markTestSkipped(); |
|
| 58 | + // Link and File tracking display as "Tracking" in SS 4.2 & 4.3, "Tracking" in 4.4 |
|
| 59 | + $location = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 60 | + $labels = $location->FieldLabels(); |
|
| 61 | + $expected = [ |
|
| 62 | + 'Title' => 'Name', |
|
| 63 | + 'Featured' => 'Featured', |
|
| 64 | + 'Website' => 'Website', |
|
| 65 | + 'Phone' => 'Phone', |
|
| 66 | + 'Email' => 'Email', |
|
| 67 | + 'Fax' => 'Fax', |
|
| 68 | + 'Address' => 'Address', |
|
| 69 | + 'City' => 'City', |
|
| 70 | + 'State' => 'State', |
|
| 71 | + 'PostalCode' => 'Postal Code', |
|
| 72 | + 'Country' => 'Country', |
|
| 73 | + 'Lat' => 'Lat', |
|
| 74 | + 'Lng' => 'Lng', |
|
| 75 | + 'Categories' => 'Categories', |
|
| 76 | + 'Category.Name' => 'Category', |
|
| 77 | + 'Category.ID' => 'Category', |
|
| 78 | + 'Featured.NiceAsBoolean' => 'Featured', |
|
| 79 | + 'Import_ID' => 'Import_ID', |
|
| 80 | + 'Version' => 'Version', |
|
| 81 | + 'Versions' => 'Versions', |
|
| 82 | + 'Address2' => 'Address2', |
|
| 83 | + 'LinkTracking' => 'Link tracking', |
|
| 84 | + 'FileTracking' => 'File tracking', |
|
| 85 | + ]; |
|
| 86 | + $this->assertEquals($expected, $labels); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * |
|
| 91 | + */ |
|
| 92 | + public function testGetCMSFields() |
|
| 93 | + { |
|
| 94 | + $object = new Location(); |
|
| 95 | + $fieldset = $object->getCMSFields(); |
|
| 96 | + $this->assertinstanceOf(FieldList::class, $fieldset); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * |
|
| 101 | + */ |
|
| 102 | + public function testCanView() |
|
| 103 | + { |
|
| 104 | + $object = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 105 | + $object->write(); |
|
| 106 | + |
|
| 107 | + $this->assertTrue($object->canView()); |
|
| 108 | + |
|
| 109 | + $nullMember = Member::create(); |
|
| 110 | + $nullMember->write(); |
|
| 111 | + |
|
| 112 | + $this->assertTrue($object->canView($nullMember)); |
|
| 113 | + |
|
| 114 | + $nullMember->delete(); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * |
|
| 119 | + */ |
|
| 120 | + public function testCanEdit() |
|
| 121 | + { |
|
| 122 | + $object = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 123 | + $object->write(); |
|
| 124 | + |
|
| 125 | + $objectID = $object->ID; |
|
| 126 | + |
|
| 127 | + //test permissions per permission setting |
|
| 128 | + $create = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 129 | + $edit = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 130 | + $delete = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 131 | + |
|
| 132 | + $originalTitle = $object->Title; |
|
| 133 | + $this->assertEquals($originalTitle, 'Dynamic, Inc.'); |
|
| 134 | + |
|
| 135 | + $this->assertTrue($object->canEdit($edit)); |
|
| 136 | + $this->assertFalse($object->canEdit($create)); |
|
| 137 | + $this->assertFalse($object->canEdit($delete)); |
|
| 138 | + |
|
| 139 | + $object->Title = 'Changed Title'; |
|
| 140 | + $object->write(); |
|
| 141 | + |
|
| 142 | + $testEdit = Location::get()->byID($objectID); |
|
| 143 | + $this->assertEquals($testEdit->Title, 'Changed Title'); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * |
|
| 148 | + */ |
|
| 149 | + public function testCanDelete() |
|
| 150 | + { |
|
| 151 | + $object = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 152 | + $object->write(); |
|
| 153 | + |
|
| 154 | + //test permissions per permission setting |
|
| 155 | + $create = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 156 | + $edit = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 157 | + $delete = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 158 | + |
|
| 159 | + $this->assertTrue($object->canDelete($delete)); |
|
| 160 | + $this->assertFalse($object->canDelete($create)); |
|
| 161 | + $this->assertFalse($object->canDelete($edit)); |
|
| 162 | + |
|
| 163 | + $checkObject = $object; |
|
| 164 | + $object->delete(); |
|
| 165 | + |
|
| 166 | + $this->assertEquals($checkObject->ID, 0); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * |
|
| 171 | + */ |
|
| 172 | + public function testCanCreate() |
|
| 173 | + { |
|
| 174 | + $object = singleton(Location::class); |
|
| 175 | + |
|
| 176 | + //test permissions per permission setting |
|
| 177 | + $create = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 178 | + $edit = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 179 | + $delete = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 180 | + |
|
| 181 | + $this->assertTrue($object->canCreate($create)); |
|
| 182 | + $this->assertFalse($object->canCreate($edit)); |
|
| 183 | + $this->assertFalse($object->canCreate($delete)); |
|
| 184 | + |
|
| 185 | + $nullMember = Member::create(); |
|
| 186 | + $nullMember->write(); |
|
| 187 | + $this->assertFalse($object->canCreate($nullMember)); |
|
| 188 | + |
|
| 189 | + $nullMember->delete(); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * |
|
| 194 | + */ |
|
| 195 | + public function testProvidePermissions() |
|
| 196 | + { |
|
| 197 | + $object = Location::create(); |
|
| 198 | + $expected = [ |
|
| 199 | + 'Location_EDIT' => 'Edit a Location', |
|
| 200 | + 'Location_DELETE' => 'Delete a Location', |
|
| 201 | + 'Location_CREATE' => 'Create a Location', |
|
| 202 | + ]; |
|
| 203 | + $this->assertEquals($expected, $object->providePermissions()); |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * |
|
| 208 | + */ |
|
| 209 | + public function testUpdateWebsiteURL() |
|
| 210 | + { |
|
| 211 | + $location = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 212 | + |
|
| 213 | + // Create unsaved raw duplicate |
|
| 214 | + $map = $location->toMap(); |
|
| 215 | + unset($map['Created']); |
|
| 216 | + /** @var static $clone */ |
|
| 217 | + $clone = Injector::inst()->create(ExtendedLocation::class, $map); |
|
| 218 | + $clone->ID = 0; |
|
| 219 | + |
|
| 220 | + $this->assertEquals('http://www.dynamicagency.com', $location->getWebsiteURL()); |
|
| 221 | + $this->assertEquals('foo', $clone->getWebsiteURL()); |
|
| 222 | + } |
|
| 223 | 223 | } |
@@ -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 | } |
@@ -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 | } |
@@ -11,47 +11,47 @@ |
||
| 11 | 11 | |
| 12 | 12 | class LocatorFormTest extends FunctionalTest |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - protected static $fixture_file = '../fixtures.yml'; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * |
|
| 21 | - */ |
|
| 22 | - public function testLocatorFormBase() |
|
| 23 | - { |
|
| 24 | - $form = LocatorForm::create(LocatorController::create(Locator::get()->first()), 'LocatorForm'); |
|
| 25 | - |
|
| 26 | - $this->assertInstanceOf(FieldList::class, $form->Fields()); |
|
| 27 | - $this->assertInstanceOf(RequiredFields::class, $form->getValidator()); |
|
| 28 | - } |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * |
|
| 32 | - */ |
|
| 33 | - public function testUpdateRequiredFields() |
|
| 34 | - { |
|
| 35 | - $form = LocatorForm::create(LocatorController::create(Locator::get()->first()), 'LocatorForm'); |
|
| 36 | - $validator = $form->getValidator(); |
|
| 37 | - |
|
| 38 | - $validator->removeRequiredField('Address'); |
|
| 39 | - $validator->addRequiredField('Foo'); |
|
| 40 | - |
|
| 41 | - $this->assertEquals(['Foo'], $form->getValidator()->getRequired()); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - public function testFields() |
|
| 46 | - { |
|
| 47 | - $form = LocatorForm::create(LocatorController::create(Locator::get()->first()), 'LocatorForm'); |
|
| 48 | - $this->assertInstanceOf(FieldList::class, $form->Fields()); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - public function testActions() |
|
| 53 | - { |
|
| 54 | - $form = LocatorForm::create(LocatorController::create(Locator::get()->first()), 'LocatorForm'); |
|
| 55 | - $this->assertInstanceOf(FieldList::class, $form->Actions()); |
|
| 56 | - } |
|
| 14 | + /** |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + protected static $fixture_file = '../fixtures.yml'; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * |
|
| 21 | + */ |
|
| 22 | + public function testLocatorFormBase() |
|
| 23 | + { |
|
| 24 | + $form = LocatorForm::create(LocatorController::create(Locator::get()->first()), 'LocatorForm'); |
|
| 25 | + |
|
| 26 | + $this->assertInstanceOf(FieldList::class, $form->Fields()); |
|
| 27 | + $this->assertInstanceOf(RequiredFields::class, $form->getValidator()); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * |
|
| 32 | + */ |
|
| 33 | + public function testUpdateRequiredFields() |
|
| 34 | + { |
|
| 35 | + $form = LocatorForm::create(LocatorController::create(Locator::get()->first()), 'LocatorForm'); |
|
| 36 | + $validator = $form->getValidator(); |
|
| 37 | + |
|
| 38 | + $validator->removeRequiredField('Address'); |
|
| 39 | + $validator->addRequiredField('Foo'); |
|
| 40 | + |
|
| 41 | + $this->assertEquals(['Foo'], $form->getValidator()->getRequired()); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + public function testFields() |
|
| 46 | + { |
|
| 47 | + $form = LocatorForm::create(LocatorController::create(Locator::get()->first()), 'LocatorForm'); |
|
| 48 | + $this->assertInstanceOf(FieldList::class, $form->Fields()); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + public function testActions() |
|
| 53 | + { |
|
| 54 | + $form = LocatorForm::create(LocatorController::create(Locator::get()->first()), 'LocatorForm'); |
|
| 55 | + $this->assertInstanceOf(FieldList::class, $form->Actions()); |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -13,89 +13,89 @@ |
||
| 13 | 13 | class LocationCsvBulkLoader extends CsvBulkLoader |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var array |
|
| 18 | - */ |
|
| 19 | - public $columnMap = array( |
|
| 20 | - 'Name' => 'Title', |
|
| 21 | - 'EmailAddress' => 'Email', |
|
| 22 | - 'Categories' => '->getCategoryByName', |
|
| 23 | - 'Import_ID' => 'Import_ID', |
|
| 24 | - 'Country' => '->getCountryByName', |
|
| 25 | - ); |
|
| 16 | + /** |
|
| 17 | + * @var array |
|
| 18 | + */ |
|
| 19 | + public $columnMap = array( |
|
| 20 | + 'Name' => 'Title', |
|
| 21 | + 'EmailAddress' => 'Email', |
|
| 22 | + 'Categories' => '->getCategoryByName', |
|
| 23 | + 'Import_ID' => 'Import_ID', |
|
| 24 | + 'Country' => '->getCountryByName', |
|
| 25 | + ); |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var array |
|
| 29 | - */ |
|
| 30 | - public $duplicateChecks = array( |
|
| 31 | - 'Import_ID' => 'Import_ID' |
|
| 32 | - ); |
|
| 27 | + /** |
|
| 28 | + * @var array |
|
| 29 | + */ |
|
| 30 | + public $duplicateChecks = array( |
|
| 31 | + 'Import_ID' => 'Import_ID' |
|
| 32 | + ); |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @param $val |
|
| 36 | - * @return string|string[]|null |
|
| 37 | - */ |
|
| 38 | - public function getEscape($val) |
|
| 39 | - { |
|
| 40 | - return preg_replace("/\r|\n/", "", $val); |
|
| 41 | - } |
|
| 34 | + /** |
|
| 35 | + * @param $val |
|
| 36 | + * @return string|string[]|null |
|
| 37 | + */ |
|
| 38 | + public function getEscape($val) |
|
| 39 | + { |
|
| 40 | + return preg_replace("/\r|\n/", "", $val); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @param $obj |
|
| 45 | - * @param $val |
|
| 46 | - * @param $record |
|
| 47 | - * @throws \SilverStripe\ORM\ValidationException |
|
| 48 | - */ |
|
| 49 | - public static function getCategoryByName(&$obj, $val, $record) |
|
| 50 | - { |
|
| 51 | - $val = Convert::raw2sql($val); |
|
| 52 | - $parts = explode(', ', $val); |
|
| 43 | + /** |
|
| 44 | + * @param $obj |
|
| 45 | + * @param $val |
|
| 46 | + * @param $record |
|
| 47 | + * @throws \SilverStripe\ORM\ValidationException |
|
| 48 | + */ |
|
| 49 | + public static function getCategoryByName(&$obj, $val, $record) |
|
| 50 | + { |
|
| 51 | + $val = Convert::raw2sql($val); |
|
| 52 | + $parts = explode(', ', $val); |
|
| 53 | 53 | |
| 54 | - foreach ($parts as $part) { |
|
| 55 | - $category = LocationCategory::get()->filter(array('Name' => $part))->first(); |
|
| 56 | - if (!$category) { |
|
| 57 | - $category = LocationCategory::create(); |
|
| 58 | - $category->Name = $part; |
|
| 59 | - $category->write(); |
|
| 60 | - } |
|
| 61 | - $obj->Categories()->add($category); |
|
| 62 | - } |
|
| 63 | - } |
|
| 54 | + foreach ($parts as $part) { |
|
| 55 | + $category = LocationCategory::get()->filter(array('Name' => $part))->first(); |
|
| 56 | + if (!$category) { |
|
| 57 | + $category = LocationCategory::create(); |
|
| 58 | + $category->Name = $part; |
|
| 59 | + $category->write(); |
|
| 60 | + } |
|
| 61 | + $obj->Categories()->add($category); |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * @param $obj |
|
| 67 | - * @param $val |
|
| 68 | - * @param $record |
|
| 69 | - */ |
|
| 70 | - public function getCountryByName(&$obj, $val, $record) |
|
| 71 | - { |
|
| 72 | - $val = $this->getEscape($val); |
|
| 73 | - $countries = IntlLocales::singleton()->getCountries(); |
|
| 65 | + /** |
|
| 66 | + * @param $obj |
|
| 67 | + * @param $val |
|
| 68 | + * @param $record |
|
| 69 | + */ |
|
| 70 | + public function getCountryByName(&$obj, $val, $record) |
|
| 71 | + { |
|
| 72 | + $val = $this->getEscape($val); |
|
| 73 | + $countries = IntlLocales::singleton()->getCountries(); |
|
| 74 | 74 | |
| 75 | - if (strlen((string)$val) == 2) { |
|
| 76 | - $val = strtolower($val); |
|
| 77 | - if (array_key_exists($val, $countries)) { |
|
| 78 | - $obj->Country = $val; |
|
| 79 | - } |
|
| 80 | - } |
|
| 75 | + if (strlen((string)$val) == 2) { |
|
| 76 | + $val = strtolower($val); |
|
| 77 | + if (array_key_exists($val, $countries)) { |
|
| 78 | + $obj->Country = $val; |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - if (in_array($val, $countries)) { |
|
| 83 | - $obj->Country = array_search($val, $countries); |
|
| 84 | - } |
|
| 85 | - } |
|
| 82 | + if (in_array($val, $countries)) { |
|
| 83 | + $obj->Country = array_search($val, $countries); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * @param array $record |
|
| 89 | - * @param array $columnMap |
|
| 90 | - * @param \SilverStripe\Dev\BulkLoader_Result $results |
|
| 91 | - * @param bool $preview |
|
| 92 | - * @return int|void |
|
| 93 | - */ |
|
| 94 | - protected function processRecord($record, $columnMap, &$results, $preview = false) |
|
| 95 | - { |
|
| 96 | - $objID = parent::processRecord($record, $columnMap, $results, $preview = false); |
|
| 87 | + /** |
|
| 88 | + * @param array $record |
|
| 89 | + * @param array $columnMap |
|
| 90 | + * @param \SilverStripe\Dev\BulkLoader_Result $results |
|
| 91 | + * @param bool $preview |
|
| 92 | + * @return int|void |
|
| 93 | + */ |
|
| 94 | + protected function processRecord($record, $columnMap, &$results, $preview = false) |
|
| 95 | + { |
|
| 96 | + $objID = parent::processRecord($record, $columnMap, $results, $preview = false); |
|
| 97 | 97 | |
| 98 | - $location = Location::get()->byID($objID); |
|
| 99 | - $location->publishSingle(); |
|
| 100 | - } |
|
| 98 | + $location = Location::get()->byID($objID); |
|
| 99 | + $location->publishSingle(); |
|
| 100 | + } |
|
| 101 | 101 | } |
@@ -72,7 +72,7 @@ |
||
| 72 | 72 | $val = $this->getEscape($val); |
| 73 | 73 | $countries = IntlLocales::singleton()->getCountries(); |
| 74 | 74 | |
| 75 | - if (strlen((string)$val) == 2) { |
|
| 75 | + if (strlen((string) $val) == 2) { |
|
| 76 | 76 | $val = strtolower($val); |
| 77 | 77 | if (array_key_exists($val, $countries)) { |
| 78 | 78 | $obj->Country = $val; |
@@ -11,12 +11,12 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class LocationExtension extends DataExtension implements TestOnly |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @param $url |
|
| 16 | - * @return string |
|
| 17 | - */ |
|
| 18 | - public function updateWebsiteURL(&$url) |
|
| 19 | - { |
|
| 20 | - $url = 'foo'; |
|
| 21 | - } |
|
| 14 | + /** |
|
| 15 | + * @param $url |
|
| 16 | + * @return string |
|
| 17 | + */ |
|
| 18 | + public function updateWebsiteURL(&$url) |
|
| 19 | + { |
|
| 20 | + $url = 'foo'; |
|
| 21 | + } |
|
| 22 | 22 | } |
@@ -12,10 +12,10 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class ExtendedLocation extends Location implements TestOnly |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @var array |
|
| 17 | - */ |
|
| 18 | - private static $extensions = [ |
|
| 19 | - LocationExtension::class, |
|
| 20 | - ]; |
|
| 15 | + /** |
|
| 16 | + * @var array |
|
| 17 | + */ |
|
| 18 | + private static $extensions = [ |
|
| 19 | + LocationExtension::class, |
|
| 20 | + ]; |
|
| 21 | 21 | } |
@@ -17,78 +17,78 @@ |
||
| 17 | 17 | class LocatorControllerTest extends FunctionalTest |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - protected static $fixture_file = '../fixtures.yml'; |
|
| 20 | + /** |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + protected static $fixture_file = '../fixtures.yml'; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @var bool |
|
| 27 | - */ |
|
| 28 | - protected static $use_draft_site = true; |
|
| 25 | + /** |
|
| 26 | + * @var bool |
|
| 27 | + */ |
|
| 28 | + protected static $use_draft_site = true; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * |
|
| 32 | - */ |
|
| 33 | - public function testIndex() |
|
| 34 | - { |
|
| 35 | - $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 36 | - $controller = LocatorController::create($locator); |
|
| 37 | - $this->assertInstanceOf(ViewableData::class, $controller->index($controller->getRequest())); |
|
| 38 | - } |
|
| 30 | + /** |
|
| 31 | + * |
|
| 32 | + */ |
|
| 33 | + public function testIndex() |
|
| 34 | + { |
|
| 35 | + $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 36 | + $controller = LocatorController::create($locator); |
|
| 37 | + $this->assertInstanceOf(ViewableData::class, $controller->index($controller->getRequest())); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * |
|
| 42 | - */ |
|
| 43 | - public function testXml() |
|
| 44 | - { |
|
| 45 | - /** @var Locator $locator */ |
|
| 46 | - $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 47 | - $page = $this->get($locator->Link('xml')); |
|
| 40 | + /** |
|
| 41 | + * |
|
| 42 | + */ |
|
| 43 | + public function testXml() |
|
| 44 | + { |
|
| 45 | + /** @var Locator $locator */ |
|
| 46 | + $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 47 | + $page = $this->get($locator->Link('xml')); |
|
| 48 | 48 | |
| 49 | - $this->assertEquals(200, $page->getStatusCode()); |
|
| 50 | - $this->assertEquals('application/xml', $page->getHeader('content-type')); |
|
| 49 | + $this->assertEquals(200, $page->getStatusCode()); |
|
| 50 | + $this->assertEquals('application/xml', $page->getHeader('content-type')); |
|
| 51 | 51 | |
| 52 | - $dom = new \DOMDocument(); |
|
| 53 | - // true if it loads, false if it doesn't |
|
| 54 | - $valid = $dom->loadXML($page->getBody()); |
|
| 55 | - $this->assertTrue($valid); |
|
| 56 | - } |
|
| 52 | + $dom = new \DOMDocument(); |
|
| 53 | + // true if it loads, false if it doesn't |
|
| 54 | + $valid = $dom->loadXML($page->getBody()); |
|
| 55 | + $this->assertTrue($valid); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * |
|
| 60 | - */ |
|
| 61 | - public function testJson() |
|
| 62 | - { |
|
| 63 | - /** @var Locator $locator */ |
|
| 64 | - $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 65 | - $page = $this->get($locator->Link('json')); |
|
| 58 | + /** |
|
| 59 | + * |
|
| 60 | + */ |
|
| 61 | + public function testJson() |
|
| 62 | + { |
|
| 63 | + /** @var Locator $locator */ |
|
| 64 | + $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 65 | + $page = $this->get($locator->Link('json')); |
|
| 66 | 66 | |
| 67 | - $this->assertEquals(200, $page->getStatusCode()); |
|
| 68 | - $this->assertEquals('application/json', $page->getHeader('content-type')); |
|
| 67 | + $this->assertEquals(200, $page->getStatusCode()); |
|
| 68 | + $this->assertEquals('application/json', $page->getHeader('content-type')); |
|
| 69 | 69 | |
| 70 | - $json = json_decode($page->getBody()); |
|
| 71 | - // if it is null its not valid |
|
| 72 | - $this->assertNotNull($json); |
|
| 73 | - } |
|
| 70 | + $json = json_decode($page->getBody()); |
|
| 71 | + // if it is null its not valid |
|
| 72 | + $this->assertNotNull($json); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * |
|
| 77 | - */ |
|
| 78 | - public function testLocationSearch() |
|
| 79 | - { |
|
| 80 | - $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 81 | - $object = LocatorController::create($locator); |
|
| 82 | - $form = $object->LocationSearch(); |
|
| 83 | - $this->assertInstanceOf(Form::class, $form); |
|
| 75 | + /** |
|
| 76 | + * |
|
| 77 | + */ |
|
| 78 | + public function testLocationSearch() |
|
| 79 | + { |
|
| 80 | + $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 81 | + $object = LocatorController::create($locator); |
|
| 82 | + $form = $object->LocationSearch(); |
|
| 83 | + $this->assertInstanceOf(Form::class, $form); |
|
| 84 | 84 | |
| 85 | - $category = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 86 | - $category2 = $this->objFromFixture(LocationCategory::class, 'manufacturing'); |
|
| 87 | - $locator->Categories()->add($category); |
|
| 88 | - $locator->Categories()->add($category2); |
|
| 85 | + $category = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 86 | + $category2 = $this->objFromFixture(LocationCategory::class, 'manufacturing'); |
|
| 87 | + $locator->Categories()->add($category); |
|
| 88 | + $locator->Categories()->add($category2); |
|
| 89 | 89 | |
| 90 | - $form = $object->LocationSearch(); |
|
| 91 | - $fields = $form->Fields(); |
|
| 92 | - $this->assertInstanceOf(FieldList::class, $fields); |
|
| 93 | - } |
|
| 90 | + $form = $object->LocationSearch(); |
|
| 91 | + $fields = $form->Fields(); |
|
| 92 | + $this->assertInstanceOf(FieldList::class, $fields); |
|
| 93 | + } |
|
| 94 | 94 | } |
@@ -27,246 +27,246 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class Locator extends \Page |
| 29 | 29 | { |
| 30 | - /** |
|
| 31 | - * @var string |
|
| 32 | - */ |
|
| 33 | - private static $singular_name = 'Locator'; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - private static $plural_name = 'Locators'; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 43 | - private static $description = 'Display locations on a map'; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var array |
|
| 47 | - */ |
|
| 48 | - private static $db = array( |
|
| 49 | - 'Unit' => 'Enum("m,km","m")', |
|
| 50 | - ); |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 55 | - private static $many_many = array( |
|
| 56 | - 'Categories' => LocationCategory::class, |
|
| 57 | - ); |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 62 | - private static $table_name = 'Locator'; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 67 | - private static $location_class = LocationPage::class; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @return FieldList |
|
| 71 | - */ |
|
| 72 | - public function getCMSFields() |
|
| 73 | - { |
|
| 74 | - $this->beforeUpdateCMSFields(function ($fields) { |
|
| 75 | - // Settings |
|
| 76 | - $fields->addFieldsToTab('Root.Settings', array( |
|
| 77 | - HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
| 78 | - OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')), |
|
| 79 | - )); |
|
| 80 | - |
|
| 81 | - // Filter categories |
|
| 82 | - $config = GridFieldConfig_RelationEditor::create(); |
|
| 83 | - $config->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
|
| 84 | - $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
| 85 | - $categories = $this->Categories(); |
|
| 86 | - $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
| 87 | - ->setDescription('only show locations from the selected category'); |
|
| 88 | - |
|
| 89 | - // Filter |
|
| 90 | - $fields->addFieldsToTab('Root.Filter', array( |
|
| 91 | - HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
| 92 | - $categoriesField, |
|
| 93 | - )); |
|
| 94 | - }); |
|
| 95 | - |
|
| 96 | - return parent::getCMSFields(); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @param array $filter |
|
| 101 | - * @param array $filterAny |
|
| 102 | - * @param array $exclude |
|
| 103 | - * @param null|callable $callback |
|
| 104 | - * |
|
| 105 | - * @return DataList|ArrayList |
|
| 106 | - */ |
|
| 107 | - public static function get_locations( |
|
| 108 | - $filter = [], |
|
| 109 | - $filterAny = [], |
|
| 110 | - $exclude = [], |
|
| 111 | - $callback = null |
|
| 112 | - ) { |
|
| 113 | - $locationClass = Config::inst()->get(static::class, 'location_class'); |
|
| 114 | - $locations = $locationClass::get()->filter($filter)->exclude($exclude); |
|
| 115 | - |
|
| 116 | - if (!empty($filterAny)) { |
|
| 117 | - $locations = $locations->filterAny($filterAny); |
|
| 118 | - } |
|
| 119 | - if (!empty($exclude)) { |
|
| 120 | - $locations = $locations->exclude($exclude); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - if ($callback !== null && is_callable($callback)) { |
|
| 124 | - $locations->filterByCallback($callback); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - return $locations; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @return DataList |
|
| 132 | - */ |
|
| 133 | - public static function get_all_categories() |
|
| 134 | - { |
|
| 135 | - return LocationCategory::get(); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @return bool |
|
| 140 | - */ |
|
| 141 | - public function getPageCategories() |
|
| 142 | - { |
|
| 143 | - return self::locator_categories_by_locator($this->ID); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @param int $id |
|
| 148 | - * |
|
| 149 | - * @return bool| |
|
| 150 | - */ |
|
| 151 | - public static function locator_categories_by_locator($id = 0) |
|
| 152 | - { |
|
| 153 | - if ($id == 0) { |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - return static::get()->byID($id)->getUsedCategories(); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Gets the list of radii |
|
| 162 | - * |
|
| 163 | - * @return ArrayList |
|
| 164 | - */ |
|
| 165 | - public function getRadii() |
|
| 166 | - { |
|
| 167 | - $radii = [ |
|
| 168 | - '0' => '25', |
|
| 169 | - '1' => '50', |
|
| 170 | - '2' => '75', |
|
| 171 | - '3' => '100', |
|
| 172 | - ]; |
|
| 173 | - $config_radii = $this->config()->get('radii'); |
|
| 174 | - if ($config_radii) { |
|
| 175 | - $radii = $config_radii; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return $radii; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - public function getRadiiArrayList() |
|
| 182 | - { |
|
| 183 | - $list = []; |
|
| 184 | - |
|
| 185 | - foreach ($this->getRadii() as $radius) { |
|
| 186 | - $list[] = new ArrayData(array( |
|
| 187 | - 'Radius' => $radius, |
|
| 188 | - )); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return new ArrayList($list); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Gets the limit of locations |
|
| 196 | - * @return mixed |
|
| 197 | - */ |
|
| 198 | - public function getLimit() |
|
| 199 | - { |
|
| 200 | - return $this->config()->get('limit'); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * Gets if the radius drop down should be shown |
|
| 205 | - * @return mixed |
|
| 206 | - */ |
|
| 207 | - public function getShowRadius() |
|
| 208 | - { |
|
| 209 | - return $this->config()->get('show_radius'); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * @return mixed |
|
| 214 | - */ |
|
| 215 | - public function getUsedCategories() |
|
| 216 | - { |
|
| 217 | - return $this->Categories()->filter([ |
|
| 218 | - 'LocationSet.ID:GreaterThan' => 0, |
|
| 219 | - ]); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Gets the path of the info window template |
|
| 224 | - * |
|
| 225 | - * @return string |
|
| 226 | - */ |
|
| 227 | - public function getInfoWindowTemplate() |
|
| 228 | - { |
|
| 229 | - return ModuleResourceLoader::singleton()->resolveURL( |
|
| 230 | - Config::inst()->get( |
|
| 231 | - static::class, |
|
| 232 | - 'infoWindowTemplate' |
|
| 233 | - ) |
|
| 234 | - ); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Gets the path of the list template |
|
| 239 | - * |
|
| 240 | - * @return string |
|
| 241 | - */ |
|
| 242 | - public function getListTemplate() |
|
| 243 | - { |
|
| 244 | - return ModuleResourceLoader::singleton()->resolveURL( |
|
| 245 | - Config::inst()->get( |
|
| 246 | - static::class, |
|
| 247 | - 'listTemplate' |
|
| 248 | - ) |
|
| 249 | - ); |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * @return null|string |
|
| 254 | - */ |
|
| 255 | - public function getMapStyle() |
|
| 256 | - { |
|
| 257 | - return AddressDataExtension::getMapStyleJSON(); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - public function getMapStyleJSONPath() |
|
| 261 | - { |
|
| 262 | - return AddressDataExtension::getMapStyleJSONPath(); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * @return null|string |
|
| 267 | - */ |
|
| 268 | - public function getMarkerIcon() |
|
| 269 | - { |
|
| 270 | - return AddressDataExtension::getIconImage(); |
|
| 271 | - } |
|
| 30 | + /** |
|
| 31 | + * @var string |
|
| 32 | + */ |
|
| 33 | + private static $singular_name = 'Locator'; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + private static $plural_name = 'Locators'; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | + private static $description = 'Display locations on a map'; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @var array |
|
| 47 | + */ |
|
| 48 | + private static $db = array( |
|
| 49 | + 'Unit' => 'Enum("m,km","m")', |
|
| 50 | + ); |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | + private static $many_many = array( |
|
| 56 | + 'Categories' => LocationCategory::class, |
|
| 57 | + ); |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | + private static $table_name = 'Locator'; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | + private static $location_class = LocationPage::class; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @return FieldList |
|
| 71 | + */ |
|
| 72 | + public function getCMSFields() |
|
| 73 | + { |
|
| 74 | + $this->beforeUpdateCMSFields(function ($fields) { |
|
| 75 | + // Settings |
|
| 76 | + $fields->addFieldsToTab('Root.Settings', array( |
|
| 77 | + HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
| 78 | + OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')), |
|
| 79 | + )); |
|
| 80 | + |
|
| 81 | + // Filter categories |
|
| 82 | + $config = GridFieldConfig_RelationEditor::create(); |
|
| 83 | + $config->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
|
| 84 | + $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
| 85 | + $categories = $this->Categories(); |
|
| 86 | + $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
| 87 | + ->setDescription('only show locations from the selected category'); |
|
| 88 | + |
|
| 89 | + // Filter |
|
| 90 | + $fields->addFieldsToTab('Root.Filter', array( |
|
| 91 | + HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
| 92 | + $categoriesField, |
|
| 93 | + )); |
|
| 94 | + }); |
|
| 95 | + |
|
| 96 | + return parent::getCMSFields(); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @param array $filter |
|
| 101 | + * @param array $filterAny |
|
| 102 | + * @param array $exclude |
|
| 103 | + * @param null|callable $callback |
|
| 104 | + * |
|
| 105 | + * @return DataList|ArrayList |
|
| 106 | + */ |
|
| 107 | + public static function get_locations( |
|
| 108 | + $filter = [], |
|
| 109 | + $filterAny = [], |
|
| 110 | + $exclude = [], |
|
| 111 | + $callback = null |
|
| 112 | + ) { |
|
| 113 | + $locationClass = Config::inst()->get(static::class, 'location_class'); |
|
| 114 | + $locations = $locationClass::get()->filter($filter)->exclude($exclude); |
|
| 115 | + |
|
| 116 | + if (!empty($filterAny)) { |
|
| 117 | + $locations = $locations->filterAny($filterAny); |
|
| 118 | + } |
|
| 119 | + if (!empty($exclude)) { |
|
| 120 | + $locations = $locations->exclude($exclude); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + if ($callback !== null && is_callable($callback)) { |
|
| 124 | + $locations->filterByCallback($callback); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + return $locations; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @return DataList |
|
| 132 | + */ |
|
| 133 | + public static function get_all_categories() |
|
| 134 | + { |
|
| 135 | + return LocationCategory::get(); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @return bool |
|
| 140 | + */ |
|
| 141 | + public function getPageCategories() |
|
| 142 | + { |
|
| 143 | + return self::locator_categories_by_locator($this->ID); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @param int $id |
|
| 148 | + * |
|
| 149 | + * @return bool| |
|
| 150 | + */ |
|
| 151 | + public static function locator_categories_by_locator($id = 0) |
|
| 152 | + { |
|
| 153 | + if ($id == 0) { |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + return static::get()->byID($id)->getUsedCategories(); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Gets the list of radii |
|
| 162 | + * |
|
| 163 | + * @return ArrayList |
|
| 164 | + */ |
|
| 165 | + public function getRadii() |
|
| 166 | + { |
|
| 167 | + $radii = [ |
|
| 168 | + '0' => '25', |
|
| 169 | + '1' => '50', |
|
| 170 | + '2' => '75', |
|
| 171 | + '3' => '100', |
|
| 172 | + ]; |
|
| 173 | + $config_radii = $this->config()->get('radii'); |
|
| 174 | + if ($config_radii) { |
|
| 175 | + $radii = $config_radii; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return $radii; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + public function getRadiiArrayList() |
|
| 182 | + { |
|
| 183 | + $list = []; |
|
| 184 | + |
|
| 185 | + foreach ($this->getRadii() as $radius) { |
|
| 186 | + $list[] = new ArrayData(array( |
|
| 187 | + 'Radius' => $radius, |
|
| 188 | + )); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return new ArrayList($list); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Gets the limit of locations |
|
| 196 | + * @return mixed |
|
| 197 | + */ |
|
| 198 | + public function getLimit() |
|
| 199 | + { |
|
| 200 | + return $this->config()->get('limit'); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * Gets if the radius drop down should be shown |
|
| 205 | + * @return mixed |
|
| 206 | + */ |
|
| 207 | + public function getShowRadius() |
|
| 208 | + { |
|
| 209 | + return $this->config()->get('show_radius'); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * @return mixed |
|
| 214 | + */ |
|
| 215 | + public function getUsedCategories() |
|
| 216 | + { |
|
| 217 | + return $this->Categories()->filter([ |
|
| 218 | + 'LocationSet.ID:GreaterThan' => 0, |
|
| 219 | + ]); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Gets the path of the info window template |
|
| 224 | + * |
|
| 225 | + * @return string |
|
| 226 | + */ |
|
| 227 | + public function getInfoWindowTemplate() |
|
| 228 | + { |
|
| 229 | + return ModuleResourceLoader::singleton()->resolveURL( |
|
| 230 | + Config::inst()->get( |
|
| 231 | + static::class, |
|
| 232 | + 'infoWindowTemplate' |
|
| 233 | + ) |
|
| 234 | + ); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Gets the path of the list template |
|
| 239 | + * |
|
| 240 | + * @return string |
|
| 241 | + */ |
|
| 242 | + public function getListTemplate() |
|
| 243 | + { |
|
| 244 | + return ModuleResourceLoader::singleton()->resolveURL( |
|
| 245 | + Config::inst()->get( |
|
| 246 | + static::class, |
|
| 247 | + 'listTemplate' |
|
| 248 | + ) |
|
| 249 | + ); |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * @return null|string |
|
| 254 | + */ |
|
| 255 | + public function getMapStyle() |
|
| 256 | + { |
|
| 257 | + return AddressDataExtension::getMapStyleJSON(); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + public function getMapStyleJSONPath() |
|
| 261 | + { |
|
| 262 | + return AddressDataExtension::getMapStyleJSONPath(); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * @return null|string |
|
| 267 | + */ |
|
| 268 | + public function getMarkerIcon() |
|
| 269 | + { |
|
| 270 | + return AddressDataExtension::getIconImage(); |
|
| 271 | + } |
|
| 272 | 272 | } |
@@ -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), |