vendor/elements/demi-bundle/src/Elements/Demi/Event/Search/Listing.php line 161

Open in your IDE?
  1. <?php
  2. /**
  3.  * Elements DeMI
  4.  *
  5.  * This source file is available under the elements DeMI license version 1
  6.  *
  7.  *  @copyright  Copyright (c) elements.at New Media Solutions GmbH (https://www.elements.at/)
  8.  *  @license    elements DeMI Lizenz Version 1 (https://www.elements.at/de/demi-lizenz)
  9.  */
  10. namespace Elements\Demi\Event\Search;
  11. use Elements\Demi\Deskline\Exception;
  12. use Pimcore\Model\Paginator\PaginateListingInterface;
  13. class Listing implements \IteratorPaginateListingInterface
  14. {
  15.     /**
  16.      * @var \Elements\Demi\Event\Search\Parameter
  17.      */
  18.     protected $parameter null;
  19.     /**
  20.      * @var int
  21.      */
  22.     protected $pageSize 10;
  23.     /**
  24.      * @var null
  25.      */
  26.     protected $randomSeed null;
  27.     /**
  28.      * @var \Elements\Demi\Deskline\Service\Search|null
  29.      */
  30.     protected $adapter null;
  31.     /**
  32.      * @var array
  33.      */
  34.     protected $objects = [];
  35.     /**
  36.      * @var int
  37.      */
  38.     protected $count 0;
  39.     /**
  40.      * Listing constructor.
  41.      *
  42.      * @param \Elements\Demi\Deskline\Service\Search $adapter
  43.      * @param int $page
  44.      * @param int $entriesPerPage
  45.      */
  46.     public function __construct(\Elements\Demi\Deskline\Service\Search $adapter, protected $page 1$entriesPerPage 10)
  47.     {
  48.         $this->pageSize $entriesPerPage;
  49.         $this->adapter $adapter;
  50.     }
  51.     /**
  52.      * @return Parameter
  53.      *
  54.      * @throws Exception
  55.      */
  56.     public function getParameter(): Parameter
  57.     {
  58.         if (empty($this->parameter)) {
  59.             throw new Exception('Parameter not set!');
  60.         }
  61.         return $this->parameter;
  62.     }
  63.     /**
  64.      * @param Parameter $parameter
  65.      */
  66.     public function setParameter(Parameter $parameter)
  67.     {
  68.         if (!$parameter->getCustomOrderKey() && !$parameter->getOrderConst()) {
  69.             $parameter->setOrderConst(\Elements\Demi\Deskline\SearchParameter\Events::ORDER_BY_DATE_BEGIN_ASC);
  70.         }
  71.         $this->parameter $parameter;
  72.     }
  73.     /**
  74.      * @return int
  75.      */
  76.     public function count()
  77.     {
  78.         if (!$this->objects) {
  79.             $this->load();
  80.         }
  81.         return $this->count;
  82.     }
  83.     /**
  84.      * @param int $page
  85.      * @param int $itemCountPerPage
  86.      *
  87.      * @return array
  88.      *
  89.      */
  90.     public function getItems($page$itemCountPerPage)
  91.     {
  92.         if (! $this->objects) {
  93.             $this->page $page;
  94.             $this->pageSize $itemCountPerPage;
  95.             $this->load();
  96.         }
  97.         return $this->objects;
  98.     }
  99.     /**
  100.      * @inheritdoc
  101.      */
  102.     public function load()
  103.     {
  104.         $result $this->adapter->searchEvent($this->getParameter(), $this->page$this->pageSize$this->getParameter()->getOrderConst(), $this->randomSeed$this->getParameter()->getCustomOrderKey(), $this->getParameter()->getCustomOrder());
  105.         $this->count $result->getTotalAmount();
  106.         $this->objects $result->getEntries();
  107.     }
  108.     /**
  109.      * @return \Elements\Demi\Accommodation\Search\Listing\VacancyLocal|\Zend\Paginator\Adapter\AdapterInterface
  110.      */
  111.     public function getPaginatorAdapter()
  112.     {
  113.         return $this;
  114.     }
  115.     /**
  116.      * @inheritdoc
  117.      */
  118.     public function rewind()
  119.     {
  120.         if ($this->objects === null) {
  121.             $this->load();
  122.         }
  123.         reset($this->objects);
  124.     }
  125.     /**
  126.      * @return mixed
  127.      */
  128.     public function current()
  129.     {
  130.         if ($this->objects === null) {
  131.             $this->load();
  132.         }
  133.         return current($this->objects);
  134.     }
  135.     /**
  136.      * @return mixed
  137.      */
  138.     public function key()
  139.     {
  140.         if ($this->objects === null) {
  141.             $this->load();
  142.         }
  143.         return key($this->objects);
  144.     }
  145.     /**
  146.      * @return mixed
  147.      */
  148.     public function next()
  149.     {
  150.         if ($this->objects === null) {
  151.             $this->load();
  152.         }
  153.         return next($this->objects);
  154.     }
  155.     /**
  156.      * @return bool
  157.      */
  158.     public function valid()
  159.     {
  160.         return $this->current() !== false;
  161.     }
  162.     /**
  163.      * @param array $objects
  164.      */
  165.     public function setObjects($objects)
  166.     {
  167.         $this->objects $objects;
  168.     }
  169.     /**
  170.      * @return array
  171.      */
  172.     public function getObjects()
  173.     {
  174.         return $this->objects;
  175.     }
  176. }