<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Utils\Constants\PaymentPlanType;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\Validator\Exception\ValidatorException;
use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
/**
* @ORM\Entity@ORM\Entity(repositoryClass="App\Repository\PaymentPlanRepository")
*/
class PaymentPlan implements \JsonSerializable, TranslatableInterface
{
use TranslatableTrait;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
public $id;
/**
* @ORM\Column(type="integer", nullable = true)
*/
public $period;
/**
* @ORM\Column(type="integer", nullable = true)
*/
public $jobOffers;
/**
* @ORM\Column(type="integer", nullable = true)
*/
public $promotedJobOffers;
/**
* @ORM\Column(type="decimal", precision=10, scale=2)
*/
public $price;
/**
* @var bool
*
* @ORM\Column(type="boolean", options={"default":"0"})
*/
public $exclusive = false;
/**
* @var bool
*
* @ORM\Column(type="boolean", options={"default":"0"})
*/
public $addon = false;
/**
* @var bool
*
* @ORM\Column(type="boolean", options={"default":"1"})
*/
public $active = true;
/**
* @var bool
*
* @ORM\Column(type="boolean", options={"default":"1"})
*/
public $public = true;
/**
* @var bool
*
* @ORM\Column(type="boolean", options={"default":"0"})
*/
public $promotedJobPackage = false;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Payment", mappedBy="paymentPlan")
*/
private $payments;
/**
* @ORM\Column(type="decimal", precision=10, scale=2)
*/
public $priceBgn;
public function __construct()
{
$this->payments = new ArrayCollection();
}
/**
* @return mixed
*/
public function getId() {
return $this->id;
}
/**
* @param mixed $id
*
* @return \App\Entity\PaymentPlan
*/
public function setId($id): self {
$this->id = $id;
return $this;
}
/**
* @return mixed
*/
public function getPeriod() {
return $this->period;
}
/**
* @param mixed $period
*
* @return \App\Entity\PaymentPlan
*/
public function setPeriod($period): self {
$this->period = $period;
return $this;
}
/**
* @return mixed
*/
public function getJobOffers() {
return $this->jobOffers;
}
/**
* @param mixed $jobOffers
*
* @return \App\Entity\PaymentPlan
*/
public function setJobOffers($jobOffers): self {
$this->jobOffers = $jobOffers;
return $this;
}
/**
* @return mixed
*/
public function getPromotedJobOffers() {
return $this->promotedJobOffers;
}
/**
* @param mixed $promotedJobOffers
*
* @return \App\Entity\PaymentPlan
*/
public function setPromotedJobOffers($promotedJobOffers): self {
// валидацията засега оставям в Admin PaymentPlanController, за да вади user-friendly грешка
// if ($promotedJobOffers > $this->getJobOffers()) {
// throw new ValidatorException(sprintf('Promoted job offers count (%s) should be less than all job offers count (%d).', (int)$promotedJobOffers, (int)$this->getJobOffers()));
// }
$this->promotedJobOffers = $promotedJobOffers;
return $this;
}
/**
* @return mixed
*/
public function getPrice() {
return $this->price;
}
/**
* @param mixed $price
*
* @return \App\Entity\PaymentPlan
*/
public function setPrice($price): self {
$this->price = $price;
return $this;
}
/**
* @return mixed
*/
public function getEuroPrice() {
return number_format(round($this->price / 1.95583), 2, '.', '');
}
/**
* @return mixed
*/
public function getLevaPrice() {
return number_format(($this->price * 1.95583), 2, '.', '');
}
/**
* @return bool
*/
public function isExclusive(): bool {
return $this->exclusive;
}
/**
* @param bool $exclusive
*
* @return \App\Entity\PaymentPlan
*/
public function setExclusive(bool $exclusive): self {
$this->exclusive = $exclusive;
return $this;
}
/**
* @return bool
*/
public function isAddon(): bool {
return $this->addon;
}
/**
* @param bool $addon
*
* @return \App\Entity\PaymentPlan
*/
public function setAddon(bool $addon): self {
$this->addon = $addon;
return $this;
}
/**
* @return bool
*/
public function isActive(): bool {
return $this->active;
}
/**
* @param bool $active
*
* @return \App\Entity\PaymentPlan
*/
public function setActive(bool $active): self {
$this->active = $active;
return $this;
}
/**
* @return bool
*/
public function isPublic(): bool {
return $this->public;
}
/**
* @param bool $public
*
* @return \App\Entity\PaymentPlan
*/
public function setPublic(bool $public): self {
$this->public = $public;
return $this;
}
/**
* @return bool
*/
public function isPromotedJobPackage(): bool {
return $this->promotedJobPackage;
}
/**
* @param bool $promotedJobPackage
*
* @return \App\Entity\PaymentPlan
*/
public function setPromotedJobPackage(bool $promotedJobPackage): self {
$this->promotedJobPackage = $promotedJobPackage;
return $this;
}
/**
* @return float
*/
public function getPriceBgn(): float {
return $this->priceBgn;
}
/**
* @param float $price
*
* @return Payment
*/
public function setPriceBgn(float $priceBgn): self {
$this->priceBgn = $priceBgn;
return $this;
}
public function getName(){
return $this->translate()->getName();
}
public function __get($name)
{
return PropertyAccess::createPropertyAccessor()->getValue($this->translate(), $name);
}
public function __toString(){
return (string)$this->translate()->getName(); //or anything else
}
/**
* Specify data which should be serialized to JSON
*
* @link https://php.net/manual/en/jsonserializable.jsonserialize.php
* @return mixed data which can be serialized by <b>json_encode</b>,
* which is a value of any type other than a resource.
* @since 5.4.0
*/
public function jsonSerialize() {
return [
'id' => $this->getId(),
'name' => $this->translate()->getName(),
'description' => $this->translate()->getDescription(),
'period' => $this->getPeriod(),
'jobOffers' => $this->getJobOffers(),
'price' => $this->getPrice(),
// 'priceEuro' => $this->getEuroPrice(),
// 'priceLeva' => $this->getLevaPrice(),
'exclusive' => $this->isExclusive(),
'addon' => $this->isAddon(),
'promotedJobPackage' => $this->isPromotedJobPackage()
];
}
}