NEW Add FirstPage() and LastPage() to PaginatedList (#10129)

This commit is contained in:
Loz Calver 2021-11-07 20:26:21 +00:00 committed by GitHub
parent e217a3d9cb
commit 20134e6a4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 2 deletions

View File

@ -394,12 +394,28 @@ class PaginatedList extends ListDecorator
return $this->TotalPages() > 1;
}
/**
* @return bool
*/
public function FirstPage()
{
return $this->CurrentPage() == 1;
}
/**
* @return bool
*/
public function NotFirstPage()
{
return $this->CurrentPage() != 1;
return !$this->FirstPage();
}
/**
* @return bool
*/
public function LastPage()
{
return $this->CurrentPage() == $this->TotalPages();
}
/**
@ -407,7 +423,7 @@ class PaginatedList extends ListDecorator
*/
public function NotLastPage()
{
return $this->CurrentPage() < $this->TotalPages();
return !$this->LastPage();
}
/**

View File

@ -282,6 +282,14 @@ class PaginatedListTest extends SapphireTest
$this->assertFalse($list->MoreThanOnePage());
}
public function testFirstPage()
{
$list = new PaginatedList(new ArrayList());
$this->assertTrue($list->FirstPage());
$list->setCurrentPage(2);
$this->assertFalse($list->FirstPage());
}
public function testNotFirstPage()
{
$list = new PaginatedList(new ArrayList());
@ -290,6 +298,16 @@ class PaginatedListTest extends SapphireTest
$this->assertTrue($list->NotFirstPage());
}
public function testLastPage()
{
$list = new PaginatedList(new ArrayList());
$list->setTotalItems(50);
$this->assertFalse($list->LastPage());
$list->setCurrentPage(5);
$this->assertTrue($list->LastPage());
}
public function testNotLastPage()
{
$list = new PaginatedList(new ArrayList());