<?php
namespace App\Entity;
use App\Entity\Traits\CreditOwnerInterface;
use App\Entity\Traits\CreditOwnerTrait;
use App\Repository\CentralPurchasingRepository;
use AppBundle\Entity\Traits\Archivable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=CentralPurchasingRepository::class)
* @Gedmo\Loggable(logEntryClass="App\Entity\LogEntry")
* @Vich\Uploadable
*/
class CentralPurchasing implements CreditOwnerInterface
{
use CreditOwnerTrait;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\OneToMany(targetEntity=CreditCost::class, mappedBy="centralPurchasing")
*/
private $creditCosts;
/**
* @ORM\OneToOne(targetEntity=User::class, inversedBy="centralPurchasing", cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=false)
* @Assert\Valid
*/
private $user;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $logoPath;
/**
* @assert\File( mimeTypes = {"image/jpeg", "image/png", "image/gif", "image/jpg"})
* @Vich\UploadableField(mapping="brand_logo", fileNameProperty="logoPath")
* @var File
*/
private $logoFile;
/**
* @ORM\Column(type="datetime", nullable=true)
* @var DateTime
*/
private $updatedAt;
/**
* @Assert\Valid
* @ORM\OneToMany(targetEntity=StoreCentralPurchasingRelation::class, mappedBy="centralPurchasing", orphanRemoval=true, cascade={"persist"})
*/
private $storeCentralPurchasingRelations;
/**
* @ORM\OneToMany(targetEntity=Order::class, mappedBy="centralPurchasing")
*/
private $orders;
public function __construct()
{
$this->creditCosts = new ArrayCollection();
$this->storeCentralPurchasingRelations = new ArrayCollection();
$this->orders = new ArrayCollection();
}
/**
* Représente l'entité par son nom
* @return string
*/
public function getLabel()
{
return $this->getName();
}
public function getNameAndEmailUser()
{
if($this->getUser() !== null) {
return strtoupper($this->getName()) . ' [' . $this->getUser()->getEmail() . ']';
} else {
return $this->getName();
}
}
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;
}
/**
* @return Collection|CreditCost[]
*/
public function getCreditCosts(): Collection
{
return $this->creditCosts;
}
public function addCreditCost(CreditCost $creditCost): self
{
if (!$this->creditCosts->contains($creditCost)) {
$this->creditCosts[] = $creditCost;
$creditCost->setCentralPurchasing($this);
}
return $this;
}
public function removeCreditCost(CreditCost $creditCost): self
{
if ($this->creditCosts->contains($creditCost)) {
$this->creditCosts->removeElement($creditCost);
// set the owning side to null (unless already changed)
if ($creditCost->getCentralPurchasing() === $this) {
$creditCost->setCentralPurchasing(null);
}
}
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(User $user): self
{
$this->user = $user;
return $this;
}
public function getLogoPath(): ?string
{
return $this->logoPath;
}
public function setLogoPath(string $logoPath=null): self
{
$this->logoPath = $logoPath;
return $this;
}
public function setLogoFile(File $image = null)
{
$this->logoFile = $image;
//update timestamp
if ($image) {
$this->updatedAt = new \DateTime('now');
}
}
public function getLogoFile()
{
return $this->logoFile;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return Collection|StoreCentralPurchasingRelation[]
*/
public function getStoreCentralPurchasingRelations(): Collection
{
return $this->storeCentralPurchasingRelations;
}
public function addStoreCentralPurchasingRelation(StoreCentralPurchasingRelation $storeCentralPurchasingRelation): self
{
if (!$this->storeCentralPurchasingRelations->contains($storeCentralPurchasingRelation)) {
$this->storeCentralPurchasingRelations[] = $storeCentralPurchasingRelation;
$storeCentralPurchasingRelation->setCentralPurchasing($this);
}
return $this;
}
public function removeStoreCentralPurchasingRelation(StoreCentralPurchasingRelation $storeCentralPurchasingRelation): self
{
if ($this->storeCentralPurchasingRelations->contains($storeCentralPurchasingRelation)) {
$this->storeCentralPurchasingRelations->removeElement($storeCentralPurchasingRelation);
// set the owning side to null (unless already changed)
if ($storeCentralPurchasingRelation->getCentralPurchasing() === $this) {
$storeCentralPurchasingRelation->setCentralPurchasing(null);
}
}
return $this;
}
/**
* @return Collection|Order[]
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders[] = $order;
$order->setCentralPurchasing($this);
}
return $this;
}
public function removeOrder(Order $order): self
{
if ($this->orders->contains($order)) {
$this->orders->removeElement($order);
// set the owning side to null (unless already changed)
if ($order->getCentralPurchasing() === $this) {
$order->setCentralPurchasing(null);
}
}
return $this;
}
}