Commit f4eee190 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #72825 handle table config for loans history

parent 70d6a38a
Pipeline #4462 failed with stage
in 35 minutes and 57 seconds
......@@ -82,14 +82,21 @@ class Admin_ModulesController extends ZendAfi_Controller_Action {
public function abonneAction() {
if ($this->_getParam('action1') === 'suggestion-achat-add')
return $this->_simpleAction('abonne_suggestion_achat_add');
if ($this->_getParam('action1') === 'prets')
return $this->_forward('abonne-prets');
if ($this->_getParam('action1') === 'loans-history')
return $this->_forward('borrower-loans-history');
return $this->_simpleAction('abonne_all');
}
public function abonnePretsAction() {
$params = Class_Profil::getCurrentProfil()
->getConfigurationOf('abonne', 'prets', '');
$post_values = $this->_request->getPost();
$params = array_merge($params, $post_values);
......@@ -106,6 +113,26 @@ class Admin_ModulesController extends ZendAfi_Controller_Action {
}
public function borrowerLoansHistoryAction() {
$params = Class_Profil::getCurrentProfil()
->getConfigurationOf('abonne', 'loans-history', '');
$post_values = $this->_request->getPost();
$params = array_merge($params, $post_values);
$this->view->titre = $this->_('Configuration du tableau de l\'historique des prêts');
$form = ZendAfi_Form_Configuration_LoansHistory::newWith($params);
$form->setAction($this->view->url());
if ($this->_request->isPost() && $form->isValid($post_values))
return $this->updateEtRetour($post_values);
$this->view->form = $form;
}
public function authAction() {
if ('register' == $this->_getParam('action1'))
return $this->_forward('auth-register');
......
......@@ -433,13 +433,13 @@ class AbonneController extends ZendAfi_Controller_Action {
public function loansHistoryAction() {
$this->view->config = new Class_Entity(['Profile' => Class_Profil::getCurrentProfil(),
'RequestParams' => $this->_request->getParams(),
'User' => $this->_user]);
try {
$this->view->page_number = $this->_getParam('page', 1);
$this->view->page_size = $this->_getParam('page_size', 10);
$this->view->loans = $this->_user->getLoansHistory();
$this->view->config->setLoans($this->_user->getLoansHistory($this->_request->getParams()));
} catch (Class_WebService_Exception $e) {
$this->view->error = $e->getMessage();
$this->view->loans = new Storm_Collection();
$this->view->config->setError($e->getMessage());
}
}
......@@ -1020,6 +1020,25 @@ class AbonneController extends ZendAfi_Controller_Action {
}
public function loansHistoryUnimarcExportAction() {
$this->_helper->viewRenderer->setNoRender();
$datas = [];
$emprunts = $this->_user
->getLoansHistory($this->_request->getParams());
foreach($emprunts as $emprunt) {
if (!$exemplaire = $emprunt->getExemplaireOPAC())
continue;
$datas[] = $exemplaire->toUnimarcIso2709();
}
$filename = 'historique_prets_' . $this->_user->getId() . '-' . uniqid() . '.txt';
$this->_helper->binaryDownload(implode($datas), $filename);
}
public function barcodesExportAction() {
$filename = $this->_('prets_codes_barres_%s_%s%s',
$this->_user->getId(),
......@@ -1042,6 +1061,28 @@ class AbonneController extends ZendAfi_Controller_Action {
}
public function loansHistoryBarcodesExportAction() {
$filename = $this->_('historique_prets_codes_barres_%s_%s%s',
$this->_user->getId(),
uniqid(),
'.csv');
$description = (new Class_TableDescription('loans-barcodes'))
->addColumn('', function($loan)
{
return $loan->getCodeBarre();
});
$datas = array_filter($this->_user
->getLoansHistory($this->_request->getParams())
->getArrayCopy());
$this->_helper->csv($filename,
$this->view->renderCsv($description,
$datas));
}
public function manageSettingsAction() {
if(!Class_Users::getIdentity())
return $this->_forward('popup-login', 'auth', 'opac', ['redirect' => $this->view->url()]);
......
<?php
$this->openBoite($this->_('Historique de prêts'));
if ($this->error)
echo $this->tag('div',
$this->error,
['class' => 'error']);
echo $this->abonne_LoansHistory($this->loans,
$this->page_number,
$this->page_size);
echo $this->abonne_LoansHistoryBoard($this->config);
$this->closeBoite();
echo $this->abonne_RetourFiche();
?>
......@@ -104,6 +104,14 @@ class Class_ModeleFusionLoader extends Storm_Model_Loader {
'type' => $template,
'contenu' => $content]);
}
public function generateDefaults($view) {
foreach(Class_ModeleFusion::getDefaultTemplates() as $template => $label)
Class_ModeleFusion::build($template,
$label,
$view->ModeleFusion_Template($template))->save();
}
}
......
......@@ -34,7 +34,7 @@ class Class_Profil_Preferences_Loans {
public function getTableCompositionOf($profile) {
$conf = $profile->getCfgModulesPreferences('abonne', 'prets', '');
$conf = $this->_getConf($profile);
$table_composition = isset($conf['table_composition'])
? $conf['table_composition']
: null;
......@@ -53,7 +53,7 @@ class Class_Profil_Preferences_Loans {
public function getToolsCompositionOf($profile) {
$conf = $profile->getCfgModulesPreferences('abonne', 'prets', '');
$conf = $this->_getConf($profile);
$table_composition = isset($conf['tools_composition'])
? $conf['tools_composition']
: null;
......@@ -62,6 +62,13 @@ class Class_Profil_Preferences_Loans {
}
protected function _getConf($profile) {
return $profile->getCfgModulesPreferences('abonne',
'prets',
'');
}
protected function _getSelectedItems($value) {
if (null === $value)
return $this->_getDefaultItemsInstances();
......@@ -163,7 +170,8 @@ class Class_Profil_Preferences_Loans {
protected function _getOptionalItems() {
return ['Onhold'];
return ['Onhold',
'LoanDate'];
}
......@@ -487,6 +495,11 @@ class Class_Profil_Preferences_LoansReturnDateHistory extends Class_Profil_Prefe
public function getLabel() {
return $this->_('Date de retour');
}
public function getRowParams($loan) {
return [];
}
}
......
......@@ -32,6 +32,13 @@ class Class_Profil_Preferences_LoansHistory extends Class_Profil_Preferences_Loa
}
protected function _getConf($profile) {
return $profile->getCfgModulesPreferences('abonne',
'loans-history',
'');
}
protected function _getDefaultItems() {
return ['LoanedBy',
'Doctype',
......@@ -48,4 +55,63 @@ class Class_Profil_Preferences_LoansHistory extends Class_Profil_Preferences_Loa
protected function _getOptionalItems() {
return [];
}
protected function _getDefaultTools() {
return [(new Class_Entity(['Id' => 'pager',
'Label' => $this->_('La pagination')]))
->whenCalledDo('renderWith', function($view_helper)
{
$view_helper->setPager(true);
})];
}
protected function _getOptionalTools() {
return [(new Class_Entity(['Id' => 'export_unimarc',
'Label' => $this->_('Export Unimarc')]))
->whenCalledDo('renderWith', function($view_helper)
{
$view = $view_helper->view;
return $view->tagAnchor($view->url(['controller' => 'abonne',
'action' => 'loans-history-unimarc-export']),
$this->_('Export Unimarc'),
['class' => 'loan-export']);
}),
(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());
$form->setAction(Class_Url::relative('/abonne/loans-history'));
return $view->renderForm($form);
}),
(new Class_Entity(['Id' => 'export_barcodes',
'Label' => $this->_('Export codes barres')]))
->whenCalledDo('renderWith', function($view_helper)
{
$view = $view_helper->view;
return $view->tagAnchor(
$view->url(['controller' => 'abonne',
'action' => 'loans-history-barcodes-export']),
$this->_('Export codes barres'),
['class' => 'loan-export']);
}),
(new Class_Entity(['Id' => 'print',
'Label' => $this->_('Imprimer')]))
->whenCalledDo('renderWith', function($view_helper)
{
xdebug_break();
$loans = $view_helper->getLoans();
$view = $view_helper->view;
$config = new Class_Entity(['Models' => $loans->getArrayCopy(),
'Ids' => 'reload',
'Strategy' => Class_ModeleFusion::LOANS_TEMPLATE]);
return $view->tagPrintLink($config);
})];
}
}
......@@ -1201,6 +1201,9 @@ class Class_Users extends Storm_Model_Abstract {
public function providesLoansHistory() {
if($this->getLoader()->isCurrentUserAllowedToEditProfile(Class_Profil::getCurrentProfil()))
return true;
if (!($emprunteur = $this->getEmprunteur()))
return false;
......@@ -1208,13 +1211,30 @@ class Class_Users extends Storm_Model_Abstract {
}
public function getLoansHistory() {
public function getLoansHistory($params = []) {
if (!($emprunteur = $this->getEmprunteur()))
return new Storm_Collection();
$history = $emprunteur->getLoansHistory();
$loans = $history->getLoans()
->select(function($loan) {return $loan->getDateRetour();});
$loans = $history->getLoans();
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);
});
}
$loans = $loans->select(function($loan) {return $loan->getDateRetour();});
$loans->uasort(function($a, $b)
{
......
......@@ -135,6 +135,17 @@ class Class_WebService_SIGB_Nanook_PatronInfoReader extends Class_WebService_SIG
}
}
public function endLoanDate($data) {
if ($this->_xml_parser->inParents('loan')) {
$date = implode('/', array_reverse(explode('-', $data)));
$this->_currentLoan->getExemplaire()->setIssueDate($date);
}
}
/**
* @param string $data
*/
......@@ -244,11 +255,8 @@ class Class_WebService_SIGB_Nanook_PatronInfoReader extends Class_WebService_SIG
}
public function endPriority($data) {
$this->_item_priorities []= $data; // @see http://forge.afi-sa.fr/issues/55166
$this->_current_operation->setRang(min($this->_item_priorities));
}
}
?>
\ No newline at end of file
}
\ No newline at end of file
......@@ -35,11 +35,7 @@ class ZendAfi_Controller_Plugin_Manager_ModeleFusion extends ZendAfi_Controller_
public function generateAction() {
foreach(Class_ModeleFusion::getDefaultTemplates() as $template => $label)
Class_ModeleFusion::build($template,
$label,
$this->_view->ModeleFusion_Template($template))->save();
Class_ModeleFusion::generateDefaults($this->_view);
$this->_redirectToReferer();
}
}
......
<?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_Form_Configuration_LoansHistory extends ZendAfi_Form {
public function init() {
parent::init();
$this
->addElement('text',
'titre',
['label' => $this->_('Titre'),
'size' => $this->_text_size])
->addElement('select',
'boite',
['label' => $this->_('Style de boite'),
'multiOptions' => (new Class_Profil_Templates(
Class_Profil::getCurrentProfil()))->toArray()])
->addElement('dragAndDrop',
'table_composition',
['label' => $this->_('Composition du tableau'),
'value' => null,
'entityfactory' => function($value) {
return (new Class_Profil_Preferences_LoansHistory)->getTableComposition($value);
}])
->addElement('dragAndDrop',
'tools_composition',
['label' => $this->_('Outils'),
'value' => null,
'entityfactory' => function($value) {
return (new Class_Profil_Preferences_LoansHistory)->getToolsComposition($value);
}])
->addToDisplaySettingsGroup(['tools_composition',
'table_composition'])
->addToStyleGroup(['titre',
'boite']);
}
}
......@@ -28,7 +28,7 @@ class ZendAfi_Form_User_LoanSearch extends ZendAfi_Form {
$this
->addElement('dateRangePicker',
'issue_date',
['label' => $this->_('Date de prêt'),
['label' => $this->_('Date d\'emprunt'),
'start' => ['name' => 'start_issue_date'],
'end' => ['name' => 'end_issue_date']])
......
......@@ -23,32 +23,26 @@
class ZendAfi_View_Helper_Abonne_LoansHistory extends ZendAfi_View_Helper_Abonne_Loans {
protected $_paginator;
public function abonne_LoansHistory($loans, $page_number, $page_size) {
public function abonne_LoansHistory($loans, $pager) {
if($loans->isEmpty()
|| (!$description = $this->_getDescription()))
return $this->_tag('p', $this->_('Pas de prêts dans l\'historique'), ['class' => 'error']);
$loans = array_reverse($loans->getArrayCopy());
$this->_paginator = (new Zend_Paginator(new Zend_Paginator_Adapter_Array($loans)))
->setItemCountPerPage($page_size)
->setCurrentPageNumber($page_number);
$this->_operations = new Storm_Collection($this->_paginator->getCurrentItems());
$this->_operations = new Storm_Collection($loans);
return
$this->_renderPaginator()
. $this->view->renderTable($description,
$this->_operations,
['class' => 'loans',
'sorter' => true]);
$this->view->renderTable($description,
$this->_operations,
['class' => 'loans',
'pager' => $pager,
'sorter' => true]);
}
public function getLinkUrl() {
return ['retour_abonne' => 'loans-history',
'page' => $this->_paginator->getCurrentPageNumber(),
'page_size' => $this->_paginator->getItemCountPerPage()];
return ['retour_abonne' => 'loans-history'];
}
......@@ -60,56 +54,4 @@ class ZendAfi_View_Helper_Abonne_LoansHistory extends ZendAfi_View_Helper_Abonne
protected function _getDescriptionId() {
return 'borrower_loans_history';
}
protected function _renderPaginator() {
$reload_link = ['module' => 'opac',
'controller' => 'abonne',
'action' => 'loans-history',
'page_size' => $this->_paginator->getItemCountPerPage()];
return $this->view->paginationControl($this->_paginator,
null,
null,
['url_link' => $reload_link,
'link_attribs' => [ 'data-ajax-reload' => 'true' ]
]);
}
protected function _tableColumns() {
return [$this->_('Emprunté par'),
$this->_('Support'),
$this->_('Vignette'),
$this->_('Titre'),
$this->_('Auteur'),
$this->_('Date d\'emprunt'),
$this->_('Date de retour'),
$this->_('Informations')];
}
protected function renderLoan($loan) {
return
$this->_tag('tr',
$this->_tag('td',
$loan->getUserFullName())
. $this->_tag('td',
$this->_renderDocTypeLabel($loan))
. $this->_tag('td',
$this->_renderThumbnail($loan, $url))
. $this->_tag('td',
$this->_renderTitle($loan, $url))
. $this->_tag('td',
$this->_renderAuthor($loan, $url))
. $this->_tag('td',
$loan->getIssueDate())
. $this->_tag('td',
$loan->getDateRetour())
. $this->_tag('td',
$loan->getType()), []);
}
}
\ No newline at end of file
<?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_LoansHistoryBoard extends ZendAfi_View_Helper_Abonne_LoansBoard {
public function abonne_LoansHistoryBoard($config) {
$this->_config = $config;
$loans = $config->getLoans();
$user = $config->getUser();
$this->_profile = $profile = $config->getProfile();
$error = $config->getError();
$request_params = $config->getRequestParams();
$this->_preferences = $preferences = new Class_Profil_Preferences_LoansHistory();
if($error)