You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NewsletterSignupToBooleanTransformer.php 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace Lc\ShopBundle\Form\DataTransformer;
  3. use Lc\ShopBundle\Context\ProductInterface;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Lc\ShopBundle\Services\UtilsManager;
  6. use Symfony\Component\Form\DataTransformerInterface;
  7. use Symfony\Component\Form\Exception\TransformationFailedException;
  8. use Symfony\Component\Security\Core\Security;
  9. class NewsletterSignupToBooleanTransformer implements DataTransformerInterface
  10. {
  11. private $security ;
  12. private $userUtils ;
  13. public function __construct(Security $security, UtilsManager $utilsManager)
  14. {
  15. $this->security = $security;
  16. $this->userUtils = $utilsManager->getUserUtils() ;
  17. }
  18. public function transform($newsletter)
  19. {
  20. $user = $this->security->getUser() ;
  21. if($user && $newsletter) {
  22. return $this->userUtils->isSubscribedToNewsletter($user, $newsletter) ;
  23. }
  24. return false ;
  25. }
  26. public function reverseTransform($isSubscribed)
  27. {
  28. // Impossible de retrouver la newsletter depuis sa valeur booléenne.
  29. //throw new TransformationFailedException('Impossible de retrouver la newsletter depuis sa valeur booléenne.') ;
  30. return false ;
  31. }
  32. }