src/Entity/Library.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Part;
  4. use App\Repository\LibraryRepository;
  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.  * @ORM\Entity(repositoryClass=LibraryRepository::class)
  11.  */
  12. class Library
  13. {
  14.     /**
  15.      * @ORM\Id
  16.      * @ORM\GeneratedValue
  17.      * @ORM\Column(type="integer")
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\Column(type="string", length=100)
  22.      * @Assert\NotBlank
  23.      */
  24.     private $name;
  25.     /**
  26.      * @ORM\Column(type="datetime")
  27.      */
  28.     private $created_at;
  29.     /**
  30.      * @ORM\Column(type="datetime")
  31.      */
  32.     private $update_at;
  33.     /**
  34.      * @ORM\ManyToOne(targetEntity=Company::class, inversedBy="libraries")
  35.      * @ORM\JoinColumn(onDelete="CASCADE")
  36.      * @ORM\JoinColumn(nullable=false)
  37.      * @Assert\NotBlank
  38.      */
  39.     private $company;
  40.     /**
  41.      * @ORM\ManyToMany(targetEntity=Part::class, mappedBy="libraries")
  42.      * @ORM\JoinColumn(onDelete="CASCADE")
  43.      * @ORM\OrderBy({"name" = "ASC"})
  44.      */
  45.     private $parts;
  46.     /**
  47.      * @ORM\Column(type="text", nullable=true)
  48.      */
  49.     private $observations;
  50.     /**
  51.      * @ORM\Column(type="integer")
  52.      */
  53.     private $parent_id;
  54.     public function __construct()
  55.     {
  56.         $this->created_at = new \DateTime();
  57.         $this->markAsUpdated();
  58.         $this->parts = new ArrayCollection();
  59.     }
  60.     public function getId(): ?int
  61.     {
  62.         return $this->id;
  63.     }
  64.     public function getName(): ?string
  65.     {
  66.         return $this->name;
  67.     }
  68.     public function setName(string $name): self
  69.     {
  70.         $this->name $name;
  71.         return $this;
  72.     }
  73.     public function getCreatedAt(): ?\DateTimeInterface
  74.     {
  75.         return $this->created_at;
  76.     }
  77.     public function getUpdateAt(): ?\DateTimeInterface
  78.     {
  79.         return $this->update_at;
  80.     }
  81.     /**
  82.      * Set the value of updatedAt
  83.      *
  84.      * @param \DateTime $updatedAt
  85.      */
  86.     public function markAsUpdated() : void
  87.     {
  88.         $this->update_at = new \DateTime();
  89.     }
  90.     public function getCompany(): ?Company
  91.     {
  92.         return $this->company;
  93.     }
  94.     public function setCompany(?Company $company): self
  95.     {
  96.         $this->company $company;
  97.         return $this;
  98.     }
  99.     /**
  100.      * @return Collection|Part[]
  101.      */
  102.     public function getParts(): Collection
  103.     {
  104.         return $this->parts;
  105.     }
  106.     public function addPart(Part $part): self
  107.     {
  108.         if (!$this->parts->contains($part)) {
  109.             $this->parts[] = $part;
  110.             $part->addLibrary($this);
  111.         }
  112.         return $this;
  113.     }
  114.     public function removePart(Part $part): self
  115.     {
  116.         if ($this->parts->removeElement($part)) {
  117.             $part->removeLibrary($this);
  118.         }
  119.         return $this;
  120.     }
  121.     public function getObservations(): ?string
  122.     {
  123.         return $this->observations;
  124.     }
  125.     public function setObservations(?string $observations): self
  126.     {
  127.         $this->observations $observations;
  128.         return $this;
  129.     }
  130.     public function getParentId(): ?int
  131.     {
  132.         return $this->parent_id;
  133.     }
  134.     public function setParentId(int $parent_id): self
  135.     {
  136.         $this->parent_id $parent_id;
  137.         return $this;
  138.     }
  139. }