Guest User

Untitled

a guest
Jun 18th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. namespace AppBundleService;
  2.  
  3. use DoctrineCommonPersistenceObjectManager;
  4. use SymfonyComponentSecurityCoreAuthenticationTokenStorageTokenStorageInterface;
  5.  
  6. class BonusService {
  7.  
  8. private $user;
  9. private $manager;
  10.  
  11. __construct(TokenStorageInterface, $tokenStorage, ObjectManager $manager) {
  12. $this->user = $tokenStorage->getToken()->getUser(); // Sometimes fails here
  13. $this->manager = $manager;
  14. }
  15.  
  16. public function hasBonuses() {
  17. return count($this->manager->getRepository(Bonus::class)->findBy(array('contact' => $user)) > 0;
  18. }
  19. }
  20.  
  21. services:
  22. _defaults:
  23. autowire: true
  24. autoconfigure: true
  25. public: true
  26.  
  27. AppBundleServiceBonusService:
  28.  
  29. twig:
  30. ...
  31. globals:
  32. bonus_service: '@AppBundleServiceBonusService'
  33.  
  34. ...
  35. {% if bonus_service.hasBonuses %}Have Bonuses{% endif %}
  36. ...
Add Comment
Please, Sign In to add comment