<?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\EntityManager as DoctrineEntityManager; | |||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use Lc\ShopBundle\Event\EntityManager\EntityManagerEvent; | |||||
//use Lc\ShopBundle\IModel\EntityInterface; | |||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | |||||
/** | |||||
* class EntityManager. | |||||
* | |||||
* @author Simon Vieille <simon@deblan.fr> | |||||
*/ | |||||
class EntityManager | |||||
{ | |||||
protected $eventDispatcher; | |||||
protected $entityManager; | |||||
public function __construct(EventDispatcherInterface $eventDispatcher, EntityManagerInterface $entityManager) | |||||
{ | |||||
$this->eventDispatcher = $eventDispatcher; | |||||
$this->entityManager = $entityManager; | |||||
} | |||||
public function getRepository($className) | |||||
{ | |||||
return $this->entityManager->getRepository($this->getEntityName($className)); | |||||
} | |||||
public function create($entity): self | |||||
{ | |||||
$this->persist($entity); | |||||
$this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::CREATE_EVENT); | |||||
return $this; | |||||
} | |||||
public function update($entity): self | |||||
{ | |||||
$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; | |||||
} | |||||
} | |||||
} |
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) |
<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> |