1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Wishlist\Extensions; |
4
|
|
|
|
5
|
|
|
use Dynamic\Wishlist\Model\ProductWishList; |
6
|
|
|
use SilverStripe\Control\HTTPRequest; |
7
|
|
|
use SilverStripe\Core\Extension; |
8
|
|
|
use SilverStripe\Security\Security; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class ProductWishListControllerExtension |
12
|
|
|
*/ |
13
|
|
|
class ProductWishListControllerExtension extends Extension |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var array |
18
|
|
|
*/ |
19
|
|
|
private static $allowed_actions = [ |
|
|
|
|
20
|
|
|
'view', |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @return \SilverStripe\CMS\Controllers\ContentController|Object |
25
|
|
|
*/ |
26
|
|
|
protected function getController() |
27
|
|
|
{ |
28
|
|
|
return $this->owner; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param HTTPRequest|null $request |
33
|
|
|
* |
34
|
|
|
* @return \SilverStripe\View\ViewableData_Customised|\SilverStripe\Control\HTTPResponse |
35
|
|
|
* @throws \SilverStripe\Control\HTTPResponse_Exception |
36
|
|
|
*/ |
37
|
1 |
|
public function view(HTTPRequest $request = null) |
38
|
|
|
{ |
39
|
1 |
|
if ($request === null) { |
40
|
|
|
$request = $this->getController()->getRequest(); |
41
|
|
|
} |
42
|
1 |
|
$id = $request->param('ID'); |
43
|
|
|
|
44
|
|
|
/** @var ProductWishList $record */ |
45
|
1 |
|
$record = ProductWishList::get()->filter([ |
46
|
1 |
|
'URLSegment' => $id, |
47
|
1 |
|
])->first(); |
48
|
|
|
|
49
|
1 |
|
if ($record) { |
|
|
|
|
50
|
1 |
|
if ($record->canView(Security::getCurrentUser())) { |
51
|
|
|
return $this->getController()->customise([ |
52
|
|
|
'WishList' => $record, |
53
|
|
|
'Breadcrumbs' => $record->Breadcrumbs(), |
|
|
|
|
54
|
|
|
'ProductWishListForm' => false, |
55
|
|
|
]); |
56
|
|
|
} |
57
|
|
|
|
58
|
1 |
|
return Security::permissionFailure($this->owner, "You don't have permission to view this record."); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $this->getController()->httpError(404); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param \SilverStripe\ORM\ArrayList $collection |
66
|
|
|
* @param $searchCriteria |
67
|
|
|
*/ |
68
|
|
|
public function updateCollectionItems(&$collection, $searchCriteria) |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
$memberID = 0; |
71
|
|
|
if ($member = Security::getCurrentUser()) { |
72
|
|
|
$memberID = $member->ID; |
73
|
|
|
} |
74
|
|
|
$collection = $collection->filter(['MemberID' => $memberID]); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|