src/Entity/DeploymentType.php line 33

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