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.

80 line
3.2KB

  1. <?php
  2. # src/EventSubscriber/EasyAdminSubscriber.php
  3. namespace Lc\ShopBundle\EventSubscriber;
  4. use Lc\ShopBundle\Context\FilterMerchantInterface;
  5. use Lc\ShopBundle\Context\FilterMultipleMerchantsInterface;
  6. use Lc\ShopBundle\Context\ProductFamilyInterface;
  7. use Lc\ShopBundle\Context\StatusInterface;
  8. use Symfony\Component\DependencyInjection\Container;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. use Symfony\Component\EventDispatcher\GenericEvent;
  11. use Symfony\Component\Security\Core\Security;
  12. class ListEventSubscriber implements EventSubscriberInterface
  13. {
  14. public $security;
  15. public function __construct(Security $security)
  16. {
  17. $this->security = $security;
  18. }
  19. public static function getSubscribedEvents()
  20. {
  21. return array(
  22. 'easy_admin.post_list' => array('setPaginatorCountStatus'),
  23. );
  24. }
  25. public function setPaginatorCountStatus(GenericEvent $event)
  26. {
  27. $paginator = $event->getSubject();
  28. $em = $event->getArgument('em');
  29. $entity = $event->getArgument('entity');
  30. $entityRepo = $em->getRepository($entity['class']);
  31. $entityObject = new $entity['class'];
  32. $criteria = array();
  33. if ($entityObject instanceof FilterMerchantInterface) {
  34. $currentMerchant = $this->security->getUser()->getMerchant();
  35. $criteria['merchant'] = $currentMerchant;
  36. }
  37. /* if ($entityObject instanceof FilterMultipleMerchantsInterface) {
  38. $paginator->nbResultsTotal = $entityRepo->count(array());
  39. // TODO : Filter sur le merchant courant; Pour le moment dans ce contexte on ne charge rien de plus, par de nbResultsOnline en fonction du merchant
  40. }else {*/
  41. if ($entityObject instanceof ProductFamilyInterface) {
  42. $paginator->nbResultsOnSale = $entityRepo->count(array('saleStatus' =>1, 'status'=> 1, 'merchant'=> $criteria['merchant']));
  43. }
  44. if ($entityObject instanceof StatusInterface) {
  45. for ($status = -1; $status <= 1; $status++) {
  46. $criteria['status'] = $status;
  47. if ($status == -1) {
  48. $paginator->nbResultsDeleted = $entityRepo->count($criteria);
  49. } elseif ($status == 0) {
  50. $paginator->nbResultsOffline = $entityRepo->count($criteria);
  51. } else if ($status == 1) {
  52. $paginator->nbResultsOnline = $entityRepo->count($criteria);
  53. }
  54. }
  55. $paginator->nbResultsTotal = $paginator->nbResultsOnline + $paginator->nbResultsOffline;
  56. }else{
  57. $paginator->nbResultsTotal = $entityRepo->count($criteria);
  58. }
  59. //}
  60. }
  61. }