Browse Source

Opening : ajustements

packProduct
Guillaume 3 years ago
parent
commit
691353f558
3 changed files with 12 additions and 27 deletions
  1. +2
    -7
      Controller/Section/OpeningAdminController.php
  2. +2
    -1
      Resolver/OpeningResolver.php
  3. +8
    -19
      Solver/Section/OpeningSolver.php

+ 2
- 7
Controller/Section/OpeningAdminController.php View File



public function configureFields(string $pageName): iterable public function configureFields(string $pageName): iterable
{ {
$fields = parent::configureFields($pageName);

return array_merge(
[
return [
ChoiceField::new('day') ChoiceField::new('day')
->setRequired(true) ->setRequired(true)
->setChoices( ->setChoices(
->setRequired(false) ->setRequired(false)
->setFormat('H:mm'), ->setFormat('H:mm'),
AssociationField::new('groupUser'), AssociationField::new('groupUser'),
],
$fields
);
];
} }


public function configureCrud(Crud $crud): Crud public function configureCrud(Crud $crud): Crud

+ 2
- 1
Resolver/OpeningResolver.php View File



if (!$this->isOpenSale($section)) { if (!$this->isOpenSale($section)) {
$opening = $this->openingSolver->getNextOpeningOfOpening($date, $openingArray); $opening = $this->openingSolver->getNextOpeningOfOpening($date, $openingArray);

if ($opening) { if ($opening) {
return $this->openingSolver->getFormatedDateByFormatAndDelimiterDayTime( return $this->openingSolver->getFormatedDateByFormatAndDelimiterDayTime(
$date, $date,
$opening->getTimeStart(),
$opening->getTimeStart() ?: (new \DateTime())->setTime(0, 0),
$formatDate, $formatDate,
$delimiterDayTime $delimiterDayTime
); );

+ 8
- 19
Solver/Section/OpeningSolver.php View File

} }


$count = 0; $count = 0;
$isClosingDay = false;


do { do {
if ($count) { if ($count) {
$date->modify('+1 day'); $date->modify('+1 day');
} }
$weekDay = $date->format('N'); $weekDay = $date->format('N');
$isClosingDay = $this->$methodTestDay($weekDay, $openings);
$testDay = $this->$methodTestDay($weekDay, $openings);
$count++; $count++;
} while (!$isClosingDay && $count <= 7);
} while (!$testDay && $count <= 8);


if ($isClosingDay) {
if ($testDay) {
return $this->getOpeningByWeekday($weekDay, $openings); return $this->getOpeningByWeekday($weekDay, $openings);
} }


return null; return null;
} }


public function isOpeningDay(int $weekDay, array $openings): bool
protected function isOpeningDay(int $weekDay, array $openings): bool
{ {
return $this->isOpeningOrClosingDay($weekDay, $openings, 'opening');
return (bool) $this->getOpeningByWeekday($weekDay, $openings);
} }


public function isClosingDay(int $weekDay, array $openings): bool
protected function isClosingDay(int $weekDay, array $openings): bool
{ {
return $this->isOpeningOrClosingDay($weekDay, $openings, 'closing');
}

protected function isOpeningOrClosingDay(int $weekDay, array $openings, string $testOpeningOrClosing = 'opening')
{
if ($testOpeningOrClosing == 'opening') {
$methodGetTime = 'getTimeStart';
} else {
$methodGetTime = 'getTimeEnd';
}

$openingDay = $this->getOpeningByWeekday($weekDay, $openings); $openingDay = $this->getOpeningByWeekday($weekDay, $openings);
if ($openingDay && $openingDay->$methodGetTime()) {

if ($openingDay && $openingDay->getTimeEnd()) {
return true; return true;
} }



Loading…
Cancel
Save