<?php
namespace App\Entity\Sales;
use App\Repository\SidebarPlacementRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* Сортировка будет выглядеть следующим образом:
* 1. Ультра вип
* 2. Вип
*/
#[ORM\Table(name: 'sidebar_placements')]
#[ORM\Entity(repositoryClass: SidebarPlacementRepository::class)]
#[ORM\InheritanceType('SINGLE_TABLE')]
#[ORM\DiscriminatorColumn(name: 'entity_type', type: 'string', length: 12)]
#[ORM\DiscriminatorMap(['profile' => Profile\SidebarPlacement::class, 'saloon' => Saloon\SidebarPlacement::class])]
abstract class SidebarPlacement
{
// Значение группы влияет на порядок сортировки на сайте
const POSITION_GROUP_ULTRA_VIP = 200;
const POSITION_GROUP_VIP = 100;
#[ORM\Id]
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
protected int $id;
/**
* Тип размещения: ультра-вип, вип, стандарт и др.
*/
#[ORM\Column(name: 'type', type: 'smallint')]
protected int $type;
#[ORM\Column(name: 'shows', type: 'integer', options: ['default' => 0])]
protected int $shows = 0;
#[ORM\Column(name: 'is_new', type: 'boolean')]
protected bool $new;
/**
* Время добавления анкеты с указанным типом в список
*/
#[ORM\Column(name: 'placed_at', type: 'datetimetz_immutable')]
protected \DateTimeImmutable $placedAt;
/**
* Время следующего списания за показ в списке
*/
#[ORM\Column(name: 'placed_until', type: 'datetimetz_immutable')]
protected \DateTimeImmutable $placedUntil;
/**
* Цена, по которой было размещено (для продления по этой же цене)
*/
#[ORM\JoinColumn(name: 'placement_price_id', referencedColumnName: 'id', nullable: true)]
#[ORM\ManyToOne(targetEntity: PaidPlacementPrice::class)]
protected ?PaidPlacementPrice $placementPrice;
protected function __construct(SidebarPlacementType $type, PaidPlacementPrice $paidPlacementPrice, \DateTimeImmutable $placedAt, \DateTimeImmutable $placedUntil)
{
$this->type = $type->getValue();
$this->placedAt = $placedAt;
$this->placedUntil = $placedUntil;
$this->placementPrice = $paidPlacementPrice;
$this->new = true;
}
public function getId(): int
{
return $this->id;
}
public function getType(): SidebarPlacementType
{
return new SidebarPlacementType($this->type);
}
public function getPosition(): int
{
return $this->position;
}
public function getPlacedAt(): \DateTimeImmutable
{
return $this->placedAt;
}
public function getPlacedUntil(): \DateTimeImmutable
{
return $this->placedUntil;
}
public function getPlacementPrice(): ?PaidPlacementPrice
{
return $this->placementPrice;
}
public function getShows(): int
{
return $this->shows;
}
public function setShows(int $shows): void
{
$this->shows = $shows;
}
public function show(): void
{
$this->shows++;
}
public function setIsNew(bool $new): void
{
$this->new = $new;
}
public function isNew(): bool
{
return $this->new;
}
/**
* Продление показа анкеты в выдаче на сайте
*/
public function prolong(\DateTimeImmutable $placedUntil): void
{
$this->placedUntil = $placedUntil;
}
}