|
- <?php
- # src/EventSubscriber/EasyAdminSubscriber.php
- namespace Lc\ShopBundle\EventSubscriber;
-
- use Lc\ShopBundle\Context\FilterMerchantInterface;
- use Symfony\Component\DependencyInjection\Container;
- use Symfony\Component\EventDispatcher\EventSubscriberInterface;
- use Symfony\Component\EventDispatcher\GenericEvent;
- use Symfony\Component\Security\Core\Security;
-
-
- class EasyAdminSubscriber implements EventSubscriberInterface
- {
- public $security;
-
- public function __construct(Security $security)
- {
- $this->security = $security;
- }
-
- public static function getSubscribedEvents()
- {
- return array(
- 'easy_admin.post_list' => array('setPaginatorCountStatus'),
- );
- }
-
- public function setPaginatorCountStatus(GenericEvent $event)
- {
- $paginator = $event->getSubject();
- $em = $event->getArgument('em');
- $entity = $event->getArgument('entity');
- $entityRepo = $em->getRepository($entity['class']);
-
- $entityObject = new $entity['class'];
- if ($entityObject instanceof FilterMerchantInterface) {
- $currentMerchant = $this->security->getUser()->getMerchant();
- $paginator->nbResultsOnline = $entityRepo->count(array('status'=>1,'merchant'=>$currentMerchant));
- $paginator->nbResultsOffline = $entityRepo->count(array('status'=>0,'merchant'=>$currentMerchant));
- $paginator->nbResultsDeleted = $entityRepo->count(array('status'=>-1,'merchant'=>$currentMerchant));
- }else{
-
- $paginator->nbResultsOnline = $entityRepo->count(array('status'=>1));
- $paginator->nbResultsOffline = $entityRepo->count(array('status'=>0));
- $paginator->nbResultsDeleted = $entityRepo->count(array('status'=>-1));
- }
- }
-
- public function setBlogPostSlug(GenericEvent $event)
- {
- $entity = $event->getSubject();
-
- if (!($entity instanceof BlogPost)) {
- return;
- }
-
- $slug = $this->slugger->slugify($entity->getTitle());
- $entity->setSlug($slug);
-
- $event['entity'] = $entity;
- }
- }
|