Commit 3f49cd5a authored by Ghislain Loas's avatar Ghislain Loas

Merge branch 'hotline#71154_retour_pnb' into 'master'

Hotline#71154 retour pnb

See merge request afi/opacce!2521
parents f25c4258 02a00723
- ticket #71154 : Ressource numérique Dilicom : branchement de l'inspecteur gadget sur les albums PNB.
\ No newline at end of file
......@@ -245,13 +245,8 @@ class AuthController extends ZendAfi_Controller_Action {
protected function _loginPrefFromWidgetOrModule() {
$module = Class_Profil::getCurrentProfil()
->getCfgModulesPreferences('auth','login');
$widget = Class_Profil::getCurrentProfil()
->getModuleAccueilPreferencesByType('LOGIN');
return $widget ? $widget : $module;
return (new Class_Profil_Preferences_Login)
->getPreferencesFromWidgetOrModule(Class_Profil::getCurrentProfil());
}
......
......@@ -154,8 +154,8 @@ class RechercheController extends ZendAfi_Controller_Action {
if (($ig = Zend_Controller_Front::getInstance()
->getPlugin('ZendAfi_Controller_Plugin_InspectorGadget'))
&& $ig->isEnabled())
$ig->logRecord($this->_('Configuration de la recherche'),
$this->view->searchInspector($this->moteur));
$ig->addButton(new Class_Entity(['Label' => $this->_('Configuration de la recherche'),
'Content' => $this->view->searchInspector($this->moteur)]));
}
......@@ -307,11 +307,7 @@ class RechercheController extends ZendAfi_Controller_Action {
Class_ScriptLoader::getInstance()->addRecordMeta($notice);
if (($ig = Zend_Controller_Front::getInstance()
->getPlugin('ZendAfi_Controller_Plugin_InspectorGadget'))
&& $ig->isEnabled())
$ig->logRecord($this->_('Notice Bokeh'),
$this->view->notice_Unimarc($notice));
$this->_addInspectorGadget($notice);
$notice_navigation = new Class_Notice_NavigationRecherche(
$this->newCriteresRecherches($this->_request->getParams()),
......@@ -791,6 +787,21 @@ class RechercheController extends ZendAfi_Controller_Action {
return $criteres;
}
}
?>
\ No newline at end of file
protected function _addInspectorGadget($record) {
if (!$ig = Zend_Controller_Front::getInstance()
->getPlugin('ZendAfi_Controller_Plugin_InspectorGadget'))
return;
if(!$ig->isEnabled())
return;
$ig->addButton(new Class_Entity(['Label' => $this->_('Notice Bokeh'),
'Content' => $this->view->notice_Unimarc($record)]));
if($record->isDilicom())
$ig->addButton(new Class_Entity(['Label' => $this->_('Dilicom'),
'Content' => $this->view->notice_Dilicom($record)]));
}
}
\ No newline at end of file
......@@ -37,6 +37,13 @@ class Class_Loan_PnbLoader extends Storm_Model_Loader {
}
public function findAllOngoingOfItem($item) {
$loans = $this->findAllOngoingBy(['order_line_id' => $item->getOrderLineId()]);
(new Class_WebService_BibNumerique_Dilicom_Hub())->updateLoansReturnDate($loans);
return $loans;
}
public function findAllOngoingBy($params) {
$closure = function($params) { return Class_Loan_Pnb::findAllBy($params); };
return $this->_applyOngoingAndDo($params, $closure);
......@@ -60,6 +67,14 @@ class Class_Loan_PnbLoader extends Storm_Model_Loader {
}
public function findLastPastLoansForItem($item) {
return Class_Loan_Pnb::findAllBy(['order_line_id' => $item->getOrderLineId(),
'order' => 'expected_return_date desc',
'limit' => 5,
'where' => sprintf('expected_return_date <= "%s"', $this->_getDate())]);
}
protected function _applyOngoingAndDo($params, $closure) {
$prefix = isset($params['where']) ? '(' . $params['where'] . ') and ' : '';
$params['where'] = $prefix . 'expected_return_date > "' . $this->_getDate() . '"';
......@@ -80,7 +95,8 @@ class Class_Loan_Pnb extends Storm_Model_Abstract {
protected
$_table_name = 'loan_pnb',
$_loader_class = 'Class_Loan_PnbLoader';
$_loader_class = 'Class_Loan_PnbLoader',
$_belongs_to = ['user' => ['model' => 'Class_Users']];
public function getAlbum() {
......
<?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_Login {
public function getPreferencesFromWidgetOrModule($profile) {
$module = $profile
->getCfgModulesPreferences('auth', 'login');
$widget = $profile
->getModuleAccueilPreferencesByType(Class_Systeme_ModulesAccueil_Login::CODE);
return $widget
? $widget
: $module;
}
}
\ No newline at end of file
......@@ -245,9 +245,20 @@ class Class_WebService_BibNumerique_Dilicom_Hub extends Class_WebService_Abstrac
protected function dilicomCall($service, $params) {
return $this->httpGet($this->buildUrl($service, $params),
['auth' => ['user' =>Class_AdminVar::get('DILICOM_PNB_GLN_COLLECTIVITE'),
'password' => Class_AdminVar::get('DILICOM_PNB_PWD_COLLECTIVITE')]]);
$response = $this->httpGet($this->buildUrl($service, $params),
['auth' => ['user' =>Class_AdminVar::get('DILICOM_PNB_GLN_COLLECTIVITE'),
'password' => Class_AdminVar::get('DILICOM_PNB_PWD_COLLECTIVITE')]]);
$this->_log();
return $response;
}
protected function _log() {
if (($ig = Zend_Controller_Front::getInstance()
->getPlugin('ZendAfi_Controller_Plugin_InspectorGadget'))
&& $ig->isEnabled())
$ig->log();
}
......
......@@ -26,8 +26,7 @@ class ZendAfi_Controller_Plugin_InspectorGadget extends Zend_Controller_Plugin_A
protected $_enabled = false,
$_calls = [],
$_record,
$_record_label,
$_buttons = [],
$_session,
$_view;
......@@ -45,7 +44,10 @@ class ZendAfi_Controller_Plugin_InspectorGadget extends Zend_Controller_Plugin_A
Class_WebService_MappedSoapClient::setLogger($this);
$sl = Class_ScriptLoader::getInstance();
$sl->addOPACPluginScript('form_to_tabs/form_to_tabs.js');
$sl
->addOPACPluginScript('form_to_tabs/form_to_tabs.js')
->addOPACStyleSheet('inspector-gadget/style.css')
;
Class_Admin_Skin::current()
->renderButtonCssOn($sl)
->renderJQueryCssOn($sl)
......@@ -86,7 +88,7 @@ class ZendAfi_Controller_Plugin_InspectorGadget extends Zend_Controller_Plugin_A
return;
}
if ($this->_record
if ($this->_buttons
&& false !== strpos($this->_response->getBody(), '<div class="entete_notice">')) {
$this->_response->setBody(str_replace('<div class="entete_notice">',
$html . '<div class="entete_notice">',
......@@ -94,7 +96,7 @@ class ZendAfi_Controller_Plugin_InspectorGadget extends Zend_Controller_Plugin_A
return;
}
if ($this->_record
if ($this->_buttons
&& false !== strpos($this->_response->getBody(), '<div class="resultats_page">')) {
$this->_response->setBody(str_replace('<div class="resultats_page">',
$html . '<div class="resultats_page">',
......@@ -115,22 +117,26 @@ class ZendAfi_Controller_Plugin_InspectorGadget extends Zend_Controller_Plugin_A
$this->_view = $renderer->view;
return $this->_view
&& (!empty($this->_calls) || null !== $this->_record);
&& (!empty($this->_calls) || null !== $this->_buttons);
}
protected function render() {
return $this->renderCalls() . $this->renderRecord();
return $this->renderCalls() . $this->renderButtons();
}
protected function renderRecord() {
if (null == $this->_record)
protected function renderButtons() {
if (empty($this->_buttons))
return '';
return $this->renderDialog($this->_record_label,
['title' => $this->_record_label,
'content' => $this->_record]);
$html = [];
foreach($this->_buttons as $button)
$html []= $this->renderDialog($button->getLabel(),
['title' => $button->getLabel(),
'content' => $button->getContent()]);
return implode(array_filter($html));
}
......@@ -154,16 +160,24 @@ class ZendAfi_Controller_Plugin_InspectorGadget extends Zend_Controller_Plugin_A
return $this
->renderDialog($this->_('Appels webservices (%s)', count($items)),
['title' => $this->_('Liste des appels webservices'),
'content' => $content])
;
'content' => $content]);
}
protected function renderDialog($label, $datas) {
if(!$label)
return '';
$datas['content'] = $this->_view->tag('div', $datas['content'],
['class' => 'inspector-gadget']);
$button = (new Class_Entity)
->setText($label)
->setImage(Class_Admin_Skin::current()->renderActionIconOn('loupe', $this->_view))
->setAttribs(['onclick' => 'opacDialogFromData('. $this->_view->escape(json_encode($datas)) .');$(\'.ig-tabs\').tabs({activate: function(event, ui) {if (ui.newPanel.attr(\'id\') == \'ig-tab-items\') ui.newPanel.accordion();}});']);
->setAttribs(['onclick' => 'opacDialogFromData('. $this->_view->escape(json_encode($datas)) .');'
. '$(\'.ig-tabs\').tabs({activate: function(event, ui) {if (ui.newPanel.hasClass(\'ig-accordion\')) ui.newPanel.accordion();},
create: function(event, ui) { if (ui.panel.hasClass(\'ig-accordion\')) ui.panel.accordion();}});'
]);
return $this->_view->Admin_Button($button);
}
......@@ -216,12 +230,14 @@ class ZendAfi_Controller_Plugin_InspectorGadget extends Zend_Controller_Plugin_A
}
public function logRecord($label, $html) {
public function addButton($instance) {
if (!$this->isEnabled())
return $this;
$this->_record = $html;
$this->_record_label = $label;
if(!$instance)
return $this;
$this->_buttons []= $instance;
return $this;
}
}
......@@ -21,13 +21,22 @@
class ZendAfi_Form_Login extends ZendAfi_Form {
protected $_data, $_redirect_url, $_id_notice,$_service;
protected $_data,
$_redirect_url,
$_id_notice,
$_service;
public function init() {
parent::init();
$this->_redirect_url = $this->_data['redirect_url'];
$this->_id_notice = $this->_data['id_notice'];
$this->_redirect_url = isset($this->_data['redirect_url'])
? $this->_data['redirect_url']
: '';
$this->_id_notice = isset($this->_data['id_notice'])
? $this->_data['id_notice']
: '';
if (isset($this->_data['service']))
$this->_service = $this->_data['service'];
$group = ['username',
......
<?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_Album_Loans extends ZendAfi_View_Helper_BaseHelper {
public function Album_Loans($item) {
if(!$loans = $this->_getLoans($item))
return $this->_tag('p',
$this->_getEmptyMessage(),
['class' => 'error']);
$html = [];
foreach($loans as $loan)
$html []= $this->_renderLoan($loan);
return implode($html);
}
protected function _getEmptyMessage() {
return $this->_('Aucun prêt en cours');
}
protected function _getLoans($item) {
return Class_Loan_Pnb::findAllOngoingOfItem($item);
}
protected function _renderLoan($loan) {
$fields =
[
'id' => $this->_('Identifiant du prêt interne Bokeh'),
'user_id' => $this->_('Indetifiant de l\'utilisateur interne Bokeh'),
'subscriber_id' => $this->_('Numéro de carte'),
'record_origin_id' => $this->_('Identifiant externe Dilicom'),
'order_line_id' => $this->_('Numéro de commande'),
'loan_date' => $this->_('Date de prêt'),
'expected_return_date' => $this->_('Date de retour prévue'),
'loan_link' => $this->_('Url du fichier de DRM'),
];
$lines = [];
foreach ($fields as $field => $label)
$lines[] = $this->_tag('tr',
$this->_tag('th', $label,
['scope' => 'row',
'style' => 'text-align:right;min-width:12em'])
. $this->_tag('td',
str_replace(['"', '\\'], '', json_encode($loan->callGetterByAttributeName($field), JSON_PRETTY_PRINT))));
$user = $loan->getUser();
return $this->_tag('h3', $user ? ($user->getNomComplet() . ' (' . $user->getLogin() . ')') : $this->_('Inconnu'))
. $this->_tag('div', $this->_tag('table', implode('', $lines)));
}
}
\ 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_Album_OldLoans extends ZendAfi_View_Helper_Album_Loans {
public function Album_OldLoans($item) {
return $this->Album_Loans($item);
}
protected function _getEmptyMessage() {
return $this->_('Le document n\'a pas encore été emprunté');
}
protected function _getLoans($item) {
return Class_Loan_Pnb::findLastPastLoansForItem($item);
}
}
\ 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_ModelProperties extends ZendAfi_View_Helper_BaseHelper{
public function modelProperties($model, $properties) {
$lines = [];
foreach ($properties as $field => $label)
$lines[] = $this->_tag('tr',
$this->_tag('th', $label,
['scope' => 'row'])
. $this->_tag('td',
str_replace(['"', '\\'], '', json_encode($model->callGetterByAttributeName($field), JSON_PRETTY_PRINT))));
return $this->_tag('table', implode('', $lines));
}
}
<?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_Notice_Dilicom extends ZendAfi_View_Helper_BaseHelper {
public function Notice_Dilicom($record) {
if(!Class_Users::isCurrentUserAdmin())
return $this->_loginForm();
return $this->_render($record);
}
protected function _render($record) {
if(!$album = $record->getAlbum())
return $this->_tag('p',
$this->_('Le document n\'a pas d\'album'),
['class' => 'error']);
if(!$album->isDilicom())
return $this->_tag('p',
$this->_('Ce document n\'est pas de type Dilicom'),
['class' => 'error']);
$this->_album = $album;
$html = [$this->_tag('h2',
$this->_('Album')),
$this->_renderAlbum(),
$this->_tag('hr'),
$this->_tag('h2',
$this->_('Dilicom')),
$this->_renderDilicom()];
return implode($html);
}
protected function _renderAlbum() {
return $this->view->modelProperties($this->_album,
[
'id' => $this->_('Identifiant interne Bokeh'),
'titre' => $this->_('Titre'),
'created_at' => $this->_('Date de création'),
'date_maj' => $this->_('Date de mise à jour'),
'id_origine' => $this->_('Identifiant externe Dilicom'),
'url_origine' => $this->_('Url de la ressource externe Dilicom'),
])
;
}
protected function _renderDilicom() {
return $this->_tag('div',
implode([$this->_renderTabs(),
$this->_renderOrders(),
$this->_renderLoans(),
$this->_renderOldLoans()]),
['class' => 'ig-tabs']);
}
protected function _renderTabs() {
$tabs = [$this->_tag('li', $this->_tag('a', $this->_('Commandes'),
['href' => '#ig-tab-orders'])),
$this->_tag('li', $this->_tag('a', $this->_('Prêts en cours'),
['href' => '#ig-tab-loans'])),
$this->_tag('li', $this->_tag('a', $this->_('Historique des 5 derniers prêts'),
['href' => '#ig-tab-old-loans']))];
return $this->_tag('ul', implode($tabs));
}
protected function _renderOrders() {
return $this->_withItemsDo(
function($item) {
$constraints = $item->getUsageConstraints();
return $this->_tag('h3', $constraints->getLoanOrderLineId())
. $this->_tag('div',
$this->view->Album_UsageConstraints($constraints));
},
['id' => 'ig-tab-orders',
'class' => 'ig-accordion'],
$this->_('Cet album n\'a pas de commande'));
}
protected function _withItemsDo($closure, $attribs, $message) {
$content = ($items = $this->_album->getItems())
? implode(array_map($closure, $items))
: $this->_tag('p', $message);
return $this->_tag('div', $content, $attribs);
}
protected function _renderLoans() {
return $this->_withItemsDo(
function($item) {
return $this->view->Album_Loans($item);
},
['id' => 'ig-tab-loans',
'class' => 'ig-accordion'],
$this->_('Cet album n\'a pas de prêt en cours'));
}
protected function _renderOldLoans() {
return $this->_withItemsDo(
function($item) {
return $this->view->Album_OldLoans($item);
},