Sfoglia il codice sorgente

Merge branch 'develop' of https://forge.laclic.fr/Laclic/CaracoleBundle into develop

packProduct
Guillaume 3 anni fa
parent
commit
aead6b29ef
10 ha cambiato i file con 230 aggiunte e 7 eliminazioni
  1. +2
    -4
      Controller/AdminControllerTrait.php
  2. +1
    -0
      Controller/Product/ProductCategoryAdminController.php
  3. +20
    -0
      Doctrine/EntityManager.php
  4. +29
    -0
      Doctrine/QueryBuilder.php
  5. +122
    -0
      Field/AssociationField.php
  6. +42
    -0
      Field/Configurator/AssociationConfigurator.php
  7. +2
    -2
      Model/Product/ProductFamilyModel.php
  8. +2
    -0
      Repository/Product/ProductCategoryRepository.php
  9. +1
    -1
      Repository/SectionRepositoryQueryTrait.php
  10. +9
    -0
      Resources/translations/admin.fr.yaml

+ 2
- 4
Controller/AdminControllerTrait.php Vedi File

@@ -58,8 +58,7 @@ trait AdminControllerTrait
//TODO Gérer depuis les événements

if ($this->isInstanceOf(FilterMerchantInterface::class)) {
$queryBuilder->andWhere('entity.merchant = :merchant');
$queryBuilder->setParameter('merchant', $this->get('merchant_resolver')->getCurrent());
$queryBuilder->andWhereMerchant('entity', $this->get('merchant_resolver')->getCurrent());
}

if ($this->isInstanceOf(FilterMultipleMerchantsInterface::class)) {
@@ -68,8 +67,7 @@ trait AdminControllerTrait
}

if ($this->isInstanceOf(FilterSectionInterface::class)) {
$queryBuilder->andWhere('entity.section = :section');
$queryBuilder->setParameter('section', $this->get('section_resolver')->getCurrent());
$queryBuilder->andWhereSection('entity', $this->get('section_resolver')->getCurrent());
}

return $queryBuilder;

+ 1
- 0
Controller/Product/ProductCategoryAdminController.php Vedi File

@@ -2,6 +2,7 @@

namespace Lc\CaracoleBundle\Controller\Product;

//use Lc\CaracoleBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;

+ 20
- 0
Doctrine/EntityManager.php Vedi File

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

namespace Lc\CaracoleBundle\Doctrine;

use Lc\SovBundle\Doctrine\EntityManager as SovEntityManager;

/**
* class EntityManager.
*
* @author La clic !!!!
*/
class EntityManager extends SovEntityManager
{

public function createQueryBuilder()
{
return new QueryBuilder($this);
}

}

+ 29
- 0
Doctrine/QueryBuilder.php Vedi File

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

namespace Lc\CaracoleBundle\Doctrine;

use Lc\SovBundle\Doctrine\QueryBuilder as SovQueryBuilder;

/**
* class EntityManager.
*
* @author La clic !!!!
*/
class QueryBuilder extends SovQueryBuilder
{

public function andWhereMerchant($dqlId, $merchant):self
{
$this->andWhere($dqlId.'.merchant = :merchant');
$this->setParameter('merchant', $merchant);
return $this;
}

public function andWhereSection($dqlId, $section):self
{
$this->andWhere($dqlId.'.section = :section');
$this->setParameter('section', $section);
return $this;
}

}

+ 122
- 0
Field/AssociationField.php Vedi File

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

namespace Lc\CaracoleBundle\Field;

use Doctrine\ORM\EntityRepository;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface;
use EasyCorp\Bundle\EasyAdminBundle\Field\FieldTrait;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;


final class AssociationField implements FieldInterface
{
use FieldTrait;

public const OPTION_AUTOCOMPLETE = 'autocomplete';
public const OPTION_CRUD_CONTROLLER = 'crudControllerFqcn';
public const OPTION_WIDGET = 'widget';
public const OPTION_QUERY_BUILDER_CALLABLE = 'queryBuilderCallable';
/** @internal this option is intended for internal use only */
public const OPTION_RELATED_URL = 'relatedUrl';
/** @internal this option is intended for internal use only */
public const OPTION_DOCTRINE_ASSOCIATION_TYPE = 'associationType';

public const WIDGET_AUTOCOMPLETE = 'autocomplete';
public const WIDGET_NATIVE = 'native';

/** @internal this option is intended for internal use only */
public const PARAM_AUTOCOMPLETE_CONTEXT = 'autocompleteContext';

protected $queryBuilderParameters = array();

/**
* @param string|false|null $label
*/
public static function new(string $propertyName, $label = null): self
{
return (new self())
->setProperty($propertyName)
->setLabel($label)
->setTemplateName('crud/field/association')
->setFormType(EntityType::class)
->addCssClass('field-association')
->setCustomOption(self::OPTION_AUTOCOMPLETE, false)
->setCustomOption(self::OPTION_CRUD_CONTROLLER, null)
->setCustomOption(self::OPTION_WIDGET, self::WIDGET_AUTOCOMPLETE)
->setCustomOption(self::OPTION_QUERY_BUILDER_CALLABLE, null)
->setCustomOption(self::OPTION_RELATED_URL, null)
->setCustomOption(self::OPTION_DOCTRINE_ASSOCIATION_TYPE, null);
}

public function setFilterOnSection(SectionInterface $section): self
{
$this->queryBuilderParameters['section'] = $section;

return $this;
}

public function setFilterOnMerchant(MerchantInterface $merchant): self
{
$this->queryBuilderParameters['merchant'] = $merchant;

return $this;
}

public function setFilterOnDevAlias(string $devAlias): self
{
$this->queryBuilderParameters['devAlias'] = $devAlias;

return $this;
}

public function initQueryBuilder(): self
{
$param = $this->queryBuilderParameters;
$this->setFormTypeOption(
'query_builder',
function (EntityRepository $er) use ($param) {
$qb = $er->createQueryBuilder('e');
if (isset($param['section'])) {
$qb->andWhereSection('e',$param['section']);
}

if (isset($param['merchant'])) {
$qb->andWhereMerchant('e',$param['merchant']);
}

/*if (isset($param['devAlias'])) {
$qb->andWhere('e.devAlias = :devAlias')->setParameter(
'devAlias',
$param['devAlias']
);
}*/

return $qb;
}
);
return $this;
}

public function autocomplete(): self
{
$this->setCustomOption(self::OPTION_AUTOCOMPLETE, true);

return $this;
}

public function renderAsNativeWidget(bool $asNative = true): self
{
$this->setCustomOption(self::OPTION_WIDGET, $asNative ? self::WIDGET_NATIVE : self::WIDGET_AUTOCOMPLETE);

return $this;
}

public function setCrudController(string $crudControllerFqcn): self
{
$this->setCustomOption(self::OPTION_CRUD_CONTROLLER, $crudControllerFqcn);

return $this;
}
}

+ 42
- 0
Field/Configurator/AssociationConfigurator.php Vedi File

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

namespace Lc\CaracoleBundle\Field\Configurator;

use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField as EaAssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldConfiguratorInterface;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
use EasyCorp\Bundle\EasyAdminBundle\Factory\EntityFactory;
use EasyCorp\Bundle\EasyAdminBundle\Field\Configurator\AssociationConfigurator as EaAssociationConfigurator;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use Lc\CaracoleBundle\Field\AssociationField;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
*/
final class AssociationConfigurator implements FieldConfiguratorInterface
{
private $parent;
private $entityFactory;
private $adminUrlGenerator;
private $translator;

public function __construct(EaAssociationConfigurator $associationConfigurator, EntityFactory $entityFactory, AdminUrlGenerator $adminUrlGenerator, TranslatorInterface $translator)
{
$this->parent = $associationConfigurator;
$this->entityFactory = $entityFactory;
$this->adminUrlGenerator = $adminUrlGenerator;
$this->translator = $translator;
}
public function supports(FieldDto $field, EntityDto $entityDto): bool
{
return AssociationField::class === $field->getFieldFqcn() || EaAssociationField::class === $field->getFieldFqcn();
}

public function configure(FieldDto $field, EntityDto $entityDto, AdminContext $context): void
{
$this->parent->configure($field, $entityDto, $context);
}
}

+ 2
- 2
Model/Product/ProductFamilyModel.php Vedi File

@@ -104,7 +104,7 @@ abstract class ProductFamilyModel extends AbstractFullEntity implements ProductP
const PROPERTY_ORGANIC_LABEL_AB = 'ab';
const PROPERTY_ORGANIC_LABEL_NP = 'nature-progres';
const PROPERTY_ORGANIC_LABEL_HVE = 'hve';
const PROPERTY_ORGANIC_LABEL_TRVR = 'trvr';
const PROPERTY_ORGANIC_LABEL_TVVR = 'tvvr';

public function getPropertyOrganicLabelChoices(): array
{
@@ -112,7 +112,7 @@ abstract class ProductFamilyModel extends AbstractFullEntity implements ProductP
self::PROPERTY_ORGANIC_LABEL_AB,
self::PROPERTY_ORGANIC_LABEL_NP,
self::PROPERTY_ORGANIC_LABEL_HVE,
self::PROPERTY_ORGANIC_LABEL_TRVR,
self::PROPERTY_ORGANIC_LABEL_TVVR,
];
}


+ 2
- 0
Repository/Product/ProductCategoryRepository.php Vedi File

@@ -8,6 +8,8 @@ use Lc\SovBundle\Repository\AbstractRepository;

class ProductCategoryRepository extends AbstractRepository
{


public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, ProductCategory::class);

+ 1
- 1
Repository/SectionRepositoryQueryTrait.php Vedi File

@@ -8,6 +8,6 @@ trait SectionRepositoryQueryTrait
{
public function filterBySection(SectionInterface $section)
{
$this->andWhere('.section = :section')->setParameter(':section', $section);
$this->andWhereSection($this->id, $section);
}
}

+ 9
- 0
Resources/translations/admin.fr.yaml Vedi File

@@ -41,12 +41,18 @@ entity:
panels:
address: Adresse
fields:
property: Caractéristiques
propertyValue : Valeurs
parent: Parent
saleStatus: En vente
subtitle: Sous-titre
address: Adresse
merchant: Marchand
taxRate: Règle de taxe
behaviorTaxRate: Avec ou sans TVA
behaviorTaxRateChoices:
tax-excluded: TVA exclue
tax-included: Tva incluse
PointSale:
label: Point de vente
label_plurial: Points de vente
@@ -115,6 +121,9 @@ entity:
label: Unité
label_plurial: Unités
fields:
unitChoices:
percent: Pourcentage
amount: Montant
unit: Unité
wording: Nom
wordingUnit: Nom long

Loading…
Annulla
Salva