|
- <?php
-
- namespace Lc\ShopBundle\Form\DataTransformer;
-
- use Lc\ShopBundle\Context\ProductInterface;
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\ShopBundle\Services\UtilsManager;
- use Symfony\Component\Form\DataTransformerInterface;
- use Symfony\Component\Form\Exception\TransformationFailedException;
- use Symfony\Component\Security\Core\Security;
-
- class NewsletterSignupToBooleanTransformer implements DataTransformerInterface
- {
- private $security ;
- private $userUtils ;
-
- public function __construct(Security $security, UtilsManager $utilsManager)
- {
- $this->security = $security;
- $this->userUtils = $utilsManager->getUserUtils() ;
- }
-
- public function transform($newsletter)
- {
- $user = $this->security->getUser() ;
-
- if($user && $newsletter) {
- return $this->userUtils->isSubscribedToNewsletter($user, $newsletter) ;
- }
-
- return false ;
- }
-
- public function reverseTransform($isSubscribed)
- {
- // Impossible de retrouver la newsletter depuis sa valeur booléenne.
- //throw new TransformationFailedException('Impossible de retrouver la newsletter depuis sa valeur booléenne.') ;
-
- return false ;
- }
- }
|