Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

63 lines
2.3KB

  1. <?php
  2. # src/EventSubscriber/EasyAdminSubscriber.php
  3. namespace Lc\ShopBundle\EventSubscriber;
  4. use Lc\ShopBundle\Context\FilterMerchantInterface;
  5. use Symfony\Component\DependencyInjection\Container;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\EventDispatcher\GenericEvent;
  8. use Symfony\Component\Security\Core\Security;
  9. class EasyAdminSubscriber implements EventSubscriberInterface
  10. {
  11. public $security;
  12. public function __construct(Security $security)
  13. {
  14. $this->security = $security;
  15. }
  16. public static function getSubscribedEvents()
  17. {
  18. return array(
  19. 'easy_admin.post_list' => array('setPaginatorCountStatus'),
  20. );
  21. }
  22. public function setPaginatorCountStatus(GenericEvent $event)
  23. {
  24. $paginator = $event->getSubject();
  25. $em = $event->getArgument('em');
  26. $entity = $event->getArgument('entity');
  27. $entityRepo = $em->getRepository($entity['class']);
  28. $entityObject = new $entity['class'];
  29. if ($entityObject instanceof FilterMerchantInterface) {
  30. $currentMerchant = $this->security->getUser()->getMerchant();
  31. $paginator->nbResultsOnline = $entityRepo->count(array('status'=>1,'merchant'=>$currentMerchant));
  32. $paginator->nbResultsOffline = $entityRepo->count(array('status'=>0,'merchant'=>$currentMerchant));
  33. $paginator->nbResultsDeleted = $entityRepo->count(array('status'=>-1,'merchant'=>$currentMerchant));
  34. }else{
  35. $paginator->nbResultsOnline = $entityRepo->count(array('status'=>1));
  36. $paginator->nbResultsOffline = $entityRepo->count(array('status'=>0));
  37. $paginator->nbResultsDeleted = $entityRepo->count(array('status'=>-1));
  38. }
  39. }
  40. public function setBlogPostSlug(GenericEvent $event)
  41. {
  42. $entity = $event->getSubject();
  43. if (!($entity instanceof BlogPost)) {
  44. return;
  45. }
  46. $slug = $this->slugger->slugify($entity->getTitle());
  47. $entity->setSlug($slug);
  48. $event['entity'] = $entity;
  49. }
  50. }