Passed
Push — master ( 81b291...4e09b0 )
by Nic
12:17 queued 09:59
created
tests/objects/LocationCategoryTest.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -14,69 +14,69 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
tests/pages/LocatorTest.php 1 patch
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -21,158 +21,158 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/form/LocatorForm.php 1 patch
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -19,88 +19,88 @@
 block discarded – undo
19 19
 class LocatorForm extends Form
20 20
 {
21 21
 
22
-    /**
23
-     * LocatorForm constructor.
24
-     * @param Controller $controller
25
-     * @param string $name
26
-     */
27
-    public function __construct(Controller $controller, $name)
28
-    {
22
+	/**
23
+	 * LocatorForm constructor.
24
+	 * @param Controller $controller
25
+	 * @param string $name
26
+	 */
27
+	public function __construct(Controller $controller, $name)
28
+	{
29 29
 
30
-        $fields = FieldList::create(
31
-            TextField::create('Address')
32
-                ->setTitle('')
33
-                ->setAttribute('placeholder', 'address or zip code')
34
-        );
30
+		$fields = FieldList::create(
31
+			TextField::create('Address')
32
+				->setTitle('')
33
+				->setAttribute('placeholder', 'address or zip code')
34
+		);
35 35
 
36
-        $pageCategories = Locator::locator_categories_by_locator($controller->data()->ID);
37
-        if ($pageCategories && $pageCategories->count() > 0) {
38
-            $categories = false;
39
-        } else {
40
-            $categories = Locator::get_all_categories();
41
-            if ($categories->count() < 1) {
42
-                $categories = false;
43
-            }
44
-        }
36
+		$pageCategories = Locator::locator_categories_by_locator($controller->data()->ID);
37
+		if ($pageCategories && $pageCategories->count() > 0) {
38
+			$categories = false;
39
+		} else {
40
+			$categories = Locator::get_all_categories();
41
+			if ($categories->count() < 1) {
42
+				$categories = false;
43
+			}
44
+		}
45 45
 
46
-        if ($categories) {
47
-            $categoriesField = DropdownField::create('CategoryID')
48
-                ->setTitle('')
49
-                ->setEmptyString('all categories')
50
-                ->setSource($categories->map());
51
-            $fields->push($categoriesField);
52
-        }
46
+		if ($categories) {
47
+			$categoriesField = DropdownField::create('CategoryID')
48
+				->setTitle('')
49
+				->setEmptyString('all categories')
50
+				->setSource($categories->map());
51
+			$fields->push($categoriesField);
52
+		}
53 53
 
54
-        if ($controller->getShowRadius()) {
55
-            $radiusArray = array_values($controller->getRadii());
56
-            $this->extend('overrideRadiusArray', $radiusArray);
57
-            $fields->push(DropdownField::create('Radius', '', ArrayLib::valuekey($radiusArray))
58
-                ->setEmptyString('radius'));
59
-        }
54
+		if ($controller->getShowRadius()) {
55
+			$radiusArray = array_values($controller->getRadii());
56
+			$this->extend('overrideRadiusArray', $radiusArray);
57
+			$fields->push(DropdownField::create('Radius', '', ArrayLib::valuekey($radiusArray))
58
+				->setEmptyString('radius'));
59
+		}
60 60
 
61
-        $actions = FieldList::create(
62
-            FormAction::create('doFilterLocations')
63
-                ->setTitle('Search')
64
-        );
61
+		$actions = FieldList::create(
62
+			FormAction::create('doFilterLocations')
63
+				->setTitle('Search')
64
+		);
65 65
 
66
-        $validator = $this->getValidator();
66
+		$validator = $this->getValidator();
67 67
 
68
-        parent::__construct($controller, $name, $fields, $actions, $validator);
69
-    }
68
+		parent::__construct($controller, $name, $fields, $actions, $validator);
69
+	}
70 70
 
71
-    /**
72
-     * @return null|RequiredFields|\SilverStripe\Forms\Validator
73
-     */
74
-    public function getValidator()
75
-    {
76
-        $validator = parent::getValidator();
77
-        if (empty($validator)) {
78
-            if (!$this->validator instanceof RequiredFields) {
79
-                $this->setValidator(RequiredFields::create('Address'));
80
-            }
81
-            $validator = $this->validator;
82
-        }
83
-        $this->extend('updateRequiredFields', $validator);
84
-        return $validator;
85
-    }
71
+	/**
72
+	 * @return null|RequiredFields|\SilverStripe\Forms\Validator
73
+	 */
74
+	public function getValidator()
75
+	{
76
+		$validator = parent::getValidator();
77
+		if (empty($validator)) {
78
+			if (!$this->validator instanceof RequiredFields) {
79
+				$this->setValidator(RequiredFields::create('Address'));
80
+			}
81
+			$validator = $this->validator;
82
+		}
83
+		$this->extend('updateRequiredFields', $validator);
84
+		return $validator;
85
+	}
86 86
 
87
-    /**
88
-     * @return FieldList
89
-     */
90
-    public function Fields()
91
-    {
92
-        $fields = parent::Fields();
93
-        $this->extend('updateLocatorFormFields', $fields);
94
-        return $fields;
95
-    }
87
+	/**
88
+	 * @return FieldList
89
+	 */
90
+	public function Fields()
91
+	{
92
+		$fields = parent::Fields();
93
+		$this->extend('updateLocatorFormFields', $fields);
94
+		return $fields;
95
+	}
96 96
 
97
-    /**
98
-     * @return \SilverStripe\Forms\FieldList
99
-     */
100
-    public function Actions()
101
-    {
102
-        $actions = parent::Actions();
103
-        $this->extend('updateLocatorActions', $actions);
104
-        return $actions;
105
-    }
97
+	/**
98
+	 * @return \SilverStripe\Forms\FieldList
99
+	 */
100
+	public function Actions()
101
+	{
102
+		$actions = parent::Actions();
103
+		$this->extend('updateLocatorActions', $actions);
104
+		return $actions;
105
+	}
106 106
 }
Please login to merge, or discard this patch.
tests/form/LocatorFormTest.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -11,47 +11,47 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/admin/LocationAdmin.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -12,80 +12,80 @@
 block discarded – undo
12 12
 class LocationAdmin extends ModelAdmin
13 13
 {
14 14
 
15
-    /**
16
-     * @var array
17
-     */
18
-    private static $managed_models = array(
19
-        Location::class,
20
-        LocationCategory::class,
21
-    );
15
+	/**
16
+	 * @var array
17
+	 */
18
+	private static $managed_models = array(
19
+		Location::class,
20
+		LocationCategory::class,
21
+	);
22 22
 
23
-    /**
24
-     * @var array
25
-     */
26
-    private static $model_importers = array(
27
-        Location::class => LocationCsvBulkLoader::class,
28
-        LocationCategory::class => CsvBulkLoader::class,
29
-    );
23
+	/**
24
+	 * @var array
25
+	 */
26
+	private static $model_importers = array(
27
+		Location::class => LocationCsvBulkLoader::class,
28
+		LocationCategory::class => CsvBulkLoader::class,
29
+	);
30 30
 
31
-    /**
32
-     * @var string
33
-     */
34
-    private static $menu_title = 'Locator';
35
-    /**
36
-     * @var string
37
-     */
38
-    private static $url_segment = 'locator';
31
+	/**
32
+	 * @var string
33
+	 */
34
+	private static $menu_title = 'Locator';
35
+	/**
36
+	 * @var string
37
+	 */
38
+	private static $url_segment = 'locator';
39 39
 
40
-    /**
41
-     * @return array
42
-     */
43
-    public function getExportFields()
44
-    {
45
-        if ($this->modelClass == Location::class) {
46
-            $fields = [
47
-                'Title' => 'Name',
48
-                'Address' => 'Address',
49
-                'Address2' => 'Address2',
50
-                'City' => 'City',
51
-                'State' => 'State',
52
-                'PostalCode' => 'PostalCode',
53
-                'CountryCode' => 'Country',
54
-                'Phone' => 'Phone',
55
-                'Fax' => 'Fax',
56
-                'Email' => 'Email',
57
-                'Website' => 'Website',
58
-                'Featured' => 'Featured',
59
-                'CategoryList' => 'Categories',
60
-                'Lat' => 'Lat',
61
-                'Lng' => 'Lng',
62
-                'Import_ID' => 'Import_ID',
63
-            ];
64
-        }
40
+	/**
41
+	 * @return array
42
+	 */
43
+	public function getExportFields()
44
+	{
45
+		if ($this->modelClass == Location::class) {
46
+			$fields = [
47
+				'Title' => 'Name',
48
+				'Address' => 'Address',
49
+				'Address2' => 'Address2',
50
+				'City' => 'City',
51
+				'State' => 'State',
52
+				'PostalCode' => 'PostalCode',
53
+				'CountryCode' => 'Country',
54
+				'Phone' => 'Phone',
55
+				'Fax' => 'Fax',
56
+				'Email' => 'Email',
57
+				'Website' => 'Website',
58
+				'Featured' => 'Featured',
59
+				'CategoryList' => 'Categories',
60
+				'Lat' => 'Lat',
61
+				'Lng' => 'Lng',
62
+				'Import_ID' => 'Import_ID',
63
+			];
64
+		}
65 65
 
66
-        if (!isset($fields)) {
67
-            $fields = parent::getExportFields();
68
-        }
66
+		if (!isset($fields)) {
67
+			$fields = parent::getExportFields();
68
+		}
69 69
 
70
-        $this->extend('updateGetExportFields', $fields);
70
+		$this->extend('updateGetExportFields', $fields);
71 71
 
72
-        return $fields;
73
-    }
72
+		return $fields;
73
+	}
74 74
 
75
-    /**
76
-     * @param null $id
77
-     * @param null $fields
78
-     * @return $this|Form
79
-     */
80
-    public function getEditForm($id = null, $fields = null)
81
-    {
82
-        $form = parent::getEditForm($id, $fields);
83
-        $class = $this->sanitiseClassName($this->modelClass);
84
-        if ($class == Location::class) {
85
-            $gridField = $form->Fields()->fieldByName($class);
86
-            $config = $gridField->getConfig();
87
-            $config->removeComponentsByType('GridFieldDeleteAction');
88
-        }
89
-        return $form;
90
-    }
75
+	/**
76
+	 * @param null $id
77
+	 * @param null $fields
78
+	 * @return $this|Form
79
+	 */
80
+	public function getEditForm($id = null, $fields = null)
81
+	{
82
+		$form = parent::getEditForm($id, $fields);
83
+		$class = $this->sanitiseClassName($this->modelClass);
84
+		if ($class == Location::class) {
85
+			$gridField = $form->Fields()->fieldByName($class);
86
+			$config = $gridField->getConfig();
87
+			$config->removeComponentsByType('GridFieldDeleteAction');
88
+		}
89
+		return $form;
90
+	}
91 91
 }
Please login to merge, or discard this patch.
src/objects/LocationCategory.php 1 patch
Indentation   +121 added lines, -121 removed lines patch added patch discarded remove patch
@@ -20,125 +20,125 @@
 block discarded – undo
20 20
  */
21 21
 class LocationCategory extends DataObject
22 22
 {
23
-    /**
24
-     * @var string
25
-     */
26
-    private static $singular_name = 'Category';
27
-
28
-    /**
29
-     * @var string
30
-     */
31
-    private static $plural_name = 'Categories';
32
-
33
-    /**
34
-     * @var array
35
-     */
36
-    private static $db = array(
37
-        'Name' => 'Varchar(100)',
38
-    );
39
-
40
-    /**
41
-     * @var array
42
-     */
43
-    private static $belongs_many_many = array(
44
-        'Locators' => Locator::class,
45
-        'LocationSet' => Location::class,
46
-    );
47
-
48
-    /**
49
-     * @var string
50
-     */
51
-    private static $table_name = 'LocationCategory';
52
-
53
-    /**
54
-     * @var string
55
-     */
56
-    private static $default_sort = 'Name';
57
-
58
-    /**
59
-     * @return \SilverStripe\Forms\FieldList
60
-     */
61
-    public function getCMSFields()
62
-    {
63
-        $this->beforeUpdateCMSFields(function ($fields) {
64
-            $fields->removeByName([
65
-                'Locations',
66
-                'LocationSet',
67
-                'Locators',
68
-                'LinkTracking',
69
-                'FileTracking',
70
-            ]);
71
-
72
-            if ($this->ID) {
73
-                // Locations
74
-                $config = GridFieldConfig_RelationEditor::create();
75
-                $config->removeComponentsByType([
76
-                    GridFieldAddExistingAutocompleter::class,
77
-                    GridFieldAddNewButton::class
78
-                ])
79
-                    ->addComponents([
80
-                        new GridFieldAddExistingSearchButton(),
81
-                    ]);
82
-                $locations = $this->Locations();
83
-                $locationField = GridField::create('Locations', 'Locations', $locations, $config);
84
-
85
-                $fields->addFieldsToTab('Root.Main', array(
86
-                    $locationField,
87
-                ));
88
-            }
89
-        });
90
-
91
-        $fields = parent::getCMSFields();
92
-
93
-        return $fields;
94
-    }
95
-
96
-    /**
97
-     * For backwards compatability
98
-     * @return Locations|ManyManyList
99
-     */
100
-    public function Locations()
101
-    {
102
-        return $this->LocationSet();
103
-    }
104
-
105
-    /**
106
-     * @param null $member
107
-     * @param array $context
108
-     * @return bool
109
-     */
110
-    public function canView($member = null, $context = [])
111
-    {
112
-        return true;
113
-    }
114
-
115
-    /**
116
-     * @param null $member
117
-     * @param array $context
118
-     * @return bool|int
119
-     */
120
-    public function canEdit($member = null, $context = [])
121
-    {
122
-        return Permission::check('Location_EDIT', 'any', $member);
123
-    }
124
-
125
-    /**
126
-     * @param null $member
127
-     * @param array $context
128
-     * @return bool|int
129
-     */
130
-    public function canDelete($member = null, $context = [])
131
-    {
132
-        return Permission::check('Location_DELETE', 'any', $member);
133
-    }
134
-
135
-    /**
136
-     * @param null $member
137
-     * @param array $context
138
-     * @return bool|int
139
-     */
140
-    public function canCreate($member = null, $context = [])
141
-    {
142
-        return Permission::check('Location_CREATE', 'any', $member);
143
-    }
23
+	/**
24
+	 * @var string
25
+	 */
26
+	private static $singular_name = 'Category';
27
+
28
+	/**
29
+	 * @var string
30
+	 */
31
+	private static $plural_name = 'Categories';
32
+
33
+	/**
34
+	 * @var array
35
+	 */
36
+	private static $db = array(
37
+		'Name' => 'Varchar(100)',
38
+	);
39
+
40
+	/**
41
+	 * @var array
42
+	 */
43
+	private static $belongs_many_many = array(
44
+		'Locators' => Locator::class,
45
+		'LocationSet' => Location::class,
46
+	);
47
+
48
+	/**
49
+	 * @var string
50
+	 */
51
+	private static $table_name = 'LocationCategory';
52
+
53
+	/**
54
+	 * @var string
55
+	 */
56
+	private static $default_sort = 'Name';
57
+
58
+	/**
59
+	 * @return \SilverStripe\Forms\FieldList
60
+	 */
61
+	public function getCMSFields()
62
+	{
63
+		$this->beforeUpdateCMSFields(function ($fields) {
64
+			$fields->removeByName([
65
+				'Locations',
66
+				'LocationSet',
67
+				'Locators',
68
+				'LinkTracking',
69
+				'FileTracking',
70
+			]);
71
+
72
+			if ($this->ID) {
73
+				// Locations
74
+				$config = GridFieldConfig_RelationEditor::create();
75
+				$config->removeComponentsByType([
76
+					GridFieldAddExistingAutocompleter::class,
77
+					GridFieldAddNewButton::class
78
+				])
79
+					->addComponents([
80
+						new GridFieldAddExistingSearchButton(),
81
+					]);
82
+				$locations = $this->Locations();
83
+				$locationField = GridField::create('Locations', 'Locations', $locations, $config);
84
+
85
+				$fields->addFieldsToTab('Root.Main', array(
86
+					$locationField,
87
+				));
88
+			}
89
+		});
90
+
91
+		$fields = parent::getCMSFields();
92
+
93
+		return $fields;
94
+	}
95
+
96
+	/**
97
+	 * For backwards compatability
98
+	 * @return Locations|ManyManyList
99
+	 */
100
+	public function Locations()
101
+	{
102
+		return $this->LocationSet();
103
+	}
104
+
105
+	/**
106
+	 * @param null $member
107
+	 * @param array $context
108
+	 * @return bool
109
+	 */
110
+	public function canView($member = null, $context = [])
111
+	{
112
+		return true;
113
+	}
114
+
115
+	/**
116
+	 * @param null $member
117
+	 * @param array $context
118
+	 * @return bool|int
119
+	 */
120
+	public function canEdit($member = null, $context = [])
121
+	{
122
+		return Permission::check('Location_EDIT', 'any', $member);
123
+	}
124
+
125
+	/**
126
+	 * @param null $member
127
+	 * @param array $context
128
+	 * @return bool|int
129
+	 */
130
+	public function canDelete($member = null, $context = [])
131
+	{
132
+		return Permission::check('Location_DELETE', 'any', $member);
133
+	}
134
+
135
+	/**
136
+	 * @param null $member
137
+	 * @param array $context
138
+	 * @return bool|int
139
+	 */
140
+	public function canCreate($member = null, $context = [])
141
+	{
142
+		return Permission::check('Location_CREATE', 'any', $member);
143
+	}
144 144
 }
Please login to merge, or discard this patch.
src/bulkloader/LocationCsvBulkLoader.php 1 patch
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -13,89 +13,89 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
src/objects/Location.php 1 patch
Indentation   +252 added lines, -252 removed lines patch added patch discarded remove patch
@@ -28,256 +28,256 @@
 block discarded – undo
28 28
  */
29 29
 class Location extends DataObject implements PermissionProvider
30 30
 {
31
-    /**
32
-     * @var string
33
-     */
34
-    private static $singular_name = 'Location';
35
-
36
-    /**
37
-     * @var string
38
-     */
39
-    private static $plural_name = 'Locations';
40
-
41
-    /**
42
-     * @var array
43
-     */
44
-    private static $db = [
45
-        'Title' => 'Varchar(255)',
46
-        'Featured' => 'Boolean',
47
-        'Website' => 'Varchar(255)',
48
-        'Phone' => 'Varchar(40)',
49
-        'Email' => 'Varchar(255)',
50
-        'Fax' => 'Varchar(45)',
51
-        'Import_ID' => 'Int',
52
-    ];
53
-
54
-    private static $many_many = [
55
-        'Categories' => LocationCategory::class,
56
-    ];
57
-
58
-    /**
59
-     * @var string
60
-     */
61
-    private static $table_name = 'Location';
62
-
63
-    /**
64
-     * @var array
65
-     */
66
-    private static $casting = [
67
-        'distance' => 'Decimal(9,3)',
68
-    ];
69
-
70
-    /**
71
-     * @var string
72
-     */
73
-    private static $default_sort = 'Title';
74
-
75
-    /**
76
-     * api access via Restful Server module
77
-     *
78
-     * @var bool
79
-     */
80
-    private static $api_access = true;
81
-
82
-    /**
83
-     * search fields for Model Admin
84
-     *
85
-     * @var array
86
-     */
87
-    private static $searchable_fields = [
88
-        'Title',
89
-        'Address',
90
-        'City',
91
-        'State',
92
-        'PostalCode',
93
-        'Country',
94
-        'Website',
95
-        'Phone',
96
-        'Email',
97
-        'Featured',
98
-    ];
99
-
100
-    /**
101
-     * columns for grid field
102
-     *
103
-     * @var array
104
-     */
105
-    private static $summary_fields = [
106
-        'Title',
107
-        'Address',
108
-        'Address2',
109
-        'City',
110
-        'State',
111
-        'PostalCode',
112
-        'CountryCode',
113
-        'Phone' => 'Phone',
114
-        'Fax' => 'Fax',
115
-        'Email' => 'Email',
116
-        'Website' => 'Website',
117
-        'Featured',
118
-        'CategoryList',
119
-        'Lat',
120
-        'Lng',
121
-        'Import_ID',
122
-    ];
123
-
124
-    /**
125
-     * Coords status for $summary_fields
126
-     *
127
-     * @return string
128
-     */
129
-    public function getCoords()
130
-    {
131
-        return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
132
-    }
133
-
134
-    /**
135
-     * @return string
136
-     */
137
-    public function getCategoryList()
138
-    {
139
-        if ($this->Categories()->count()) {
140
-            return implode(', ', $this->Categories()->column('Name'));
141
-        }
142
-
143
-        return '';
144
-    }
145
-
146
-    /**
147
-     * @return bool|string
148
-     */
149
-    public function getCountryCode()
150
-    {
151
-        if ($this->Country) {
152
-            return strtoupper($this->Country);
153
-        }
154
-
155
-        return false;
156
-    }
157
-
158
-    /**
159
-     * custom labels for fields
160
-     *
161
-     * @param bool $includerelations
162
-     * @return array|string
163
-     */
164
-    public function fieldLabels($includerelations = true)
165
-    {
166
-        $labels = parent::fieldLabels($includerelations);
167
-        $labels['Title'] = 'Name';
168
-        $labels['Address2'] = 'Address 2';
169
-        $labels['PostalCode'] = 'Postal Code';
170
-        $labels['Categories.Name'] = 'Categories';
171
-        $labels['Featured.NiceAsBoolean'] = 'Featured';
172
-
173
-        return $labels;
174
-    }
175
-
176
-    /**
177
-     * @return FieldList
178
-     */
179
-    public function getCMSFields()
180
-    {
181
-        $this->beforeUpdateCMSFields(function ($fields) {
182
-            $fields->removeByName([
183
-                'Import_ID',
184
-                'LinkTracking',
185
-                'FileTracking',
186
-            ]);
187
-
188
-            $fields->dataFieldByName('Website')
189
-                ->setAttribute('placeholder', 'http://');
190
-
191
-            $fields->replaceField('Email', EmailField::create('Email'));
192
-
193
-            $featured = $fields->dataFieldByName('Featured')
194
-                ->setDescription('Location will display near the top of the results list');
195
-            $fields->insertAfter(
196
-                'Fax',
197
-                $featured
198
-            );
199
-
200
-            if ($this->ID) {
201
-                $categories = $fields->dataFieldByName('Categories');
202
-                $config = $categories->getConfig();
203
-                $config->removeComponentsByType([
204
-                    GridFieldAddExistingAutocompleter::class,
205
-                ])
206
-                    ->addComponents([
207
-                        new GridFieldAddExistingSearchButton(),
208
-                    ]);
209
-            }
210
-        });
211
-
212
-        $fields = parent::getCMSFields();
213
-
214
-        // allow to be extended via DataExtension
215
-        $this->extend('updateLocationFields', $fields);
216
-
217
-        return $fields;
218
-    }
219
-
220
-    /**
221
-     * @param null $member
222
-     * @param array $context
223
-     * @return bool
224
-     */
225
-    public function canView($member = null, $context = [])
226
-    {
227
-        return true;
228
-    }
229
-
230
-    /**
231
-     * @param null $member
232
-     * @param array $context
233
-     * @return bool|int
234
-     */
235
-    public function canEdit($member = null, $context = [])
236
-    {
237
-        return Permission::check('Location_EDIT', 'any', $member);
238
-    }
239
-
240
-    /**
241
-     * @param null $member
242
-     * @param array $context
243
-     * @return bool|int
244
-     */
245
-    public function canDelete($member = null, $context = [])
246
-    {
247
-        return Permission::check('Location_DELETE', 'any', $member);
248
-    }
249
-
250
-    /**
251
-     * @param null $member
252
-     * @param array $context
253
-     * @return bool|int
254
-     */
255
-    public function canCreate($member = null, $context = [])
256
-    {
257
-        return Permission::check('Location_CREATE', 'any', $member);
258
-    }
259
-
260
-    /**
261
-     * @return array
262
-     */
263
-    public function providePermissions()
264
-    {
265
-        return [
266
-            'Location_EDIT' => 'Edit a Location',
267
-            'Location_DELETE' => 'Delete a Location',
268
-            'Location_CREATE' => 'Create a Location',
269
-        ];
270
-    }
271
-
272
-    /**
273
-     * @return string
274
-     */
275
-    public function getWebsiteURL()
276
-    {
277
-        $url = $this->Website;
278
-
279
-        $this->extend('updateWebsiteURL', $url);
280
-
281
-        return $url;
282
-    }
31
+	/**
32
+	 * @var string
33
+	 */
34
+	private static $singular_name = 'Location';
35
+
36
+	/**
37
+	 * @var string
38
+	 */
39
+	private static $plural_name = 'Locations';
40
+
41
+	/**
42
+	 * @var array
43
+	 */
44
+	private static $db = [
45
+		'Title' => 'Varchar(255)',
46
+		'Featured' => 'Boolean',
47
+		'Website' => 'Varchar(255)',
48
+		'Phone' => 'Varchar(40)',
49
+		'Email' => 'Varchar(255)',
50
+		'Fax' => 'Varchar(45)',
51
+		'Import_ID' => 'Int',
52
+	];
53
+
54
+	private static $many_many = [
55
+		'Categories' => LocationCategory::class,
56
+	];
57
+
58
+	/**
59
+	 * @var string
60
+	 */
61
+	private static $table_name = 'Location';
62
+
63
+	/**
64
+	 * @var array
65
+	 */
66
+	private static $casting = [
67
+		'distance' => 'Decimal(9,3)',
68
+	];
69
+
70
+	/**
71
+	 * @var string
72
+	 */
73
+	private static $default_sort = 'Title';
74
+
75
+	/**
76
+	 * api access via Restful Server module
77
+	 *
78
+	 * @var bool
79
+	 */
80
+	private static $api_access = true;
81
+
82
+	/**
83
+	 * search fields for Model Admin
84
+	 *
85
+	 * @var array
86
+	 */
87
+	private static $searchable_fields = [
88
+		'Title',
89
+		'Address',
90
+		'City',
91
+		'State',
92
+		'PostalCode',
93
+		'Country',
94
+		'Website',
95
+		'Phone',
96
+		'Email',
97
+		'Featured',
98
+	];
99
+
100
+	/**
101
+	 * columns for grid field
102
+	 *
103
+	 * @var array
104
+	 */
105
+	private static $summary_fields = [
106
+		'Title',
107
+		'Address',
108
+		'Address2',
109
+		'City',
110
+		'State',
111
+		'PostalCode',
112
+		'CountryCode',
113
+		'Phone' => 'Phone',
114
+		'Fax' => 'Fax',
115
+		'Email' => 'Email',
116
+		'Website' => 'Website',
117
+		'Featured',
118
+		'CategoryList',
119
+		'Lat',
120
+		'Lng',
121
+		'Import_ID',
122
+	];
123
+
124
+	/**
125
+	 * Coords status for $summary_fields
126
+	 *
127
+	 * @return string
128
+	 */
129
+	public function getCoords()
130
+	{
131
+		return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
132
+	}
133
+
134
+	/**
135
+	 * @return string
136
+	 */
137
+	public function getCategoryList()
138
+	{
139
+		if ($this->Categories()->count()) {
140
+			return implode(', ', $this->Categories()->column('Name'));
141
+		}
142
+
143
+		return '';
144
+	}
145
+
146
+	/**
147
+	 * @return bool|string
148
+	 */
149
+	public function getCountryCode()
150
+	{
151
+		if ($this->Country) {
152
+			return strtoupper($this->Country);
153
+		}
154
+
155
+		return false;
156
+	}
157
+
158
+	/**
159
+	 * custom labels for fields
160
+	 *
161
+	 * @param bool $includerelations
162
+	 * @return array|string
163
+	 */
164
+	public function fieldLabels($includerelations = true)
165
+	{
166
+		$labels = parent::fieldLabels($includerelations);
167
+		$labels['Title'] = 'Name';
168
+		$labels['Address2'] = 'Address 2';
169
+		$labels['PostalCode'] = 'Postal Code';
170
+		$labels['Categories.Name'] = 'Categories';
171
+		$labels['Featured.NiceAsBoolean'] = 'Featured';
172
+
173
+		return $labels;
174
+	}
175
+
176
+	/**
177
+	 * @return FieldList
178
+	 */
179
+	public function getCMSFields()
180
+	{
181
+		$this->beforeUpdateCMSFields(function ($fields) {
182
+			$fields->removeByName([
183
+				'Import_ID',
184
+				'LinkTracking',
185
+				'FileTracking',
186
+			]);
187
+
188
+			$fields->dataFieldByName('Website')
189
+				->setAttribute('placeholder', 'http://');
190
+
191
+			$fields->replaceField('Email', EmailField::create('Email'));
192
+
193
+			$featured = $fields->dataFieldByName('Featured')
194
+				->setDescription('Location will display near the top of the results list');
195
+			$fields->insertAfter(
196
+				'Fax',
197
+				$featured
198
+			);
199
+
200
+			if ($this->ID) {
201
+				$categories = $fields->dataFieldByName('Categories');
202
+				$config = $categories->getConfig();
203
+				$config->removeComponentsByType([
204
+					GridFieldAddExistingAutocompleter::class,
205
+				])
206
+					->addComponents([
207
+						new GridFieldAddExistingSearchButton(),
208
+					]);
209
+			}
210
+		});
211
+
212
+		$fields = parent::getCMSFields();
213
+
214
+		// allow to be extended via DataExtension
215
+		$this->extend('updateLocationFields', $fields);
216
+
217
+		return $fields;
218
+	}
219
+
220
+	/**
221
+	 * @param null $member
222
+	 * @param array $context
223
+	 * @return bool
224
+	 */
225
+	public function canView($member = null, $context = [])
226
+	{
227
+		return true;
228
+	}
229
+
230
+	/**
231
+	 * @param null $member
232
+	 * @param array $context
233
+	 * @return bool|int
234
+	 */
235
+	public function canEdit($member = null, $context = [])
236
+	{
237
+		return Permission::check('Location_EDIT', 'any', $member);
238
+	}
239
+
240
+	/**
241
+	 * @param null $member
242
+	 * @param array $context
243
+	 * @return bool|int
244
+	 */
245
+	public function canDelete($member = null, $context = [])
246
+	{
247
+		return Permission::check('Location_DELETE', 'any', $member);
248
+	}
249
+
250
+	/**
251
+	 * @param null $member
252
+	 * @param array $context
253
+	 * @return bool|int
254
+	 */
255
+	public function canCreate($member = null, $context = [])
256
+	{
257
+		return Permission::check('Location_CREATE', 'any', $member);
258
+	}
259
+
260
+	/**
261
+	 * @return array
262
+	 */
263
+	public function providePermissions()
264
+	{
265
+		return [
266
+			'Location_EDIT' => 'Edit a Location',
267
+			'Location_DELETE' => 'Delete a Location',
268
+			'Location_CREATE' => 'Create a Location',
269
+		];
270
+	}
271
+
272
+	/**
273
+	 * @return string
274
+	 */
275
+	public function getWebsiteURL()
276
+	{
277
+		$url = $this->Website;
278
+
279
+		$this->extend('updateWebsiteURL', $url);
280
+
281
+		return $url;
282
+	}
283 283
 }
Please login to merge, or discard this patch.
tests/Extension/LocationExtension.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -11,12 +11,12 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.