Guest User

Untitled

a guest
Oct 13th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.11 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Rodenas\AsistenciaBundle\Entity;
  4.  
  5. use Symfony\Component\Security\Core\User\UserInterface;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8.  
  9.  
  10. /**
  11.  * Rodenas\AsistenciaBundle\Entity\Profesor
  12.  *
  13.  * @ORM\Table()
  14.  * @ORM\Entity
  15.  */
  16. class Profesor implements UserInterface
  17. {
  18.     /**
  19.      * @var integer $id
  20.      *
  21.      * @ORM\Column(name="idProfesor", type="integer")
  22.      * @ORM\Id
  23.      * @ORM\GeneratedValue(strategy="AUTO")
  24.      */
  25.     private $id;
  26.  
  27.     /**
  28.      * @var string $nombre
  29.      *
  30.      * @ORM\Column(name="nombre", type="string", length=100)
  31.      */
  32.     private $nombre;
  33.  
  34.     /**
  35.      * @var string $apellidos
  36.      *
  37.      * @ORM\Column(name="apellidos", type="string", length=100)
  38.      */
  39.     private $apellidos;
  40.  
  41.     /**
  42.      * @var string $username
  43.      *
  44.      * @ORM\Column(name="username", type="string", length=16)
  45.      */
  46.     private $username;
  47.  
  48.     /**
  49.      * @var string $password
  50.      *
  51.      * @ORM\Column(name="password", type="string", length=255)
  52.      */
  53.     private $password;
  54.    
  55.     /**
  56.      * @var string $email
  57.      *
  58.      * @ORM\Column(name="email", type="string", length=255)
  59.      */
  60.     private $email;
  61.    
  62.     /**
  63.      * @var datetime $lastlogin
  64.      *
  65.      * @ORM\Column(name="lastlogin", type="datetime")
  66.      */
  67.     private $lastlogin;
  68.    
  69.     /**
  70.      * @var string $salt
  71.      *
  72.      * @ORM\Column(name="salt", type="string", length=255)
  73.      */
  74.     private $salt;
  75.    
  76.    
  77.     /**
  78.      * @ORM\ManyToMany(targetEntity="Roles", inversedBy="profesores")
  79.      * @ORM\JoinTable(name="profesor_rol",
  80.      *      joinColumns={@ORM\JoinColumn(name="idProfesor", referencedColumnName="idProfesor")},
  81.      *      inverseJoinColumns={@ORM\JoinColumn(name="idRol", referencedColumnName="idRol")}
  82.      *      )
  83.      */
  84.     protected $roles;
  85.    
  86.  
  87.     /**
  88.      * @ORM\OneToMany(targetEntity="Subgrupo", mappedBy="profesor")
  89.      */
  90.     protected $subgrupos;
  91.    
  92.    
  93.     /**
  94.      * @ORM\OneToMany(targetEntity="Incidencia", mappedBy="profesor")
  95.      */
  96.     protected $incidencias;
  97.    
  98.     /**
  99.      * @ORM\Column(name="is_active", type="boolean")
  100.      */
  101.     private $isActive;
  102.    
  103.    
  104.    
  105.  
  106.     public function __construct()
  107.     {  
  108.         $this->roles = new ArrayCollection();
  109.         $this->subgrupos = new ArrayCollection();
  110.         $this->incidencias = new ArrayCollection();
  111.         $this->salt = md5(uniqid(null, true));
  112.         $this->isActive = true;
  113.     }
  114.  
  115.     /**
  116.      * Get id
  117.      *
  118.      * @return integer
  119.      */
  120.     public function getId()
  121.     {
  122.         return $this->id;
  123.     }
  124.  
  125.     /**
  126.      * Set nombre
  127.      *
  128.      * @param string $nombre
  129.      */
  130.     public function setNombre($nombre)
  131.     {
  132.         $this->nombre = $nombre;
  133.     }
  134.  
  135.     /**
  136.      * Get nombre
  137.      *
  138.      * @return string
  139.      */
  140.     public function getNombre()
  141.     {
  142.         return $this->nombre;
  143.     }
  144.  
  145.     /**
  146.      * Set apellidos
  147.      *
  148.      * @param string $apellidos
  149.      */
  150.     public function setApellidos($apellidos)
  151.     {
  152.         $this->apellidos = $apellidos;
  153.     }
  154.  
  155.     /**
  156.      * Get apellidos
  157.      *
  158.      * @return string
  159.      */
  160.     public function getApellidos()
  161.     {
  162.         return $this->apellidos;
  163.     }
  164.  
  165.     /**
  166.      * Set usuario
  167.      *
  168.      * @param string $username
  169.      */
  170.     public function setUsername($username)
  171.     {
  172.         $this->username = $username;
  173.     }
  174.  
  175.     /**
  176.      * Get usuario
  177.      *
  178.      * @return string
  179.      */
  180.     public function getUsername()
  181.     {
  182.         return $this->username;
  183.     }
  184.  
  185.     /**
  186.      * Set password
  187.      *
  188.      * @param string $password
  189.      */
  190.     public function setPassword($password)
  191.     {
  192.         $this->password = $password;
  193.     }
  194.    
  195.  
  196.     /**
  197.      * Get password
  198.      *
  199.      * @return string
  200.      */
  201.     public function getPassword()
  202.     {
  203.         return $this->password;
  204.     }
  205.    
  206.    
  207.  
  208.     /**
  209.      * Get salt
  210.      *
  211.      * @return string
  212.      */
  213.     public function getSalt()
  214.     {
  215.         return $this->salt;
  216.     }
  217.  
  218.    
  219.  
  220.     /**
  221.      * Add subgrupos
  222.      *
  223.      * @param Rodenas\AsistenciaBundle\Entity\Subgrupo $subgrupos
  224.      */
  225.     public function addSubgrupo(\Rodenas\AsistenciaBundle\Entity\Subgrupo $subgrupos)
  226.     {
  227.         $this->subgrupos[] = $subgrupos;
  228.     }
  229.  
  230.     /**
  231.      * Get subgrupos
  232.      *
  233.      * @return Doctrine\Common\Collections\Collection
  234.      */
  235.     public function getSubgrupos()
  236.     {
  237.         return $this->subgrupos;
  238.     }
  239.  
  240.     /**
  241.      * Add incidencias
  242.      *
  243.      * @param Rodenas\AsistenciaBundle\Entity\Incidencia $incidencias
  244.      */
  245.     public function addIncidencia(\Rodenas\AsistenciaBundle\Entity\Incidencia $incidencias)
  246.     {
  247.         $this->incidencias[] = $incidencias;
  248.     }
  249.  
  250.     /**
  251.      * Get incidencias
  252.      *
  253.      * @return Doctrine\Common\Collections\Collection
  254.      */
  255.     public function getIncidencias()
  256.     {
  257.         return $this->incidencias;
  258.     }
  259.    
  260.  
  261.     public function equals(UserInterface $user) {
  262.        
  263.        
  264.         /*if (!$user instanceof Profesor) {
  265.             return false;
  266.         }
  267.  
  268.         if ($this->password != $user->getPassword()) {
  269.             return false;
  270.         }
  271.         if ($this->getSalt() != $user->getSalt()) {
  272.             return false;
  273.         }
  274.  
  275.         return true; */
  276.        
  277.         return $this->username === $user->getUsername();
  278.     }
  279.    
  280.  
  281.     public function eraseCredentials() {
  282.         $this->password = null;
  283.         return true;
  284.     }
  285.  
  286.  
  287.  
  288.     /**
  289.      * Set lastlogin
  290.      *
  291.      * @param datetime $lastlogin
  292.      */
  293.     public function setLastlogin($lastlogin)
  294.     {
  295.         $this->lastlogin = $lastlogin;
  296.     }
  297.  
  298.     /**
  299.      * Get lastlogin
  300.      *
  301.      * @return datetime
  302.      */
  303.     public function getLastlogin()
  304.     {
  305.         return $this->lastlogin;
  306.     }
  307.    
  308.    
  309.     /**
  310.     * Serializes the user.
  311.     *
  312.     * The serialized data have to contain the fields used by the equals method and the username.
  313.     *
  314.     * @return string
  315.     */
  316.     public function serialize()
  317.     {
  318.         return serialize(array(
  319.             $this->id,
  320.             $this->password,
  321.             $this->salt,
  322.             $this->username,
  323.         ));
  324.     }
  325.  
  326.     /**
  327.     * Unserializes the user.
  328.     *
  329.     * @param string $serialized
  330.     */
  331.     public function unserialize($serialized)
  332.     {
  333.         list(
  334.             $this->id,
  335.             $this->password,
  336.             $this->salt,
  337.             $this->username
  338.         ) = unserialize($serialized);
  339.     }
  340.  
  341.  
  342.  
  343.     /**
  344.      * Set email
  345.      *
  346.      * @param string $email
  347.      */
  348.     public function setEmail($email)
  349.     {
  350.         $this->email = $email;
  351.     }
  352.  
  353.     /**
  354.      * Get email
  355.      *
  356.      * @return string
  357.      */
  358.     public function getEmail()
  359.     {
  360.         return $this->email;
  361.     }
  362.  
  363.    
  364.     /**
  365.      * Add roles
  366.      *
  367.      * @param Rodenas\AsistenciaBundle\Entity\Roles $roles
  368.      */
  369.     public function addRoles(\Rodenas\AsistenciaBundle\Entity\Roles $roles)
  370.     {
  371.         $this->roles[] = $roles;
  372.     }
  373.    
  374.    
  375.     /**
  376.     * Sets the roles of the user.
  377.     *
  378.     * This overwrites any previous roles.
  379.     *
  380.     * @param array $roles
  381.     */
  382.     public function setRoles(array $roles)
  383.     {
  384.         $this->roles = array();
  385.  
  386.         foreach ($roles as $role) {
  387.             $this->addRoles($role);
  388.         }
  389.     }
  390.  
  391.     /**
  392.      * Get roles
  393.      *
  394.      * @return Doctrine\Common\Collections\Collection
  395.      */
  396.     public function getRoles()
  397.     {
  398.         //return $this->roles;
  399.         return array('ROLE_USER');
  400.     }
  401.  
  402.     /**
  403.      * Set salt
  404.      *
  405.      * @param string $salt
  406.      */
  407.     public function setSalt($salt)
  408.     {
  409.         $this->salt = $salt;
  410.     }
  411.  
  412.     /**
  413.      * Set isActive
  414.      *
  415.      * @param boolean $isActive
  416.      */
  417.     public function setIsActive($isActive)
  418.     {
  419.         $this->isActive = $isActive;
  420.     }
  421.  
  422.     /**
  423.      * Get isActive
  424.      *
  425.      * @return boolean
  426.      */
  427.     public function getIsActive()
  428.     {
  429.         return $this->isActive;
  430.     }
  431. }
Add Comment
Please, Sign In to add comment