<?php | |||||
namespace Lc\CaracoleBundle\Controller\Section; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TimeField; | |||||
use Lc\CaracoleBundle\Controller\AdminControllerTrait; | |||||
use Lc\SovBundle\Controller\AbstractAdminController; | |||||
abstract class OpeningAdminController extends AbstractAdminController | |||||
{ | |||||
use AdminControllerTrait; | |||||
public function configureFields(string $pageName): iterable | |||||
{ | |||||
$fields = parent::configureFields($pageName); | |||||
return array_merge( | |||||
[ | |||||
ChoiceField::new('day') | |||||
->setRequired(true) | |||||
->setChoices( | |||||
[ | |||||
'Lundi' => 1, | |||||
'Mardi' => 2, | |||||
'Mercredi' => 3, | |||||
'Jeudi' => 4, | |||||
'Vendredi' => 5, | |||||
'Samedi' => 6, | |||||
'Dimanche' => 7, | |||||
] | |||||
), | |||||
TimeField::new('timeStart') | |||||
->setRequired(false) | |||||
->setFormat('H:mm'), | |||||
TimeField::new('timeEnd') | |||||
->setRequired(false) | |||||
->setFormat('H:mm'), | |||||
AssociationField::new('groupUser'), | |||||
], | |||||
$fields | |||||
); | |||||
} | |||||
public function configureCrud(Crud $crud): Crud | |||||
{ | |||||
$crud = parent::configureCrud($crud); | |||||
$crud->setDefaultSort(['day' => 'ASC']); | |||||
return $crud; | |||||
} | |||||
} |
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField; | use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; | use EasyCorp\Bundle\EasyAdminBundle\Field\TextField; | ||||
use Lc\CaracoleBundle\Controller\AdminControllerTrait; | use Lc\CaracoleBundle\Controller\AdminControllerTrait; | ||||
use Lc\CaracoleBundle\Form\Section\OpeningsFormType; | |||||
use Lc\CaracoleBundle\Model\Section\SectionModel; | use Lc\CaracoleBundle\Model\Section\SectionModel; | ||||
use Lc\SovBundle\Controller\AbstractAdminController; | use Lc\SovBundle\Controller\AbstractAdminController; | ||||
use Lc\SovBundle\Field\BooleanField; | use Lc\SovBundle\Field\BooleanField; | ||||
use Lc\SovBundle\Field\CKEditorField; | use Lc\SovBundle\Field\CKEditorField; | ||||
use Lc\SovBundle\Field\StatusField; | use Lc\SovBundle\Field\StatusField; | ||||
use Symfony\Component\HttpFoundation\Request; | |||||
use Symfony\Component\Routing\Annotation\Route; | |||||
abstract class SectionAdminController extends AbstractAdminController | abstract class SectionAdminController extends AbstractAdminController | ||||
{ | { |
<?php | |||||
namespace Lc\CaracoleBundle\Definition; | |||||
use Lc\SovBundle\Definition\AbstractSettingDefinition; | |||||
class SectionSettingDefinition extends AbstractSettingDefinition implements SectionSettingDefinitionInterface | |||||
{ | |||||
const CATEGORY_GENERAL = 'general'; | |||||
const SETTING_REFERENCE_PREFIX = 'orderReferencePrefix'; | |||||
const SETTING_ORDER_STATE = 'orderState'; | |||||
const SETTING_ORDER_CLOSED_START = 'orderClosedStart'; | |||||
const SETTING_ORDER_CLOSED_END = 'orderClosedEnd'; | |||||
const SETTING_ORDER_MAXIMUM_PER_CYCLE = 'orderMaximumPerCycle'; | |||||
const VALUE_ORDER_STATE_DEFAULT = 'default'; | |||||
const VALUE_ORDER_STATE_OPEN = 'open'; | |||||
const VALUE_ORDER_STATE_CLOSED = 'closed'; | |||||
public function __construct() | |||||
{ | |||||
$this->addSettingText( | |||||
[ | |||||
'name' => self::SETTING_REFERENCE_PREFIX, | |||||
'category' => self::CATEGORY_GENERAL, | |||||
] | |||||
); | |||||
$this->addSettingSelect( | |||||
[ | |||||
'name' => self::SETTING_ORDER_STATE, | |||||
'category' => self::CATEGORY_GENERAL, | |||||
'choices' => [ | |||||
'Suivant configuration ouvertures' => self::VALUE_ORDER_STATE_DEFAULT, | |||||
'Ouvertes' => self::VALUE_ORDER_STATE_OPEN, | |||||
'Fermées' => self::VALUE_ORDER_STATE_CLOSED, | |||||
], | |||||
'default' => self::VALUE_ORDER_STATE_DEFAULT | |||||
] | |||||
); | |||||
$this->addSettingDate( | |||||
[ | |||||
'name' => self::SETTING_ORDER_CLOSED_START, | |||||
'category' => self::CATEGORY_GENERAL, | |||||
] | |||||
); | |||||
$this->addSettingDate( | |||||
[ | |||||
'name' => self::SETTING_ORDER_CLOSED_END, | |||||
'category' => self::CATEGORY_GENERAL, | |||||
] | |||||
); | |||||
$this->addSettingText( | |||||
[ | |||||
'name' => self::SETTING_ORDER_MAXIMUM_PER_CYCLE, | |||||
'category' => self::CATEGORY_GENERAL, | |||||
] | |||||
); | |||||
} | |||||
public function getCategories() | |||||
{ | |||||
return [ | |||||
self::CATEGORY_GENERAL, | |||||
]; | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\EventSubscriber; | |||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface; | |||||
use Lc\CaracoleBundle\Factory\Setting\MerchantSettingFactory; | |||||
use Lc\CaracoleBundle\Factory\Setting\SectionSettingFactory; | |||||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | |||||
use Lc\CaracoleBundle\Definition\SectionSettingDefinitionInterface; | |||||
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository; | |||||
use Lc\CaracoleBundle\Repository\Section\OpeningRepositoryQuery; | |||||
use Lc\CaracoleBundle\Repository\Section\SectionRepository; | |||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |||||
use Symfony\Component\HttpKernel\KernelEvents; | |||||
class OpeningEventSubscriber implements EventSubscriberInterface | |||||
{ | |||||
protected $entityManager; | |||||
protected $openingRepositoryQuery; | |||||
public function __construct( | |||||
EntityManagerInterface $entityManager, | |||||
OpeningRepositoryQuery $openingRepositoryQuery | |||||
) { | |||||
$this->entityManager = $entityManager; | |||||
$this->openingRepositoryQuery = $openingRepositoryQuery; | |||||
} | |||||
public static function getSubscribedEvents() | |||||
{ | |||||
return [ | |||||
KernelEvents::CONTROLLER => ['initOpenings'] | |||||
]; | |||||
} | |||||
public function initOpenings() | |||||
{ | |||||
} | |||||
} |
protected $sectionSettingFactory; | protected $sectionSettingFactory; | ||||
public function __construct( | public function __construct( | ||||
EntityManagerInterface $em, | |||||
MerchantSettingDefinitionInterface $merchantSettingDefinition, | |||||
SectionSettingDefinitionInterface $sectionSettingDefinition, | |||||
MerchantRepository $merchantRepository, | |||||
SectionRepository $sectionRepository, | |||||
MerchantSettingFactory $merchantSettingFactory, | |||||
SectionSettingFactory $sectionSettingFactory | |||||
) | |||||
{ | |||||
EntityManagerInterface $em, | |||||
MerchantSettingDefinitionInterface $merchantSettingDefinition, | |||||
SectionSettingDefinitionInterface $sectionSettingDefinition, | |||||
MerchantRepository $merchantRepository, | |||||
SectionRepository $sectionRepository, | |||||
MerchantSettingFactory $merchantSettingFactory, | |||||
SectionSettingFactory $sectionSettingFactory | |||||
) { | |||||
$this->em = $em; | $this->em = $em; | ||||
$this->merchantRepository = $merchantRepository; | $this->merchantRepository = $merchantRepository; | ||||
$this->sectionRepository = $sectionRepository; | $this->sectionRepository = $sectionRepository; | ||||
public static function getSubscribedEvents() | public static function getSubscribedEvents() | ||||
{ | { | ||||
return [ | return [ | ||||
KernelEvents::CONTROLLER => ['initSettings'] | |||||
KernelEvents::CONTROLLER => ['initSettings'] | |||||
]; | ]; | ||||
} | } | ||||
public function initSettings() | public function initSettings() | ||||
{ | { | ||||
$this->initSettingsGeneric( | $this->initSettingsGeneric( | ||||
'merchant', | |||||
$this->merchantSettingDefinition->getSettings(), | |||||
$this->merchantRepository->findAll(), | |||||
$this->merchantSettingFactory | |||||
'merchant', | |||||
$this->merchantSettingDefinition->getSettings(), | |||||
$this->merchantRepository->findAll(), | |||||
$this->merchantSettingFactory | |||||
); | ); | ||||
$this->initSettingsGeneric( | $this->initSettingsGeneric( | ||||
'section', | |||||
$this->sectionSettingDefinition->getSettings(), | |||||
$this->sectionRepository->findAll(), | |||||
$this->sectionSettingFactory | |||||
'section', | |||||
$this->sectionSettingDefinition->getSettings(), | |||||
$this->sectionRepository->findAll(), | |||||
$this->sectionSettingFactory | |||||
); | ); | ||||
} | } | ||||
public function initSettingsGeneric($type, $settings, $entities, $factory) | public function initSettingsGeneric($type, $settings, $entities, $factory) | ||||
} | } | ||||
if ($createEntitySetting) { | if ($createEntitySetting) { | ||||
$entitySetting = $factory->create( | |||||
[ | |||||
$type => $entity, | |||||
'name' => $setting['name'], | |||||
$setting['field'] => isset($setting['default']) ? $setting['default'] : null, | |||||
] | |||||
); | |||||
if ($type == 'section') { | |||||
$factory->setSection($entity); | |||||
} elseif ($type == 'merchant') { | |||||
$factory->setMerchant($entity); | |||||
} | |||||
$text = null; | |||||
$date = null; | |||||
$file = null; | |||||
$fieldValue = isset($setting['default']) ? $setting['default'] : null; | |||||
if ($setting['field'] == 'text') { | |||||
$text = $fieldValue; | |||||
} elseif ($setting['field'] == 'date') { | |||||
$date = $fieldValue; | |||||
} elseif ($setting['field'] == 'file') { | |||||
$file = $fieldValue; | |||||
} | |||||
$entitySetting = $factory->create($setting['name'], $text, $date, $file); | |||||
$this->em->persist($entitySetting); | $this->em->persist($entitySetting); | ||||
} | } | ||||
} else { | } else { | ||||
if ($entitySetting->getValue() === null | if ($entitySetting->getValue() === null | ||||
&& isset($setting['default']) | |||||
&& $setting['default'] !== null) { | |||||
&& isset($setting['default']) | |||||
&& $setting['default'] !== null) { | |||||
$methodSetValue = 'set' . ucfirst($setting['field']); | $methodSetValue = 'set' . ucfirst($setting['field']); | ||||
$entitySetting->$methodSetValue($setting['default']); | $entitySetting->$methodSetValue($setting['default']); | ||||
$this->em->update($entitySetting); | $this->em->update($entitySetting); |
<?php | |||||
namespace Lc\CaracoleBundle\Factory\Section; | |||||
use App\Entity\Section\Opening; | |||||
use Lc\CaracoleBundle\Factory\SectionFactoryTrait; | |||||
use Lc\SovBundle\Factory\AbstractFactory; | |||||
use Lc\SovBundle\Model\User\GroupUserInterface; | |||||
class OpeningFactory extends AbstractFactory implements OpeningFactoryInterface | |||||
{ | |||||
use SectionFactoryTrait; | |||||
public function create( | |||||
int $day, | |||||
\DateTime $timeStart = null, | |||||
\DateTime $timeEnd = null, | |||||
GroupUserInterface $groupUser = null | |||||
): Opening { | |||||
$opening = new Opening(); | |||||
$opening->setSection($this->section); | |||||
$opening->setTimeStart($timeStart); | |||||
$opening->setTimeEnd($timeEnd); | |||||
$opening->setGroupUser($groupUser); | |||||
return $opening; | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Factory\Section; | |||||
interface OpeningFactoryInterface | |||||
{ | |||||
} |
use App\Entity\Setting\MerchantSetting; | use App\Entity\Setting\MerchantSetting; | ||||
use Lc\CaracoleBundle\Factory\MerchantFactoryTrait; | use Lc\CaracoleBundle\Factory\MerchantFactoryTrait; | ||||
use Lc\SovBundle\Factory\AbstractFactory; | use Lc\SovBundle\Factory\AbstractFactory; | ||||
use Lc\SovBundle\Model\File\FileInterface; | |||||
class MerchantSettingFactory extends AbstractFactory | class MerchantSettingFactory extends AbstractFactory | ||||
{ | { | ||||
use MerchantFactoryTrait; | use MerchantFactoryTrait; | ||||
public function create() | |||||
public function create(string $name, string $text = null, \DateTime $date = null, FileInterface $file = null) | |||||
{ | { | ||||
$merchantSetting = new MerchantSetting(); | $merchantSetting = new MerchantSetting(); | ||||
$merchantSetting->setMerchant($this->merchant); | $merchantSetting->setMerchant($this->merchant); | ||||
$merchantSetting->setName($name); | |||||
$merchantSetting->setText($text); | |||||
$merchantSetting->setDate($date); | |||||
$merchantSetting->setFile($file); | |||||
return $merchantSetting; | return $merchantSetting; | ||||
} | } |
namespace Lc\CaracoleBundle\Factory\Setting; | namespace Lc\CaracoleBundle\Factory\Setting; | ||||
use App\Entity\Setting\SectionSetting; | use App\Entity\Setting\SectionSetting; | ||||
use Lc\CaracoleBundle\Factory\MerchantFactoryTrait; | |||||
use Lc\CaracoleBundle\Factory\SectionFactoryTrait; | use Lc\CaracoleBundle\Factory\SectionFactoryTrait; | ||||
use Lc\SovBundle\Factory\AbstractFactory; | use Lc\SovBundle\Factory\AbstractFactory; | ||||
use Lc\SovBundle\Model\File\FileInterface; | |||||
class SectionSettingFactory extends AbstractFactory | class SectionSettingFactory extends AbstractFactory | ||||
{ | { | ||||
use SectionFactoryTrait; | use SectionFactoryTrait; | ||||
public function create() | |||||
public function create(string $name, string $text = null, \DateTime $date = null, FileInterface $file = null) | |||||
{ | { | ||||
$sectionSetting = new SectionSetting(); | |||||
$merchantSetting = new SectionSetting(); | |||||
$sectionSetting->setSection($this->section); | |||||
$merchantSetting->setSection($this->section); | |||||
$merchantSetting->setName($name); | |||||
$merchantSetting->setText($text); | |||||
$merchantSetting->setDate($date); | |||||
$merchantSetting->setFile($file); | |||||
return $sectionSetting; | |||||
return $merchantSetting; | |||||
} | } | ||||
} | } |
$label = 'setting_definition.'.$transCategory.'.settings.'.$settingName ; | $label = 'setting_definition.'.$transCategory.'.settings.'.$settingName ; | ||||
if(isset($settingDefinition) && $settingDefinition) { | if(isset($settingDefinition) && $settingDefinition) { | ||||
$this->buildFormSetting($label, $form, $settingDefinition, $settingEntity); | $this->buildFormSetting($label, $form, $settingDefinition, $settingEntity); | ||||
} | } | ||||
} | } |
*/ | */ | ||||
protected $section; | protected $section; | ||||
/** | |||||
* @ORM\Column(type="integer", nullable=true) | |||||
*/ | |||||
protected $cycleId; | |||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
$this->orderStatusHistories = new ArrayCollection(); | $this->orderStatusHistories = new ArrayCollection(); | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getCycleId(): ?int | |||||
{ | |||||
return $this->cycleId; | |||||
} | |||||
public function setCycleId(?int $cycleId): self | |||||
{ | |||||
$this->cycleId = $cycleId; | |||||
return $this; | |||||
} | |||||
} | } |
<?php | |||||
namespace Lc\CaracoleBundle\Model\Section; | |||||
interface OpeningInterface | |||||
{ | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Model\Section; | |||||
use Doctrine\ORM\Mapping as ORM; | |||||
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface; | |||||
use Lc\SovBundle\Doctrine\EntityInterface; | |||||
use Lc\SovBundle\Model\User\GroupUserInterface; | |||||
/** | |||||
* @ORM\MappedSuperclass() | |||||
*/ | |||||
abstract class OpeningModel implements EntityInterface, OpeningInterface, FilterSectionInterface | |||||
{ | |||||
/** | |||||
* @ORM\Column(type="integer") | |||||
*/ | |||||
protected $day; | |||||
/** | |||||
* @ORM\Column(type="time", nullable=true) | |||||
*/ | |||||
protected $timeStart; | |||||
/** | |||||
* @ORM\Column(type="time", nullable=true) | |||||
*/ | |||||
protected $timeEnd; | |||||
/** | |||||
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface", inversedBy="openings") | |||||
* @ORM\JoinColumn(nullable=false) | |||||
*/ | |||||
protected $section; | |||||
/** | |||||
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\User\GroupUserInterface", inversedBy="openings") | |||||
*/ | |||||
protected $groupUser; | |||||
public function __toString() | |||||
{ | |||||
$toString = ''.$this->getDay(); | |||||
if($this->getTimeStart()) { | |||||
$toString .= ' / Début : '.$this->getTimeStart()->format('H:i'); | |||||
} | |||||
if($this->getTimeEnd()) { | |||||
$toString .= ' / Fin : '.$this->getTimeEnd()->format('H:i'); | |||||
} | |||||
return $toString ; | |||||
} | |||||
public function getDay(): ?int | |||||
{ | |||||
return $this->day; | |||||
} | |||||
public function setDay(int $day): self | |||||
{ | |||||
$this->day = $day; | |||||
return $this; | |||||
} | |||||
public function getTimeStart(): ?\DateTimeInterface | |||||
{ | |||||
return $this->timeStart; | |||||
} | |||||
public function setTimeStart(?\DateTimeInterface $timeStart): self | |||||
{ | |||||
$this->timeStart = $timeStart; | |||||
return $this; | |||||
} | |||||
public function getTimeEnd(): ?\DateTimeInterface | |||||
{ | |||||
return $this->timeEnd; | |||||
} | |||||
public function setTimeEnd(?\DateTimeInterface $timeEnd): self | |||||
{ | |||||
$this->timeEnd = $timeEnd; | |||||
return $this; | |||||
} | |||||
public function getSection(): ?SectionInterface | |||||
{ | |||||
return $this->section; | |||||
} | |||||
public function setSection(?SectionInterface $section): self | |||||
{ | |||||
$this->section = $section; | |||||
return $this; | |||||
} | |||||
public function getGroupUser(): ?GroupUserInterface | |||||
{ | |||||
return $this->groupUser; | |||||
} | |||||
public function setGroupUser(?GroupUserInterface $groupUser): self | |||||
{ | |||||
$this->groupUser = $groupUser; | |||||
return $this; | |||||
} | |||||
} |
*/ | */ | ||||
protected $settings; | protected $settings; | ||||
/** | |||||
* @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Section\OpeningInterface", mappedBy="section", orphanRemoval=true) | |||||
*/ | |||||
protected $openings; | |||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
$this->productFamilies = new ArrayCollection(); | $this->productFamilies = new ArrayCollection(); | ||||
$this->orderShops = new ArrayCollection(); | $this->orderShops = new ArrayCollection(); | ||||
$this->openings = new ArrayCollection(); | |||||
} | } | ||||
public function __toString() | public function __toString() | ||||
return $this; | return $this; | ||||
} | } | ||||
/** | |||||
* @return Collection|OpeningInterface[] | |||||
*/ | |||||
public function getOpenings(): Collection | |||||
{ | |||||
return $this->openings; | |||||
} | |||||
public function addOpening(OpeningInterface $opening): self | |||||
{ | |||||
if (!$this->openings->contains($opening)) { | |||||
$this->openings[] = $opening; | |||||
$opening->setSection($this); | |||||
} | |||||
return $this; | |||||
} | |||||
public function removeOpening(OpeningInterface $opening): self | |||||
{ | |||||
if ($this->openings->removeElement($opening)) { | |||||
// set the owning side to null (unless already changed) | |||||
if ($opening->getSection() === $this) { | |||||
$opening->setSection(null); | |||||
} | |||||
} | |||||
return $this; | |||||
} | |||||
} | } |
namespace Lc\CaracoleBundle\Model\User; | namespace Lc\CaracoleBundle\Model\User; | ||||
use Doctrine\Common\Collections\ArrayCollection; | |||||
use Doctrine\Common\Collections\Collection; | |||||
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface; | use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface; | ||||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | ||||
use Lc\CaracoleBundle\Model\Section\OpeningInterface; | |||||
use Lc\SovBundle\Model\User\GroupUserModel as SovGroupUserModel; | use Lc\SovBundle\Model\User\GroupUserModel as SovGroupUserModel; | ||||
/** | /** | ||||
*/ | */ | ||||
protected $merchant; | protected $merchant; | ||||
/** | |||||
* @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Section\OpeningInterface", mappedBy="groupUser") | |||||
*/ | |||||
protected $openings; | |||||
public function __construct() | |||||
{ | |||||
parent::__construct(); | |||||
$this->openings = new ArrayCollection(); | |||||
} | |||||
public function getMerchant(): MerchantInterface | public function getMerchant(): MerchantInterface | ||||
{ | { | ||||
return $this->merchant; | return $this->merchant; | ||||
return $this; | return $this; | ||||
} | } | ||||
/** | |||||
* @return Collection|OpeningInterface[] | |||||
*/ | |||||
public function getOpenings(): Collection | |||||
{ | |||||
return $this->openings; | |||||
} | |||||
public function addOpening(OpeningInterface $opening): self | |||||
{ | |||||
if (!$this->openings->contains($opening)) { | |||||
$this->openings[] = $opening; | |||||
$opening->setGroupUser($this); | |||||
} | |||||
return $this; | |||||
} | |||||
public function removeOpening(OpeningInterface $opening): self | |||||
{ | |||||
if ($this->openings->removeElement($opening)) { | |||||
// set the owning side to null (unless already changed) | |||||
if ($opening->getGroupUser() === $this) { | |||||
$opening->setGroupUser(null); | |||||
} | |||||
} | |||||
return $this; | |||||
} | |||||
} | } |
<?php | |||||
namespace Lc\CaracoleBundle\ReferenceBuilder; | |||||
use Lc\CaracoleBundle\Definition\SectionSettingDefinition; | |||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | |||||
use Lc\CaracoleBundle\Model\Section\SectionModel; | |||||
class OrderReferenceBuilder | |||||
{ | |||||
public function buildReference(OrderShopInterface $orderShop, \DateTime $distributionDate = null): string | |||||
{ | |||||
switch ($orderShop->getSection()->getCycle()) { | |||||
case SectionModel::CYCLE_DAY: | |||||
return $this->buildReferenceCycleDay($orderShop); | |||||
case SectionModel::CYCLE_WEEK: | |||||
return $this->buildReferenceCycleWeek($orderShop, $distributionDate); | |||||
case SectionModel::CYCLE_MONTH: | |||||
return $this->buildReferenceCycleMonth($orderShop, $distributionDate); | |||||
case SectionModel::CYCLE_YEAR: | |||||
return $this->buildReferenceCycleYear($orderShop, $distributionDate); | |||||
} | |||||
return 'C' . $orderShop->getId(); | |||||
} | |||||
public function buildReferenceCycleDay(OrderShopInterface $orderShop): string | |||||
{ | |||||
return $this->getPrefixReference($orderShop) . | |||||
'C' . $this->numberPad($orderShop->getCycleId(), 3); | |||||
} | |||||
public function buildReferenceCycleWeek(OrderShopInterface $orderShop, \DateTime $distributionDate): string | |||||
{ | |||||
return $this->getPrefixReference($orderShop) . | |||||
'S' . $distributionDate->format('W') . | |||||
'C' . $this->numberPad($orderShop->getCycleId(), 4) . | |||||
'A' . $distributionDate->format('y'); | |||||
} | |||||
public function buildReferenceCycleMonth(OrderShopInterface $orderShop, \DateTime $distributionDate): string | |||||
{ | |||||
return $this->getPrefixReference($orderShop) . | |||||
'M' . $distributionDate->format('m') . | |||||
'C' . $this->numberPad($orderShop->getCycleId(), 4) . | |||||
'A' . $distributionDate->format('y'); | |||||
} | |||||
public function buildReferenceCycleYear(OrderShopInterface $orderShop, \DateTime $distributionDate): string | |||||
{ | |||||
return $this->getPrefixReference($orderShop) . | |||||
'C' . $this->numberPad($orderShop->getCycleId(), 5) . | |||||
'A' . $distributionDate->format('y'); | |||||
} | |||||
public function getPrefixReference(OrderShopInterface $orderShop): string | |||||
{ | |||||
return $orderShop->getSection()->getSettingValue(SectionSettingDefinition::SETTING_REFERENCE_PREFIX);; | |||||
} | |||||
public function numberPad($number, $length): string | |||||
{ | |||||
return str_pad($number, $length, "0", STR_PAD_LEFT); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Repository\Section; | |||||
use App\Entity\Section\Opening; | |||||
use Doctrine\Persistence\ManagerRegistry; | |||||
use Lc\SovBundle\Repository\AbstractRepository; | |||||
class OpeningRepository extends AbstractRepository | |||||
{ | |||||
public function __construct(ManagerRegistry $registry) | |||||
{ | |||||
parent::__construct($registry, Opening::class); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Repository\Section; | |||||
use Knp\Component\Pager\PaginatorInterface; | |||||
use Lc\SovBundle\Repository\AbstractRepositoryQuery; | |||||
class OpeningRepositoryQuery extends AbstractRepositoryQuery | |||||
{ | |||||
public function __construct(OpeningRepository $repository, PaginatorInterface $paginator) | |||||
{ | |||||
parent::__construct($repository, 'r', $paginator); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Repository\Section; | |||||
class OpeningStore | |||||
{ | |||||
protected OpeningRepositoryQuery $query; | |||||
public function __construct(OpeningRepositoryQuery $query) | |||||
{ | |||||
$this->query = $query; | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Resolver; | |||||
use Lc\CaracoleBundle\Definition\SectionSettingDefinition; | |||||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | |||||
class OpeningResolver | |||||
{ | |||||
protected ?bool $isOpenSale = null; | |||||
protected array $messages = []; | |||||
public function init() | |||||
{ | |||||
$this->isOpenSale = false; | |||||
$this->messages = []; | |||||
} | |||||
public function isOpenSale(SectionInterface $section) | |||||
{ | |||||
$this->init(); | |||||
$now = new \DateTime(); | |||||
// order state | |||||
$this->checkOrderState(); | |||||
if(is_null($this->getIsOpenSale())) { | |||||
return $this->getIsOpenSale(); | |||||
} | |||||
// order maximum per cycle | |||||
$countOrderShopCycle = 0 ; | |||||
$orderMaximumPerCycle = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_MAXIMUM_PER_CYCLE); | |||||
if($countOrderShopCycle >= $orderMaximumPerCycle) { | |||||
return false; | |||||
} | |||||
// période de fermeture des commandes | |||||
$orderClosedStart = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_CLOSED_START); | |||||
$orderClosedEnd = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_CLOSED_END); | |||||
if($orderClosedStart && $orderClosedEnd && $now >= $orderClosedStart && $now <= $orderClosedEnd) { | |||||
return false; | |||||
} | |||||
// commandes ouvertes | |||||
// .. | |||||
// par défaut | |||||
if(is_null($this->getIsOpenSale())) { | |||||
$this->setIsOpenSale(true); | |||||
} | |||||
return $this->getIsOpenSale(); | |||||
} | |||||
public function checkOrderState(SectionInterface $section) | |||||
{ | |||||
$orderState = $section->getSettingValue(SectionSettingDefinition::SETTING_ORDER_STATE); | |||||
if($orderState == SectionSettingDefinition::VALUE_ORDER_STATE_OPEN) { | |||||
$this->setIsOpenSale(true); | |||||
$this->addMessage('Les commandes sont ouvertes.'); | |||||
} | |||||
if($orderState == SectionSettingDefinition::VALUE_ORDER_STATE_CLOSED) { | |||||
$this->setIsOpenSale(false); | |||||
$this->addMessage('Les commandes sont fermées.'); | |||||
} | |||||
} | |||||
public function getIsOpenSale() | |||||
{ | |||||
return $this->isOpenSale; | |||||
} | |||||
public function setIsOpenSale(bool $isOpenSale) | |||||
{ | |||||
$this->isOpenSale = $isOpenSale; | |||||
} | |||||
public function addMessage(string $message) | |||||
{ | |||||
$this->messages[] = $message; | |||||
} | |||||
/* | |||||
public function isOpenSale($context = self::OPENSALE_CONTEXT_FRONTEND, $checkMaximumOrderWeek = true) | |||||
{ | |||||
if($this->isOpenFullTime()) { | |||||
return true ; | |||||
} | |||||
$merchantCurrent = $this->merchantUtils->getMerchantCurrent(); | |||||
$orderOpenDay = $merchantCurrent->getMerchantConfig('order-open-day'); | |||||
$orderOpenTime = new \DateTime($merchantCurrent->getMerchantConfig('order-open-time')); | |||||
$orderOpenDayVip = $merchantCurrent->getMerchantConfig('order-open-day-vip'); | |||||
$orderOpenTimeVip = new \DateTime($merchantCurrent->getMerchantConfig('order-open-time-vip')); | |||||
$orderCloseDay = $merchantCurrent->getMerchantConfig('order-close-day'); | |||||
$orderCloseTime = new \DateTime($merchantCurrent->getMerchantConfig('order-close-time')); | |||||
if($orderOpenDayVip && $orderOpenTimeVip) { | |||||
if($context == self::OPENSALE_CONTEXT_BACKEND | |||||
|| ($context == self::OPENSALE_CONTEXT_FRONTEND | |||||
&& $this->userUtils->isUserInGroupVip())) { | |||||
if($orderOpenDayVip < $orderOpenDay) { | |||||
$orderOpenDay = $orderOpenDayVip ; | |||||
$orderOpenTime = $orderOpenTimeVip ; | |||||
} | |||||
elseif($orderOpenDayVip == $orderOpenDay) { | |||||
if($orderOpenTimeVip < $orderOpenTime) { | |||||
$orderOpenTime = $orderOpenTimeVip ; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
$dayToday = date('N'); | |||||
$now = new \DateTime(); | |||||
$openDays = $this->getOpenDays($orderOpenDay, $orderCloseDay); | |||||
if( in_array($dayToday, $openDays) | |||||
&& !$this->isHolidays() | |||||
&& (!$checkMaximumOrderWeek || ($checkMaximumOrderWeek && !$this->isMaximumOrderWeekAchieved())) | |||||
&& in_array($dayToday, $openDays) | |||||
&& (($dayToday == $orderOpenDay && $dayToday == $orderCloseDay && $now >= $orderOpenTime && $now <= $orderCloseTime) | |||||
|| ($dayToday == $orderOpenDay && $dayToday != $orderCloseDay && $now >= $orderOpenTime) | |||||
|| ($dayToday == $orderCloseDay && $dayToday != $orderOpenDay && $now <= $orderCloseTime) | |||||
|| ($dayToday != $orderOpenDay && $dayToday != $orderCloseDay)) | |||||
) { | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
*/ | |||||
} |
setting: Paramètres | setting: Paramètres | ||||
setting_merchant: Marchand | setting_merchant: Marchand | ||||
setting_section: Section | setting_section: Section | ||||
section_openings: Ouvertures | |||||
admin: Administration | admin: Administration | ||||
admin_merchant: Marchands | admin_merchant: Marchands | ||||
admin_section: Sections | admin_section: Sections | ||||
settings: | settings: | ||||
url: URL absolue | url: URL absolue | ||||
section: | |||||
settings: | |||||
orderReferencePrefix: Préfixe référence commandes | |||||
orderState: Statut d'ouverture des commandes | |||||
orderClosedStart: Période commandes fermées (début) | |||||
orderClosedEnd: Période commandes fermées (fin) | |||||
orderMaximumPerCycle: Nombre maximum de commande par cycle de vente | |||||
entity: | entity: | ||||
default: | default: | ||||
wordingShort: Nom court | wordingShort: Nom court | ||||
coefficient: Coefficient | coefficient: Coefficient | ||||
unitReference: Unité de référence | unitReference: Unité de référence | ||||
Opening: | |||||
label: Ouverture | |||||
label_plurial: Ouvertures | |||||
fields: | |||||
timeStart: Heure d'ouverture | |||||
timeEnd: Heure de fermeture | |||||
form: | form: | ||||
user_merchant: | user_merchant: |
use Lc\CaracoleBundle\Repository\Reminder\ReminderStore; | use Lc\CaracoleBundle\Repository\Reminder\ReminderStore; | ||||
use Lc\CaracoleBundle\Repository\Section\SectionRepository; | use Lc\CaracoleBundle\Repository\Section\SectionRepository; | ||||
use Lc\CaracoleBundle\Repository\Section\SectionRepositoryInterface; | use Lc\CaracoleBundle\Repository\Section\SectionRepositoryInterface; | ||||
use Lc\CaracoleBundle\Repository\Section\SectionRepositoryQuery; | |||||
use Lc\CaracoleBundle\Resolver\MerchantResolver; | use Lc\CaracoleBundle\Resolver\MerchantResolver; | ||||
use Lc\CaracoleBundle\Resolver\SectionResolver; | use Lc\CaracoleBundle\Resolver\SectionResolver; | ||||
use Twig\Extension\AbstractExtension; | use Twig\Extension\AbstractExtension; | ||||
class StoreTwigExtension extends AbstractExtension | class StoreTwigExtension extends AbstractExtension | ||||
{ | { | ||||
protected $merchantRepository; | |||||
protected $sectionRepository; | |||||
protected MerchantRepositoryQuery $merchantRepositoryQuery; | |||||
protected SectionRepositoryQuery $sectionRepositoryQuery; | |||||
protected ReminderStore $reminderStore; | protected ReminderStore $reminderStore; | ||||
protected MerchantResolver $merchantResolver; | protected MerchantResolver $merchantResolver; | ||||
protected SectionResolver $sectionResolver; | protected SectionResolver $sectionResolver; | ||||
public function __construct( | public function __construct( | ||||
MerchantResolver $merchantResolver, | MerchantResolver $merchantResolver, | ||||
SectionResolver $sectionResolver, | SectionResolver $sectionResolver, | ||||
MerchantRepositoryQuery $merchantRepository, | |||||
SectionRepository $sectionRepository, | |||||
MerchantRepositoryQuery $merchantRepositoryQuery, | |||||
SectionRepositoryQuery $sectionRepositoryQuery, | |||||
ReminderStore $reminderStore | ReminderStore $reminderStore | ||||
) { | ) { | ||||
$this->merchantResolver = $merchantResolver; | $this->merchantResolver = $merchantResolver; | ||||
$this->sectionResolver = $sectionResolver; | $this->sectionResolver = $sectionResolver; | ||||
$this->merchantRepository = $merchantRepository; | |||||
$this->sectionRepository = $sectionRepository; | |||||
$this->merchantRepositoryQuery = $merchantRepositoryQuery; | |||||
$this->sectionRepositoryQuery = $sectionRepositoryQuery; | |||||
$this->reminderStore = $reminderStore; | $this->reminderStore = $reminderStore; | ||||
} | } | ||||
public function getSections() | public function getSections() | ||||
{ | { | ||||
return $this->sectionRepository->findAll(); | |||||
return $this->sectionRepositoryQuery | |||||
->filterByMerchant($this->merchantResolver->getCurrent()) | |||||
->find(); | |||||
} | } | ||||
public function getMerchants() | public function getMerchants() | ||||
{ | { | ||||
return $this->merchantRepository->findAll(); | |||||
return $this->merchantRepositoryQuery->find(); | |||||
} | } | ||||
public function getReminders($params = []) | public function getReminders($params = []) |