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 |
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
|
12 |
|
public function onBeforeWrite() |
33
|
|
|
{ |
34
|
12 |
|
parent::onBeforeWrite(); |
35
|
|
|
|
36
|
12 |
|
if (!$this->MemberID > 0) { |
37
|
12 |
|
$this->MemberID = Member::currentUserID(); |
38
|
12 |
|
} |
39
|
12 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param null $params |
43
|
|
|
* |
44
|
|
|
* @return FieldList |
45
|
|
|
*/ |
46
|
2 |
|
public function getFrontEndFields($params = null) |
47
|
|
|
{ |
48
|
2 |
|
$fields = parent::getFrontEndFields($params); |
49
|
|
|
|
50
|
2 |
|
$fields->removeByName([ |
51
|
2 |
|
'MemberID', |
52
|
2 |
|
'MenuTitle', |
53
|
2 |
|
'URLSegment', |
54
|
2 |
|
'MetaTitle', |
55
|
2 |
|
'MetaDescription', |
56
|
2 |
|
]); |
57
|
|
|
|
58
|
2 |
|
return $fields; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param bool $showCancel |
63
|
|
|
* |
64
|
|
|
* @return FieldList |
65
|
|
|
*/ |
66
|
2 |
|
public function getFrontEndActions($showCancel = false) |
67
|
|
|
{ |
68
|
2 |
|
$processTitle = ($this->getIsEditing()) ? "Update {$this->i18n_singular_name()}" : "Create {$this->i18n_singular_name()}"; |
69
|
2 |
|
$actions = FieldList::create( |
70
|
2 |
|
FormAction::create('doProcessWishList') |
71
|
2 |
|
->setTitle($processTitle) |
72
|
2 |
|
); |
73
|
|
|
|
74
|
2 |
|
if ($showCancel === true) { |
75
|
1 |
|
$actions->insertBefore('action_doProcessWishList', CancelFormAction::create('Cancel')); |
76
|
1 |
|
} |
77
|
|
|
|
78
|
2 |
|
$this->extend('updateFrontEndActions', $actions); |
79
|
|
|
|
80
|
2 |
|
return $actions; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return RequiredFields |
85
|
|
|
*/ |
86
|
2 |
|
public function getFrontEndRequiredFields() |
87
|
|
|
{ |
88
|
2 |
|
$fields = RequiredFields::create([ |
89
|
2 |
|
'Title', |
90
|
2 |
|
]); |
91
|
|
|
|
92
|
2 |
|
$this->extend('updateFrontEndRequiredFields', $fields); |
93
|
|
|
|
94
|
2 |
|
return $fields; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return bool |
99
|
|
|
*/ |
100
|
2 |
|
public function getIsEditing() |
101
|
|
|
{ |
102
|
2 |
|
$params = Controller::curr()->getRequest()->latestParams(); |
103
|
|
|
|
104
|
2 |
|
return isset($params['Action']) && $params['Action'] == 'update' && isset($params['ID']); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* set ParentPage for ViewableDataobject |
109
|
|
|
* |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
|
|
public function getParentPage() |
113
|
|
|
{ |
114
|
|
|
return NucuProductWishListPage::get()->first(); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return String|bool |
119
|
|
|
*/ |
120
|
1 |
|
public function getUpdateLink() |
121
|
|
|
{ |
122
|
1 |
|
return ($this->ID > 0) ? Controller::join_links('update', $this->ID) : false; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* set ViewAction for ViewableDataobject |
127
|
|
|
* |
128
|
|
|
* @return string |
129
|
|
|
*/ |
130
|
1 |
|
public function getViewAction() |
131
|
|
|
{ |
132
|
1 |
|
return 'view'; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return array |
137
|
|
|
*/ |
138
|
1 |
|
public function providePermissions() |
139
|
|
|
{ |
140
|
|
|
return array( |
141
|
1 |
|
'WishList_EDIT' => 'Edit a Wish List', |
142
|
1 |
|
'WishList_DELETE' => 'Delete a Wish List', |
143
|
1 |
|
'WishList_CREATE' => 'Create a Wish List', |
144
|
1 |
|
'WishList_VIEW' => 'View a Wish List', |
145
|
1 |
|
); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param Member|null $member |
150
|
|
|
* |
151
|
|
|
* @return bool|int |
152
|
|
|
*/ |
153
|
1 |
|
public function canEdit($member = null) |
154
|
|
|
{ |
155
|
1 |
|
return Permission::check('WishList_EDIT', 'any', $member); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param Member|null $member |
160
|
|
|
* |
161
|
|
|
* @return bool|int |
162
|
|
|
*/ |
163
|
1 |
|
public function canDelete($member = null) |
164
|
|
|
{ |
165
|
1 |
|
return Permission::check('WishList_DELETE', 'any', $member); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @param Member|null $member |
170
|
|
|
* |
171
|
|
|
* @return bool|int |
172
|
|
|
*/ |
173
|
1 |
|
public function canCreate($member = null) |
174
|
|
|
{ |
175
|
1 |
|
return Permission::check('WishList_CREATE', 'any', $member); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @param Member|null $member |
180
|
|
|
* |
181
|
|
|
* @return bool |
182
|
|
|
*/ |
183
|
1 |
|
public function canView($member = null) |
184
|
|
|
{ |
185
|
1 |
|
$member = ($member === null) ? Member::currentUser() : $member; |
186
|
|
|
|
187
|
1 |
|
return (!$this->Private) || ((Permission::check('WishList_VIEW', 'any', |
188
|
1 |
|
$member) && $member->ID == $this->MemberID) || Permission::check('ADMIN')); |
|
|
|
|
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
} |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: