Total Complexity | 30 |
Total Lines | 203 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
26 | class ProductWishList extends DataObject implements PermissionProvider, ViewableDataObjectInterface, ManageableDataObjectInterface |
||
27 | { |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | private static $table_name = 'ProductWishList'; |
||
1 ignored issue
–
show
|
|||
33 | |||
34 | /** |
||
35 | * @var array |
||
36 | */ |
||
37 | private static $db = [ |
||
1 ignored issue
–
show
|
|||
38 | 'Title' => 'Varchar(100)', |
||
39 | 'Private' => 'Boolean', |
||
40 | ]; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | private static $has_one = [ |
||
1 ignored issue
–
show
|
|||
46 | 'Member' => Member::class, |
||
47 | ]; |
||
48 | |||
49 | /** |
||
50 | * |
||
51 | */ |
||
52 | public function onBeforeWrite() |
||
58 | } |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @param array|null $params |
||
63 | * |
||
64 | * @return FieldList |
||
65 | */ |
||
66 | public function getFrontEndFields($params = null) |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @param bool $showCancel |
||
83 | * |
||
84 | * @return FieldList |
||
85 | */ |
||
86 | public function getFrontEndActions($showCancel = false) |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * @return RequiredFields |
||
105 | */ |
||
106 | public function getFrontEndRequiredFields() |
||
107 | { |
||
108 | $fields = RequiredFields::create([ |
||
109 | 'Title', |
||
110 | ]); |
||
111 | |||
112 | $this->extend('updateFrontEndRequiredFields', $fields); |
||
113 | |||
114 | return $fields; |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * @return bool |
||
119 | */ |
||
120 | public function getIsEditing() |
||
121 | { |
||
122 | $params = Controller::curr()->getRequest()->latestParams(); |
||
123 | |||
124 | return isset($params['Action']) && $params['Action'] == 'edit' && isset($params['ID']); |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * set ParentPage for ViewableDataobject |
||
129 | * |
||
130 | * @return \SilverStripe\CMS\Model\SiteTree |
||
131 | */ |
||
132 | public function getParentPage() |
||
133 | { |
||
134 | $class = $this->config()->get('listing_page_class'); |
||
135 | return $class::get()->first(); |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * @return String|bool |
||
140 | */ |
||
141 | public function getUpdateLink() |
||
142 | { |
||
143 | return ($this->ID > 0) ? Controller::join_links($this->getParentPage()->Link(), 'edit', $this->ID) : false; |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * set ViewAction for ViewableDataobject |
||
148 | * |
||
149 | * @return string |
||
150 | */ |
||
151 | public function getViewAction() |
||
152 | { |
||
153 | return 'view'; |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * @return array |
||
158 | */ |
||
159 | public function providePermissions() |
||
160 | { |
||
161 | return [ |
||
162 | 'WishList_EDIT' => [ |
||
163 | 'name' => 'Edit a Wish List', |
||
164 | 'category' => 'Wish List Permissions', |
||
165 | ], |
||
166 | 'WishList_DELETE' => [ |
||
167 | 'name' => 'Delete a Wish List', |
||
168 | 'category' => 'Wish List Permissions', |
||
169 | ], |
||
170 | 'WishList_CREATE' => [ |
||
171 | 'name' => 'Create a Wish List', |
||
172 | 'category' => 'Wish List Permissions', |
||
173 | ], |
||
174 | 'WishList_VIEW' => [ |
||
175 | 'name' => 'View a Wish List', |
||
176 | 'category' => 'Wish List Permissions', |
||
177 | ], |
||
178 | ]; |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * @param Member|null $member |
||
183 | * |
||
184 | * @return bool|int |
||
185 | */ |
||
186 | public function canEdit($member = null) |
||
187 | { |
||
188 | $member = ($member === null) ? Security::getCurrentUser() : $member; |
||
189 | |||
190 | return ((Permission::check('WishList_EDIT', 'any', |
||
191 | $member) && $member->ID == $this->MemberID) || Permission::check('ADMIN')); |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * @param Member|null $member |
||
196 | * |
||
197 | * @return bool|int |
||
198 | */ |
||
199 | public function canDelete($member = null) |
||
205 | } |
||
206 | |||
207 | /** |
||
208 | * @param Member|null $member |
||
209 | * @param array $context |
||
210 | * |
||
211 | * @return bool|int |
||
212 | */ |
||
213 | public function canCreate($member = null, $context = array()) |
||
214 | { |
||
215 | return Security::getCurrentUser() && Permission::check('WishList_CREATE', 'any', $member); |
||
216 | } |
||
217 | |||
218 | /** |
||
219 | * @param Member|null $member |
||
220 | * |
||
221 | * @return bool |
||
222 | */ |
||
223 | public function canView($member = null) |
||
229 | } |
||
230 | |||
231 | } |
||
232 |