src/Entity/Operation.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 Symfony\Component\Serializer\Annotation\Groups;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  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'Operation',
  25.     itemOperations: [
  26.         'get' => ['normalization_context' => ['groups' => 'operation:item:get''enable_max_depth' => true]],
  27.         'put' => [
  28.             'normalization_context' => ['groups' => 'operation:item:put''enable_max_depth' => true],
  29.             'denormalization_context' => ['groups' => 'operation:item:put''enable_max_depth' => true],
  30.         ],
  31.         'delete' => [],
  32.     ],
  33.     collectionOperations: [
  34.         'get' => [
  35.             'normalization_context' => [
  36.                 'groups' => ['operation:collection:get'],
  37.                 'enable_max_depth' => true,
  38.             ],
  39.         ],
  40.         'post' => [
  41.             'normalization_context' => ['groups' => 'operation:collection:post''enable_max_depth' => true],
  42.             'denormalization_context' => ['groups' => 'operation:collection:post''enable_max_depth' => true],
  43.         ],
  44.     ],
  45. )]
  46. class Operation
  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.     #[Groups(['operation:item:get''operation:collection:get'])]
  55.     private ?UuidInterface $id null;
  56.     /**
  57.      * @var string|null
  58.      *
  59.      * @see _:operationType
  60.      */
  61.     #[ORM\Column(type'string'nullablefalse)]
  62.     #[ApiProperty(iri'https://schema.org/operationType')]
  63.     #[Groups(['operation:item:get''operation:item:put''operation:collection:post'])]
  64.     #[Assert\NotBlank// Asegura que no esté vacío
  65.     private ?string $operationType null;
  66.     /**
  67.      * @var string|null
  68.      *
  69.      * @see _:status
  70.      */
  71.     #[ORM\Column(type'string'nullablefalse)]
  72.     #[ApiProperty(iri'https://schema.org/status')]
  73.     #[Groups(['operation:item:get''operation:item:put''operation:collection:post'])]
  74.     #[Assert\NotBlank// Asegura que no esté vacío
  75.     private ?string $status null;
  76.     /** @see _:contract */
  77.     #[ORM\OneToOne(targetEntity'App\Entity\Contract')]
  78.     #[ORM\JoinColumn(nullablefalse)]
  79.     #[Groups(['operation:item:get''operation:item:put''operation:collection:post'])]
  80.     private ?Contract $contract null;
  81.     /** @see _:schedule */
  82.     #[ORM\OneToOne(targetEntity'App\Entity\OperationSchedule')]
  83.     #[ORM\JoinColumn(nullablefalse)]
  84.     #[Groups(['operation:item:get''operation:item:put''operation:collection:post'])]
  85.     private ?OperationSchedule $schedule null;
  86.     /** @see _:incidents */
  87.     #[ORM\ManyToMany(targetEntity'App\Entity\Incident')]
  88.     #[ORM\InverseJoinColumn(uniquetrue)]
  89.     #[Groups(['operation:item:get''operation:item:put'])]
  90.     private Collection $incidents;
  91.     /** @see _:notifications */
  92.     #[ORM\ManyToMany(targetEntity'App\Entity\Notification')]
  93.     #[ORM\InverseJoinColumn(uniquetrue)]
  94.     #[Groups(['operation:item:get''operation:item:put'])]
  95.     private Collection $notifications;
  96.     public function __construct()
  97.     {
  98.         $this->id Uuid::uuid4();
  99.         $this->incidents = new ArrayCollection();
  100.         $this->notifications = new ArrayCollection();
  101.     }
  102.     public function getId(): ?UuidInterface
  103.     {
  104.         return $this->id;
  105.     }
  106.     /**
  107.      * @param string|null $operationType
  108.      */
  109.     public function setOperationType(?string $operationType): void
  110.     {
  111.         $this->operationType $operationType;
  112.     }
  113.     /**
  114.      * @return string|null
  115.      */
  116.     public function getOperationType(): ?string
  117.     {
  118.         return $this->operationType;
  119.     }
  120.     /**
  121.      * @param string|null $status
  122.      */
  123.     public function setStatus(?string $status): void
  124.     {
  125.         $this->status $status;
  126.     }
  127.     /**
  128.      * @return string|null
  129.      */
  130.     public function getStatus(): ?string
  131.     {
  132.         return $this->status;
  133.     }
  134.     public function setContract(?Contract $contract): void
  135.     {
  136.         $this->contract $contract;
  137.     }
  138.     public function getContract(): ?Contract
  139.     {
  140.         return $this->contract;
  141.     }
  142.     public function setSchedule(?OperationSchedule $schedule): void
  143.     {
  144.         $this->schedule $schedule;
  145.     }
  146.     public function getSchedule(): ?OperationSchedule
  147.     {
  148.         return $this->schedule;
  149.     }
  150.     public function addIncident(Incident $incident): void
  151.     {
  152.         $this->incidents[] = $incident;
  153.     }
  154.     public function removeIncident(Incident $incident): void
  155.     {
  156.         $this->incidents->removeElement($incident);
  157.     }
  158.     public function getIncidents(): Collection
  159.     {
  160.         return $this->incidents;
  161.     }
  162.     public function addNotification(Notification $notification): void
  163.     {
  164.         $this->notifications[] = $notification;
  165.     }
  166.     public function removeNotification(Notification $notification): void
  167.     {
  168.         $this->notifications->removeElement($notification);
  169.     }
  170.     public function getNotifications(): Collection
  171.     {
  172.         return $this->notifications;
  173.     }
  174. }