src/Entity/PyramidHead.php line 31

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use DateTime;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11.  * @ORM\Entity(repositoryClass="App\Repository\PyramidHeadRepository")
  12.  */
  13. #[ApiResource(
  14.     attributes: ['security' => "is_granted('ROLE_USER')"],
  15.     normalizationContext: ['groups' => ['pyramidHead:read']],
  16.     denormalizationContext: ['groups' => ['pyramidHead:write']],
  17.     collectionOperations: [
  18.         'get',
  19.         'post' => [
  20.             'security' => "is_granted('ROLE_ADMIN')",
  21.         ],
  22.     ],
  23.     itemOperations: [
  24.         'get',
  25.         'put' => ['security' => "is_granted('ROLE_ADMIN') or object.owner == user"],
  26.     ],
  27. )]
  28. class PyramidHead
  29. {
  30.     /**
  31.      * @ORM\Id()
  32.      * @ORM\GeneratedValue()
  33.      * @ORM\Column(type="integer")
  34.      */
  35.     private $id;
  36.     /**
  37.      * @ORM\Column(name="name", type="string", length=100)
  38.      * @Assert\NotBlank()
  39.      * @Assert\Length(max="100")
  40.      * @Groups({"pyramidHead:read", "pyramidHead:write"})
  41.      */
  42.     private $name;
  43.     /**
  44.      * @ORM\Column(type="boolean")
  45.      * @Assert\Type(type="boolean")
  46.      * @Groups({"pyramidHead:read", "pyramidHead:write"})
  47.      */
  48.     private $isActive;
  49.     /**
  50.      * @var DateTime
  51.      *
  52.      * @ORM\Column(type="datetime", nullable=false)
  53.      */
  54.     private $createdAt;
  55.     /**
  56.      * @var DateTime
  57.      *
  58.      * @ORM\Column(type="datetime", nullable=true)
  59.      */
  60.     private $updatedAt;
  61.     /**
  62.      * @var Collection
  63.      *
  64.      * @ORM\ManyToMany(targetEntity="App\Entity\Company", mappedBy="pyramidHeads")
  65.      * Ignore()
  66.      */
  67.     private $companies;
  68.     public function __construct()
  69.     {
  70.         $this->isActive true;
  71.         $this->createdAt = new \DateTime();
  72.         $this->updatedAt = new \DateTime();
  73.         $this->companies = new ArrayCollection();
  74.     }
  75.     /**
  76.      * @return string
  77.      */
  78.     public function __toString()
  79.     {
  80.         return $this->name;
  81.     }
  82.     public function getId(): ?int
  83.     {
  84.         return $this->id;
  85.     }
  86.     public function getName(): ?string
  87.     {
  88.         return $this->name;
  89.     }
  90.     public function setName(?string $name): self
  91.     {
  92.         $this->name $name;
  93.         return $this;
  94.     }
  95.     public function getIsActive(): bool
  96.     {
  97.         return $this->isActive;
  98.     }
  99.     public function setIsActive(bool $isActive): self
  100.     {
  101.         $this->isActive $isActive;
  102.         return $this;
  103.     }
  104.     public function getCreatedAt(): ?DateTime
  105.     {
  106.         return $this->createdAt;
  107.     }
  108.     public function setCreatedAt(?DateTime $createdAt): self
  109.     {
  110.         $this->createdAt $createdAt;
  111.         return $this;
  112.     }
  113.     public function getUpdatedAt(): ?DateTime
  114.     {
  115.         return $this->updatedAt;
  116.     }
  117.     public function setUpdatedAt(?DateTime $updatedAt): self
  118.     {
  119.         $this->updatedAt $updatedAt;
  120.         return $this;
  121.     }
  122.     /**
  123.      * @return Collection|Company[]
  124.      */
  125.     public function getCompanies(): Collection
  126.     {
  127.         return $this->companies;
  128.     }
  129.     public function addCompany(Company $company): self
  130.     {
  131.         if (!$this->companies->contains($company)) {
  132.             $this->companies[] = $company;
  133.         }
  134.         return $this;
  135.     }
  136.     public function removeCompany(Company $company): self
  137.     {
  138.         if ($this->companies->contains($company)) {
  139.             $this->companies->removeElement($company);
  140.         }
  141.         return $this;
  142.     }
  143. }