1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class ProductWishList |
5
|
|
|
* |
6
|
|
|
* @property string $Title |
7
|
|
|
* @property bool $Private |
8
|
|
|
* @property int $MemberID |
9
|
|
|
* @method Member $Member |
10
|
|
|
*/ |
11
|
|
|
class ProductWishList extends DataObject implements PermissionProvider, Dynamic\ViewableDataObject\VDOInterfaces\ViewableDataObjectInterface, ManageableDataObjectInterface |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var array |
16
|
|
|
*/ |
17
|
|
|
private static $db = [ |
18
|
|
|
'Title' => 'Varchar(100)', |
19
|
|
|
'Private' => 'Boolean', |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
private static $has_one = [ |
26
|
|
|
'Member' => 'Member', |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* |
31
|
|
|
*/ |
32
|
10 |
|
public function onBeforeWrite() |
33
|
|
|
{ |
34
|
10 |
|
parent::onBeforeWrite(); |
35
|
|
|
|
36
|
10 |
|
if (!$this->MemberID > 0) { |
37
|
10 |
|
$this->MemberID = Member::currentUserID(); |
38
|
10 |
|
} |
39
|
10 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param null $params |
43
|
|
|
* |
44
|
|
|
* @return FieldList |
45
|
|
|
*/ |
46
|
1 |
|
public function getFrontEndFields($params = null) |
47
|
|
|
{ |
48
|
1 |
|
$fields = parent::getFrontEndFields($params); |
49
|
|
|
|
50
|
1 |
|
$fields->removeByName([ |
51
|
1 |
|
'MemberID', |
52
|
1 |
|
'MenuTitle', |
53
|
1 |
|
'URLSegment', |
54
|
1 |
|
'MetaTitle', |
55
|
1 |
|
'MetaDescription', |
56
|
1 |
|
]); |
57
|
|
|
|
58
|
1 |
|
return $fields; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param bool $showCancel |
63
|
|
|
* |
64
|
|
|
* @return FieldList |
65
|
|
|
*/ |
66
|
1 |
|
public function getFrontEndActions($showCancel = false) |
67
|
|
|
{ |
68
|
1 |
|
$processTitle = ($this->getIsEditing()) ? "Update {$this->i18n_singular_name()}" : "Create {$this->i18n_singular_name()}"; |
69
|
1 |
|
$actions = FieldList::create( |
70
|
1 |
|
FormAction::create('doSaveObject') |
71
|
1 |
|
->setTitle($processTitle) |
72
|
1 |
|
); |
73
|
|
|
|
74
|
1 |
|
if ($showCancel === true) { |
75
|
1 |
|
$actions->insertBefore('action_doSaveObject', CancelFormAction::create('Cancel')); |
76
|
1 |
|
} |
77
|
|
|
|
78
|
1 |
|
$this->extend('updateFrontEndActions', $actions); |
79
|
|
|
|
80
|
1 |
|
return $actions; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return RequiredFields |
85
|
|
|
*/ |
86
|
1 |
|
public function getFrontEndRequiredFields() |
87
|
|
|
{ |
88
|
1 |
|
$fields = RequiredFields::create([ |
89
|
1 |
|
'Title', |
90
|
1 |
|
]); |
91
|
|
|
|
92
|
1 |
|
$this->extend('updateFrontEndRequiredFields', $fields); |
93
|
|
|
|
94
|
1 |
|
return $fields; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return bool |
99
|
|
|
*/ |
100
|
1 |
|
public function getIsEditing() |
101
|
|
|
{ |
102
|
1 |
|
$params = Controller::curr()->getRequest()->latestParams(); |
103
|
|
|
|
104
|
1 |
|
return isset($params['Action']) && $params['Action'] == 'edit' && isset($params['ID']); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* set ParentPage for ViewableDataobject |
109
|
|
|
* |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
|
|
public function getParentPage() |
113
|
|
|
{ |
114
|
|
|
$class = $this->config()->get('listing_page_class'); |
115
|
|
|
return $class::get()->first(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return String|bool |
120
|
|
|
*/ |
121
|
|
|
public function getUpdateLink() |
122
|
|
|
{ |
123
|
|
|
return ($this->ID > 0) ? Controller::join_links($this->getParentPage()->Link(), 'edit', $this->ID) : false; |
|
|
|
|
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* set ViewAction for ViewableDataobject |
128
|
|
|
* |
129
|
|
|
* @return string |
130
|
|
|
*/ |
131
|
1 |
|
public function getViewAction() |
132
|
|
|
{ |
133
|
1 |
|
return 'view'; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @return array |
138
|
|
|
*/ |
139
|
1 |
|
public function providePermissions() |
140
|
|
|
{ |
141
|
|
|
return [ |
142
|
|
|
'WishList_EDIT' => [ |
143
|
1 |
|
'name' => 'Edit a Wish List', |
144
|
1 |
|
'category' => 'Wish List Permissions', |
145
|
1 |
|
], |
146
|
|
|
'WishList_DELETE' => [ |
147
|
1 |
|
'name' => 'Delete a Wish List', |
148
|
1 |
|
'category' => 'Wish List Permissions', |
149
|
1 |
|
], |
150
|
|
|
'WishList_CREATE' => [ |
151
|
1 |
|
'name' => 'Create a Wish List', |
152
|
1 |
|
'category' => 'Wish List Permissions', |
153
|
1 |
|
], |
154
|
|
|
'WishList_VIEW' => [ |
155
|
1 |
|
'name' => 'View a Wish List', |
156
|
1 |
|
'category' => 'Wish List Permissions', |
157
|
1 |
|
], |
158
|
1 |
|
]; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @param Member|null $member |
163
|
|
|
* |
164
|
|
|
* @return bool|int |
165
|
|
|
*/ |
166
|
1 |
View Code Duplication |
public function canEdit($member = null) |
|
|
|
|
167
|
|
|
{ |
168
|
1 |
|
$member = ($member === null) ? Member::currentUser() : $member; |
169
|
|
|
|
170
|
1 |
|
return ((Permission::check('WishList_EDIT', 'any', |
171
|
1 |
|
$member) && $member->ID == $this->MemberID) || Permission::check('ADMIN')); |
|
|
|
|
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @param Member|null $member |
176
|
|
|
* |
177
|
|
|
* @return bool|int |
178
|
|
|
*/ |
179
|
1 |
View Code Duplication |
public function canDelete($member = null) |
|
|
|
|
180
|
|
|
{ |
181
|
1 |
|
$member = ($member === null) ? Member::currentUser() : $member; |
182
|
|
|
|
183
|
1 |
|
return ((Permission::check('WishList_DELETE', 'any', |
184
|
1 |
|
$member) && $member->ID == $this->MemberID) || Permission::check('ADMIN')); |
|
|
|
|
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @param Member|null $member |
189
|
|
|
* |
190
|
|
|
* @return bool|int |
191
|
|
|
*/ |
192
|
1 |
|
public function canCreate($member = null) |
193
|
|
|
{ |
194
|
1 |
|
return Member::currentUser() && Permission::check('WishList_CREATE', 'any', $member); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @param Member|null $member |
199
|
|
|
* |
200
|
|
|
* @return bool |
201
|
|
|
*/ |
202
|
2 |
View Code Duplication |
public function canView($member = null) |
|
|
|
|
203
|
|
|
{ |
204
|
2 |
|
$member = ($member === null) ? Member::currentUser() : $member; |
205
|
|
|
|
206
|
2 |
|
return (!$this->Private) || ((Permission::check('WishList_VIEW', 'any', |
207
|
2 |
|
$member) && $member->ID == $this->MemberID) || Permission::check('ADMIN')); |
|
|
|
|
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
} |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.