|
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->hasMethod('getCurrentPage')) |
|
29
|
|
|
? $this->owner->getCurrentPage() |
|
30
|
|
|
: $this->owner; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param HTTPRequest|null $request |
|
35
|
|
|
* |
|
36
|
|
|
* @return \SilverStripe\View\ViewableData_Customised|\SilverStripe\Control\HTTPResponse |
|
37
|
|
|
* @throws \SilverStripe\Control\HTTPResponse_Exception |
|
38
|
|
|
*/ |
|
39
|
|
|
public function view(HTTPRequest $request = null) |
|
40
|
|
|
{ |
|
41
|
|
|
if ($request === null) { |
|
42
|
|
|
$request = $this->getController()->getRequest(); |
|
43
|
|
|
} |
|
44
|
|
|
$id = $request->param('ID'); |
|
45
|
|
|
|
|
46
|
|
|
if ($record = ProductWishList::get()->byID($id)) { |
|
|
|
|
|
|
47
|
|
|
if ($record->canView(Security::getCurrentUser())) { |
|
48
|
|
|
return $this->getController()->customise([ |
|
49
|
|
|
'WishList' => $record, |
|
50
|
|
|
'Breadcrumbs' => $record->Breadcrumbs(), |
|
51
|
|
|
'ProductWishListForm' => false, |
|
52
|
|
|
]); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return Security::permissionFailure($this->owner, "You don't have permission to view this record."); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return $this->getController()->httpError(404); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @param \SilverStripe\ORM\ArrayList $collection |
|
63
|
|
|
* @param $searchCriteria |
|
64
|
|
|
*/ |
|
65
|
|
|
public function updateCollectionItems(&$collection, $searchCriteria) |
|
|
|
|
|
|
66
|
|
|
{ |
|
67
|
|
|
$collection = $collection->filter(['MemberID' => Security::getCurrentUser()->ID]); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|