Browse Source

Opening : ajustements

packProduct
Guillaume 2 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

@@ -24,10 +24,7 @@ abstract class OpeningAdminController extends AbstractAdminController

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

return array_merge(
[
return [
ChoiceField::new('day')
->setRequired(true)
->setChoices(
@@ -48,9 +45,7 @@ abstract class OpeningAdminController extends AbstractAdminController
->setRequired(false)
->setFormat('H:mm'),
AssociationField::new('groupUser'),
],
$fields
);
];
}

public function configureCrud(Crud $crud): Crud

+ 2
- 1
Resolver/OpeningResolver.php View File

@@ -254,10 +254,11 @@ class OpeningResolver

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

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

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

@@ -25,44 +25,33 @@ class OpeningSolver
}

$count = 0;
$isClosingDay = false;

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

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

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);
if ($openingDay && $openingDay->$methodGetTime()) {

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


Loading…
Cancel
Save