namespace Friendica\Content;
use Friendica\Core\L10n;
+use Friendica\Core\Renderer;
/**
* The Pager has two very different output, Minimal and Full, see renderMinimal() and renderFull() for more details.
* @var integer
*/
private $itemsPerPage = 50;
- /**
- * @var integer
- */
- private $itemCount = 0;
/**
* @var string
* Guesses the page number from the GET parameter 'page'.
*
* @param string $queryString The query string of the current page
- * @param integer $itemCount The total item count (for the full mode) or null (for the minimal mode)
* @param integer $itemsPerPage An optional number of items per page to override the default value
*/
- public function __construct($queryString, $itemCount = null, $itemsPerPage = 50)
+ public function __construct($queryString, $itemsPerPage = 50)
{
$this->setQueryString($queryString);
$this->setItemsPerPage($itemsPerPage);
- $this->setItemCount(defaults($itemCount, $this->getItemsPerPage()));
$this->setPage(defaults($_GET, 'page', 1));
}
* Returns the base query string.
*
* Warning: this isn't the same value as passed to the constructor.
- * See setQueryString for the inventory of transformations
+ * See setQueryString() for the inventory of transformations
*
* @see setBaseQuery()
* @return string
$this->page = max(1, intval($page));
}
- /**
- * Sets the item count, 0 minimum.
- *
- * @param integer $itemCount
- */
- public function setItemCount($itemCount)
- {
- $this->itemCount = max(0, intval($itemCount));
- }
-
/**
* Sets the base query string from a full query string.
*
*/
public function renderMinimal($itemCount)
{
- $this->setItemCount($itemCount);
+ $displayedItemCount = max(0, intval($itemCount));
$data = [
'class' => 'pager',
'next' => [
'url' => $this->ensureQueryParameter($this->baseQueryString . '&page=' . ($this->getPage() + 1)),
'text' => L10n::t('older'),
- 'class' => 'next' . ($this->itemCount <= 0 ? ' disabled' : '')
+ 'class' => 'next' . ($displayedItemCount < $this->getItemsPerPage() ? ' disabled' : '')
]
];
- $tpl = get_markup_template('paginate.tpl');
- return replace_macros($tpl, ['pager' => $data]);
+ $tpl = Renderer::getMarkupTemplate('paginate.tpl');
+ return Renderer::replaceMacros($tpl, ['pager' => $data]);
}
/**
*
* $html = $pager->renderFull();
*
+ * @param integer $itemCount The total number of items including those note displayed on the page
* @return string HTML string of the pager
*/
- public function renderFull()
+ public function renderFull($itemCount)
{
+ $totalItemCount = max(0, intval($itemCount));
+
$data = [];
$data['class'] = 'pagination';
- if ($this->itemCount > $this->getItemsPerPage()) {
+ if ($totalItemCount > $this->getItemsPerPage()) {
$data['first'] = [
'url' => $this->ensureQueryParameter($this->baseQueryString . '&page=1'),
'text' => L10n::t('first'),
'class' => $this->getPage() == 1 ? 'disabled' : ''
];
- $numpages = $this->itemCount / $this->getItemsPerPage();
+ $numpages = $totalItemCount / $this->getItemsPerPage();
$numstart = 1;
$numstop = $numpages;
}
}
- if (($this->itemCount % $this->getItemsPerPage()) != 0) {
+ if (($totalItemCount % $this->getItemsPerPage()) != 0) {
if ($i == $this->getPage()) {
$pages[$i] = [
'url' => '#',
];
}
- $tpl = get_markup_template('paginate.tpl');
- return replace_macros($tpl, ['pager' => $data]);
+ $tpl = Renderer::getMarkupTemplate('paginate.tpl');
+ return Renderer::replaceMacros($tpl, ['pager' => $data]);
}
}