|
- <?php
-
- namespace Lc\SovBundle\Solver\User;
-
- use Lc\SovBundle\Model\Newsletter\NewsletterInterface;
- use Lc\SovBundle\Model\User\GroupUserInterface;
- use Lc\SovBundle\Model\User\UserInterface;
- use Lc\SovBundle\Model\User\UserModel;
-
- class UserSolver
- {
- // @TODO : à écrire si besoin (voir __toString de UserModel)
- public function getSummary(UserInterface $user)
- {
-
- }
-
- public function getName(UserInterface $user): ?string
- {
- return (string) ucfirst(strtolower($user->getFirstname())) . ' ' . strtoupper($user->getLastname());
- }
-
-
- // isUserInGroupVip
- public function isInGroupUserVip(UserInterface $user)
- {
- return $this->isInGroupByDevAlias($user, 'vip') ;
- }
-
- // isUserInGroup
- public function isInGroupUser(UserInterface $user, GroupUserInterface $groupUser)
- {
- return $this->isInGroupByDevAlias($user, $groupUser->getDevAlias());
- }
-
- // isUserInGroupByDevAlias
- public function isInGroupByDevAlias(UserInterface $user, string $groupUserDevAlias)
- {
- $groupUsers = $user->getGroupUsers();
-
- foreach($groupUsers as $groupUser) {
- if($groupUser->getDevAlias() == $groupUserDevAlias) {
- return true;
- }
- }
-
- return false;
- }
-
- public function isSubscribedToNewsletter(UserInterface $user, NewsletterInterface $newsletter)
- {
- return $user->getNewsletters()->contains($newsletter);
- }
-
- public function getAge(UserInterface $user): ?int
- {
- if($user->getBirthdate()) {
- $now = new \DateTime();
- $interval = $now->diff($user->getBirthdate());
- return $interval->y;
- }else{
- return null;
- }
- }
-
- public static function getGenderChoices(){
- return[
- '0',
- '1'
- ];
- }
-
- }
|