Commit 684086bb authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #72825 refacto loans table actions

parent 56684dc7
Pipeline #4430 failed with stage
in 34 minutes and 46 seconds
......@@ -374,26 +374,19 @@ class AbonneController extends ZendAfi_Controller_Action {
'start_issue_date' => $this->_getPost('start_issue_date'),
'end_issue_date' => $this->_getPost('end_issue_date')]);
if ((new Class_Profil_Preferences_Loans)->isSearchEnabled(Class_Profil::getCurrentProfil()))
$this->view->form = ZendAfi_Form_User_LoanSearch::newWith($this->_request->getParams());
$cards = new Class_User_Cards($this->_user);
$this->view->loans = $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());
$loans = $cards->getLoansWithOutPNB($this->_request->getParams());
$fiche = $this->_user->getFicheSigb();
if (isset($this->fiche['error']) && $this->fiche['error'])
$this->view->error = $this->fiche['error'];
$this->view->user = $this->_user;
$error = (isset($fiche['error']) && $fiche['error'])
? $fiche['error']
: '';
$this->view->config = new Class_Entity(['Loans' => $loans,
'RenewableLoansIds' => $cards->getRenewableLoansIds($loans),
'User' => $this->_user,
'Error' => $error,
'Profile' => Class_Profil::getCurrentProfil(),
'RequestParams' => $this->_request->getParams()]);
}
......@@ -1008,7 +1001,7 @@ class AbonneController extends ZendAfi_Controller_Action {
$this->_helper->viewRenderer->setNoRender();
$datas = [];
$emprunts = $this->_user->getLoansWithoutPNB();
$emprunts = $this->_user->getLoansWithoutPNB($this->_request->getParams());
foreach($emprunts as $emprunt) {
if (!$exemplaire = $emprunt->getExemplaireOPAC())
continue;
......
<?php
$this->openBoite($this->_('Prêts en cours'));
$loans = $this->loans;
$extend_all = $this->loans_ids
? ($this->tagAnchor(['action' => 'prolongerPret',
'id_pret' => $this->loans_ids],
$this->_('Tout prolonger'),
['class' => 'extend_all']))
: '';
$pnb = ($this->user->hasPNB())
? ($this->tag('h2', $this->_('Prêts numériques en cours'))
. $this->abonne_LoansPNB($this->user->getPNBLoans()))
: '';
$content = [$this->tag('div',
$this->user->getNomAff(),
['class' => 'abonneTitre']),
($this->form ? $this->renderForm($this->form) : ''),
$extend_all,
($this->error ? $this->tag('p', $this->error, ['class' => 'error']): ''),
($loans->isEmpty() ? '' : $this->abonne_LoanExport()),
$this->abonne_Loans($loans),
$extend_all,
$pnb
];
echo implode($content);
echo $this->abonne_LoansBoard($this->config);
$this->closeBoite();
echo $this->abonne_RetourFiche();
......@@ -37,33 +37,44 @@ class Class_Profil_Preferences_Loans {
$conf = $profile->getCfgModulesPreferences('abonne', 'prets', '');
$table_composition = isset($conf['table_composition'])
? $conf['table_composition']
: '';
: null;
return $this->getTableComposition($table_composition);
}
public function isSearchEnabled($profile) {
public function getToolsComposition($value) {
return (new Class_Entity(['Id' => 'tools_composition',
'AvailableHeader' => $this->_('Outils disponibles'),
'SelectedHeader' => $this->_('Outils activées'),
'Available' => $this->_getAvailablesTools($value),
'Selected' => $this->_getSelectedTools($value)]));
}
public function getToolsCompositionOf($profile) {
$conf = $profile->getCfgModulesPreferences('abonne', 'prets', '');
return isset($conf['search_tool'])
? (boolean) $conf['search_tool']
: false;
$table_composition = isset($conf['tools_composition'])
? $conf['tools_composition']
: null;
return $this->getToolsComposition($table_composition);
}
protected function _getSelectedItems($value) {
if (!$value)
if (null === $value)
return $this->_getDefaultItemsInstances();
$selected = [];
foreach($this->_getHeaderCompositionFromString($value) as $id)
$selected[] = $this->_getEntity($id);
$selected[] = $this->_getItem($id);
return array_filter($selected);
}
protected function _getEntity($id) {
protected function _getItem($id) {
foreach($this->_getAllItems() as $instance)
if($id == $instance->getId())
return $instance;
......@@ -71,6 +82,14 @@ class Class_Profil_Preferences_Loans {
}
protected function _getTool($id) {
foreach($this->_getAllTools() as $instance)
if($id == $instance->getId())
return $instance;
return null;
}
protected function _getHeaderCompositionFromString($value) {
return explode(';', $value);
}
......@@ -91,6 +110,7 @@ class Class_Profil_Preferences_Loans {
return $this->_getInstances($this->_getOptionalItems());
}
protected function _getInstances($items) {
return array_map(function ($item) {
$class = 'Class_Profil_Preferences_Loans'.$item;
......@@ -113,7 +133,7 @@ class Class_Profil_Preferences_Loans {
protected function _getAvailablesItems($value) {
if(!$value)
if(null === $value)
return $this->_getOptionalItemsInstances();
$settings = $this->_getHeaderCompositionFromString($value);
......@@ -127,9 +147,97 @@ class Class_Profil_Preferences_Loans {
}
protected function _getAvailablesTools($value) {
if(null === $value)
return $this->_getOptionalTools();
$settings = $this->_getHeaderCompositionFromString($value);
return (new Storm_Collection($this->_getAllTools()))
->select(function($item) use ($settings)
{
return !in_array($item->getId(), $settings);
})
->getArrayCopy();
}
protected function _getOptionalItems() {
return ['Onhold'];
}
protected function _getDefaultTools() {
return [(new Class_Entity(['Id' => 'extend_all',
'Label' => $this->_('Tout prolonger')]))
->whenCalledDo('renderWith', function($view_helper)
{
$view = $view_helper->view;
$renewable_loans = $view_helper->getRenewableLoans();
$html = $renewable_loans
? ($view->tagAnchor(['action' => 'prolongerPret',
'id_pret' => $renewable_loans],
$this->_('Tout prolonger'),
['class' => 'extend_all']))
: '';
$view_helper->setExtendAll($html);
return $html;
})];
}
protected function _getOptionalTools() {
return [(new Class_Entity(['Id' => 'export_unimarc',
'Label' => $this->_('Export Unimarc')]))
->whenCalledDo('renderWith', function($view_helper)
{
$loans = $view_helper->getLoans();
$view = $view_helper->view;
return ($loans->isEmpty()
? ''
: $view->abonne_LoanExport());
}),
(new Class_Entity(['Id' => 'search_tool',
'Label' => $this->_('La recherche')]))
->whenCalledDo('renderWith', function($view_helper)
{
$view = $view_helper->view;
$form = ZendAfi_Form_User_LoanSearch::newWith($view_helper->getRequestParams());
return $view->renderForm($form);
})];
}
protected function _getSelectedTools($value) {
if (null === $value)
return $this->_getDefaultTools();
$selected = [];
foreach($this->_getHeaderCompositionFromString($value) as $id)
$selected[] = $this->_getTool($id);
return array_filter($selected);
}
protected function _getSelectedToolsIdsOf($profile) {
$composition = $this->getToolsCompositionOf($profile);
$selected = new Storm_Collection($composition->getSelected());
return $selected->collect(function ($tool)
{
return $tool->getId();
})
->getArrayCopy();
}
protected function _getAllTools() {
return array_merge($this->_getdefaultTools(),
$this->_getOptionalTools());
}
}
......@@ -318,6 +426,13 @@ class Class_Profil_Preferences_LoansReturnDate extends Class_Profil_Preferences_
}
public function getRowParams($loan) {
return $loan
? (($loan->isLate()) ? ['class' => 'pret_en_retard'] : [])
: [];
}
public function getCellParams($loan) {
return ['class' => 'date_retour'];
}
......@@ -367,13 +482,6 @@ class Class_Profil_Preferences_LoansInformations extends Class_Profil_Preference
public function renderWith($view_helper, $loan) {
return $loan->getType();
}
public function getRowParams($loan) {
return $loan
? (($loan->isLate()) ? ['class' => 'pret_en_retard'] : [])
: [];
}
}
......
......@@ -122,6 +122,18 @@ class Class_User_Cards extends Storm_Model_Collection {
}
public function getRenewableLoansIds($loans) {
$renewable_loans = $this->getRenewableLoans($loans);
return implode(';',
$renewable_loans
->collect(function($loan)
{
return $loan->getId();
})
->getArrayCopy());
}
protected function _decorateOperationFrom($closure) {
$operations = new Storm_Collection();
foreach($this as $card)
......
......@@ -30,10 +30,6 @@ class ZendAfi_Form_Configuration_Loans extends ZendAfi_Form {
['label' => $this->_('Titre'),
'size' => $this->_text_size])
->addElement('checkbox',
'search_tool',
['label' => $this->_('Afficher l\'outil de recherche')])
->addElement('select',
'boite',
['label' => $this->_('Style de boite'),
......@@ -41,14 +37,24 @@ class ZendAfi_Form_Configuration_Loans extends ZendAfi_Form {
Class_Profil::getCurrentProfil()))->toArray()])
->addElement('dragAndDrop',
'table_composition',
['label' => $this->_('Composition du tableau'),
'value' => null,
'entityfactory' => function($value) {
return (new Class_Profil_Preferences_Loans)->getTableComposition($value);
}])
->addToDisplaySettingsGroup(['search_tool',
'table_composition',
['label' => $this->_('Composition du tableau'),
'value' => null,
'entityfactory' => function($value) {
return (new Class_Profil_Preferences_Loans)->getTableComposition($value);
}])
->addElement('dragAndDrop',
'tools_composition',
['label' => $this->_('Outils'),
'value' => null,
'entityfactory' => function($value) {
return (new Class_Profil_Preferences_Loans)->getToolsComposition($value);
}])
->addToDisplaySettingsGroup(['tools_composition',
'table_composition'])
->addToStyleGroup(['titre',
'boite']);
}
......
......@@ -16,7 +16,7 @@
*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
......@@ -26,8 +26,7 @@ class ZendAfi_View_Helper_Abonne_LoanExport extends ZendAfi_View_Helper_Abonne_A
return '';
return $this->view->tagAnchor($this->view->url(['controller' => 'abonne',
'action' => 'loan-export'],
null, true),
'action' => 'loan-export']),
$this->view->_('Export unimarc'),
['class' => 'loan-export']);
}
......
......@@ -55,8 +55,8 @@ class ZendAfi_View_Helper_Abonne_Loans extends ZendAfi_View_Helper_Abonne_Operat
protected function _getDescription() {
$selected_columns = $this->_getDescriptionClass()
->getTableCompositionOf(Class_Profil::getCurrentProfil())
->getSelected();
->getTableCompositionOf(Class_Profil::getCurrentProfil())
->getSelected();
if(!$selected_columns)
return;
......
<?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 ZendAfi_View_Helper_Abonne_LoansBoard extends ZendAfi_View_Helper_BaseHelper {
protected
$_config,
$_extend_all,
$_preferences,
$_profile;
public function abonne_LoansBoard($config) {
$this->_config = $config;
$loans = $config->getLoans();
$renewable_loans = $config->getRenewableLoansIds();
$user = $config->getUser();
$this->_profile = $profile = $config->getProfile();
$error = $config->getError();
$request_params = $config->getRequestParams();
$this->_preferences = $preferences = new Class_Profil_Preferences_Loans();
if($error)
return $this->_tag('p', $error, ['class' => 'error']);
$extend_all = $renewable_loans
? ($this->view->tagAnchor(['action' => 'prolongerPret',
'id_pret' => $renewable_loans],
$this->_('Tout prolonger'),
['class' => 'extend_all']))
: '';
$pnb = ($user->hasPNB())
? ($this->_tag('h2', $this->_('Prêts numériques en cours'))
. $this->view->abonne_LoansPNB($user->getPNBLoans()))
: '';
$content = [$this->_tag('div',
$user->getNomAff(),
['class' => 'abonneTitre']),
$this->_renderTools(),
$this->view->abonne_Loans($loans),
$this->_extend_all,
$pnb
];
return implode(array_filter($content));
}
public function getRequestParams() {
return $this->_config->getRequestParams();
}
public function getLoans() {
return $this->_config->getLoans();
}
public function getRenewableLoans () {
return $this->_config->getRenewableLoansIds();
}
public function setExtendAll($html) {
$this->_extend_all = $html;
}
protected function _renderTools() {
$tools = [];
$composition = $this->_preferences->getToolsCompositionOf($this->_profile);
$selected_tools = $composition->getSelected();
foreach($selected_tools as $tool)
$tools [] = $tool->renderWith($this);
return implode(array_filter($tools));
}
}
\ No newline at end of file
......@@ -3013,11 +3013,6 @@ a.readspeaker {
text-align: center;
}
a.loan-export {
display: none;
}
.ui-autocomplete span {
font-weight: bold;
}
......
......@@ -1440,12 +1440,19 @@ class ModulesControllerLoansConfiguration extends Admin_AbstractControllerTestCa
}
/** @test */
public function tableConfigurationShouldBeDrapAndDrop() {
$this->assertXPath('//p[@class="show_drag_and_drop"]',$this->_response->getBody());
public function drapAndDropShouldBePresent() {
$this->assertXPath('//p[@class="show_drag_and_drop"]');
}
/** @test */
public function configurationTableShouldHaveSelectedValues() {
public function tableCompositionShouldContainsInformations() {
$this->assertXPathContentContains('//span[@class="selected"]', 'Informations');
}
/** @test */
public function toolsTableCompositionShouldContainsExtandAll() {
$this->assertXPathContentContains('//span[@class="selected"]', 'Tout prolonger');
}
}
\ No newline at end of file
......@@ -47,7 +47,7 @@ abstract class HandleOnholdTestCase extends AbstractControllerTestCase {
(new Class_Entity())
->setController('abonne')
->setAction('prets'),
['search_tool' => 1,
['tools_composition' => 'search_tool;export_unimarc;extend_all',
'table_composition' => 'loaned_by;doctype;thumbnail;title;author;library;return_date;onhold']);
$this->_ilsdi = 'http://chamb.com/koha/ilsdi.pl';
......@@ -110,14 +110,14 @@ abstract class HandleOnholdDispatchTestCase extends HandleOnholdTestCase {
/** @test */
public function onHoldShouldDisplayBookedByOther() {
$this->dispatch('/opac/abonne/prets', true);
$this->assertXPathContentContains('//th', 'Déjà réservé par d\'autres', $this->_response->getBody());
$this->assertXPathContentContains('//th', 'Déjà réservé par d\'autres');
}
/** @test */
public function informationsShouldNotBeDisplayed() {
$this->dispatch('/opac/abonne/prets', true);
$this->assertNotXPathContentContains('//th', 'Informations', $this->_response->getBody());
$this->assertNotXPathContentContains('//th', 'Informations');
}
......
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