瀏覽代碼

Livraisons : adaptations des créneaux

reduction
Guillaume 4 年之前
父節點
當前提交
ef2a2c915a
共有 2 個文件被更改,包括 39 次插入9 次删除
  1. +8
    -0
      ShopBundle/Context/FilterMerchantInterface.php
  2. +31
    -9
      ShopBundle/Controller/Admin/AdminController.php

+ 8
- 0
ShopBundle/Context/FilterMerchantInterface.php 查看文件

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

namespace Lc\ShopBundle\Context ;

interface FilterMerchantInterface
{

}

+ 31
- 9
ShopBundle/Controller/Admin/AdminController.php 查看文件

@@ -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…
取消
儲存