diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index b53c1d4843b16f91c2c2df8ed7dc2eff38dbf627..0e3264c2eece47ca80c0d7cf05fb255650f43b38 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -368,9 +368,10 @@ class AbonneController extends ZendAfi_Controller_Action { public function pretsAction() { $criteria = (new Class_User_LoanCriteria($this->_request->getParams())); - $this->_helper - ->loanSearch([], - $criteria); + if (Class_AdminVar::searchLoanIsActive()) + $this->_helper + ->loanSearch([], + $criteria); $this->view->criteria = $criteria; $fiche = $this->_user->getFicheSigb(); diff --git a/library/Class/AdminVar.php b/library/Class/AdminVar.php index 50df1d024bf3d3eb72ebb1cdf3f8b922de9ca863..c1cd5aed3826e228d296c6e20ff0a21c0cde30b7 100644 --- a/library/Class/AdminVar.php +++ b/library/Class/AdminVar.php @@ -236,7 +236,8 @@ class Class_AdminVarLoader extends Storm_Model_Loader { 'DISABLE_SUGGESTIONS' => Class_AdminVar_Meta::newOnOff($this->_('Désactivation des suggestions d\'achats'))->bePrivate(), 'ENABLE_BOOKMARKABLE_LIBRARIES' => Class_AdminVar_Meta::newOnOff($this->_('Les utilisateurs peuvent sélectionner des bibliothèques favorites pour leurs recherche'), ['value' => 1]), 'ENABLE_BOOKMARKABLE_SEARCHES' => Class_AdminVar_Meta::newOnOff($this->_('Les utilisateurs peuvent enregister des recherches dans leurs favoris'), ['value' => 0]), - 'ENABLE_BOOKMARKABLE_SEARCHES_NOTIFY' => Class_AdminVar_Meta::newOnOff($this->_('Les utilisateurs peuvent recevoir les nouveautés de leurs recherches favorites par email'), ['value' => 0])]; + 'ENABLE_BOOKMARKABLE_SEARCHES_NOTIFY' => Class_AdminVar_Meta::newOnOff($this->_('Les utilisateurs peuvent recevoir les nouveautés de leurs recherches favorites par email'), ['value' => 0]), + 'ENABLE_USER_LOAN_SEARCH' => Class_AdminVar_Meta::newOnOff($this->_('Activer la recherche dans la liste des prêts de l\'abonné'), ['value' => 0])]; } @@ -884,6 +885,10 @@ class Class_AdminVarLoader extends Storm_Model_Loader { return Class_AdminVar::isModuleEnabled('ENABLE_BOOKMARKABLE_SEARCHES'); } + public static function searchLoanIsActive() { + return Class_AdminVar::isModuleEnabled('ENABLE_USER_LOAN_SEARCH'); + } + public static function isBookmarkSearchesNotifyEnabled() { return Class_AdminVar::isModuleEnabled('ENABLE_BOOKMARKABLE_SEARCHES_NOTIFY'); diff --git a/library/Class/User/LoanCriteria.php b/library/Class/User/LoanCriteria.php index fc3d4c6bed0a69ef7b5e350316998fd15e0afd03..d9ed71f85f9f2388d9030e8b3fbedce217bd8345 100644 --- a/library/Class/User/LoanCriteria.php +++ b/library/Class/User/LoanCriteria.php @@ -25,28 +25,41 @@ class Class_User_LoanCriteria { protected $_criteria = []; protected $_params = ['start_date_retour' => '', 'end_date_retour' => '', + 'start_issue_date' => '', + 'end_issue_date' => '', 'onhold' => '']; + + protected $_onhold_values = ['yes' => 1, + 'no' => 0, + 'all' => '']; protected $_selected_filters = []; + + public function __construct($filters) { - $this->_selected_filters = array_intersect_key($filters, $this->_params); - xdebug_break(); + $this->_selected_filters = array_filter(array_intersect_key($filters, $this->_params)); - $this->_criteria = [ new ZendAfi_Form_Element_DateRangePicker('loan_dates', + $this->_criteria = [ + (new ZendAfi_Form_Element_DateRangePicker('loan_dates', ['label' => $this->_('Date de prêt'), - 'start' => ['name' => 'start_loan_date'], - 'end' => ['name' => 'end_loan_date'] - ]), - new ZendAfi_Form_Element_DateRangePicker('return_dates', + 'start' => ['name' => 'start_issue_date'], + 'end' => ['name' => 'end_issue_date'] + ])) + ->setStartValue( isset($this->_selected_filters['start_issue_date']) ? $this->_selected_filters['start_issue_date'] : '') + ->setEndValue( isset($this->_selected_filters['end_issue_date']) ? $this->_selected_filters['end_issue_date'] : ''), + (new ZendAfi_Form_Element_DateRangePicker('return_dates', ['label' => $this->_('Date de retour'), 'start' => ['name' => 'start_date_retour'], - 'end' => ['name' => 'end_date_retour'] - ]), + 'end' => ['name' => 'end_date_retour'] + ])) + ->setStartValue( isset($this->_selected_filters['start_date_retour']) ? $this->_selected_filters['start_date_retour'] : '') + ->setEndValue( isset($this->_selected_filters['end_date_retour']) ? $this->_selected_filters['end_date_retour'] : ''), new Zend_Form_Element_Select('onhold', - ['label' => $this->_('Réservé par d\'autres'), - 'multiOptions' => ['yes' => $this->_('Oui'), - 'no' => $this->_('Non'), - 'all' => $this->_('Indifférent')], - 'value' => 'all'])]; + ['label' => $this->_('Réservé par d\'autres'), + 'multiOptions' => [ + 'no' => $this->_('Non'), + 'yes' => $this->_('Oui'), + 'all' => $this->_('Indifférent')], + 'value' => isset($this->_selected_filters['onhold']) ? $this->_selected_filters['onhold'] : 'all' ])]; } @@ -55,7 +68,7 @@ class Class_User_LoanCriteria { $form = (new ZendAfi_Form()) ->setAttrib('style', 'position: relative') ->setMethod('get'); - xdebug_break(); + $names = (new Storm_Collection($this->_criteria)) ->select(function($c) { return $c; }) ->eachDo(function($c) use ($form) { $form->addElement($c); }) @@ -68,19 +81,44 @@ class Class_User_LoanCriteria { $form->addDisplayGroup($names, 'loan_search_group', ['legend' => $this->_('Filtrer par')]); - return $form; } + public function isAfterDate($date1,$date2) { + if (!$date1 || !$date2) + return true; + + return (DateTime::createFromFormat('Y-m-d',$date1)) >= (DateTime::createFromFormat('Y-m-d',$date2)); + } + + + public function isBeforeDate($date1,$date2) { + if (!$date1 || !$date2) + return true; + return (DateTime::createFromFormat('Y-m-d',$date1)) <= (DateTime::createFromFormat('Y-m-d',$date2)); + } + + + public function mapOnHoldFilter() { + if (!isset($this->_selected_filters['onhold'])) + return $this->_selected_filters; + $this->_selected_filters['onhold'] = $this->_onhold_values[$this->_selected_filters['onhold']]; + + return $this->_selected_filters=array_filter($this->_selected_filters); + } + + public function filter($loans) { - foreach ($this->_selected_filters as $key => $value) { + + foreach ($this->mapOnHoldFilter($this->_selected_filters) as $key => $value) { $loans = $loans->select(function($loan) use ($key,$value) { if (($pos = strpos($key, 'start_')) !== false) - return $loan->callGetterByAttributeName(substr($key,6)) > $value; + return ($this->isAfterDate($loan->callGetterByAttributeName(substr($key,6)),$value)); + if (($pos = strpos($key, 'end_')) !== false) - return $loan->callGetterByAttributeName(substr($key,6)) < $value; + return $this->isBeforeDate($loan->callGetterByAttributeName(substr($key,4)),$value); return $loan->callGetterByAttributeName($key) == $value; diff --git a/library/ZendAfi/Controller/Action/Helper/LoanSearch.php b/library/ZendAfi/Controller/Action/Helper/LoanSearch.php index 4dfeba9a1912c5206d15467e73e8df951e849b4c..eaf0f12aa4c68651e09455a6a40f22d2717ca1ee 100644 --- a/library/ZendAfi/Controller/Action/Helper/LoanSearch.php +++ b/library/ZendAfi/Controller/Action/Helper/LoanSearch.php @@ -27,8 +27,6 @@ class ZendAfi_Controller_Action_Helper_LoanSearch extends Zend_Controller_Action $this->view = $this->getActionController()->view; $this->view->page = $this->_getParam('page', 1); -// $this->view->users = $criteria->findPage($this->view->page); -// $this->view->total = $criteria->count(); $this->view->form = $this->_prepareForm($action_params, $criteria); $this->view->params = array_merge($this->view->form->getValues(), ['page' => $this->view->page, diff --git a/tests/scenarios/HandleBranchcode/HandleBranchcodeTest.php b/tests/scenarios/HandleBranchcode/HandleBranchcodeTest.php index 5e4ec85fa8c2ccec31806f852ec66bd9a148ba7e..880eb700e4cf2a843b4afbb5e7d50e6498b19b28 100644 --- a/tests/scenarios/HandleBranchcode/HandleBranchcodeTest.php +++ b/tests/scenarios/HandleBranchcode/HandleBranchcodeTest.php @@ -136,7 +136,7 @@ class HandleBranchcodeDisplayLoanByOthersTest extends HandleBranchcodeTestCase { protected $expected_call = false; public function setUp() { parent::setUp(); - + Class_AdminVar::set('ENABLE_USER_LOAN_SEARCH',true); } protected function _setMockWebClient() { @@ -173,7 +173,7 @@ class HandleBranchcodeDisplayLoanByOthersTest extends HandleBranchcodeTestCase { /** @test */ public function postOnHoldShouldDisplayBookedByOther() { $this->borrower = $this->service->getEmprunteur($this->user); - $this->postDispatch('/opac/abonne/prets', ['onhold' => 1],true); + $this->postDispatch('/opac/abonne/prets', ['onhold' => 'yes'],true); $this->assertXPathContentContains('//div', 'réservé par d\'autres', $this->_response->getBody()); } @@ -182,9 +182,33 @@ class HandleBranchcodeDisplayLoanByOthersTest extends HandleBranchcodeTestCase { /** @test */ public function postReturnDateShouldDisplayBookedByOther() { $this->borrower = $this->service->getEmprunteur($this->user); - $this->postDispatch('/opac/abonne/prets', ['start_date_retour' => '2018-01-01'],true); - $this->assertXPathContentContains('//div', '', $this->_response->getBody()); + $this->dispatch('/opac/abonne/prets?start_loan_date=12%2F06%2F2018&end_loan_date=&start_date_retour=&end_date_retour=&onhold=',true); + $this->assertXPathContentContains('//td', 'Quel bazar, Léonard', $this->_response->getBody()); } + + /** @test */ + public function startIssueDateInFuturShouldNotDisplayBooks() { + $this->borrower = $this->service->getEmprunteur($this->user); + $this->dispatch('/opac/abonne/prets?start_issue_date=12%2F06%2F2019&end_issue_date=&start_date_retour=&end_date_retour=&onhold=',true); + $this->assertNotXPathContentContains('//td', 'Quel bazar, Léonard', $this->_response->getBody()); + } + + + /** @test */ + public function startIssueDateDateShouldDisplayBooks() { + $this->borrower = $this->service->getEmprunteur($this->user); + $this->dispatch('/opac/abonne/prets?start_issue_date=12%2F06%2F2015&end_issue_date=&start_date_retour=&end_date_retour=&onhold=',true); + $this->assertXPathContentContains('//td', 'Quel bazar, Léonard', $this->_response->getBody()); + } + + /** @test */ + public function endIssueDateDateShouldDisplayBooks() { + $this->borrower = $this->service->getEmprunteur($this->user); + $this->dispatch('/opac/abonne/prets?start_issue_date=12%2F06%2F2015&end_issue_date=12%2F06%2F2019&start_date_retour=&end_date_retour=&onhold=',true); + $this->assertXPathContentContains('//td', 'Quel bazar, Léonard', $this->_response->getBody()); + } + + } ?>