|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dynamic\Foxy\Model; |
|
4
|
|
|
|
|
5
|
|
|
use Dynamic\Products\Page\Product; |
|
|
|
|
|
|
6
|
|
|
use SilverStripe\Forms\FieldList; |
|
7
|
|
|
use SilverStripe\Forms\GridField\GridField; |
|
8
|
|
|
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter; |
|
9
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor; |
|
10
|
|
|
use SilverStripe\ORM\DataObject; |
|
11
|
|
|
use SilverStripe\Security\Permission; |
|
12
|
|
|
use SilverStripe\Security\Security; |
|
13
|
|
|
use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton; |
|
14
|
|
|
use Symbiote\GridFieldExtensions\GridFieldOrderableRows; |
|
15
|
|
|
|
|
16
|
|
|
class OptionType extends DataObject |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var array |
|
20
|
|
|
*/ |
|
21
|
|
|
private static $db = [ |
|
|
|
|
|
|
22
|
|
|
'Title' => 'Varchar(255)', |
|
23
|
|
|
'SortOrder' => 'Int', |
|
24
|
|
|
]; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var array |
|
28
|
|
|
*/ |
|
29
|
|
|
private static $many_many = [ |
|
|
|
|
|
|
30
|
|
|
'Options' => ProductOption::class, |
|
31
|
|
|
]; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var array |
|
35
|
|
|
*/ |
|
36
|
|
|
private static $many_many_extraFields = [ |
|
|
|
|
|
|
37
|
|
|
'Options' => [ |
|
38
|
|
|
'WeightModifier' => 'Decimal', |
|
39
|
|
|
'CodeModifier' => 'Text', |
|
40
|
|
|
'PriceModifier' => 'Currency', |
|
41
|
|
|
'WeightModifierAction' => "Enum('Add,Subtract,Set', null)", |
|
42
|
|
|
'CodeModifierAction' => "Enum('Add,Subtract,Set', null)", |
|
43
|
|
|
'PriceModifierAction' => "Enum('Add,Subtract,Set', null)", |
|
44
|
|
|
'Available' => 'Boolean', |
|
45
|
|
|
'SortOrder' => 'Int', |
|
46
|
|
|
], |
|
47
|
|
|
]; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @var string |
|
51
|
|
|
*/ |
|
52
|
|
|
private static $table_name = 'OptionType'; |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
public function getCMSFields() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
57
|
|
|
$fields->removeByName([ |
|
58
|
|
|
'SortOrder', |
|
59
|
|
|
'ProductID', |
|
60
|
|
|
'Options', |
|
61
|
|
|
]); |
|
62
|
|
|
|
|
63
|
|
|
if ($this->ID) { |
|
64
|
|
|
$config = GridFieldConfig_RelationEditor::create(); |
|
65
|
|
|
$config |
|
66
|
|
|
->addComponents([ |
|
67
|
|
|
new GridFieldAddExistingSearchButton(), |
|
68
|
|
|
new GridFieldOrderableRows('SortOrder'), |
|
69
|
|
|
]) |
|
70
|
|
|
->removeComponentsByType([ |
|
71
|
|
|
GridFieldAddExistingAutocompleter::class, |
|
72
|
|
|
]); |
|
73
|
|
|
$options = GridField::create( |
|
74
|
|
|
'Options', |
|
75
|
|
|
'Options', |
|
76
|
|
|
$this->owner->Options()->sort('SortOrder'), |
|
|
|
|
|
|
77
|
|
|
$config |
|
78
|
|
|
); |
|
79
|
|
|
$fields->addFieldToTab('Root.Main', $options); |
|
80
|
|
|
} |
|
81
|
|
|
}); |
|
82
|
|
|
|
|
83
|
|
|
return parent::getCMSFields(); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param $member |
|
88
|
|
|
* @return bool|int|void |
|
89
|
|
|
*/ |
|
90
|
|
|
public function canCreate($member = null, $context = []) |
|
91
|
|
|
{ |
|
92
|
|
|
if (!$member) { |
|
93
|
|
|
$member = Security::getCurrentUser(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return Permission::checkMember($member, 'MANAGE_FOXY_PRODUCTS'); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param $member |
|
101
|
|
|
* @return bool|int|void|null |
|
102
|
|
|
*/ |
|
103
|
|
|
public function canEdit($member = null, $context = []) |
|
|
|
|
|
|
104
|
|
|
{ |
|
105
|
|
|
if (!$member) { |
|
106
|
|
|
$member = Security::getCurrentUser(); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
return Permission::checkMember($member, 'MANAGE_FOXY_PRODUCTS'); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param $member |
|
114
|
|
|
* @return bool|int|void |
|
115
|
|
|
*/ |
|
116
|
|
|
public function canDelete($member = null, $context = []) |
|
|
|
|
|
|
117
|
|
|
{ |
|
118
|
|
|
if (!$member) { |
|
119
|
|
|
$member = Security::getCurrentUser(); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
return Permission::checkMember($member, 'MANAGE_FOXY_PRODUCTS'); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths