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.

74 lines
1.8KB

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