private function calculatePaginated()
    {
        $this->calculatedTotal = $this->getTotalAmount();

        // If a total limit has been defined, we need to honor that.
        if (($this->calculatedLimit !== null) && ($this->calculatedTotal > $this->calculatedLimit)) {
            $this->calculatedTotal -= $this->calculatedLimit;
        }
        $this->calculatedTotal -= $this->calculatedOffset;

        // Get the current page.
        $page = $this->getCurrentPage();

        if ($page > ($this->calculatedTotal / $this->getPerPage())) {
            $page = (int) ceil($this->calculatedTotal / $this->getPerPage());
        }

        // Set limit and offset.
        $pageOffset              = ((max($page, 1) - 1) * $this->getPerPage());
        $this->calculatedOffset += $pageOffset;
        if ($this->calculatedLimit === null) {
            $this->calculatedLimit = $this->getPerPage();
        } else {
            $this->calculatedLimit = min(($this->calculatedLimit - $this->calculatedOffset), $this->getPerPage());
        }
    }