Commit fdc9f16a authored by Laurent's avatar Laurent
Browse files

dev #13615 loans history pagination

parent 3ab13e9d
......@@ -410,7 +410,9 @@ class AbonneController extends ZendAfi_Controller_Action {
public function loansHistoryAction() {
try {
$this->view->loans = $this->_user->getLoansHistory($this->_getParam('page',1));
$this->view->page_number = $this->_getParam('page', 1);
$this->view->page_size = $this->_getParam('page_size', 10);
$this->view->loans = $this->_user->getLoansHistory();
} catch (Class_WebService_Exception $e) {
$this->view->error = $e->getMessage();
$this->view->loans = new Storm_Collection();
......
......@@ -6,7 +6,9 @@ if ($this->error)
$this->error,
['class' => 'error']);
echo $this->abonne_LoansHistory(($this->loans ? $this->loans : new Storm_Collection()));
echo $this->abonne_LoansHistory($this->loans,
$this->page_number,
$this->page_size);
$this->closeBoite();
echo $this->abonne_RetourFiche();
......
......@@ -1206,14 +1206,20 @@ class Class_Users extends Storm_Model_Abstract {
}
public function getLoansHistory($page = 1) {
public function getLoansHistory() {
if (!($emprunteur = $this->getEmprunteur()))
return new Storm_Collection();
$history = $emprunteur->getLoansHistory($page)->getLoans()
->select(function($loan) {return $loan->getDateRetour();});
$history = $emprunteur->getLoansHistory()->fetchAll();
$loans = $history->getLoans()
->select(function($loan) {return $loan->getDateRetour();});
return Class_User_CardsOperationDecorator::decorateAll($history, $this);
$loans->uasort(function($a, $b)
{
return strcmp(implode('/', array_reverse(explode('/', $a->getIssueDate()))),
implode('/', array_reverse(explode('/', $b->getIssueDate()))));
});
return Class_User_CardsOperationDecorator::decorateAll($loans, $this);
}
......
......@@ -21,25 +21,29 @@
class ZendAfi_View_Helper_Abonne_LoansHistory extends ZendAfi_View_Helper_Abonne_Loans {
public function abonne_LoansHistory($loans, $page_number, $page_size) {
$paginator = (new Zend_Paginator(new Zend_Paginator_Adapter_Array(array_reverse($loans->getArrayCopy()))))
->setItemCountPerPage($page_size)
->setCurrentPageNumber($page_number);
public function abonne_LoansHistory($loans) {
$this->_operations = array_reverse($loans->getArrayCopy());
$this->_operations = $paginator->getCurrentItems();
Class_ScriptLoader::getInstance()->loadTableSorter();
return
$this->renderPaginator($paginator) .
$this->_tag('table',
$this->renderHeader()
. $this->renderLoans()
. $this->renderPaginator(),
. $this->renderLoans(),
['class' => 'tablesorter loans-history']);
}
protected function renderPaginator() {
$paginator = (new Zend_Paginator(new Zend_Paginator_Adapter_Null(count($this->_operations))))
->setItemCountPerPage(max(20, 1))
->setCurrentPageNumber(1);
protected function renderPaginator($paginator) {
$reload_link = ['module' => 'opac',
'controller' => 'abonne',
'action' => 'loans-history',
'page_size' => $paginator->getItemCountPerPage()];
return $this->view->paginationControl($paginator,
null,
null,
......
......@@ -74,15 +74,25 @@ class AbonneControllerLoansHistoryNanookIndexTest extends AbonneControllerLoansH
public function setUp() {
parent::setUp();
$this->dispatch('/abonne/loans-history',true);
$this->dispatch('/abonne/loans-history/page_size/2',true);
}
/** @test */
public function titleShouldBeDisplayed() {
public function pageShouldContainLoanLaFemmeADroite() {
$this->assertXPathContentContains('//table', 'La femme à droite sur la photo');
}
/** @test */
public function pageShouldContainLoanLeCameleon() {
$this->assertXPathContentContains('//table', 'Le caméléon');
}
/** @test */
public function pageShouldNotContainLoanJeTeCroquerai() {
$this->assertNotXPathContentContains('//table', 'Je te croquerai');
}
}
......@@ -92,12 +102,18 @@ class AbonneControllerLoansHistoryNanookIndexPageTwoTest extends AbonneControlle
public function setUp() {
parent::setUp();
$this->dispatch('/abonne/loans-history/page/2',true);
$this->dispatch('/abonne/loans-history/page_size/2/page/2',true);
}
/** @test */
public function paginatorShouldHaveLinkToPageOne() {
$this->assertXPathContentContains('//div[@class="paginationControl"]//a[contains(@href, "/abonne/loans-history/page_size/2/page/1")]', '1');
}
/** @test */
public function titleShouldBeDisplayed() {
public function pageShouldContainsLoanJeTeCroquerai() {
$this->assertXPathContentContains('//table', 'Je te croquerai');
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment