Skip to content
Snippets Groups Projects
Select Git revision
  • d6f6b18045cf4ae8489acca2ddbc2bd702b19af5
  • main default protected
  • register-logging-channel
  • expr-lang
  • ci-82
  • attr-events
  • locale-wip
  • custom-routes
  • v0.1.85
  • v0.1.84
  • v0.1.83
  • v0.1.82
  • v0.1.81
  • v0.1.80
  • v0.1.79
  • v0.1.78
  • v0.1.77
  • v0.1.76
  • v0.1.75
  • v0.1.74
  • v0.1.73
  • v0.1.72
  • v0.1.71
  • v0.1.70
  • v0.1.69
  • v0.1.68
  • v0.1.67
  • v0.1.65
28 results

Pagination.php

Blame
  • Pagination.php 925 B
    <?php
    
    declare(strict_types=1);
    
    namespace Dbp\Relay\CoreBundle\Pagination;
    
    class Pagination
    {
        private const CURRENT_PAGE_NUMBER_DEFAULT = 1;
        public const MAX_NUM_ITEMS_PER_PAGE_DEFAULT = 30;
    
        private const CURRENT_PAGE_NUMBER_PARAMETER_NAME = 'page';
        private const MAX_NUM_ITEMS_PER_PAGE_PARAMETER_NAME = 'perPage';
    
        public static function getCurrentPageNumber(array $options): int
        {
            return max(1, intval($options[self::CURRENT_PAGE_NUMBER_PARAMETER_NAME] ?? self::CURRENT_PAGE_NUMBER_DEFAULT));
        }
    
        public static function getMaxNumItemsPerPage(array $options): int
        {
            return max(1, intval($options[self::MAX_NUM_ITEMS_PER_PAGE_PARAMETER_NAME] ?? self::MAX_NUM_ITEMS_PER_PAGE_DEFAULT));
        }
    
        public static function getFirstItemIndex(int $currentPageNumber, int $maxNumItemsPerPage)
        {
            return max(0, ($currentPageNumber - 1) * $maxNumItemsPerPage);
        }
    }