src/Entity/Projects.php line 46

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Delete;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\GetCollection;
  7. use ApiPlatform\Metadata\Patch;
  8. use ApiPlatform\Metadata\Post;
  9. use App\Controller\ProjectsController;
  10. use App\Controller\MediaGetController;
  11. use App\Controller\ProjectsGetController;
  12. use App\Entity\Traits\CreatedAtTrait;
  13. use App\Entity\Traits\UpdatedAtTrait;
  14. use App\Repository\ProjectsRepository;
  15. use Doctrine\Common\Collections\ArrayCollection;
  16. use Doctrine\Common\Collections\Collection;
  17. use Doctrine\ORM\Mapping as ORM;
  18. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  19. use Symfony\Component\Serializer\Annotation\Groups;
  20. #[ORM\HasLifecycleCallbacks]
  21. #[ORM\Entity(repositoryClassProjectsRepository::class)]
  22. #[ApiResource(
  23.     operations: [
  24.         new GetCollection(
  25.             uriTemplate'/user/projects',
  26.             controllerProjectsController::class,
  27.             normalizationContext: ['groups' => ['projects:read']],
  28.             security"is_granted('ROLE_USER')",
  29.         ),
  30.         new Patch(
  31.             denormalizationContext: ['groups' => ['projects:update']]
  32.         ),
  33.         new Get(
  34.             uriTemplate'/user/projects/{id}',
  35.             controllerProjectsGetController::class,
  36.             normalizationContext: ['groups' => ['projects:read']],
  37.             security"is_granted('ROLE_USER')",
  38.         )
  39.     ],
  40.     normalizationContext: ['groups' => ['projects:read']],
  41.     paginationEnabledfalse
  42. )]
  43. class Projects
  44. {
  45.     use CreatedAtTrait;
  46.     use UpdatedAtTrait;
  47.     #[ORM\Id]
  48.     #[ORM\GeneratedValue]
  49.     #[ORM\Column]
  50.     #[Groups(['projects:read'])]
  51.     private ?int $id null;
  52.     #[ORM\Column(length255)]
  53.     #[Groups(['projects:write''projects:update''projects:read'])]
  54.     private ?string $title null;
  55.     #[ORM\Column]
  56.     #[Groups(['projects:write''projects:read''projects:update'])]
  57.     private ?int $width null;
  58.     #[ORM\Column]
  59.     #[Groups(['projects:write''projects:read''projects:update'])]
  60.     private ?int $height null;
  61.     #[ORM\Column(length255)]
  62.     #[Groups(['projects:write''projects:read''projects:update'])]
  63.     private ?string $orientation null;
  64.     #[ORM\Column]
  65.     #[Groups(['projects:write''projects:read''projects:update'])]
  66.     private array $widgets = [];
  67.     #[ORM\OneToMany(mappedBy'project'targetEntityPages::class, cascade: ['all'])]
  68.     #[Groups(['projects:read'])]
  69.     private Collection $pages;
  70.     #[ORM\ManyToOne(cascade: ['all'], inversedBy'projects')]
  71.     #[ORM\JoinColumn(nullablefalse)]
  72.     private ?Client $client null;
  73.     public function __construct()
  74.     {
  75.         $this->pages = new ArrayCollection();
  76.     }
  77.     public function getId(): ?int
  78.     {
  79.         return $this->id;
  80.     }
  81.     public function getTitle(): ?string
  82.     {
  83.         return $this->title;
  84.     }
  85.     public function setTitle(string $title): static
  86.     {
  87.         $this->title $title;
  88.         return $this;
  89.     }
  90.     public function getWidth(): ?int
  91.     {
  92.         return $this->width;
  93.     }
  94.     public function setWidth(int $width): static
  95.     {
  96.         $this->width $width;
  97.         return $this;
  98.     }
  99.     public function getHeight(): ?int
  100.     {
  101.         return $this->height;
  102.     }
  103.     public function setHeight(int $height): static
  104.     {
  105.         $this->height $height;
  106.         return $this;
  107.     }
  108.     public function getOrientation(): ?string
  109.     {
  110.         return $this->orientation;
  111.     }
  112.     public function setOrientation(string $orientation): static
  113.     {
  114.         $this->orientation $orientation;
  115.         return $this;
  116.     }
  117.     public function getWidgets(): array
  118.     {
  119.         return $this->widgets;
  120.     }
  121.     public function setWidgets(array $widgets): static
  122.     {
  123.         $this->widgets $widgets;
  124.         return $this;
  125.     }
  126.     /**
  127.      * @return Collection<int, Pages>
  128.      */
  129.     public function getPages(): Collection
  130.     {
  131.         return $this->pages;
  132.     }
  133.     public function addPage(Pages $page): static
  134.     {
  135.         if (!$this->pages->contains($page)) {
  136.             $this->pages->add($page);
  137.             $page->setProject($this);
  138.         }
  139.         return $this;
  140.     }
  141.     public function removePage(Pages $page): static
  142.     {
  143.         if ($this->pages->removeElement($page)) {
  144.             // set the owning side to null (unless already changed)
  145.             if ($page->getProject() === $this) {
  146.                 $page->setProject(null);
  147.             }
  148.         }
  149.         return $this;
  150.     }
  151.     public function getClient(): ?Client
  152.     {
  153.         return $this->client;
  154.     }
  155.     public function setClient(?Client $client): static
  156.     {
  157.         $this->client $client;
  158.         return $this;
  159.     }
  160. }