Selaa lähdekoodia

[Feature] Parrainage

develop
Fab 3 vuotta sitten
vanhempi
commit
0387cae468
7 muutettua tiedostoa jossa 166 lisäystä ja 6 poistoa
  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 Näytä tiedosto

@@ -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 Näytä tiedosto

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

+ 86
- 0
ShopBundle/Manager/EntityManager.php Näytä tiedosto

@@ -0,0 +1,86 @@
<?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 Näytä tiedosto

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

+ 6
- 1
ShopBundle/Repository/OrderShopRepository.php Näytä tiedosto

@@ -118,7 +118,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)');

+ 3
- 2
ShopBundle/Repository/UserRepository.php Näytä tiedosto

@@ -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
- 1
ShopBundle/Resources/views/backend/user/macros.html.twig Näytä tiedosto

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

Loading…
Peruuta
Tallenna