235 lines
4.6 KiB
PHP
Raw Normal View History

2018-04-06 23:00:37 +02:00
<?php
declare(strict_types=1);
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use JsonSerializable;
/**
* @ORM\Entity
* @ORM\Table(name="teams")
*/
class Team implements JsonSerializable
{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
* @ORM\Column(name="id", type="integer")
* @var int
*/
private $id;
/**
* @ORM\Column(name="name", type="string", length=200, unique=true)
* @var string
*/
private $name;
/**
* @ORM\Column(name="members", type="json")
* @var array
*/
private $members;
/**
* @ORM\OneToMany(
* targetEntity="Slide",
* mappedBy="team",
* cascade={"persist", "remove"},
* orphanRemoval=true
* )
* @var Slide[]|Collection
*/
private $slides;
/**
* @ORM\Column(name="is_active", type="boolean")
* @var bool
*/
private $isActive;
/**
* @ORM\Column(name="created_at", type="datetime_immutable", nullable=true)
* @Gedmo\Timestampable(on="create")
* @var \DateTimeImmutable
*/
private $createdAt;
/**
* @ORM\Column(name="updated_at", type="datetime_immutable", nullable=true)
* @Gedmo\Timestampable(on="update")
* @var \DateTimeImmutable
*/
private $updatedAt;
public function __construct()
{
$this->slides = new ArrayCollection;
$this->members = new \ArrayObject;
}
/**
* @return int
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @param int $id
* @return Team
*/
public function setId(int $id): Team
{
$this->id = $id;
return $this;
}
/**
* @return string
*/
public function getName(): ?string
{
return $this->name;
}
/**
* @param string $name
* @return Team
*/
public function setName(string $name): Team
{
$this->name = $name;
return $this;
}
/**
* @return array
*/
public function getMembers()
{
return $this->members;
}
/**
* @param array $members
* @return Team
*/
public function setMembers(array $members): Team
{
$this->members = $members;
return $this;
}
/**
* @param Slide $slide
* @return Team
*/
public function addSlides(Slide $slide): Team
{
if (!$this->slides->contains($slide)) {
$this->slides->removeElement($slide);
}
return $this;
}
/**
* @return Slide[]|Collection
*/
public function getSlides(): ?Collection
{
return $this->slides;
}
/**
* @param Slide $slide
* @return Team
*/
public function removeSlide(Slide $slide): Team
{
if ($this->slides->contains($slide)) {
$this->slides->removeElement($slide);
}
return $this;
}
/**
* @return bool
*/
public function isActive(): ?bool
{
return $this->isActive;
}
/**
* @param bool $isActive
* @return Team
*/
public function setIsActive(bool $isActive): Team
{
$this->isActive = $isActive;
return $this;
}
/**
* @return \DateTimeImmutable
*/
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
/**
* @param \DateTimeImmutable $createdAt
* @return Team
*/
public function setCreatedAt(\DateTimeImmutable $createdAt): Team
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return \DateTimeImmutable
*/
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
/**
* @param \DateTimeImmutable $updatedAt
* @return Team
*/
public function setUpdatedAt(\DateTimeImmutable $updatedAt): Team
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return array
*/
public function jsonSerialize()
{
return [
'id' => $this->getId(),
'name' => $this->getName(),
'members' => $this->getMembers(),
'isActive' => $this->isActive(),
'createdAt' => $this->getCreatedAt()
? $this->getCreatedAt()->format("Y-m-d H:i:s")
: null,
'updatedAt' => $this->getUpdatedAt()
? $this->getUpdatedAt()->format("Y-m-d H:i:s")
: null,
];
}
}