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

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