|
|
@@ -8,6 +8,8 @@ use Lc\CaracoleBundle\Model\Section\OpeningInterface; |
|
|
|
use Lc\CaracoleBundle\Model\Section\SectionInterface; |
|
|
|
use Lc\CaracoleBundle\Model\Section\SectionModel; |
|
|
|
use Lc\CaracoleBundle\Repository\Order\OrderShopStore; |
|
|
|
use Lc\CaracoleBundle\Repository\Section\OpeningStore; |
|
|
|
use Lc\CaracoleBundle\Solver\Section\OpeningSolver; |
|
|
|
use Lc\SovBundle\Model\User\UserInterface; |
|
|
|
use Lc\SovBundle\Solver\Setting\SettingSolver; |
|
|
|
use Symfony\Component\Security\Core\Security; |
|
|
@@ -22,17 +24,23 @@ class OpeningResolver |
|
|
|
protected Security $security; |
|
|
|
protected OrderShopStore $orderShopStore; |
|
|
|
protected SettingSolver $settingSolver; |
|
|
|
protected OpeningStore $openingStore; |
|
|
|
protected OpeningSolver $openingSolver; |
|
|
|
|
|
|
|
public function __construct( |
|
|
|
SectionResolver $sectionResolver, |
|
|
|
Security $security, |
|
|
|
OrderShopStore $orderShopStore, |
|
|
|
SettingSolver $settingSolver |
|
|
|
SettingSolver $settingSolver, |
|
|
|
OpeningStore $openingStore, |
|
|
|
OpeningSolver $openingSolver |
|
|
|
) { |
|
|
|
$this->sectionResolver = $sectionResolver; |
|
|
|
$this->security = $security; |
|
|
|
$this->orderShopStore = $orderShopStore; |
|
|
|
$this->settingSolver = $settingSolver; |
|
|
|
$this->openingStore = $openingStore; |
|
|
|
$this->openingSolver = $openingSolver; |
|
|
|
} |
|
|
|
|
|
|
|
public function isOpenSale( |
|
|
@@ -43,10 +51,14 @@ class OpeningResolver |
|
|
|
// Initialisation |
|
|
|
$this->messages = []; |
|
|
|
|
|
|
|
if(is_null($section)) { |
|
|
|
if (is_null($section)) { |
|
|
|
$section = $this->sectionResolver->getCurrent(); |
|
|
|
} |
|
|
|
|
|
|
|
if (is_null($user)) { |
|
|
|
$user = $this->security->getUser(); |
|
|
|
} |
|
|
|
|
|
|
|
$date = new \DateTime(); |
|
|
|
|
|
|
|
// État des prise de commande (voir configuration de section) |
|
|
@@ -97,13 +109,13 @@ class OpeningResolver |
|
|
|
|
|
|
|
public function isOpenFullTime(SectionInterface $section = null) |
|
|
|
{ |
|
|
|
if(is_null($section)) { |
|
|
|
if (is_null($section)) { |
|
|
|
$section = $this->sectionResolver->getCurrent(); |
|
|
|
} |
|
|
|
|
|
|
|
$orderState = $this->settingSolver->getSettingValue($section, SectionSettingDefinition::SETTING_ORDER_STATE); |
|
|
|
|
|
|
|
if($orderState == SectionSettingDefinition::VALUE_ORDER_STATE_OPEN) { |
|
|
|
if ($orderState == SectionSettingDefinition::VALUE_ORDER_STATE_OPEN) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
@@ -113,14 +125,20 @@ class OpeningResolver |
|
|
|
// isHolidays |
|
|
|
public function isClosingPeriod(SectionInterface $section = null) |
|
|
|
{ |
|
|
|
if(is_null($section)) { |
|
|
|
if (is_null($section)) { |
|
|
|
$section = $this->sectionResolver->getCurrent(); |
|
|
|
} |
|
|
|
|
|
|
|
$date = new \DateTime(); |
|
|
|
|
|
|
|
$orderClosedStart = $this->settingSolver->getSettingValue($section, SectionSettingDefinition::SETTING_ORDER_CLOSED_START); |
|
|
|
$orderClosedEnd = $this->settingSolver->getSettingValue($section, SectionSettingDefinition::SETTING_ORDER_CLOSED_END); |
|
|
|
$orderClosedStart = $this->settingSolver->getSettingValue( |
|
|
|
$section, |
|
|
|
SectionSettingDefinition::SETTING_ORDER_CLOSED_START |
|
|
|
); |
|
|
|
$orderClosedEnd = $this->settingSolver->getSettingValue( |
|
|
|
$section, |
|
|
|
SectionSettingDefinition::SETTING_ORDER_CLOSED_END |
|
|
|
); |
|
|
|
|
|
|
|
if ($orderClosedStart && $orderClosedEnd && $date >= $orderClosedStart && $date <= $orderClosedEnd) { |
|
|
|
return true; |
|
|
@@ -136,7 +154,10 @@ class OpeningResolver |
|
|
|
->setSection($section) |
|
|
|
->countValidByCurrentCycle(); |
|
|
|
|
|
|
|
$orderMaximumPerCycle = $this->settingSolver->getSettingValue($section, SectionSettingDefinition::SETTING_ORDER_MAXIMUM_PER_CYCLE); |
|
|
|
$orderMaximumPerCycle = $this->settingSolver->getSettingValue( |
|
|
|
$section, |
|
|
|
SectionSettingDefinition::SETTING_ORDER_MAXIMUM_PER_CYCLE |
|
|
|
); |
|
|
|
if ($orderMaximumPerCycle && $countOrderShopCycle >= $orderMaximumPerCycle) { |
|
|
|
return true; |
|
|
|
} |
|
|
@@ -185,41 +206,73 @@ class OpeningResolver |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public function getDateEndCurrentSale(SectionInterface $section = null, $formatDate = '', $delimiterDayTime = 'à') |
|
|
|
{ |
|
|
|
if(is_null($section)) { |
|
|
|
// getDateEndCurrentSale |
|
|
|
public function getFormatedDateClosingCurrentSale( |
|
|
|
SectionInterface $section = null, |
|
|
|
$formatDate = '', |
|
|
|
$delimiterDayTime = 'à' |
|
|
|
) { |
|
|
|
if (is_null($section)) { |
|
|
|
$section = $this->sectionResolver->getCurrent(); |
|
|
|
} |
|
|
|
|
|
|
|
// @TODO : à réécrire |
|
|
|
$date = new \DateTime(); |
|
|
|
$openingArray = $this->openingStore |
|
|
|
->setSection($section) |
|
|
|
->get(); |
|
|
|
|
|
|
|
if ($this->isOpenSale($section)) { |
|
|
|
$openingClosing = $this->openingSolver->getNextOpeningOfClosing($date, $openingArray); |
|
|
|
if ($openingClosing) { |
|
|
|
return $this->openingSolver->getFormatedDateByFormatAndDelimiterDayTime( |
|
|
|
$date, |
|
|
|
$openingClosing->getTimeEnd(), |
|
|
|
$formatDate, |
|
|
|
$delimiterDayTime |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return ''; |
|
|
|
} |
|
|
|
|
|
|
|
public function getDateBeginNextSale(SectionInterface $section = null, $formatDate = '', $delimiterDayTime = 'à') |
|
|
|
{ |
|
|
|
if(is_null($section)) { |
|
|
|
// getDateBeginNextSale |
|
|
|
public function getFormatedDateOpeningNextSale( |
|
|
|
SectionInterface $section = null, |
|
|
|
$formatDate = '', |
|
|
|
$delimiterDayTime = 'à' |
|
|
|
) { |
|
|
|
if (is_null($section)) { |
|
|
|
$section = $this->sectionResolver->getCurrent(); |
|
|
|
} |
|
|
|
|
|
|
|
// @TODO : à réécrire |
|
|
|
} |
|
|
|
|
|
|
|
public function getMessages(): array |
|
|
|
{ |
|
|
|
return $this->messages; |
|
|
|
} |
|
|
|
$date = new \DateTime(); |
|
|
|
$openingArray = $this->openingStore |
|
|
|
->setSection($section) |
|
|
|
->get(); |
|
|
|
|
|
|
|
if (!$this->isOpenSale($section)) { |
|
|
|
$opening = $this->openingSolver->getNextOpeningOfOpening($date, $openingArray); |
|
|
|
if ($opening) { |
|
|
|
return $this->openingSolver->getFormatedDateByFormatAndDelimiterDayTime( |
|
|
|
$date, |
|
|
|
$opening->getTimeStart(), |
|
|
|
$formatDate, |
|
|
|
$delimiterDayTime |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function addMessage(string $message): void |
|
|
|
{ |
|
|
|
$this->messages[] = $message; |
|
|
|
return ''; |
|
|
|
} |
|
|
|
|
|
|
|
public function isOpenSaleOnlyComplementaryOrders(Section $section = null, UserInterface $user = null) |
|
|
|
{ |
|
|
|
if(is_null($section)) { |
|
|
|
if (is_null($section)) { |
|
|
|
$section = $this->sectionResolver->getCurrent(); |
|
|
|
} |
|
|
|
|
|
|
|
if(is_null($user)) { |
|
|
|
if (is_null($user)) { |
|
|
|
$user = $this->security->getUser(); |
|
|
|
} |
|
|
|
|
|
|
@@ -230,4 +283,16 @@ class OpeningResolver |
|
|
|
&& $this->isMaximumOrderCycleAchieved($section) |
|
|
|
&& count($orderShopsUser) > 0; |
|
|
|
} |
|
|
|
|
|
|
|
public function getMessages(): array |
|
|
|
{ |
|
|
|
return $this->messages; |
|
|
|
} |
|
|
|
|
|
|
|
public function addMessage(string $message): void |
|
|
|
{ |
|
|
|
$this->messages[] = $message; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |