src/FMT/Data/Entity/UserProfile.php line 36

Open in your IDE?
  1. <?php
  2. namespace FMT\Data\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Gedmo\Timestampable\Traits\TimestampableEntity;
  5. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  6. /**
  7.  * UserProfile
  8.  *
  9.  * @ORM\Table(
  10.  *     name="user_profile",
  11.  *     indexes={
  12.  *          @ORM\Index(name="FK_profile_school", columns={"school_id"}),
  13.  *          @ORM\Index(name="FK_profile_major", columns={"major_id"}),
  14.  *          @ORM\Index(name="FK_profile_address", columns={"address_id"}),
  15.  *          @ORM\Index(name="FK_profile_avatar", columns={"avatar_id"})
  16.  *      }
  17.  * )
  18.  * @UniqueEntity(
  19.  *     fields={"phone"},
  20.  *     message="fmt.sign_up.phone_unique", groups={"registration"}
  21.  * )
  22.  * @UniqueEntity(
  23.  *     fields={"phone"},
  24.  *     message="fmt.admin.phone_unique", groups={"Admin"}
  25.  *     )
  26.  * @ORM\Entity
  27.  * @ORM\HasLifecycleCallbacks()
  28.  * @SuppressWarnings(PHPMD.TooManyFields)
  29.  * @SuppressWarnings(PHPMD.ExcessivePublicCount)
  30.  */
  31. class UserProfile implements EntityInterface
  32. {
  33.     use TimestampableEntity;
  34.     const VISIBILITY_ALL 0;
  35.     const VISIBILITY_REGISTRED 1;
  36.     const VISIBILITY_NON 2;
  37.     const GRADUATE 'Graduate Student';
  38.     const UNDERGRADUATE 'Undergraduate Student';
  39.     
  40.     /**
  41.      * @var integer
  42.      *
  43.      * @ORM\Column(name="id", type="integer")
  44.      * @ORM\Id
  45.      * @ORM\GeneratedValue(strategy="IDENTITY")
  46.      */
  47.     private $id;
  48.     /**
  49.      * @var \FMT\Data\Entity\UserSchool
  50.      *
  51.      * @ORM\ManyToOne(targetEntity="FMT\Data\Entity\UserSchool", cascade={"persist"})
  52.      * @ORM\JoinColumns({
  53.      *   @ORM\JoinColumn(name="school_id", referencedColumnName="id")
  54.      * })
  55.      */
  56.     private $school;
  57.     /**
  58.      * @var \FMT\Data\Entity\UserMajor
  59.      *
  60.      * @ORM\ManyToOne(targetEntity="FMT\Data\Entity\UserMajor", inversedBy="profile", cascade={"persist"})
  61.      * @ORM\JoinColumns({
  62.      *   @ORM\JoinColumn(name="major_id", referencedColumnName="id")
  63.      * })
  64.      */
  65.     private $major;
  66.     /**
  67.      * @var \FMT\Data\Entity\Address
  68.      *
  69.      * @ORM\ManyToOne(targetEntity="FMT\Data\Entity\Address", inversedBy="profile", cascade={"persist"})
  70.      * @ORM\JoinColumns({
  71.      *   @ORM\JoinColumn(name="address_id", referencedColumnName="id")
  72.      * })
  73.      */
  74.     private $address;
  75.     /**
  76.      * @var \FMT\Data\Entity\UserAvatar
  77.      *
  78.      * @ORM\ManyToOne(targetEntity="FMT\Data\Entity\UserAvatar", inversedBy="profile", cascade={"persist"})
  79.      * @ORM\JoinColumns({
  80.      *   @ORM\JoinColumn(name="avatar_id", referencedColumnName="id")
  81.      * })
  82.      */
  83.     private $avatar;
  84.     /**
  85.      * @var string
  86.      *
  87.      * @ORM\Column(name="email", type="string", length=255, nullable=false)
  88.      */
  89.     private $email;
  90.     /**
  91.      * @var string
  92.      *
  93.      * @ORM\Column(name="first_name", type="string", length=255, nullable=true)
  94.      */
  95.     private $firstName;
  96.     /**
  97.      * @var string
  98.      *
  99.      * @ORM\Column(name="last_name", type="string", length=255, nullable=true)
  100.      */
  101.     private $lastName;
  102.     /**
  103.      * @var integer|null
  104.      *
  105.      * @ORM\Column(name="grad_year", type="integer", nullable=true)
  106.      */
  107.     private $gradYear;
  108.     /**
  109.      * @var integer
  110.      *
  111.      * @ORM\Column(name="first_gen", type="smallint", nullable=false)
  112.      */
  113.     private $firstGen 0;
  114.     /**
  115.      * @var string
  116.      *
  117.      * @ORM\Column(name="student_type", type="string", length=30, nullable=true)
  118.      */
  119.     private $studentType self::UNDERGRADUATE;
  120.     /**
  121.      * @var string
  122.      *
  123.      * @ORM\Column(name="phone", type="string", length=30, nullable=true)
  124.      */
  125.     private $phone;
  126.     /**
  127.      * @var string
  128.      *
  129.      * @ORM\Column(name="about", type="text", length=65535, nullable=true)
  130.      */
  131.     private $aboutText;
  132.     /**
  133.      * @var string
  134.      *
  135.      * @ORM\Column(name="snapchat_id", type="text", length=255, nullable=true)
  136.      */
  137.     private $snapchatId;
  138.     /**
  139.      * @var string
  140.      *
  141.      * @ORM\Column(name="facebook_messenger_id", type="text", length=255, nullable=true)
  142.      */
  143.     private $facebookMessengerId;
  144.     /**
  145.      * @var string
  146.      *
  147.      * @ORM\Column(name="other_email", type="text", length=255, nullable=true)
  148.      */
  149.     private $otherEmail;
  150.     /**
  151.      * @var integer
  152.      *
  153.      * @ORM\Column(name="visible", type="smallint", nullable=false)
  154.      */
  155.     private $visible self::VISIBILITY_ALL;
  156.     /**
  157.      * @var integer
  158.      *
  159.      * @ORM\Column(name="facebook", type="smallint", nullable=false)
  160.      */
  161.     private $facebook 0;
  162.     /**
  163.      * @var integer
  164.      *
  165.      * @ORM\Column(name="twitter", type="smallint", nullable=false)
  166.      */
  167.     private $twitter 0;
  168.     /**
  169.      * @var User
  170.      *
  171.      * @ORM\OneToOne(targetEntity="User", mappedBy="profile")
  172.      */
  173.     protected $user;
  174.     /**
  175.     * Virtual field to fetch additional data.
  176.     */
  177.     public function getCampaignTotal(): string
  178.     {
  179.         // Perform your custom query or logic here
  180.         // For example, fetch data from another repository or API
  181.         return ''// Replace with actual logic
  182.     }
  183.     public function getFundedTotal(): string
  184.     {
  185.         // Perform your custom query or logic here
  186.         // For example, fetch data from another repository or API
  187.         return ''// Replace with actual logic
  188.     }
  189.     public function getPurchaseUrl(): string
  190.     {
  191.         // Perform your custom query or logic here
  192.         // For example, fetch data from another repository or API
  193.         return ''// Replace with actual logic
  194.     }
  195.     public function getTransferTotal(): string
  196.     {
  197.         // Perform your custom query or logic here
  198.         // For example, fetch data from another repository or API
  199.         return ''// Replace with actual logic
  200.     }
  201.     public function getRemainingTotal(): string
  202.     {
  203.         // Perform your custom query or logic here
  204.         // For example, fetch data from another repository or API
  205.         return ''// Replace with actual logic
  206.     }
  207.     public function getFundedPercent(): string
  208.     {
  209.         // Perform your custom query or logic here
  210.         // For example, fetch data from another repository or API
  211.         return ''// Replace with actual logic
  212.     }
  213.     /**
  214.      * @return int
  215.      */
  216.     public function getId()
  217.     {
  218.         return $this->id;
  219.     }
  220.     /**
  221.      * @return UserSchool
  222.      */
  223.     public function getSchool()
  224.     {
  225.         return $this->school;
  226.     }
  227.     /**
  228.      * @return string
  229.      */
  230.     public function getSnapchatId()
  231.     {
  232.         return $this->snapchatId;
  233.     }
  234.     /**
  235.      * @return string
  236.      */
  237.     public function getFacebookMessengerId()
  238.     {
  239.         return $this->facebookMessengerId;
  240.     }
  241.     /**
  242.      * @return string
  243.      */
  244.     public function getOtherEmail()
  245.     {
  246.         return $this->otherEmail;
  247.     }
  248.     /**
  249.      * @param string $snapchatId
  250.      * @return $this
  251.      */
  252.     public function setSnapchatId(string $snapchatId)
  253.     {
  254.         $this->snapchatId $snapchatId;
  255.         return $this;
  256.     }
  257.     /**
  258.      * @param string $facebookMessengerId
  259.      * @return $this
  260.      */
  261.     public function setFacebookMessengerId(string $facebookMessengerId)
  262.     {
  263.         $this->facebookMessengerId $facebookMessengerId;
  264.         return $this;
  265.     }
  266.     /**
  267.      * @param ?string $otherEmail
  268.      * @return $this
  269.      */
  270.     public function setOtherEmail(?string $otherEmail)
  271.     {
  272.         $this->otherEmail $otherEmail;
  273.         return $this;
  274.     }
  275.     /**
  276.      * @param UserSchool $school
  277.      * @return $this
  278.      */
  279.     public function setSchool($school)
  280.     {
  281.         $this->school $school;
  282.         return $this;
  283.     }
  284.     /**
  285.      * @return UserMajor
  286.      */
  287.     public function getMajor()
  288.     {
  289.         return $this->major;
  290.     }
  291.     /**
  292.      * @param UserMajor $major
  293.      * @return $this
  294.      */
  295.     public function setMajor($major)
  296.     {
  297.         $this->major $major;
  298.         return $this;
  299.     }
  300.     /**
  301.      * @return Address
  302.      */
  303.     public function getAddress()
  304.     {
  305.         return $this->address;
  306.     }
  307.     /**
  308.      * @param Address $address
  309.      * @return $this
  310.      */
  311.     public function setAddress($address)
  312.     {
  313.         $this->address $address;
  314.         return $this;
  315.     }
  316.     /**
  317.      * @return UserAvatar
  318.      */
  319.     public function getAvatar()
  320.     {
  321.         return $this->avatar;
  322.     }
  323.     /**
  324.      * @param UserAvatar $avatar
  325.      * @return $this
  326.      */
  327.     public function setAvatar($avatar)
  328.     {
  329.         $this->avatar $avatar;
  330.         return $this;
  331.     }
  332.     /**
  333.      * @return string
  334.      */
  335.     public function getEmail()
  336.     {
  337.         return $this->email;
  338.     }
  339.     /**
  340.      * @param string $email
  341.      * @return $this
  342.      */
  343.     public function setEmail($email)
  344.     {
  345.         $this->email $email;
  346.         if ($this->user) {
  347.             $this->user->syncFromProfile();
  348.         }
  349.         return $this;
  350.     }
  351.     /**
  352.      * @return string
  353.      */
  354.     public function getFirstName()
  355.     {
  356.         return $this->firstName;
  357.     }
  358.     /**
  359.      * @param string $firstName
  360.      * @return $this
  361.      */
  362.     public function setFirstName($firstName)
  363.     {
  364.         $this->firstName $firstName;
  365.         return $this;
  366.     }
  367.     /**
  368.      * @return string
  369.      */
  370.     public function getLastName()
  371.     {
  372.         return $this->lastName;
  373.     }
  374.     /**
  375.      * @param string $lastName
  376.      * @return $this
  377.      */
  378.     public function setLastName($lastName)
  379.     {
  380.         $this->lastName $lastName;
  381.         return $this;
  382.     }
  383.     /**
  384.      * @return int|null
  385.      */
  386.     public function getGradYear()
  387.     {
  388.         return $this->gradYear;
  389.     }
  390.     /**
  391.      * @param int|null $gradYear
  392.      * @return $this
  393.      */
  394.     public function setGradYear($gradYear)
  395.     {
  396.         $this->gradYear $gradYear;
  397.         return $this;
  398.     }
  399.     /**
  400.      * @return int|null
  401.      */
  402.     public function getfirstGen(): bool
  403.     {
  404.         return $this->firstGen;
  405.     }
  406.     /**
  407.      * @return int|null
  408.      */
  409.     public function getfirst_gen(): bool
  410.     {
  411.         return $this->firstGen;
  412.     }
  413.     /**
  414.      * @param int|null $firstGen
  415.      * @return $this
  416.      */
  417.     public function setfirstGen($firstGen)
  418.     {
  419.         $this->firstGen $firstGen 0;
  420.         return $this;
  421.     }
  422.     /**
  423.      * @param int|null $firstGen
  424.      * @return $this
  425.      */
  426.     public function setfirst_gen($firstGen)
  427.     {
  428.         $this->firstGen $firstGen 0;
  429.         return $this;
  430.     }
  431.     /**
  432.      * @return string|null
  433.      */
  434.     public function getStudentType(): string
  435.     {
  436.         return $this->studentType?$this->studentType:self::UNDERGRADUATE;
  437.     }
  438.     
  439.     /**
  440.      * @param string|null $studentType
  441.      * @return $this
  442.      */
  443.     public function setStudentType($studentType)
  444.     {
  445.         $this->studentType $studentType;
  446.         return $this;
  447.     }
  448.     
  449.     /**
  450.      * @return string
  451.      */
  452.     public function getPhone()
  453.     {
  454.         return $this->phone;
  455.     }
  456.     /**
  457.      * @param string $phone
  458.      * @return $this
  459.      */
  460.     public function setPhone($phone)
  461.     {
  462.         $this->phone $phone;
  463.         return $this;
  464.     }
  465.     /**
  466.      * @return string
  467.      */
  468.     public function getAboutText()
  469.     {
  470.         return $this->aboutText;
  471.     }
  472.     /**
  473.      * @param string $aboutText
  474.      * @return $this
  475.      */
  476.     public function setAboutText($aboutText)
  477.     {
  478.         $this->aboutText $aboutText;
  479.         return $this;
  480.     }
  481.     /**
  482.      * @return int
  483.      */
  484.     public function getVisible()
  485.     {
  486.         return $this->visible;
  487.     }
  488.     /**
  489.      * @return bool
  490.      */
  491.     public function isVisible()
  492.     {
  493.         return in_array($this->visible, [
  494.             self::VISIBILITY_ALL,
  495.             self::VISIBILITY_REGISTRED,
  496.             self::VISIBILITY_NON,
  497.         ]);
  498.     }
  499.     /**
  500.      * @return bool
  501.      */
  502.     public function isVisibleForAll()
  503.     {
  504.         return $this->visible == self::VISIBILITY_ALL;
  505.     }
  506.     /**
  507.      * @return bool
  508.      */
  509.     public function isVisibleForRegisteredOnly()
  510.     {
  511.         return $this->visible == self::VISIBILITY_REGISTRED;
  512.     }
  513.     /**
  514.      * @return bool
  515.      */
  516.     public function isInvisible()
  517.     {
  518.         return $this->visible == self::VISIBILITY_NON;
  519.     }
  520.     /**
  521.      * @param bool $visible
  522.      * @return $this
  523.      */
  524.     public function setVisible($visible)
  525.     {
  526.         $this->visible $visible;
  527.         return $this;
  528.     }
  529.     /**
  530.      * @return bool
  531.      */
  532.     public function isFacebook(): bool
  533.     {
  534.         return $this->facebook;
  535.     }
  536.     /**
  537.      * @param bool $facebook
  538.      * @return $this
  539.      */
  540.     public function setFacebook($facebook)
  541.     {
  542.         $this->facebook $facebook 0;
  543.         return $this;
  544.     }
  545.     /**
  546.      * @return bool
  547.      */
  548.     public function isTwitter(): bool
  549.     {
  550.         
  551.         return $this->twitter;
  552.     }
  553.     /**
  554.      * @param bool $twitter
  555.      * @return $this
  556.      */
  557.     public function setTwitter($twitter)
  558.     {
  559.         $this->twitter $twitter 0;
  560.         return $this;
  561.     }
  562.     /**
  563.      * @return string
  564.      */
  565.     public function getFullName()
  566.     {
  567.         return sprintf('%s %s'$this->firstName$this->lastName);
  568.     }
  569.     /**
  570.      * @return User
  571.      */
  572.     public function getUser()
  573.     {
  574.         return $this->user;
  575.     }
  576.     /**
  577.      * @param User $user
  578.      * @return $this
  579.      */
  580.     public function setUser(User $user)
  581.     {
  582.         $this->user $user;
  583.         return $this;
  584.     }
  585.     /**
  586.      * @return $this
  587.      */
  588.     public function syncFromUser()
  589.     {
  590.         if ($this->user) {
  591.             $this->email $this->user->getLogin();
  592.         }
  593.         return $this;
  594.     }
  595. }