<?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; | |||||
} | |||||
} |
<?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; | |||||
} | |||||
} |
<?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; | |||||
} | |||||
} | |||||
} |
*/ | */ | ||||
protected $description; | protected $description; | ||||
/** | /** | ||||
* @ORM\Column(type="string", length=255, nullable=true) | * @ORM\Column(type="string", length=255, nullable=true) | ||||
*/ | */ | ||||
protected $devAlias; | protected $devAlias; | ||||
public function getTitle(): ?string | public function getTitle(): ?string | ||||
{ | { | ||||
return $this->title; | return $this->title; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getDevAlias(): ?string | public function getDevAlias(): ?string | ||||
{ | { | ||||
return $this->devAlias; | return $this->devAlias; |
protected $merchant; | protected $merchant; | ||||
/** | /** | ||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface", inversedBy="orders") | |||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface", inversedBy="orders", fetch="EAGER") | |||||
*/ | */ | ||||
protected $user; | protected $user; | ||||
*/ | */ | ||||
protected $orders; | protected $orders; | ||||
/** | /** | ||||
* @ORM\Column(type="string", length=64, nullable=true) | * @ORM\Column(type="string", length=64, nullable=true) | ||||
*/ | */ |
return $qb->getQuery()->getOneOrNullResult(); | 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') | return $this->createQueryBuilder('e') | ||||
->where('e.merchant = :currentMerchant') | ->where('e.merchant = :currentMerchant') | ||||
->setParameter('currentMerchant', $this->merchantUtils->getMerchantCurrent()->getId()) ; | |||||
->setParameter('currentMerchant', $merchant) ; | |||||
} | } | ||||
public function findAll() | public function findAll() |
public function findAllBy($params = []) | 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']) { | if (isset($params['count']) && $params['count']) { | ||||
$query->select('count(e.id)'); | $query->select('count(e.id)'); |
return UserInterface::class; | 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') | return $this->createQueryBuilder('e') | ||||
->innerJoin('e.userMerchants', "userMerchants") | ->innerJoin('e.userMerchants', "userMerchants") | ||||
->andWhere('userMerchants.merchant = :currentMerchant') | ->andWhere('userMerchants.merchant = :currentMerchant') | ||||
->setParameter('currentMerchant', $this->merchantUtils->getMerchantCurrent()->getId()) ; | |||||
->setParameter('currentMerchant', $merchant) ; | |||||
} | } | ||||
public function findAllByNewsletter($newsletter) | public function findAllByNewsletter($newsletter) |
{% macro list_reduction_credits(reductionCredits, user) %} | {% macro list_reduction_credits(reductionCredits, user) %} | ||||
{% set merchant_current = merchantUtils.getMerchantCurrent() %} | |||||
<table class="table table-condensed"> | <table class="table table-condensed"> | ||||
<thead> | <thead> | ||||
<tr> | <tr> | ||||
</thead> | </thead> | ||||
<tbody> | <tbody> | ||||
{% for reductionCredit in reductionCredits %} | {% for reductionCredit in reductionCredits %} | ||||
{% 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> | |||||
{% 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 %} | {% endfor %} | ||||
</tbody> | </tbody> | ||||
</table> | </table> |
{% 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> | <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 %} | {% else %} | ||||
{{ value }} | {{ value }} | ||||
{% endif %} | {% endif %} |
</th> | </th> | ||||
{% endfor %} | {% 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"' }}> | <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> | <span class="sr-only">{{ 'list.row_actions'|trans(_trans_parameters, 'EasyAdminBundle') }}</span> | ||||
</th> | </th> | ||||
{% endif %} | |||||
{#{% endif %}#} | |||||
</tr> | </tr> | ||||
{% endblock table_head %} | {% endblock table_head %} | ||||
{% block table_filters %} | {% block table_filters %} | ||||
</th> | </th> | ||||
{% endfor %} | {% endfor %} | ||||
{% if _list_item_actions|length > 0 %} | |||||
{#{% if _list_item_actions|length > 0 %}#} | |||||
<th class="actions"> | <th class="actions"> | ||||
<button type="submit" form="filters-form" class="btn btn-sm btn-info" | <button type="submit" form="filters-form" class="btn btn-sm btn-info" | ||||
data-toggle="tooltip" | data-toggle="tooltip" | ||||
</th> | </th> | ||||
{% endif %} | |||||
{# {% endif %}#} | |||||
</tr> | </tr> | ||||
{% endif %} | {% endif %} | ||||
</td> | </td> | ||||
{% endfor %} | {% endfor %} | ||||
<td class="actions"> | |||||
{% if _list_item_actions|length > 0 %} | {% if _list_item_actions|length > 0 %} | ||||
{% set _column_label = 'list.row_actions'|trans(_trans_parameters, 'EasyAdminBundle') %} | {% set _column_label = 'list.row_actions'|trans(_trans_parameters, 'EasyAdminBundle') %} | ||||
<td class="actions"> | |||||
{% block item_actions %} | {% block item_actions %} | ||||
{% set _actions_template = '@LcShop/backend/default/block/actions.html.twig' %} | {% set _actions_template = '@LcShop/backend/default/block/actions.html.twig' %} | ||||
{{ include(_actions_template, { | {{ include(_actions_template, { | ||||
item: item | item: item | ||||
}, with_context = false) }} | }, with_context = false) }} | ||||
{% endblock item_actions %} | {% endblock item_actions %} | ||||
</td> | |||||
{% endif %} | {% endif %} | ||||
</td> | |||||
</tr> | </tr> | ||||
{% endif %} | {% endif %} | ||||
{% else %} | {% else %} |
<li class="list-group-item"> | <li class="list-group-item"> | ||||
<b> <i class="fa fa-users"></i> Groupes</b> | <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> | <span class="badge badge-info float-right">{{ group }}</span> | ||||
{% else %} | {% else %} | ||||
<span class="badge badge-dark float-right">Aucun</span> | <span class="badge badge-dark float-right">Aucun</span> |