PHP Classes

File: src/App/PageComponent.php

Recommend this page to a friend!
  Packages of Thierry Feuzeu   Jaxon   src/App/PageComponent.php   Download  
File: src/App/PageComponent.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Jaxon
Call PHP classes from JavaScript using AJAX
Author: By
Last change:
Date: 1 year ago
Size: 1,324 bytes
 

Contents

Class file image Download
<?php

namespace Jaxon\App;

use Jaxon\App\Pagination\Paginator;

abstract class PageComponent extends NodeComponent
{
    /**
     * The current page number.
     *
     * @var int
     */
    private int $currentPage = 1;

    /**
     * Get the total number of items to paginate.
     *
     * @return int
     */
    abstract protected function count(): int;

    /**
     * Get the max number of items per page.
     *
     * @return int
     */
    abstract protected function limit(): int;

    /**
     * Get the paginator for the component.
     *
     * @param int $pageNumber
     *
     * @return Paginator
     */
    protected function paginator(int $pageNumber): Paginator
    {
        return $this->cl(Component\Pagination::class)
            // Use the js class name as component item identifier.
            ->item($this->rq()->_class())
            ->paginator($pageNumber > 0 ? $pageNumber : 1, $this->limit(), $this->count())
            // This callback will receive the final value of the current page number.
            ->page(function(int $currentPage) {
                $this->currentPage = $currentPage;
            });
    }

    /**
     * Get the current page number
     *
     * @return int
     */
    protected function currentPage(): int
    {
        return $this->currentPage;
    }
}