Commit e88e31cd authored by efalcy's avatar efalcy
Browse files

dev #75244 : add admin var to activate filters and fix errors on search

parent dbeea660
Pipeline #4382 failed with stage
in 35 minutes and 36 seconds
......@@ -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();
......
......@@ -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');
......
......@@ -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;
......
......@@ -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,
......
......@@ -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());
}
}
?>
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