src/Bidcoz/Bundle/CoreBundle/Entity/User.php line 31

Open in your IDE?
  1. <?php
  2. namespace Bidcoz\Bundle\CoreBundle\Entity;
  3. use Bidcoz\Bundle\CoreBundle\Entity\Auction\WatchListItem;
  4. use Bidcoz\Bundle\CoreBundle\Entity\Contact\CompanyMember;
  5. use Bidcoz\Bundle\CoreBundle\Entity\PaymentGateway\PaymentGateway;
  6. use Bidcoz\Bundle\CoreBundle\Entity\Terms\UserTerms;
  7. use Bidcoz\Bundle\CoreBundle\Util\TextManipulator;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use FOS\UserBundle\Model\User as BaseUser;
  11. use FOS\UserBundle\Util\Canonicalizer;
  12. use JMS\Serializer\Annotation as Serialize;
  13. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. /**
  16.  * @ORM\Entity(repositoryClass="UserRepository")
  17.  * @ORM\Table(name="users")
  18.  * @Serialize\ExclusionPolicy("all")
  19.  * @UniqueEntity("email", message="")
  20.  * @ORM\AttributeOverrides({
  21.  *     @ORM\AttributeOverride(name="password",
  22.  *         column=@ORM\Column(
  23.  *             nullable=true
  24.  *         )
  25.  *     ),
  26.  * })
  27.  */
  28. class User extends BaseUser
  29. {
  30.     public const NOTIFICATION_EMAIL 'email';
  31.     public const NOTIFICATION_SMS   'sms';
  32.     public const DEFAULT_TIMEZONE   'America/Chicago';
  33.     /**
  34.      * @ORM\Id
  35.      * @ORM\Column(name="id", type="integer")
  36.      * @ORM\GeneratedValue(strategy="AUTO")
  37.      * @Serialize\Expose
  38.      * @Serialize\Groups({"Default", "API"})
  39.      */
  40.     protected $id;
  41.     /**
  42.      * @ORM\Column(name="fname", length=50)
  43.      * @Assert\NotBlank(groups={"Registration", "Profile"})
  44.      * @Assert\Length(min=1, max=50, groups={"Registration", "Profile"})
  45.      * @Serialize\Expose
  46.      * @Serialize\SerializedName("firstName")
  47.      */
  48.     protected $firstName;
  49.     /**
  50.      * @ORM\Column(name="lname", length=50)
  51.      * @Assert\NotBlank(groups={"Registration", "Profile"})
  52.      * @Assert\Length(min=1, max=50)
  53.      * @Serialize\Expose
  54.      * @Serialize\SerializedName("lastName")
  55.      */
  56.     protected $lastName;
  57.     /**
  58.      * @Serialize\Expose
  59.      * @Serialize\SerializedName("email")
  60.      * @Serialize\Groups({"Default", "API"})
  61.      */
  62.     protected $emailCanonical;
  63.     /**
  64.      * @ORM\Embedded(class= "Address", columnPrefix=false)
  65.      * @Assert\Valid
  66.      */
  67.     protected $address;
  68.     /**
  69.      * @ORM\Column(name="phone", length=42, nullable=true)
  70.      * @Assert\Expression(
  71.      *     "this.isPhoneValidForSMS() or !this.getSMSOptIn()",
  72.      *     message="Please provide a valid mobile phone number!",
  73.      *     groups={"Registration", "Profile"}
  74.      * )
  75.      */
  76.     protected $phone;
  77.     /**
  78.      * @ORM\Column(name="skip_mobile", type="boolean")
  79.      * @Assert\NotNull(groups={"Registration", "Profile"})
  80.      */
  81.     protected $skipMobile false;
  82.     /**
  83.      * @ORM\Column(name="sms_opt_in", type="boolean")
  84.      * @Assert\NotNull(groups={"Registration", "Profile"})
  85.      */
  86.     protected bool $smsOptIn true;
  87.     /**
  88.      * @ORM\Column(name="timezone", length=50)
  89.      * @Assert\NotBlank(groups={"Registration", "Profile"}, message="Please choose your timezone")
  90.      */
  91.     protected $timezone self::DEFAULT_TIMEZONE;
  92.     /**
  93.      * @ORM\OneToMany(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Auction\WatchListItem", mappedBy="user")
  94.      */
  95.     protected $watchList;
  96.     /**
  97.      * @ORM\OneToMany(targetEntity="OrganizationAdmin", mappedBy="user")
  98.      */
  99.     protected $orgAdmins;
  100.     /**
  101.      * @ORM\OneToMany(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Ticket\Ticket", mappedBy="user")
  102.      */
  103.     protected $tickets;
  104.     /**
  105.      * @ORM\OneToMany(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\CreditCard", mappedBy="user")
  106.      */
  107.     protected $creditCards;
  108.     /**
  109.      * @ORM\OneToMany(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Ticket\TicketGroup", mappedBy="owner")
  110.      */
  111.     protected $ticketGroups;
  112.     /**
  113.      * @ORM\OneToMany(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Purchase\Purchase", mappedBy="user")
  114.      */
  115.     protected $purchases;
  116.     /**
  117.      * @ORM\OneToMany(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Transaction\Transaction", mappedBy="user")
  118.      */
  119.     protected $transactions;
  120.     /**
  121.      * @ORM\OneToMany(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Donation\CashDonation", mappedBy="user")
  122.      */
  123.     protected $donations;
  124.     /**
  125.      * @ORM\OneToMany(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Email\Email", mappedBy="user", fetch="EXTRA_LAZY")
  126.      */
  127.     protected $emails;
  128.     /**
  129.      * @ORM\OneToMany(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Auction\Bid", mappedBy="user")
  130.      */
  131.     protected $bids;
  132.     /**
  133.      * @ORM\OneToMany(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Auction\BidNumber", mappedBy="user")
  134.      */
  135.     protected $bidNumbers;
  136.     /**
  137.      * @ORM\Column(name="user_allow_admin_update", type="boolean")
  138.      */
  139.     protected $allowAdminUpdate true;
  140.     /**
  141.      * @ORM\ManyToOne(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Terms\UserTerms")
  142.      */
  143.     protected $userTerms;
  144.     /**
  145.      * @ORM\Column(name="service_fee_type", type="text", length=20);
  146.      */
  147.     protected $feeType Campaign::FEE_USER;
  148.     /**
  149.      * @ORM\Column(name="notitication_preference", type="string", length=5, options={"fixed" = true});
  150.      */
  151.     protected $notificationPreference self::NOTIFICATION_SMS;
  152.     /**
  153.      * @ORM\ManyToOne(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\PaymentGateway\PaymentGateway")
  154.      */
  155.     protected $preferredPaymentGateway;
  156.     /**
  157.      * @ORM\Column(name="is_test", type="boolean")
  158.      */
  159.     protected $test false;
  160.     /**
  161.      * @ORM\Column(name="email_optout", type="boolean")
  162.      */
  163.     protected $emailOptout false;
  164.     /**
  165.      * @ORM\ManyToOne(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Organization")
  166.      * @ORM\JoinColumn(name="last_visit_organization_id", referencedColumnName="id", onDelete="SET NULL")
  167.      */
  168.     protected ?Organization $lastVisitOrganization null;
  169.     /**
  170.      * @ORM\ManyToOne(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Campaign")
  171.      * @ORM\JoinColumn(name="last_visit_campaign_id", referencedColumnName="id", onDelete="SET NULL")
  172.      */
  173.     protected ?Campaign $lastVisitCampaign null;
  174.     /**
  175.      * @ORM\Column(type="datetime")
  176.      */
  177.     protected $createdAt;
  178.     /**
  179.      * @ORM\Column(name="modals", type="simple_array", nullable=true)
  180.      */
  181.     protected $modals = [];
  182.     // Not mapped, a hack around the registration form
  183.     protected $acceptTerms;
  184.     /**
  185.      * @ORM\Column(name="profile_update_dismissed_at", type="datetime", nullable=true)
  186.      */
  187.     protected $profileUpdateDismissedAt;
  188.     /**
  189.      * @ORM\Column(name="has_logged_in", type="boolean")
  190.      * @Serialize\Expose
  191.      */
  192.     protected $loggedIn false;
  193.     /**
  194.      * @ORM\OneToMany(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Contact\Tag", mappedBy="user")
  195.      */
  196.     protected $tags;
  197.     /**
  198.      * @ORM\Column(name="facebook_id", type="string", length=32, nullable=true)
  199.      */
  200.     protected $facebookId;
  201.     /**
  202.      * @ORM\Column(name="facebook_access_token", type="string", length=64, nullable=true)
  203.      */
  204.     protected $facebookAccessToken;
  205.     /**
  206.      * @ORM\Column(name="google_id", type="string", length=32, nullable=true)
  207.      */
  208.     protected $googleId;
  209.     /**
  210.      * @ORM\Column(name="nvidia_id", type="string", length=32, nullable=true)
  211.      */
  212.     protected $nvidiaId;
  213.     /**
  214.      * @ORM\Column(name="chg_id", type="string", length=255, nullable=true)
  215.      */
  216.     protected $chgId;
  217.     /**
  218.      * @ORM\OneToMany(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Contact\Contact", mappedBy="user")
  219.      */
  220.     protected $contacts;
  221.     /**
  222.      * @var CompanyMember[]|ArrayCollection
  223.      * @ORM\OneToMany(targetEntity="Bidcoz\Bundle\CoreBundle\Entity\Contact\CompanyMember", mappedBy="user")
  224.      */
  225.     protected $companyMembers;
  226.     /**
  227.      * @ORM\Column(name="use_fast_list", type="boolean")
  228.      */
  229.     protected $useFastList false;
  230.     public function __construct()
  231.     {
  232.         parent::__construct();
  233.         $this->watchList      = new ArrayCollection();
  234.         $this->tickets        = new ArrayCollection();
  235.         $this->ticketGroups   = new ArrayCollection();
  236.         $this->purchases      = new ArrayCollection();
  237.         $this->transactions   = new ArrayCollection();
  238.         $this->donations      = new ArrayCollection();
  239.         $this->bids           = new ArrayCollection();
  240.         $this->bidNumbers     = new ArrayCollection();
  241.         $this->orgAdmins      = new ArrayCollection();
  242.         $this->tags           = new ArrayCollection();
  243.         $this->createdAt      = new \DateTime();
  244.         $this->companyMembers = new ArrayCollection();
  245.     }
  246.     public function setId($id)
  247.     {
  248.         $this->id $id;
  249.         return $this;
  250.     }
  251.     public function getWatchList()
  252.     {
  253.         return $this->watchList;
  254.     }
  255.     public function addWatchListItem(WatchListItem $item)
  256.     {
  257.         if (!$this->watchList->contains($item)) {
  258.             $this->watchList->add($item);
  259.         }
  260.     }
  261.     public function removeWatchListItem(WatchListItem $item)
  262.     {
  263.         if ($this->watchList->contains($item)) {
  264.             $this->watchList->removeElement($item);
  265.         }
  266.     }
  267.     public function setFirstName($firstName)
  268.     {
  269.         $this->firstName $firstName;
  270.     }
  271.     public function getFirstName()
  272.     {
  273.         return $this->firstName;
  274.     }
  275.     public function setLastName($lastName)
  276.     {
  277.         $this->lastName $lastName;
  278.     }
  279.     public function getLastName()
  280.     {
  281.         return $this->lastName;
  282.     }
  283.     /**
  284.      * @Serialize\VirtualProperty
  285.      * @Serialize\SerializedName("name")
  286.      * @Serialize\Groups({"Default", "API"})
  287.      */
  288.     public function getName()
  289.     {
  290.         $name $this->firstName;
  291.         if ($this->lastName) {
  292.             $name .= ' '.$this->lastName;
  293.         }
  294.         return $name;
  295.     }
  296.     public function hasName(): bool
  297.     {
  298.         return (bool) $this->firstName && $this->lastName;
  299.     }
  300.     public function setAddress(Address $address)
  301.     {
  302.         $this->address $address;
  303.     }
  304.     public function getAddress()
  305.     {
  306.         return $this->address;
  307.     }
  308.     public function setPhone($phone)
  309.     {
  310.         $this->phone TextManipulator::normalizePhoneNumber($phone);
  311.     }
  312.     public function isPhoneValidForSMS(): bool
  313.     {
  314.         // We are going international!  Phone number must start with a '+' (intl code)
  315.         return strlen($this->phone) > && '+' === $this->phone[0];
  316.     }
  317.     public function hasValidPhoneForSmsOrHasOptedOut(): bool
  318.     {
  319.         return !$this->getSMSOptIn() || $this->isPhoneValidForSMS();
  320.     }
  321.     public function hasValidPhoneForSmsAndHasNotOptedOut(): bool
  322.     {
  323.         return $this->getSMSOptIn() && $this->isPhoneValidForSMS();
  324.     }
  325.     public function getPhone()
  326.     {
  327.         return $this->phone;
  328.     }
  329.     public function getSkipMobile(): bool
  330.     {
  331.         return $this->skipMobile;
  332.     }
  333.     public function setSkipMobile($value)
  334.     {
  335.         $this->skipMobile = (bool) $value;
  336.         if ($value) {
  337.             $this->notificationPreference self::NOTIFICATION_EMAIL;
  338.         } else {
  339.             $this->notificationPreference self::NOTIFICATION_SMS;
  340.         }
  341.     }
  342.     public function getSMSOptIn(): bool
  343.     {
  344.         return $this->smsOptIn;
  345.     }
  346.     public function setSMSOptIn($value)
  347.     {
  348.         $this->smsOptIn = (bool) $value;
  349.         if ($value) {
  350.             $this->notificationPreference self::NOTIFICATION_SMS;
  351.         } else {
  352.             $this->notificationPreference self::NOTIFICATION_EMAIL;
  353.         }
  354.     }
  355.     public function setTimezone($timezone)
  356.     {
  357.         $this->timezone $timezone ?: self::DEFAULT_TIMEZONE;
  358.     }
  359.     public function getTimezone()
  360.     {
  361.         return $this->timezone;
  362.     }
  363.     public function getTickets()
  364.     {
  365.         return $this->tickets;
  366.     }
  367.     public function getCreditCards()
  368.     {
  369.         return $this->creditCards;
  370.     }
  371.     public function getTags()
  372.     {
  373.         return $this->tags;
  374.     }
  375.     public function getOrgAdmins()
  376.     {
  377.         return $this->orgAdmins;
  378.     }
  379.     public function getPurchases()
  380.     {
  381.         return $this->purchases;
  382.     }
  383.     public function setAllowAdminUpdate($allowAdminUpdate)
  384.     {
  385.         $this->allowAdminUpdate $allowAdminUpdate;
  386.     }
  387.     public function getAllowAdminUpdate()
  388.     {
  389.         return $this->allowAdminUpdate;
  390.     }
  391.     public function setUserTerms(UserTerms $userTerms)
  392.     {
  393.         $this->userTerms $userTerms;
  394.     }
  395.     public function getUserTerms()
  396.     {
  397.         return $this->userTerms;
  398.     }
  399.     public function setFeeType(string $feeType)
  400.     {
  401.         if (!array_key_exists($feeTypeself::getFeeChoices())) {
  402.             return;
  403.         }
  404.         $this->feeType $feeType;
  405.     }
  406.     public function getFeeType(): string
  407.     {
  408.         return $this->feeType ?: Campaign::FEE_USER;
  409.     }
  410.     public static function getFeeChoices()
  411.     {
  412.         return [
  413.             Campaign::FEE_USER         => 'Accept',
  414.             Campaign::FEE_ORGANIZATION => 'Decline',
  415.         ];
  416.     }
  417.     public function setNotificationPreference($notificationPreference)
  418.     {
  419.         $this->notificationPreference $notificationPreference;
  420.     }
  421.     public function getNotificationPreference()
  422.     {
  423.         return $this->notificationPreference;
  424.     }
  425.     public function sendSMSNotifications()
  426.     {
  427.         return
  428.             $this->notificationPreference
  429.             && self::NOTIFICATION_SMS === $this->notificationPreference
  430.             && $this->isPhoneValidForSMS();
  431.     }
  432.     public static function getNotificationChoices()
  433.     {
  434.         return [
  435.             'Email' => self::NOTIFICATION_EMAIL,
  436.             'Text'  => self::NOTIFICATION_SMS,
  437.         ];
  438.     }
  439.     public function setPreferredPaymentGateway(PaymentGateway $preferredPaymentGateway)
  440.     {
  441.         $this->preferredPaymentGateway $preferredPaymentGateway;
  442.     }
  443.     public function getPreferredPaymentGateway()
  444.     {
  445.         return $this->preferredPaymentGateway;
  446.     }
  447.     public function setTest($test)
  448.     {
  449.         $this->test $test;
  450.     }
  451.     public function isTest()
  452.     {
  453.         return $this->test;
  454.     }
  455.     public function setEmailOptout($emailOptout)
  456.     {
  457.         $this->emailOptout $emailOptout;
  458.     }
  459.     public function setEmail($email)
  460.     {
  461.         $email =  Canonicalizer::canonicalize($email);
  462.         $this->email $email;
  463.         $this->setEmailCanonical($email);
  464.         $this->setUsername($email);
  465.         $this->setUsernameCanonical($email);
  466.     }
  467.     public function isEmailOptout()
  468.     {
  469.         return $this->emailOptout;
  470.     }
  471.     public function setLastVisitOrganization(?Organization $lastVisitOrganization): void
  472.     {
  473.         $this->lastVisitOrganization $lastVisitOrganization;
  474.     }
  475.     public function getLastVisitOrganization(): ?Organization
  476.     {
  477.         return $this->lastVisitOrganization;
  478.     }
  479.     public function setLastVisitCampaign(?Campaign $campaign): void
  480.     {
  481.         $this->lastVisitCampaign     $campaign;
  482.         $this->lastVisitOrganization $campaign $campaign->getOrganization() : null;
  483.     }
  484.     public function getLastVisitCampaign(): ?Campaign
  485.     {
  486.         return $this->lastVisitCampaign;
  487.     }
  488.     public function setCreatedAt(\DateTime $date)
  489.     {
  490.         $this->createdAt $date;
  491.     }
  492.     public function getCreatedAt()
  493.     {
  494.         return $this->createdAt;
  495.     }
  496.     public function setAcceptTerms($acceptTerms)
  497.     {
  498.         $this->acceptTerms $acceptTerms;
  499.     }
  500.     /**
  501.      * @Assert\IsTrue(groups={"Registration"}, message="You must accept the User Terms of Use")
  502.      */
  503.     public function getAcceptTerms()
  504.     {
  505.         return $this->acceptTerms;
  506.     }
  507.     public function getModals()
  508.     {
  509.         return $this->modals ?: [];
  510.     }
  511.     public function hasViewedModal($modal)
  512.     {
  513.         return in_array($modal$this->modals);
  514.     }
  515.     public function viewModal($modal)
  516.     {
  517.         if (!$this->hasViewedModal($modal)) {
  518.             $this->modals[] = $modal;
  519.         }
  520.     }
  521.     public function removeModal($modal)
  522.     {
  523.         $idx array_search($modal$this->modals);
  524.         if (false !== $idx) {
  525.             unset($this->modals[$idx]);
  526.         }
  527.     }
  528.     public function dismissProfileUpdate()
  529.     {
  530.         $this->profileUpdateDismissedAt = new \DateTime();
  531.     }
  532.     public function showProfileUpdate()
  533.     {
  534.         if (!$this->profileUpdateDismissedAt) {
  535.             return true;
  536.         }
  537.         $then = new \DateTime('-8 hours');
  538.         return $this->profileUpdateDismissedAt $then;
  539.     }
  540.     public function hasLoggedIn()
  541.     {
  542.         return $this->loggedIn;
  543.     }
  544.     public function setLoggedIn()
  545.     {
  546.         $this->loggedIn true;
  547.     }
  548.     public function resetLoggedIn()
  549.     {
  550.         $this->loggedIn false;
  551.     }
  552.     public function setFacebookId(int $facebookId)
  553.     {
  554.         $this->setFacebookId $facebookId;
  555.     }
  556.     public function setFacebookAccessToken(string $accessToken)
  557.     {
  558.         $this->facebookAccessToken $accessToken;
  559.     }
  560.     public function getGoogleId()
  561.     {
  562.         return $this->googleId;
  563.     }
  564.     public function setGoogleId(string $googleId)
  565.     {
  566.         $this->googleId $googleId;
  567.     }
  568.     public function getNvidiaId()
  569.     {
  570.         return $this->nvidiaId;
  571.     }
  572.     public function setNvidiaId(string $nvidiaId)
  573.     {
  574.         $this->nvidiaId $nvidiaId;
  575.     }
  576.     public function setChgId(string $chgId)
  577.     {
  578.         $this->chgId $chgId;
  579.     }
  580.     public function getChgId()
  581.     {
  582.         return $this->chgId;
  583.     }
  584.     public function getCompanyMembers()
  585.     {
  586.         return $this->companyMembers;
  587.     }
  588.     public function getEmail()
  589.     {
  590.         return $this->email;
  591.     }
  592.     public function getUseFastList(): bool
  593.     {
  594.         return $this->useFastList;
  595.     }
  596. }