src/Entity/Equipment.php line 18

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