1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Foxy\Model; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Forms\FieldList; |
6
|
|
|
use SilverStripe\ORM\DataObject; |
7
|
|
|
use SilverStripe\Security\Permission; |
8
|
|
|
use SilverStripe\Security\Security; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class VariationType |
12
|
|
|
* @package Dynamic\Foxy\Model |
13
|
|
|
*/ |
14
|
|
|
class VariationType extends DataObject |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
private static $table_name = 'VariationType'; |
|
|
|
|
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
private static $singular_name = 'Variation Type'; |
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private static $plural_name = 'Variation Types'; |
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string[] |
33
|
|
|
*/ |
34
|
|
|
private static $db = [ |
|
|
|
|
35
|
|
|
'Title' => 'Varchar', |
36
|
|
|
'SortOrder' => 'Int', |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var string[] |
41
|
|
|
*/ |
42
|
|
|
private static $has_many = [ |
|
|
|
|
43
|
|
|
'Variations' => Variation::class, |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
private static $default_sort = 'SortOrder'; |
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return FieldList |
53
|
|
|
*/ |
54
|
|
|
public function getCMSFields() |
55
|
|
|
{ |
56
|
|
|
$this->beforeUpdateCMSFields(function (FieldList $fields) { |
57
|
|
|
$fields->removeByName([ |
58
|
|
|
'VariationSets', |
59
|
|
|
]); |
60
|
|
|
}); |
61
|
|
|
|
62
|
|
|
return parent::getCMSFields(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param $member |
67
|
|
|
* @return bool|int|void |
68
|
|
|
*/ |
69
|
|
|
public function canCreate($member = null, $context = []) |
70
|
|
|
{ |
71
|
|
|
if (!$member) { |
72
|
|
|
$member = Security::getCurrentUser(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return Permission::checkMember($member, 'MANAGE_FOXY_PRODUCTS'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param $member |
80
|
|
|
* @return bool|int|void|null |
81
|
|
|
*/ |
82
|
|
|
public function canEdit($member = null, $context = []) |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
if (!$member) { |
85
|
|
|
$member = Security::getCurrentUser(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return Permission::checkMember($member, 'MANAGE_FOXY_PRODUCTS'); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param $member |
93
|
|
|
* @return bool|int|void |
94
|
|
|
*/ |
95
|
|
|
public function canDelete($member = null, $context = []) |
|
|
|
|
96
|
|
|
{ |
97
|
|
|
if (!$member) { |
98
|
|
|
$member = Security::getCurrentUser(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
return Permission::checkMember($member, 'MANAGE_FOXY_PRODUCTS'); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|