src/Entity/User.php line 29

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by Mediterranean Develup Solutions.
  4.  * User: jorge.defreitas@develup.solutions
  5.  * Date: 14/06/2017
  6.  * Time: 16:51
  7.  */
  8. namespace App\Entity;
  9. use App\Entity\SettingsRol;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Component\Security\Core\User\UserInterface;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  17. /**
  18.  * User
  19.  *
  20.  * @ORM\Table(name="users")
  21.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  22.  * @UniqueEntity("username")
  23.  * @UniqueEntity("email")
  24.  * @ORM\HasLifecycleCallbacks()
  25.  */
  26. class User implements UserInterface
  27. {
  28.     /**
  29.      * @ORM\Id
  30.      * @ORM\GeneratedValue(strategy="AUTO")
  31.      * @ORM\Column(type="integer")
  32.      *
  33.      * @Groups({"assistant:read"})
  34.      */
  35.     private $id;
  36.     /**
  37.      * @ORM\Column(name="picture", type="string", length=255, nullable=true)
  38.      */
  39.     private $picture;
  40.     /**
  41.      * @ORM\Column(name="username", type="string", length=255, unique=true)
  42.      * @Assert\NotBlank()
  43.      *
  44.      * @Groups({"assistant:read"})
  45.      */
  46.     private $username;
  47.     /**
  48.      * @ORM\Column(name="email", type="string", length=255, unique=true)
  49.      * @Assert\NotBlank()
  50.      * @Assert\Email()
  51.      *
  52.      * @Groups({"assistant:read"})
  53.      */
  54.     private $email;
  55.     /**
  56.      * @ORM\Column(name="password", type="string", length=64)
  57.      */
  58.     private $password;
  59.     /**
  60.      * @ORM\Column(name="movil_password", type="string", length=255, nullable=true)
  61.      */
  62.     private $movilPassword;
  63.     /**
  64.      * @ORM\Column(name="pass_gmail", type="string", length=100, nullable=true)
  65.      */
  66.     private $passGmail;
  67.     /**
  68.      * @ORM\Column(name="firm_gmail", type="text", nullable=true)
  69.      */
  70.     private $firmGmail;
  71.     /**
  72.      * @ORM\Column(name="name", type="string", length=255)
  73.      * @Assert\NotBlank()
  74.      *
  75.      * @Groups({"assistant:read"})
  76.      */
  77.     private $name;
  78.     /**
  79.      * @ORM\Column(name="last_name", type="string", length=255)
  80.      * @Assert\NotBlank()
  81.      *
  82.      * @Groups({"assistant:read"})
  83.      */
  84.     private $lastname;
  85.     /**
  86.      * @ORM\Column(name="telephone", type="string", length=255, nullable=true)
  87.      */
  88.     private $telephone;
  89.     /**
  90.      * @ORM\Column(name="mobile", type="string", length=255, nullable=true)
  91.      */
  92.     private $mobile;
  93.     /**
  94.      * @ORM\Column(name="id_office", type="integer", length=11, nullable=true)
  95.      */
  96.     private $office;
  97.     /**
  98.      * @ORM\Column(name="status", type="boolean")
  99.      */
  100.     private $status;
  101.     /**
  102.      * @ORM\Column(name="id_company", type="integer", length=11, nullable=true)
  103.      */
  104.     private $company;
  105.     /**
  106.      * Relación ManyToOne con SettingsRol usando la misma columna id_user_rol.
  107.      *
  108.      * @ORM\ManyToOne(targetEntity=SettingsRol::class)
  109.      * @ORM\JoinColumn(name="id_user_rol", referencedColumnName="id", nullable=true)
  110.      */
  111.     private $settingsRol;
  112.     /**
  113.      * @ORM\Column(name="id_team", type="integer", length=11, nullable=true)
  114.      */
  115.     private $team;
  116.     /**
  117.      * @ORM\Column(name="team_leader", type="boolean", nullable=true)
  118.      */
  119.     private $teamleader;
  120.     /**
  121.      * @ORM\Column(name="role", type="string", length=50)
  122.      */
  123.     private $role;
  124.     /**
  125.      * @ORM\Column(type="string", length=255, nullable=true)
  126.      */
  127.     private $accessKey;
  128.     /**
  129.      * @var string
  130.      * @ORM\Column(name="language", type="string", length=11, nullable=true)
  131.      */
  132.     private $language;
  133.     /**
  134.      * @var string
  135.      * @ORM\Column(name="color", type="string", length=11, nullable=true)
  136.      */
  137.     private $color;
  138.     /**
  139.      * @ORM\Column(name="sidebar", type="boolean", nullable=true)
  140.      */
  141.     private $sidebar;
  142.     /**
  143.      * @var \Datetime
  144.      *
  145.      * @ORM\Column(name="created_at", type="datetime")
  146.      */
  147.     private $createdAt;
  148.     /**
  149.      * @var \Datetime
  150.      *
  151.      * @ORM\Column(name="updated_at", type="datetime")
  152.      */
  153.     private $updatedAt;
  154.     /**
  155.      * @ORM\Column(name="description", type="text", nullable=true)
  156.      */
  157.     private $description;
  158.     /**
  159.      * @var string
  160.      * @ORM\Column(name="job_title", type="string", length=255, nullable=true)
  161.      */
  162.     private $jobTitle;
  163.     /**
  164.      * @ORM\OneToMany(targetEntity=UserNotification::class, mappedBy="user", orphanRemoval=true)
  165.      */
  166.     private $userNotifications;
  167.     /**
  168.      * Nueva relación ManyToMany con ManteApp
  169.      *
  170.      * @ORM\ManyToMany(targetEntity=ManteApp::class)
  171.      * @ORM\JoinTable(name="user_mante_app")
  172.      */
  173.     private $apps;
  174.     public function __construct()
  175.     {
  176.         $this->userNotifications = new ArrayCollection();
  177.         $this->apps = new ArrayCollection();
  178.     }
  179.     public function getId()
  180.     {
  181.         return $this->id;
  182.     }
  183.     public function setId($id)
  184.     {
  185.         $this->id $id;
  186.     }
  187.     public function getEmail()
  188.     {
  189.         return $this->email;
  190.     }
  191.     public function setEmail($email)
  192.     {
  193.         $this->email $email;
  194.     }
  195.     public function getUsername()
  196.     {
  197.         return $this->username;
  198.     }
  199.     public function setUsername($username)
  200.     {
  201.         $this->username $username;
  202.     }
  203.     public function getPassword()
  204.     {
  205.         return $this->password;
  206.     }
  207.     public function setPassword($password)
  208.     {
  209.         $this->password $password;
  210.     }
  211.     public function getSalt()
  212.     {
  213.         // bcrypt no requiere salt separado.
  214.     }
  215.     public function eraseCredentials()
  216.     {
  217.     }
  218.     public function getRole()
  219.     {
  220.         return $this->role;
  221.     }
  222.     public function setRole($role null)
  223.     {
  224.         $this->role $role;
  225.     }
  226.     public function getRoles()
  227.     {
  228.         return [$this->getRole()];
  229.     }
  230.     public function getAccessKey()
  231.     {
  232.         return $this->accessKey;
  233.     }
  234.     public function setAccessKey($accessKey null)
  235.     {
  236.         $this->accessKey $accessKey;
  237.     }
  238.     /**
  239.      * Set createdAt
  240.      *
  241.      * @param \Datetime $createdAt
  242.      *
  243.      * @return User
  244.      */
  245.     public function setCreatedAt(\Datetime $createdAt)
  246.     {
  247.         $this->createdAt $createdAt;
  248.         return $this;
  249.     }
  250.     /**
  251.      * Get createdAt
  252.      *
  253.      * @return \Datetime
  254.      */
  255.     public function getCreatedAt()
  256.     {
  257.         return $this->createdAt;
  258.     }
  259.     /**
  260.      * Set updatedAt
  261.      *
  262.      * @param \Datetime $updatedAt
  263.      *
  264.      * @return User
  265.      */
  266.     public function setUpdatedAt(\Datetime $updatedAt)
  267.     {
  268.         $this->updatedAt $updatedAt;
  269.         return $this;
  270.     }
  271.     /**
  272.      * Get updatedAt
  273.      *
  274.      * @return \Datetime
  275.      */
  276.     public function getUpdatedAt()
  277.     {
  278.         return $this->updatedAt;
  279.     }
  280.     /**
  281.      * @ORM\PrePersist
  282.      */
  283.     public function setCreatedAtValue()
  284.     {
  285.         $this->createdAt = new \Datetime();
  286.     }
  287.     /**
  288.      * @ORM\PrePersist
  289.      * @ORM\PreUpdate
  290.      */
  291.     public function setUpdatedAtValue()
  292.     {
  293.         $this->updatedAt = new \Datetime();
  294.     }
  295.     public function setPicture($picture)
  296.     {
  297.         $this->picture $picture;
  298.         return $this;
  299.     }
  300.     public function getPicture()
  301.     {
  302.         return $this->picture;
  303.     }
  304.     public function setName($name)
  305.     {
  306.         $this->name $name;
  307.         return $this;
  308.     }
  309.     public function getName()
  310.     {
  311.         return $this->name;
  312.     }
  313.     public function setLastname($lastname)
  314.     {
  315.         $this->lastname $lastname;
  316.         return $this;
  317.     }
  318.     public function getLastname()
  319.     {
  320.         return $this->lastname;
  321.     }
  322.     public function setTelephone($telephone)
  323.     {
  324.         $this->telephone $telephone;
  325.         return $this;
  326.     }
  327.     public function getTelephone()
  328.     {
  329.         return $this->telephone;
  330.     }
  331.     public function setMobile($mobile)
  332.     {
  333.         $this->mobile $mobile;
  334.         return $this;
  335.     }
  336.     public function getMobile()
  337.     {
  338.         return $this->mobile;
  339.     }
  340.     public function setOffice($office)
  341.     {
  342.         $this->office $office;
  343.         return $this;
  344.     }
  345.     public function getOffice()
  346.     {
  347.         return $this->office;
  348.     }
  349.     public function setStatus($status)
  350.     {
  351.         $this->status $status;
  352.         return $this;
  353.     }
  354.     public function getStatus()
  355.     {
  356.         return $this->status;
  357.     }
  358.     public function setCompany($company)
  359.     {
  360.         $this->company $company;
  361.         return $this;
  362.     }
  363.     public function getCompany()
  364.     {
  365.         return $this->company;
  366.     }
  367.     /**
  368.      * Setter “antiguo” para el id de rol.
  369.      * No afecta a Doctrine.
  370.      */
  371.     public function setUserrol(?SettingsRol $userrol): self {
  372.         // CAMBIO: Antes decía $this->userrol, ahora $this->settingsRol
  373.         $this->settingsRol $userrol;
  374.         return $this;
  375.     }
  376.     /**
  377.      * Devuelve el id del SettingsRol si existe; si no, el valor crudo.
  378.      */
  379.     public function getUserrol(): ?SettingsRol {
  380.         // CAMBIO: Antes decía $this->userrol, ahora $this->settingsRol
  381.         return $this->settingsRol;
  382.     }
  383.     public function setTeam($team)
  384.     {
  385.         $this->team $team;
  386.         return $this;
  387.     }
  388.     public function getTeam()
  389.     {
  390.         return $this->team;
  391.     }
  392.     public function setTeamleader($teamleader)
  393.     {
  394.         $this->teamleader $teamleader;
  395.         return $this;
  396.     }
  397.     public function getTeamleader()
  398.     {
  399.         return $this->teamleader;
  400.     }
  401.     public function setLanguage($language)
  402.     {
  403.         $this->language $language;
  404.         return $this;
  405.     }
  406.     public function getLanguage()
  407.     {
  408.         return $this->language;
  409.     }
  410.     public function setPassGmail($passGmail)
  411.     {
  412.         $this->passGmail $passGmail;
  413.         return $this;
  414.     }
  415.     public function getPassGmail()
  416.     {
  417.         return $this->passGmail;
  418.     }
  419.     public function setFirmGmail($firmGmail)
  420.     {
  421.         $this->firmGmail $firmGmail;
  422.         return $this;
  423.     }
  424.     public function getFirmGmail()
  425.     {
  426.         return $this->firmGmail;
  427.     }
  428.     public function setColor($color)
  429.     {
  430.         $this->color $color;
  431.         return $this;
  432.     }
  433.     public function getColor()
  434.     {
  435.         return $this->color;
  436.     }
  437.     public function setSidebar($sidebar)
  438.     {
  439.         $this->sidebar $sidebar;
  440.         return $this;
  441.     }
  442.     public function getSidebar()
  443.     {
  444.         return $this->sidebar;
  445.     }
  446.     public function setDescription($description)
  447.     {
  448.         $this->description $description;
  449.         return $this;
  450.     }
  451.     public function getDescription()
  452.     {
  453.         return $this->description;
  454.     }
  455.     public function setJobTitle($jobTitle)
  456.     {
  457.         $this->jobTitle $jobTitle;
  458.         return $this;
  459.     }
  460.     public function getJobTitle()
  461.     {
  462.         return $this->jobTitle;
  463.     }
  464.     public function getFullName()
  465.     {
  466.         return $this->name ' ' $this->lastname;
  467.     }
  468.     public function setMovilPassword($movilPassword)
  469.     {
  470.         $this->movilPassword $movilPassword;
  471.         return $this;
  472.     }
  473.     public function getMovilPassword()
  474.     {
  475.         return $this->movilPassword;
  476.     }
  477.     /**
  478.      * Relación ManyToOne con SettingsRol
  479.      */
  480.     public function getSettingsRol(): ?SettingsRol
  481.     {
  482.         return $this->settingsRol;
  483.     }
  484.     public function setSettingsRol(?SettingsRol $settingsRol): self
  485.     {
  486.         $this->settingsRol $settingsRol;
  487.         return $this;
  488.     }
  489.     /**
  490.      * @return Collection<int, UserNotification>
  491.      */
  492.     public function getUserNotifications(): Collection
  493.     {
  494.         return $this->userNotifications;
  495.     }
  496.     public function addUserNotification(UserNotification $userNotification): self
  497.     {
  498.         if (!$this->userNotifications->contains($userNotification)) {
  499.             $this->userNotifications[] = $userNotification;
  500.             $userNotification->setUser($this);
  501.         }
  502.         return $this;
  503.     }
  504.     public function removeUserNotification(UserNotification $userNotification): self
  505.     {
  506.         if ($this->userNotifications->removeElement($userNotification)) {
  507.             if ($userNotification->getUser() === $this) {
  508.                 $userNotification->setUser(null);
  509.             }
  510.         }
  511.         return $this;
  512.     }
  513.     /**
  514.      * @return Collection|ManteApp[]
  515.      */
  516.     public function getApps(): Collection
  517.     {
  518.         return $this->apps;
  519.     }
  520.     public function addApp(ManteApp $app): self
  521.     {
  522.         if (!$this->apps->contains($app)) {
  523.             $this->apps[] = $app;
  524.         }
  525.         return $this;
  526.     }
  527.     public function removeApp(ManteApp $app): self
  528.     {
  529.         if ($this->apps->contains($app)) {
  530.             $this->apps->removeElement($app);
  531.         }
  532.         return $this;
  533.     }
  534. }