|
|
|
|
|
|
|
|
use Lc\ShopBundle\Context\ProductFamilyInterface; |
|
|
use Lc\ShopBundle\Context\ProductFamilyInterface; |
|
|
use Lc\ShopBundle\Context\ReductionCatalogInterface; |
|
|
use Lc\ShopBundle\Context\ReductionCatalogInterface; |
|
|
use Lc\ShopBundle\Context\TaxRateInterface; |
|
|
use Lc\ShopBundle\Context\TaxRateInterface; |
|
|
|
|
|
use Lc\ShopBundle\Form\Backend\Common\AbstractEditPositionType; |
|
|
use Lc\ShopBundle\Form\Backend\Common\ReductionCatalogType; |
|
|
use Lc\ShopBundle\Form\Backend\Common\ReductionCatalogType; |
|
|
use Lc\ShopBundle\Form\Backend\ProductFamily\ProductType; |
|
|
use Lc\ShopBundle\Form\Backend\ProductFamily\ProductType; |
|
|
use Lc\ShopBundle\Model\ProductFamily; |
|
|
use Lc\ShopBundle\Model\ProductFamily; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//hack utilisé pour filter sur les catégories lors du tri des produits par sous cat |
|
|
|
|
|
//A améliorer à l'occas |
|
|
|
|
|
protected function createListQueryBuilder($entityClass, $sortDirection, $sortField = null, $dqlFilter = null) |
|
|
|
|
|
{ |
|
|
|
|
|
$productCategoryId = false; |
|
|
|
|
|
|
|
|
|
|
|
if (isset($dqlFilter['productCategoryId'])) $productCategoryId = $dqlFilter['productCategoryId']; |
|
|
|
|
|
if(isset($dqlFilter['filter']))$dqlFilter = $dqlFilter['filter']; |
|
|
|
|
|
|
|
|
|
|
|
$queryBuilder = parent::createListQueryBuilder($entityClass, $sortDirection, $sortField, $dqlFilter); |
|
|
|
|
|
|
|
|
|
|
|
$queryBuilder->leftJoin('entity.productCategories', 'product_categories'); |
|
|
|
|
|
|
|
|
|
|
|
if ($productCategoryId) { |
|
|
|
|
|
$queryBuilder->andWhere('product_categories.id = :cat'); |
|
|
|
|
|
$queryBuilder->setParameter('cat', $productCategoryId); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $queryBuilder; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function sortByProductCategoryAction(){ |
|
|
|
|
|
$this->dispatch(EasyAdminEvents::PRE_LIST); |
|
|
|
|
|
$entity = null; |
|
|
|
|
|
|
|
|
|
|
|
//Replace this with query builder function, do not use finAll of easyAdmin |
|
|
|
|
|
if ($this->request->query->get('productCategoryId')) { |
|
|
|
|
|
if(!is_array($this->entity['list']['dql_filter'])) { |
|
|
|
|
|
$this->entity['list']['dql_filter'] = array('filter' => $this->entity['list']['dql_filter']); |
|
|
|
|
|
} |
|
|
|
|
|
$this->entity['list']['dql_filter']['productCategoryId'] = $this->request->query->get('productCategoryId'); |
|
|
|
|
|
$easyadmin = $this->request->attributes->get('easyadmin'); |
|
|
|
|
|
$entity = $easyadmin['item']; |
|
|
|
|
|
}else{ |
|
|
|
|
|
throw new \ErrorException('Action impossible') ; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($this->entity['list']['dql_filter']['filter']) $this->entity['list']['dql_filter']['filter'] .= sprintf(' AND entity.status = 1'); |
|
|
|
|
|
else $this->entity['list']['dql_filter']['filter'] .= sprintf(' entity.status = 1'); |
|
|
|
|
|
|
|
|
|
|
|
$fields = $this->entity['list']['fields']; |
|
|
|
|
|
|
|
|
|
|
|
$paginator = $this->findAll($this->entity['class'], $this->request->query->get('page', 1), 500, 'position', 'asc', $this->entity['list']['dql_filter']); |
|
|
|
|
|
|
|
|
|
|
|
$this->dispatch(EasyAdminEvents::POST_LIST, ['paginator' => $paginator]); |
|
|
|
|
|
|
|
|
|
|
|
$positionForm = $this->createFormBuilder(array('entities', $paginator->getCurrentPageResults())) |
|
|
|
|
|
->add('entities', CollectionType::class, array( |
|
|
|
|
|
'required' => true, |
|
|
|
|
|
'allow_add' => true, |
|
|
|
|
|
'entry_type' => AbstractEditPositionType::class, |
|
|
|
|
|
)) |
|
|
|
|
|
->getForm(); |
|
|
|
|
|
|
|
|
|
|
|
$positionForm->handleRequest($this->request); |
|
|
|
|
|
|
|
|
|
|
|
if ($positionForm->isSubmitted() && $positionForm->isValid()) { |
|
|
|
|
|
$class = $this->entity['class']; |
|
|
|
|
|
$repo = $this->em->getRepository($class); |
|
|
|
|
|
|
|
|
|
|
|
$latsPos = 0; |
|
|
|
|
|
foreach ($positionForm->get('entities')->getData() as $elm) { |
|
|
|
|
|
$this->dispatch(EasyAdminEvents::PRE_UPDATE, ['entity' => $entity]); |
|
|
|
|
|
$entity = $repo->find($elm['id']); |
|
|
|
|
|
$entity->setPosition($elm['position']); |
|
|
|
|
|
$this->em->persist($entity); |
|
|
|
|
|
$this->dispatch(EasyAdminEvents::POST_UPDATE, ['entity' => $entity]); |
|
|
|
|
|
$latsPos = $elm['position']; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//die(); |
|
|
|
|
|
//to do récupérer les élements hors ligne et incrémenter position |
|
|
|
|
|
/*foreach ($repo->findBy(array('status'=> false)) as $offlineEntity) { |
|
|
|
|
|
$latsPos++; |
|
|
|
|
|
$offlineEntity->setPosition($latsPos); |
|
|
|
|
|
$this->em->persist($offlineEntity); |
|
|
|
|
|
}*/ |
|
|
|
|
|
$this->em->flush(); |
|
|
|
|
|
|
|
|
|
|
|
$this->addFlash('success', 'Position modifié', array(), 'mweb'); |
|
|
|
|
|
|
|
|
|
|
|
return $this->redirectToReferrer(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$parameters = [ |
|
|
|
|
|
'paginator' => $paginator, |
|
|
|
|
|
'fields' => $fields, |
|
|
|
|
|
'batch_form' => $this->createBatchForm($this->entity['name'])->createView(), |
|
|
|
|
|
'delete_form_template' => $this->createDeleteForm($this->entity['name'], '__id__')->createView(), |
|
|
|
|
|
'postion_form' => $positionForm->createView(), |
|
|
|
|
|
'entity' => $entity, |
|
|
|
|
|
'sortable' => true |
|
|
|
|
|
]; |
|
|
|
|
|
return $this->executeDynamicMethod('render<EntityName>Template', ['sortable', "@LcShop/backend/default/sortable.html.twig", $parameters]); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|