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.      * @ORM\Column(name="status", type="integer", options={"default" : 0}))
  56.      */
  57.     private int $status;
  58.     /**
  59.      * @return string
  60.      */
  61.     public function getCreatedBy(): string
  62.     {
  63.         return $this->createdBy;
  64.     }
  65.     public function __construct()
  66.     {
  67.         $this->equipmentHistory = new ArrayCollection();
  68.     }
  69.     /**
  70.      * @return Collection<int, EquipmentHistory>
  71.      */
  72.     public function getEquipmentHistory(): Collection
  73.     {
  74.         return $this->equipmentHistory;
  75.     }
  76.     /**
  77.      * @param EquipmentHistory $equipHistory
  78.      * @return void
  79.      */
  80.     public function setEquipmentHistory(EquipmentHistory $equipHistory): void
  81.     {
  82.         $this->equipmentHistory[] = $equipHistory;
  83.     }
  84.     /**
  85.      * @return Building
  86.      */
  87.     public function getBuilding(): Building
  88.     {
  89.         return $this->building;
  90.     }
  91.     /**
  92.      * @param Building $building
  93.      */
  94.     public function setBuilding(Building $building): void
  95.     {
  96.         $this->building $building;
  97.         if (empty($this->createdBy)) {
  98.             $user $building->getUser();
  99.             $this->createdBy $user->getCreatedByValue();
  100.         }
  101.     }
  102.     /**
  103.      * Get id
  104.      *
  105.      * @return int
  106.      */
  107.     public function getId(): int
  108.     {
  109.         return $this->id;
  110.     }
  111.     /**
  112.      * @param string $type
  113.      *
  114.      * @return $this
  115.      */
  116.     public function setType(string $type): self
  117.     {
  118.         $this->type $type;
  119.         return $this;
  120.     }
  121.     /**
  122.      * Get type
  123.      *
  124.      * @return string
  125.      */
  126.     public function getType(): string
  127.     {
  128.         return $this->type;
  129.     }
  130.     /**
  131.      * Set comment
  132.      *
  133.      * @param string $comment
  134.      *
  135.      * @return Equipment
  136.      */
  137.     public function setComment(string $comment): Equipment
  138.     {
  139.         $this->comment $comment;
  140.         return $this;
  141.     }
  142.     /**
  143.      * Get comment
  144.      *
  145.      * @return string
  146.      */
  147.     public function getComment(): string
  148.     {
  149.         return $this->comment;
  150.     }
  151.     /**
  152.      * Set nextServiceDate
  153.      *
  154.      * @param DateTime $nextServiceDate
  155.      *
  156.      * @return Equipment
  157.      */
  158.     public function setNextServiceDate(DateTime $nextServiceDate): Equipment
  159.     {
  160.         $this->nextServiceDate $nextServiceDate;
  161.         return $this;
  162.     }
  163.     /**
  164.      * Get nextServiceDate
  165.      *
  166.      * @return DateTime
  167.      */
  168.     public function getNextServiceDate(): DateTime
  169.     {
  170.         return $this->nextServiceDate;
  171.     }
  172.     public function __toString()
  173.     {
  174.         return (string) $this->getComment();
  175.     }
  176.     /**
  177.      * @return int
  178.      */
  179.     public function getStatus(): int
  180.     {
  181.         return $this->status;
  182.     }
  183.     /**
  184.      * @param int $status
  185.      * @return void
  186.      */
  187.     public function setStatus(int $status): void
  188.     {
  189.         $this->status $status;
  190.     }
  191. }