Você não pode selecionar mais de 25 tópicos
Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
|
- <?php
- # src/EventSubscriber/EasyAdminSubscriber.php
- namespace Lc\ShopBundle\EventSubscriber;
-
- use Lc\ShopBundle\Context\FilterMerchantInterface;
- use Lc\ShopBundle\Context\StatusInterface;
- 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'];
- $criteria = array();
- if ($entityObject instanceof FilterMerchantInterface) {
- $currentMerchant = $this->security->getUser()->getMerchant();
- $criteria['merchant'] = $currentMerchant;
- }
-
-
- if($entityObject instanceof StatusInterface) {
- for ($status = -1; $status <= 1; $status++) {
- $criteria['status'] = $status;
- if ($status == -1) {
- $paginator->nbResultsDeleted = $entityRepo->count($criteria);
- } elseif ($status == 0) {
- $paginator->nbResultsOffline = $entityRepo->count($criteria);
- } else if ($status == 1) {
- $paginator->nbResultsOnline = $entityRepo->count($criteria);
- }
- }
- }
- }
-
- 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;
- }
- }
|