src/Entity/Contract.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ContractRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\Table(indexes={ @ORM\Index(name="idx_contract_module_id", columns={"module_id"}), @ORM\Index(name="idx_contract_program_id", columns={"program_id"}) })
  9. * @ORM\Entity(repositoryClass=ContractRepository::class)
  10. */
  11. class Contract extends BaseEntity
  12. {
  13. /**
  14. * @ORM\Id
  15. * @ORM\GeneratedValue
  16. * @ORM\Column(type="integer")
  17. */
  18. private $id;
  19. /**
  20. * @ORM\Column(type="string", length=255)
  21. */
  22. private $name;
  23. /**
  24. * @ORM\Column(type="string", length=255, nullable=true)
  25. */
  26. private $code;
  27. /**
  28. * @ORM\ManyToOne(targetEntity=Module::class, inversedBy="contracts")
  29. * @ORM\JoinColumn(name="module_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
  30. */
  31. private $module;
  32. /**
  33. * @ORM\ManyToOne(targetEntity=Program::class, inversedBy="contracts")
  34. * @ORM\JoinColumn(name="program_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
  35. */
  36. private $program;
  37. /**
  38. * @ORM\ManyToOne(targetEntity=Live::class, inversedBy="contracts")
  39. */
  40. private $live;
  41. /**
  42. * @ORM\OneToMany(targetEntity=User::class, mappedBy="contract", fetch="EXTRA_LAZY")
  43. */
  44. private $users;
  45. /**
  46. * @ORM\OneToMany(targetEntity=Target::class, mappedBy="contract", fetch="EXTRA_LAZY")
  47. */
  48. private $targets;
  49. public function __construct()
  50. {
  51. $this->users = new ArrayCollection();
  52. $this->targets = new ArrayCollection();
  53. }
  54. public function getId(): ?int
  55. {
  56. return $this->id;
  57. }
  58. public function getName(): ?string
  59. {
  60. return $this->name;
  61. }
  62. public function setName(string $name): self
  63. {
  64. $this->name = $name;
  65. return $this;
  66. }
  67. public function getCode(): ?string
  68. {
  69. return $this->code;
  70. }
  71. public function setCode(?string $code): self
  72. {
  73. $this->code = $code;
  74. return $this;
  75. }
  76. public function getModule(): ?Module
  77. {
  78. return $this->module;
  79. }
  80. public function setModule(?Module $module): self
  81. {
  82. $this->module = $module;
  83. return $this;
  84. }
  85. public function getProgram(): ?Program
  86. {
  87. return $this->program;
  88. }
  89. public function setProgram(?Program $program): self
  90. {
  91. $this->program = $program;
  92. return $this;
  93. }
  94. public function getLive(): ?Live
  95. {
  96. return $this->live;
  97. }
  98. public function setLive(?Live $live): self
  99. {
  100. $this->live = $live;
  101. return $this;
  102. }
  103. /**
  104. * @return Collection<int, User>
  105. */
  106. public function getUsers(): Collection
  107. {
  108. return $this->users;
  109. }
  110. public function addUser(User $user): self
  111. {
  112. if (!$this->users->contains($user)) {
  113. $this->users[] = $user;
  114. $user->setContract($this);
  115. }
  116. return $this;
  117. }
  118. public function removeUser(User $user): self
  119. {
  120. if ($this->users->removeElement($user)) {
  121. // set the owning side to null (unless already changed)
  122. if ($user->getContract() === $this) {
  123. $user->setContract(null);
  124. }
  125. }
  126. return $this;
  127. }
  128. /**
  129. * @return Collection<int, Target>
  130. */
  131. public function getTarges(): Collection
  132. {
  133. return $this->targets;
  134. }
  135. public function addTarget(Target $target): self
  136. {
  137. if (!$this->targets->contains($target)) {
  138. $this->targets[] = $target;
  139. $target->setContract($this);
  140. }
  141. return $this;
  142. }
  143. public function removeTarget(Target $target): self
  144. {
  145. if ($this->targets->removeElement($target)) {
  146. // set the owning side to null (unless already changed)
  147. if ($target->getContract() === $this) {
  148. $target->setContract(null);
  149. }
  150. }
  151. return $this;
  152. }
  153. }