Hallo meine Pagination funktioniert jetzt richtig und es werden die Daten genau so angezeigt, wie ich es gerne möchte.
Hier mein Modul und darunter noch das Model, welches ich erweitert habe. Es gibt sicherlich einen Code, der nicht so umfassend ist, aber ich bin ja schon mal froh, dass ich es so hinbekommen habe.
PHP-Code:
protected function compile()
{
System::loadLanguageFile('tl_webmail');
if (($this->webmail_template != $this->strTemplate) && ($this->webmail_template != ''))
{
$this->strTemplate = $this->webmail_template;
$this->Template = new FrontendTemplate($this->strTemplate);
}
if ($this->strTemplate == 'mod_webmail_list_compliance')
{
$webmailCount = WebmailModel::findBy('compliance', 1);
while ($webmailCount->next())
{
$rows[] = $webmailCount->row();
}
} else {
$webmailCount = WebmailModel::findBy('alle', 1);
while ($webmailCount->next())
{
$rows[] = $webmailCount->row();
}
}
/**
* Abfragen der Tabelle
**/
$total = \count($rows);
$limit = $total;
$offset = 0;
// Pagination
if ($this->perPage > 0)
{
$id = 'page_e' . $this->id;
$page = Input::get($id) ?? 1;
if ($page < 1 || $page > max(ceil($total/$this->perPage), 1))
{
throw new PageNotFoundException('Page not found: ' . Environment::get('uri'));
}
$offset = ($page - 1) * $this->perPage;
$limit = min($this->perPage + $offset, $total);
$objPagination = new Pagination($total, $this->perPage, Config::get('maxPaginationLinks'), $id);
$this->Template->pagination = $objPagination->generate("\n ");
}
$webmails = array();
if ($this->strTemplate == 'mod_webmail_list_compliance')
{
$result = WebmailModel::findAllByPublishedCompliance($offset, (int)$this->perPage);
while ($result->next())
{
$webmails[] = array
(
'title' => StringUtil::specialchars($result->title),
'url' => htmlspecialchars($result->url),
'alle' => $result->alle,
'compliance' => $result->compliance,
'date' => $result->date
);
}
} else {
$result = WebmailModel::findAllByPublished($offset, (int)$this->perPage);
while ($result->next())
{
$webmails[] = array
(
'title' => StringUtil::specialchars($result->title),
'url' => htmlspecialchars($result->url),
'alle' => $result->alle,
'compliance' => $result->compliance,
'date' => $result->date
);
}
}
//Template
$this->Template->title = StringUtil::specialchars($GLOBALS['TL_LANG']['tl_webmail']['header_title']);
$this->Template->datum = StringUtil::specialchars($GLOBALS['TL_LANG']['tl_webmail']['header_date']);
$this->Template->webmails = $webmails;
}
Und hier mein Model:
PHP-Code:
public static function findAllByPublished($offset, $limit)
{
$t = static::$strTable;
$arrColumns = array("$t.published=?");
$arrOptions = array('order' => "$t.date desc", 'offset' => $offset, 'limit' => $limit);
return static::findBy($arrColumns, 1, $arrOptions);
}
public static function findAllByPublishedCompliance($offset, $limit)
{
$t = static::$strTable;
$arrColumns = array("$t.published=? AND $t.compliance=1");
$arrOptions = array('order' => "$t.date desc", 'offset' => $offset, 'limit' => $limit);
return static::findBy($arrColumns, 1, $arrOptions);
}