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
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class LocationCategory |
15
|
|
|
* |
16
|
|
|
* @property string $Name |
17
|
|
|
* @method Locations|ManyManyList LocationSet() |
18
|
|
|
* @method Locators|ManyManyList Locators() |
19
|
|
|
*/ |
20
|
|
|
class LocationCategory extends DataObject |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private static $singular_name = 'Category'; |
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
private static $plural_name = 'Categories'; |
|
|
|
|
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
private static $db = array( |
|
|
|
|
36
|
|
|
'Name' => 'Varchar(100)', |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var array |
41
|
|
|
*/ |
42
|
|
|
private static $belongs_many_many = array( |
|
|
|
|
43
|
|
|
'Locators' => Locator::class, |
44
|
|
|
'LocationSet' => Location::class, |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string |
49
|
|
|
*/ |
50
|
|
|
private static $table_name = 'LocationCategory'; |
|
|
|
|
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var string |
54
|
|
|
*/ |
55
|
|
|
private static $default_sort = 'Name'; |
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return \SilverStripe\Forms\FieldList |
59
|
|
|
*/ |
60
|
|
|
public function getCMSFields() |
61
|
|
|
{ |
62
|
|
|
$this->beforeUpdateCMSFields(function ($fields) { |
63
|
|
|
$fields->removeByName([ |
64
|
|
|
'Locations', |
65
|
|
|
'LocationSet', |
66
|
|
|
'LinkTracking', |
67
|
|
|
'FileTracking', |
68
|
|
|
]); |
69
|
|
|
|
70
|
|
|
if ($this->ID) { |
71
|
|
|
// Locations |
72
|
|
|
$config = GridFieldConfig_RelationEditor::create(); |
73
|
|
|
$config->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
74
|
|
|
$config->addComponent(new GridFieldAddExistingAutocompleter()); |
75
|
|
|
$config->removeComponentsByType(GridFieldAddNewButton::class); |
76
|
|
|
$locations = $this->Locations(); |
77
|
|
|
$locationField = GridField::create('Locations', 'Locations', $locations, $config); |
78
|
|
|
|
79
|
|
|
$fields->addFieldsToTab('Root.Locations', array( |
80
|
|
|
$locationField, |
81
|
|
|
)); |
82
|
|
|
} |
83
|
|
|
}); |
84
|
|
|
|
85
|
|
|
$fields = parent::getCMSFields(); |
86
|
|
|
|
87
|
|
|
return $fields; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* For backwards compatability |
92
|
|
|
* @return Locations|ManyManyList |
|
|
|
|
93
|
|
|
*/ |
94
|
|
|
public function Locations() |
95
|
|
|
{ |
96
|
|
|
return $this->LocationSet(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param null $member |
|
|
|
|
101
|
|
|
* @param array $context |
102
|
|
|
* @return bool |
103
|
|
|
*/ |
104
|
|
|
public function canView($member = null, $context = []) |
|
|
|
|
105
|
|
|
{ |
106
|
|
|
return true; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param null $member |
|
|
|
|
111
|
|
|
* @param array $context |
112
|
|
|
* @return bool|int |
113
|
|
|
*/ |
114
|
|
|
public function canEdit($member = null, $context = []) |
|
|
|
|
115
|
|
|
{ |
116
|
|
|
return Permission::check('Location_EDIT', 'any', $member); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param null $member |
|
|
|
|
121
|
|
|
* @param array $context |
122
|
|
|
* @return bool|int |
123
|
|
|
*/ |
124
|
|
|
public function canDelete($member = null, $context = []) |
|
|
|
|
125
|
|
|
{ |
126
|
|
|
return Permission::check('Location_DELETE', 'any', $member); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param null $member |
|
|
|
|
131
|
|
|
* @param array $context |
132
|
|
|
* @return bool|int |
133
|
|
|
*/ |
134
|
|
|
public function canCreate($member = null, $context = []) |
135
|
|
|
{ |
136
|
|
|
return Permission::check('Location_CREATE', 'any', $member); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|