Commit 1f8c35f4 authored by efalcy's avatar efalcy
Browse files

dev #72825 : refacto

parent 4830fad8
Pipeline #4418 failed with stage
in 29 minutes and 7 seconds
......@@ -367,16 +367,32 @@ class AbonneController extends ZendAfi_Controller_Action {
public function pretsAction() {
$criteria = (new Class_User_LoanCriteria($this->_request->getParams()));
if($this->_request->isPost())
return $this->_redirectToRefererWithNewParams(['onhold' => $this->_getPost('onhold'),
'start_date_retour' => $this->_getPost('start_date_retour'),
'end_date_retour' => $this->_getPost('end_date_retour'),
'start_issue_date' => $this->_getPost('start_issue_date'),
'end_issue_date' => $this->_getPost('end_issue_date')]);
if (Class_AdminVar::searchLoanIsActive())
$this->_helper
->loanSearch([],
$criteria);
$this->view->criteria = $criteria;
$this->view->form = ZendAfi_Form_User_LoanSearch::newWith($this->_request->getParams());
$cards = new Class_User_Cards($this->_user);
$this->view->loans = $cards->getLoansWithOutPNB($this->_request->getParams());
$renewable_loans = $cards->getRenewableLoans($this->view->loans);
$this->view->loans_ids = implode(';',
$renewable_loans
->collect(function($loan)
{
return $loan->getId();
})
->getArrayCopy());
$fiche = $this->_user->getFicheSigb();
if (isset($this->fiche['error']) && $this->fiche['error'])
$this->view->error = $this->fiche['error'];
$this->view->user = $this->_user;
}
......
<?php $this->openBoite('Prêts en cours');?>
<div class="abonneTitre"><?php echo $this->user->getNomAff();?></div>
<?php
$this->openBoite('Prêts en cours');
echo $this->tag('div',
$this->user->getNomAff(),
['class' => 'abonneTitre']);
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) {
if ($loan->isRenewable())
$renewable_loan[] = $loan->getId();
}
$loans_ids = implode(';', $renewable_loan);
if($this->form)
echo $this->renderForm($this->form);
$extend_all = $this->tagAnchor(['action' => 'prolongerPret',
'id_pret' => $loans_ids],
$this->_('Tout prolonger'),
['class' => 'extend_all']);
'id_pret' => $this->loans_ids],
$this->_('Tout prolonger'),
['class' => 'extend_all']);
if ($this->error)
echo '<p class="error">' . $this->error . '</p>';
echo $this->tag('p', $this->error, ['class' => 'error']);
echo $extend_all;
if ($emprunts = $this->user->getEmprunts()) {
if ($emprunts = $this->user->getEmprunts())
echo $this->abonne_LoanExport();
}
echo $this->abonne_Loans($loans);
echo $this->abonne_Loans($this->loans);
echo $extend_all;
......@@ -40,4 +31,3 @@ if($this->user->hasPNB()) {
$this->closeBoite();
echo $this->abonne_RetourFiche();
?>
......@@ -31,8 +31,8 @@ class Class_User_Cards extends Storm_Model_Collection {
}
public function getLoansWithOutPNB() {
return $this->_decorateOperationFrom(function($card) { return $card->getLoansWithOutPNB(); });
public function getLoansWithOutPNB($params = []) {
return $this->_decorateOperationFrom(function($card) use ($params) { return $card->getLoansWithOutPNB($params); });
}
......@@ -114,6 +114,14 @@ class Class_User_Cards extends Storm_Model_Collection {
}
public function getRenewableLoans($loans) {
return $loans->select(function($loan)
{
return $loan->isRenewable();
});
}
protected function _decorateOperationFrom($closure) {
$operations = new Storm_Collection();
foreach($this as $card)
......
......@@ -25,13 +25,33 @@ class Class_User_Loans extends Storm_Model_Collection_Abstract {
}
public function withoutPNB() {
return $this->reject(function($loan) {return $loan->isPNB();});
public function selectPNB() {
return $this->select(function($loan) {return $loan->isPNB();});
}
public function selectPNB() {
return $this->select(function($loan) {return $loan->isPNB();});
public function withoutPNB($params = []) {
$loans = $this->reject(function($loan) {return $loan->isPNB();});
if(empty($params))
return $loans;
foreach (['start_date_retour',
'end_date_retour',
'start_issue_date',
'end_issue_date',
'onhold'] as $key) {
if(!isset($params[$key]))
continue;
$value = $params[$key];
$loans = $loans->select(function($loan) use ($key, $value)
{
return $loan->filterBy($key, $value);
});
}
return $loans;
}
}
?>
\ No newline at end of file
}
\ No newline at end of file
......@@ -1230,8 +1230,8 @@ class Class_Users extends Storm_Model_Abstract {
}
public function getLoansWithOutPNB() {
return $this->getEmprunts()->withoutPNB();
public function getLoansWithOutPNB($params = []) {
return $this->getEmprunts()->withoutPNB($params);
}
......
......@@ -145,14 +145,36 @@ class Class_WebService_SIGB_Emprunt extends Class_WebService_SIGB_ExemplaireOper
return $this;
}
public function callGetterByAttributeName($attribute) {
return call_user_func(array($this, 'get'.$this->attributeNameToAccessor($attribute)));
public function filterBy($key, $value) {
if ('start_date_retour' == $key)
return $this->_isAfterDate($this->getDateRetour(), $value);
if ('start_issue_date' == $key)
return $this->_isAfterDate($this->getIssueDate(), $value);
if ('end_date_retour' == $key)
return $this->_isBeforeDate($this->getDateRetour(), $value);
if ('end_issue_date' == $key)
return $this->_isBeforeDate($this->getIssueDate(), $value);
return $this->getOnhold() == $value;
}
public function attributeNameToAccessor($name) {
return Storm_Inflector::camelize($name);
protected function _isAfterDate($date1, $date2) {
if (!$date1 || !$date2)
return true;
return DateTime::createFromFormat('d/m/Y', $date1) >= DateTime::createFromFormat('d/m/Y', $date2);
}
}
?>
\ No newline at end of file
protected function _isBeforeDate($date1, $date2) {
if (!$date1 || !$date2)
return true;
return (DateTime::createFromFormat('d/m/Y', $date1)) <= (DateTime::createFromFormat('d/m/Y', $date2));
}
}
\ No newline at end of file
......@@ -193,8 +193,8 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action {
}
protected function _getPost() {
return $this->_request->getPost();
protected function _getPost($key = null, $default = null) {
return $this->_request->getPost($key, $default);
}
......
<?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->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
......@@ -217,8 +217,8 @@ abstract class ZendAfi_Controller_Plugin_Abstract {
}
protected function _getPost() {
return call_user_func($this->_get_post);
protected function _getPost($key = null, $default = null) {
return call_user_func_array($this->_get_post, [$key, $default]);
}
......
......@@ -76,7 +76,7 @@ class ZendAfi_Controller_Plugin_Manager_User extends ZendAfi_Controller_Plugin_M
}
protected function _getPost() {
protected function _getPost($key = null, $default = null) {
$post = $this->_request->getPost();
$post['user_groups'] = array_filter(
array_map(function($id) { return Class_UserGroup::find((int)$id);},
......
......@@ -52,29 +52,18 @@ class ZendAfi_View_Helper_Abonne_Loans extends ZendAfi_View_Helper_Abonne_Operat
protected function _tableColumns() {
return array_filter([$this->_('Emprunté par'),
$this->_('Support'),
$this->_('Vignette'),
$this->_('Titre'),
$this->_('Auteur'),
$this->_('Bibliothèque'),
$this->_('Retour prévu'),
$this->displayField('type') ? $this->_('Informations') : null,
$this->displayField('booked_by_others') ? $this->_('Document réservé par d\'autres') : null]);
return [$this->_('Emprunté par'),
$this->_('Support'),
$this->_('Vignette'),
$this->_('Titre'),
$this->_('Auteur'),
$this->_('Bibliothèque'),
$this->_('Retour prévu'),
$this->_('Informations'),
$this->_('Document réservé par d\'autres')];
}
protected function displayField($field) {
foreach ($this->_operations as $loan) {
if ($loan->callGetterByAttributeName($field))
return true;
}
return false;
}
protected function renderLoans() {
$html = '';
......@@ -87,12 +76,11 @@ class ZendAfi_View_Helper_Abonne_Loans extends ZendAfi_View_Helper_Abonne_Operat
protected function renderLoan($loan) {
$tag_bookedbyothers = $this->displayField('booked_by_others') ? $this->_tag('td',
'',
$loan->getBookedByOthers()?
['class' => 'checkedbox'] :
['class' => 'uncheckedbox'])
: '';
$tag_bookedbyothers = $this->_tag('td',
'',
$loan->getBookedByOthers()?
['class' => 'checkedbox'] :
['class' => 'uncheckedbox']);
return
$this->_tag('tr',
......
......@@ -22,11 +22,15 @@
require_once 'tests/fixtures/ChamberyKohaFixtures.php';
abstract class HandleBranchcodeTestCase extends AbstractControllerTestCase {
protected $_storm_default_to_volatile = true,
protected
$_storm_default_to_volatile = true,
$mock_web_client,
$service,
$user,
$ilsdi;
protected function _setMockWebClient() {
$this->mock_web_client
->whenCalled('open_url')
......@@ -36,12 +40,11 @@ abstract class HandleBranchcodeTestCase extends AbstractControllerTestCase {
->whenCalled('open_url')
->with($this->ilsdi . '?service=GetPatronInfo&patron_id=18&show_contact=1&show_loans=1&show_holds=1')
->answers(ChamberyKohaFixtures::getPatronInfoChambelle());
}
}
public function setUp() {
parent::setUp();
Class_WebService_SIGB_Koha::reset();
Class_AdminVar::newInstanceWithId('KOHA_MULTI_SITES', ['valeur' => '' ]);
$this->ilsdi = 'http://chamb.com/koha/ilsdi.pl';
$this->mock_web_client = $this->mock();
......@@ -57,27 +60,33 @@ abstract class HandleBranchcodeTestCase extends AbstractControllerTestCase {
'id_origine' => 'CHY-GB']);
$sigb_gb = $this->fixture('Class_IntBib',
[
'id' => 3,
'comm_params' => ['url_serveur' => $this->ilsdi],
'comm_sigb' => Class_IntBib::COM_KOHA
]);
[
'id' => 3,
'comm_params' => ['url_serveur' => $this->ilsdi],
'comm_sigb' => Class_IntBib::COM_KOHA
]);
$this->fixture('Class_Bib', ['id' => 12,
'libelle' => 'Bibliothèque Georges Brassens',
'int_bib' => $sigb_gb]);
$this->user = $this->fixture('Class_Users',
['id' => 78,
'login' => 'Chambelle',
'password' => 'upw',
'idabon' => '93658',
'id_site' => 12,
'int_bib' => $sigb_gb,
'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB]);
['id' => 78,
'login' => 'Chambelle',
'password' => 'upw',
'idabon' => '93658',
'id_site' => 12,
'int_bib' => $sigb_gb,
'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB]);
ZendAfi_Auth::getInstance()->logUser($this->user);
}
public function tearDown() {
Class_WebService_SIGB_Koha::reset();
parent::tearDown();
}
}
......@@ -132,13 +141,28 @@ class HandleBranchcodeSuggestionTest extends HandleBranchcodeTestCase {
}
class HandleBranchcodeDisplayLoanByOthersTest extends HandleBranchcodeTestCase {
protected $expected_call = false;
protected
$_referer,
$expected_call = false;
public function setUp() {
parent::setUp();
$this->_referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
$_SERVER['HTTP_REFERER'] = 'https://bokeh.org/opac/abonne/prets';
Class_AdminVar::set('ENABLE_USER_LOAN_SEARCH',true);
}
public function tearDown() {
$_SERVER['HTTP_REFERER'] = $this->_referer;
parent::tearDown();
}
protected function _setMockWebClient() {
$this->mock_web_client
->whenCalled('open_url')
......@@ -148,8 +172,6 @@ class HandleBranchcodeDisplayLoanByOthersTest extends HandleBranchcodeTestCase {
->whenCalled('open_url')
->with($this->ilsdi . '?service=GetPatronInfo&patron_id=18&show_contact=1&show_loans=1&show_holds=1')
->answers(ChamberyKohaFixtures::getLoans());
}
......@@ -163,29 +185,36 @@ class HandleBranchcodeDisplayLoanByOthersTest extends HandleBranchcodeTestCase {
/** @test */
public function informationsShouldNotBeDisplayed() {
$profil = Class_Profil::getCurrentProfil();
$this->borrower = $this->service->getEmprunteur($this->user);
$this->dispatch('/opac/abonne/prets', true);
$this->assertNotXPathContentContains('//div', 'Informations', $this->_response->getBody());
}
/** @test */
public function postOnHoldShouldRedirectToAbonnePretsOnholdYes() {
$this->postDispatch('/opac/abonne/prets', ['onhold' => 'yes']);
$this->assertRedirectTo('/abonne/prets/onhold/yes');
}
/** @test */
public function postOnHoldShouldDisplayBookedByOther() {
$this->postDispatch('/opac/abonne/prets', ['onhold' => 'yes'],true);
public function searchOnHoldShouldDisplayBookedByOther() {
$this->dispatch('/opac/abonne/prets/onhold/yes', true);
$this->assertXPathContentContains('//div', 'réservé par d\'autres', $this->_response->getBody());
}
/** @test */
public function postReturnDateShouldDisplayBookedByOther() {
$this->dispatch('/opac/abonne/prets?start_issue_date=12%2F06%2F2010&end_loan_date=&start_date_retour=&end_date_retour=&onhold=',true);
$this->dispatch('/opac/abonne/prets/start_issue_date/12%2F06%2F2010/end_loan_date//start_date_retour//end_date_retour//onhold//',true);
$this->assertXPathContentContains('//td', 'Quel bazar, Léonard', $this->_response->getBody());
}
}
/** @test */
/** @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);
......@@ -193,20 +222,18 @@ class HandleBranchcodeDisplayLoanByOthersTest extends HandleBranchcodeTestCase {
}
/** @test */
/** @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->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 */
/** @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->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