No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

UserSolver.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Lc\SovBundle\Solver\User;
  3. use Lc\SovBundle\Model\Newsletter\NewsletterInterface;
  4. use Lc\SovBundle\Model\User\GroupUserInterface;
  5. use Lc\SovBundle\Model\User\UserInterface;
  6. class UserSolver
  7. {
  8. // @TODO : à écrire si besoin (voir __toString de UserModel)
  9. public function getSummary(UserInterface $user)
  10. {
  11. }
  12. public function getName(UserInterface $user): ?string
  13. {
  14. return (string) ucfirst(strtolower($user->getFirstname())) . ' ' . strtoupper($user->getLastname());
  15. }
  16. // isUserInGroupVip
  17. public function isInGroupUserVip(UserInterface $user)
  18. {
  19. return $this->isInGroupByDevAlias($user, 'vip') ;
  20. }
  21. // isUserInGroup
  22. public function isInGroupUser(UserInterface $user, GroupUserInterface $groupUser)
  23. {
  24. return $this->isInGroupByDevAlias($user, $groupUser->getDevAlias());
  25. }
  26. // isUserInGroupByDevAlias
  27. public function isInGroupByDevAlias(UserInterface $user, string $groupUserDevAlias)
  28. {
  29. $groupUsers = $user->getGroupUsers();
  30. foreach($groupUsers as $groupUser) {
  31. if($groupUser->getDevAlias() == $groupUserDevAlias) {
  32. return true;
  33. }
  34. }
  35. return false;
  36. }
  37. public function isSubscribedToNewsletter(UserInterface $user, NewsletterInterface $newsletter)
  38. {
  39. return $user->getNewsletters()->contains($newsletter);
  40. }
  41. public function getAge(UserInterface $user): ?int
  42. {
  43. if($user->getBirthdate()) {
  44. $now = new \DateTime();
  45. $interval = $now->diff($user->getBirthdate());
  46. return $interval->y;
  47. }else{
  48. return null;
  49. }
  50. }
  51. }