<?php
namespace App\Entity;
use App\Entity\Part;
use App\Repository\LibraryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=LibraryRepository::class)
*/
class Library
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=100)
* @Assert\NotBlank
*/
private $name;
/**
* @ORM\Column(type="datetime")
*/
private $created_at;
/**
* @ORM\Column(type="datetime")
*/
private $update_at;
/**
* @ORM\ManyToOne(targetEntity=Company::class, inversedBy="libraries")
* @ORM\JoinColumn(onDelete="CASCADE")
* @ORM\JoinColumn(nullable=false)
* @Assert\NotBlank
*/
private $company;
/**
* @ORM\ManyToMany(targetEntity=Part::class, mappedBy="libraries")
* @ORM\JoinColumn(onDelete="CASCADE")
* @ORM\OrderBy({"name" = "ASC"})
*/
private $parts;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $observations;
/**
* @ORM\Column(type="integer")
*/
private $parent_id;
public function __construct()
{
$this->created_at = new \DateTime();
$this->markAsUpdated();
$this->parts = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function getUpdateAt(): ?\DateTimeInterface
{
return $this->update_at;
}
/**
* Set the value of updatedAt
*
* @param \DateTime $updatedAt
*/
public function markAsUpdated() : void
{
$this->update_at = new \DateTime();
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
/**
* @return Collection|Part[]
*/
public function getParts(): Collection
{
return $this->parts;
}
public function addPart(Part $part): self
{
if (!$this->parts->contains($part)) {
$this->parts[] = $part;
$part->addLibrary($this);
}
return $this;
}
public function removePart(Part $part): self
{
if ($this->parts->removeElement($part)) {
$part->removeLibrary($this);
}
return $this;
}
public function getObservations(): ?string
{
return $this->observations;
}
public function setObservations(?string $observations): self
{
$this->observations = $observations;
return $this;
}
public function getParentId(): ?int
{
return $this->parent_id;
}
public function setParentId(int $parent_id): self
{
$this->parent_id = $parent_id;
return $this;
}
}