src/Entity/Package.php line 15
<?phpnamespace App\Entity;use App\Repository\PackageRepository;use App\Traits\TimeStampTrait;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Validator\Constraints as Assert;#[ORM\Entity(repositoryClass: PackageRepository::class)]class Package{use TimeStampTrait;public const STARTER = 'Starter';public const STANDARD = 'Standard';public const PRO = 'Pro';public const BUSINESS = 'Business';#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column(type: 'integer')]private ?int $id = null;/*** Billing type (e.g. "monthly", "yearly") or any internal categorization you use.* Avoid “interval” (reserved in SQL).*/#[ORM\Column(length: 100)]#[Assert\NotBlank]#[Assert\Length(max: 100)]private ?string $type = null;#[ORM\Column(length: 255)]#[Assert\NotBlank]#[Assert\Length(max: 255)]private ?string $description = null;#[ORM\Column(options: ['default' => true])]private ?bool $publish = true;#[ORM\OneToMany(mappedBy: 'package', targetEntity: Subscription::class)]private Collection $entreprisePackages;#[ORM\Column(length: 25)]#[Assert\NotBlank]#[Assert\Length(max: 25)]private ?string $name = null;// Decimal columns map to string in PHP with Doctrine.#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2)]#[Assert\NotBlank]#[Assert\Regex('/^\d+(\.\d{1,2})?$/')]private ?string $price = null; // monthly price#[ORM\OneToMany(mappedBy: 'package', targetEntity: Entreprise::class)]private Collection $entreprises;#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true)]#[Assert\Regex('/^\d+(\.\d{1,2})?$/')]private ?string $priceannuel = null;/*** Maximum allowed “lots/units” for this package. NULL = unlimited.*/#[ORM\Column(type: 'integer', nullable: true, options: ['unsigned' => true])]#[Assert\Positive]private ?int $maxUnits = null;/*** Number of free trial months (default: 2).*/#[ORM\Column(type: 'smallint', options: ['unsigned' => true, 'default' => 2])]#[Assert\PositiveOrZero]private int $trialMonths = 2;public function __construct(){$this->entreprisePackages = new ArrayCollection();$this->entreprises = new ArrayCollection();}// -----------------------// Core getters / setters// -----------------------public function getId(): ?int{return $this->id;}public function setId(?int $id): void{$this->id = $id;}public function getType(): ?string{return $this->type;}public function setType(?string $type): void{$this->type = $type;}public function getDescription(): ?string{return $this->description;}public function setDescription(?string $description): void{$this->description = $description;}public function getPublish(): ?bool{return $this->publish;}public function setPublish(?bool $publish): void{$this->publish = $publish;}/*** @return Collection<int, Subscription>*/public function getEntreprisePackages(): Collection{return $this->entreprisePackages;}public function addEntreprisePackage(Subscription $entreprisePackage): static{if (!$this->entreprisePackages->contains($entreprisePackage)) {$this->entreprisePackages->add($entreprisePackage);$entreprisePackage->setPackage($this);}return $this;}public function removeEntreprisePackage(Subscription $entreprisePackage): static{if ($this->entreprisePackages->removeElement($entreprisePackage)) {if ($entreprisePackage->getPackage() === $this) {$entreprisePackage->setPackage(null);}}return $this;}public function getName(): ?string{return $this->name;}public function setName(string $name): static{$this->name = $name;return $this;}public function getPrice(): ?string{return $this->price;}public function setPrice(string $price): static{$this->price = $price;return $this;}/*** @return Collection<int, Entreprise>*/public function getEntreprises(): Collection{return $this->entreprises;}public function addEntreprise(Entreprise $entreprise): static{if (!$this->entreprises->contains($entreprise)) {$this->entreprises->add($entreprise);$entreprise->setPackage($this);}return $this;}public function removeEntreprise(Entreprise $entreprise): static{if ($this->entreprises->removeElement($entreprise)) {if ($entreprise->getPackage() === $this) {$entreprise->setPackage(null);}}return $this;}public function getPriceannuel(): ?string{return $this->priceannuel;}public function setPriceannuel(?string $priceannuel): static{$this->priceannuel = $priceannuel;return $this;}public function getMaxUnits(): ?int{return $this->maxUnits;}public function setMaxUnits(?int $maxUnits): static{$this->maxUnits = $maxUnits;return $this;}public function getTrialMonths(): int{return $this->trialMonths;}public function setTrialMonths(int $trialMonths): static{$this->trialMonths = $trialMonths;return $this;}// -------------// Helper API// -------------public function hasUnlimitedUnits(): bool{return $this->maxUnits === null;}public function getLotsLimitLabel(): string{return $this->hasUnlimitedUnits() ? 'Illimité' : (string)$this->maxUnits;}/** Float accessors for easier math (Doctrine stores DECIMAL as string) */public function getMonthlyPriceFloat(): ?float{return $this->price !== null ? (float)$this->price : null;}public function getAnnualPriceFloat(): ?float{return $this->priceannuel !== null ? (float)$this->priceannuel : null;}/** Trial end from a given start date (e.g., signup date) */public function getTrialEndFrom(\DateTimeInterface $start): \DateTimeImmutable{$dt = \DateTimeImmutable::createFromInterface($start);return $dt->modify('+' . max(0, $this->trialMonths) . ' months');}public function __toString(): string{return sprintf('%s (%s)', $this->name ?? 'Package', $this->type ?? 'type');}}////namespace App\Entity;////use App\Repository\PackageRepository;//use App\Traits\TimeStampTrait;//use Doctrine\Common\Collections\ArrayCollection;//use Doctrine\Common\Collections\Collection;//use Doctrine\DBAL\Types\Types;//use Doctrine\ORM\Mapping as ORM;////#[ORM\Entity(repositoryClass: PackageRepository::class)]//class Package//{// use TimeStampTrait;//// #[ORM\Id]// #[ORM\GeneratedValue]// #[ORM\Column(type: 'integer')]// private ?int $id = null;//// #[ORM\Column(length: 100)]// private ?string $type = null;//// #[ORM\Column(length: 255)]// private ?string $description = null;//// #[ORM\Column]// private ?bool $publish = null;//// #[ORM\OneToMany(mappedBy: 'package', targetEntity: Subscription::class)]// private Collection $entreprisePackages;//// #[ORM\Column(length: 25)]// private ?string $name = null;//// #[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2)]// private ?string $price = null;//// #[ORM\OneToMany(mappedBy: 'package', targetEntity: Entreprise::class)]// private Collection $entreprises;//// #[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2, nullable: true)]// private ?string $priceannuel = null;//// public function __construct()// {// $this->entreprisePackages = new ArrayCollection();// $this->entreprises = new ArrayCollection();// }//// /**// * @return int|null// */// public function getId(): ?int// {// return $this->id;// }//// /**// * @param int|null $id// */// public function setId(?int $id): void// {// $this->id = $id;// }//// /**// * @return string|null// */// public function getType(): ?string// {// return $this->type;// }//// /**// * @param string|null $type// */// public function setType(?string $type): void// {// $this->type = $type;// }//// /**// * @return string|null// */// public function getDescription(): ?string// {// return $this->description;// }//// /**// * @param string|null $description// */// public function setDescription(?string $description): void// {// $this->description = $description;// }//// /**// * @return bool|null// */// public function getPublish(): ?bool// {// return $this->publish;// }//// /**// * @param bool|null $publish// */// public function setPublish(?bool $publish): void// {// $this->publish = $publish;// }//// /**// * @return Collection<int, Subscription>// */// public function getEntreprisePackages(): Collection// {// return $this->entreprisePackages;// }//// public function addEntreprisePackage(Subscription $entreprisePackage): static// {// if (!$this->entreprisePackages->contains($entreprisePackage)) {// $this->entreprisePackages->add($entreprisePackage);// $entreprisePackage->setPackage($this);// }//// return $this;// }//// public function removeEntreprisePackage(Subscription $entreprisePackage): static// {// if ($this->entreprisePackages->removeElement($entreprisePackage)) {// // set the owning side to null (unless already changed)// if ($entreprisePackage->getPackage() === $this) {// $entreprisePackage->setPackage(null);// }// }//// return $this;// }//// public function getName(): ?string// {// return $this->name;// }//// public function setName(string $name): static// {// $this->name = $name;//// return $this;// }//// public function getPrice(): ?string// {// return $this->price;// }//// public function setPrice(string $price): static// {// $this->price = $price;//// return $this;// }//// /**// * @return Collection<int, Entreprise>// */// public function getEntreprises(): Collection// {// return $this->entreprises;// }//// public function addEntreprise(Entreprise $entreprise): static// {// if (!$this->entreprises->contains($entreprise)) {// $this->entreprises->add($entreprise);// $entreprise->setPackage($this);// }//// return $this;// }//// public function removeEntreprise(Entreprise $entreprise): static// {// if ($this->entreprises->removeElement($entreprise)) {// // set the owning side to null (unless already changed)// if ($entreprise->getPackage() === $this) {// $entreprise->setPackage(null);// }// }//// return $this;// }//// public function getPriceannuel(): ?string// {// return $this->priceannuel;// }//// public function setPriceannuel(?string $priceannuel): static// {// $this->priceannuel = $priceannuel;//// return $this;// }//}