184 lines
3.3 KiB
PHP
184 lines
3.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Entity;
|
||
|
|
|
||
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
||
|
|
use Doctrine\ORM\Mapping as ORM;
|
||
|
|
use JsonSerializable;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @ORM\Entity
|
||
|
|
* @ORM\Table(name="user")
|
||
|
|
*/
|
||
|
|
class User implements JsonSerializable
|
||
|
|
{
|
||
|
|
use Traits\GetterSetter;
|
||
|
|
/**
|
||
|
|
* @ORM\Id
|
||
|
|
* @ORM\Column(name="id", type="integer")
|
||
|
|
* @ORM\GeneratedValue(strategy="IDENTITY")
|
||
|
|
* @var int
|
||
|
|
*/
|
||
|
|
private $id;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @ORM\Column(name="name", type="string", length=150)
|
||
|
|
* @var string
|
||
|
|
*/
|
||
|
|
private $name;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @ORM\Column(name="email", type="string", length=255)
|
||
|
|
* @var string
|
||
|
|
*/
|
||
|
|
private $email;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @ORM\OneToMany(targetEntity="Article", mappedBy="author")
|
||
|
|
* @ORM\JoinColumn(name="id", referencedColumnName="author_id", nullable=false)
|
||
|
|
* @var Article[]
|
||
|
|
*/
|
||
|
|
private $articles;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @ORM\OneToMany(targetEntity="Comment", mappedBy="author")
|
||
|
|
* @ORM\JoinColumn(name="id", referencedColumnName="author_id", nullable=false)
|
||
|
|
* @var Comment[]
|
||
|
|
*/
|
||
|
|
private $comments;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @ORM\Column(name="active", type="boolean")
|
||
|
|
* @var bool
|
||
|
|
*/
|
||
|
|
private $active = true;
|
||
|
|
|
||
|
|
public function __construct()
|
||
|
|
{
|
||
|
|
$this->articles = new ArrayCollection();
|
||
|
|
$this->comments = new ArrayCollection();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return int
|
||
|
|
*/
|
||
|
|
public function getId()
|
||
|
|
{
|
||
|
|
return $this->id;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return string
|
||
|
|
*/
|
||
|
|
public function getName()
|
||
|
|
{
|
||
|
|
return $this->name;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return string
|
||
|
|
*/
|
||
|
|
public function getEmail()
|
||
|
|
{
|
||
|
|
return $this->email;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return Article[]
|
||
|
|
*/
|
||
|
|
public function getArticles()
|
||
|
|
{
|
||
|
|
return $this->articles;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return Comment[]
|
||
|
|
*/
|
||
|
|
public function getComments()
|
||
|
|
{
|
||
|
|
return $this->comments;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return bool
|
||
|
|
*/
|
||
|
|
public function getActive()
|
||
|
|
{
|
||
|
|
return $this->active;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param int $id
|
||
|
|
* @return User
|
||
|
|
*/
|
||
|
|
public function setId(int $id)
|
||
|
|
{
|
||
|
|
$this->id = $id;
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param string $name
|
||
|
|
* @return User
|
||
|
|
*/
|
||
|
|
public function setName(string $name)
|
||
|
|
{
|
||
|
|
$this->name = $name;
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param string $email
|
||
|
|
* @return User
|
||
|
|
*/
|
||
|
|
public function setEmail(string $email)
|
||
|
|
{
|
||
|
|
$this->email = $email;
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param Article[] $articles
|
||
|
|
* @return User
|
||
|
|
*/
|
||
|
|
public function setArticles(array $articles)
|
||
|
|
{
|
||
|
|
$this->articles = $articles;
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param Comment[] $comments
|
||
|
|
* @return User
|
||
|
|
*/
|
||
|
|
public function setComments(array $comments)
|
||
|
|
{
|
||
|
|
$this->comments = $comments;
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @param bool $active
|
||
|
|
* @return User
|
||
|
|
*/
|
||
|
|
public function setActive(bool $active)
|
||
|
|
{
|
||
|
|
$this->active = $active;
|
||
|
|
return $this;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return array
|
||
|
|
*/
|
||
|
|
public function jsonSerialize()
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'id' => $this->id,
|
||
|
|
'name' => $this->name,
|
||
|
|
'email' => $this->email,
|
||
|
|
'articles' => $this->articles,
|
||
|
|
'comments' => $this->comments,
|
||
|
|
'active' => $this->active,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|