Commit 25d46292 authored by Patrick Barroca's avatar Patrick Barroca 😠

hotline #71154 : plug inspector gadget on pnb dilicom albums

parent f25c4258
- 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,7 +154,7 @@ 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'),
$ig->addButton($this->_('Configuration de la recherche'),
$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,11 @@ class Class_Loan_PnbLoader extends Storm_Model_Loader {
}
public function findAllOngoingOfItem($item) {
return $this->findAllOngoingBy(['order_line_id' => $item->getOrderLineId()]);
}
public function findAllOngoingBy($params) {
$closure = function($params) { return Class_Loan_Pnb::findAllBy($params); };
return $this->_applyOngoingAndDo($params, $closure);
......
<?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
......@@ -26,8 +26,7 @@ class ZendAfi_Controller_Plugin_InspectorGadget extends Zend_Controller_Plugin_A
protected $_enabled = false,
$_calls = [],
$_record,
$_record_label,
$_buttons = [],
$_session,
$_view;
......@@ -86,7 +85,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 +93,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 +114,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));
}
......@@ -160,6 +163,9 @@ class ZendAfi_Controller_Plugin_InspectorGadget extends Zend_Controller_Plugin_A
protected function renderDialog($label, $datas) {
if(!$label)
return '';
$button = (new Class_Entity)
->setText($label)
->setImage(Class_Admin_Skin::current()->renderActionIconOn('loupe', $this->_view))
......@@ -216,12 +222,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 = Class_Loan_Pnb::findAllOngoingOfItem($item))
return $this->_tag('p',
$this->_('Aucun prêt en cours'),
['class' => 'error']);
$html = [];
foreach($loans as $loan)
$html []= $this->_renderLoan($loan);
return implode($html);
}
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))));
return $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_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() {
$fields =
[
'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'),
];
$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($this->_album->callGetterByAttributeName($field), JSON_PRETTY_PRINT))));
return $this->_tag('table', implode('', $lines));
}
protected function _renderDilicom() {
return $this->_tag('div',
implode([$this->_renderTabs(),
$this->_renderOrders(),
$this->_renderLoans()]),
['class' => 'ig-tabs']);
}
protected function _renderTabs() {
return $this->_tag('ul',
$this->_tag('li', $this->_tag('a', $this->_('Commandes'),
['href' => '#ig-tab-orders']))
. $this->_tag('li', $this->_tag('a', $this->_('Prêts'),
['href' => '#ig-tab-loans'])));
}
protected function _renderOrders() {
$id = 'ig-tab-orders';
if(!$items = $this->_album->getItems())
return $this->_renderTabContent($id,
$this->_tag('p',
$this->_('Cet album n\'a pas de commande')));
$html = [];
foreach($items as $item)
$html []= $this->view->Album_UsageConstraints($item->getUsageConstraints());
return $this->_renderTabContent($id,
implode($html));
}
protected function _renderTabContent($id, $content) {
return $this->_tag('div',
$content,
['id' => $id]);
}
protected function _renderLoans() {
$id = 'ig-tab-loans';
if(!$items = $this->_album->getItems())
return $this->_renderTabContent($id,
$this->_tag('p',
$this->_('Cet album n\'a pas de commande')));
$html = [];
foreach($items as $item)
$html []= $this->view->Album_Loans($item);
return $this->_renderTabContent($id,
implode($html));
}
protected function _loginForm() {
$preferences = (new Class_Profil_Preferences_Login())
->getPreferencesFromWidgetOrModule(Class_Profil::getCurrentProfil());
$form =
ZendAfi_Form_Login::newWithOptions(['data' => $preferences,
'action' => $this->view->url(['module' => 'opac',
'controller' => 'auth',
'action' => 'ajax-login'],
null, true)
. '?location=' . $this->view->url()]);
return $this->view->renderForm($form);
}
}
\ 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 RechercheControllerViewnoticeWithInspectorGadgetTest extends AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
$this->fixture('Class_Notice',
['id' => 2,
'unimarc' => '',
'alpha_titre' => '',
'alpha_auteur' => '']);
$this->dispatch('/opac/recherche/viewnotice/id/2/inspector_gadget/1', true);
}
/** @test */
public function buttonNoticeBokehShouldBePresent() {
$this->assertXPathContentContains('//button', 'Notice Bokeh');
}
}
class RechercheControllerViewnoticeDilicomWithInspectorGadgetTest extends Admin_AbstractControllerTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
$this->fixture('Class_Notice',
['id' => 2,
'type_doc' => Class_TypeDoc::DILICOM,
'unimarc' => '',
'alpha_titre' => '',
'alpha_auteur' => '']);
$this->dispatch('/opac/recherche/viewnotice/id/2/inspector_gadget/1', true);
}
/** @test */
public function buttonNoticeBokehShouldBePresent() {
$this->assertXPathContentContains('//button', 'Notice Bokeh');
}
/** @test */
public function buttonDilicomShouldBePresent() {
$this->assertXPathContentContains('//button', 'Dilicom');
}
}
\ 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
*/
abstract class ZendAfi_View_Helper_Notice_DilicomTestCase extends ViewHelperTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
$this->_helper = new ZendAfi_View_Helper_Notice_Dilicom();
$this->_helper->setView(new ZendAfi_Controller_Action_Helper_View());
$this->_prepareFixture();
$this->_html = $this->_helper->Notice_Dilicom($this->_record);
}
protected function _prepareFixture() {
$this->_record = $this->fixture('Class_Notice',
['id' => 1,
'type_doc' => Class_TypeDoc::DILICOM,
'clef_alpha' => 'POMMEETANANAS',
'alpha_titre' => 'POM POMS ANANA ANANAS',
'alpha_auteur' => 'AUTEUR AUTEURS',
'unimarc' => '']);
}
}
class ZendAfi_View_Helper_Notice_DilicomNotLoggedTest extends ZendAfi_View_Helper_Notice_DilicomTestCase {
/** @test */
public function shouldRenderLoginForm() {
$this->assertXPath($this->_html, '//form', $this->_html);
}
}
class ZendAfi_View_Helper_Notice_DilicomLoggedTest extends ZendAfi_View_Helper_Notice_DilicomTestCase {
protected function _prepareFixture() {
parent::_prepareFixture();
$user = $this->fixture('Class_Users',
['id' => 6,
'login' => 'admin',
'password' => 'admin',
'role_level' => ZendAfi_Acl_AdminControllerRoles::ADMIN_PORTAIL]);
ZendAfi_Auth::getInstance()->logUser($user);
$this->fixture('Class_Album',
['id' => 2,
'titre' => 'Musso Dilicom',