wip: implement admin crud
This commit is contained in:
1 parent
306cd6bec4
commit
e902a5e298
78 files changed
+2555
-101
No files matched your search
@@ -9,6 +9,8 @@ use App\Entity\TimestampableEntityInterface;
|
||||
use App\Repository\Groups\AccommodationPriceRepository;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
|
||||
#[ORM\Entity(repositoryClass: AccommodationPriceRepository::class)]
|
||||
class AccommodationPrice implements BlameableEntityInterface, TimestampableEntityInterface
|
||||
@@ -26,23 +28,44 @@ class AccommodationPrice implements BlameableEntityInterface, TimestampableEntit
|
||||
private ?Accommodation $accommodation = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
|
||||
#[Assert\NotNull(message: 'required')]
|
||||
private ?\DateTimeImmutable $dateFrom = null;
|
||||
|
||||
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
|
||||
#[Assert\NotNull(message: 'required')]
|
||||
#[Assert\GreaterThan(propertyPath: 'dateFrom', message: 'Das Bis-Datum muss nach dem Von-Datum liegen')]
|
||||
private ?\DateTimeImmutable $dateTo = null;
|
||||
|
||||
#[ORM\Column]
|
||||
#[Assert\NotNull(message: 'required')]
|
||||
private ?int $includedPax = null;
|
||||
|
||||
#[ORM\Column]
|
||||
#[Assert\NotNull(message: 'required')]
|
||||
private ?int $pricePerNight = null;
|
||||
|
||||
#[ORM\Column]
|
||||
#[Assert\NotNull(message: 'required')]
|
||||
private ?int $priceAdditionalPerson = null;
|
||||
|
||||
#[ORM\Column]
|
||||
#[Assert\NotNull(message: 'required')]
|
||||
private ?int $minNights = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?int $pricePerNightOverride = null;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?int $priceAdditionalPersonOverride = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private bool $acceptUndersubscription = false;
|
||||
|
||||
public function __clone()
|
||||
{
|
||||
$this->id = null;
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
@@ -131,4 +154,71 @@ class AccommodationPrice implements BlameableEntityInterface, TimestampableEntit
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPricePerNightOverride(): ?int
|
||||
{
|
||||
return $this->pricePerNightOverride;
|
||||
}
|
||||
|
||||
public function setPricePerNightOverride(?int $pricePerNightOverride): self
|
||||
{
|
||||
$this->pricePerNightOverride = $pricePerNightOverride;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEffectivePricePerNight(): int
|
||||
{
|
||||
return $this->pricePerNightOverride ?? $this->pricePerNight;
|
||||
}
|
||||
|
||||
public function getPriceAdditionalPersonOverride(): ?int
|
||||
{
|
||||
return $this->priceAdditionalPersonOverride;
|
||||
}
|
||||
|
||||
public function setPriceAdditionalPersonOverride(?int $priceAdditionalPersonOverride): self
|
||||
{
|
||||
$this->priceAdditionalPersonOverride = $priceAdditionalPersonOverride;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEffectivePriceAdditionalPerson(): int
|
||||
{
|
||||
return $this->priceAdditionalPersonOverride ?? $this->priceAdditionalPerson;
|
||||
}
|
||||
|
||||
public function isAcceptUndersubscription(): bool
|
||||
{
|
||||
return $this->acceptUndersubscription;
|
||||
}
|
||||
|
||||
public function setAcceptUndersubscription(bool $acceptUndersubscription): self
|
||||
{
|
||||
$this->acceptUndersubscription = $acceptUndersubscription;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
#[Assert\Callback]
|
||||
public function assertDatesValid(ExecutionContextInterface $context): void
|
||||
{
|
||||
// we only check new entities
|
||||
if (null !== $this->getId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// come on, we need something to work with
|
||||
if (null === $this->getDateFrom() || null === $this->getDateTo()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->getDateFrom() < new \DateTimeImmutable()) {
|
||||
$context
|
||||
->buildViolation('Das Von-Datum darf nicht in der Vergangenheit liegen')
|
||||
->atPath('dateFrom')
|
||||
->addViolation();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user