src/JanusHercules/Clearing/Domain/Entity/ClearingRequest.php line 15

Open in your IDE?
  1. <?php
  2. namespace JanusHercules\Clearing\Domain\Entity;
  3. use App\Entity\User;
  4. use App\Utility\DatabaseIdGenerator;
  5. use App\Utility\DateTimeUtility;
  6. use DateTime;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Exception;
  10. #[ORM\Entity]
  11. #[ORM\Table(name: 'clearing_request')]
  12. class ClearingRequest
  13. {
  14. public const CLEARING_TYPE_CUSTOMER_RECURRENT_JOBS_DELETION = 0;
  15. public const CLEARING_TYPES_WITH_NAMES = [
  16. self::CLEARING_TYPE_CUSTOMER_RECURRENT_JOBS_DELETION => 'Löschung aller RJs von Customer'
  17. ];
  18. /**
  19. * @throws Exception
  20. */
  21. public function __construct(
  22. User $user,
  23. int $type,
  24. ?string $additionalInfo
  25. ) {
  26. $this->user = $user;
  27. if (!in_array($type, array_flip(self::CLEARING_TYPES_WITH_NAMES))) {
  28. throw new Exception('Unbekannter Clearing Typ');
  29. }
  30. $this->type = $type;
  31. $this->additionalInfo = $additionalInfo;
  32. $this->createdAt = DateTimeUtility::createDateTimeCet();
  33. }
  34. #[ORM\Id]
  35. #[ORM\GeneratedValue(strategy: 'CUSTOM')]
  36. #[ORM\CustomIdGenerator(class: DatabaseIdGenerator::class)]
  37. #[ORM\Column(
  38. type : Types::GUID,
  39. unique: true
  40. )]
  41. private ?string $id = null;
  42. public function getId(): ?string
  43. {
  44. return $this->id;
  45. }
  46. #[ORM\ManyToOne(
  47. targetEntity: User::class,
  48. cascade : ['persist']
  49. )]
  50. #[ORM\JoinColumn(
  51. name : 'users_id',
  52. referencedColumnName: 'id',
  53. nullable : false,
  54. onDelete : 'CASCADE'
  55. )]
  56. private User $user;
  57. public function getUser(): User
  58. {
  59. return $this->user;
  60. }
  61. #[ORM\Column(
  62. type : Types::INTEGER,
  63. nullable: false
  64. )]
  65. private int $type;
  66. public function getType(): int
  67. {
  68. return $this->type;
  69. }
  70. #[ORM\Column(
  71. type : Types::STRING,
  72. nullable: true
  73. )]
  74. private ?string $additionalInfo;
  75. public function getAdditionalInfo(): ?string
  76. {
  77. return $this->additionalInfo;
  78. }
  79. #[ORM\Column(
  80. type : Types::DATETIME_MUTABLE,
  81. nullable: false
  82. )]
  83. private DateTime $createdAt;
  84. public function setCreatedAt(DateTime $createdAt): void
  85. {
  86. $this->createdAt = $createdAt;
  87. }
  88. public function getCreatedAt(): DateTime
  89. {
  90. return $this->createdAt;
  91. }
  92. }