@@ -13,69 +13,69 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class LocationCategoryTest extends SapphireTest |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 19 | - protected static $fixture_file = 'categoryfixture.yml'; |
|
| 16 | + /** |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | + protected static $fixture_file = 'categoryfixture.yml'; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * |
|
| 23 | - */ |
|
| 24 | - public function testGetCMSFields() |
|
| 25 | - { |
|
| 26 | - $object = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 27 | - $fieldset = $object->getCMSFields(); |
|
| 28 | - $this->assertInstanceOf(FieldList::class, $fieldset); |
|
| 29 | - } |
|
| 21 | + /** |
|
| 22 | + * |
|
| 23 | + */ |
|
| 24 | + public function testGetCMSFields() |
|
| 25 | + { |
|
| 26 | + $object = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 27 | + $fieldset = $object->getCMSFields(); |
|
| 28 | + $this->assertInstanceOf(FieldList::class, $fieldset); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * |
|
| 33 | - */ |
|
| 34 | - public function testCanView() |
|
| 35 | - { |
|
| 36 | - $object = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 37 | - $this->assertTrue($object->canView()); |
|
| 38 | - } |
|
| 31 | + /** |
|
| 32 | + * |
|
| 33 | + */ |
|
| 34 | + public function testCanView() |
|
| 35 | + { |
|
| 36 | + $object = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 37 | + $this->assertTrue($object->canView()); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * |
|
| 42 | - */ |
|
| 43 | - public function testCanEdit() |
|
| 44 | - { |
|
| 45 | - $object = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 40 | + /** |
|
| 41 | + * |
|
| 42 | + */ |
|
| 43 | + public function testCanEdit() |
|
| 44 | + { |
|
| 45 | + $object = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 46 | 46 | |
| 47 | - $admin = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 48 | - $this->assertTrue($object->canEdit($admin)); |
|
| 47 | + $admin = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 48 | + $this->assertTrue($object->canEdit($admin)); |
|
| 49 | 49 | |
| 50 | - $member = $this->objFromFixture(Member::class, 'default'); |
|
| 51 | - $this->assertFalse($object->canEdit($member)); |
|
| 52 | - } |
|
| 50 | + $member = $this->objFromFixture(Member::class, 'default'); |
|
| 51 | + $this->assertFalse($object->canEdit($member)); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * |
|
| 56 | - */ |
|
| 57 | - public function testCanDelete() |
|
| 58 | - { |
|
| 59 | - $object = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 54 | + /** |
|
| 55 | + * |
|
| 56 | + */ |
|
| 57 | + public function testCanDelete() |
|
| 58 | + { |
|
| 59 | + $object = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 60 | 60 | |
| 61 | - $admin = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 62 | - $this->assertTrue($object->canDelete($admin)); |
|
| 61 | + $admin = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 62 | + $this->assertTrue($object->canDelete($admin)); |
|
| 63 | 63 | |
| 64 | - $member = $this->objFromFixture(Member::class, 'default'); |
|
| 65 | - $this->assertFalse($object->canDelete($member)); |
|
| 66 | - } |
|
| 64 | + $member = $this->objFromFixture(Member::class, 'default'); |
|
| 65 | + $this->assertFalse($object->canDelete($member)); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * |
|
| 70 | - */ |
|
| 71 | - public function testCanCreate() |
|
| 72 | - { |
|
| 73 | - $object = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 68 | + /** |
|
| 69 | + * |
|
| 70 | + */ |
|
| 71 | + public function testCanCreate() |
|
| 72 | + { |
|
| 73 | + $object = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 74 | 74 | |
| 75 | - $admin = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 76 | - $this->assertTrue($object->canCreate($admin)); |
|
| 75 | + $admin = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 76 | + $this->assertTrue($object->canCreate($admin)); |
|
| 77 | 77 | |
| 78 | - $member = $this->objFromFixture(Member::class, 'default'); |
|
| 79 | - $this->assertFalse($object->canCreate($member)); |
|
| 80 | - } |
|
| 78 | + $member = $this->objFromFixture(Member::class, 'default'); |
|
| 79 | + $this->assertFalse($object->canCreate($member)); |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -16,206 +16,206 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class LocationTest extends SapphireTest |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - protected static $fixture_file = 'locationfixture.yml'; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var array |
|
| 26 | - */ |
|
| 27 | - protected static $extra_dataobjects = [ |
|
| 28 | - ExtendedLocation::class, |
|
| 29 | - ]; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 34 | - protected static $required_extensions = [ |
|
| 35 | - ExtendedLocation::class => [ |
|
| 36 | - LocationExtension::class, |
|
| 37 | - ], |
|
| 38 | - ]; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * |
|
| 42 | - */ |
|
| 43 | - public function testGetCoords() |
|
| 44 | - { |
|
| 45 | - $location = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 46 | - $coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false'; |
|
| 47 | - $this->assertEquals($coords, $location->getCoords()); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * |
|
| 52 | - */ |
|
| 53 | - public function testFieldLabels() |
|
| 54 | - { |
|
| 55 | - $this->markTestSkipped(); |
|
| 56 | - // Link and File tracking display as "Tracking" in SS 4.2 & 4.3, "Tracking" in 4.4 |
|
| 57 | - $location = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 58 | - $labels = $location->FieldLabels(); |
|
| 59 | - $expected = [ |
|
| 60 | - 'Title' => 'Name', |
|
| 61 | - 'Featured' => 'Featured', |
|
| 62 | - 'Website' => 'Website', |
|
| 63 | - 'Phone' => 'Phone', |
|
| 64 | - 'Email' => 'Email', |
|
| 65 | - 'Fax' => 'Fax', |
|
| 66 | - 'Address' => 'Address', |
|
| 67 | - 'City' => 'City', |
|
| 68 | - 'State' => 'State', |
|
| 69 | - 'PostalCode' => 'Postal Code', |
|
| 70 | - 'Country' => 'Country', |
|
| 71 | - 'Lat' => 'Lat', |
|
| 72 | - 'Lng' => 'Lng', |
|
| 73 | - 'Categories' => 'Categories', |
|
| 74 | - 'Category.Name' => 'Category', |
|
| 75 | - 'Category.ID' => 'Category', |
|
| 76 | - 'Featured.NiceAsBoolean' => 'Featured', |
|
| 77 | - 'Import_ID' => 'Import_ID', |
|
| 78 | - 'Version' => 'Version', |
|
| 79 | - 'Versions' => 'Versions', |
|
| 80 | - 'Address2' => 'Address2', |
|
| 81 | - 'LinkTracking' => 'Link tracking', |
|
| 82 | - 'FileTracking' => 'File tracking', |
|
| 83 | - ]; |
|
| 84 | - $this->assertEquals($expected, $labels); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * |
|
| 89 | - */ |
|
| 90 | - public function testGetCMSFields() |
|
| 91 | - { |
|
| 92 | - $object = new Location(); |
|
| 93 | - $fieldset = $object->getCMSFields(); |
|
| 94 | - $this->assertinstanceOf(FieldList::class, $fieldset); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * |
|
| 99 | - */ |
|
| 100 | - public function testCanView() |
|
| 101 | - { |
|
| 102 | - $object = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 103 | - $object->write(); |
|
| 104 | - |
|
| 105 | - $this->assertTrue($object->canView()); |
|
| 106 | - |
|
| 107 | - $nullMember = Member::create(); |
|
| 108 | - $nullMember->write(); |
|
| 109 | - |
|
| 110 | - $this->assertTrue($object->canView($nullMember)); |
|
| 111 | - |
|
| 112 | - $nullMember->delete(); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * |
|
| 117 | - */ |
|
| 118 | - public function testCanEdit() |
|
| 119 | - { |
|
| 120 | - $object = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 121 | - $object->write(); |
|
| 122 | - |
|
| 123 | - $objectID = $object->ID; |
|
| 124 | - |
|
| 125 | - //test permissions per permission setting |
|
| 126 | - $create = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 127 | - $edit = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 128 | - $delete = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 129 | - |
|
| 130 | - $originalTitle = $object->Title; |
|
| 131 | - $this->assertEquals($originalTitle, 'Dynamic, Inc.'); |
|
| 132 | - |
|
| 133 | - $this->assertTrue($object->canEdit($edit)); |
|
| 134 | - $this->assertFalse($object->canEdit($create)); |
|
| 135 | - $this->assertFalse($object->canEdit($delete)); |
|
| 136 | - |
|
| 137 | - $object->Title = 'Changed Title'; |
|
| 138 | - $object->write(); |
|
| 139 | - |
|
| 140 | - $testEdit = Location::get()->byID($objectID); |
|
| 141 | - $this->assertEquals($testEdit->Title, 'Changed Title'); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * |
|
| 146 | - */ |
|
| 147 | - public function testCanDelete() |
|
| 148 | - { |
|
| 149 | - $object = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 150 | - $object->write(); |
|
| 151 | - |
|
| 152 | - //test permissions per permission setting |
|
| 153 | - $create = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 154 | - $edit = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 155 | - $delete = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 156 | - |
|
| 157 | - $this->assertTrue($object->canDelete($delete)); |
|
| 158 | - $this->assertFalse($object->canDelete($create)); |
|
| 159 | - $this->assertFalse($object->canDelete($edit)); |
|
| 160 | - |
|
| 161 | - $checkObject = $object; |
|
| 162 | - $object->delete(); |
|
| 163 | - |
|
| 164 | - $this->assertEquals($checkObject->ID, 0); |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * |
|
| 169 | - */ |
|
| 170 | - public function testCanCreate() |
|
| 171 | - { |
|
| 172 | - $object = singleton(Location::class); |
|
| 173 | - |
|
| 174 | - //test permissions per permission setting |
|
| 175 | - $create = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 176 | - $edit = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 177 | - $delete = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 178 | - |
|
| 179 | - $this->assertTrue($object->canCreate($create)); |
|
| 180 | - $this->assertFalse($object->canCreate($edit)); |
|
| 181 | - $this->assertFalse($object->canCreate($delete)); |
|
| 182 | - |
|
| 183 | - $nullMember = Member::create(); |
|
| 184 | - $nullMember->write(); |
|
| 185 | - $this->assertFalse($object->canCreate($nullMember)); |
|
| 186 | - |
|
| 187 | - $nullMember->delete(); |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * |
|
| 192 | - */ |
|
| 193 | - public function testProvidePermissions() |
|
| 194 | - { |
|
| 195 | - $object = Location::create(); |
|
| 196 | - $expected = [ |
|
| 197 | - 'Location_EDIT' => 'Edit a Location', |
|
| 198 | - 'Location_DELETE' => 'Delete a Location', |
|
| 199 | - 'Location_CREATE' => 'Create a Location', |
|
| 200 | - ]; |
|
| 201 | - $this->assertEquals($expected, $object->providePermissions()); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * |
|
| 206 | - */ |
|
| 207 | - public function testUpdateWebsiteURL() |
|
| 208 | - { |
|
| 209 | - $location = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 210 | - |
|
| 211 | - // Create unsaved raw duplicate |
|
| 212 | - $map = $location->toMap(); |
|
| 213 | - unset($map['Created']); |
|
| 214 | - /** @var static $clone */ |
|
| 215 | - $clone = Injector::inst()->create(ExtendedLocation::class, $map); |
|
| 216 | - $clone->ID = 0; |
|
| 217 | - |
|
| 218 | - $this->assertEquals('http://www.dynamicagency.com', $location->getWebsiteURL()); |
|
| 219 | - $this->assertEquals('foo', $clone->getWebsiteURL()); |
|
| 220 | - } |
|
| 19 | + /** |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + protected static $fixture_file = 'locationfixture.yml'; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var array |
|
| 26 | + */ |
|
| 27 | + protected static $extra_dataobjects = [ |
|
| 28 | + ExtendedLocation::class, |
|
| 29 | + ]; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | + protected static $required_extensions = [ |
|
| 35 | + ExtendedLocation::class => [ |
|
| 36 | + LocationExtension::class, |
|
| 37 | + ], |
|
| 38 | + ]; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * |
|
| 42 | + */ |
|
| 43 | + public function testGetCoords() |
|
| 44 | + { |
|
| 45 | + $location = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 46 | + $coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false'; |
|
| 47 | + $this->assertEquals($coords, $location->getCoords()); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * |
|
| 52 | + */ |
|
| 53 | + public function testFieldLabels() |
|
| 54 | + { |
|
| 55 | + $this->markTestSkipped(); |
|
| 56 | + // Link and File tracking display as "Tracking" in SS 4.2 & 4.3, "Tracking" in 4.4 |
|
| 57 | + $location = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 58 | + $labels = $location->FieldLabels(); |
|
| 59 | + $expected = [ |
|
| 60 | + 'Title' => 'Name', |
|
| 61 | + 'Featured' => 'Featured', |
|
| 62 | + 'Website' => 'Website', |
|
| 63 | + 'Phone' => 'Phone', |
|
| 64 | + 'Email' => 'Email', |
|
| 65 | + 'Fax' => 'Fax', |
|
| 66 | + 'Address' => 'Address', |
|
| 67 | + 'City' => 'City', |
|
| 68 | + 'State' => 'State', |
|
| 69 | + 'PostalCode' => 'Postal Code', |
|
| 70 | + 'Country' => 'Country', |
|
| 71 | + 'Lat' => 'Lat', |
|
| 72 | + 'Lng' => 'Lng', |
|
| 73 | + 'Categories' => 'Categories', |
|
| 74 | + 'Category.Name' => 'Category', |
|
| 75 | + 'Category.ID' => 'Category', |
|
| 76 | + 'Featured.NiceAsBoolean' => 'Featured', |
|
| 77 | + 'Import_ID' => 'Import_ID', |
|
| 78 | + 'Version' => 'Version', |
|
| 79 | + 'Versions' => 'Versions', |
|
| 80 | + 'Address2' => 'Address2', |
|
| 81 | + 'LinkTracking' => 'Link tracking', |
|
| 82 | + 'FileTracking' => 'File tracking', |
|
| 83 | + ]; |
|
| 84 | + $this->assertEquals($expected, $labels); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * |
|
| 89 | + */ |
|
| 90 | + public function testGetCMSFields() |
|
| 91 | + { |
|
| 92 | + $object = new Location(); |
|
| 93 | + $fieldset = $object->getCMSFields(); |
|
| 94 | + $this->assertinstanceOf(FieldList::class, $fieldset); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * |
|
| 99 | + */ |
|
| 100 | + public function testCanView() |
|
| 101 | + { |
|
| 102 | + $object = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 103 | + $object->write(); |
|
| 104 | + |
|
| 105 | + $this->assertTrue($object->canView()); |
|
| 106 | + |
|
| 107 | + $nullMember = Member::create(); |
|
| 108 | + $nullMember->write(); |
|
| 109 | + |
|
| 110 | + $this->assertTrue($object->canView($nullMember)); |
|
| 111 | + |
|
| 112 | + $nullMember->delete(); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * |
|
| 117 | + */ |
|
| 118 | + public function testCanEdit() |
|
| 119 | + { |
|
| 120 | + $object = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 121 | + $object->write(); |
|
| 122 | + |
|
| 123 | + $objectID = $object->ID; |
|
| 124 | + |
|
| 125 | + //test permissions per permission setting |
|
| 126 | + $create = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 127 | + $edit = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 128 | + $delete = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 129 | + |
|
| 130 | + $originalTitle = $object->Title; |
|
| 131 | + $this->assertEquals($originalTitle, 'Dynamic, Inc.'); |
|
| 132 | + |
|
| 133 | + $this->assertTrue($object->canEdit($edit)); |
|
| 134 | + $this->assertFalse($object->canEdit($create)); |
|
| 135 | + $this->assertFalse($object->canEdit($delete)); |
|
| 136 | + |
|
| 137 | + $object->Title = 'Changed Title'; |
|
| 138 | + $object->write(); |
|
| 139 | + |
|
| 140 | + $testEdit = Location::get()->byID($objectID); |
|
| 141 | + $this->assertEquals($testEdit->Title, 'Changed Title'); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * |
|
| 146 | + */ |
|
| 147 | + public function testCanDelete() |
|
| 148 | + { |
|
| 149 | + $object = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 150 | + $object->write(); |
|
| 151 | + |
|
| 152 | + //test permissions per permission setting |
|
| 153 | + $create = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 154 | + $edit = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 155 | + $delete = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 156 | + |
|
| 157 | + $this->assertTrue($object->canDelete($delete)); |
|
| 158 | + $this->assertFalse($object->canDelete($create)); |
|
| 159 | + $this->assertFalse($object->canDelete($edit)); |
|
| 160 | + |
|
| 161 | + $checkObject = $object; |
|
| 162 | + $object->delete(); |
|
| 163 | + |
|
| 164 | + $this->assertEquals($checkObject->ID, 0); |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * |
|
| 169 | + */ |
|
| 170 | + public function testCanCreate() |
|
| 171 | + { |
|
| 172 | + $object = singleton(Location::class); |
|
| 173 | + |
|
| 174 | + //test permissions per permission setting |
|
| 175 | + $create = $this->objFromFixture(Member::class, 'locationcreate'); |
|
| 176 | + $edit = $this->objFromFixture(Member::class, 'locationedit'); |
|
| 177 | + $delete = $this->objFromFixture(Member::class, 'locationdelete'); |
|
| 178 | + |
|
| 179 | + $this->assertTrue($object->canCreate($create)); |
|
| 180 | + $this->assertFalse($object->canCreate($edit)); |
|
| 181 | + $this->assertFalse($object->canCreate($delete)); |
|
| 182 | + |
|
| 183 | + $nullMember = Member::create(); |
|
| 184 | + $nullMember->write(); |
|
| 185 | + $this->assertFalse($object->canCreate($nullMember)); |
|
| 186 | + |
|
| 187 | + $nullMember->delete(); |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * |
|
| 192 | + */ |
|
| 193 | + public function testProvidePermissions() |
|
| 194 | + { |
|
| 195 | + $object = Location::create(); |
|
| 196 | + $expected = [ |
|
| 197 | + 'Location_EDIT' => 'Edit a Location', |
|
| 198 | + 'Location_DELETE' => 'Delete a Location', |
|
| 199 | + 'Location_CREATE' => 'Create a Location', |
|
| 200 | + ]; |
|
| 201 | + $this->assertEquals($expected, $object->providePermissions()); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * |
|
| 206 | + */ |
|
| 207 | + public function testUpdateWebsiteURL() |
|
| 208 | + { |
|
| 209 | + $location = $this->objFromFixture(Location::class, 'dynamic'); |
|
| 210 | + |
|
| 211 | + // Create unsaved raw duplicate |
|
| 212 | + $map = $location->toMap(); |
|
| 213 | + unset($map['Created']); |
|
| 214 | + /** @var static $clone */ |
|
| 215 | + $clone = Injector::inst()->create(ExtendedLocation::class, $map); |
|
| 216 | + $clone->ID = 0; |
|
| 217 | + |
|
| 218 | + $this->assertEquals('http://www.dynamicagency.com', $location->getWebsiteURL()); |
|
| 219 | + $this->assertEquals('foo', $clone->getWebsiteURL()); |
|
| 220 | + } |
|
| 221 | 221 | } |
@@ -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 | |
@@ -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 | } |
@@ -11,11 +11,11 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class LocationExtension extends DataExtension implements TestOnly |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @param $url |
|
| 16 | - */ |
|
| 17 | - public function updateWebsiteURL(&$url) |
|
| 18 | - { |
|
| 19 | - $url = 'foo'; |
|
| 20 | - } |
|
| 14 | + /** |
|
| 15 | + * @param $url |
|
| 16 | + */ |
|
| 17 | + public function updateWebsiteURL(&$url) |
|
| 18 | + { |
|
| 19 | + $url = 'foo'; |
|
| 20 | + } |
|
| 21 | 21 | } |
@@ -13,35 +13,35 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class EmailAddressTask extends BuildTask |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 19 | - protected $title = 'Email Address Task'; // title of the script |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $description = "Convert depreciated 'Email Address' field to new 'Email' field."; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @param HTTPRequest $request |
|
| 28 | - */ |
|
| 29 | - public function run($request) |
|
| 30 | - { |
|
| 31 | - Config::modify()->set('DataObject', 'validation_enabled', false); |
|
| 32 | - |
|
| 33 | - $ct = 0; |
|
| 34 | - $updateEmail = function ($location) use (&$ct) { |
|
| 35 | - if (!$location->Email && $location->EmailAddress) { |
|
| 36 | - $location->Email = $location->EmailAddress; |
|
| 37 | - $location->write(); |
|
| 38 | - ++$ct; |
|
| 39 | - } |
|
| 40 | - }; |
|
| 41 | - |
|
| 42 | - Location::get()->each($updateEmail); |
|
| 43 | - Config::modify()->set('DataObject', 'validation_enabled', true); |
|
| 44 | - |
|
| 45 | - echo '<p>' . $ct . ' Locations updated</p>'; |
|
| 46 | - } |
|
| 16 | + /** |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | + protected $title = 'Email Address Task'; // title of the script |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $description = "Convert depreciated 'Email Address' field to new 'Email' field."; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @param HTTPRequest $request |
|
| 28 | + */ |
|
| 29 | + public function run($request) |
|
| 30 | + { |
|
| 31 | + Config::modify()->set('DataObject', 'validation_enabled', false); |
|
| 32 | + |
|
| 33 | + $ct = 0; |
|
| 34 | + $updateEmail = function ($location) use (&$ct) { |
|
| 35 | + if (!$location->Email && $location->EmailAddress) { |
|
| 36 | + $location->Email = $location->EmailAddress; |
|
| 37 | + $location->write(); |
|
| 38 | + ++$ct; |
|
| 39 | + } |
|
| 40 | + }; |
|
| 41 | + |
|
| 42 | + Location::get()->each($updateEmail); |
|
| 43 | + Config::modify()->set('DataObject', 'validation_enabled', true); |
|
| 44 | + |
|
| 45 | + echo '<p>' . $ct . ' Locations updated</p>'; |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | Config::modify()->set('DataObject', 'validation_enabled', false); |
| 32 | 32 | |
| 33 | 33 | $ct = 0; |
| 34 | - $updateEmail = function ($location) use (&$ct) { |
|
| 34 | + $updateEmail = function($location) use (&$ct) { |
|
| 35 | 35 | if (!$location->Email && $location->EmailAddress) { |
| 36 | 36 | $location->Email = $location->EmailAddress; |
| 37 | 37 | $location->write(); |
@@ -42,6 +42,6 @@ discard block |
||
| 42 | 42 | Location::get()->each($updateEmail); |
| 43 | 43 | Config::modify()->set('DataObject', 'validation_enabled', true); |
| 44 | 44 | |
| 45 | - echo '<p>' . $ct . ' Locations updated</p>'; |
|
| 45 | + echo '<p>'.$ct.' Locations updated</p>'; |
|
| 46 | 46 | } |
| 47 | 47 | } |
@@ -17,83 +17,83 @@ |
||
| 17 | 17 | class LocationsAdmin extends CatalogPageAdmin |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var array |
|
| 22 | - */ |
|
| 23 | - private static $managed_models = [ |
|
| 24 | - LocationPage::class, |
|
| 25 | - LocationCategory::class, |
|
| 26 | - ]; |
|
| 20 | + /** |
|
| 21 | + * @var array |
|
| 22 | + */ |
|
| 23 | + private static $managed_models = [ |
|
| 24 | + LocationPage::class, |
|
| 25 | + LocationCategory::class, |
|
| 26 | + ]; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - private static $model_importers = [ |
|
| 32 | - LocationCategory::class => CsvBulkLoader::class, |
|
| 33 | - ]; |
|
| 28 | + /** |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + private static $model_importers = [ |
|
| 32 | + LocationCategory::class => CsvBulkLoader::class, |
|
| 33 | + ]; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - private static $menu_title = 'Locations'; |
|
| 35 | + /** |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + private static $menu_title = 'Locations'; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 43 | - private static $url_segment = 'locations'; |
|
| 40 | + /** |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | + private static $url_segment = 'locations'; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @return array |
|
| 47 | - */ |
|
| 48 | - public function getExportFields() |
|
| 49 | - { |
|
| 50 | - if ($this->modelClass == LocationPage::class) { |
|
| 51 | - $fields = [ |
|
| 52 | - 'Title' => 'Name', |
|
| 53 | - 'Address' => 'Address', |
|
| 54 | - 'Address2' => 'Address2', |
|
| 55 | - 'City' => 'City', |
|
| 56 | - 'State' => 'State', |
|
| 57 | - 'PostalCode' => 'PostalCode', |
|
| 58 | - 'CountryCode' => 'Country', |
|
| 59 | - 'Phone' => 'Phone', |
|
| 60 | - 'Fax' => 'Fax', |
|
| 61 | - 'Email' => 'Email', |
|
| 62 | - 'Website' => 'Website', |
|
| 63 | - 'Featured' => 'Featured', |
|
| 64 | - 'CategoryList' => 'Categories', |
|
| 65 | - 'Lat' => 'Lat', |
|
| 66 | - 'Lng' => 'Lng', |
|
| 67 | - 'Import_ID' => 'Import_ID', |
|
| 68 | - ]; |
|
| 69 | - } |
|
| 45 | + /** |
|
| 46 | + * @return array |
|
| 47 | + */ |
|
| 48 | + public function getExportFields() |
|
| 49 | + { |
|
| 50 | + if ($this->modelClass == LocationPage::class) { |
|
| 51 | + $fields = [ |
|
| 52 | + 'Title' => 'Name', |
|
| 53 | + 'Address' => 'Address', |
|
| 54 | + 'Address2' => 'Address2', |
|
| 55 | + 'City' => 'City', |
|
| 56 | + 'State' => 'State', |
|
| 57 | + 'PostalCode' => 'PostalCode', |
|
| 58 | + 'CountryCode' => 'Country', |
|
| 59 | + 'Phone' => 'Phone', |
|
| 60 | + 'Fax' => 'Fax', |
|
| 61 | + 'Email' => 'Email', |
|
| 62 | + 'Website' => 'Website', |
|
| 63 | + 'Featured' => 'Featured', |
|
| 64 | + 'CategoryList' => 'Categories', |
|
| 65 | + 'Lat' => 'Lat', |
|
| 66 | + 'Lng' => 'Lng', |
|
| 67 | + 'Import_ID' => 'Import_ID', |
|
| 68 | + ]; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - if (!isset($fields)) { |
|
| 72 | - $fields = parent::getExportFields(); |
|
| 73 | - } |
|
| 71 | + if (!isset($fields)) { |
|
| 72 | + $fields = parent::getExportFields(); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - $this->extend('updateGetExportFields', $fields); |
|
| 75 | + $this->extend('updateGetExportFields', $fields); |
|
| 76 | 76 | |
| 77 | - return $fields; |
|
| 78 | - } |
|
| 77 | + return $fields; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @param null $id |
|
| 82 | - * @param null $fields |
|
| 83 | - * @return $this|Form |
|
| 84 | - */ |
|
| 85 | - public function getEditForm($id = null, $fields = null) |
|
| 86 | - { |
|
| 87 | - $form = parent::getEditForm($id, $fields); |
|
| 80 | + /** |
|
| 81 | + * @param null $id |
|
| 82 | + * @param null $fields |
|
| 83 | + * @return $this|Form |
|
| 84 | + */ |
|
| 85 | + public function getEditForm($id = null, $fields = null) |
|
| 86 | + { |
|
| 87 | + $form = parent::getEditForm($id, $fields); |
|
| 88 | 88 | |
| 89 | - if ($this->modelClass == LocationPage::class) { |
|
| 90 | - /** @var GridField $gridField */ |
|
| 91 | - if ($gridField = $form->Fields()->fieldByName($this->sanitiseClassName($this->modelClass))) { |
|
| 92 | - $gridField->getConfig() |
|
| 93 | - ->removeComponentsByType('GridFieldDeleteAction'); |
|
| 94 | - } |
|
| 95 | - } |
|
| 89 | + if ($this->modelClass == LocationPage::class) { |
|
| 90 | + /** @var GridField $gridField */ |
|
| 91 | + if ($gridField = $form->Fields()->fieldByName($this->sanitiseClassName($this->modelClass))) { |
|
| 92 | + $gridField->getConfig() |
|
| 93 | + ->removeComponentsByType('GridFieldDeleteAction'); |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - return $form; |
|
| 98 | - } |
|
| 97 | + return $form; |
|
| 98 | + } |
|
| 99 | 99 | } |
@@ -28,269 +28,269 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class Locator extends \Page |
| 30 | 30 | { |
| 31 | - /** |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - private static $singular_name = 'Locator'; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - private static $plural_name = 'Locators'; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var string |
|
| 43 | - */ |
|
| 44 | - private static $description = 'Display locations on a map'; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var array |
|
| 48 | - */ |
|
| 49 | - private static $db = [ |
|
| 50 | - 'Unit' => 'Enum("m,km","m")', |
|
| 51 | - ]; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var array |
|
| 55 | - */ |
|
| 56 | - private static $many_many = [ |
|
| 57 | - 'Categories' => LocationCategory::class, |
|
| 58 | - ]; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @var string |
|
| 62 | - */ |
|
| 63 | - private static $table_name = 'Locator'; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @var string |
|
| 67 | - */ |
|
| 68 | - private static $location_class = LocationPage::class; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @var string[] |
|
| 72 | - */ |
|
| 73 | - private static $extensions = [ |
|
| 74 | - Lumberjack::class, |
|
| 75 | - ]; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @var string[] |
|
| 79 | - */ |
|
| 80 | - private static $allowed_children = [ |
|
| 81 | - LocationPage::class, |
|
| 82 | - ]; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @return FieldList |
|
| 86 | - */ |
|
| 87 | - public function getCMSFields() |
|
| 88 | - { |
|
| 89 | - $this->beforeUpdateCMSFields(function ($fields) { |
|
| 90 | - // Settings |
|
| 91 | - $fields->addFieldsToTab('Root.Settings', [ |
|
| 92 | - HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
| 93 | - OptionsetField::create('Unit', 'Unit of measure', ['m' => 'Miles', 'km' => 'Kilometers']), |
|
| 94 | - ]); |
|
| 95 | - |
|
| 96 | - // Filter categories |
|
| 97 | - $config = GridFieldConfig_RelationEditor::create(); |
|
| 98 | - $config->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
|
| 99 | - $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
| 100 | - $categories = $this->Categories(); |
|
| 101 | - $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
| 102 | - ->setDescription('only show locations from the selected category'); |
|
| 103 | - |
|
| 104 | - // Filter |
|
| 105 | - $fields->addFieldsToTab('Root.Filter', [ |
|
| 106 | - HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
| 107 | - $categoriesField, |
|
| 108 | - ]); |
|
| 109 | - }); |
|
| 110 | - |
|
| 111 | - return parent::getCMSFields(); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @param array $filter |
|
| 116 | - * @param array $filterAny |
|
| 117 | - * @param array $exclude |
|
| 118 | - * @param null|callable $callback |
|
| 119 | - * |
|
| 120 | - * @return DataList|ArrayList |
|
| 121 | - */ |
|
| 122 | - public static function get_locations($filter = [], $filterAny = [], $exclude = [], $callback = null) |
|
| 123 | - { |
|
| 124 | - $locationClass = Config::inst()->get(static::class, 'location_class'); |
|
| 125 | - $locations = $locationClass::get()->filter($filter)->exclude($exclude); |
|
| 126 | - |
|
| 127 | - if (!empty($filterAny)) { |
|
| 128 | - $locations = $locations->filterAny($filterAny); |
|
| 129 | - } |
|
| 130 | - if (!empty($exclude)) { |
|
| 131 | - $locations = $locations->exclude($exclude); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - if ($callback !== null && is_callable($callback)) { |
|
| 135 | - $locations->filterByCallback($callback); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $locations; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @return DataList |
|
| 143 | - */ |
|
| 144 | - public static function get_all_categories() |
|
| 145 | - { |
|
| 146 | - return LocationCategory::get(); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @return bool |
|
| 151 | - */ |
|
| 152 | - public function getPageCategories() |
|
| 153 | - { |
|
| 154 | - return self::locator_categories_by_locator($this->ID); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @param int $id |
|
| 159 | - * |
|
| 160 | - * @return bool| |
|
| 161 | - */ |
|
| 162 | - public static function locator_categories_by_locator($id = 0) |
|
| 163 | - { |
|
| 164 | - if ($id == 0) { |
|
| 165 | - return false; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** @var Locator $locator */ |
|
| 169 | - if ($locator = static::get()->byID($id)) { |
|
| 170 | - return $locator->getUsedCategories(); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - return false; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Gets the list of radii |
|
| 178 | - * |
|
| 179 | - * @return ArrayList |
|
| 180 | - */ |
|
| 181 | - public function getRadii() |
|
| 182 | - { |
|
| 183 | - $radii = [ |
|
| 184 | - '0' => '25', |
|
| 185 | - '1' => '50', |
|
| 186 | - '2' => '75', |
|
| 187 | - '3' => '100', |
|
| 188 | - ]; |
|
| 189 | - $config_radii = $this->config()->get('radii'); |
|
| 190 | - if ($config_radii) { |
|
| 191 | - $radii = $config_radii; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - return $radii; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - public function getRadiiArrayList() |
|
| 198 | - { |
|
| 199 | - $list = []; |
|
| 200 | - |
|
| 201 | - foreach ($this->getRadii() as $radius) { |
|
| 202 | - $list[] = new ArrayData([ |
|
| 203 | - 'Radius' => $radius, |
|
| 204 | - ]); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - return new ArrayList($list); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Gets the limit of locations |
|
| 212 | - * @return mixed |
|
| 213 | - */ |
|
| 214 | - public function getLimit() |
|
| 215 | - { |
|
| 216 | - return $this->config()->get('limit'); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Gets if the radius drop down should be shown |
|
| 221 | - * @return mixed |
|
| 222 | - */ |
|
| 223 | - public function getShowRadius() |
|
| 224 | - { |
|
| 225 | - return $this->config()->get('show_radius'); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * @return mixed |
|
| 230 | - */ |
|
| 231 | - public function getUsedCategories() |
|
| 232 | - { |
|
| 233 | - return $this->Categories()->filter([ |
|
| 234 | - 'LocationSet.ID:GreaterThan' => 0, |
|
| 235 | - ]); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * Gets the path of the info window template |
|
| 240 | - * |
|
| 241 | - * @return string |
|
| 242 | - */ |
|
| 243 | - public function getInfoWindowTemplate() |
|
| 244 | - { |
|
| 245 | - return ModuleResourceLoader::singleton()->resolveURL( |
|
| 246 | - Config::inst()->get( |
|
| 247 | - static::class, |
|
| 248 | - 'infoWindowTemplate' |
|
| 249 | - ) |
|
| 250 | - ); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * Gets the path of the list template |
|
| 255 | - * |
|
| 256 | - * @return string |
|
| 257 | - */ |
|
| 258 | - public function getListTemplate() |
|
| 259 | - { |
|
| 260 | - return ModuleResourceLoader::singleton()->resolveURL( |
|
| 261 | - Config::inst()->get( |
|
| 262 | - static::class, |
|
| 263 | - 'listTemplate' |
|
| 264 | - ) |
|
| 265 | - ); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * @return null|string |
|
| 270 | - */ |
|
| 271 | - public function getMapStyle() |
|
| 272 | - { |
|
| 273 | - return AddressDataExtension::getMapStyleJSON(); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - public function getMapStyleJSONPath() |
|
| 277 | - { |
|
| 278 | - return AddressDataExtension::getMapStyleJSONPath(); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * @return null|string |
|
| 283 | - */ |
|
| 284 | - public function getMarkerIcon() |
|
| 285 | - { |
|
| 286 | - return AddressDataExtension::getIconImage(); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * @return string |
|
| 291 | - */ |
|
| 292 | - public function getLumberjackTitle() |
|
| 293 | - { |
|
| 294 | - return _t(__CLASS__ . '.LumberjackTitle', 'Locations'); |
|
| 295 | - } |
|
| 31 | + /** |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + private static $singular_name = 'Locator'; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + private static $plural_name = 'Locators'; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var string |
|
| 43 | + */ |
|
| 44 | + private static $description = 'Display locations on a map'; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var array |
|
| 48 | + */ |
|
| 49 | + private static $db = [ |
|
| 50 | + 'Unit' => 'Enum("m,km","m")', |
|
| 51 | + ]; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var array |
|
| 55 | + */ |
|
| 56 | + private static $many_many = [ |
|
| 57 | + 'Categories' => LocationCategory::class, |
|
| 58 | + ]; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @var string |
|
| 62 | + */ |
|
| 63 | + private static $table_name = 'Locator'; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @var string |
|
| 67 | + */ |
|
| 68 | + private static $location_class = LocationPage::class; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @var string[] |
|
| 72 | + */ |
|
| 73 | + private static $extensions = [ |
|
| 74 | + Lumberjack::class, |
|
| 75 | + ]; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @var string[] |
|
| 79 | + */ |
|
| 80 | + private static $allowed_children = [ |
|
| 81 | + LocationPage::class, |
|
| 82 | + ]; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @return FieldList |
|
| 86 | + */ |
|
| 87 | + public function getCMSFields() |
|
| 88 | + { |
|
| 89 | + $this->beforeUpdateCMSFields(function ($fields) { |
|
| 90 | + // Settings |
|
| 91 | + $fields->addFieldsToTab('Root.Settings', [ |
|
| 92 | + HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
| 93 | + OptionsetField::create('Unit', 'Unit of measure', ['m' => 'Miles', 'km' => 'Kilometers']), |
|
| 94 | + ]); |
|
| 95 | + |
|
| 96 | + // Filter categories |
|
| 97 | + $config = GridFieldConfig_RelationEditor::create(); |
|
| 98 | + $config->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
|
| 99 | + $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
| 100 | + $categories = $this->Categories(); |
|
| 101 | + $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
| 102 | + ->setDescription('only show locations from the selected category'); |
|
| 103 | + |
|
| 104 | + // Filter |
|
| 105 | + $fields->addFieldsToTab('Root.Filter', [ |
|
| 106 | + HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
| 107 | + $categoriesField, |
|
| 108 | + ]); |
|
| 109 | + }); |
|
| 110 | + |
|
| 111 | + return parent::getCMSFields(); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @param array $filter |
|
| 116 | + * @param array $filterAny |
|
| 117 | + * @param array $exclude |
|
| 118 | + * @param null|callable $callback |
|
| 119 | + * |
|
| 120 | + * @return DataList|ArrayList |
|
| 121 | + */ |
|
| 122 | + public static function get_locations($filter = [], $filterAny = [], $exclude = [], $callback = null) |
|
| 123 | + { |
|
| 124 | + $locationClass = Config::inst()->get(static::class, 'location_class'); |
|
| 125 | + $locations = $locationClass::get()->filter($filter)->exclude($exclude); |
|
| 126 | + |
|
| 127 | + if (!empty($filterAny)) { |
|
| 128 | + $locations = $locations->filterAny($filterAny); |
|
| 129 | + } |
|
| 130 | + if (!empty($exclude)) { |
|
| 131 | + $locations = $locations->exclude($exclude); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + if ($callback !== null && is_callable($callback)) { |
|
| 135 | + $locations->filterByCallback($callback); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $locations; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @return DataList |
|
| 143 | + */ |
|
| 144 | + public static function get_all_categories() |
|
| 145 | + { |
|
| 146 | + return LocationCategory::get(); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @return bool |
|
| 151 | + */ |
|
| 152 | + public function getPageCategories() |
|
| 153 | + { |
|
| 154 | + return self::locator_categories_by_locator($this->ID); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @param int $id |
|
| 159 | + * |
|
| 160 | + * @return bool| |
|
| 161 | + */ |
|
| 162 | + public static function locator_categories_by_locator($id = 0) |
|
| 163 | + { |
|
| 164 | + if ($id == 0) { |
|
| 165 | + return false; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** @var Locator $locator */ |
|
| 169 | + if ($locator = static::get()->byID($id)) { |
|
| 170 | + return $locator->getUsedCategories(); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + return false; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Gets the list of radii |
|
| 178 | + * |
|
| 179 | + * @return ArrayList |
|
| 180 | + */ |
|
| 181 | + public function getRadii() |
|
| 182 | + { |
|
| 183 | + $radii = [ |
|
| 184 | + '0' => '25', |
|
| 185 | + '1' => '50', |
|
| 186 | + '2' => '75', |
|
| 187 | + '3' => '100', |
|
| 188 | + ]; |
|
| 189 | + $config_radii = $this->config()->get('radii'); |
|
| 190 | + if ($config_radii) { |
|
| 191 | + $radii = $config_radii; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + return $radii; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + public function getRadiiArrayList() |
|
| 198 | + { |
|
| 199 | + $list = []; |
|
| 200 | + |
|
| 201 | + foreach ($this->getRadii() as $radius) { |
|
| 202 | + $list[] = new ArrayData([ |
|
| 203 | + 'Radius' => $radius, |
|
| 204 | + ]); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + return new ArrayList($list); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Gets the limit of locations |
|
| 212 | + * @return mixed |
|
| 213 | + */ |
|
| 214 | + public function getLimit() |
|
| 215 | + { |
|
| 216 | + return $this->config()->get('limit'); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Gets if the radius drop down should be shown |
|
| 221 | + * @return mixed |
|
| 222 | + */ |
|
| 223 | + public function getShowRadius() |
|
| 224 | + { |
|
| 225 | + return $this->config()->get('show_radius'); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * @return mixed |
|
| 230 | + */ |
|
| 231 | + public function getUsedCategories() |
|
| 232 | + { |
|
| 233 | + return $this->Categories()->filter([ |
|
| 234 | + 'LocationSet.ID:GreaterThan' => 0, |
|
| 235 | + ]); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * Gets the path of the info window template |
|
| 240 | + * |
|
| 241 | + * @return string |
|
| 242 | + */ |
|
| 243 | + public function getInfoWindowTemplate() |
|
| 244 | + { |
|
| 245 | + return ModuleResourceLoader::singleton()->resolveURL( |
|
| 246 | + Config::inst()->get( |
|
| 247 | + static::class, |
|
| 248 | + 'infoWindowTemplate' |
|
| 249 | + ) |
|
| 250 | + ); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * Gets the path of the list template |
|
| 255 | + * |
|
| 256 | + * @return string |
|
| 257 | + */ |
|
| 258 | + public function getListTemplate() |
|
| 259 | + { |
|
| 260 | + return ModuleResourceLoader::singleton()->resolveURL( |
|
| 261 | + Config::inst()->get( |
|
| 262 | + static::class, |
|
| 263 | + 'listTemplate' |
|
| 264 | + ) |
|
| 265 | + ); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * @return null|string |
|
| 270 | + */ |
|
| 271 | + public function getMapStyle() |
|
| 272 | + { |
|
| 273 | + return AddressDataExtension::getMapStyleJSON(); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + public function getMapStyleJSONPath() |
|
| 277 | + { |
|
| 278 | + return AddressDataExtension::getMapStyleJSONPath(); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * @return null|string |
|
| 283 | + */ |
|
| 284 | + public function getMarkerIcon() |
|
| 285 | + { |
|
| 286 | + return AddressDataExtension::getIconImage(); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * @return string |
|
| 291 | + */ |
|
| 292 | + public function getLumberjackTitle() |
|
| 293 | + { |
|
| 294 | + return _t(__CLASS__ . '.LumberjackTitle', 'Locations'); |
|
| 295 | + } |
|
| 296 | 296 | } |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | public function getCMSFields() |
| 88 | 88 | { |
| 89 | - $this->beforeUpdateCMSFields(function ($fields) { |
|
| 89 | + $this->beforeUpdateCMSFields(function($fields) { |
|
| 90 | 90 | // Settings |
| 91 | 91 | $fields->addFieldsToTab('Root.Settings', [ |
| 92 | 92 | HeaderField::create('DisplayOptions', 'Display Options', 3), |
@@ -291,6 +291,6 @@ discard block |
||
| 291 | 291 | */ |
| 292 | 292 | public function getLumberjackTitle() |
| 293 | 293 | { |
| 294 | - return _t(__CLASS__ . '.LumberjackTitle', 'Locations'); |
|
| 294 | + return _t(__CLASS__.'.LumberjackTitle', 'Locations'); |
|
| 295 | 295 | } |
| 296 | 296 | } |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | */ |
| 200 | 200 | public function getCMSFields() |
| 201 | 201 | { |
| 202 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 202 | + $this->beforeUpdateCMSFields(function(FieldList $fields) { |
|
| 203 | 203 | $fields->addFieldsToTab( |
| 204 | 204 | 'Root.Main', |
| 205 | 205 | [ |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | $url = $this->Website; |
| 304 | 304 | |
| 305 | 305 | if ($url && !preg_match('/^(http|https):\/\//', $url)) { |
| 306 | - $url = 'http://' . $url; |
|
| 306 | + $url = 'http://'.$url; |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | $this->extend('updateWebsiteURL', $url); |
@@ -31,283 +31,283 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class LocationPage extends \Page implements PermissionProvider |
| 33 | 33 | { |
| 34 | - /** |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 37 | - private static $singular_name = 'Location'; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var string |
|
| 41 | - */ |
|
| 42 | - private static $plural_name = 'Locations'; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var array |
|
| 46 | - */ |
|
| 47 | - private static $db = [ |
|
| 48 | - 'Featured' => 'Boolean', |
|
| 49 | - 'Website' => 'Varchar(255)', |
|
| 50 | - 'Phone' => 'Varchar(40)', |
|
| 51 | - 'Email' => 'Varchar(255)', |
|
| 52 | - 'Fax' => 'Varchar(45)', |
|
| 53 | - 'Import_ID' => 'Int', |
|
| 54 | - 'LegacyObjectID' => 'Int', |
|
| 55 | - ]; |
|
| 56 | - |
|
| 57 | - private static $many_many = [ |
|
| 58 | - 'Categories' => LocationCategory::class, |
|
| 59 | - ]; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var string |
|
| 63 | - */ |
|
| 64 | - private static $table_name = 'LocationPage'; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var array |
|
| 68 | - */ |
|
| 69 | - private static $casting = [ |
|
| 70 | - 'distance' => 'Decimal(9,3)', |
|
| 71 | - ]; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @var int[] |
|
| 75 | - */ |
|
| 76 | - private static $defaults = [ |
|
| 77 | - 'ShowInMenus' => 0, |
|
| 78 | - ]; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @var string |
|
| 82 | - */ |
|
| 83 | - private static $default_sort = 'Title'; |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * api access via Restful Server module |
|
| 87 | - * |
|
| 88 | - * @var bool |
|
| 89 | - */ |
|
| 90 | - private static $api_access = true; |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * search fields for Model Admin |
|
| 94 | - * |
|
| 95 | - * @var array |
|
| 96 | - */ |
|
| 97 | - private static $searchable_fields = [ |
|
| 98 | - 'Title', |
|
| 99 | - 'Address', |
|
| 100 | - 'City', |
|
| 101 | - 'State', |
|
| 102 | - 'PostalCode', |
|
| 103 | - 'Country', |
|
| 104 | - 'Website', |
|
| 105 | - 'Phone', |
|
| 106 | - 'Email', |
|
| 107 | - 'Featured', |
|
| 108 | - ]; |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * columns for grid field |
|
| 112 | - * |
|
| 113 | - * @var array |
|
| 114 | - */ |
|
| 115 | - private static $summary_fields = [ |
|
| 116 | - 'Title', |
|
| 117 | - 'Address', |
|
| 118 | - 'Address2', |
|
| 119 | - 'City', |
|
| 120 | - 'State', |
|
| 121 | - 'PostalCode', |
|
| 122 | - 'CountryCode', |
|
| 123 | - 'Phone' => 'Phone', |
|
| 124 | - 'Fax' => 'Fax', |
|
| 125 | - 'Email' => 'Email', |
|
| 126 | - 'Website' => 'Website', |
|
| 127 | - 'Featured', |
|
| 128 | - 'CategoryList', |
|
| 129 | - 'Lat', |
|
| 130 | - 'Lng', |
|
| 131 | - 'Import_ID', |
|
| 132 | - ]; |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @var bool |
|
| 136 | - */ |
|
| 137 | - private static $show_in_sitetree = false; |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * @var array |
|
| 141 | - */ |
|
| 142 | - private static $allowed_children = []; |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Coords status for $summary_fields |
|
| 146 | - * |
|
| 147 | - * @return string |
|
| 148 | - */ |
|
| 149 | - public function getCoords() |
|
| 150 | - { |
|
| 151 | - return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false'; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 157 | - public function getCategoryList() |
|
| 158 | - { |
|
| 159 | - if ($this->Categories()->count()) { |
|
| 160 | - return implode(', ', $this->Categories()->column('Name')); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - return ''; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @return bool|string |
|
| 168 | - */ |
|
| 169 | - public function getCountryCode() |
|
| 170 | - { |
|
| 171 | - if ($this->Country) { |
|
| 172 | - return strtoupper($this->Country); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - return false; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * custom labels for fields |
|
| 180 | - * |
|
| 181 | - * @param bool $includerelations |
|
| 182 | - * @return array|string |
|
| 183 | - */ |
|
| 184 | - public function fieldLabels($includerelations = true) |
|
| 185 | - { |
|
| 186 | - $labels = parent::fieldLabels($includerelations); |
|
| 187 | - |
|
| 188 | - $labels['Title'] = 'Name'; |
|
| 189 | - $labels['Address2'] = 'Address 2'; |
|
| 190 | - $labels['PostalCode'] = 'Postal Code'; |
|
| 191 | - $labels['Categories.Name'] = 'Categories'; |
|
| 192 | - $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
| 193 | - |
|
| 194 | - return $labels; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * @return FieldList |
|
| 199 | - */ |
|
| 200 | - public function getCMSFields() |
|
| 201 | - { |
|
| 202 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 203 | - $fields->addFieldsToTab( |
|
| 204 | - 'Root.Main', |
|
| 205 | - [ |
|
| 206 | - CheckboxField::create('Featured') |
|
| 207 | - ->setTitle('Featured'), |
|
| 208 | - ], |
|
| 209 | - 'Content' |
|
| 210 | - ); |
|
| 211 | - |
|
| 212 | - if ($this->exists()) { |
|
| 213 | - $fields->addFieldToTab( |
|
| 214 | - 'Root.Categories', |
|
| 215 | - GridField::create( |
|
| 216 | - 'Categories', |
|
| 217 | - 'Categories', |
|
| 218 | - $this->Categories(), |
|
| 219 | - $catConfig = GridFieldConfig_RelationEditor::create() |
|
| 220 | - ) |
|
| 221 | - ); |
|
| 222 | - |
|
| 223 | - $catConfig->removeComponentsByType([ |
|
| 224 | - GridFieldAddExistingAutocompleter::class, |
|
| 225 | - ])->addComponents([ |
|
| 226 | - new GridFieldAddExistingSearchButton() |
|
| 227 | - ]); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - $fields->addFieldsToTab('Root.Contact', [ |
|
| 231 | - TextField::create('Website') |
|
| 232 | - ->setTitle('Website') |
|
| 233 | - ->setDescription('Include the http/https (example: https://google.com)'), |
|
| 234 | - TextField::create('Phone') |
|
| 235 | - ->setTitle('Phone'), |
|
| 236 | - EmailField::create('Email') |
|
| 237 | - ->setTitle('Email'), |
|
| 238 | - TextField::create('Fax') |
|
| 239 | - ->setTitle('Fax'), |
|
| 240 | - ]); |
|
| 241 | - }); |
|
| 242 | - |
|
| 243 | - return parent::getCMSFields(); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * @param null $member |
|
| 248 | - * @param array $context |
|
| 249 | - * @return bool |
|
| 250 | - */ |
|
| 251 | - public function canView($member = null, $context = []) |
|
| 252 | - { |
|
| 253 | - return true; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * @param null $member |
|
| 258 | - * @param array $context |
|
| 259 | - * @return bool|int |
|
| 260 | - */ |
|
| 261 | - public function canEdit($member = null, $context = []) |
|
| 262 | - { |
|
| 263 | - return Permission::check('Location_EDIT', 'any', $member); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * @param null $member |
|
| 268 | - * @param array $context |
|
| 269 | - * @return bool|int |
|
| 270 | - */ |
|
| 271 | - public function canDelete($member = null, $context = []) |
|
| 272 | - { |
|
| 273 | - return Permission::check('Location_DELETE', 'any', $member); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * @param null $member |
|
| 278 | - * @param array $context |
|
| 279 | - * @return bool|int |
|
| 280 | - */ |
|
| 281 | - public function canCreate($member = null, $context = []) |
|
| 282 | - { |
|
| 283 | - return Permission::check('Location_CREATE', 'any', $member); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * @return array |
|
| 288 | - */ |
|
| 289 | - public function providePermissions() |
|
| 290 | - { |
|
| 291 | - return [ |
|
| 292 | - 'Location_EDIT' => 'Edit a Location', |
|
| 293 | - 'Location_DELETE' => 'Delete a Location', |
|
| 294 | - 'Location_CREATE' => 'Create a Location', |
|
| 295 | - ]; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * @return string |
|
| 300 | - */ |
|
| 301 | - public function getWebsiteURL() |
|
| 302 | - { |
|
| 303 | - $url = $this->Website; |
|
| 304 | - |
|
| 305 | - if ($url && !preg_match('/^(http|https):\/\//', $url)) { |
|
| 306 | - $url = 'http://' . $url; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - $this->extend('updateWebsiteURL', $url); |
|
| 310 | - |
|
| 311 | - return $url; |
|
| 312 | - } |
|
| 34 | + /** |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | + private static $singular_name = 'Location'; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var string |
|
| 41 | + */ |
|
| 42 | + private static $plural_name = 'Locations'; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var array |
|
| 46 | + */ |
|
| 47 | + private static $db = [ |
|
| 48 | + 'Featured' => 'Boolean', |
|
| 49 | + 'Website' => 'Varchar(255)', |
|
| 50 | + 'Phone' => 'Varchar(40)', |
|
| 51 | + 'Email' => 'Varchar(255)', |
|
| 52 | + 'Fax' => 'Varchar(45)', |
|
| 53 | + 'Import_ID' => 'Int', |
|
| 54 | + 'LegacyObjectID' => 'Int', |
|
| 55 | + ]; |
|
| 56 | + |
|
| 57 | + private static $many_many = [ |
|
| 58 | + 'Categories' => LocationCategory::class, |
|
| 59 | + ]; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var string |
|
| 63 | + */ |
|
| 64 | + private static $table_name = 'LocationPage'; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var array |
|
| 68 | + */ |
|
| 69 | + private static $casting = [ |
|
| 70 | + 'distance' => 'Decimal(9,3)', |
|
| 71 | + ]; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @var int[] |
|
| 75 | + */ |
|
| 76 | + private static $defaults = [ |
|
| 77 | + 'ShowInMenus' => 0, |
|
| 78 | + ]; |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * @var string |
|
| 82 | + */ |
|
| 83 | + private static $default_sort = 'Title'; |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * api access via Restful Server module |
|
| 87 | + * |
|
| 88 | + * @var bool |
|
| 89 | + */ |
|
| 90 | + private static $api_access = true; |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * search fields for Model Admin |
|
| 94 | + * |
|
| 95 | + * @var array |
|
| 96 | + */ |
|
| 97 | + private static $searchable_fields = [ |
|
| 98 | + 'Title', |
|
| 99 | + 'Address', |
|
| 100 | + 'City', |
|
| 101 | + 'State', |
|
| 102 | + 'PostalCode', |
|
| 103 | + 'Country', |
|
| 104 | + 'Website', |
|
| 105 | + 'Phone', |
|
| 106 | + 'Email', |
|
| 107 | + 'Featured', |
|
| 108 | + ]; |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * columns for grid field |
|
| 112 | + * |
|
| 113 | + * @var array |
|
| 114 | + */ |
|
| 115 | + private static $summary_fields = [ |
|
| 116 | + 'Title', |
|
| 117 | + 'Address', |
|
| 118 | + 'Address2', |
|
| 119 | + 'City', |
|
| 120 | + 'State', |
|
| 121 | + 'PostalCode', |
|
| 122 | + 'CountryCode', |
|
| 123 | + 'Phone' => 'Phone', |
|
| 124 | + 'Fax' => 'Fax', |
|
| 125 | + 'Email' => 'Email', |
|
| 126 | + 'Website' => 'Website', |
|
| 127 | + 'Featured', |
|
| 128 | + 'CategoryList', |
|
| 129 | + 'Lat', |
|
| 130 | + 'Lng', |
|
| 131 | + 'Import_ID', |
|
| 132 | + ]; |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @var bool |
|
| 136 | + */ |
|
| 137 | + private static $show_in_sitetree = false; |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * @var array |
|
| 141 | + */ |
|
| 142 | + private static $allowed_children = []; |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Coords status for $summary_fields |
|
| 146 | + * |
|
| 147 | + * @return string |
|
| 148 | + */ |
|
| 149 | + public function getCoords() |
|
| 150 | + { |
|
| 151 | + return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false'; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | + public function getCategoryList() |
|
| 158 | + { |
|
| 159 | + if ($this->Categories()->count()) { |
|
| 160 | + return implode(', ', $this->Categories()->column('Name')); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + return ''; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @return bool|string |
|
| 168 | + */ |
|
| 169 | + public function getCountryCode() |
|
| 170 | + { |
|
| 171 | + if ($this->Country) { |
|
| 172 | + return strtoupper($this->Country); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + return false; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * custom labels for fields |
|
| 180 | + * |
|
| 181 | + * @param bool $includerelations |
|
| 182 | + * @return array|string |
|
| 183 | + */ |
|
| 184 | + public function fieldLabels($includerelations = true) |
|
| 185 | + { |
|
| 186 | + $labels = parent::fieldLabels($includerelations); |
|
| 187 | + |
|
| 188 | + $labels['Title'] = 'Name'; |
|
| 189 | + $labels['Address2'] = 'Address 2'; |
|
| 190 | + $labels['PostalCode'] = 'Postal Code'; |
|
| 191 | + $labels['Categories.Name'] = 'Categories'; |
|
| 192 | + $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
| 193 | + |
|
| 194 | + return $labels; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * @return FieldList |
|
| 199 | + */ |
|
| 200 | + public function getCMSFields() |
|
| 201 | + { |
|
| 202 | + $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 203 | + $fields->addFieldsToTab( |
|
| 204 | + 'Root.Main', |
|
| 205 | + [ |
|
| 206 | + CheckboxField::create('Featured') |
|
| 207 | + ->setTitle('Featured'), |
|
| 208 | + ], |
|
| 209 | + 'Content' |
|
| 210 | + ); |
|
| 211 | + |
|
| 212 | + if ($this->exists()) { |
|
| 213 | + $fields->addFieldToTab( |
|
| 214 | + 'Root.Categories', |
|
| 215 | + GridField::create( |
|
| 216 | + 'Categories', |
|
| 217 | + 'Categories', |
|
| 218 | + $this->Categories(), |
|
| 219 | + $catConfig = GridFieldConfig_RelationEditor::create() |
|
| 220 | + ) |
|
| 221 | + ); |
|
| 222 | + |
|
| 223 | + $catConfig->removeComponentsByType([ |
|
| 224 | + GridFieldAddExistingAutocompleter::class, |
|
| 225 | + ])->addComponents([ |
|
| 226 | + new GridFieldAddExistingSearchButton() |
|
| 227 | + ]); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + $fields->addFieldsToTab('Root.Contact', [ |
|
| 231 | + TextField::create('Website') |
|
| 232 | + ->setTitle('Website') |
|
| 233 | + ->setDescription('Include the http/https (example: https://google.com)'), |
|
| 234 | + TextField::create('Phone') |
|
| 235 | + ->setTitle('Phone'), |
|
| 236 | + EmailField::create('Email') |
|
| 237 | + ->setTitle('Email'), |
|
| 238 | + TextField::create('Fax') |
|
| 239 | + ->setTitle('Fax'), |
|
| 240 | + ]); |
|
| 241 | + }); |
|
| 242 | + |
|
| 243 | + return parent::getCMSFields(); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * @param null $member |
|
| 248 | + * @param array $context |
|
| 249 | + * @return bool |
|
| 250 | + */ |
|
| 251 | + public function canView($member = null, $context = []) |
|
| 252 | + { |
|
| 253 | + return true; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * @param null $member |
|
| 258 | + * @param array $context |
|
| 259 | + * @return bool|int |
|
| 260 | + */ |
|
| 261 | + public function canEdit($member = null, $context = []) |
|
| 262 | + { |
|
| 263 | + return Permission::check('Location_EDIT', 'any', $member); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * @param null $member |
|
| 268 | + * @param array $context |
|
| 269 | + * @return bool|int |
|
| 270 | + */ |
|
| 271 | + public function canDelete($member = null, $context = []) |
|
| 272 | + { |
|
| 273 | + return Permission::check('Location_DELETE', 'any', $member); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * @param null $member |
|
| 278 | + * @param array $context |
|
| 279 | + * @return bool|int |
|
| 280 | + */ |
|
| 281 | + public function canCreate($member = null, $context = []) |
|
| 282 | + { |
|
| 283 | + return Permission::check('Location_CREATE', 'any', $member); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * @return array |
|
| 288 | + */ |
|
| 289 | + public function providePermissions() |
|
| 290 | + { |
|
| 291 | + return [ |
|
| 292 | + 'Location_EDIT' => 'Edit a Location', |
|
| 293 | + 'Location_DELETE' => 'Delete a Location', |
|
| 294 | + 'Location_CREATE' => 'Create a Location', |
|
| 295 | + ]; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * @return string |
|
| 300 | + */ |
|
| 301 | + public function getWebsiteURL() |
|
| 302 | + { |
|
| 303 | + $url = $this->Website; |
|
| 304 | + |
|
| 305 | + if ($url && !preg_match('/^(http|https):\/\//', $url)) { |
|
| 306 | + $url = 'http://' . $url; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + $this->extend('updateWebsiteURL', $url); |
|
| 310 | + |
|
| 311 | + return $url; |
|
| 312 | + } |
|
| 313 | 313 | } |
@@ -17,62 +17,62 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class LocatorFormTest extends FunctionalTest |
| 19 | 19 | { |
| 20 | - protected static $fixture_file = 'locatorformfixture.yml'; |
|
| 20 | + protected static $fixture_file = 'locatorformfixture.yml'; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * |
|
| 24 | - */ |
|
| 25 | - protected function setUp(): void |
|
| 26 | - { |
|
| 27 | - parent::setUp(); |
|
| 22 | + /** |
|
| 23 | + * |
|
| 24 | + */ |
|
| 25 | + protected function setUp(): void |
|
| 26 | + { |
|
| 27 | + parent::setUp(); |
|
| 28 | 28 | |
| 29 | - Config::modify()->set(Locator::class, 'location_class', Location::class); |
|
| 30 | - } |
|
| 29 | + Config::modify()->set(Locator::class, 'location_class', Location::class); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * |
|
| 34 | - */ |
|
| 35 | - public function testLocatorFormBase() |
|
| 36 | - { |
|
| 37 | - $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 38 | - $form = LocatorForm::create(LocatorController::create($locator), 'LocatorForm'); |
|
| 32 | + /** |
|
| 33 | + * |
|
| 34 | + */ |
|
| 35 | + public function testLocatorFormBase() |
|
| 36 | + { |
|
| 37 | + $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 38 | + $form = LocatorForm::create(LocatorController::create($locator), 'LocatorForm'); |
|
| 39 | 39 | |
| 40 | - $this->assertInstanceOf(FieldList::class, $form->Fields()); |
|
| 41 | - $this->assertInstanceOf(RequiredFields::class, $form->getValidator()); |
|
| 42 | - } |
|
| 40 | + $this->assertInstanceOf(FieldList::class, $form->Fields()); |
|
| 41 | + $this->assertInstanceOf(RequiredFields::class, $form->getValidator()); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * |
|
| 46 | - */ |
|
| 47 | - public function testUpdateRequiredFields() |
|
| 48 | - { |
|
| 49 | - $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 50 | - $form = LocatorForm::create(LocatorController::create($locator), 'LocatorForm'); |
|
| 51 | - $validator = $form->getValidator(); |
|
| 44 | + /** |
|
| 45 | + * |
|
| 46 | + */ |
|
| 47 | + public function testUpdateRequiredFields() |
|
| 48 | + { |
|
| 49 | + $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 50 | + $form = LocatorForm::create(LocatorController::create($locator), 'LocatorForm'); |
|
| 51 | + $validator = $form->getValidator(); |
|
| 52 | 52 | |
| 53 | - $validator->removeRequiredField('Address'); |
|
| 54 | - $validator->addRequiredField('Foo'); |
|
| 53 | + $validator->removeRequiredField('Address'); |
|
| 54 | + $validator->addRequiredField('Foo'); |
|
| 55 | 55 | |
| 56 | - $this->assertEquals(['Foo'], $form->getValidator()->getRequired()); |
|
| 57 | - } |
|
| 56 | + $this->assertEquals(['Foo'], $form->getValidator()->getRequired()); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * |
|
| 61 | - */ |
|
| 62 | - public function testFields() |
|
| 63 | - { |
|
| 64 | - $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 65 | - $form = LocatorForm::create(LocatorController::create($locator), 'LocatorForm'); |
|
| 66 | - $this->assertInstanceOf(FieldList::class, $form->Fields()); |
|
| 67 | - } |
|
| 59 | + /** |
|
| 60 | + * |
|
| 61 | + */ |
|
| 62 | + public function testFields() |
|
| 63 | + { |
|
| 64 | + $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 65 | + $form = LocatorForm::create(LocatorController::create($locator), 'LocatorForm'); |
|
| 66 | + $this->assertInstanceOf(FieldList::class, $form->Fields()); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * |
|
| 71 | - */ |
|
| 72 | - public function testActions() |
|
| 73 | - { |
|
| 74 | - $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 75 | - $form = LocatorForm::create(LocatorController::create($locator), 'LocatorForm'); |
|
| 76 | - $this->assertInstanceOf(FieldList::class, $form->Actions()); |
|
| 77 | - } |
|
| 69 | + /** |
|
| 70 | + * |
|
| 71 | + */ |
|
| 72 | + public function testActions() |
|
| 73 | + { |
|
| 74 | + $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 75 | + $form = LocatorForm::create(LocatorController::create($locator), 'LocatorForm'); |
|
| 76 | + $this->assertInstanceOf(FieldList::class, $form->Actions()); |
|
| 77 | + } |
|
| 78 | 78 | } |