Browse Source

Merge branch 'feature/sponsor' into develop

develop
Fab 3 years ago
parent
commit
d1e20258bd
7 changed files with 166 additions and 6 deletions
  1. +32
    -0
      ShopBundle/Event/EntityManager/EntityManagerEvent.php
  2. +35
    -0
      ShopBundle/Event/OrderShop/OrderShopChangeStatusEvent.php
  3. +86
    -0
      ShopBundle/Manager/EntityManager.php
  4. +3
    -2
      ShopBundle/Repository/BaseRepository.php
  5. +6
    -1
      ShopBundle/Repository/OrderShopRepository.php
  6. +3
    -2
      ShopBundle/Repository/UserRepository.php
  7. +1
    -1
      ShopBundle/Resources/views/backend/user/macros.html.twig

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

<?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

<?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;
}
}

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

<?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;
}

}
}

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

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()

+ 6
- 1
ShopBundle/Repository/OrderShopRepository.php View File



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)');

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

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)

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



<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>&nbsp; <span class="badge badge-info float-right">{{ group }}</span>&nbsp;
{% else %} {% else %}
<span class="badge badge-dark float-right">Aucun</span> <span class="badge badge-dark float-right">Aucun</span>

Loading…
Cancel
Save