|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class EcommerceSecurityBaseClass extends DataObject |
|
|
|
|
|
|
5
|
|
|
{ |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* standard SS variable |
|
10
|
|
|
* @Var String |
|
11
|
|
|
*/ |
|
12
|
|
|
private static $singular_name = "Blacklisted Item"; |
|
|
|
|
|
|
13
|
|
|
public function i18n_singular_name() |
|
|
|
|
|
|
14
|
|
|
{ |
|
15
|
|
|
return Config::inst()->get($this->ClassName, 'singular_name'); |
|
16
|
|
|
} |
|
17
|
|
|
/** |
|
18
|
|
|
* standard SS variable |
|
19
|
|
|
* @Var String |
|
20
|
|
|
*/ |
|
21
|
|
|
private static $plural_name = "Blacklisted Items"; |
|
|
|
|
|
|
22
|
|
|
public function i18n_plural_name() |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
return Config::inst()->get($this->ClassName, 'plural_name'); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
private static $db = array( |
|
|
|
|
|
|
28
|
|
|
'Title' => 'Varchar(200)', |
|
29
|
|
|
'Status' => 'Enum("Unknown, Good, Bad", "Unknown")' |
|
30
|
|
|
); |
|
31
|
|
|
|
|
32
|
|
|
private static $belongs_many_many = array( |
|
|
|
|
|
|
33
|
|
|
'SecurityChecks' => 'OrderStatusLog_SecurityCheck' |
|
34
|
|
|
); |
|
35
|
|
|
|
|
36
|
|
|
private static $casting = array( |
|
|
|
|
|
|
37
|
|
|
'Type' => 'Varchar', |
|
38
|
|
|
'SimplerName' => 'Varchar' |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
private static $summary_fields = array( |
|
|
|
|
|
|
42
|
|
|
'Created' => 'Created', |
|
43
|
|
|
'LastEdited.Ago' => 'Last Edit', |
|
44
|
|
|
'SimplerName' => 'Type', |
|
45
|
|
|
'Title' => 'Value', |
|
46
|
|
|
'Status' => 'Status' |
|
47
|
|
|
); |
|
48
|
|
|
|
|
49
|
|
|
private static $indexes = array( |
|
|
|
|
|
|
50
|
|
|
'ClassName_Title' => array('type' => 'unique', 'value' => '"ClassName","Title"'), |
|
51
|
|
|
'Title' => true, |
|
52
|
|
|
'ClassName' => true, |
|
53
|
|
|
); |
|
54
|
|
|
|
|
55
|
|
|
private static $field_labels = array( |
|
|
|
|
|
|
56
|
|
|
'Title' => 'Value' |
|
57
|
|
|
); |
|
58
|
|
|
|
|
59
|
|
|
private static $searchable_fields = array( |
|
|
|
|
|
|
60
|
|
|
'Title' => 'PartialMatchFilter', |
|
61
|
|
|
'ClassName' => array( |
|
62
|
|
|
'filter' => 'PartialMatchFilter', |
|
63
|
|
|
'title' => 'Type' |
|
64
|
|
|
), |
|
65
|
|
|
'Status' => 'PartialMatchFilter' |
|
66
|
|
|
); |
|
67
|
|
|
|
|
68
|
|
|
private static $default_sort = 'Status DESC'; |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* filter value examples are: |
|
72
|
|
|
* ```php |
|
73
|
|
|
* array('Title' => 'Foo') |
|
74
|
|
|
* ``` |
|
75
|
|
|
* you can not provide multi-dimensional arrays |
|
76
|
|
|
* |
|
77
|
|
|
* @param array $filterArray associative array of filter values |
|
78
|
|
|
* @param bool $filterArray if a new one is created, should it be written |
|
79
|
|
|
* @return DataObject |
|
80
|
|
|
*/ |
|
81
|
|
|
public static function find_or_create($filterArray, $write = true) |
|
82
|
|
|
{ |
|
83
|
|
|
$className = get_called_class(); |
|
84
|
|
|
//we dont want empty ones so we just return a temp object... |
|
85
|
|
|
if (empty($filterArray['Title'])) { |
|
86
|
|
|
$obj = EcommerceSecurityBaseClass::create(); |
|
87
|
|
|
} else { |
|
88
|
|
|
$filterArray['ClassName'] = $className; |
|
89
|
|
|
$obj = $className::get()->filter($filterArray)->first(); |
|
90
|
|
|
if (! $obj) { |
|
91
|
|
|
$obj = $className::create($filterArray); |
|
92
|
|
|
if ($write) { |
|
93
|
|
|
$obj->write(); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return $obj; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function canCreate($member = null) |
|
102
|
|
|
{ |
|
103
|
|
|
return true; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
View Code Duplication |
public function canView($member = null) |
|
|
|
|
|
|
107
|
|
|
{ |
|
108
|
|
|
if (! $member) { |
|
109
|
|
|
$member = Member::currentUser(); |
|
110
|
|
|
} |
|
111
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member); |
|
112
|
|
|
if ($extended !== null) { |
|
113
|
|
|
return $extended; |
|
114
|
|
|
} |
|
115
|
|
|
if (Permission::checkMember($member, Config::inst()->get('EcommerceRole', 'admin_permission_code'))) { |
|
116
|
|
|
return true; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
return parent::canView($member); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
View Code Duplication |
public function canEdit($member = null) |
|
|
|
|
|
|
123
|
|
|
{ |
|
124
|
|
|
if (! $member) { |
|
125
|
|
|
$member = Member::currentUser(); |
|
126
|
|
|
} |
|
127
|
|
|
$extended = $this->extendedCan(__FUNCTION__, $member); |
|
128
|
|
|
if ($extended !== null) { |
|
129
|
|
|
return $extended; |
|
130
|
|
|
} |
|
131
|
|
|
if (Permission::checkMember($member, Config::inst()->get('EcommerceRole', 'admin_permission_code'))) { |
|
132
|
|
|
return true; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
return parent::canEdit($member); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function canDelete($member = null) |
|
139
|
|
|
{ |
|
140
|
|
|
return false; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* CMS Fields |
|
145
|
|
|
* @return FieldList |
|
146
|
|
|
*/ |
|
147
|
|
|
public function getCMSFields() |
|
148
|
|
|
{ |
|
149
|
|
|
$fields = parent::getCMSFields(); |
|
150
|
|
|
if ($this->exists()) { |
|
151
|
|
|
$labels = $this->fieldLabels(); |
|
152
|
|
|
$fields->addFieldToTab( |
|
153
|
|
|
'Root.Main', |
|
154
|
|
|
$type = ReadonlyField::create('Type', 'Type', $labels['Title']), |
|
155
|
|
|
'Title' |
|
156
|
|
|
); |
|
157
|
|
|
$fields->replaceField( |
|
158
|
|
|
'Title', |
|
159
|
|
|
$fields->dataFieldByName('Title')->setTitle($labels["Title"])->performReadonlyTransformation() |
|
160
|
|
|
); |
|
161
|
|
|
} else { |
|
162
|
|
|
$availableClasses = ClassInfo::subclassesFor($this->ClassName); |
|
163
|
|
|
unset($availableClasses[$this->ClassName]); |
|
164
|
|
|
$fields->addFieldToTab( |
|
165
|
|
|
'Root.Main', |
|
166
|
|
|
EcommerceClassNameOrTypeDropdownField::create( |
|
167
|
|
|
'ClassName', |
|
168
|
|
|
'Type', |
|
169
|
|
|
'EcommerceSecurityBaseClass', |
|
170
|
|
|
$availableClasses |
|
171
|
|
|
)->addExtraClass('dropdown') |
|
172
|
|
|
); |
|
173
|
|
|
$fields->dataFieldByName('Title')->setTitle('Value'); |
|
174
|
|
|
} |
|
175
|
|
|
return $fields; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
public function getType() |
|
179
|
|
|
{ |
|
180
|
|
|
return $this->singular_name(); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
public function getSimplerName() |
|
184
|
|
|
{ |
|
185
|
|
|
return str_replace('Blacklisted ', '', $this->singular_name()); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* |
|
190
|
|
|
* |
|
191
|
|
|
* @return bool |
|
192
|
|
|
*/ |
|
193
|
|
|
public function hasRisks() |
|
194
|
|
|
{ |
|
195
|
|
|
return $this->Title && $this->ID && $this->Status == 'Bad' ? true : false; |
|
|
|
|
|
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* |
|
200
|
|
|
* |
|
201
|
|
|
* @return bool |
|
202
|
|
|
*/ |
|
203
|
|
|
public function isSafe() |
|
204
|
|
|
{ |
|
205
|
|
|
return $this->Status == 'Good' ? true : false; |
|
|
|
|
|
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* |
|
210
|
|
|
* |
|
211
|
|
|
* @return bool |
|
212
|
|
|
*/ |
|
213
|
|
|
public function hasOpinion() |
|
214
|
|
|
{ |
|
215
|
|
|
return $this->Status !== 'Unknown' ? true : false; |
|
|
|
|
|
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
public function requireDefaultRecords() |
|
219
|
|
|
{ |
|
220
|
|
|
parent::requireDefaultRecords(); |
|
221
|
|
|
} |
|
222
|
|
|
} |
|
223
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.