<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\PyramidHeadRepository")
*/
#[ApiResource(
attributes: ['security' => "is_granted('ROLE_USER')"],
normalizationContext: ['groups' => ['pyramidHead:read']],
denormalizationContext: ['groups' => ['pyramidHead:write']],
collectionOperations: [
'get',
'post' => [
'security' => "is_granted('ROLE_ADMIN')",
],
],
itemOperations: [
'get',
'put' => ['security' => "is_granted('ROLE_ADMIN') or object.owner == user"],
],
)]
class PyramidHead
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(name="name", type="string", length=100)
* @Assert\NotBlank()
* @Assert\Length(max="100")
* @Groups({"pyramidHead:read", "pyramidHead:write"})
*/
private $name;
/**
* @ORM\Column(type="boolean")
* @Assert\Type(type="boolean")
* @Groups({"pyramidHead:read", "pyramidHead:write"})
*/
private $isActive;
/**
* @var DateTime
*
* @ORM\Column(type="datetime", nullable=false)
*/
private $createdAt;
/**
* @var DateTime
*
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @var Collection
*
* @ORM\ManyToMany(targetEntity="App\Entity\Company", mappedBy="pyramidHeads")
* Ignore()
*/
private $companies;
public function __construct()
{
$this->isActive = true;
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
$this->companies = new ArrayCollection();
}
/**
* @return string
*/
public function __toString()
{
return $this->name;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getIsActive(): bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getCreatedAt(): ?DateTime
{
return $this->createdAt;
}
public function setCreatedAt(?DateTime $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?DateTime
{
return $this->updatedAt;
}
public function setUpdatedAt(?DateTime $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return Collection|Company[]
*/
public function getCompanies(): Collection
{
return $this->companies;
}
public function addCompany(Company $company): self
{
if (!$this->companies->contains($company)) {
$this->companies[] = $company;
}
return $this;
}
public function removeCompany(Company $company): self
{
if ($this->companies->contains($company)) {
$this->companies->removeElement($company);
}
return $this;
}
}