src/Entity/Users.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Event\PreUpdateEventArgs;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\Validator\Constraints as Assert;
  6. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. /**
  9.  * Users
  10.  *
  11.  * @ORM\Table(name="users", indexes={@ORM\Index(name="users_companies_fk", columns={"company_id"}), @ORM\Index(name="users_category_fk", columns={"category_id"}), @ORM\Index(name="users_created_fk", columns={"created_by"})})
  12.  * @ORM\Entity
  13.  * @ORM\HasLifecycleCallbacks
  14.  *
  15.  * @UniqueEntity(fields="mobileNumber", message="mobile number already taken")
  16.  * @UniqueEntity(fields="username", message="identification number is already exist")
  17.  * @ORM\Entity(repositoryClass="App\Entity\UsersRepository")
  18.  */
  19. class Users implements UserInterface, \Serializable
  20. {
  21.     /**
  22.      * @var string
  23.      *
  24.      * @ORM\Column(name="user_id", type="guid", length=36, nullable=false)
  25.      * @ORM\Id
  26.      * @ORM\GeneratedValue(strategy="UUID")
  27.      */
  28.     private $userId;
  29.     /**
  30.      * @var string
  31.      *
  32.      *
  33.      * @ORM\Column(name="username", type="string", length=50, nullable=true)
  34.      */
  35.     private $username;
  36.     /**
  37.      * @var string
  38.      *
  39.      * @ORM\Column(name="password", type="string", length=64, nullable=true)
  40.      */
  41.     private $password;
  42.     /**
  43.      * @var string
  44.      *
  45.      * @ORM\Column(name="telephone", type="string", length=20, nullable=true)
  46.      */
  47.     private $telephone;
  48.     /**
  49.      * @var array
  50.      *
  51.      * @ORM\Column(name="roles", type="array")
  52.      */
  53.     private $roles = array('ROLE_USER');
  54.     /**
  55.      * @var string
  56.      *
  57.      * @ORM\Column(name="mobile_number", type="string", length=20, nullable=true)
  58.      */
  59.     private $mobileNumber;
  60.     /**
  61.      * @var string
  62.      *
  63.      * @ORM\Column(name="mobile_number2", type="string", length=20, nullable=true)
  64.      */
  65.     private $mobileNumber2;
  66.     /**
  67.      * @var boolean
  68.      *
  69.      * @ORM\Column(name="is_mobile_number2_verified", type="boolean", nullable=false)
  70.      *
  71.      */
  72.     private $isMobileNumber2Verified ;
  73.     /**
  74.      * @var string
  75.      *
  76.      * @ORM\Column(name="email", type="string", length=50, nullable=true)
  77.      */
  78.     private $email;
  79.     /**
  80.      * @var boolean
  81.      *
  82.      * @ORM\Column(name="email_verified", type="boolean", nullable=false)
  83.      */
  84.     private $emailVerified 0;
  85.     /**
  86.      * @var string
  87.      *
  88.      * @ORM\Column(name="verify_token", type="string", length=100, nullable=true)
  89.      */
  90.     private $verify_token;
  91.     /**
  92.      * @var float
  93.      *
  94.      * @ORM\Column(name="balance", type="float", precision=10, scale=0, nullable=true)
  95.      */
  96.     private $balance;
  97.     /**
  98.      * @var float
  99.      *
  100.      * @ORM\Column(name="locked_ot_security", type="float", precision=10, scale=0, nullable=true)
  101.      */
  102.     private $lockedOtSecurity;
  103.     /**
  104.      * @var boolean
  105.      *
  106.      * @ORM\Column(name="is_verified", type="boolean", nullable=false)
  107.      */
  108.     private $isVerified 0;
  109.     /**
  110.      * @var boolean
  111.      *
  112.      * @ORM\Column(name="is_deleted", type="boolean", nullable=false)
  113.      */
  114.     private $isDeleted 0;
  115.     
  116.     /**
  117.      * @var boolean
  118.      *
  119.      * @ORM\Column(name="is_receive_sms", type="boolean", nullable=false)
  120.      */
  121.     private $isReceiveSms false;
  122.     /**
  123.      * @var \DateTime
  124.      *
  125.      * @ORM\Column(name="last_login", type="datetime", nullable=true)
  126.      */
  127.     private $lastLogin;
  128.     /**
  129.      * @var \DateTime
  130.      *
  131.      * @ORM\Column(name="created_at", type="datetime", nullable=true)
  132.      */
  133.     private $createdAt;
  134.     /**
  135.      * @var \DateTime
  136.      *
  137.      * @ORM\Column(name="updated_at", type="datetime", nullable=true)
  138.      */
  139.     private $updatedAt;
  140.     /**
  141.      * @var UsersCategories
  142.      *
  143.      * @ORM\ManyToOne(targetEntity="UsersCategories")
  144.      * @ORM\JoinColumns({
  145.      *   @ORM\JoinColumn(name="category_id", referencedColumnName="category_id")
  146.      * })
  147.      */
  148.     private $category;
  149.     /**
  150.      * @var Companies
  151.      *
  152.      * @ORM\ManyToOne(targetEntity="Companies")
  153.      * @ORM\JoinColumns({
  154.      *   @ORM\JoinColumn(name="company_id", referencedColumnName="company_id")
  155.      * })
  156.      */
  157.     private $company;
  158.     /**
  159.      * @var Users
  160.      *
  161.      * @ORM\ManyToOne(targetEntity="Users")
  162.      * @ORM\JoinColumns({
  163.      *   @ORM\JoinColumn(name="created_by", referencedColumnName="user_id")
  164.      * })
  165.      */
  166.     private $createdBy;
  167.     /**
  168.      * @var Users
  169.      *
  170.      * @ORM\ManyToOne(targetEntity="Users")
  171.      * @ORM\JoinColumns({
  172.      *   @ORM\JoinColumn(name="updated_by", referencedColumnName="user_id")
  173.      * })
  174.      */
  175.     private $updatedBy;
  176.     /**
  177.      * @var UserIdentityInfo
  178.      *
  179.      * @ORM\OneToOne(targetEntity="UserIdentityInfo", mappedBy="user", cascade={"persist"})
  180.      *@Assert\Valid
  181.      */
  182.     private $userIdentityInfo;
  183.     /**
  184.      * @var UserAdditionalDetails
  185.      *
  186.      * @ORM\OneToOne(targetEntity="UserAdditionalDetails", mappedBy="user", cascade={"persist"})
  187.      */
  188.     private $userAdditionalDetails;
  189.     /**
  190.      * @ORM\OneToMany(targetEntity="App\Entity\UserBankDetails", mappedBy="user")
  191.      */
  192.     private $bankAccounts;
  193.     /**
  194.      * @var string
  195.      *
  196.      * @ORM\Column(name="profile_origin", type="string", nullable=true, columnDefinition="enum('self registered','created','imported')")
  197.      */
  198.     private $profileOrigin;
  199.     /**
  200.      * @var string
  201.      *
  202.      * @ORM\Column(name="signature_path", type="string",  length=100, nullable=true)
  203.      */
  204.     private $signaturePath;
  205.     /**
  206.      * @var string
  207.      *
  208.      */
  209.     private $signatureWebPath;
  210.     /**
  211.      * Get id
  212.      *
  213.      * @return string
  214.      */
  215.     public function getId()
  216.     {
  217.         return $this->getUserId();
  218.     }
  219.     /**
  220.      * Set userId
  221.      *
  222.      * @param string $userId
  223.      *
  224.      * @return Users
  225.      */
  226.     public function setUserId($userId)
  227.     {
  228.         $this->userId $userId;
  229.         return $this;
  230.     }
  231.     /**
  232.      * Get userId
  233.      *
  234.      * @return string
  235.      */
  236.     public function getUserId()
  237.     {
  238.         return $this->userId;
  239.     }
  240.     /**
  241.      * Set username
  242.      *
  243.      * @param string $username
  244.      *
  245.      * @return Users
  246.      */
  247.     public function setUsername($username)
  248.     {
  249.         $this->username $username;
  250.         return $this;
  251.     }
  252.     /**
  253.      * Set password
  254.      *
  255.      * @param string $password
  256.      *
  257.      * @return Users
  258.      */
  259.     public function setPassword($password)
  260.     {
  261.         $this->password $password;
  262.         return $this;
  263.     }
  264.     /**
  265.      * Set telephone
  266.      *
  267.      * @param string $telephone
  268.      *
  269.      * @return Users
  270.      */
  271.     public function setTelephone($telephone)
  272.     {
  273.         $this->telephone $telephone;
  274.         return $this;
  275.     }
  276.     /**
  277.      * Get telephone
  278.      *
  279.      * @return string
  280.      */
  281.     public function getTelephone()
  282.     {
  283.         return $this->telephone;
  284.     }
  285.     /**
  286.      * Set mobileNumber
  287.      *
  288.      * @param string $mobileNumber
  289.      *
  290.      * @return Users
  291.      */
  292.     public function setMobileNumber($mobileNumber)
  293.     {
  294.         $this->mobileNumber $mobileNumber;
  295.         return $this;
  296.     }
  297.     /**
  298.      * Get mobileNumber
  299.      *
  300.      * @return string
  301.      */
  302.     public function getMobileNumber()
  303.     {
  304.         return $this->mobileNumber;
  305.     }
  306.     /**
  307.      * Set mobileNumber2
  308.      *
  309.      * @param string $mobileNumber2
  310.      *
  311.      * @return Users
  312.      */
  313.     public function setMobileNumber2($mobileNumber2)
  314.     {
  315.         $this->mobileNumber2 $mobileNumber2;
  316.         return $this;
  317.     }
  318.     /**
  319.      * Get mobileNumber2
  320.      *
  321.      * @return string
  322.      */
  323.     public function getMobileNumber2()
  324.     {
  325.         return $this->mobileNumber2;
  326.     }
  327.     /**
  328.      * @return bool
  329.      */
  330.     public function getIsMobileNumber2Verified()
  331.     {
  332.         return $this->isMobileNumber2Verified;
  333.     }
  334.     /**
  335.      * @param bool $isMobileNumber2Verified
  336.      */
  337.     public function setIsMobileNumber2Verified($isMobileNumber2Verified)
  338.     {
  339.         $this->isMobileNumber2Verified $isMobileNumber2Verified;
  340.     }
  341.     /**
  342.      * Set email
  343.      *
  344.      * @param string $email
  345.      *
  346.      * @return Users
  347.      */
  348.     public function setEmail($email)
  349.     {
  350.         $this->email $email;
  351.         return $this;
  352.     }
  353.     /**
  354.      * Get email
  355.      *
  356.      * @return string
  357.      */
  358.     public function getEmail()
  359.     {
  360.         return $this->email;
  361.     }
  362.     /**
  363.      * Set emailVerified
  364.      *
  365.      * @param boolean $emailVerified
  366.      *
  367.      * @return Users
  368.      */
  369.     public function setEmailVerified($emailVerified)
  370.     {
  371.         $this->emailVerified $emailVerified;
  372.         return $this;
  373.     }
  374.     /**
  375.      * Get emailVerified
  376.      *
  377.      * @return boolean
  378.      */
  379.     public function getEmailVerified()
  380.     {
  381.         return $this->emailVerified;
  382.     }
  383.     /**
  384.      * Set verify_token
  385.      *
  386.      * @param string $verify_token
  387.      *
  388.      * @return Users
  389.      */
  390.     public function setVerifyToken($verify_token)
  391.     {
  392.         $this->verify_token $verify_token;
  393.         return $this;
  394.     }
  395.     /**
  396.      * Get verify_token
  397.      *
  398.      * @return string
  399.      */
  400.     public function getVerifyToken()
  401.     {
  402.         return $this->verify_token;
  403.     }
  404.     /**
  405.      * Set balance
  406.      *
  407.      * @param float $balance
  408.      *
  409.      * @return Users
  410.      */
  411.     public function setBalance($balance)
  412.     {
  413.         $this->balance $balance;
  414.         return $this;
  415.     }
  416.     /**
  417.      * Get balance
  418.      *
  419.      * @return float
  420.      */
  421.     public function getBalance()
  422.     {
  423.         return $this->balance;
  424.     }
  425.     /**
  426.      * Set lockedOtSecurity
  427.      *
  428.      * @param float $lockedOtSecurity
  429.      *
  430.      * @return Users
  431.      */
  432.     public function setLockedOtSecurity($lockedOtSecurity)
  433.     {
  434.         $this->lockedOtSecurity $lockedOtSecurity;
  435.         return $this;
  436.     }
  437.     /**
  438.      * Get lockedOtSecurity
  439.      *
  440.      * @return float
  441.      */
  442.     public function getLockedOtSecurity()
  443.     {
  444.         return $this->lockedOtSecurity;
  445.     }
  446.     /**
  447.      * Set isVerified
  448.      *
  449.      * @param boolean $isVerified
  450.      *
  451.      * @return Users
  452.      */
  453.     public function setIsVerified($isVerified)
  454.     {
  455.         $this->isVerified $isVerified;
  456.         return $this;
  457.     }
  458.     /**
  459.      * Get isVerified
  460.      *
  461.      * @return boolean
  462.      */
  463.     public function getIsVerified()
  464.     {
  465.         return $this->isVerified;
  466.     }
  467.     /**
  468.      * Set isDeleted
  469.      *
  470.      * @param boolean $isDeleted
  471.      *
  472.      * @return Users
  473.      */
  474.     public function setIsDeleted($isDeleted)
  475.     {
  476.         $this->isDeleted $isDeleted;
  477.         return $this;
  478.     }
  479.     /**
  480.      * Get isDeleted
  481.      *
  482.      * @return boolean
  483.      */
  484.     public function getIsDeleted()
  485.     {
  486.         return $this->isDeleted;
  487.     }
  488.     
  489.     /**
  490.      * Set isReceiveSms
  491.      *
  492.      * @param boolean $isReceiveSms
  493.      *
  494.      * @return Users
  495.      */
  496.     public function setIsReceiveSms($isReceiveSms)
  497.     {
  498.         $this->isReceiveSms $isReceiveSms;
  499.         return $this;
  500.     }
  501.     /**
  502.      * Get isReceiveSms
  503.      *
  504.      * @return boolean
  505.      */
  506.     public function getIsReceiveSms()
  507.     {
  508.         return $this->isReceiveSms;
  509.     }
  510.     /**
  511.      * Set lastLogin
  512.      *
  513.      * @param \DateTime $lastLogin
  514.      *
  515.      * @return Users
  516.      */
  517.     public function setLastLogin($lastLogin)
  518.     {
  519.         $this->lastLogin $lastLogin;
  520.         return $this;
  521.     }
  522.     /**
  523.      * Get lastLogin
  524.      *
  525.      * @return \DateTime
  526.      */
  527.     public function getLastLogin()
  528.     {
  529.         return $this->lastLogin;
  530.     }
  531.     /**
  532.      * Set createdAt
  533.      *
  534.      * @param \DateTime $createdAt
  535.      *
  536.      * @return Users
  537.      */
  538.     public function setCreatedAt($createdAt)
  539.     {
  540.         $this->createdAt $createdAt;
  541.         return $this;
  542.     }
  543.     /**
  544.      * Get createdAt
  545.      *
  546.      * @return \DateTime
  547.      */
  548.     public function getCreatedAt()
  549.     {
  550.         return $this->createdAt;
  551.     }
  552.     /**
  553.      * Set updatedAt
  554.      *
  555.      * @param \DateTime $updatedAt
  556.      *
  557.      * @return Users
  558.      */
  559.     public function setUpdatedAt($updatedAt)
  560.     {
  561.         $this->updatedAt $updatedAt;
  562.         return $this;
  563.     }
  564.     /**
  565.      * Get updatedAt
  566.      *
  567.      * @return \DateTime
  568.      */
  569.     public function getUpdatedAt()
  570.     {
  571.         return $this->updatedAt;
  572.     }
  573.     /**
  574.      * Set category
  575.      *
  576.      * @param UsersCategories $category
  577.      *
  578.      * @return Users
  579.      */
  580.     public function setCategory(UsersCategories $category null)
  581.     {
  582.         $this->category $category;
  583.         return $this;
  584.     }
  585.     /**
  586.      * Get category
  587.      *
  588.      * @return UsersCategories
  589.      */
  590.     public function getCategory()
  591.     {
  592.         return $this->category;
  593.     }
  594.     /**
  595.      * Set company
  596.      *
  597.      * @param Companies $company
  598.      *
  599.      * @return Users
  600.      */
  601.     public function setCompany(Companies $company null)
  602.     {
  603.         $this->company $company;
  604.         return $this;
  605.     }
  606.     /**
  607.      * Get company
  608.      *
  609.      * @return Companies
  610.      */
  611.     public function getCompany()
  612.     {
  613.         return $this->company;
  614.     }
  615.     /**
  616.      * Set createdBy
  617.      *
  618.      * @param Users $createdBy
  619.      *
  620.      * @return Users
  621.      */
  622.     public function setCreatedBy(Users $createdBy null)
  623.     {
  624.         $this->createdBy $createdBy;
  625.         return $this;
  626.     }
  627.     /**
  628.      * Get createdBy
  629.      *
  630.      * @return Users
  631.      */
  632.     public function getCreatedBy()
  633.     {
  634.         return $this->createdBy;
  635.     }
  636.     /**
  637.      * @return string
  638.      */
  639.     public function getProfileOrigin()
  640.     {
  641.         return $this->profileOrigin;
  642.     }
  643.     /**
  644.      * @param string $profileOrigin
  645.      */
  646.     public function setProfileOrigin($profileOrigin)
  647.     {
  648.         $this->profileOrigin $profileOrigin;
  649.     }
  650.     /**
  651.      * Set updatedBy
  652.      *
  653.      * @param Users $updatedBy
  654.      *
  655.      * @return Users
  656.      */
  657.     public function setUpdatedBy(Users $updatedBy null)
  658.     {
  659.         $this->updatedBy $updatedBy;
  660.         return $this;
  661.     }
  662.     /**
  663.      * Get updatedBy
  664.      *
  665.      * @return Users
  666.      */
  667.     public function getUpdatedBy()
  668.     {
  669.         return $this->updatedBy;
  670.     }
  671.     /**
  672.      * Set userIdentityInfo
  673.      *
  674.      * @param UserIdentityInfo $userIdentityInfo
  675.      *
  676.      * @return Users
  677.      */
  678.     public function setUserIdentityInfo(UserIdentityInfo $userIdentityInfo null)
  679.     {
  680.         $this->userIdentityInfo $userIdentityInfo;
  681.         return $this;
  682.     }
  683.     /**
  684.      * Get userIdentityInfo
  685.      *
  686.      * @return UserIdentityInfo
  687.      */
  688.     public function getUserIdentityInfo()
  689.     {
  690.         return $this->userIdentityInfo;
  691.     }
  692.     /**
  693.      * Set userAdditionalDetails
  694.      *
  695.      * @param UserAdditionalDetails $userAdditionalDetails
  696.      *
  697.      * @return Users
  698.      */
  699.     public function setUserAdditionalDetails(UserAdditionalDetails $userAdditionalDetails null)
  700.     {
  701.         $this->userAdditionalDetails $userAdditionalDetails;
  702.         return $this;
  703.     }
  704.     /**
  705.      * Get userAdditionalDetails
  706.      *
  707.      * @return UserAdditionalDetails
  708.      */
  709.     public function getUserAdditionalDetails()
  710.     {
  711.         return $this->userAdditionalDetails;
  712.     }
  713.     /**
  714.      * @ORM\PrePersist
  715.      */
  716.     public function prePersist() {
  717.         if ($this->getCreatedAt() == null) {
  718.             $this->setCreatedAt(new \DateTime(date('Y-m-d H:i:s')));
  719.         }
  720.     }
  721.     /**
  722.      * @ORM\PreUpdate
  723.      *
  724.      * @param PreUpdateEventArgs $event
  725.      */
  726.     public function preUpdate(PreUpdateEventArgs $event) {
  727.         if (!$event->hasChangedField('last_login')) {
  728.             $this->setUpdatedAt(new \DateTime(date('Y-m-d H:i:s')));
  729.         }
  730.     }
  731.     /**
  732.      * @return string
  733.      */
  734.     public function getUsername()
  735.     {
  736.         return $this->username;
  737.     }
  738.     /**
  739.      * @return null|string
  740.      */
  741.     public function getSalt()
  742.     {
  743.         // you *may* need a real salt depending on your encoder
  744.         // see section on salt below
  745.         return null;
  746.     }
  747.     /**
  748.      * @return string
  749.      */
  750.     public function getPassword()
  751.     {
  752.         return $this->password;
  753.     }
  754.     /**
  755.      * @return array
  756.      */
  757.     public function getRoles()
  758.     {
  759.         return $this->roles != null $this->roles : array('ROLE_USER');
  760.     }
  761.     /**
  762.      *
  763.      */
  764.     public function eraseCredentials()
  765.     {}
  766.     /**
  767.      * @see \Serializable::serialize()
  768.      *
  769.      * @return string
  770.      */
  771.     public function serialize()
  772.     {
  773.         return serialize(array(
  774.             $this->userId,
  775.             $this->username,
  776.             $this->password,
  777.             // see section on salt below
  778.             // $this->salt,
  779.         ));
  780.     }
  781.     /**
  782.      * @see \Serializable::unserialize()
  783.      *
  784.      * @param string $serialized
  785.      */
  786.     public function unserialize($serialized)
  787.     {
  788.         list (
  789.             $this->userId,
  790.             $this->username,
  791.             $this->password,
  792.             // see section on salt below
  793.             // $this->salt
  794.             ) = unserialize($serialized);
  795.     }
  796.     /**
  797.      * Set roles
  798.      *
  799.      * @param array $roles
  800.      *
  801.      * @return Users
  802.      */
  803.     public function setRoles($roles)
  804.     {
  805.         $this->roles $roles;
  806.         return $this;
  807.     }
  808.     /**
  809.      * Get the entity class name
  810.      *
  811.      * @return string
  812.      * @throws \ReflectionException
  813.      */
  814.     public function getEntityName() {
  815.         return (new \ReflectionClass($this))->getShortName();
  816.     }
  817.     /**
  818.      * @return mixed
  819.      */
  820.     public function getUserBankDetails(){
  821.         return $this->bankAccounts;
  822.     }
  823.     /**
  824.      * @return string
  825.      */
  826.     public function getSignaturePath()
  827.     {
  828.         return $this->signaturePath;
  829.     }
  830.     /**
  831.      * @param string $signaturePath
  832.      */
  833.     public function setSignaturePath($signaturePath)
  834.     {
  835.         $this->signaturePath $signaturePath;
  836.     }
  837.     /**
  838.      * @return string
  839.      */
  840.     public function getSignatureWebPath()
  841.     {
  842.         return $this->signatureWebPath;
  843.     }
  844.     /**
  845.      * @param string $signatureWebPath
  846.      */
  847.     public function setSignatureWebPath($signatureWebPath)
  848.     {
  849.         $this->signatureWebPath $signatureWebPath;
  850.     }
  851.     /**
  852.      * This is to enable fetching user name via VehicleClient->getActualClient() without knowing if it was company or user
  853.      *
  854.      * @param string $locale
  855.      *
  856.      * @return string
  857.      */
  858.     public function getName($locale'ar')
  859.     {
  860.         if($locale == 'en'){
  861.             return $this->getUserIdentityInfo()->getFullNameEn(1);
  862.         }else{
  863.             return $this->getUserIdentityInfo()->getFullNameAr(1);
  864.         }
  865.     }
  866. }