src/Domains/UserWord/Domain/Entity/UserWord.php line 18

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Domains\UserWord\Domain\Entity;
  4. use App\Domains\User\Domain\Entity\User;
  5. use App\Domains\UserWord\Domain\Enum\WordStatus;
  6. use App\Domains\UserWord\Infrastructure\Repository\UserWordRepository;
  7. use App\Domains\Word\Domain\Entity\Word;
  8. use DateTimeImmutable;
  9. use Doctrine\DBAL\Types\Types;
  10. use Doctrine\ORM\Mapping as ORM;
  11. #[ORM\Entity(repositoryClassUserWordRepository::class)]
  12. #[ORM\Table(name'user_word')]
  13. #[ORM\UniqueConstraint(name'unique_user_word'columns: ['user_id''word_id'])]
  14. class UserWord
  15. {
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column(typeTypes::INTEGER)]
  19.     private ?int $id null;
  20.     #[ORM\ManyToOne(targetEntityUser::class)]
  21.     #[ORM\JoinColumn(name'user_id'referencedColumnName'id'nullablefalse)]
  22.     private User $user;
  23.     #[ORM\ManyToOne(targetEntityWord::class, cascade: ['persist'])]
  24.     #[ORM\JoinColumn(name'word_id'referencedColumnName'id'nullablefalse)]
  25.     private Word $word;
  26.     #[ORM\Column(typeTypes::STRINGenumTypeWordStatus::class)]
  27.     private WordStatus $status;
  28.     #[ORM\Column(name'interval_days'typeTypes::INTEGER)]
  29.     private int $intervalDays;
  30.     #[ORM\Column(name'ease_factor'typeTypes::FLOAT)]
  31.     private float $easeFactor;
  32.     #[ORM\Column(typeTypes::INTEGER)]
  33.     private int $repetition;
  34.     #[ORM\Column(name'next_review_date'typeTypes::DATE_IMMUTABLE)]
  35.     private \DateTimeImmutable $nextReviewDate;
  36.     #[ORM\Column(name'created_at'typeTypes::DATETIME_IMMUTABLE)]
  37.     private \DateTimeImmutable $createdAt;
  38.     public function __construct(
  39.         User $user,
  40.         Word $word,
  41.         WordStatus $status WordStatus::NEW,
  42.         int $intervalDays 1,
  43.         float $easeFactor 2.5,
  44.         int $repetition 0,
  45.         DateTimeImmutable|null $nextReviewDate null
  46.     ) {
  47.         $this->user $user;
  48.         $this->word $word;
  49.         $this->status $status;
  50.         $this->intervalDays $intervalDays;
  51.         $this->easeFactor $easeFactor;
  52.         $this->repetition $repetition;
  53.         $this->nextReviewDate $nextReviewDate ?? new DateTimeImmutable();
  54.         $this->createdAt = new DateTimeImmutable();
  55.     }
  56.     public function getId(): int|null
  57.     {
  58.         return $this->id;
  59.     }
  60.     public function getUser(): User
  61.     {
  62.         return $this->user;
  63.     }
  64.     public function getWord(): Word
  65.     {
  66.         return $this->word;
  67.     }
  68.     public function getStatus(): WordStatus
  69.     {
  70.         return $this->status;
  71.     }
  72.     public function getIntervalDays(): int
  73.     {
  74.         return $this->intervalDays;
  75.     }
  76.     public function getEaseFactor(): float
  77.     {
  78.         return $this->easeFactor;
  79.     }
  80.     public function getRepetition(): int
  81.     {
  82.         return $this->repetition;
  83.     }
  84.     public function getNextReviewDate(): DateTimeImmutable
  85.     {
  86.         return $this->nextReviewDate;
  87.     }
  88.     public function getCreatedAt(): DateTimeImmutable
  89.     {
  90.         return $this->createdAt;
  91.     }
  92. }