<?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\Serializer\Annotation\Ignore;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\DeploymentTypeRepository")
* @ORM\HasLifecycleCallbacks()
*/
#[ApiResource(
attributes: ['security' => "is_granted('ROLE_USER')"],
normalizationContext: ['groups' => ['deployment_type:read']],
denormalizationContext: ['groups' => ['deployment_type:write']],
collectionOperations: [
'get',
'post' => [
'security' => "is_granted('ROLE_ADMIN')",
],
],
itemOperations: [
'get',
'put' => ['security' => "is_granted('ROLE_ADMIN') or object.owner == user"],
],
)]
class DeploymentType
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @Groups({"surveyComapany:read"})
*/
private $id;
/**
* @ORM\Column(type="name", type="string", length=100)
* @Assert\NotBlank()
* @Assert\Length(max="100")
* @Groups({"deployment_type:read", "deployment_type:write","surveyComapany:read"})
*/
private $name;
/**
* @var DateTime
*
* @ORM\Column(type="datetime", nullable=false)
*/
private $createdAt;
/**
* @var DateTime
*
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="App\Entity\SurveyCompany", mappedBy="deploymentType")
* @Ignore()
*/
public $surveyCompanies;
public function __construct()
{
$this->isActive = true;
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
$this->surveyCompanies = 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|SurveyCompany[]
*/
public function getSurveyCompanies(): Collection
{
return $this->surveyCompanies;
}
public function addSurveyCompany(SurveyCompany $surveycompany): self
{
if (!$this->surveyCompanies->contains($surveycompany)) {
$this->surveyCompanies[] = $surveycompany;
}
return $this;
}
public function removeSurveyCompany(SurveyCompany $surveycompany): self
{
if ($this->surveyCompanies->contains($surveycompany)) {
$this->surveyCompanies->removeElement($surveycompany);
}
return $this;
}
}