app/Plugin/MailMagazine4/Event/MailMagazineHistoryFilePaginationSubscriber.php line 37

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Plugin\MailMagazine4\Event;
  13. use Knp\Component\Pager\Event\ItemsEvent;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. use Plugin\MailMagazine4\Service\MailMagazineService;
  16. class MailMagazineHistoryFilePaginationSubscriber implements EventSubscriberInterface
  17. {
  18.     /**
  19.      * @var MailMagazineService
  20.      */
  21.     protected $mailMagazineService;
  22.     /**
  23.      * MailMagazineHistoryFilePaginationSubscriber constructor.
  24.      *
  25.      * @param MailMagazineService $mailMagazineService
  26.      */
  27.     public function __construct(MailMagazineService $mailMagazineService)
  28.     {
  29.         $this->mailMagazineService $mailMagazineService;
  30.     }
  31.     public function items(ItemsEvent $event)
  32.     {
  33.         $mailMagazineDir $this->mailMagazineService->getMailMagazineDir();
  34.         if (!is_string($event->target) || strpos($event->target$mailMagazineDir) !== 0) {
  35.             return;
  36.         }
  37.         $event->stopPropagation();
  38.         $file $event->target;
  39.         if (!file_exists($file)) {
  40.             $event->count 0;
  41.             $event->items = [];
  42.             return;
  43.         }
  44.         $skip $event->getOffset();
  45.         $fp fopen($file'r');
  46.         $count $event->getLimit();
  47.         $total 0;
  48.         $event->items = [];
  49.         while ($line fgets($fp)) {
  50.             $total++;
  51.             if ($skip-- > 0) {
  52.                 continue;
  53.             }
  54.             if ($count 0) {
  55.                 list($status$customerId$email$name) = explode(','str_replace(PHP_EOL''$line), 4);
  56.                 $event->items[] = [
  57.                     'status' => $status,
  58.                     'customerId' => $customerId,
  59.                     'email' => $email,
  60.                     'name' => $name,
  61.                 ];
  62.             }
  63.             --$count;
  64.         }
  65.         $event->count $total;
  66.     }
  67.     public static function getSubscribedEvents()
  68.     {
  69.         return [
  70.             'knp_pager.items' => ['items'1],
  71.         ];
  72.     }
  73. }