HEX
Server: Apache/2.4.34 (Red Hat) OpenSSL/1.0.2k-fips
System: Linux WORDPRESS 3.10.0-1160.118.1.el7.x86_64 #1 SMP Thu Apr 4 03:33:23 EDT 2024 x86_64
User: digital (1020)
PHP: 7.2.24
Disabled: NONE
Upload Files
File: /datos/www/fabricas.colombiatrade.com.co/web_https/core/lib/Drupal/Core/Pager/Pager.php
<?php

namespace Drupal\Core\Pager;

/**
 * A value object that represents a pager.
 */
class Pager {

  /**
   * The total number of items .
   *
   * @var int
   */
  protected $totalItems;

  /**
   * The total number of pages.
   *
   * @var int
   */
  protected $totalPages;

  /**
   * The current page of the pager.
   *
   * @var int
   */
  protected $currentPage;

  /**
   * The maximum number of items per page.
   *
   * @var int
   */
  protected $limit;

  /**
   * Pager constructor.
   *
   * @param int $totalItems
   *   The total number of items.
   * @param int $limit
   *   The maximum number of items per page.
   * @param int $currentPage
   *   The current page.
   */
  public function __construct($totalItems, $limit, $currentPage = 0) {
    $this->totalItems = $totalItems;
    $this->limit = $limit;
    $this->setTotalPages($totalItems, $limit);
    $this->setCurrentPage($currentPage);
  }

  /**
   * Sets the current page to a valid value within range.
   *
   * If a page that does not correspond to the actual range of the result set
   * was provided, this function will set the closest page actually within
   * the result set.
   *
   * @param int $currentPage
   *   (optional) The current page.
   */
  protected function setCurrentPage($currentPage = 0) {
    $this->currentPage = max(0, min($currentPage, $this->getTotalPages() - 1));
  }

  /**
   * Sets the total number of pages.
   *
   * @param int $totalItems
   *   The total number of items.
   * @param int $limit
   *   The maximum number of items per page.
   */
  protected function setTotalPages($totalItems, $limit) {
    $this->totalPages = (int) ceil($totalItems / $limit);
  }

  /**
   * Gets the total number of items.
   *
   * @return int
   *   The total number of items.
   */
  public function getTotalItems() {
    return $this->totalItems;
  }

  /**
   * Gets the total number of pages.
   *
   * @return int
   *   The total number of pages.
   */
  public function getTotalPages() {
    return $this->totalPages;
  }

  /**
   * Gets the current page.
   *
   * @return int
   *   The current page.
   */
  public function getCurrentPage() {
    return $this->currentPage;
  }

  /**
   * Gets the maximum number of items per page.
   *
   * @return int
   *   The maximum number of items per page.
   */
  public function getLimit() {
    return $this->limit;
  }

}