<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\CompanyFormPageRepository")
*/
#[ApiResource(
attributes: ['security' => "is_granted('ROLE_USER')"],
normalizationContext: ['groups' => ['companyForm:read']],
denormalizationContext: ['groups' => ['companyForm:write']],
collectionOperations: [
'get',
'post' => [
'security' => "is_granted('ROLE_ADMIN')",
],
],
itemOperations: [
'get',
'put' => ['security' => "is_granted('ROLE_ADMIN') or object.owner == user"],
],
)]
class CompanyFormPage
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @var string
*
* @ORM\Column(type="string", length=128)
* @Assert\Length(max="128")
* @Assert\NotBlank()
* @Groups({"companyForm:read", "companyForm:write"})
*/
private $label;
/**
* @var string
*
* @ORM\Column(type="string", length=128)
* @Gedmo\Slug(fields={"label"})
* @Groups({"companyForm:read", "companyForm:write"})
*/
private $slug;
/**
* @var int
*
* @ORM\Column(type="integer")
* @Assert\NotBlank()
* @Assert\Type(type="integer")
* @Groups({"companyForm:read", "companyForm:write"})
*/
private $position;
/**
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="App\Entity\CompanyFormGroup", mappedBy="formPage", cascade={"persist"})
*/
private $formGroups;
/**
* @ORM\Column(type="boolean")
* @Assert\Type("bool")
*/
private $subscriptionRequired;
/**
* CompanyFormPage constructor.
*
* @throws \Exception
*/
public function __construct()
{
$this->subscriptionRequired = false;
$this->formGroups = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): self
{
$this->label = $label;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(int $position): self
{
$this->position = $position;
return $this;
}
/**
* @return Collection|CompanyFormGroup[]
*/
public function getFormGroups(): Collection
{
return $this->formGroups;
}
public function addFormGroup(CompanyFormGroup $formGroup): self
{
if (!$this->formGroups->contains($formGroup)) {
$this->formGroups[] = $formGroup;
$formGroup->setFormPage($this);
}
return $this;
}
public function removeFormGroup(CompanyFormGroup $formGroup): self
{
if ($this->formGroups->contains($formGroup)) {
$this->formGroups->removeElement($formGroup);
// set the owning side to null (unless already changed)
if ($formGroup->getFormPage() === $this) {
$formGroup->setFormPage(null);
}
}
return $this;
}
public function getSubscriptionRequired(): ?bool
{
return $this->subscriptionRequired;
}
public function setSubscriptionRequired(bool $subscriptionRequired): self
{
$this->subscriptionRequired = $subscriptionRequired;
return $this;
}
}