src/Entity/Dashboard.php line 51

Open in your IDE?
  1. <?php
  2. // @deprecated
  3. declare(strict_types=1);
  4. namespace App\Entity;
  5. use ApiPlatform\Core\Annotation\ApiProperty;
  6. use ApiPlatform\Core\Annotation\ApiResource;
  7. use App\Trait\TimestampableEntity;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. use Ramsey\Uuid\Uuid;
  14. use Ramsey\Uuid\UuidInterface;
  15. /**
  16.  * The most generic type of item.
  17.  *
  18.  * @see https://schema.org/Thing
  19.  *
  20.  * @author Jordi Fernandes Alves <jfadev@gmail.com>
  21.  */
  22. #[ORM\Entity]
  23. #[ApiResource(
  24.     iri'Dashboard',
  25.     itemOperations: [
  26.         'get' => ['normalization_context' => ['groups' => 'dashboard:item:get''enable_max_depth' => true]],
  27.         'put' => [
  28.             'normalization_context' => ['groups' => 'dashboard:item:put''enable_max_depth' => true],
  29.             'denormalization_context' => ['groups' => 'dashboard:item:put''enable_max_depth' => true],
  30.         ],
  31.         'delete' => [],
  32.     ],
  33.     collectionOperations: [
  34.         'get' => [
  35.             'normalization_context' => [
  36.                 'groups' => ['dashboard:collection:get''createdAt'],
  37.                 'enable_max_depth' => true,
  38.             ],
  39.         ],
  40.         'post' => [
  41.             'normalization_context' => ['groups' => 'dashboard:collection:post''enable_max_depth' => true],
  42.             'denormalization_context' => ['groups' => 'dashboard:collection:post''enable_max_depth' => true],
  43.         ],
  44.     ],
  45. )]
  46. class Dashboard
  47. {
  48.     use TimestampableEntity;
  49.     
  50.     #[ORM\Id]
  51.     #[ORM\GeneratedValue(strategy'NONE')]
  52.     #[ORM\Column(type'uuid'uniquetrue)]
  53.     #[ApiProperty(iri'https://schema.org/identifier')]
  54.     private ?UuidInterface $id null;
  55.     /**
  56.      * The user associated with the dashboard.
  57.      *
  58.      * @var User|null
  59.      *
  60.      * @see _:user
  61.      */
  62.     #[ORM\ManyToOne(targetEntity'App\Entity\User')]
  63.     #[ApiProperty(iri'https://schema.org/Person')]
  64.     #[Groups(['dashboard:collection:get''dashboard:collection:post''dashboard:item:get''dashboard:item:put'])]
  65.     #[Assert\NotNull]
  66.     private ?User $user null;
  67.     /** 
  68.      * The widgets associated with the dashboard.
  69.      * 
  70.      * @see _:widgets
  71.      */
  72.     #[ORM\ManyToMany(targetEntity'App\Entity\Widget')]
  73.     #[ORM\InverseJoinColumn(nullablefalseuniquetrue)]
  74.     #[ApiProperty(iri'https://schema.org/hasPart')]
  75.     #[Groups(['dashboard:collection:get''dashboard:collection:post''dashboard:item:get''dashboard:item:put'])]
  76.     private ?Collection $widgets null;
  77.     public function __construct()
  78.     {
  79.         $this->id Uuid::uuid4();
  80.         $this->widgets = new ArrayCollection();
  81.     }
  82.     public function getId(): ?UuidInterface
  83.     {
  84.         return $this->id;
  85.     }
  86.     /**
  87.      * @param User|null $user
  88.      */
  89.     public function setUser(?User $user): void
  90.     {
  91.         $this->user $user;
  92.     }
  93.     /**
  94.      * @return User|null
  95.      */
  96.     public function getUser(): ?User
  97.     {
  98.         return $this->user;
  99.     }
  100.     public function addWidget(Widget $widget): void
  101.     {
  102.         $this->widgets[] = $widget;
  103.     }
  104.     public function removeWidget(Widget $widget): void
  105.     {
  106.         $this->widgets->removeElement($widget);
  107.     }
  108.     public function getWidgets(): Collection
  109.     {
  110.         return $this->widgets;
  111.     }
  112. }