Commit dbeea660 authored by efalcy's avatar efalcy
Browse files

dev #72825 : add filters for loan page (wip)

parent 90dcecac
Pipeline #4366 failed with stage
in 33 minutes and 20 seconds
......@@ -357,6 +357,7 @@ class AbonneController extends ZendAfi_Controller_Action {
public function ficheAction() {
$fiche_sigb = $this->_user->getFicheSigb();
$this->view->error = isset($fiche_sigb['erreur']) ? $fiche_sigb["erreur"] : '';
......@@ -366,6 +367,12 @@ class AbonneController extends ZendAfi_Controller_Action {
public function pretsAction() {
$criteria = (new Class_User_LoanCriteria($this->_request->getParams()));
$this->_helper
->loanSearch([],
$criteria);
$this->view->criteria = $criteria;
$fiche = $this->_user->getFicheSigb();
if (isset($this->fiche['error']) && $this->fiche['error'])
$this->view->error = $this->fiche['error'];
......
......@@ -2,8 +2,10 @@
<div class="abonneTitre"><?php echo $this->user->getNomAff();?></div>
<?php
echo $this->renderForm($this->form);
$cards = new Class_User_Cards($this->user);
$loans = $cards->getLoansWithOutPNB();
$loans = $this->criteria->filter($loans);
$renewable_loan = [];
foreach ($loans as $loan) {
......
<?php
/**
* Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Class_User_LoanCriteria {
use Trait_Translator;
protected $_criteria = [];
protected $_params = ['start_date_retour' => '',
'end_date_retour' => '',
'onhold' => ''];
protected $_selected_filters = [];
public function __construct($filters) {
$this->_selected_filters = array_intersect_key($filters, $this->_params);
xdebug_break();
$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',
['label' => $this->_('Date de retour'),
'start' => ['name' => 'start_date_retour'],
'end' => ['name' => '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'])];
}
public function getForm() {
$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); })
->collect(function($c) { return $c->getName(); })
->getArrayCopy();
if (!$names)
return $form;
$form->addDisplayGroup($names,
'loan_search_group',
['legend' => $this->_('Filtrer par')]);
return $form;
}
public function filter($loans) {
foreach ($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;
if (($pos = strpos($key, 'end_')) !== false)
return $loan->callGetterByAttributeName(substr($key,6)) < $value;
return $loan->callGetterByAttributeName($key) == $value;
});
}
return $loans;
}
}
?>
\ No newline at end of file
......@@ -63,6 +63,9 @@ class Class_WebService_SIGB_Emprunt extends Class_WebService_SIGB_ExemplaireOper
$this->_exemplaire->setOnHold($onhold);
}
public function getOnHold() {
return $this->_exemplaire->onHold();
}
public function onParseAttributes() {
if( !$this->type = $this->getAttribute('Type'))
......@@ -141,6 +144,15 @@ class Class_WebService_SIGB_Emprunt extends Class_WebService_SIGB_ExemplaireOper
$this->type = $type;
return $this;
}
public function callGetterByAttributeName($attribute) {
return call_user_func(array($this, 'get'.$this->attributeNameToAccessor($attribute)));
}
public function attributeNameToAccessor($name) {
return Storm_Inflector::camelize($name);
}
}
?>
\ No newline at end of file
<?php
/**
* Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class ZendAfi_Controller_Action_Helper_LoanSearch extends Zend_Controller_Action_Helper_Abstract {
protected $view;
public function loanSearch($action_params=[], $criteria) {
$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,
'search_order' => $this->_getParam('search_order', 'nom asc')]);
}
protected function _prepareForm($action_params, $criteria) {
$form = $criteria->getForm();
$url_params = array_merge(['module' => $this->getRequest()->getModuleName(),
'controller' => $this->getRequest()->getControllerName(),
'action' => $this->getRequest()->getActionName()],
$action_params);
return $form->setAction(Class_Url::absolute($url_params, null, true));
}
protected function _getParam($name, $default=null) {
return $this->getRequest()->getParam($name, $default);
}
public function direct($action_params=[], $criteria) {
return $this->loanSearch($action_params, $criteria);
}
}
\ No newline at end of file
......@@ -168,5 +168,23 @@ class HandleBranchcodeDisplayLoanByOthersTest extends HandleBranchcodeTestCase {
$this->assertXPathContentContains('//div', 'réservé par d\'autres', $this->_response->getBody());
}
/** @test */
public function postOnHoldShouldDisplayBookedByOther() {
$this->borrower = $this->service->getEmprunteur($this->user);
$this->postDispatch('/opac/abonne/prets', ['onhold' => 1],true);
$this->assertXPathContentContains('//div', 'réservé par d\'autres', $this->_response->getBody());
}
/** @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());
}
}
?>
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