src/Bidcoz/Bundle/CoreBundle/Entity/Proxy/ItemPurchaseProxy.php line 13

Open in your IDE?
  1. <?php
  2. namespace Bidcoz\Bundle\CoreBundle\Entity\Proxy;
  3. use Bidcoz\Bundle\CoreBundle\Entity\Auction\Item;
  4. use Bidcoz\Bundle\CoreBundle\Util\TextManipulator;
  5. use Symfony\Component\Validator\Constraints as Assert;
  6. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  7. /**
  8.  * A proxy object to create a bid.
  9.  */
  10. class ItemPurchaseProxy
  11. {
  12.     /**
  13.      * @Assert\Range(min=".01")
  14.      * @Assert\NotNull
  15.      */
  16.     protected $amount 0;
  17.     /**
  18.      * @Assert\Range(min=1)
  19.      * @Assert\NotNull
  20.      */
  21.     protected $quantity 1;
  22.     /**
  23.      * @Assert\NotNull
  24.      */
  25.     protected $item;
  26.     protected $emails = [];
  27.     public function __construct(Item $item)
  28.     {
  29.         $this->item $item;
  30.         if ($item->isFixedPrice()) {
  31.             $this->amount $item->getFixedPrice();
  32.         }
  33.     }
  34.     public function getItem()
  35.     {
  36.         return $this->item;
  37.     }
  38.     public function setAmount($amount)
  39.     {
  40.         $this->amount $amount;
  41.     }
  42.     public function getAmount()
  43.     {
  44.         return $this->amount;
  45.     }
  46.     public function setQuantity($quantity)
  47.     {
  48.         $this->quantity $quantity;
  49.     }
  50.     public function getQuantity()
  51.     {
  52.         if ($this->item->getCollectEmail()) {
  53.             return count($this->emails);
  54.         }
  55.         return $this->quantity;
  56.     }
  57.     public function setEmails(string $emails)
  58.     {
  59.         $this->emails TextManipulator::parseEmails($emails);
  60.     }
  61.     public function getEmails()
  62.     {
  63.         return implode(', '$this->emails);
  64.     }
  65.     public function getEmailByIndex(int $idx)
  66.     {
  67.         return $this->emails[$idx];
  68.     }
  69.     /**
  70.      * @Assert\Callback
  71.      */
  72.     public function validate(ExecutionContextInterface $context$payload)
  73.     {
  74.         if (!$this->item->getCollectEmail()) {
  75.             return;
  76.         }
  77.         if ($this->item->isDonation()) {
  78.             return;
  79.         }
  80.         if (=== count($this->emails)) {
  81.             $context->buildViolation('Must provide at least one email address.')
  82.                 ->atPath('emails')
  83.                 ->addViolation();
  84.         }
  85.     }
  86. }