1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Locator; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Forms\GridField\GridField; |
6
|
|
|
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter; |
7
|
|
|
use SilverStripe\Forms\GridField\GridFieldAddNewButton; |
8
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor; |
9
|
|
|
use SilverStripe\ORM\DataObject; |
10
|
|
|
use SilverStripe\ORM\ManyManyList; |
11
|
|
|
use SilverStripe\Security\Permission; |
12
|
|
|
use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class LocationCategory |
16
|
|
|
* |
17
|
|
|
* @property string $Name |
18
|
|
|
* @method Locations|ManyManyList LocationSet() |
19
|
|
|
* @method Locators|ManyManyList Locators() |
20
|
|
|
*/ |
21
|
|
|
class LocationCategory extends DataObject |
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
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|