Browse Source

Ajout section par defaut dans section

feature/ticket
Fab 3 years ago
parent
commit
e6f66da687
4 changed files with 83 additions and 9 deletions
  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 View File



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


dump($queryBuilder);
return $queryBuilder; return $queryBuilder;
} }



+ 18
- 2
Model/Section/SectionModel.php View File

*/ */
protected $merchant; protected $merchant;




/** /**
* @ORM\Column(type="string", length=32) * @ORM\Column(type="string", length=32)
*/ */
const CYCLE_MONTH = 'month'; const CYCLE_MONTH = 'month';
const CYCLE_YEAR = 'year'; const CYCLE_YEAR = 'year';


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


/** /**
* @ORM\Column(type="string", length=32) * @ORM\Column(type="string", length=32)
*/ */


return $this; 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 View File



use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; 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 Lc\SovBundle\Resolver\UrlResolver;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Security;


class MerchantResolver class MerchantResolver
{ {
protected $requestStack; protected $requestStack;
protected $em; protected $em;
protected $urlResolver; 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->requestStack = $requestStack;
$this->em = $entityManager; $this->em = $entityManager;
$this->urlResolver = $urlResolver; $this->urlResolver = $urlResolver;
$this->security = $security;
} }


public function getCurrent(): MerchantInterface public function getCurrent(): MerchantInterface


$currentMerchant = false; $currentMerchant = false;
$request = $this->requestStack->getCurrentRequest(); $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 ($request) {
if ($this->urlResolver->isServerLocalhost()) { if ($this->urlResolver->isServerLocalhost()) {
} }
} }



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 View File



namespace Lc\CaracoleBundle\Resolver; namespace Lc\CaracoleBundle\Resolver;


use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface; 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 class SectionResolver
{ {
protected $sectionRepository;
protected $merchantResolver;

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

public function getCurrent(): SectionInterface 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;
} }



} }

Loading…
Cancel
Save