src/Entity/Equipment.php line 18

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Building;
  4. use DateTime;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. #[ORM\Table(name: 'equipment')]
  10. #[ORM\Entity(repositoryClass: 'App\Repository\EquipmentRepository')]
  11. class Equipment
  12. {
  13. #[ORM\Column(name: 'id', type: 'integer')]
  14. #[ORM\Id]
  15. #[ORM\GeneratedValue(strategy: 'AUTO')]
  16. private int $id;
  17. #[ORM\Column(name: 'type', type: 'string', length: 255)]
  18. private string $type;
  19. #[Assert\Length(
  20. max: 255,
  21. maxMessage: 'Komentar treba da ima maksimalno {{ limit }} karaktera.'
  22. )]
  23. #[ORM\Column(name: 'comment', type: 'string', length: 255)]
  24. private string $comment;
  25. #[ORM\Column(name: 'nextServiceDate', type: 'datetime')]
  26. private DateTime $nextServiceDate;
  27. #[ORM\ManyToOne(targetEntity: 'Building', inversedBy: 'equipment', cascade: ['persist'])]
  28. #[ORM\JoinColumn(name: 'building_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
  29. private Building $building;
  30. /**
  31. * @var Collection<int, EquipmentHistory>
  32. */
  33. #[ORM\OneToMany(targetEntity: 'EquipmentHistory', mappedBy: 'equipment')]
  34. private Collection $equipmentHistory;
  35. #[ORM\Column(name: 'createdBy', type: 'string', nullable: true)]
  36. private string|null $createdBy;
  37. #[ORM\Column(name: 'status', type: 'integer', options: ['default' => 0])]
  38. private int $status;
  39. /**
  40. * @return string
  41. */
  42. public function getCreatedBy(): string
  43. {
  44. return $this->createdBy;
  45. }
  46. public function __construct()
  47. {
  48. $this->equipmentHistory = new ArrayCollection();
  49. }
  50. /**
  51. * @return Collection<int, EquipmentHistory>
  52. */
  53. public function getEquipmentHistory(): Collection
  54. {
  55. return $this->equipmentHistory;
  56. }
  57. /**
  58. * @param EquipmentHistory $equipHistory
  59. * @return void
  60. */
  61. public function setEquipmentHistory(EquipmentHistory $equipHistory): void
  62. {
  63. $this->equipmentHistory[] = $equipHistory;
  64. }
  65. /**
  66. * @return Building
  67. */
  68. public function getBuilding(): Building
  69. {
  70. return $this->building;
  71. }
  72. /**
  73. * @param Building $building
  74. */
  75. public function setBuilding(Building $building): void
  76. {
  77. $this->building = $building;
  78. if (empty($this->createdBy)) {
  79. $user = $building->getUser();
  80. $this->createdBy = $user->getCreatedByValue();
  81. }
  82. }
  83. /**
  84. * Get id
  85. *
  86. * @return int
  87. */
  88. public function getId(): int
  89. {
  90. return $this->id;
  91. }
  92. /**
  93. * @param string $type
  94. *
  95. * @return $this
  96. */
  97. public function setType(string $type): self
  98. {
  99. $this->type = $type;
  100. return $this;
  101. }
  102. /**
  103. * Get type
  104. *
  105. * @return string
  106. */
  107. public function getType(): string
  108. {
  109. return $this->type;
  110. }
  111. /**
  112. * Set comment
  113. *
  114. * @param string $comment
  115. *
  116. * @return Equipment
  117. */
  118. public function setComment(string $comment): Equipment
  119. {
  120. $this->comment = $comment;
  121. return $this;
  122. }
  123. /**
  124. * Get comment
  125. *
  126. * @return string
  127. */
  128. public function getComment(): string
  129. {
  130. return $this->comment;
  131. }
  132. /**
  133. * Set nextServiceDate
  134. *
  135. * @param DateTime $nextServiceDate
  136. *
  137. * @return Equipment
  138. */
  139. public function setNextServiceDate(DateTime $nextServiceDate): Equipment
  140. {
  141. $this->nextServiceDate = $nextServiceDate;
  142. return $this;
  143. }
  144. /**
  145. * Get nextServiceDate
  146. *
  147. * @return DateTime
  148. */
  149. public function getNextServiceDate(): DateTime
  150. {
  151. return $this->nextServiceDate;
  152. }
  153. public function __toString()
  154. {
  155. return (string) $this->getComment();
  156. }
  157. /**
  158. * @return int
  159. */
  160. public function getStatus(): int
  161. {
  162. return $this->status;
  163. }
  164. /**
  165. * @param int $status
  166. * @return void
  167. */
  168. public function setStatus(int $status): void
  169. {
  170. $this->status = $status;
  171. }
  172. }