Commit 01cb95e8 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #72825 handle laons table columns configuration

parent 739f3c04
Pipeline #4421 failed with stage
in 31 minutes and 2 seconds
......@@ -88,11 +88,21 @@ class Admin_ModulesController extends ZendAfi_Controller_Action {
}
public function abonnePretsAction() {
$this->view->form = ZendAfi_Form_Configuration_Loans::newWith($this->preferences);
$this->view->form->setAction($this->view->url());
if ($this->_request->isPost())
$this->updateEtRetour($this->_request->getPost());
$params = Class_Profil::getCurrentProfil()
->getConfigurationOf('abonne', 'prets', '');
$post_values = $this->_request->getPost();
$params = array_merge($params, $post_values);
$this->view->titre = $this->_('Configuration du tableau des prêts');
$form = ZendAfi_Form_Configuration_Loans::newWith($params);
$form->setAction($this->view->url());
if ($this->_request->isPost() && $form->isValid($post_values))
return $this->updateEtRetour($post_values);
$this->view->form = $form;
}
......
......@@ -374,11 +374,11 @@ class AbonneController extends ZendAfi_Controller_Action {
'start_issue_date' => $this->_getPost('start_issue_date'),
'end_issue_date' => $this->_getPost('end_issue_date')]);
if (Class_AdminVar::searchLoanIsActive())
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 = $cards->getLoansWithOutPNB($this->_request->getParams());
$this->view->loans = $loans = $cards->getLoansWithOutPNB($this->_request->getParams());
$renewable_loans = $cards->getRenewableLoans($this->view->loans);
$this->view->loans_ids = implode(';',
......
<?php
$this->openBoite('Prêts en cours');
echo $this->tag('div',
$this->user->getNomAff(),
['class' => 'abonneTitre']);
$this->openBoite($this->_('Prêts en cours'));
if($this->form)
echo $this->renderForm($this->form);
$loans = $this->loans;
$extend_all = $this->tagAnchor(['action' => 'prolongerPret',
'id_pret' => $this->loans_ids],
$this->_('Tout prolonger'),
['class' => 'extend_all']);
$extend_all = $this->loans_ids
? ($this->tagAnchor(['action' => 'prolongerPret',
'id_pret' => $this->loans_ids],
$this->_('Tout prolonger'),
['class' => 'extend_all']))
: '';
if ($this->error)
echo $this->tag('p', $this->error, ['class' => 'error']);
$pnb = ($this->user->hasPNB())
? ($this->tag('h2', $this->_('Prêts numériques en cours'))
. $this->abonne_LoansPNB($this->user->getPNBLoans()))
: '';
echo $extend_all;
$content = [$this->tag('div',
$this->user->getNomAff(),
['class' => 'abonneTitre']),
if ($emprunts = $this->user->getEmprunts())
echo $this->abonne_LoanExport();
($this->form ? $this->renderForm($this->form) : ''),
echo $this->abonne_Loans($this->loans);
$extend_all,
echo $extend_all;
($this->error ? $this->tag('p', $this->error, ['class' => 'error']): ''),
if($this->user->hasPNB()) {
echo $this->tag('h2', $this->_('Prêts numériques en cours'));
echo $this->abonne_LoansPNB($this->user->getPNBLoans());
}
($loans->isEmpty() ? '' : $this->abonne_LoanExport()),
$this->abonne_Loans($loans),
$extend_all,
$pnb
];
echo implode($content);
$this->closeBoite();
echo $this->abonne_RetourFiche();
<?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_Profil_Preferences_Loans {
use Trait_Translator;
public function getTableComposition($value) {
return (new Class_Entity(['Id' => 'table_composition',
'AvailableHeader' => $this->_('Colonnes disponibles'),
'SelectedHeader' => $this->_('Colonnes activées'),
'Available' => $this->_getAvailablesItems($value),
'Selected' => $this->_getSelectedItems($value)]));
}
public function getTableCompositionOf($profile) {
$conf = $profile->getCfgModulesPreferences('abonne', 'prets', '');
$table_composition = isset($conf['table_composition'])
? $conf['table_composition']
: '';
return $this->getTableComposition($table_composition);
}
public function isSearchEnabled($profile) {
$conf = $profile->getCfgModulesPreferences('abonne', 'prets', '');
return isset($conf['search_tool'])
? (boolean) $conf['search_tool']
: false;
}
protected function _getSelectedItems($value) {
if (!$value)
return $this->_getDefaultItems();
$selected = [];
foreach($this->_getHeaderCompositionFromString($value) as $id)
$selected[] = $this->_getEntity($id);
return array_filter($selected);
}
protected function _getEntity($id) {
foreach($this->_getAllItems() as $instance)
if($id == $instance->getId())
return $instance;
return null;
}
protected function _getHeaderCompositionFromString($value) {
return explode(';', $value);
}
protected function _getAllItems() {
return array_merge($this->_getDefaultItems(),
$this->_getOptionalItems());
}
protected function _getDefaultItems() {
return [(new Class_Entity())
->setId('loaned_by')
->setLabel($this->_('Emprunté par'))
->whenCalledDo('renderWith', function($view_helper, $loan)
{
return $loan->getUserFullName();
}),
(new Class_Entity())
->setId('doctype')
->setLabel($this->_('Support'))
->whenCalledDo('renderWith', function($view_helper, $loan)
{
return $view_helper->renderDocTypeLabel($loan);
}),
(new Class_Entity())
->setId('thumbnail')
->setLabel($this->_('Vignette'))
->whenCalledDo('renderWith', function($view_helper, $loan)
{
return $view_helper->renderThumbnail($loan, ['retour_abonne' => 'prets']);
}),
(new Class_Entity())
->setId('title')
->setLabel($this->_('Titre'))
->whenCalledDo('renderWith', function($view_helper, $loan)
{
return $view_helper->renderTitle($loan, ['retour_abonne' => 'prets']);
}),
(new Class_Entity())
->setId('author')
->setLabel($this->_('Auteur'))
->whenCalledDo('renderWith', function($view_helper, $loan)
{
return $view_helper->renderAuthor($loan, ['retour_abonne' => 'prets']);
}),
(new Class_Entity())
->setId('library')
->setLabel($this->_('Bibliothèque'))
->whenCalledDo('renderWith', function($view_helper, $loan)
{
return $loan->getBibliotheque();
}),
(new Class_Entity())
->setId('return_date')
->setLabel($this->_('Retour prévu'))
->setParams(['class' => 'date_retour'])
->whenCalledDo('renderWith', function($view_helper, $loan)
{
$view = $view_helper->view;
return $loan->getDateRetour() . ' ' . $view->abonne_LoanAction($loan);
}),
(new Class_Entity())
->setId('Informations')
->setLabel($this->_('Informations'))
->whenCalledDo('renderWith', function($view_helper, $loan)
{
return $loan->getType();
})
->whenCalledDo('getRawParams', function ($loan)
{
return $loan
? (($loan->isLate()) ? ['class' => 'pret_en_retard'] : [])
: [];
})];
}
protected function _getAvailablesItems($value) {
if(!$value)
return $this->_getOptionalItems();
$settings = $this->_getHeaderCompositionFromString($value);
return (new Storm_Collection($this->_getAllItems()))
->select(function($item) use ($settings)
{
return !in_array($item->getId(), $settings);
})
->getArrayCopy();
}
protected function _getOptionalItems() {
return [(new Class_Entity())
->setId('Onhold')
->setLabel($this->_('Déjà réservé par d\'autres'))
->whenCalledDo('renderWith', function($view_helper, $loan)
{
return $loan->getBookedByOthers()
? $this->_('Oui')
: $this->_('Non');
})];
}
}
<?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_Profil_Preferences_LoansPNB extends Class_Profil_Preferences_Loans{
public function getTableCompositionOf($profile) {
$conf = $profile->getCfgModulesPreferences('abonne', 'prets', '');
$table_composition = isset($conf['pnb_table_composition'])
? $conf['pnb_table_composition']
: '';
return $this->getTableComposition($table_composition);
}
protected function _getDefaultItems() {
return [(new Class_Entity())
->setId('number')
->setLabel($this->_('n°'))
->whenCalledDo('renderWith', function($view_helper, $loan)
{
return $view_helper->line_no++;
}),
(new Class_Entity())
->setId('title')
->setLabel($this->_('Titre'))
->whenCalledDo('renderWith', function($view_helper, $loan)
{
$view = $view_helper->view;
return ($record_id = $loan->getNoticeOPACId())
? $view->tagAnchor($view->url(
['controller' => 'recherche',
'action' => 'viewnotice',
'id' => $record_id,
'retour_abonne' => 'prets'],
null, true),
$loan->getTitre())
: $loan->getTitre();
}),
(new Class_Entity())
->setId('author')
->setLabel($this->_('Auteur'))
->whenCalledDo('renderWith', function($view_helper, $loan)
{
return $loan->getAuteur();
}),
(new Class_Entity())
->setId('loan_date')
->setLabel($this->_('Date d\'emprunt'))
->whenCalledDo('renderWith', function($view_helper, $loan)
{
return date('d/m/Y', strtotime($loan->getIssueDate()));
}),
(new Class_Entity())
->setId('return_date')
->setLabel($this->_('Retour prévu'))
->setCellParams(['class' => 'date_retour'])
->whenCalledDo('renderWith', function($view_helper, $loan)
{
return date('d/m/Y', strtotime($loan->getDateRetour()));
})];
}
protected function _getOptionalItems() {
return [];
}
}
......@@ -66,7 +66,7 @@ class Class_TableDescription {
$this
->_columns
->add($this->newColumn($label, $description)
->setOptions($description['options']));
->setOptions($description['options']));
return $this;
}
......@@ -175,6 +175,54 @@ abstract class Class_TableDescription_ColumnAbstract {
}
public function getOptionsParams() {
$options = $this->_options;
if(is_callable($options))
return call_user_func($options);
if(!is_array($options))
return [];
if($this->_hasSubOptions($options))
return [];
return $options ? $options : [];
}
protected function _hasSubOptions($option) {
foreach($option as $value)
if(!is_scalar($value))
return true;
return false;
}
public function getRawParams($model) {
return $this->_getSubOption('raw_params', $model);
}
public function getCellParams($model) {
return $this->_getSubOption('cell_params', $model);
}
protected function _getSubOption($key, $model) {
$options = $this->getOptions();
if(!isset($options[$key]))
return [];
$sub_option = $options[$key];
$result = is_callable($sub_option)
? $sub_option($model)
: $sub_option;
return $result ? $result : [];
}
abstract public function renderModelOn($model, $canvas);
}
......@@ -194,9 +242,10 @@ class Class_TableDescription_ColumnForCallback extends Class_TableDescription_Co
public function renderModelOn($model, $canvas) {
return $canvas->renderContent(call_user_func($this->_callback,
$model,
$this->_attribute));
return $canvas
->renderContent(call_user_func($this->_callback,
$model,
$this->_attribute));
}
}
......
......@@ -30,6 +30,10 @@ 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,102 +45,11 @@ class ZendAfi_Form_Configuration_Loans extends ZendAfi_Form {
['label' => $this->_('Composition du tableau'),
'value' => null,
'entityfactory' => function($value) {
$pref = new Class_Entity(['Id' => 'table_composition',
'AvailableHeader' => $this->_('Colonnes disponibles'),
'SelectedHeader' => $this->_('Colonnes activées'),
'Available' => $this->_getAvailablesItems($value),
'Selected' => $this->_getSelectedItems($value)]);
return $pref;
return (new Class_Profil_Preferences_Loans)->getTableComposition($value);
}])
->addToDisplaySettingsGroup(['table_composition'])
->addToDisplaySettingsGroup(['search_tool',
'table_composition'])
->addToStyleGroup(['titre',
'boite']);
}
protected function _getSelectedItems($value) {
if (!$value)
return $this->_getDefaultItems();
$selected = [];
foreach($this->_getHeaderCompositionFromString($value) as $id)
$selected[] = $this->_getEntity($id);
return array_filter($selected);
}
protected function _getEntity($id) {
foreach($this->_getAllItems() as $instance)
if($id == $instance->getId())
return $instance;
return null;
}
protected function _getHeaderCompositionFromString($value) {
return explode(';', $value);
}
protected function _getAllItems() {
return array_merge($this->_getDefaultItems(),
$this->_getOptionalItems());
}
protected function _getDefaultItems() {
return [(new Class_Entity())
->setId('loaned_by')
->setLabel($this->_('Emprunté par')),
(new Class_Entity())
->setId('doctype')
->setLabel($this->_('Support')),
(new Class_Entity())
->setId('thumbnail')
->setLabel($this->_('Vignette')),
(new Class_Entity())
->setId('title')
->setLabel($this->_('Titre')),
(new Class_Entity())
->setId('author')
->setLabel($this->_('Auteur')),
(new Class_Entity())
->setId('library')
->setLabel($this->_('Bibliothèque')),
(new Class_Entity())
->setId('return_date')
->setLabel($this->_('Retour prévu'))];
}
protected function _getAvailablesItems($value) {
if(!$value)
return $this->_getOptionalItems();
$settings = $this->_getHeaderCompositionFromString($value);
return (new Storm_Collection($this->_getAllItems()))
->select(function($item) use ($settings)
{
return !in_array($item->getId(), $settings);
})
->getArrayCopy();
}
protected function _getOptionalItems() {
return [(new Class_Entity())
->setId('Informations')
->setLabel($this->_('Informations')),
(new Class_Entity())
->setId('Onhold')
->setLabel($this->_('Déjà réservé par d\'autres'))];
}
}
......@@ -41,10 +41,9 @@ class ZendAfi_Form_User_LoanSearch extends ZendAfi_Form {
->addElement('select',
'onhold',
['label' => $this->_('Réservé par d\'autres'),
'multiOptions' => [
'no' => $this->_('Non'),
'multiOptions' => ['all' => $this->_('Indifférent'),
'yes' => $this->_('Oui'),
'all' => $this->_('Indifférent')]])
'no' => $this->_('Non')]])
->addUniqDisplayGroup('loan_search_group')
->setAction(Class_Url::absolute('/opac/abonne/prets'));
......
......@@ -27,81 +27,48 @@ class ZendAfi_View_Helper_Abonne_Loans extends ZendAfi_View_Helper_Abonne_Operat