You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EasyAdminSubscriber.php 2.6KB

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