src/Services/UsersBundle/Entity/Users.php line 31

Open in your IDE?
  1. <?php
  2. namespace Services\UsersBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Services\UsersBundle\Entity\UserSync;
  5. use Services\PaymentBundle\Entity\Payment;
  6. use Services\ConfigurationBundle\Entity\Roles;
  7. use JMS\Serializer\Annotation as Serializer;
  8. use Services\PaymentBundle\Entity\UserTokens;
  9. use Services\LocationBundle\Entity\UserAddress;
  10. use Services\PaymentBundle\Entity\PaymentTypes;
  11. use Services\PaymentBundle\Entity\PaymentStatus;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use Symfony\Component\Security\Core\User\UserInterface;
  14. use Symfony\Component\Security\Core\User\EquatableInterface;
  15. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  16. use Doctrine\ORM\Mapping\UniqueConstraint;
  17. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  18. /**
  19.  * Users
  20.  *
  21.  * @Serializer\ExclusionPolicy("ALL")
  22.  *
  23.  * @ORM\Table(name="users",uniqueConstraints={@UniqueConstraint(name="user_site_unique_idx", columns={"mail", "site_id"})})
  24.  * @ORM\Entity(repositoryClass="Services\UsersBundle\Repository\UsersRepository")
  25.  * @UniqueEntity(fields={"mail"},
  26.  * message = "Le mail est déjà utilisé")
  27.  */
  28. class Users implements UserInterface\SerializableEquatableInterfacePasswordAuthenticatedUserInterface
  29. {
  30.     /**
  31.      * @var integer
  32.      *
  33.      * @ORM\Column(name="id", type="integer")
  34.      * @ORM\Id
  35.      * @ORM\GeneratedValue(strategy="AUTO")
  36.      */
  37.     private $id;
  38.     /**
  39.      * @var string
  40.      * @ORM\Column(name="username", type="string", length=255, nullable=false)
  41.      */
  42.     private $username;
  43.     /**
  44.      * User Score 0-100
  45.      * @var int
  46.      * @ORM\Column(name="score", type="integer", nullable=true)
  47.      */
  48.     private $score;
  49.     /**
  50.      * // FIXME: not many to one
  51.      * @ORM\ManyToOne(targetEntity="Services\ConfigurationBundle\Entity\Roles", inversedBy="user")
  52.      * @Serializer\Expose
  53.      * @ORM\JoinColumn(nullable=false)
  54.      */
  55.     private $roles// singular
  56.     /**
  57.      * @var string
  58.      * @ORM\Column(name="password", type="string", length=255)
  59.      */
  60.     private $password;
  61.     /**
  62.      * @var string
  63.      *
  64.      * @ORM\Column(name="salt", type="string", length=255)
  65.      */
  66.     private $salt;
  67.     //@NaturalId
  68.     /**
  69.      * @var string
  70.      *
  71.      * @Serializer\Expose
  72.      * @ORM\Column(name="mail", type="string", length=255)
  73.      */
  74.     private $mail;
  75.     /**
  76.      * @ORM\OneToOne(targetEntity="Services\UsersBundle\Entity\UserInfos", inversedBy="user", cascade={"persist", "remove"})
  77.      * @ORM\JoinColumn(nullable=false)
  78.      * @Serializer\Expose
  79.      * @Serializer\Groups({"user_sync"})
  80.      */
  81.     private $userInfos;
  82.     /**
  83.      * @ORM\OneToOne(targetEntity="Services\UsersBundle\Entity\UserErrorAcquisition")
  84.      * @ORM\JoinColumn(name="user_error_acquisition_id", referencedColumnName="id", nullable=true)
  85.      */
  86.     private $userErrorAcquisition;
  87.     /**
  88.      * @ORM\OneToMany(targetEntity="Services\PaymentBundle\Entity\Payment", mappedBy="user", cascade={"persist", "remove"})
  89.      * @ORM\JoinColumn(nullable=true)
  90.      */
  91.     private $payment;
  92.     /**
  93.      * contract modifictions, last one first
  94.      * @ORM\OneToMany(targetEntity="Services\UsersBundle\Entity\ContractModification", mappedBy="user", cascade={"persist", "remove"})
  95.      * @ORM\JoinColumn(nullable=true)
  96.      * @ORM\OrderBy({"id" = "DESC"})
  97.      */
  98.     private $contractModifications;
  99.     /**
  100.      * @ORM\OneToMany(targetEntity="Services\UsersBundle\Entity\UserSync", mappedBy="user", cascade={"persist", "remove"})
  101.      * @ORM\JoinColumn(nullable=true)
  102.      * @ORM\OrderBy({"id" = "DESC"})
  103.      */
  104.     private $userSyncs;
  105.     /**
  106.      * @ORM\ManyToOne(targetEntity="Services\ConfigurationBundle\Entity\Site", inversedBy="user")
  107.      * @ORM\JoinColumn(nullable=true)
  108.      */
  109.     private $site;
  110.     /**
  111.      * @ORM\OneToMany(targetEntity="Services\UsersBundle\Entity\Unsubscribe", mappedBy="user", cascade={"persist", "remove"})
  112.      * @ORM\JoinColumn(nullable=false)
  113.      */
  114.     private $unsubscribe;
  115.     /**
  116.      * @Serializer\Expose
  117.      * @ORM\OneToOne(targetEntity="Services\LocationBundle\Entity\UserAddress", inversedBy="user", cascade={"persist", "remove"})
  118.      * @ORM\JoinColumn(nullable=true)
  119.      */
  120.     private $userAddress;
  121.     /**
  122.      * @ORM\OneToMany(targetEntity="Services\PaymentBundle\Entity\UserTokens", mappedBy="user", cascade={"persist", "remove"})
  123.      * added an order to get the latest active first
  124.      * @ORM\OrderBy({"isActive" = "DESC", "id" = "DESC"})
  125.      */
  126.     private $userTokens;
  127.     /**
  128.      * Flag to determine if a User is created manually by us (retry manual ghost)
  129.      *
  130.      * @var bool
  131.      *
  132.      * @ORM\Column(name="is_manual", type="boolean")
  133.      */
  134.     private $isManual false;
  135.     /**
  136.      * Flag to determine if the user failed to pay the remaining amount in the INITIAL_ONE_EURO campaign type
  137.      * on their first payment
  138.      *
  139.      * @var bool
  140.      * @Serializer\Expose
  141.      * @ORM\Column(name="is_preaboes", type="boolean", nullable=true, options={"default": 0})
  142.      */
  143.     private $isPreaboEs false;
  144.     /**
  145.      * @Serializer\Exclude
  146.      * @ORM\OneToMany(targetEntity="Services\ManualRetryBundle\Entity\RetryUser", mappedBy="user", cascade={"persist", "remove"})
  147.      */
  148.     private $userRetries;
  149.     /**
  150.      * @var boolean
  151.      *
  152.      * @Serializer\Expose
  153.      * @ORM\Column(name="is_deleted", type="boolean", options={"default": 0})
  154.      */
  155.     private $isDeleted;
  156.     /**
  157.      * @var bool
  158.      * @Serializer\Expose
  159.      * @ORM\Column(name="is_external_billing", type="boolean", nullable=true, options={"default": 0})
  160.      */
  161.     private $isExternalBilling;
  162.     /**
  163.      * @var bool
  164.      * @Serializer\Expose
  165.      * @ORM\Column(name="is_external_billing_stopped", type="boolean", nullable=true, options={"default": 0})
  166.      */
  167.     private $isExternalBillingStopped;
  168.     /**
  169.      * @var bool
  170.      * @Serializer\Expose
  171.      * @ORM\Column(name="is_inactive", type="boolean", nullable=true, options={"default": 0})
  172.      */
  173.     private $isInactive;
  174.     /**
  175.      * @var \DateTime
  176.      *
  177.      * @ORM\Column(name="last_conversion_to_inactive", type="datetime", nullable=true)
  178.      */
  179.     private $lastConversionToInactive;
  180.     /**
  181.      * @var \DateTime
  182.      *
  183.      * @ORM\Column(name="last_conversion_to_active", type="datetime", nullable=true)
  184.      */
  185.     private $lastConversionToActive;
  186.     /**
  187.      * @var int|null
  188.      * @ORM\Column(name="prev_roles_id", type="smallint")
  189.      */
  190.     private ?int $prevRoleId;
  191.     public function __construct()
  192.     {
  193.         $this->salt md5(time());
  194.         $this->payment = new \Doctrine\Common\Collections\ArrayCollection();
  195.         $this->isManual false;
  196.         $this->password 'XXXXX';
  197.         $this->score 100;
  198.         $this->isDeleted false;
  199.         $this->isInactive false;
  200.         $this->prevRoleId null;
  201.     }
  202.     /**
  203.      * @inheritDoc
  204.      */
  205.     public function eraseCredentials()
  206.     {
  207.     }
  208.     /**
  209.      * @see \Serializable::serialize()
  210.      */
  211.     public function serialize()
  212.     {
  213.         return serialize([
  214.             $this->id,
  215.             $this->mail,
  216.         ]);
  217.     }
  218.     /**
  219.      * @see \Serializable::unserialize()
  220.      */
  221.     public function unserialize($serialized)
  222.     {
  223.         list(
  224.             $this->id,
  225.         ) = unserialize($serialized);
  226.     }
  227.     public function isEqualTo(UserInterface $user)
  228.     {
  229.         return $user->id === $this->id;
  230.     }
  231.     /**
  232.      * Set roles (role singular)
  233.      *
  234.      * @param \Services\ConfigurationBundle\Entity\Roles $roles
  235.      * @return Users
  236.      */
  237.     public function setRoles(\Services\ConfigurationBundle\Entity\Roles $roles)
  238.     {
  239.         $this->roles $roles;
  240.         return $this;
  241.     }
  242.     /**
  243.      * Set role (role singular)
  244.      *
  245.      * @param \Services\ConfigurationBundle\Entity\Roles $roles
  246.      * @return Users
  247.      */
  248.     public function setRole(\Services\ConfigurationBundle\Entity\Roles $roles)
  249.     {
  250.         $this->roles $roles;
  251.         return $this;
  252.     }
  253.     /**
  254.      * Get roles returns an array of roles!
  255.      * so get the first role's name
  256.      *
  257.      * @return String
  258.      */
  259.     public function getRoleName()
  260.     {
  261.         $roleNames $this->roles->getName();
  262.         return is_array($roleNames) ? $roleNames[0] : $roleNames;
  263.     }
  264.     /**
  265.      * Get roles returns an array of roles!
  266.      *
  267.      * @return String
  268.      */
  269.     public function getRoles()
  270.     {
  271.         return $this->roles->getName();
  272.     }
  273.     /**
  274.      * Get roles
  275.      *
  276.      * @return \Services\ConfigurationBundle\Entity\Roles
  277.      */
  278.     public function getRolesString()
  279.     {
  280.         return  $this->roles;
  281.     }
  282.     /**
  283.      * Get roles
  284.      *
  285.      * @return \Services\ConfigurationBundle\Entity\Roles
  286.      */
  287.     public function getRolesObject()
  288.     {
  289.         return  $this->roles;
  290.     }
  291.     /**
  292.      * @return Bool on whether this user is active (premium, error sub, split, preabo)
  293.      */
  294.     public function isActiveRole(): bool
  295.     {
  296.         $currentRoleId $this->getRolesObject()->getId();
  297.         return in_array($currentRoleIdRoles::ACTIVE_USER_ROLES);
  298.     }
  299.     /**
  300.      * Get id
  301.      *
  302.      * @return integer
  303.      */
  304.     public function getId()
  305.     {
  306.         return $this->id;
  307.     }
  308.     /**
  309.      * Set username
  310.      *
  311.      * @param string $username
  312.      * @return Users
  313.      */
  314.     public function setUsername($username)
  315.     {
  316.         $this->username $username;
  317.         return $this;
  318.     }
  319.     /**
  320.      * Get username
  321.      *
  322.      * @return string
  323.      */
  324.     public function getUsername()
  325.     {
  326.         return $this->username;
  327.     }
  328.     /**
  329.      * Get user identifier
  330.      *
  331.      * @return string
  332.      */
  333.     public function getUserIdentifier(): string
  334.     {
  335.         return $this->getUsername();
  336.     }
  337.     /**
  338.      * Set password
  339.      *
  340.      * @param string $password
  341.      * @return Users
  342.      */
  343.     public function setPassword($password)
  344.     {
  345.         $this->password $password;
  346.         return $this;
  347.     }
  348.     /**
  349.      * Get password
  350.      *
  351.      * @return string
  352.      */
  353.     public function getPassword(): ?string
  354.     {
  355.         return $this->password;
  356.     }
  357.     /**
  358.      * Set salt
  359.      *
  360.      * @param string $salt
  361.      * @return Users
  362.      */
  363.     public function setSalt($salt)
  364.     {
  365.         $this->salt $salt;
  366.         return $this;
  367.     }
  368.     /**
  369.      * Get salt
  370.      *
  371.      * @return string
  372.      */
  373.     public function getSalt()
  374.     {
  375.         return $this->salt;
  376.     }
  377.     /**
  378.      * Set mail
  379.      *
  380.      * @param string $mail
  381.      * @return Users
  382.      */
  383.     public function setMail($mail)
  384.     {
  385.         $this->mail $mail;
  386.         return $this;
  387.     }
  388.     /**
  389.      * Get mail
  390.      *
  391.      * @return string
  392.      */
  393.     public function getMail()
  394.     {
  395.         return $this->mail;
  396.     }
  397.     /**
  398.      * Set userInfos
  399.      *
  400.      * @param \Services\UsersBundle\Entity\UserInfos $userInfos
  401.      * @return Users
  402.      */
  403.     public function setUserInfos(\Services\UsersBundle\Entity\UserInfos $userInfos)
  404.     {
  405.         $this->userInfos $userInfos;
  406.         return $this;
  407.     }
  408.     /**
  409.      * Get userInfos
  410.      *
  411.      * @return \Services\UsersBundle\Entity\UserInfos
  412.      */
  413.     public function getUserInfos()
  414.     {
  415.         return $this->userInfos;
  416.     }
  417.     /**
  418.      * Add payment
  419.      *
  420.      * @param Payment $payment
  421.      * @param bool $checkIfAlreadyExists check if payment has been already added for this user
  422.      * @return Users
  423.      */
  424.     public function addPayment(Payment $paymentbool $checkIfAlreadyExists false)
  425.     {
  426.         $exists false;
  427.         if ($checkIfAlreadyExists) {
  428.             foreach ($this->payment as $p) {
  429.                 if ($p->getId() == $payment->getId()) {
  430.                     $exists true;
  431.                     break;
  432.                 }
  433.             }
  434.         }
  435.         if (!$exists) {
  436.             $this->payment[] = $payment;
  437.         }
  438.         return $this;
  439.     }
  440.     /**
  441.      * Remove payment
  442.      *
  443.      * @param \Services\PaymentBundle\Entity\Payment $payment
  444.      */
  445.     public function removePayment(\Services\PaymentBundle\Entity\Payment $payment)
  446.     {
  447.         $this->payment->removeElement($payment);
  448.     }
  449.     /**
  450.      * Get payment (s)
  451.      * TODO: payments
  452.      * @return \Doctrine\Common\Collections\Collection
  453.      */
  454.     public function getPayment()
  455.     {
  456.         return $this->payment;
  457.     }
  458.     /**
  459.      * Get payment (s)
  460.      * correct name for get all payments
  461.      * @return \Doctrine\Common\Collections\Collection
  462.      */
  463.     public function getPayments()
  464.     {
  465.         return $this->payment;
  466.     }
  467.     /**
  468.      * Get contract modification (s)
  469.      * @return \Doctrine\Common\Collections\Collection
  470.      */
  471.     public function getContractModifications()
  472.     {
  473.         return $this->contractModifications;
  474.     }
  475.     /**
  476.      * Get userSyncs
  477.      * @return \Doctrine\Common\Collections\Collection
  478.      */
  479.     public function getUserSyncs()
  480.     {
  481.         return $this->userSyncs;
  482.     }
  483.     /**
  484.      * Get payment
  485.      *
  486.      * @return ContractModification|null if none
  487.      */
  488.     public function getLastContractModification()
  489.     {
  490.         return
  491.         $this->contractModifications[0] ?? null;
  492.     }
  493.     /**
  494.      * Get payment
  495.      *
  496.      * @return Payment
  497.      */
  498.     public function getLastPayment()
  499.     {
  500.         return $this->payment->last() ?: null;
  501.         //[count($this->payment) - 1];
  502.     }
  503.     /**
  504.      * Get payment
  505.      *
  506.      * @return Payment
  507.      */
  508.     public function getFirstPayment()
  509.     {
  510.         return $this->payment[0];
  511.     }
  512.     /**
  513.      * return first `Active` payment (3, 11, 2)
  514.      * @return Payment|null if user has no active payment
  515.      */
  516.     public function getActivePayment($includeSplit false)
  517.     {
  518.         $activePaymentTypes = [
  519.             PaymentStatus::STATUS_PAIEMENT_SIMPLE,
  520.             PaymentStatus::STATUS_RETRY_7_DAY,
  521.             PaymentStatus::STATUS_PREMIER_PRELEVEMENT,
  522.         ];
  523.         if ($includeSplit) {
  524.             $activePaymentTypes[] = PaymentStatus::STATUS_PAIEMENT_SPLIT;
  525.         }
  526.         foreach ($this->payment as $paymentCheck) {
  527.             /** @var Payment $paymentCheck */
  528.             if (in_array($paymentCheck->getPaymentStatus()->getId(), $activePaymentTypes)) {
  529.                 return $paymentCheck;
  530.             }
  531.         }
  532.         return null;
  533.     }
  534.     /**
  535.      * Get the payment previous (taking into account the value of nextPaymentDate) to the provided payment
  536.      *
  537.      * @param \Services\PaymentBundle\Entity\Payment $payment
  538.      * @return Payment|null
  539.      */
  540.     public function getPreviousPayment(Payment $payment): ?Payment
  541.     {
  542.         $paymentsList $this->payment->toArray();
  543.         $paymentsList array_reverse($paymentsList);
  544.         foreach ($paymentsList as $p) {
  545.             if ($p->getNextPaymentDate() < $payment->getNextPaymentDate()) {
  546.                 return $p;
  547.             }
  548.         }
  549.         return null;
  550.     }
  551.     /**
  552.      * Get the start date of the first period for this user.
  553.      *
  554.      * @return \DateTime
  555.      */
  556.     public function getInitialPeriodStartDate()
  557.     {
  558.         // PM: Period starts when 1st payment is captured (even if it has been just 1 euro)
  559.         $paymentsList $this->getPayment(); // Get payments ordered by nextPaymentDate ASC
  560.         // 1) We get the last created payment nextPaymentDate by default
  561.         // Example: If we have an Auth today (Nov 30th) (1 euro + rest immediately - Payment D+3),
  562.         // his period start in December when we have the capture.
  563.         if ($paymentsList->isEmpty()) {
  564.             $initialDate = clone $this->getUserInfos()->getDateInscription();
  565.         } else {
  566.             $initialDate = clone $paymentsList->last()->getNextPaymentDate();
  567.             $paymentsList->first();
  568.             // 2) If we have a captured payment, get its subscription date as initial date
  569.             foreach ($paymentsList as $p) {
  570.                 if ($p->getPaymentStatus()->getId() == PaymentStatus::STATUS_PAYE) {
  571.                     $initialDate = clone $p->getNextPaymentDate();
  572.                     break;
  573.                 }
  574.             }
  575.         }
  576.         return $initialDate;
  577.     }
  578.     /**
  579.      * Get payment
  580.      *
  581.      * @return \Doctrine\Common\Collections\Collection
  582.      */
  583.     public function countPayment()
  584.     {
  585.         return count($this->payment);
  586.     }
  587.     /**
  588.      * Set site.
  589.      *
  590.      * @param \Services\ConfigurationBundle\Entity\Site $site
  591.      *
  592.      * @return Users
  593.      */
  594.     public function setSite(\Services\ConfigurationBundle\Entity\Site $site)
  595.     {
  596.         $this->site $site;
  597.         return $this;
  598.     }
  599.     /**
  600.      * Get site.
  601.      *
  602.      * @return \Services\ConfigurationBundle\Entity\Site
  603.      */
  604.     public function getSite()
  605.     {
  606.         return $this->site;
  607.     }
  608.     /**
  609.      * Add unsubscribe.
  610.      *
  611.      * @param \Services\UsersBundle\Entity\Unsubscribe $unsubscribe
  612.      *
  613.      * @return Users
  614.      */
  615.     public function addUnsubscribe(\Services\UsersBundle\Entity\Unsubscribe $unsubscribe)
  616.     {
  617.         $this->unsubscribe[] = $unsubscribe;
  618.         return $this;
  619.     }
  620.     /**
  621.      * Remove unsubscribe.
  622.      *
  623.      * @param \Services\UsersBundle\Entity\Unsubscribe $unsubscribe
  624.      *
  625.      * @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
  626.      */
  627.     public function removeUnsubscribe(\Services\UsersBundle\Entity\Unsubscribe $unsubscribe)
  628.     {
  629.         return $this->unsubscribe->removeElement($unsubscribe);
  630.     }
  631.     /**
  632.      * Get unsubscribe.
  633.      *
  634.      * @return \Doctrine\Common\Collections\Collection
  635.      */
  636.     public function getUnsubscribe()
  637.     {
  638.         return $this->unsubscribe;
  639.     }
  640.     /**
  641.      * Set userAddress.
  642.      *
  643.      * @param \Services\LocationBundle\Entity\UserAddress|null $userAddress
  644.      *
  645.      * @return Users
  646.      */
  647.     public function setUserAddress(\Services\LocationBundle\Entity\UserAddress $userAddress null)
  648.     {
  649.         $this->userAddress $userAddress;
  650.         return $this;
  651.     }
  652.     /**
  653.      * Get userAddress.
  654.      *
  655.      * @return UserAddress
  656.      */
  657.     public function getUserAddress()
  658.     {
  659.         return $this->userAddress;
  660.     }
  661.     /**
  662.      * Add userToken.
  663.      *
  664.      * @param \Services\PaymentBundle\Entity\UserTokens $userToken
  665.      *
  666.      * @return Users
  667.      */
  668.     public function addUserToken(\Services\PaymentBundle\Entity\UserTokens $userToken)
  669.     {
  670.         $this->userTokens[] = $userToken;
  671.         return $this;
  672.     }
  673.     /**
  674.      * Remove userToken.
  675.      *
  676.      * @param \Services\PaymentBundle\Entity\UserTokens $userToken
  677.      *
  678.      * @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
  679.      */
  680.     public function removeUserToken(\Services\PaymentBundle\Entity\UserTokens $userToken)
  681.     {
  682.         return $this->userTokens->removeElement($userToken);
  683.     }
  684.     /**
  685.      * Get userTokens. (latest first)
  686.      *
  687.      * @return \Doctrine\Common\Collections\Collection
  688.      */
  689.     public function getUserTokens()
  690.     {
  691.         return $this->userTokens;
  692.     }
  693.     /**
  694.      * return last active UserToken
  695.      * if mid is not given, just return the last generated token (freshest CC)
  696.      * @param PaymentTypes $mid used
  697.      * @return UserTokens|null
  698.      */
  699.     public function getLatestActiveUserToken($mid null)
  700.     {
  701.         if ($this->userTokens) {
  702.             // user tokens are sorted from last to first
  703.             foreach ($this->userTokens as $userToken) {
  704.                 /** @var UserTokens $userToken */
  705.                 if (null == $mid
  706.                 || ($userToken->getPaymentTypes()->getId() == $mid->getId()
  707.                     && $userToken->getIsActive()
  708.                 )) {
  709.                     return $userToken;
  710.                 }
  711.             }
  712.         }
  713.         return null;
  714.     }
  715.     /**
  716.      * WIP:
  717.      * has a valid credit card
  718.      * goes through the tokens to check if there's a least one card still valid
  719.      * @return bool
  720.      */
  721.     public function hasValidCreditCard()
  722.     {
  723.         foreach ($this->userTokens as $userToken) {
  724.             /** @var UserTokens $userToken */
  725.             if (!$userToken->getIsExpired()) {
  726.                 return true;
  727.             }
  728.         }
  729.         return false;
  730.     }
  731.     /**
  732.      * is Active
  733.      * helper
  734.      * @return bool true if active
  735.      */
  736.     public function isActive()
  737.     {
  738.         return (null != $this->roles)
  739.             && in_array($this->roles->getId(), [
  740.                 Roles::ROLE_PREMIUM,
  741.                 Roles::ROLE_ERROR_SUBSCRIPTION,
  742.                 Roles::ROLE_SPLIT,
  743.                 Roles::ROLE_PREABO
  744.             ]);
  745.     }
  746.     /**
  747.      * Set isManual.
  748.      *
  749.      * @param bool $isManual
  750.      *
  751.      * @return Users
  752.      */
  753.     public function setIsManual($isManual)
  754.     {
  755.         $this->isManual $isManual;
  756.         return $this;
  757.     }
  758.     /**
  759.      * Get isManual.
  760.      *
  761.      * @return bool
  762.      */
  763.     public function getIsManual()
  764.     {
  765.         return $this->isManual;
  766.     }
  767.     /**
  768.      * Set score.
  769.      *
  770.      * @param int|null $score
  771.      *
  772.      * @return Users
  773.      */
  774.     public function setScore($score null)
  775.     {
  776.         $this->score $score;
  777.         return $this;
  778.     }
  779.     /**
  780.      * Get score.
  781.      *
  782.      * @return int|null
  783.      */
  784.     public function getScore()
  785.     {
  786.         return $this->score;
  787.     }
  788.     /**
  789.      * Set userErrorAcquisition.
  790.      *
  791.      * @param \Services\UsersBundle\Entity\UserErrorAcquisition|null $userErrorAcquisition
  792.      *
  793.      * @return Users
  794.      */
  795.     public function setUserErrorAcquisition(\Services\UsersBundle\Entity\UserErrorAcquisition $userErrorAcquisition null)
  796.     {
  797.         $this->userErrorAcquisition $userErrorAcquisition;
  798.         return $this;
  799.     }
  800.     /**
  801.      * Get userErrorAcquisition.
  802.      *
  803.      * @return \Services\UsersBundle\Entity\UserErrorAcquisition|null
  804.      */
  805.     public function getUserErrorAcquisition()
  806.     {
  807.         return $this->userErrorAcquisition;
  808.     }
  809.     /**
  810.      * @return string|null fullname FIRST + LAST or null if not defined
  811.      */
  812.     public function getFullname()
  813.     {
  814.         if (null == $this->userAddress) {
  815.             return null;
  816.         }
  817.         $firstName $this->userAddress->getFirstname();
  818.         $lastName $this->userAddress->getLastname();
  819.         if ((null == $firstName) && (null == $lastName)) {
  820.             return null;
  821.         }
  822.         return "{$firstName} {$lastName}";
  823.     }
  824.     /**
  825.      * is the user a UEA.
  826.      * this one is a bit tricky as a user with a first error made upon subscription is directly put in UEA
  827.      * i.e. even if there was a typo in the card number
  828.      * so the only way is to see if the UEA date is > than the sub date.
  829.      * @return bool
  830.      */
  831.     public function isUEA()
  832.     {
  833.         if (null == $this->userErrorAcquisition) {
  834.             // it's obviously not an UserErrorAcquisition
  835.             return false;
  836.         }
  837.         $dateInscriptionUser $this->userInfos->getDateInscription();
  838.         $dateInscriptionUEA $this->userErrorAcquisition->getDateInscription();
  839.         if (is_null($dateInscriptionUser) || is_null($dateInscriptionUEA)) {
  840.             return false// security
  841.         }
  842.         $acceptedInterval = new \DateInterval('P1D');
  843.         return $dateInscriptionUser->add($acceptedInterval) >= $dateInscriptionUEA;
  844.         // return $dateInscriptionUser->diff($dateInscriptionUEA) >= $acceptedInterval;
  845.     }
  846.     /**
  847.      * Add userRetry.
  848.      *
  849.      * @param \Services\ManualRetryBundle\Entity\RetryUser $userRetry
  850.      *
  851.      * @return Users
  852.      */
  853.     public function addUserRetry(\Services\ManualRetryBundle\Entity\RetryUser $userRetry)
  854.     {
  855.         $this->userRetries[] = $userRetry;
  856.         return $this;
  857.     }
  858.     /**
  859.      * Remove userRetry.
  860.      *
  861.      * @param \Services\ManualRetryBundle\Entity\RetryUser $userRetry
  862.      *
  863.      * @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
  864.      */
  865.     public function removeUserRetry(\Services\ManualRetryBundle\Entity\RetryUser $userRetry)
  866.     {
  867.         return $this->userRetries->removeElement($userRetry);
  868.     }
  869.     /**
  870.      * Get userRetries.
  871.      *
  872.      * @return \Doctrine\Common\Collections\Collection
  873.      */
  874.     public function getUserRetries()
  875.     {
  876.         return $this->userRetries;
  877.     }
  878.     /**
  879.      * Get isPreaboEs
  880.      *
  881.      * @return  bool
  882.      */
  883.     public function getIsPreaboEs()
  884.     {
  885.         return $this->isPreaboEs;
  886.     }
  887.     /**
  888.      * Set isPreaboEs
  889.      *
  890.      * @param  bool  $isPreaboEs
  891.      *
  892.      * @return  self
  893.      */
  894.     public function setIsPreaboEs(bool $isPreaboEs)
  895.     {
  896.         $this->isPreaboEs $isPreaboEs;
  897.         return $this;
  898.     }
  899.     /**
  900.      * Get the value of isExternalBilling
  901.      *
  902.      * @return  boolean
  903.      */
  904.     public function getIsExternalBilling(): bool
  905.     {
  906.         return (bool) $this->isExternalBilling;
  907.     }
  908.     /**
  909.      * Set the value of isExternalBilling
  910.      *
  911.      * @param  boolean  $isExternalBilling
  912.      *
  913.      * @return  self
  914.      */
  915.     public function setIsExternalBilling(bool $isExternalBilling): self
  916.     {
  917.         $this->isExternalBilling $isExternalBilling;
  918.         return $this;
  919.     }
  920.     /**
  921.      * Get isDeleted.
  922.      *
  923.      * @return bool
  924.      */
  925.     public function getIsDeleted()
  926.     {
  927.         return $this->isDeleted;
  928.     }
  929.     /**
  930.      * Set isDeleted.
  931.      *
  932.      * @param bool $isDeleted
  933.      *
  934.      * @return Users
  935.      */
  936.     public function setIsDeleted($isDeleted): Users
  937.     {
  938.         $this->isDeleted $isDeleted;
  939.         return $this;
  940.     }
  941.     /**
  942.      * Retrieve if its processed from unsubscribed external billing
  943.      * @return bool
  944.      */
  945.     public function getIsExternalBillingStopped(): bool
  946.     {
  947.         return $this->isExternalBillingStopped;
  948.     }
  949.     /**
  950.      * Mark if it's processed from unsubscribed external billing
  951.      * @param bool $isExternalBillingStopped
  952.      * @return void
  953.      */
  954.     public function setIsExternalBillingStopped(bool $isExternalBillingStopped): self
  955.     {
  956.         $this->isExternalBillingStopped $isExternalBillingStopped;
  957.         return $this;
  958.     }
  959.     /**
  960.      * Get the value of isInactive
  961.      *
  962.      * @return  boolean
  963.      */
  964.     public function getIsInactive(): bool
  965.     {
  966.         return (bool) $this->isInactive;
  967.     }
  968.     /**
  969.      * Set the value of isInactive
  970.      *
  971.      * @param  boolean  $isInactive
  972.      *
  973.      * @return  self
  974.      */
  975.     public function setIsInactive(bool $isInactive): self
  976.     {
  977.         $this->isInactive $isInactive;
  978.         return $this;
  979.     }
  980.     /**
  981.      * Get the value of lastConversionToInactive
  982.      *
  983.      * @return  \DateTime|null
  984.      */
  985.     public function getLastConversionToInactive()
  986.     {
  987.         return $this->lastConversionToInactive ? clone $this->lastConversionToInactive null;
  988.     }
  989.     /**
  990.      * Set the value of lastConversionToInactive
  991.      *
  992.      * @param  \DateTime|null  $lastConversionToInactive
  993.      *
  994.      * @return  self
  995.      */
  996.     public function setLastConversionToInactive(?\DateTime $lastConversionToInactive)
  997.     {
  998.         $this->lastConversionToInactive $lastConversionToInactive;
  999.         return $this;
  1000.     }
  1001.     /**
  1002.      * Get the value of lastConversionToActive
  1003.      *
  1004.      * @return  \DateTime|null
  1005.      */
  1006.     public function getLastConversionToActive()
  1007.     {
  1008.         return $this->lastConversionToActive ? clone $this->lastConversionToActive null;
  1009.     }
  1010.     /**
  1011.      * Set the value of lastConversionToActive
  1012.      *
  1013.      * @param  \DateTime|null  $lastConversionToActive
  1014.      *
  1015.      * @return  self
  1016.      */
  1017.     public function setLastConversionToActive(?\DateTime $lastConversionToActive)
  1018.     {
  1019.         $this->lastConversionToActive $lastConversionToActive;
  1020.         return $this;
  1021.     }
  1022.     /**
  1023.      * Get the value of prevRoleId
  1024.      *
  1025.      * @return  boolean
  1026.      */
  1027.     public function getPrevRoleId(): bool
  1028.     {
  1029.         return $this->prevRoleId;
  1030.     }
  1031.     /**
  1032.      * Set the value of prevRoleId
  1033.      *
  1034.      * @param int $prevRoleId
  1035.      *
  1036.      * @return self
  1037.      */
  1038.     public function setPrevRoleId($prevRoleId): self
  1039.     {
  1040.         $this->prevRoleId $prevRoleId;
  1041.         return $this;
  1042.     }
  1043. }