1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* WellCommerce Open-Source E-Commerce Platform |
4
|
|
|
* |
5
|
|
|
* This file is part of the WellCommerce package. |
6
|
|
|
* |
7
|
|
|
* (c) Adam Piotrowski <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, |
10
|
|
|
* please view the LICENSE file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace WellCommerce\Bundle\ReviewBundle\Controller\Box; |
14
|
|
|
|
15
|
|
|
use Symfony\Component\HttpFoundation\Response; |
16
|
|
|
use WellCommerce\Bundle\CoreBundle\Controller\Box\AbstractBoxController; |
17
|
|
|
use WellCommerce\Bundle\ReviewBundle\Entity\Review; |
18
|
|
|
use WellCommerce\Bundle\ReviewBundle\Repository\ReviewRepositoryInterface; |
19
|
|
|
use WellCommerce\Component\Layout\Collection\LayoutBoxSettingsCollection; |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class ReviewBoxController |
24
|
|
|
* |
25
|
|
|
* @author Adam Piotrowski <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class ReviewBoxController extends AbstractBoxController |
28
|
|
|
{ |
29
|
|
|
public function indexAction(LayoutBoxSettingsCollection $boxSettings): Response |
30
|
|
|
{ |
31
|
|
|
/** @var ReviewRepositoryInterface $repository */ |
32
|
|
|
$repository = $this->manager->getRepository(); |
33
|
|
|
$product = $this->getProductStorage()->getCurrentProduct(); |
34
|
|
|
|
35
|
|
|
/** @var Review $resource */ |
36
|
|
|
$resource = $this->getManager()->initResource(); |
37
|
|
|
$resource->setProduct($product); |
38
|
|
|
|
39
|
|
|
$currentRoute = $product->translate()->getRoute()->getId(); |
|
|
|
|
40
|
|
|
$form = $this->formBuilder->createForm($resource); |
41
|
|
|
|
42
|
|
|
if ($form->handleRequest()->isSubmitted()) { |
43
|
|
|
if ($form->isValid()) { |
44
|
|
|
if (false === $this->get('security.authorization_checker')->isGranted('ROLE_CLIENT') |
45
|
|
|
&& false === $this->get('security.authorization_checker')->isGranted('ROLE_ADMIN') |
46
|
|
|
) { |
47
|
|
|
$resource->setEnabled(0); |
|
|
|
|
48
|
|
|
} |
49
|
|
|
$this->getManager()->createResource($resource); |
50
|
|
|
|
51
|
|
|
$this->getFlashHelper()->addSuccess('review.flash.success'); |
52
|
|
|
|
53
|
|
|
return $this->getRouterHelper()->redirectTo('dynamic_' . $currentRoute); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$this->getFlashHelper()->addError('review.flash.error'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return $this->displayTemplate('index', [ |
60
|
|
|
'form' => $form, |
61
|
|
|
'product' => $product, |
62
|
|
|
'reviews' => $repository->getProductReviews($product), |
63
|
|
|
'boxSettings' => $boxSettings, |
64
|
|
|
]); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function reportAction(Review $review) |
68
|
|
|
{ |
69
|
|
|
$currentRoute = $review->getProduct()->translate()->getRoute()->getId(); |
|
|
|
|
70
|
|
|
$mailerConfiguration = $this->getShopStorage()->getCurrentShop()->getMailerConfiguration(); |
71
|
|
|
|
72
|
|
|
$this->getMailerHelper()->sendEmail([ |
73
|
|
|
'recipient' => $mailerConfiguration->getFrom(), |
74
|
|
|
'subject' => $this->trans('review.email.heading.report'), |
75
|
|
|
'template' => 'WellCommerceAppBundle:Email:report_review.html.twig', |
76
|
|
|
'parameters' => [ |
77
|
|
|
'review' => $review, |
78
|
|
|
], |
79
|
|
|
'configuration' => $mailerConfiguration, |
80
|
|
|
]); |
81
|
|
|
|
82
|
|
|
$this->getFlashHelper()->addSuccess('report.flash.success'); |
83
|
|
|
|
84
|
|
|
return $this->redirectToRoute('dynamic_' . $currentRoute); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.