Browse Source

Merge branch 'develop'

master^2
Fab 3 years ago
parent
commit
5521479982
17 changed files with 266 additions and 43 deletions
  1. +32
    -0
      ShopBundle/Event/EntityManager/EntityManagerEvent.php
  2. +35
    -0
      ShopBundle/Event/OrderShop/OrderShopChangeStatusEvent.php
  3. +5
    -5
      ShopBundle/Form/Frontend/TicketType.php
  4. +104
    -0
      ShopBundle/Manager/EntityManager.php
  5. +1
    -1
      ShopBundle/Model/OrderShop.php
  6. +3
    -2
      ShopBundle/Repository/BaseRepository.php
  7. +9
    -3
      ShopBundle/Repository/OrderShopRepository.php
  8. +3
    -2
      ShopBundle/Repository/UserRepository.php
  9. +1
    -0
      ShopBundle/Resources/translations/lcshop.fr.yaml
  10. +27
    -0
      ShopBundle/Resources/views/backend/default/block/list_ordersgiftvoucher.html.twig
  11. +22
    -19
      ShopBundle/Resources/views/backend/default/block/macros.html.twig
  12. +3
    -1
      ShopBundle/Resources/views/backend/default/field/user.html.twig
  13. +8
    -6
      ShopBundle/Resources/views/backend/default/list.html.twig
  14. +1
    -1
      ShopBundle/Resources/views/backend/user/macros.html.twig
  15. +1
    -1
      ShopBundle/Resources/views/backend/user/show.html.twig
  16. +2
    -2
      ShopBundle/Services/Order/OrderUtilsReductionTrait.php
  17. +9
    -0
      ShopBundle/Services/Utils.php

+ 32
- 0
ShopBundle/Event/EntityManager/EntityManagerEvent.php View File

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

namespace Lc\ShopBundle\Event\EntityManager;

use Symfony\Contracts\EventDispatcher\Event;

/**
* class EntityEvent.
*
* @author Simon Vieille <simon@deblan.fr>
*/
class EntityManagerEvent extends Event
{
const CREATE_EVENT = 'entity_manager_event.create';
const UPDATE_EVENT = 'entity_manager_event.update';
const DELETE_EVENT = 'entity_manager_event.delete';
const PRE_CREATE_EVENT = 'entity_manager_event.pre_create';
const PRE_UPDATE_EVENT = 'entity_manager_event.pre_update';
const PRE_DELETE_EVENT = 'entity_manager_event.pre_delete';

protected $entity;

public function __construct($entity)
{
$this->entity = $entity;
}

public function getEntity()
{
return $this->entity;
}
}

+ 35
- 0
ShopBundle/Event/OrderShop/OrderShopChangeStatusEvent.php View File

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

namespace Lc\ShopBundle\Event\OrderShop;

use Symfony\Contracts\EventDispatcher\Event;

/**
* class EntityEvent.
*
* @author Simon Vieille <simon@deblan.fr>
*/
class OrderShopChangeStatusEvent extends Event
{
const PRE_CHANGE_STATUS = 'order_shop_event.pre_change_status';
const POST_CHANGE_STATUS = 'order_shop_event.post_change_status';

protected $orderShop;
protected $orderStatus;

public function __construct($orderShop, $orderStatus)
{
$this->orderShop = $orderShop;
$this->orderStatus = $orderStatus;
}

public function getOrderShop()
{
return $this->orderShop;
}

public function getOrderStatus()
{
return $this->orderStatus;
}
}

+ 5
- 5
ShopBundle/Form/Frontend/TicketType.php View File

@@ -23,6 +23,7 @@ class TicketType extends AbstractType
protected $security ;
protected $em ;
protected $priceUtils ;
protected $utils ;

public function __construct(Security $security, EntityManagerInterface $em, UtilsManager $utilsManager)
{
@@ -30,6 +31,7 @@ class TicketType extends AbstractType
$this->em = $em ;
$this->orderShopRepository = $this->em->getRepository(OrderShop::class) ;
$this->priceUtils = $utilsManager->getPriceUtils() ;
$this->utils = $utilsManager->getUtils() ;
}

public function buildForm(FormBuilderInterface $builder, array $options)
@@ -83,13 +85,11 @@ class TicketType extends AbstractType
]) ;
}
else {
// captcha (honey pot)
$builder->add('body', TextType::class, [
'label' => 'Body',
'required' => false,
]) ;
// captcha
$this->utils->addCaptchaType($builder);
}


$builder->add('subject', TextType::class, [
'label' => 'Sujet'
])

+ 104
- 0
ShopBundle/Manager/EntityManager.php View File

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

namespace Lc\ShopBundle\Manager;

use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\UserInterface;
use Lc\ShopBundle\Event\EntityManager\EntityManagerEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Security\Core\Security;

/**
* class EntityManager.
*
* @author Simon Vieille <simon@deblan.fr>
*/
class EntityManager
{
protected $eventDispatcher;
protected $entityManager;
protected $security;
protected $userSystem = null;

public function __construct(EventDispatcherInterface $eventDispatcher, EntityManagerInterface $entityManager, Security $security)
{
$this->eventDispatcher = $eventDispatcher;
$this->entityManager = $entityManager;
$this->security = $security;
}


public function getUserSystem()
{
if ($this->userSystem === null) {
$this->userSystem = $this->getRepository(UserInterface::class)->findOneByDevAlias('system');
}
return $this->userSystem;
}

public function getRepository($className)
{
return $this->entityManager->getRepository($this->getEntityName($className));
}


public function create($entity): self
{

if ($this->security->getUser() === null) {
$entity->setUpdatedBy($this->getUserSystem());
$entity->setCreadtedBy($this->getUserSystem());
}
$this->persist($entity);
$this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::CREATE_EVENT);
return $this;
}

public function update($entity): self
{
if ($this->security->getUser() === null) {
$entity->setUpdatedBy($this->getUserSystem());
}
$this->persist($entity);
$this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::UPDATE_EVENT);

return $this;
}

public function delete($entity): self
{
$this->remove($entity);
$this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::DELETE_EVENT);

return $this;
}

public function flush(): self
{
$this->entityManager->flush();

return $this;
}

public function clear(): self
{
$this->entityManager->clear();

return $this;
}

protected function persist($entity)
{
$this->entityManager->persist($entity);
}

public function getEntityName($className)
{
if (substr($className, -9) === 'Interface') {
return $this->entityManager->getClassMetadata($className)->getName();
} else {
return $className;
}

}
}

+ 1
- 1
ShopBundle/Model/OrderShop.php View File

@@ -23,7 +23,7 @@ abstract class OrderShop extends AbstractEntity implements FilterMerchantInterfa
protected $merchant;

/**
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface", inversedBy="orders")
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface", inversedBy="orders", fetch="EAGER")
*/
protected $user;


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

@@ -66,11 +66,12 @@ class BaseRepository extends EntityRepository implements ServiceEntityRepository
return $qb->getQuery()->getOneOrNullResult();
}

public function findByMerchantQuery() :QueryBuilder
public function findByMerchantQuery($merchant = null) :QueryBuilder
{
if($merchant === false || $merchant===null)$merchant = $this->merchantUtils->getMerchantCurrent();
return $this->createQueryBuilder('e')
->where('e.merchant = :currentMerchant')
->setParameter('currentMerchant', $this->merchantUtils->getMerchantCurrent()->getId()) ;
->setParameter('currentMerchant', $merchant) ;
}

public function findAll()

+ 9
- 3
ShopBundle/Repository/OrderShopRepository.php View File

@@ -4,6 +4,7 @@ namespace Lc\ShopBundle\Repository;

use App\Entity\DeliveryAvailabilityPointSale;
use App\Entity\DeliveryAvailabilityZone;
use App\Entity\PointSale;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
use Lc\ShopBundle\Context\DefaultRepositoryInterface;
@@ -118,7 +119,12 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt

public function findAllBy($params = [])
{
$query = $this->findByMerchantQuery();

if(isset($params['merchant'])){
$query = $this->findByMerchantQuery($params['merchant']);
}else{
$query = $this->findByMerchantQuery();
}

if (isset($params['count']) && $params['count']) {
$query->select('count(e.id)');
@@ -232,11 +238,11 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt
}

if($setParameterHorsTournee) {
$query->setParameter('devAliasHorsTournee', 'horstournee') ;
$query->setParameter('devAliasHorsTournee', PointSale::DEV_ALIAS_OFF_CIRCUIT) ;
}

if($setParameterGiftVoucher) {
$query->setParameter('devAliasGiftVoucher', 'giftvoucher') ;
$query->setParameter('devAliasGiftVoucher', PointSale::DEV_ALIAS_GIFT_VOUCHER) ;
}

if (isset($params['deliveryAvailability'])) {

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

@@ -19,12 +19,13 @@ class UserRepository extends BaseRepository implements DefaultRepositoryInterfac
return UserInterface::class;
}

public function findByMerchantQuery() :QueryBuilder
public function findByMerchantQuery($merchant = null) :QueryBuilder
{
if($merchant === false || $merchant===null)$merchant = $this->merchantUtils->getMerchantCurrent();
return $this->createQueryBuilder('e')
->innerJoin('e.userMerchants', "userMerchants")
->andWhere('userMerchants.merchant = :currentMerchant')
->setParameter('currentMerchant', $this->merchantUtils->getMerchantCurrent()->getId()) ;
->setParameter('currentMerchant', $merchant) ;
}

public function findAllByNewsletter($newsletter)

+ 1
- 0
ShopBundle/Resources/translations/lcshop.fr.yaml View File

@@ -78,6 +78,7 @@ group:
orderStatusHistories: Historique de changement de statut
waitingBankReturn: Commandes en attente de retour banque
list: Liste des commandes
giftVoucher: Commandes de bons cadeaux
Ticket:
listMessages: Liste des messages
list: Tickets ouverts

+ 27
- 0
ShopBundle/Resources/views/backend/default/block/list_ordersgiftvoucher.html.twig View File

@@ -0,0 +1,27 @@
<table class="table table-condensed" id="address-list">
<thead>
<tr>
<th>Id</th>
<th>Utilisateurs</th>
<th>Date</th>
<th></th>
</tr>
</thead>
<tbody>
{% for order in orderShopsWeekGiftVoucher %}
<tr>
<td>{{ order.id }}</td>
<td>{{ order.user }}</td>
<td>{{ order.updatedAt|date('d-m H:i') }}</td>
<td><a class="btn-sm btn-success"
href="{{ path('easyadmin', {id: order.id, entity: 'OrderShop', action: 'show'}) }}">
<i class="fas fa-eye"></i>
</a></td>
</tr>
{% else %}
<tr>
<td colspan="4"><i>Aucune commande de bons cadeaux</i></td>
{% endfor %}
</tbody>
</table>


+ 22
- 19
ShopBundle/Resources/views/backend/default/block/macros.html.twig View File

@@ -331,7 +331,8 @@



{% macro list_reduction_credits(reductionCredits) %}
{% macro list_reduction_credits(reductionCredits, user) %}
{% set merchant_current = merchantUtils.getMerchantCurrent() %}
<table class="table table-condensed">
<thead>
<tr>
@@ -344,24 +345,26 @@
</thead>
<tbody>
{% for reductionCredit in reductionCredits %}
{% set isUsed = orderUtils.isReductionCreditUsed(reductionCredit) %}
<tr>
<td>{{ reductionCredit.title }}</td>
<td>
{{ reductionCredit.value|format_price(false) }}
</td>
<td>
{% include '@EasyAdmin/default/field_boolean.html.twig' with {value: reductionCredit.status} %}
</td>
<td>
{% include '@EasyAdmin/default/field_boolean.html.twig' with {value: isUsed} %}
</td>
<td>
{% if isUsed == false %}
{{ _self.button('ReductionCredit', 'edit', reductionCredit.id, 'primary') }}
{% endif %}
</td>
</tr>
{% if reductionCredit.getMerchant() == merchant_current %}
{% set isUsed = orderUtils.isReductionCreditUsed(reductionCredit, user) %}
<tr>
<td>{{ reductionCredit.title }}</td>
<td>
{{ reductionCredit.value|format_price(false) }}
</td>
<td>
{% include '@EasyAdmin/default/field_boolean.html.twig' with {value: reductionCredit.status} %}
</td>
<td>
{% include '@EasyAdmin/default/field_boolean.html.twig' with {value: isUsed} %}
</td>
<td>
{% if isUsed == false %}
{{ _self.button('ReductionCredit', 'edit', reductionCredit.id, 'primary') }}
{% endif %}
</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>

+ 3
- 1
ShopBundle/Resources/views/backend/default/field/user.html.twig View File

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

+ 8
- 6
ShopBundle/Resources/views/backend/default/list.html.twig View File

@@ -240,11 +240,11 @@
</th>
{% endfor %}

{% if _list_item_actions|length > 0 %}
{# {% if _list_item_actions|length > 0 %}#}
<th {% if _entity_config.list.collapse_actions %}width="10px"{% endif %} {{ easyadmin_config('design.rtl') ? 'dir="rtl"' }}>
<span class="sr-only">{{ 'list.row_actions'|trans(_trans_parameters, 'EasyAdminBundle') }}</span>
</th>
{% endif %}
{#{% endif %}#}
</tr>
{% endblock table_head %}
{% block table_filters %}
@@ -287,7 +287,7 @@

</th>
{% endfor %}
{% if _list_item_actions|length > 0 %}
{#{% if _list_item_actions|length > 0 %}#}
<th class="actions">
<button type="submit" form="filters-form" class="btn btn-sm btn-info"
data-toggle="tooltip"
@@ -307,7 +307,7 @@


</th>
{% endif %}
{# {% endif %}#}

</tr>
{% endif %}
@@ -353,9 +353,10 @@
</td>
{% endfor %}

<td class="actions">
{% if _list_item_actions|length > 0 %}
{% set _column_label = 'list.row_actions'|trans(_trans_parameters, 'EasyAdminBundle') %}
<td class="actions">
{% block item_actions %}
{% set _actions_template = '@LcShop/backend/default/block/actions.html.twig' %}
{{ include(_actions_template, {
@@ -368,8 +369,9 @@
item: item
}, with_context = false) }}
{% endblock item_actions %}
</td>
{% endif %}
</td>

</tr>
{% endif %}
{% else %}

+ 1
- 1
ShopBundle/Resources/views/backend/user/macros.html.twig View File

@@ -37,7 +37,7 @@

<li class="list-group-item">
<b> <i class="fa fa-users"></i> Groupes</b>
{% for group in user.groups %}
{% for group in user.groupUsers %}
<span class="badge badge-info float-right">{{ group }}</span>&nbsp;
{% else %}
<span class="badge badge-dark float-right">Aucun</span>

+ 1
- 1
ShopBundle/Resources/views/backend/user/show.html.twig View File

@@ -53,7 +53,7 @@

{% if entity.reductionCredits|length %}
{{ macros.card_start('ReductionCredit.list', 'warning card-outline', false) }}
{{ macros.list_reduction_credits(entity.reductionCredits) }}
{{ macros.list_reduction_credits(entity.reductionCredits, entity) }}
{{ macros.card_end() }}
{% endif %}


+ 2
- 2
ShopBundle/Services/Order/OrderUtilsReductionTrait.php View File

@@ -200,8 +200,8 @@ trait OrderUtilsReductionTrait
}
}

public function isReductionCreditUsed($reductionCredit){
if($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit)) {
public function isReductionCreditUsed($reductionCredit, $user = false){
if($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $user)) {
return true;
}else{
return false;

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

@@ -87,6 +87,15 @@ class Utils
return $text;
}

public function limitTextByLength($text, $length, $append = '...')
{
if(strlen($text) > $length) {
$text = substr($text, 0, $length) . $append ;
}

return $text ;
}

function truncateHtml($text, $length = 100, $ending = '...', $exact = false, $considerHtml = true)
{
if ($considerHtml) {

Loading…
Cancel
Save