src/Entity/PaymentPlan.php line 333

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Utils\Constants\PaymentPlanType;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Symfony\Component\PropertyAccess\PropertyAccess;
  7. use Symfony\Component\Validator\Exception\ValidatorException;
  8. use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
  9. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  10. /**
  11.  * @ORM\Entity@ORM\Entity(repositoryClass="App\Repository\PaymentPlanRepository")
  12.  */
  13. class PaymentPlan implements \JsonSerializable, TranslatableInterface
  14. {
  15.     use TranslatableTrait;
  16.     /**
  17.      * @ORM\Id()
  18.      * @ORM\GeneratedValue()
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     public $id;
  22.     /**
  23.      * @ORM\Column(type="integer", nullable = true)
  24.      */
  25.     public $period;
  26.     /**
  27.      * @ORM\Column(type="integer", nullable = true)
  28.      */
  29.     public $jobOffers;
  30.     /**
  31.      * @ORM\Column(type="integer", nullable = true)
  32.      */
  33.     public $promotedJobOffers;
  34.     /**
  35.      * @ORM\Column(type="decimal", precision=10, scale=2)
  36.      */
  37.     public $price;
  38.     /**
  39.      * @var bool
  40.      *
  41.      * @ORM\Column(type="boolean", options={"default":"0"})
  42.      */
  43.     public $exclusive = false;
  44.     /**
  45.      * @var bool
  46.      *
  47.      * @ORM\Column(type="boolean", options={"default":"0"})
  48.      */
  49.     public $addon = false;
  50.     /**
  51.      * @var bool
  52.      *
  53.      * @ORM\Column(type="boolean", options={"default":"1"})
  54.      */
  55.     public $active = true;
  56.     /**
  57.      * @var bool
  58.      *
  59.      * @ORM\Column(type="boolean", options={"default":"1"})
  60.      */
  61.     public $public = true;
  62.     /**
  63.      * @var bool
  64.      *
  65.      * @ORM\Column(type="boolean", options={"default":"0"})
  66.      */
  67.     public $promotedJobPackage = false;
  68.     /**
  69.      * @ORM\OneToMany(targetEntity="App\Entity\Payment", mappedBy="paymentPlan")
  70.      */
  71.     private $payments;
  72.     /**
  73.      * @ORM\Column(type="decimal", precision=10, scale=2)
  74.      */
  75.     public $priceBgn;
  76.     public function __construct()
  77.     {
  78.         $this->payments = new ArrayCollection();
  79.     }
  80.     /**
  81.      * @return mixed
  82.      */
  83.     public function getId() {
  84.         return $this->id;
  85.     }
  86.     /**
  87.      * @param mixed $id
  88.      *
  89.      * @return \App\Entity\PaymentPlan
  90.      */
  91.     public function setId($id): self {
  92.         $this->id = $id;
  93.         return $this;
  94.     }
  95.     /**
  96.      * @return mixed
  97.      */
  98.     public function getPeriod() {
  99.         return $this->period;
  100.     }
  101.     /**
  102.      * @param mixed $period
  103.      *
  104.      * @return \App\Entity\PaymentPlan
  105.      */
  106.     public function setPeriod($period): self {
  107.         $this->period = $period;
  108.         return $this;
  109.     }
  110.     /**
  111.      * @return mixed
  112.      */
  113.     public function getJobOffers() {
  114.         return $this->jobOffers;
  115.     }
  116.     /**
  117.      * @param mixed $jobOffers
  118.      *
  119.      * @return \App\Entity\PaymentPlan
  120.      */
  121.     public function setJobOffers($jobOffers): self {
  122.         $this->jobOffers = $jobOffers;
  123.         return $this;
  124.     }
  125.     /**
  126.      * @return mixed
  127.      */
  128.     public function getPromotedJobOffers() {
  129.         return $this->promotedJobOffers;
  130.     }
  131.     /**
  132.      * @param mixed $promotedJobOffers
  133.      *
  134.      * @return \App\Entity\PaymentPlan
  135.      */
  136.     public function setPromotedJobOffers($promotedJobOffers): self {
  137.         // валидацията засега оставям в Admin PaymentPlanController, за да вади user-friendly грешка
  138.         // if ($promotedJobOffers > $this->getJobOffers()) {
  139.         //     throw new ValidatorException(sprintf('Promoted job offers count (%s) should be less than all job offers count (%d).', (int)$promotedJobOffers, (int)$this->getJobOffers()));
  140.         // }
  141.         $this->promotedJobOffers = $promotedJobOffers;
  142.         return $this;
  143.     }
  144.     /**
  145.      * @return mixed
  146.      */
  147.     public function getPrice() {
  148.         return $this->price;
  149.     }
  150.     /**
  151.      * @param mixed $price
  152.      *
  153.      * @return \App\Entity\PaymentPlan
  154.      */
  155.     public function setPrice($price): self {
  156.         $this->price = $price;
  157.         return $this;
  158.     }
  159.     /**
  160.      * @return mixed
  161.      */
  162.     public function getEuroPrice() {
  163.         return number_format(round($this->price / 1.95583), 2, '.', '');
  164.     }
  165.     /**
  166.      * @return mixed
  167.      */
  168.     public function getLevaPrice() {
  169.         return number_format(($this->price * 1.95583), 2, '.', '');
  170.     }
  171.     /**
  172.      * @return bool
  173.      */
  174.     public function isExclusive(): bool {
  175.         return $this->exclusive;
  176.     }
  177.     /**
  178.      * @param bool $exclusive
  179.      *
  180.      * @return \App\Entity\PaymentPlan
  181.      */
  182.     public function setExclusive(bool $exclusive): self {
  183.         $this->exclusive = $exclusive;
  184.         return $this;
  185.     }
  186.     /**
  187.      * @return bool
  188.      */
  189.     public function isAddon(): bool {
  190.         return $this->addon;
  191.     }
  192.     /**
  193.      * @param bool $addon
  194.      *
  195.      * @return \App\Entity\PaymentPlan
  196.      */
  197.     public function setAddon(bool $addon): self {
  198.         $this->addon = $addon;
  199.         return $this;
  200.     }
  201.     /**
  202.      * @return bool
  203.      */
  204.     public function isActive(): bool {
  205.         return $this->active;
  206.     }
  207.     /**
  208.      * @param bool $active
  209.      *
  210.      * @return \App\Entity\PaymentPlan
  211.      */
  212.     public function setActive(bool $active): self {
  213.         $this->active = $active;
  214.         return $this;
  215.     }
  216.     /**
  217.      * @return bool
  218.      */
  219.     public function isPublic(): bool {
  220.         return $this->public;
  221.     }
  222.     /**
  223.      * @param bool $public
  224.      *
  225.      * @return \App\Entity\PaymentPlan
  226.      */
  227.     public function setPublic(bool $public): self {
  228.         $this->public = $public;
  229.         return $this;
  230.     }
  231.     /**
  232.      * @return bool
  233.      */
  234.     public function isPromotedJobPackage(): bool {
  235.         return $this->promotedJobPackage;
  236.     }
  237.     /**
  238.      * @param bool $promotedJobPackage
  239.      *
  240.      * @return \App\Entity\PaymentPlan
  241.      */
  242.     public function setPromotedJobPackage(bool $promotedJobPackage): self {
  243.         $this->promotedJobPackage = $promotedJobPackage;
  244.         return $this;
  245.     }
  246.     /**
  247.      * @return float
  248.      */
  249.     public function getPriceBgn(): float {
  250.         return $this->priceBgn;
  251.     }
  252.     /**
  253.      * @param float $price
  254.      *
  255.      * @return Payment
  256.      */
  257.     public function setPriceBgn(float $priceBgn): self {
  258.         $this->priceBgn = $priceBgn;
  259.         return $this;
  260.     }
  261.     public function getName(){
  262.         return $this->translate()->getName();
  263.     }
  264.     public function __get($name)
  265.     {
  266.         return PropertyAccess::createPropertyAccessor()->getValue($this->translate(), $name);
  267.     }
  268.     public function __toString(){
  269.         return (string)$this->translate()->getName(); //or anything else
  270.     }
  271.     /**
  272.      * Specify data which should be serialized to JSON
  273.      *
  274.      * @link https://php.net/manual/en/jsonserializable.jsonserialize.php
  275.      * @return mixed data which can be serialized by <b>json_encode</b>,
  276.      * which is a value of any type other than a resource.
  277.      * @since 5.4.0
  278.      */
  279.     public function jsonSerialize() {
  280.         return [
  281.             'id' => $this->getId(),
  282.             'name' => $this->translate()->getName(),
  283.             'description' => $this->translate()->getDescription(),
  284.             'period' => $this->getPeriod(),
  285.             'jobOffers' => $this->getJobOffers(),
  286.             'price' => $this->getPrice(),
  287.             // 'priceEuro' => $this->getEuroPrice(),
  288.             // 'priceLeva' => $this->getLevaPrice(),
  289.             'exclusive' => $this->isExclusive(),
  290.             'addon' => $this->isAddon(),
  291.             'promotedJobPackage' => $this->isPromotedJobPackage()
  292.         ];
  293.     }
  294. }