<?php
namespace App\Entity;
use App\Entity\Building;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Equipment
*
* @ORM\Table(name="equipment")
* @ORM\Entity(repositoryClass="App\Repository\EquipmentRepository")
*/
class Equipment
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private int $id;
/**
* @ORM\Column(name="type", type="string", length=255)
*/
private string $type;
/**
* @Assert\Length(
* max = 255,
* maxMessage = "Komentar treba da ima maksimalno {{ limit }} karaktera."
* )
*
* @ORM\Column(name="comment", type="string", length=255)
*/
private string $comment;
/**
* @ORM\Column(name="nextServiceDate", type="datetime")
*/
private DateTime $nextServiceDate;
/**
* @ORM\ManyToOne(targetEntity="Building", inversedBy="equipment", cascade={"persist"})
* @ORM\JoinColumn(name="building_id", referencedColumnName="id", onDelete="CASCADE")
*/
private Building $building;
/**
* @var Collection<int, EquipmentHistory>
* @ORM\OneToMany(targetEntity="EquipmentHistory", mappedBy="equipment")
*/
private Collection $equipmentHistory;
/**
* @ORM\Column(name="createdBy", type="string", nullable=true)
*/
private string|null $createdBy;
/**
* @return string
*/
public function getCreatedBy(): string
{
return $this->createdBy;
}
public function __construct()
{
$this->equipmentHistory = new ArrayCollection();
}
/**
* @return Collection<int, EquipmentHistory>
*/
public function getEquipmentHistory(): Collection
{
return $this->equipmentHistory;
}
/**
* @param EquipmentHistory $equipHistory
* @return void
*/
public function setEquipmentHistory(EquipmentHistory $equipHistory): void
{
$this->equipmentHistory[] = $equipHistory;
}
/**
* @return Building
*/
public function getBuilding(): Building
{
return $this->building;
}
/**
* @param Building $building
*/
public function setBuilding(Building $building): void
{
$this->building = $building;
if (empty($this->createdBy)) {
$user = $building->getUser();
$this->createdBy = $user->getCreatedByValue();
}
}
/**
* Get id
*
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @param string $type
*
* @return $this
*/
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
/**
* Get type
*
* @return string
*/
public function getType(): string
{
return $this->type;
}
/**
* Set comment
*
* @param string $comment
*
* @return Equipment
*/
public function setComment(string $comment): Equipment
{
$this->comment = $comment;
return $this;
}
/**
* Get comment
*
* @return string
*/
public function getComment(): string
{
return $this->comment;
}
/**
* Set nextServiceDate
*
* @param DateTime $nextServiceDate
*
* @return Equipment
*/
public function setNextServiceDate(DateTime $nextServiceDate): Equipment
{
$this->nextServiceDate = $nextServiceDate;
return $this;
}
/**
* Get nextServiceDate
*
* @return DateTime
*/
public function getNextServiceDate(): DateTime
{
return $this->nextServiceDate;
}
public function __toString()
{
return (string) $this->getComment();
}
}