Parcourir la source

Ajout section par defaut dans section

feature/ticket
Fab il y a 3 ans
Parent
révision
e6f66da687
4 fichiers modifiés avec 83 ajouts et 9 suppressions
  1. +2
    -1
      Controller/AbstractAdminController.php
  2. +18
    -2
      Model/Section/SectionModel.php
  3. +37
    -5
      Resolver/MerchantResolver.php
  4. +26
    -1
      Resolver/SectionResolver.php

+ 2
- 1
Controller/AbstractAdminController.php Voir le fichier

@@ -56,9 +56,10 @@ abstract class AbstractAdminController extends SovAbstractAdminController

if ($this->isInstanceOf(FilterSectionInterface::class)) {
$queryBuilder->andWhere('entity.section = :section');
$queryBuilder->setParameter('section', $this->merchantResolver->getCurrent());
$queryBuilder->setParameter('section', $this->sectionResolver->getCurrent());
}

dump($queryBuilder);
return $queryBuilder;
}


+ 18
- 2
Model/Section/SectionModel.php Voir le fichier

@@ -24,8 +24,6 @@ abstract class SectionModel extends AbstractFullEntity implements FilterMerchant
*/
protected $merchant;



/**
* @ORM\Column(type="string", length=32)
*/
@@ -36,6 +34,12 @@ abstract class SectionModel extends AbstractFullEntity implements FilterMerchant
const CYCLE_MONTH = 'month';
const CYCLE_YEAR = 'year';

/**
* @ORM\Column(type="boolean", nullable=true)
*/
protected $isDefault;


/**
* @ORM\Column(type="string", length=32)
*/
@@ -229,4 +233,16 @@ abstract class SectionModel extends AbstractFullEntity implements FilterMerchant

return $this;
}

public function getIsDefault(): ?bool
{
return $this->isDefault;
}

public function setIsDefault(?bool $isDefault): self
{
$this->isDefault = $isDefault;

return $this;
}
}

+ 37
- 5
Resolver/MerchantResolver.php Voir le fichier

@@ -9,20 +9,30 @@ namespace Lc\CaracoleBundle\Resolver;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Resolver\UrlResolver;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Security;

class MerchantResolver
{
protected $requestStack;
protected $em;
protected $urlResolver;
protected $security;

public function __construct(EntityManagerInterface $entityManager, RequestStack $requestStack, UrlResolver $urlResolver)
{
public function __construct(
EntityManagerInterface $entityManager,
RequestStack $requestStack,
UrlResolver $urlResolver,
Security $security
) {
$this->requestStack = $requestStack;
$this->em = $entityManager;
$this->urlResolver = $urlResolver;
$this->security = $security;
}

public function getCurrent(): MerchantInterface
@@ -33,9 +43,8 @@ class MerchantResolver

$currentMerchant = false;
$request = $this->requestStack->getCurrentRequest();

$merchantRepo = $this->em->getRepository(MerchantInterface::class);
$merchants = $merchantRepo->findAll();
$merchantRepository = $this->em->getRepository(MerchantInterface::class);
$merchants = $merchantRepository->findAll();

if ($request) {
if ($this->urlResolver->isServerLocalhost()) {
@@ -70,4 +79,27 @@ class MerchantResolver
}
}


public function getUserMerchant(
UserInterface $user = null,
MerchantInterface $merchant = null
): ?UserMerchantInterface {

$userMerchantRepository = $this->em->getRepository(UserMerchantInterface::class);

if ($user === null) {
$user = $this->security->getUser();
}
if ($merchant === null) {
$merchant = $this->getCurrent();
}

return $userMerchantRepository->findOneBy(
[
'user' => $user,
'merchant' => $merchant,
]
);
}

}

+ 26
- 1
Resolver/SectionResolver.php Voir le fichier

@@ -6,13 +6,38 @@

namespace Lc\CaracoleBundle\Resolver;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Repository\Section\SectionRepository;
use Lc\SovBundle\Resolver\UrlResolver;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Security;

class SectionResolver
{
protected $sectionRepository;
protected $merchantResolver;

public function __construct(MerchantResolver $merchantResolver, SectionRepository $sectionRepository)
{
$this->sectionRepository = $sectionRepository;
$this->merchantResolver = $merchantResolver;
}

public function getCurrent(): SectionInterface
{
//return ;
$currentAdminSection = null;
$userMerchant = $this->merchantResolver->getUserMerchant();

if($userMerchant!==null){
$currentAdminSection = $userMerchant->getCurrentAdminSection();
}

if($currentAdminSection === null){
$currentAdminSection = $this->sectionRepository->findOneBy(array('isDefault'=>true));
}
return $currentAdminSection;
}


}

Chargement…
Annuler
Enregistrer