src/Entity/Sales/SidebarPlacement.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Sales;
  3. use App\Repository\SidebarPlacementRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. /**
  6.  * Сортировка будет выглядеть следующим образом:
  7.  * 1. Ультра вип
  8.  * 2. Вип
  9.  */
  10. #[ORM\Table(name'sidebar_placements')]
  11. #[ORM\Entity(repositoryClassSidebarPlacementRepository::class)]
  12. #[ORM\InheritanceType('SINGLE_TABLE')]
  13. #[ORM\DiscriminatorColumn(name'entity_type'type'string'length12)]
  14. #[ORM\DiscriminatorMap(['profile' => Profile\SidebarPlacement::class, 'saloon' => Saloon\SidebarPlacement::class])]
  15. abstract class SidebarPlacement
  16. {
  17.     // Значение группы влияет на порядок сортировки на сайте
  18.     const POSITION_GROUP_ULTRA_VIP 200;
  19.     const POSITION_GROUP_VIP 100;
  20.     #[ORM\Id]
  21.     #[ORM\Column(name'id'type'integer')]
  22.     #[ORM\GeneratedValue(strategy'AUTO')]
  23.     protected int $id;
  24.     /**
  25.      * Тип размещения: ультра-вип, вип, стандарт и др.
  26.      */
  27.     #[ORM\Column(name'type'type'smallint')]
  28.     protected int $type;
  29.     #[ORM\Column(name'shows'type'integer'options: ['default' => 0])]
  30.     protected int $shows 0;
  31.     #[ORM\Column(name'is_new'type'boolean')]
  32.     protected bool $new;
  33.     /**
  34.      * Время добавления анкеты с указанным типом в список
  35.      */
  36.     #[ORM\Column(name'placed_at'type'datetimetz_immutable')]
  37.     protected \DateTimeImmutable $placedAt;
  38.     /**
  39.      * Время следующего списания за показ в списке
  40.      */
  41.     #[ORM\Column(name'placed_until'type'datetimetz_immutable')]
  42.     protected \DateTimeImmutable $placedUntil;
  43.     /**
  44.      * Цена, по которой было размещено (для продления по этой же цене)
  45.      */
  46.     #[ORM\JoinColumn(name'placement_price_id'referencedColumnName'id'nullabletrue)]
  47.     #[ORM\ManyToOne(targetEntityPaidPlacementPrice::class)]
  48.     protected ?PaidPlacementPrice $placementPrice;
  49.     protected function __construct(SidebarPlacementType $typePaidPlacementPrice $paidPlacementPrice\DateTimeImmutable $placedAt\DateTimeImmutable $placedUntil)
  50.     {
  51.         $this->type $type->getValue();
  52.         $this->placedAt $placedAt;
  53.         $this->placedUntil $placedUntil;
  54.         $this->placementPrice $paidPlacementPrice;
  55.         $this->new true;
  56.     }
  57.     public function getId(): int
  58.     {
  59.         return $this->id;
  60.     }
  61.     public function getType(): SidebarPlacementType
  62.     {
  63.         return new SidebarPlacementType($this->type);
  64.     }
  65.     public function getPosition(): int
  66.     {
  67.         return $this->position;
  68.     }
  69.     public function getPlacedAt(): \DateTimeImmutable
  70.     {
  71.         return $this->placedAt;
  72.     }
  73.     public function getPlacedUntil(): \DateTimeImmutable
  74.     {
  75.         return $this->placedUntil;
  76.     }
  77.     public function getPlacementPrice(): ?PaidPlacementPrice
  78.     {
  79.         return $this->placementPrice;
  80.     }
  81.     public function getShows(): int
  82.     {
  83.         return $this->shows;
  84.     }
  85.     public function setShows(int $shows): void
  86.     {
  87.         $this->shows $shows;
  88.     }
  89.     public function show(): void
  90.     {
  91.         $this->shows++;
  92.     }
  93.     public function setIsNew(bool $new): void
  94.     {
  95.         $this->new $new;
  96.     }
  97.     public function isNew(): bool
  98.     {
  99.         return $this->new;
  100.     }
  101.     /**
  102.      * Продление показа анкеты в выдаче на сайте
  103.      */
  104.     public function prolong(\DateTimeImmutable $placedUntil): void
  105.     {
  106.         $this->placedUntil $placedUntil;
  107.     }
  108. }