src/Entity/CentralPurchasing.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\CreditOwnerInterface;
  4. use App\Entity\Traits\CreditOwnerTrait;
  5. use App\Repository\CentralPurchasingRepository;
  6. use AppBundle\Entity\Traits\Archivable;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Gedmo\Mapping\Annotation as Gedmo;
  11. use Symfony\Component\HttpFoundation\File\File;
  12. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. /**
  15.  * @ORM\Entity(repositoryClass=CentralPurchasingRepository::class)
  16.  * @Gedmo\Loggable(logEntryClass="App\Entity\LogEntry")
  17.  * @Vich\Uploadable
  18.  */
  19. class CentralPurchasing implements CreditOwnerInterface
  20. {
  21.     use CreditOwnerTrait;
  22.     /**
  23.      * @ORM\Id()
  24.      * @ORM\GeneratedValue()
  25.      * @ORM\Column(type="integer")
  26.      */
  27.     private $id;
  28.     /**
  29.      * @ORM\Column(type="string", length=255)
  30.      */
  31.     private $name;
  32.     /**
  33.      * @ORM\OneToMany(targetEntity=CreditCost::class, mappedBy="centralPurchasing")
  34.      */
  35.     private $creditCosts;
  36.     /**
  37.      * @ORM\OneToOne(targetEntity=User::class, inversedBy="centralPurchasing", cascade={"persist", "remove"})
  38.      * @ORM\JoinColumn(nullable=false)
  39.      * @Assert\Valid
  40.      */
  41.     private $user;
  42.     /**
  43.      * @ORM\Column(type="string", length=255, nullable=true)
  44.      */
  45.     private $logoPath;
  46.     /**
  47.      * @assert\File( mimeTypes = {"image/jpeg", "image/png", "image/gif", "image/jpg"})
  48.      * @Vich\UploadableField(mapping="brand_logo", fileNameProperty="logoPath")
  49.      * @var File
  50.      */
  51.     private $logoFile;
  52.     /**
  53.      * @ORM\Column(type="datetime", nullable=true)
  54.      * @var DateTime
  55.      */
  56.     private $updatedAt;
  57.     /**
  58.      * @Assert\Valid
  59.      * @ORM\OneToMany(targetEntity=StoreCentralPurchasingRelation::class, mappedBy="centralPurchasing", orphanRemoval=true, cascade={"persist"})
  60.      */
  61.     private $storeCentralPurchasingRelations;
  62.     /**
  63.      * @ORM\OneToMany(targetEntity=Order::class, mappedBy="centralPurchasing")
  64.      */
  65.     private $orders;
  66.     public function __construct()
  67.     {
  68.         $this->creditCosts = new ArrayCollection();
  69.         $this->storeCentralPurchasingRelations = new ArrayCollection();
  70.         $this->orders = new ArrayCollection();
  71.     }
  72.     /**
  73.      * Représente l'entité par son nom
  74.      * @return string
  75.      */
  76.     public function getLabel()
  77.     {
  78.         return $this->getName();
  79.     }
  80.     public function getNameAndEmailUser()
  81.     {
  82.         if($this->getUser() !== null) {
  83.             return strtoupper($this->getName()) . ' [' $this->getUser()->getEmail() . ']';
  84.         } else {
  85.             return $this->getName();
  86.         }
  87.     }
  88.     public function getId(): ?int
  89.     {
  90.         return $this->id;
  91.     }
  92.     public function getName(): ?string
  93.     {
  94.         return $this->name;
  95.     }
  96.     public function setName(string $name): self
  97.     {
  98.         $this->name $name;
  99.         return $this;
  100.     }
  101.     /**
  102.      * @return Collection|CreditCost[]
  103.      */
  104.     public function getCreditCosts(): Collection
  105.     {
  106.         return $this->creditCosts;
  107.     }
  108.     public function addCreditCost(CreditCost $creditCost): self
  109.     {
  110.         if (!$this->creditCosts->contains($creditCost)) {
  111.             $this->creditCosts[] = $creditCost;
  112.             $creditCost->setCentralPurchasing($this);
  113.         }
  114.         return $this;
  115.     }
  116.     public function removeCreditCost(CreditCost $creditCost): self
  117.     {
  118.         if ($this->creditCosts->contains($creditCost)) {
  119.             $this->creditCosts->removeElement($creditCost);
  120.             // set the owning side to null (unless already changed)
  121.             if ($creditCost->getCentralPurchasing() === $this) {
  122.                 $creditCost->setCentralPurchasing(null);
  123.             }
  124.         }
  125.         return $this;
  126.     }
  127.     public function getUser(): ?User
  128.     {
  129.         return $this->user;
  130.     }
  131.     public function setUser(User $user): self
  132.     {
  133.         $this->user $user;
  134.         return $this;
  135.     }
  136.     public function getLogoPath(): ?string
  137.     {
  138.         return $this->logoPath;
  139.     }
  140.     public function setLogoPath(string $logoPath=null): self
  141.     {
  142.         $this->logoPath $logoPath;
  143.         return $this;
  144.     }
  145.     public function setLogoFile(File $image null)
  146.     {
  147.         $this->logoFile $image;
  148.         //update timestamp
  149.         if ($image) {
  150.             $this->updatedAt = new \DateTime('now');
  151.         }
  152.     }
  153.     public function getLogoFile()
  154.     {
  155.         return $this->logoFile;
  156.     }
  157.     public function getUpdatedAt(): ?\DateTimeInterface
  158.     {
  159.         return $this->updatedAt;
  160.     }
  161.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  162.     {
  163.         $this->updatedAt $updatedAt;
  164.         return $this;
  165.     }
  166.     /**
  167.      * @return Collection|StoreCentralPurchasingRelation[]
  168.      */
  169.     public function getStoreCentralPurchasingRelations(): Collection
  170.     {
  171.         return $this->storeCentralPurchasingRelations;
  172.     }
  173.     public function addStoreCentralPurchasingRelation(StoreCentralPurchasingRelation $storeCentralPurchasingRelation): self
  174.     {
  175.         if (!$this->storeCentralPurchasingRelations->contains($storeCentralPurchasingRelation)) {
  176.             $this->storeCentralPurchasingRelations[] = $storeCentralPurchasingRelation;
  177.             $storeCentralPurchasingRelation->setCentralPurchasing($this);
  178.         }
  179.         return $this;
  180.     }
  181.     public function removeStoreCentralPurchasingRelation(StoreCentralPurchasingRelation $storeCentralPurchasingRelation): self
  182.     {
  183.         if ($this->storeCentralPurchasingRelations->contains($storeCentralPurchasingRelation)) {
  184.             $this->storeCentralPurchasingRelations->removeElement($storeCentralPurchasingRelation);
  185.             // set the owning side to null (unless already changed)
  186.             if ($storeCentralPurchasingRelation->getCentralPurchasing() === $this) {
  187.                 $storeCentralPurchasingRelation->setCentralPurchasing(null);
  188.             }
  189.         }
  190.         return $this;
  191.     }
  192.     /**
  193.      * @return Collection|Order[]
  194.      */
  195.     public function getOrders(): Collection
  196.     {
  197.         return $this->orders;
  198.     }
  199.     public function addOrder(Order $order): self
  200.     {
  201.         if (!$this->orders->contains($order)) {
  202.             $this->orders[] = $order;
  203.             $order->setCentralPurchasing($this);
  204.         }
  205.         return $this;
  206.     }
  207.     public function removeOrder(Order $order): self
  208.     {
  209.         if ($this->orders->contains($order)) {
  210.             $this->orders->removeElement($order);
  211.             // set the owning side to null (unless already changed)
  212.             if ($order->getCentralPurchasing() === $this) {
  213.                 $order->setCentralPurchasing(null);
  214.             }
  215.         }
  216.         return $this;
  217.     }
  218. }