Selaa lähdekoodia

Livraisons : adaptations des créneaux

reduction
Guillaume 4 vuotta sitten
vanhempi
commit
ef2a2c915a
2 muutettua tiedostoa jossa 39 lisäystä ja 9 poistoa
  1. +8
    -0
      ShopBundle/Context/FilterMerchantInterface.php
  2. +31
    -9
      ShopBundle/Controller/Admin/AdminController.php

+ 8
- 0
ShopBundle/Context/FilterMerchantInterface.php Näytä tiedosto

@@ -0,0 +1,8 @@
<?php

namespace Lc\ShopBundle\Context ;

interface FilterMerchantInterface
{

}

+ 31
- 9
ShopBundle/Controller/Admin/AdminController.php Näytä tiedosto

@@ -125,9 +125,14 @@ class AdminController extends EasyAdminController

protected function removeEntity($entity)
{
$entity->setStatus(-1);
$this->em->persist($entity);
$this->em->flush();
if(method_exists($entity, 'setStatus')) {
$entity->setStatus(-1);
$this->em->persist($entity);
$this->em->flush();
}
else {
parent::removeEntity($entity);
}
}

public function updateEntity($entity)
@@ -342,21 +347,38 @@ class AdminController extends EasyAdminController
$form = $event->getForm();
$allChilds = $form->all() ;
foreach($allChilds as $child) {

$type = $child->getConfig()->getType()->getInnerType() ;

if($type instanceof EntityType) {
$attributes = $child->getConfig()->getAttributes() ;
$passedOptions = $attributes['data_collector/passed_options'] ;
$classImplements = class_implements($passedOptions['class']) ;

if(in_array('App\Context\FilterHubInterface', $classImplements)) {
if(in_array('App\Context\FilterHubInterface', $classImplements) ||
in_array('Lc\ShopBundle\Context\FilterMerchantInterface', $classImplements)) {

$propertyMerchant = 'merchant' ;
if(in_array('App\Context\FilterHubInterface', $classImplements)) {
$propertyMerchant = 'hub' ;
}

$form->add($child->getName(), EntityType::class, array(
'class' => $this->em->getClassMetadata($passedOptions['class'])->getName(),
'label' => $passedOptions['label'],
'query_builder' => function (EntityRepository $repo) {
return $repo->createQueryBuilder('e')
->where('e.hub = :currentMerchant')
->setParameter(':currentMerchant', $this->getUser()->getMerchant()->getId());
'placeholder' => '--',
'query_builder' => function (EntityRepository $repo) use ($passedOptions, $propertyMerchant) {
$queryBuilder = $repo->createQueryBuilder('e') ;
$propertyMerchant = 'e.'.$propertyMerchant ;

if($passedOptions['class'] == 'App\Entity\PointSale') {
$queryBuilder->where(':currentMerchant MEMBER OF '.$propertyMerchant) ;
}
else {
$queryBuilder->where($propertyMerchant.' = :currentMerchant') ;
}

$queryBuilder->setParameter(':currentMerchant', $this->getUser()->getMerchant()->getId()) ;
return $queryBuilder ;
},
'required' => $passedOptions['required'],
)

Loading…
Peruuta
Tallenna