Skip to content

Instantly share code, notes, and snippets.

@fjugaldev
Created April 14, 2020 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fjugaldev/2174620e062a0050c92fcfa2c790ee40 to your computer and use it in GitHub Desktop.
Save fjugaldev/2174620e062a0050c92fcfa2c790ee40 to your computer and use it in GitHub Desktop.
<?php
/**
* User.php
*
* User Entity
*
* @category Entity
* @package MyKanban
* @author Francisco Ugalde
* @copyright 2018 www.franciscougalde.com
* @license http://www.php.net/license/3_0.txt PHP License 3.0
*/
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use DateTime;
use Symfony\Component\Security\Core\User\UserInterface;
use JMS\Serializer\Annotation as Serializer;
/**
* User
*
* @ORM\Table(name="user");
* @ORM\Entity(repositoryClass="App\Repository\UserRepository");
* @ORM\HasLifecycleCallbacks()
*/
class User implements UserInterface
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id()
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="name", type="string", length=150)
*/
protected $name;
/**
* @ORM\Column(type="string", length=255, unique=true)
*/
protected $email;
/**
* @ORM\Column(name="username", type="string", length=255, unique=true)
*/
protected $username;
protected $salt;
/**
* @ORM\Column(name="password", type="string", length=255)
* @Serializer\Exclude()
*/
protected $password;
/**
* @var string
*/
protected $plainPassword;
/**
* @var array
*
* @ORM\Column(name="roles", type="json_array")
*/
protected $roles = [];
/**
* @ORM\Column(name="created_at", type="datetime")
*/
protected $createdAt;
/**
* @ORM\Column(name="updated_at", type="datetime")
*/
protected $updatedAt;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Board", mappedBy="user")
*/
protected $boards;
public function __construct()
{
$this->boards = new ArrayCollection();
}
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @param mixed $name
* @return self
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Set email
*
* @param string $email
*
* @return User
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* @return mixed
*/
public function getUsername()
{
return $this->username;
}
/**
* @param mixed $username
* @return self
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* @return mixed
*/
public function getPassword()
{
return $this->password;
}
/**
* @param mixed $password
* @return self
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* @return string
*/
public function getPlainPassword()
{
return $this->plainPassword;
}
/**
* @param $plainPassword
*/
public function setPlainPassword($plainPassword)
{
$this->plainPassword = $plainPassword;
$this->password = null;
}
/**
* Set roles
*
* @param array $roles
*
* @return User
*/
public function setRoles($roles)
{
$this->roles = $roles;
return $this;
}
/**
* Get roles
*
* @return array
*/
public function getRoles()
{
return ["ROLE_USER"];
}
public function getSalt() {}
public function eraseCredentials() {}
/**
* @return mixed
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* @param mixed $createdAt
* @return self
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return mixed
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* @param mixed $updatedAt
* @return self
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function updatedTimestamps()
{
$dateTimeNow = new DateTime('now');
$this->setUpdatedAt($dateTimeNow);
if ($this->getCreatedAt() === null) {
$this->setCreatedAt($dateTimeNow);
}
}
/**
* @return mixed
*/
public function getBoards()
{
return $this->boards->toArray();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment