src/Program/Doctrine/Entity/Program.php line 31

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Program\Doctrine\Entity;
  4. use App\Client\Doctrine\Entity\Client;
  5. use App\Program\Doctrine\Repository\ProgramRepository;
  6. use DateTimeImmutable;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping\Column;
  10. use Doctrine\ORM\Mapping\Entity;
  11. use Doctrine\ORM\Mapping\GeneratedValue;
  12. use Doctrine\ORM\Mapping\Id;
  13. use Doctrine\ORM\Mapping\JoinColumn;
  14. use Doctrine\ORM\Mapping\ManyToOne;
  15. use Doctrine\ORM\Mapping\OneToMany;
  16. use Doctrine\ORM\Mapping\Table;
  17. use Symfony\Component\Security\Core\User\UserInterface;
  18. use Symfony\Component\Uid\Uuid;
  19. use Symfony\Component\Validator\Constraints\Email;
  20. use Symfony\Component\Validator\Constraints\GreaterThan;
  21. use Symfony\Component\Validator\Constraints\NotBlank;
  22. use Symfony\Component\Validator\Constraints\NotNull;
  23. use Symfony\Component\Validator\Constraints\Url;
  24. use Symfony\Component\Validator\Constraints\Valid;
  25. #[Entity(repositoryClassProgramRepository::class)]
  26. #[Table(name'`program`')]
  27. class Program implements UserInterface
  28. {
  29.     #[Id]
  30.     #[Column(type'integer')]
  31.     #[GeneratedValue]
  32.     private ?int $id null;
  33.     #[Column]
  34.     #[NotBlank]
  35.     private string $name '';
  36.     #[Column]
  37.     #[NotBlank]
  38.     #[Url]
  39.     private string $url '';
  40.     #[Column(type'date_immutable'nullabletrue)]
  41.     #[NotBlank]
  42.     private ?DateTimeImmutable $startedAt null;
  43.     #[Column(type'date_immutable'nullabletrue)]
  44.     #[GreaterThan(propertyPath'startedAt')]
  45.     private ?DateTimeImmutable $endedAt null;
  46.     #[ManyToOne(targetEntityClient::class)]
  47.     #[JoinColumn(nullablefalseonDelete'CASCADE')]
  48.     #[NotNull(message'Veuillez sélectionner un client.')]
  49.     private Client $client;
  50.     #[Column(type'point_evaluator')]
  51.     #[NotNull(message'Veuillez saisir une expression.')]
  52.     #[Valid]
  53.     private PointEvaluator $currencyToPoint;
  54.     #[Column(type'point_evaluator')]
  55.     #[NotNull(message'Veuillez saisir une expression.')]
  56.     #[Valid]
  57.     private PointEvaluator $pointToCurrency;
  58.     /**
  59.      * @var Collection<array-key, Profile>
  60.      */
  61.     #[OneToMany(mappedBy'program'targetEntityProfile::class)]
  62.     private Collection $profiles;
  63.     /**
  64.      * @var Collection<array-key, ProgramEmail>
  65.      */
  66.     #[OneToMany(mappedBy'program'targetEntityProgramEmail::class, cascade: ['persist'])]
  67.     private Collection $emails;
  68.     #[Column(uniquetrue)]
  69.     private string $apiKey;
  70.     #[Column]
  71.     #[NotBlank]
  72.     #[Email]
  73.     private string $email;
  74.     public function __construct()
  75.     {
  76.         $this->apiKey = (string) Uuid::v4();
  77.         $this->profiles = new ArrayCollection();
  78.         $this->emails = new ArrayCollection();
  79.     }
  80.     public function getId(): ?int
  81.     {
  82.         return $this->id;
  83.     }
  84.     public function getName(): string
  85.     {
  86.         return $this->name;
  87.     }
  88.     public function setName(string $name): void
  89.     {
  90.         $this->name $name;
  91.     }
  92.     public function getUrl(): string
  93.     {
  94.         return $this->url;
  95.     }
  96.     public function setUrl(string $url): void
  97.     {
  98.         $this->url $url;
  99.     }
  100.     public function getStartedAt(): ?DateTimeImmutable
  101.     {
  102.         return $this->startedAt;
  103.     }
  104.     public function setStartedAt(?DateTimeImmutable $startedAt): void
  105.     {
  106.         $this->startedAt $startedAt;
  107.     }
  108.     public function getEndedAt(): ?DateTimeImmutable
  109.     {
  110.         return $this->endedAt;
  111.     }
  112.     public function setEndedAt(?DateTimeImmutable $endedAt): void
  113.     {
  114.         $this->endedAt $endedAt;
  115.     }
  116.     public function isClosed(): bool
  117.     {
  118.         return $this->endedAt < new DateTimeImmutable();
  119.     }
  120.     public function isUpcoming(): bool
  121.     {
  122.         return $this->startedAt > new DateTimeImmutable();
  123.     }
  124.     public function isPending(): bool
  125.     {
  126.         return $this->startedAt <= new DateTimeImmutable()
  127.             && (null === $this->endedAt || $this->endedAt > new DateTimeImmutable());
  128.     }
  129.     public function getClient(): Client
  130.     {
  131.         return $this->client;
  132.     }
  133.     public function setClient(Client $client): void
  134.     {
  135.         $this->client $client;
  136.     }
  137.     public function getCurrencyToPoint(): PointEvaluator
  138.     {
  139.         return $this->currencyToPoint;
  140.     }
  141.     public function setCurrencyToPoint(PointEvaluator $currencyToPoint): void
  142.     {
  143.         $this->currencyToPoint $currencyToPoint;
  144.     }
  145.     public function getPointToCurrency(): PointEvaluator
  146.     {
  147.         return $this->pointToCurrency;
  148.     }
  149.     public function setPointToCurrency(PointEvaluator $pointToCurrency): void
  150.     {
  151.         $this->pointToCurrency $pointToCurrency;
  152.     }
  153.     public function getApiKey(): string
  154.     {
  155.         return $this->apiKey;
  156.     }
  157.     /**
  158.      * @return array<int, string>
  159.      */
  160.     public function getRoles(): array
  161.     {
  162.         return ['ROLE_API''ROLE_USER'];
  163.     }
  164.     public function getPassword(): string
  165.     {
  166.         return '';
  167.     }
  168.     public function getSalt(): ?string
  169.     {
  170.         return null;
  171.     }
  172.     public function eraseCredentials(): void
  173.     {
  174.     }
  175.     public function getUsername(): string
  176.     {
  177.         return $this->apiKey;
  178.     }
  179.     public function getUserIdentifier(): string
  180.     {
  181.         return $this->apiKey;
  182.     }
  183.     /**
  184.      * @return Collection<array-key, Profile>
  185.      */
  186.     public function getProfiles(): Collection
  187.     {
  188.         return $this->profiles;
  189.     }
  190.     public function getEmail(): string
  191.     {
  192.         return $this->email;
  193.     }
  194.     public function setEmail(string $email): void
  195.     {
  196.         $this->email $email;
  197.     }
  198.     public function getEmails(): Collection
  199.     {
  200.         return $this->emails;
  201.     }
  202.     public function getEmailByCode(string $code): ProgramEmail
  203.     {
  204.         foreach ($this->emails as $email) {
  205.             if ($email->getEmail()->getCode() === $code) {
  206.                 return $email;
  207.             }
  208.         }
  209.     }
  210. }