소스 검색

[Backend] Découpage et recherche sur champ user name/firstname/email

develop
Fab 3 년 전
부모
커밋
bb51988559
8개의 변경된 파일104개의 추가작업 그리고 43개의 파일을 삭제
  1. +44
    -31
      ShopBundle/Controller/Backend/AdminController.php
  2. +2
    -1
      ShopBundle/Form/Backend/Filters/ListFilterType.php
  3. +22
    -5
      ShopBundle/Repository/BaseRepository.php
  4. +3
    -2
      ShopBundle/Repository/ReductionCartRepository.php
  5. +5
    -0
      ShopBundle/Resources/views/backend/default/field/textorempty.html.twig
  6. +5
    -0
      ShopBundle/Resources/views/backend/default/field/user.html.twig
  7. +4
    -4
      ShopBundle/Resources/views/backend/default/list.html.twig
  8. +19
    -0
      ShopBundle/Services/Utils.php

+ 44
- 31
ShopBundle/Controller/Backend/AdminController.php 파일 보기

@@ -93,7 +93,7 @@ class AdminController extends EasyAdminController

$response = array();
foreach ($values as $value) {
$response[] = $value[$field];
$response[] = $value[$this->utils->getFilterWithoutAssociationAlias($field, '_')];
}
return new JsonResponse($response);

@@ -138,11 +138,11 @@ class AdminController extends EasyAdminController

if ($pos = strpos($dqlFilter, 'TODAYSTART')) {
$date = new \DateTime();
$dqlFilter = sprintf(str_replace('TODAYSTART', $date->format('Y-m-d').' 00:00:00', $dqlFilter));
$dqlFilter = sprintf(str_replace('TODAYSTART', $date->format('Y-m-d') . ' 00:00:00', $dqlFilter));
}
if ($pos = strpos($dqlFilter, 'TODAYEND')) {
$date = new \DateTime();
$dqlFilter = sprintf(str_replace('TODAYEND', $date->format('Y-m-d').' 23:59:59', $dqlFilter));
$dqlFilter = sprintf(str_replace('TODAYEND', $date->format('Y-m-d') . ' 23:59:59', $dqlFilter));
}

if ($pos = strpos($dqlFilter, 'sectionLunch')) {
@@ -195,9 +195,11 @@ class AdminController extends EasyAdminController
$this->filtersForm->handleRequest($this->request);
$easyadmin = $this->request->attributes->get('easyadmin');
$view = $easyadmin['view'];
if($easyadmin['view']=='listChildren') $view = 'list';
if (($this->filtersForm->isSubmitted() && $this->filtersForm->isValid()) || $this->entity[$view]['filters']!==false) {
if ($easyadmin['view'] == 'listChildren') $view = 'list';
if (($this->filtersForm->isSubmitted() && $this->filtersForm->isValid()) || $this->entity[$view]['filters'] !== false) {
foreach ($listFields as $field) {
$field['initProperty'] = $field['property'];
$field['property'] = $this->utils->getFilterPropertyClean($field['property']);
//if ($this->filtersForm->has($field['property'])->getConfig()->getOption('AdminController')) {
if ($this->filtersForm->has($field['property'])) {
switch ($field['dataType']) {
@@ -209,14 +211,24 @@ class AdminController extends EasyAdminController
$filter = $this->getListFilterParam($field['property']);
//$filter = $this->filtersForm->get($field['property'])->getData();
if ($filter !== null) {
if ($this->utils->hasFilterAssociation($field['initProperty'])) {
$aliasRelation = $this->utils->getFilterAssociationAlias($field['initProperty']);
if(array_search($aliasRelation, $queryBuilder->getAllAliases())===false){
$queryBuilder->innerJoin('entity.'.$aliasRelation, $aliasRelation);
}
$queryBuilder->andWhere($field['initProperty'] . ' LIKE :' . $field['property'] . '');
$queryBuilder->setParameter($field['property'], '%' . $filter . '%');
} else {
$queryBuilder->andWhere('entity.' . $field['property'] . ' LIKE :' . $field['property'] . '');
$queryBuilder->setParameter($field['property'], '%' . $filter . '%');

}

$queryBuilder->andWhere('entity.' . $field['property'] . ' LIKE :' . $field['property'] . '');
$queryBuilder->setParameter($field['property'], '%' . $filter . '%');
}
break;
case 'association' :
$filter = $this->getListFilterParam($field['property']);
//$filter = $this->filtersForm->get($field['property'])->getData();
//$filter = $this->filtersForm->get($field['property'])->getData();
if ($filter !== null) {
if ($field['type_options']['multiple']) {
$queryBuilder->andWhere(':' . $field['property'] . ' MEMBER OF entity.' . $field['property'] . '');
@@ -246,7 +258,7 @@ class AdminController extends EasyAdminController
}

//TODO déplacer dans LC
if($this->entity['name']== 'OrderShopLunch' || $this->entity['name']== 'OrderShopLunchDay'){
if ($this->entity['name'] == 'OrderShopLunch' || $this->entity['name'] == 'OrderShopLunchDay') {
$queryBuilder->addOrderBy('entity.user', 'asc');
}

@@ -255,34 +267,35 @@ class AdminController extends EasyAdminController

//TODO finaliser la sauvegarde des filtres

protected function getListFilterParam($param, $extraParam = null){
protected function getListFilterParam($param, $extraParam = null)
{
$entityName = $this->entity['name'];
$sessionParam = $entityName.$param.$extraParam;
$sessionParam = $entityName . $param . $extraParam;
//CUSTOM
if($extraParam){
if ($extraParam) {
$value = $this->filtersForm->get($param)->get($extraParam)->getViewData();
}else{
} else {
$value = $this->filtersForm->get($param)->getViewData();
}

if($this->request->query->get('filterClear')){
if ($this->request->query->get('filterClear')) {
$this->session->remove($sessionParam);
}else {
} else {
if ($value) {
$this->session->set($sessionParam, $value);
} else if ($this->session->get($sessionParam) && !$this->filtersForm->isSubmitted() && $this->filtersForm->get($param)) {
$value = $this->session->get($sessionParam);

if($extraParam){
if ($extraParam) {

if($this->filtersForm->get($param)->get($extraParam)->getConfig()->getOption('input')=='datetime'){
if ($this->filtersForm->get($param)->get($extraParam)->getConfig()->getOption('input') == 'datetime') {

$this->filtersForm->get($param)->get($extraParam)->setData(new \DateTime($value));
}else{
} else {
$this->filtersForm->get($param)->get($extraParam)->setData($value);
}

}else {
} else {
//Champ association
if ($this->filtersForm->get($param)->getConfig()->getOption('class')) {
$valFormated = $this->em->getRepository($this->filtersForm->get($param)->getConfig()->getOption('class'))->find($value);
@@ -296,13 +309,12 @@ class AdminController extends EasyAdminController
}
}

if($value !== "")return $value;
if ($value !== "") return $value;
else return null;

}



public function renderTemplate($actionName, $templatePath, array $parameters = [])
{

@@ -380,21 +392,22 @@ class AdminController extends EasyAdminController
}


protected function getListParam($param, $default =null){
protected function getListParam($param, $default = null)
{
$entityName = $this->entity['name'];
$sessionParam = $entityName.$param;
$sessionParam = $entityName . $param;
//CUSTOM
if($param == 'maxResults'){
$val = $this->entity['list']['max_results'];
}else{
if ($param == 'maxResults') {
$val = $this->entity['list']['max_results'];
} else {
$val = $this->request->query->get($param, $default);
}

if(isset($_GET[$param])){
$val = $this->request->query->get($param);
if (isset($_GET[$param])) {
$val = $this->request->query->get($param);
$this->session->set($sessionParam, $val);
}else if($this->session->get($sessionParam)){
$val = $this->session->get($sessionParam);
} else if ($this->session->get($sessionParam)) {
$val = $this->session->get($sessionParam);
$this->request->query->set($param, $val);
}

@@ -407,7 +420,7 @@ class AdminController extends EasyAdminController

$fields = $this->entity['list']['fields'];

$paginator = $this->findAll($this->entity['class'], $this->getListParam('page', 1), $this->getListParam('maxResults'), $this->getListParam('sortField'), $this->getListParam('sortDirection'), $this->entity['list']['dql_filter']);
$paginator = $this->findAll($this->entity['class'], $this->getListParam('page', 1), $this->getListParam('maxResults'), $this->getListParam('sortField'), $this->getListParam('sortDirection'), $this->entity['list']['dql_filter']);

$this->dispatch(EasyAdminEvents::POST_LIST, ['paginator' => $paginator]);


+ 2
- 1
ShopBundle/Form/Backend/Filters/ListFilterType.php 파일 보기

@@ -67,8 +67,9 @@ class ListFilterType extends AbstractType
)
));
break;
case 'text':
case 'string':
$builder->add($field['property'], TextType::class, array(
$builder->add(str_replace('.', '_',$field['property']), TextType::class, array(
'required' => false,
'attr'=>array(
'class'=> ' input-sm',

+ 22
- 5
ShopBundle/Repository/BaseRepository.php 파일 보기

@@ -10,26 +10,42 @@ use Lc\ShopBundle\Context\FilterMerchantInterface;
use Lc\ShopBundle\Context\FilterMultipleMerchantsInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\StatusInterface;
use Lc\ShopBundle\Services\Utils;

class BaseRepository extends EntityRepository implements ServiceEntityRepositoryInterface
{
public $merchantUtils;
protected $merchantUtils;
protected $utils;

/**
* @param string $entityClass The class name of the entity this repository manages
*/
public function __construct(EntityManager $entityManager, MerchantUtilsInterface $merchantUtils)
public function __construct(EntityManager $entityManager, MerchantUtilsInterface $merchantUtils, Utils $utils)
{
$this->merchantUtils = $merchantUtils;
$this->utils = $utils;
parent::__construct($entityManager, $entityManager->getClassMetadata($this->getInterfaceClass()));
}



public function findByTerm($field, $term, $limit=10){
$qb = $this->findByMerchantQuery();
$qb->select('e.'.$field);
$qb->andWhere(
$qb->expr()->like('e.'.$field, ':term'));

if($this->utils->hasFilterAssociation($field, '_')){
$aliasRelation = $this->utils->getFilterAssociationAlias($field, '_');

$qb->innerJoin('e.'.$aliasRelation, $aliasRelation);
$qb->select($this->utils->getFilterPropertyInit($field));
$qb->groupBy($this->utils->getFilterPropertyInit($field));
$qb->andWhere(
$qb->expr()->like($this->utils->getFilterPropertyInit($field), ':term'));
}else {
$qb->select('e.' . $field);
$qb->groupBy('e.' . $field);
$qb->andWhere(
$qb->expr()->like('e.' . $field, ':term'));
}
$qb->setParameter('term', '%'.$term.'%');
$qb->setMaxResults($limit);

@@ -39,6 +55,7 @@ class BaseRepository extends EntityRepository implements ServiceEntityRepository




public function findOneByOldUrl($url)
{
$qb = $this->createQueryBuilder('entity')

+ 3
- 2
ShopBundle/Repository/ReductionCartRepository.php 파일 보기

@@ -7,6 +7,7 @@ use Lc\ShopBundle\Context\DefaultRepositoryInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\OrderUtilsInterface;
use Lc\ShopBundle\Context\ReductionCartInterface;
use Lc\ShopBundle\Services\Utils;

/**
* @method ReductionCartInterface|null find($id, $lockMode = null, $lockVersion = null)
@@ -18,9 +19,9 @@ class ReductionCartRepository extends BaseRepository implements DefaultRepositor
{
protected $orderUtils ;

public function __construct(EntityManager $entityManager, MerchantUtilsInterface $merchantUtils, OrderUtilsInterface $orderUtils)
public function __construct(EntityManager $entityManager, MerchantUtilsInterface $merchantUtils, Utils $utils, OrderUtilsInterface $orderUtils)
{
parent::__construct($entityManager, $merchantUtils);
parent::__construct($entityManager, $merchantUtils, $utils);
$this->orderUtils = $orderUtils ;
}


+ 5
- 0
ShopBundle/Resources/views/backend/default/field/textorempty.html.twig 파일 보기

@@ -0,0 +1,5 @@
{% if value is not null or value is not empty %}
{{ value }}
{% else %}
<span class="badge badge-secondary">Non défini</span>
{% endif %}

+ 5
- 0
ShopBundle/Resources/views/backend/default/field/user.html.twig 파일 보기

@@ -0,0 +1,5 @@
{% if item.user is not null %}
<a href="{{ path('easyadmin', {"entity": 'User', 'action': "show", "id" : item.user.id})}}">{{ value }}</a>
{% else %}
{{ value }}
{% endif %}

+ 4
- 4
ShopBundle/Resources/views/backend/default/list.html.twig 파일 보기

@@ -212,8 +212,9 @@
{% endif %}

{% for field, metadata in _fields_visible_by_user %}

{% set isSortingField = (metadata.property == app.request.get('sortField')) or ('association' == metadata.type and app.request.get('sortField') starts with metadata.property ~ '.') %}
{% set nextSortDirection = isSortingField ? (app.request.get('sortDirection') == 'DESC' ? 'ASC' : 'DESC') : 'DESC' %}
{% set nextSortDirection = isSortingField ? (app.request.get('sortDirection') == 'DESC' ? 'ASC' : 'DESC') : 'ASC' %}
{% set _column_label = metadata.label|trans(_trans_parameters) %}
{% set _column_icon = isSortingField ? (nextSortDirection == 'DESC' ? 'fa-arrow-up' : 'fa-arrow-down') : 'fa-sort' %}
{% set isFilteredField = false %}
@@ -254,9 +255,8 @@
<th></th>{% endif %}
{% for field, metadata in _fields_visible_by_user %}
<th>
{% set field = utils.getFilterPropertyClean(field) %}
{% if filters_form[field] is defined %}

{% if filters_form[field].vars.value is not null and filters_form[field].vars.value is not empty %}{% set fieldAreNotEmpty = true %}{% endif %}
{% if metadata['dataType'] == 'datetime' or metadata['dataType'] == 'date' %}
<div class="input-group input-group-sm">
@@ -270,7 +270,7 @@
</div>
{% else %}
<div class="form-widget input-group-sm">
{% if metadata.dataType == 'integer' or metadata.dataType== 'string' %}
{% if metadata.dataType == 'integer' or metadata.dataType== 'string' or metadata.dataType== 'text' %}
{{ form_widget(filters_form[field], {'attr': {'autocomplete': 'off', 'data-lc-autocomplete-url' : path('easyadmin', {
action: 'autocomplete',
field: field,

+ 19
- 0
ShopBundle/Services/Utils.php 파일 보기

@@ -567,5 +567,24 @@ class Utils
return md5($key);
}

public function getFilterPropertyClean($fieldName){
return str_replace('.', '_', $fieldName);
}

public function getFilterPropertyInit($fieldName){
return str_replace('_', '.', $fieldName);
}

public function hasFilterAssociation($fieldName, $needle="."){
return strpos($fieldName, $needle);
}

public function getFilterWithoutAssociationAlias($fieldName, $needle = '.'){
return substr($fieldName, strpos($fieldName, $needle)+1);
}
public function getFilterAssociationAlias($fieldName, $needle = '.'){
return substr($fieldName, 0, strpos($fieldName, $needle));
}


}

Loading…
취소
저장