src/Entity/User.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Component\Security\Core\User\UserInterface;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use App\Entity\Order;
  7. use Doctrine\Common\Collections\Criteria;
  8. use JMS\Serializer\Annotation\ExclusionPolicy;
  9. use JMS\Serializer\Annotation\Expose;
  10. use JMS\Serializer\Annotation\Groups;
  11. use JMS\Serializer\Annotation\VirtualProperty;
  12. use JMS\Serializer\Annotation\Accessor;
  13. /**
  14.  * App\Entity\User
  15.  *
  16.  * @ORM\Table(name="users")
  17.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  18.  * @ExclusionPolicy("all") 
  19.  */
  20. class User implements UserInterface\Serializable
  21. {
  22.     /**
  23.      * @ORM\Column(type="integer")
  24.      * @ORM\Id
  25.      * @ORM\GeneratedValue(strategy="AUTO")
  26.      * @Expose
  27.      * @Groups({"single","rest","apiv1"})
  28.      */
  29.     private $id;
  30.     /**
  31.      * @ORM\Column(type="string", length=25, unique=true)
  32.      * @Expose
  33.      * @Groups({"single","rest","apiv1"})
  34.      */
  35.     private $username;
  36.     
  37.     /**
  38.      * @ORM\Column(name="USERNAMEENCRIPTED", type="string", length=45)
  39.      */
  40.     private $usernameencripted;
  41.     
  42.     
  43.     
  44.     
  45.     /**
  46.      * @ORM\Column(type="string", length=64)
  47.      */
  48.     private $password;
  49.     /**
  50.      * @var string
  51.      *
  52.      * @ORM\Column( type="string", length=45, nullable=true)
  53.      * @Expose
  54.      * @Groups({"single","rest","apiv1"})
  55.      */
  56.     private $name;
  57.     
  58.     /**
  59.      * @var string
  60.      *
  61.      * @ORM\Column( type="string", length=45, nullable=true)
  62.      * @Expose
  63.      * @Groups({"single","rest","apiv1"})
  64.      */
  65.     private $lastname;
  66.     
  67.     
  68.     
  69.     /**
  70.      * @var string
  71.      *
  72.      * @ORM\Column(type="string", length=45, nullable=true)
  73.      */
  74.     private $cellphone;
  75.     
  76.     /**
  77.      * @var string
  78.      *
  79.      * @ORM\Column(type="string", length=45, nullable=true)
  80.      * @Expose
  81.      * @Groups({"single"})
  82.      */
  83.     private $phone;
  84.     
  85.       
  86.     
  87.     
  88.     /**
  89.      * @ORM\Column(type="string", length=60, unique=true)
  90.      * @Expose
  91.      * @Groups({"single","rest"})
  92.      */
  93.     private $email;
  94.     
  95.     
  96.     /**
  97.      * @var integer
  98.      *
  99.      * @ORM\Column(name="IDENTITYADMIN", type="integer", nullable=false)
  100.  
  101.      */
  102.     private $identityAdmin;
  103.     
  104.     /**
  105.      * @ORM\Column(name="is_active", type="boolean")
  106.      * @Expose
  107.      * @Groups({"single"})
  108.      */
  109.     private $isActive;
  110.     
  111.     
  112.  
  113.     public function __construct()
  114.     {
  115.         $this->userRoles = new  ArrayCollection();
  116.         $this->useraddress = new  ArrayCollection();
  117.         $this->userattributes = new ArrayCollection();
  118.         $this->isActive true;
  119.     }
  120.     /**
  121.      * @inheritDoc
  122.      */
  123.     public function getUsername()
  124.     {
  125.         return $this->username;
  126.     }
  127.     /**
  128.      * @inheritDoc
  129.      */
  130.     public function getSalt()
  131.     {
  132.         // you *may* need a real salt depending on your encoder
  133.         // see section on salt below
  134.         return null;
  135.     }
  136.     /**
  137.      * @inheritDoc
  138.      */
  139.     public function getPassword()
  140.     {
  141.         return $this->password;
  142.     }
  143.     
  144.     
  145.     
  146.     
  147.     /**
  148.      * @inheritDoc
  149.      */
  150.     public function eraseCredentials()
  151.     {
  152.     }
  153.     /**
  154.      * @see \Serializable::serialize()
  155.      */
  156.     public function serialize()
  157.     {
  158.         return serialize(array(
  159.                 $this->id,
  160.                 $this->username,
  161.                 $this->password,
  162.                 // see section on salt below
  163.                 // $this->salt,
  164.         ));
  165.     }
  166.     /**
  167.      * @see \Serializable::unserialize()
  168.      */
  169.     public function unserialize($serialized)
  170.     {
  171.         list (
  172.                 $this->id,
  173.                 $this->username,
  174.                 $this->password,
  175.                 // see section on salt below
  176.                 // $this->salt
  177.         ) = unserialize($serialized);
  178.     }
  179.     /**
  180.      * Get id
  181.      *
  182.      * @return integer 
  183.      */
  184.     public function getId()
  185.     {
  186.         return $this->id;
  187.     }
  188.     
  189.     
  190.     /**
  191.      * Get id
  192.      *
  193.      * @return integer
  194.      */
  195.     public function setId($id)
  196.     {
  197.          $this->id $id;
  198.         return $this;
  199.     }
  200.     
  201.     
  202.     /**
  203.      * Set username
  204.      *
  205.      * @param string $username
  206.      * @return User
  207.      */
  208.     public function setUsername($username)
  209.     {
  210.         $this->username $username;
  211.         return $this;
  212.     }
  213.     
  214.     
  215.     
  216.     
  217.     /**
  218.      * Set password
  219.      *
  220.      * @param string $password
  221.      * @return User
  222.      */
  223.     public function setPassword($password)
  224.     {
  225.         $this->password $password;
  226.         return $this;
  227.     }
  228.     
  229.     
  230.     /**
  231.      * Set name
  232.      *
  233.      * @param string $name
  234.      * @return Usuario
  235.      */
  236.     public function setName($name)
  237.     {
  238.         $this->name $name;
  239.     
  240.         return $this;
  241.     }
  242.     
  243.     /**
  244.      * Get name
  245.      *
  246.      * @return string
  247.      */
  248.     public function getName()
  249.     {
  250.         return $this->name;
  251.     }
  252.     
  253.     /**
  254.      * Set lastname
  255.      *
  256.      * @param string $lastname
  257.      * @return Usuario
  258.      */
  259.     public function setLastname($lastname)
  260.     {
  261.         $this->lastname $lastname;
  262.     
  263.         return $this;
  264.     }
  265.     
  266.     /**
  267.      * Get lastname
  268.      *
  269.      * @return string
  270.      */
  271.     public function getLastname()
  272.     {
  273.         return $this->lastname;
  274.     }
  275.     
  276.     /**
  277.      * Set cellphone
  278.      *
  279.      * @param string $cellphone
  280.      * @return Usuario
  281.      */
  282.     public function setCellphone($cellphone)
  283.     {
  284.         $this->cellphone $cellphone;
  285.     
  286.         return $this;
  287.     }
  288.     
  289.     /**
  290.      * Get cellphone
  291.      *
  292.      * @return string
  293.      */
  294.     public function getCellphone()
  295.     {
  296.         return $this->cellphone;
  297.     }
  298.     
  299.     /**
  300.      * Set phone
  301.      *
  302.      * @param string $phone
  303.      * @return Usuario
  304.      */
  305.     public function setPhone($phone)
  306.     {
  307.         $this->phone $phone;
  308.     
  309.         return $this;
  310.     }
  311.     
  312.     /**
  313.      * Get phone
  314.      *
  315.      * @return string
  316.      */
  317.     public function getPhone()
  318.     {
  319.         return $this->phone;
  320.     }
  321.     /**
  322.      * Set email
  323.      *
  324.      * @param string $email
  325.      * @return User
  326.      */
  327.     public function setEmail($email)
  328.     {
  329.         $this->email $email;
  330.         return $this;
  331.     }
  332.     /**
  333.      * Get email
  334.      *
  335.      * @return string 
  336.      */
  337.     public function getEmail()
  338.     {
  339.         return $this->email;
  340.     }
  341.     /**
  342.      * Set isActive
  343.      *
  344.      * @param boolean $isActive
  345.      * @return User
  346.      */
  347.     public function setIsActive($isActive)
  348.     {
  349.         $this->isActive $isActive;
  350.         return $this;
  351.     }
  352.     /**
  353.      * Get isActive
  354.      *
  355.      * @return boolean 
  356.      */
  357.     public function getIsActive()
  358.     {
  359.         return $this->isActive;
  360.     }
  361.     
  362.     
  363.     
  364.    /**
  365.      * Get the formatted name to display (NAME Firstname or username)
  366.      * 
  367.      * @param $separator: the separator between name and firstname (default: ' ')
  368.      * @return String
  369.      * @VirtualProperty 
  370.      * @Groups({"single","rest","apiv1"})
  371.     */
  372.     public function getNameComplete()
  373.     {
  374.         return $this->name '  ' .  $this->lastname ;
  375.     }
  376.     
  377.     
  378.     
  379.     
  380.     
  381.     
  382.     
  383.     
  384.     //-------------------------RELACIONES-------------------------------------------------//
  385.     
  386.     
  387.     
  388.     /**
  389.      * @ORM\OneToMany(targetEntity="UserRole", mappedBy="user", cascade={"all"})
  390.      */
  391.     private $userRoles;
  392.      
  393.       
  394.     public function getRoles()
  395.     {
  396.     
  397.         $roles = array();
  398.         foreach ($this->userRoles as $userRole) {
  399.             $roles[] = $userRole->getRole();
  400.         }
  401.         return $roles;
  402.     }
  403.     
  404.     
  405.     
  406.  
  407.     /**
  408.      * @inheritDoc
  409.      */
  410.     public function addUserRole(\App\Entity\UserRole $userrole)
  411.     {
  412.         $this->userRoles[] = $userrole;
  413.     
  414.         return $this;
  415.       
  416.     }
  417.       
  418.     /**
  419.      * Remove userRoles
  420.      *
  421.      * @param \App\Entity\UserRole $userRoles
  422.      */
  423.     public function removeUserRole(\App\Entity\UserRole $userRoles)
  424.     {
  425.         $this->userRoles->removeElement($userRoles);
  426.     }
  427.     /**
  428.      * Get userRoles
  429.      *
  430.      * @return \Doctrine\Common\Collections\Collection 
  431.      */
  432.     public function getUserRoles()
  433.     {
  434.         return $this->userRoles;
  435.     }
  436.     
  437.     
  438.      
  439.     
  440.     /**
  441.      * @ORM\OneToMany(targetEntity="Useraddress", mappedBy="user", cascade={"all"})
  442.      * @Expose
  443.      * @Groups({"rest","apiv1"})
  444.       * @Accessor(getter="getUserAddresactives")
  445.      * @ORM\OrderBy({"iduseraddress" = "DESC"})
  446.      */
  447.     private $useraddress;
  448.     
  449.     /**
  450.      * @ORM\OneToMany(targetEntity="Userattributes", mappedBy="user", cascade={"all"})
  451.      */
  452.     private $userattributes;
  453.      
  454.     public function getUserattributes()
  455.     {
  456.         return $this->userattributes;
  457.     }
  458.     public function getUserattributesbyname($name)
  459.     {
  460.        $criteria Criteria::create()->where(Criteria::expr()->eq("attributename"$name));
  461.        return $this->userattributes->matching($criteria);
  462.      }
  463.      
  464.     public function setUserattributes($userattributes)
  465.     {
  466.         $this->userattributes $userattributes;
  467.         return $this;
  468.     }
  469.     /**
  470.      * Add useraddress
  471.      *
  472.      * @param \App\Entity\Useraddress $useraddress
  473.      * @return User
  474.      */
  475.     public function addUserAddress($useraddress)
  476.     {
  477.         $this->useraddress[] = $useraddress;
  478.         return $this;
  479.     }
  480.     /**
  481.      * Remove useraddress
  482.      *
  483.      * @param \App\Entity\Useraddress $useraddress
  484.      */
  485.     public function removeUserAddress$useraddress)
  486.     {
  487.         $this->useraddress->removeElement($useraddress);
  488.     }
  489.     /**
  490.      * Get useraddress
  491.      *
  492.      * @return \Doctrine\Common\Collections\Collection 
  493.      */
  494.     public function getUserAddress()
  495.     { 
  496.          return $this->useraddress;
  497.     }
  498.     
  499.     
  500.     public function getUserAddresactives()
  501.     {
  502.         $criteria Criteria::create()->where(Criteria::expr()->eq("active"true));
  503.         return $this->useraddress->matching($criteria);
  504.          
  505.     }
  506.     
  507.     
  508.     
  509.     
  510.     public function setUserAddress($useraddress)
  511.     {
  512.         $criteria Criteria::create()->where(Criteria::expr()->eq("active"true));
  513.          
  514.         $this->useraddress $this->useraddress->matching($criteria);
  515.     
  516.         return $this;
  517.     }
  518.     
  519.     
  520.     
  521.     /**
  522.      * @ORM\OneToMany(targetEntity="App\Entity\Order", mappedBy="user", cascade={"all"})
  523.      */
  524.     private $userOrders;
  525.     
  526.       
  527.      
  528.  
  529.     public function addUserOrders(Order $userOrders)
  530.     {
  531.         $this->userOrders[] = $userOrders;
  532.         return $this;
  533.     }
  534.    
  535.     public function removeUserOrders(Order $userOrders)
  536.     {
  537.         $this->userOrders->removeElement($userOrders);
  538.     }
  539.      
  540.     public function getUserOrders()
  541.     {
  542.         return $this->userOrders;
  543.     }
  544.     
  545.     
  546.     
  547.      
  548.     /** @ORM\Column(name="SOCIALID", type="string", length=255, nullable=true) */
  549.     protected $social_id;
  550.     
  551.     
  552.     
  553.     
  554.     /** @ORM\Column(name="SOCIALACCESSTOKEN", type="string", length=255, nullable=true) */
  555.     protected $social_access_token;
  556.     
  557.  
  558.     
  559.     public function getTypelogin() {
  560.         return $this->typelogin;
  561.     }
  562.     public function setTypelogin($typelogin) {
  563.         $this->typelogin $typelogin;
  564.         return $this;
  565.     }
  566.     public function getSocialId() {
  567.         return $this->social_id;
  568.     }
  569.     public function setSocialId($social_id) {
  570.         $this->social_id $social_id;
  571.         return $this;
  572.     }
  573.     public function getSocialAccessToken() {
  574.         return $this->social_access_token;
  575.     }
  576.     public function setSocialAccessToken($social_access_token) {
  577.         $this->social_access_token $social_access_token;
  578.         return $this;
  579.     }
  580.     
  581.     
  582.     public function getIdentityAdmin() {
  583.         return $this->identityAdmin;
  584.     }
  585.     public function setIdentityAdmin($identityAdmin) {
  586.         $this->identityAdmin $identityAdmin;
  587.         return $this;
  588.     }
  589.     
  590.     
  591.     /**
  592.      * @var boolean
  593.      *
  594.      * @ORM\Column(name="NOTIFICATIONEMAIL", type="boolean", nullable=true)
  595.      */
  596.     private $notificationemail;
  597.     
  598.     
  599.     /**
  600.      * @var boolean
  601.      *
  602.      * @ORM\Column(name="NOTIFICATIONMOBILE", type="boolean", nullable=true)
  603.      */
  604.     private $notificationmobile;
  605.     
  606.     
  607.      /** @ORM\Column(name="MOBILETOKEN", type="string", length=100, nullable=true) */
  608.     private $mobiletoken;
  609.     
  610.     
  611.     public function getNotificationemail() {
  612.         return $this->notificationemail;
  613.     }
  614.     public function setNotificationemail($notificationemail) {
  615.         $this->notificationemail $notificationemail;
  616.         return $this;
  617.     }
  618.     public function getNotificationmobile() {
  619.         return $this->notificationmobile;
  620.     }
  621.     public function setNotificationmobile($notificationmobile) {
  622.         $this->notificationmobile $notificationmobile;
  623.         return $this;
  624.     }
  625.     public function getMobiletoken() {
  626.         return $this->mobiletoken;
  627.     }
  628.     public function setMobiletoken($mobiletoken) {
  629.         $this->mobiletoken $mobiletoken;
  630.         return $this;
  631.     }
  632.     
  633.     
  634.     /**
  635.      * @var \DateTime
  636.      *
  637.      * @ORM\Column(name="INSERTDATE", type="datetime", nullable=true)
  638.      */
  639.     private $insertdate;
  640.     
  641.     
  642.     public function getInsertdate() {
  643.         return $this->insertdate;
  644.     }
  645.     public function setInsertdate(\DateTime $insertdate) {
  646.         $this->insertdate $insertdate;
  647.         return $this;
  648.     }
  649.     public function getUsernameencripted() {
  650.         return $this->usernameencripted;
  651.     }
  652.     public function setUsernameencripted($usernameencripted) {
  653.         $this->usernameencripted $usernameencripted;
  654.         return $this;
  655.     }
  656.     
  657.     
  658.     /**
  659.      * @ORM\ManyToOne(targetEntity="App\Entity\Usertypelogin", inversedBy="usertypeslogin", cascade={"all"})
  660.      *       @ORM\JoinColumns({
  661.      *   @ORM\JoinColumn(name="IDUSERTYPELOGIN", referencedColumnName="IDUSERTYPELOGIN")
  662.      * })
  663.      * @Expose
  664.      * @Groups({"rest"})
  665.      */
  666.     private $typelogin;
  667.     
  668.     
  669.         /**
  670.      * @var \Country
  671.      *
  672.      * @ORM\ManyToOne(targetEntity="Country")
  673.      * @ORM\JoinColumns({
  674.      *   @ORM\JoinColumn(name="IDCOUNTRY", referencedColumnName="idcountry")
  675.      * })
  676.      * @Expose
  677.      * @Groups({"single","rest","apiv1"})
  678.      */
  679.     private $country;
  680.     
  681.     
  682.     /**
  683.      * Add userOrder.
  684.      *
  685.      * @param \App\Entity\Order $userOrder
  686.      *
  687.      * @return User
  688.      */
  689.     public function addUserOrder(\App\Entity\Order $userOrder)
  690.     {
  691.         $this->userOrders[] = $userOrder;
  692.     
  693.         return $this;
  694.     }
  695.     /**
  696.      * Remove userOrder.
  697.      *
  698.      * @param \App\Entity\Order $userOrder
  699.      *
  700.      * @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
  701.      */
  702.     public function removeUserOrder(\App\Entity\Order $userOrder)
  703.     {
  704.         return $this->userOrders->removeElement($userOrder);
  705.     }
  706.     public function getCountry()
  707.     {
  708.         return $this->country;
  709.     }
  710.     
  711.     public function setCountry($country)
  712.     {
  713.         $this->country $country;
  714.         return $this;
  715.     }
  716.      /**
  717.      * A visual identifier that represents this user.
  718.      *
  719.      * @see UserInterface
  720.      */
  721.     public function getUserIdentifier(): string
  722.     {
  723.         return (string) $this->username;
  724.     }
  725. }