Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Rodenas\AsistenciaBundle\Entity;
- use Symfony\Component\Security\Core\User\UserInterface;
- use Doctrine\ORM\Mapping as ORM;
- use Doctrine\Common\Collections\ArrayCollection;
- /**
- * Rodenas\AsistenciaBundle\Entity\Profesor
- *
- * @ORM\Table()
- * @ORM\Entity
- */
- class Profesor implements UserInterface
- {
- /**
- * @var integer $id
- *
- * @ORM\Column(name="idProfesor", type="integer")
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @var string $nombre
- *
- * @ORM\Column(name="nombre", type="string", length=100)
- */
- private $nombre;
- /**
- * @var string $apellidos
- *
- * @ORM\Column(name="apellidos", type="string", length=100)
- */
- private $apellidos;
- /**
- * @var string $username
- *
- * @ORM\Column(name="username", type="string", length=16)
- */
- private $username;
- /**
- * @var string $password
- *
- * @ORM\Column(name="password", type="string", length=255)
- */
- private $password;
- /**
- * @var string $email
- *
- * @ORM\Column(name="email", type="string", length=255)
- */
- private $email;
- /**
- * @var datetime $lastlogin
- *
- * @ORM\Column(name="lastlogin", type="datetime")
- */
- private $lastlogin;
- /**
- * @var string $salt
- *
- * @ORM\Column(name="salt", type="string", length=255)
- */
- private $salt;
- /**
- * @ORM\ManyToMany(targetEntity="Roles", inversedBy="profesores")
- * @ORM\JoinTable(name="profesor_rol",
- * joinColumns={@ORM\JoinColumn(name="idProfesor", referencedColumnName="idProfesor")},
- * inverseJoinColumns={@ORM\JoinColumn(name="idRol", referencedColumnName="idRol")}
- * )
- */
- protected $roles;
- /**
- * @ORM\OneToMany(targetEntity="Subgrupo", mappedBy="profesor")
- */
- protected $subgrupos;
- /**
- * @ORM\OneToMany(targetEntity="Incidencia", mappedBy="profesor")
- */
- protected $incidencias;
- /**
- * @ORM\Column(name="is_active", type="boolean")
- */
- private $isActive;
- public function __construct()
- {
- $this->roles = new ArrayCollection();
- $this->subgrupos = new ArrayCollection();
- $this->incidencias = new ArrayCollection();
- $this->salt = md5(uniqid(null, true));
- $this->isActive = true;
- }
- /**
- * Get id
- *
- * @return integer
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * Set nombre
- *
- * @param string $nombre
- */
- public function setNombre($nombre)
- {
- $this->nombre = $nombre;
- }
- /**
- * Get nombre
- *
- * @return string
- */
- public function getNombre()
- {
- return $this->nombre;
- }
- /**
- * Set apellidos
- *
- * @param string $apellidos
- */
- public function setApellidos($apellidos)
- {
- $this->apellidos = $apellidos;
- }
- /**
- * Get apellidos
- *
- * @return string
- */
- public function getApellidos()
- {
- return $this->apellidos;
- }
- /**
- * Set usuario
- *
- * @param string $username
- */
- public function setUsername($username)
- {
- $this->username = $username;
- }
- /**
- * Get usuario
- *
- * @return string
- */
- public function getUsername()
- {
- return $this->username;
- }
- /**
- * Set password
- *
- * @param string $password
- */
- public function setPassword($password)
- {
- $this->password = $password;
- }
- /**
- * Get password
- *
- * @return string
- */
- public function getPassword()
- {
- return $this->password;
- }
- /**
- * Get salt
- *
- * @return string
- */
- public function getSalt()
- {
- return $this->salt;
- }
- /**
- * Add subgrupos
- *
- * @param Rodenas\AsistenciaBundle\Entity\Subgrupo $subgrupos
- */
- public function addSubgrupo(\Rodenas\AsistenciaBundle\Entity\Subgrupo $subgrupos)
- {
- $this->subgrupos[] = $subgrupos;
- }
- /**
- * Get subgrupos
- *
- * @return Doctrine\Common\Collections\Collection
- */
- public function getSubgrupos()
- {
- return $this->subgrupos;
- }
- /**
- * Add incidencias
- *
- * @param Rodenas\AsistenciaBundle\Entity\Incidencia $incidencias
- */
- public function addIncidencia(\Rodenas\AsistenciaBundle\Entity\Incidencia $incidencias)
- {
- $this->incidencias[] = $incidencias;
- }
- /**
- * Get incidencias
- *
- * @return Doctrine\Common\Collections\Collection
- */
- public function getIncidencias()
- {
- return $this->incidencias;
- }
- public function equals(UserInterface $user) {
- /*if (!$user instanceof Profesor) {
- return false;
- }
- if ($this->password != $user->getPassword()) {
- return false;
- }
- if ($this->getSalt() != $user->getSalt()) {
- return false;
- }
- return true; */
- return $this->username === $user->getUsername();
- }
- public function eraseCredentials() {
- $this->password = null;
- return true;
- }
- /**
- * Set lastlogin
- *
- * @param datetime $lastlogin
- */
- public function setLastlogin($lastlogin)
- {
- $this->lastlogin = $lastlogin;
- }
- /**
- * Get lastlogin
- *
- * @return datetime
- */
- public function getLastlogin()
- {
- return $this->lastlogin;
- }
- /**
- * Serializes the user.
- *
- * The serialized data have to contain the fields used by the equals method and the username.
- *
- * @return string
- */
- public function serialize()
- {
- return serialize(array(
- $this->id,
- $this->password,
- $this->salt,
- $this->username,
- ));
- }
- /**
- * Unserializes the user.
- *
- * @param string $serialized
- */
- public function unserialize($serialized)
- {
- list(
- $this->id,
- $this->password,
- $this->salt,
- $this->username
- ) = unserialize($serialized);
- }
- /**
- * Set email
- *
- * @param string $email
- */
- public function setEmail($email)
- {
- $this->email = $email;
- }
- /**
- * Get email
- *
- * @return string
- */
- public function getEmail()
- {
- return $this->email;
- }
- /**
- * Add roles
- *
- * @param Rodenas\AsistenciaBundle\Entity\Roles $roles
- */
- public function addRoles(\Rodenas\AsistenciaBundle\Entity\Roles $roles)
- {
- $this->roles[] = $roles;
- }
- /**
- * Sets the roles of the user.
- *
- * This overwrites any previous roles.
- *
- * @param array $roles
- */
- public function setRoles(array $roles)
- {
- $this->roles = array();
- foreach ($roles as $role) {
- $this->addRoles($role);
- }
- }
- /**
- * Get roles
- *
- * @return Doctrine\Common\Collections\Collection
- */
- public function getRoles()
- {
- //return $this->roles;
- return array('ROLE_USER');
- }
- /**
- * Set salt
- *
- * @param string $salt
- */
- public function setSalt($salt)
- {
- $this->salt = $salt;
- }
- /**
- * Set isActive
- *
- * @param boolean $isActive
- */
- public function setIsActive($isActive)
- {
- $this->isActive = $isActive;
- }
- /**
- * Get isActive
- *
- * @return boolean
- */
- public function getIsActive()
- {
- return $this->isActive;
- }
- }
Add Comment
Please, Sign In to add comment