src/Entity/PointsCatalog/CatalogGiftHasProvider.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity\PointsCatalog;
  3. use App\Annotation\SiteAware;
  4. use App\Entity\AbstractBase;
  5. use App\Entity\Interfaces\SiteInterface;
  6. use App\Entity\Traits\SiteTrait;
  7. use App\Repository\PointsCatalog\CatalogGiftHasProviderRepository;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. use Money\Currency;
  11. use Money\Money;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. /**
  14.  * @ORM\Table(name="vulco_points_catalog_gift_has_provider", indexes={@ORM\Index(name="catalog_gift_has_provider_site_idx", columns={"site"})})
  15.  * @ORM\Entity(repositoryClass=CatalogGiftHasProviderRepository::class)
  16.  * @Gedmo\SoftDeleteable(fieldName="removedAt", timeAware=false)
  17.  * @SiteAware(siteFieldName="site")
  18.  */
  19. class CatalogGiftHasProvider extends AbstractBase implements SiteInterface
  20. {
  21.     use SiteTrait;
  22.     /**
  23.      * @ORM\ManyToOne(targetEntity="App\Entity\PointsCatalog\CatalogGift", inversedBy="providers")
  24.      */
  25.     private CatalogGift $gift;
  26.     /**
  27.      * @ORM\ManyToOne(targetEntity="App\Entity\PointsCatalog\CatalogGiftProvider", inversedBy="gifts")
  28.      * @Assert\NotBlank()
  29.      */
  30.     private CatalogGiftProvider $provider;
  31.     /**
  32.      * @ORM\Column(type="integer")
  33.      * @Assert\NotNull()
  34.      */
  35.     private int $priceAmount;
  36.     /**
  37.      * @ORM\Column(type="string", length=64)
  38.      */
  39.     private string $priceCurrency;
  40.     public function getGift(): CatalogGift
  41.     {
  42.         return $this->gift;
  43.     }
  44.     public function setGift(CatalogGift $gift): self
  45.     {
  46.         $this->gift $gift;
  47.         return $this;
  48.     }
  49.     public function getProvider(): CatalogGiftProvider
  50.     {
  51.         return $this->provider;
  52.     }
  53.     public function setProvider(CatalogGiftProvider $provider): self
  54.     {
  55.         $this->provider $provider;
  56.         return $this;
  57.     }
  58.     public function getPrice(): ?Money
  59.     {
  60.         if (!$this->priceCurrency) {
  61.             return null;
  62.         }
  63.         if (!$this->priceAmount) {
  64.             return new Money(0, new Currency($this->priceCurrency));
  65.         }
  66.         return new Money($this->priceAmount, new Currency($this->priceCurrency));
  67.     }
  68.     public function setPrice(Money $price): self
  69.     {
  70.         $this->priceAmount $price->getAmount();
  71.         $this->priceCurrency $price->getCurrency()->getCode();
  72.         return $this;
  73.     }
  74.     public function __toString(): string
  75.     {
  76.         return 'ID#'.$this->id.' ';
  77.     }
  78. }