Browse Source

Merge branch 'develop'

master^2
Guillaume 3 years ago
parent
commit
5202eae2dd
8 changed files with 126 additions and 51 deletions
  1. +64
    -39
      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. +21
    -0
      ShopBundle/Services/Utils.php

+ 64
- 39
ShopBundle/Controller/Backend/AdminController.php View File



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




if ($pos = strpos($dqlFilter, 'TODAYSTART')) { if ($pos = strpos($dqlFilter, 'TODAYSTART')) {
$date = new \DateTime(); $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')) { if ($pos = strpos($dqlFilter, 'TODAYEND')) {
$date = new \DateTime(); $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')) { if ($pos = strpos($dqlFilter, 'sectionLunch')) {
$this->filtersForm->handleRequest($this->request); $this->filtersForm->handleRequest($this->request);
$easyadmin = $this->request->attributes->get('easyadmin'); $easyadmin = $this->request->attributes->get('easyadmin');
$view = $easyadmin['view']; $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) { 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'])->getConfig()->getOption('AdminController')) {
if ($this->filtersForm->has($field['property'])) { if ($this->filtersForm->has($field['property'])) {
switch ($field['dataType']) { switch ($field['dataType']) {
$filter = $this->getListFilterParam($field['property']); $filter = $this->getListFilterParam($field['property']);
//$filter = $this->filtersForm->get($field['property'])->getData(); //$filter = $this->filtersForm->get($field['property'])->getData();
if ($filter !== null) { 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; break;
case 'association' : case 'association' :
$filter = $this->getListFilterParam($field['property']); $filter = $this->getListFilterParam($field['property']);
//$filter = $this->filtersForm->get($field['property'])->getData();
//$filter = $this->filtersForm->get($field['property'])->getData();
if ($filter !== null) { if ($filter !== null) {
if ($field['type_options']['multiple']) {
$queryBuilder->andWhere(':' . $field['property'] . ' MEMBER OF entity.' . $field['property'] . '');
} else {
$queryBuilder->andWhere('entity.' . $field['property'] . ' = :' . $field['property'] . '');
}
if ($filter instanceof TreeInterface && $filter->getParent() == null) {
$queryBuilder->setParameter($field['property'], array_merge(array($filter), $filter->getChildrens()->toArray()));
} else {

//TODO Faut généraliser avec TreeInterface, ça ne doit pas être ici
if($field['property'] == 'productCategories') {

$queryBuilder->andWhere(':' . $field['property'] . ' MEMBER OF entity.' . $field['property'].' OR product_categories.parent = :' . $field['property']);
$queryBuilder->setParameter($field['property'], $filter); $queryBuilder->setParameter($field['property'], $filter);
} }
else {
if ($field['type_options']['multiple']) {
$queryBuilder->andWhere(':' . $field['property'] . ' MEMBER OF entity.' . $field['property'] . '');
}
else {
$queryBuilder->andWhere('entity.' . $field['property'] . ' = :' . $field['property'] . '');
}

if ($filter instanceof TreeInterface && $filter->getParent() == null) {
$queryBuilder->setParameter($field['property'], array_merge(array($filter), $filter->getChildrens()->toArray()));
}
else {
$queryBuilder->setParameter($field['property'], $filter);
}
}
} }
break; break;
case 'datetime': case 'datetime':
} }


//TODO déplacer dans LC //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'); $queryBuilder->addOrderBy('entity.user', 'asc');
} }




//TODO finaliser la sauvegarde des filtres //TODO finaliser la sauvegarde des filtres


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


if($this->request->query->get('filterClear')){
if ($this->request->query->get('filterClear')) {
$this->session->remove($sessionParam); $this->session->remove($sessionParam);
}else {
} else {
if ($value) { if ($value) {
$this->session->set($sessionParam, $value); $this->session->set($sessionParam, $value);
} else if ($this->session->get($sessionParam) && !$this->filtersForm->isSubmitted() && $this->filtersForm->get($param)) { } else if ($this->session->get($sessionParam) && !$this->filtersForm->isSubmitted() && $this->filtersForm->get($param)) {
$value = $this->session->get($sessionParam); $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)); $this->filtersForm->get($param)->get($extraParam)->setData(new \DateTime($value));
}else{
} else {
$this->filtersForm->get($param)->get($extraParam)->setData($value); $this->filtersForm->get($param)->get($extraParam)->setData($value);
} }


}else {
} else {
//Champ association //Champ association
if ($this->filtersForm->get($param)->getConfig()->getOption('class')) { if ($this->filtersForm->get($param)->getConfig()->getOption('class')) {
$valFormated = $this->em->getRepository($this->filtersForm->get($param)->getConfig()->getOption('class'))->find($value); $valFormated = $this->em->getRepository($this->filtersForm->get($param)->getConfig()->getOption('class'))->find($value);
} }
} }


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


} }





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


} }




protected function getListParam($param, $default =null){
protected function getListParam($param, $default = null)
{
$entityName = $this->entity['name']; $entityName = $this->entity['name'];
$sessionParam = $entityName.$param;
$sessionParam = $entityName . $param;
//CUSTOM //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); $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); $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); $this->request->query->set($param, $val);
} }




$fields = $this->entity['list']['fields']; $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]); $this->dispatch(EasyAdminEvents::POST_LIST, ['paginator' => $paginator]);



+ 2
- 1
ShopBundle/Form/Backend/Filters/ListFilterType.php View File

) )
)); ));
break; break;
case 'text':
case 'string': case 'string':
$builder->add($field['property'], TextType::class, array(
$builder->add(str_replace('.', '_',$field['property']), TextType::class, array(
'required' => false, 'required' => false,
'attr'=>array( 'attr'=>array(
'class'=> ' input-sm', 'class'=> ' input-sm',

+ 22
- 5
ShopBundle/Repository/BaseRepository.php View File

use Lc\ShopBundle\Context\FilterMultipleMerchantsInterface; use Lc\ShopBundle\Context\FilterMultipleMerchantsInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface; use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\StatusInterface; use Lc\ShopBundle\Context\StatusInterface;
use Lc\ShopBundle\Services\Utils;


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


/** /**
* @param string $entityClass The class name of the entity this repository manages * @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->merchantUtils = $merchantUtils;
$this->utils = $utils;
parent::__construct($entityManager, $entityManager->getClassMetadata($this->getInterfaceClass())); parent::__construct($entityManager, $entityManager->getClassMetadata($this->getInterfaceClass()));
} }





public function findByTerm($field, $term, $limit=10){ public function findByTerm($field, $term, $limit=10){
$qb = $this->findByMerchantQuery(); $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->setParameter('term', '%'.$term.'%');
$qb->setMaxResults($limit); $qb->setMaxResults($limit);









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

+ 3
- 2
ShopBundle/Repository/ReductionCartRepository.php View File

use Lc\ShopBundle\Context\MerchantUtilsInterface; use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\OrderUtilsInterface; use Lc\ShopBundle\Context\OrderUtilsInterface;
use Lc\ShopBundle\Context\ReductionCartInterface; use Lc\ShopBundle\Context\ReductionCartInterface;
use Lc\ShopBundle\Services\Utils;


/** /**
* @method ReductionCartInterface|null find($id, $lockMode = null, $lockVersion = null) * @method ReductionCartInterface|null find($id, $lockMode = null, $lockVersion = null)
{ {
protected $orderUtils ; 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 ; $this->orderUtils = $orderUtils ;
} }



+ 5
- 0
ShopBundle/Resources/views/backend/default/field/textorempty.html.twig View File

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

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

{% endif %} {% endif %}


{% for field, metadata in _fields_visible_by_user %} {% 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 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_label = metadata.label|trans(_trans_parameters) %}
{% set _column_icon = isSortingField ? (nextSortDirection == 'DESC' ? 'fa-arrow-up' : 'fa-arrow-down') : 'fa-sort' %} {% set _column_icon = isSortingField ? (nextSortDirection == 'DESC' ? 'fa-arrow-up' : 'fa-arrow-down') : 'fa-sort' %}
{% set isFilteredField = false %} {% set isFilteredField = false %}
<th></th>{% endif %} <th></th>{% endif %}
{% for field, metadata in _fields_visible_by_user %} {% for field, metadata in _fields_visible_by_user %}
<th> <th>
{% set field = utils.getFilterPropertyClean(field) %}
{% if filters_form[field] is defined %} {% 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 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' %} {% if metadata['dataType'] == 'datetime' or metadata['dataType'] == 'date' %}
<div class="input-group input-group-sm"> <div class="input-group input-group-sm">
</div> </div>
{% else %} {% else %}
<div class="form-widget input-group-sm"> <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', { {{ form_widget(filters_form[field], {'attr': {'autocomplete': 'off', 'data-lc-autocomplete-url' : path('easyadmin', {
action: 'autocomplete', action: 'autocomplete',
field: field, field: field,

+ 21
- 0
ShopBundle/Services/Utils.php View File

use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Validator\Constraints\EqualTo; use Symfony\Component\Validator\Constraints\EqualTo;
use Symfony\Component\Validator\Constraints\NotNull;
use Symfony\Contracts\Translation\TranslatorInterface; use Symfony\Contracts\Translation\TranslatorInterface;


class Utils class Utils
'class' => 'special-field' 'class' => 'special-field'
], ],
'constraints' => [ 'constraints' => [
new NotNull(),
new EqualTo(['value' => $this->parameterBag->get('app.captcha_value'), 'message' => 'Valeur incorrecte']) new EqualTo(['value' => $this->parameterBag->get('app.captcha_value'), 'message' => 'Valeur incorrecte'])
], ],
]); ]);
return md5($key); 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…
Cancel
Save