src/Entity/Supplier.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\Common\Collections\Criteria;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Table(name="suppliers__suppliers")
  9.  * @ORM\Entity(repositoryClass="App\Repository\SupplierRepository")
  10.  */
  11. class Supplier
  12. {
  13.     use IdTrait;
  14.     /**
  15.      * @ORM\Column(name="name", type="string")
  16.      */
  17.     private string $name;
  18.     /**
  19.      * @ORM\Column(name="alias", type="string", unique=true)
  20.      */
  21.     private string $alias;
  22.     /**
  23.      * @ORM\OneToOne(targetEntity="SupplierMarkup", mappedBy="supplier")
  24.      */
  25.     private ?SupplierMarkup $supplierMarkup null;
  26.     /**
  27.      * @var SupplierWarehouse[]|Collection
  28.      * @ORM\OneToMany(targetEntity="SupplierWarehouse", mappedBy="supplier")
  29.      */
  30.     private $supplierWarehouses;
  31.     /**
  32.      * @var SupplierBrandDiscount[]|Collection
  33.      * @ORM\OneToMany(targetEntity="SupplierBrandDiscount", mappedBy="supplier")
  34.      */
  35.     private $supplierBrandsDiscount;
  36.     /**
  37.      * @var SupplierMarkupRange[]|Collection
  38.      * @ORM\OneToMany(targetEntity="SupplierMarkupRange", mappedBy="supplier")
  39.      */
  40.     private $supplierMarkupRanges;
  41.     public function __construct(string $namestring $alias)
  42.     {
  43.         $this->name $name;
  44.         $this->alias $alias;
  45.         $this->supplierBrandsDiscount = new ArrayCollection();
  46.         $this->supplierWarehouses = new ArrayCollection();
  47.     }
  48.     public function getName(): string
  49.     {
  50.         return $this->name;
  51.     }
  52.     public function getAlias(): string
  53.     {
  54.         return $this->alias;
  55.     }
  56.     public function getSupplierMarkup(): ?SupplierMarkup
  57.     {
  58.         return $this->supplierMarkup;
  59.     }
  60.     public function getSupplierBrandDiscount(Brand $brand): ?SupplierBrandDiscount
  61.     {
  62.         $supplierBrandsDiscount $this->supplierBrandsDiscount->matching(Criteria::create()->where(Criteria::expr()->eq('brand'$brand)));
  63.         return $supplierBrandsDiscount->count() ? $supplierBrandsDiscount->last() : null;
  64.     }
  65.     /**
  66.      * @return SupplierWarehouse[]
  67.      */
  68.     public function getWarehouses()
  69.     {
  70.         return $this->supplierWarehouses;
  71.     }
  72.     public function getSupplierMarkupRange(int $price): ?SupplierMarkupRange
  73.     {
  74.         $supplierMarkupRanges $this->supplierMarkupRanges
  75.             ->matching(
  76.                 Criteria::create()->where(
  77.                     Criteria::expr()->orX(
  78.                         Criteria::expr()->andX(
  79.                             Criteria::expr()->gte('rangeFrom'$price),
  80.                             Criteria::expr()->lt('rangeTo'$price)
  81.                         ),
  82.                         Criteria::expr()->andX(
  83.                             Criteria::expr()->gt('rangeFrom'$price),
  84.                             Criteria::expr()->lte('rangeTo'$price)
  85.                         )
  86.                     )
  87.                 )
  88.             );
  89.         return $supplierMarkupRanges->count() ? $supplierMarkupRanges->last() : null;
  90.     }
  91. }