Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- switch ($this->getLoadType()) {
- case self::LOAD_TYPE_PAGINATION:
- // Create the paginator as you wish.
- // Because I'm using Doctrine, I have a $query variable and pass it
- // to the Doctrine's paginator adapter for Zend\Paginator.
- $paginator;
- $items = $paginator->getCurrentItems();
- break;
- case self::LOAD_TYPE_INFINITE_SCROLL:
- // Items per page
- $itemCount = 24;
- // How many portions have been loaded so far.
- // By default 1 portion has been loaded.
- $portions = $queryParams['portions'] ?: 1;
- // Which portion to load (used in AJAX requests).
- // Works like some kind of an offset.
- $portion = $queryParams['portion'];
- // Let's calculate the limit from the portions that have to be loaded
- // times the item count per page (per scroll).
- $limit = $portions * $itemCount;
- $offset = 0;
- // If we are loading a specific portion (via AJAX)
- // the portion query param will be specified.
- if ($portion) {
- // The limit is the item count
- $limit = $itemCount;
- // The offset is the portion that has to be loaded minus one (because it works as an index)
- // times the item count.
- $offset = ($portion - 1) * $itemCount;
- }
- // Here, I'm working with doctrine and I have a $queryBuilder variable,
- // so I just pass the $limit and $offset to it, but you could pass them to
- // any query (even to a plain old SQL)
- $items = $queryBuilder
- ->setMaxResults($limit)
- ->setFirstResult($offset)
- ->getQuery()
- ->getResult();
- break;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement