diff --git a/FEATURES/95222 b/FEATURES/95222 new file mode 100644 index 0000000000000000000000000000000000000000..fb0b6c9913ff9da03760195210c4aef3fead78e1 --- /dev/null +++ b/FEATURES/95222 @@ -0,0 +1,10 @@ + '95222' => + ['Label' => $this->_('Boite Auteurs'), + 'Desc' => $this->_('Permet d\'afficher dynamiquement des auteurs à partir d\'une sélection de notices (domaines, paniers)'), + 'Image' => '', + 'Video' => 'https://www.youtube.com/watch?v=aK4Dz3LVOIo', + 'Category' => 'Recherche', + 'Right' => function($feature_description, $user) {return true;}, + 'Wiki' => 'http://wiki.bokeh-library-portal.org/index.php?title=Boite_auteurs', + 'Test' => '', + 'Date' => '2019-07-18'], \ No newline at end of file diff --git a/VERSIONS_WIP/95222 b/VERSIONS_WIP/95222 new file mode 100644 index 0000000000000000000000000000000000000000..8cd4aaec3ba029821b80ec8d9f250334246887a3 --- /dev/null +++ b/VERSIONS_WIP/95222 @@ -0,0 +1 @@ + - ticket #95222 : Ajout de la boite Auteurs \ No newline at end of file diff --git a/application/modules/admin/controllers/AjaxController.php b/application/modules/admin/controllers/AjaxController.php index 983c3ff7a9ee5b89f89b6a0599f25c8b73464c28..ce63c3a2215dfc3812e0df6a9f96bf02273e679e 100644 --- a/application/modules/admin/controllers/AjaxController.php +++ b/application/modules/admin/controllers/AjaxController.php @@ -53,7 +53,8 @@ class Admin_AjaxController extends ZendAfi_Controller_Action { protected function getAuthorityFor($code) { - $authorities = ['auteur' => new Class_Auteur(), + $authorities = ['auteur' => new Class_CodifAuteur(), + 'responsibility' => new Class_CodifAuteurFonction(), 'matiere' => new Class_Matiere(), 'interet' => new Class_CodifCentreInteret(), 'dewey' => new Class_CodifDewey(), diff --git a/application/modules/admin/controllers/WidgetController.php b/application/modules/admin/controllers/WidgetController.php index 5ca52152035925a692214acf143ffbd08cdca3b3..55058fe4d15d5fb7a6c7c6f32a5c0bd3ab23c635 100644 --- a/application/modules/admin/controllers/WidgetController.php +++ b/application/modules/admin/controllers/WidgetController.php @@ -305,4 +305,21 @@ class Admin_WidgetController extends ZendAfi_Controller_Action { public function formProvider($widget) { return call_user_func_array([$widget->getForm(), 'newWith'], [$widget->forForm()]); } + + + public function widgetActionAction() { + $id_module = $this->_getParam('id_module'); + + if (Class_Profil::getCurrentProfil()->getId() !== (int)$this->_getParam('id_profil')) + throw new Zend_Controller_Action_Exception($this->view->_('Profil inexistant'), 404); + + if (!$config = Class_Profil::getCurrentProfil()->getLocalModuleAccueilConfig($id_module)) + throw new Zend_Controller_Action_Exception($this->view->_('Boite inexistante'), 404); + + $helper = ZendAfi_View_Helper_Accueil_Base::getModuleHelperFromParams($id_module, + $config, + $this->view); + $helper->performAction($this->_getParam('named')); + $this->_redirectToReferer(); + } } \ No newline at end of file diff --git a/cosmogramme/sql/patch/patch_376.php b/cosmogramme/sql/patch/patch_376.php new file mode 100644 index 0000000000000000000000000000000000000000..823c2cd028ab43a23ea72601f503fb3dd02c0bf4 --- /dev/null +++ b/cosmogramme/sql/patch/patch_376.php @@ -0,0 +1,6 @@ +<?php +$adapter = Zend_Db_Table_Abstract::getDefaultAdapter(); +try { + $adapter->query('alter table codif_auteur add column thumbnail_url varchar(255)'); + +} catch(Exception $e) {} diff --git a/library/Class/Auteur.php b/library/Class/Auteur.php deleted file mode 100644 index 4cc4bc90f9473f0976dd7ad0568b418cbdb6275c..0000000000000000000000000000000000000000 --- a/library/Class/Auteur.php +++ /dev/null @@ -1,62 +0,0 @@ -<?PHP -/** - * Copyright (c) 2012, 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 - */ -//////////////////////////////////////////////////////////////////////////////////////// -// OPAC 3 :AUTEURS -/////////////////////////////////////////////////////////////////////////////////////// - -class Class_Auteur -{ - -// ---------------------------------------------------------------- -// Rend une liste pour un champ suggestion -// ---------------------------------------------------------------- - public function getListeSuggestion($recherche,$mode,$limite_resultat) - { - // Lancer la recherche - $ix=new Class_Indexation(); - $code_alpha=$ix->alphaMaj($recherche); - $code_alpha=str_replace(" ","x",$code_alpha); - if($mode=="1") $req="select id_auteur,libelle from codif_auteur where formes like'".$code_alpha."%' order by FORMES limit ".$limite_resultat; - - $resultat=fetchAll($req); - - // Mettre l'indice et le libelle - if(!$resultat) return false; - foreach($resultat as $enreg) - { - $liste[]=array($enreg["id_auteur"],$enreg["libelle"]); - } - - return $liste; - } - - -// ---------------------------------------------------------------- -// Rend prénom et nom -// ---------------------------------------------------------------- - static function getLibelle($id_auteur) - { - $libelle = fetchEnreg("select libelle from codif_auteur where id_auteur='$id_auteur'"); - return $libelle; - } -} - -?> \ No newline at end of file diff --git a/library/Class/CodifAuteur.php b/library/Class/CodifAuteur.php index cf45e5818da69827a02980a63d73b49ad2ee2d2f..1ae9b079875be577871dffbaaac4971b166f8e47 100644 --- a/library/Class/CodifAuteur.php +++ b/library/Class/CodifAuteur.php @@ -122,9 +122,36 @@ class Class_CodifAuteur extends Storm_Model_Abstract { 'wikidata_id' => '', 'youtube_channel_id' => '', 'isni' => '', - 'ark' => '']; + 'ark' => '', + 'thumbnail_url' => '']; public function getCategorie() { return; } + + + public function getListeSuggestion($recherche, $mode, $limite_resultat) { + $code_alpha = str_replace(' ', + 'x', + Class_Indexation::getInstance()->alphaMaj($recherche)); + + $authors = Class_CodifAuteur::getLoader() + ->findAllBy(['where' => 'formes like "' . $code_alpha . '%"', + 'order' => 'FORMES', + 'limit' => $limite_resultat]); + + return array_map(function($author) + { + return [$author->getId(), $author->getLibelle()]; + }, + $authors); + } + + + public function isThumbnailValid() { + return + (!empty($this->getThumbnailUrl())) + && + (false == strpos($this->getThumbnailUrl(), 'Defaut.svg')); + } } \ No newline at end of file diff --git a/library/Class/CodifAuteur/Description.php b/library/Class/CodifAuteur/Description.php index 1b72d9dbc1e4499cb735de0392aef3dd08c23e07..a916cf8659bcdef9aa50eace6e1f50e31c9b2d59 100644 --- a/library/Class/CodifAuteur/Description.php +++ b/library/Class/CodifAuteur/Description.php @@ -106,19 +106,9 @@ class Class_CodifAuteur_Description { if (!count($this->getRecords())) return ''; - $data = $this->_fetchBiography($this->_author, - $this->getRecords(), - $this->getAssociatedAuthors()); - - $author_attribs = array_intersect_key($data, ['wikidata_id' => '', - 'youtube_channel_id' => '', - 'ark' => '', - 'isni' => '']); - $this->_author - ->updateAttributes($author_attribs) - ->save(); + $data = $this->fetchBiography(); - if ($biography = $data['biographie']) { + if ($biography = $data->getbiographie()) { $biography = $this->_enrichBiographyWithRecords($biography, $this->getRecords(), $view); @@ -129,17 +119,19 @@ class Class_CodifAuteur_Description { } $thumbnail = ''; - if ($data['vignette']) + if ($this->_author->getThumbnailUrl()) $thumbnail = $view->tag('img', null, - ['src' => $data['vignette'], + ['src' => $this->_author->getThumbnailUrl(), 'alt' => $this->getLabel() . '. ' . $this->_('Source: Wikipedia')]); $update_button = $view->biographie_UpdateButton($this->getRecords()[0], $this->getLabel()); - $licence = $view->biographie_Licence($this->getLabel(), $data['source'], $data['url_source']); + $licence = $view->biographie_Licence($this->getLabel(), + $data->getsource(), + $data->geturl_source()); return $update_button . $thumbnail . $biography . $licence; } @@ -222,9 +214,23 @@ class Class_CodifAuteur_Description { public function fetchBiography() { - return new Class_Entity($this->_fetchBiography($this->_author, - $this->getRecords(), - $this->getAssociatedAuthors())); + $bio = new Class_Entity($this->_fetchBiography($this->_author, + $this->getRecords(), + $this->getAssociatedAuthors())); + + $author_attribs = array_intersect_key($bio->toArray(), + ['wikidata_id' => '', + 'youtube_channel_id' => '', + 'ark' => '', + 'isni' => '']); + if ($bio->getvignette()) + $author_attribs['thumbnail_url'] = $bio->getvignette(); + + $this->_author + ->updateAttributes($author_attribs) + ->save(); + + return $bio; } @@ -309,30 +315,19 @@ class Class_CodifAuteur_Description { public function renderThumbnailOn($view) { - $data = new Class_Entity($this->_fetchBiography($this->_author, - $this->getRecords(), - $this->getAssociatedAuthors())); - return $data->getvignette() + $this->fetchBiography(); + + return $this->_author->getThumbnailUrl() ? $view->tag('img', null, - ['src' => $data->getvignette(), + ['src' => $this->_author->getThumbnailUrl(), 'alt' => $this->getLabel() . '. ' . $this->_('Source: Wikipedia')]) : ''; } public function renderWikipediaOn($view) { - $data = new Class_Entity($this->_fetchBiography($this->_author, - $this->getRecords(), - $this->getAssociatedAuthors())); - - $author_attribs = array_intersect_key($data->toArray(), ['wikidata_id' => '', - 'youtube_channel_id' => '', - 'ark' => '', - 'isni' => '']); - $this->_author - ->updateAttributes($author_attribs) - ->save(); + $data = $this->fetchBiography(); if (!$biography = $data->getbiographie()) return ''; diff --git a/library/Class/CodifAuteurFonction.php b/library/Class/CodifAuteurFonction.php index 4ae6196f045b33f9120b605913634527923a71ae..465bdcda6a68a42cb19a1a083845cc6270ed992b 100644 --- a/library/Class/CodifAuteurFonction.php +++ b/library/Class/CodifAuteurFonction.php @@ -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 */ class Class_CodifAuteurFonctionLoader extends Storm_Model_Loader { @@ -24,12 +24,29 @@ class Class_CodifAuteurFonctionLoader extends Storm_Model_Loader { return array_map(function ($model) {return $model->getLibelle();}, Class_CodifAuteurFonction::findAllBy(['order' => 'libelle'])); } + } + + class Class_CodifAuteurFonction extends Storm_Model_Abstract { - protected $_table_name = 'codif_auteurs_fonctions'; - protected $_table_primary = 'id_fonction'; - protected $_loader_class = 'Class_CodifAuteurFonctionLoader'; + protected + $_table_name = 'codif_auteurs_fonctions', + $_table_primary = 'id_fonction', + $_loader_class = 'Class_CodifAuteurFonctionLoader'; + + + public function getListeSuggestion($recherche, $mode, $limite_resultat) { + $responsibilities = Class_CodifAuteurFonction::getLoader() + ->findAllBy(['where' => 'libelle like "' . $recherche .'%"', + 'order' => 'libelle']); + + return array_map(function($responsibility) + { + return [$responsibility->getId(), $responsibility->getLibelle()]; + }, + $responsibilities); + } } ?> \ No newline at end of file diff --git a/library/Class/Notice.php b/library/Class/Notice.php index a4ed9fa41db1d7549509d432444eccc8f7ab7e4e..e2383cb92669d9c43873be2768b02ff06ad0f2d8 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -1029,12 +1029,14 @@ class Class_Notice extends Storm_Model_Abstract { return $this->_auteur_principal; } + public function getFirstAuthor() { if (!$auteurs = $this->getAuteursUnimarc(true)) return ''; return $auteurs[0]; } + public function setAuteurPrincipal($auteur) { $this->_auteur_principal = $auteur; return $this; @@ -1047,7 +1049,6 @@ class Class_Notice extends Storm_Model_Abstract { public function getAuteursUnimarc($auteurPrincipal = false, $getFonction = false) { - $indexation = Class_Indexation::getInstance(); $auteurs = []; $zones = ['700', '710', '720', '730', '701', '702', '711', '712', '721', '722']; @@ -1226,7 +1227,9 @@ class Class_Notice extends Storm_Model_Abstract { return []; $label = trim($prenom . ' ' . $nom) . (($fonction) ? ' (' . $fonction . ')': ''); - return (new Class_Notice_FieldAuthor($codif_auteur))->setLabel($label); + return (new Class_Notice_FieldAuthor($codif_auteur)) + ->setLabel($label) + ->setFonction($fonction); } @@ -1628,21 +1631,7 @@ class Class_Notice extends Storm_Model_Abstract { public function getAvailableLibrariesFromFacet() { - $existing = array_filter( - Class_Notice_Facette::parseFacettesFromNoticeField($this->getFacettes()), - function($facet) { - return $facet->isAvailability(); - }); - - $values = array_unique( - array_filter( - array_map(function($facet) - { - return $facet->getValue(); - }, - $existing))); - - if(!$values) + if (!$values = Class_Notice_Facette::facetsValuesFromRecordFilteredBy($this, 'isAvailability')) return []; return Class_Bib::findAllBy(['id_site' => $values]); diff --git a/library/Class/Notice/Facette.php b/library/Class/Notice/Facette.php index 7935c67195d13638b9aa42ab74429f3d2e552b5c..ab1a48e33d3a1366604085abbc96a87e95158b04 100644 --- a/library/Class/Notice/Facette.php +++ b/library/Class/Notice/Facette.php @@ -37,6 +37,24 @@ class Class_Notice_Facette { } + public static function facetsValuesFromRecordFilteredBy($record, $filter_name) { + $existing = array_filter( + Class_Notice_Facette::parseFacettesFromNoticeField($record->getFacettes()), + function($facet) use ($filter_name){ + return call_user_func([$facet, $filter_name]); + }); + + $values = array_unique( + array_filter( + array_map(function($facet) + { + return $facet->getValue(); + }, + $existing))); + return $values; + } + + public static function extractCodeRubrique($cle) { return (Class_CodifThesaurus::CODE_FACETTE == ($code = $cle[0])) ? Class_CodifThesaurus::getLoader()->getFacetGroup($cle) diff --git a/library/Class/Systeme/ModulesAccueil.php b/library/Class/Systeme/ModulesAccueil.php index f710a0d5bafb2b2934b454ea0267040ee94086ce..9f09d4e6630877f703c899f72022f664dc71da3c 100644 --- a/library/Class/Systeme/ModulesAccueil.php +++ b/library/Class/Systeme/ModulesAccueil.php @@ -136,7 +136,8 @@ class Class_Systeme_ModulesAccueil extends Class_Systeme_ModulesAbstract { 'Panier', 'DomainBrowser', 'PremierChapitre', - 'Library']; + 'Library', + 'Authors']; foreach($defaults as $default) { $name = 'Class_Systeme_ModulesAccueil_' . $default; diff --git a/library/Class/Systeme/ModulesAccueil/Authors.php b/library/Class/Systeme/ModulesAccueil/Authors.php new file mode 100644 index 0000000000000000000000000000000000000000..8d8742866b41ad0c255a9714f2e418dc32b7c469 --- /dev/null +++ b/library/Class/Systeme/ModulesAccueil/Authors.php @@ -0,0 +1,57 @@ +<?php +/** + * Copyright (c) 2012, 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_Systeme_ModulesAccueil_Authors extends Class_Systeme_ModulesAccueil_Null { + const + CODE = 'AUTHORS', + AUTHORS_SELECTION_MODE_ALL = 'all', + AUTHORS_SELECTION_MODE_RESPONSIBILITIES = 'responsibilities', + AUTHORS_SELECTION_MODE_MAIN = 'main'; + + + protected + $_group = Class_Systeme_ModulesAccueil::GROUP_RECH, + $_isPhone = true; + + + public function __construct() { + $this->_libelle = $this->_('Boite auteurs'); + $this->_form = 'ZendAfi_Form_Configuration_Widget_Authors'; + $this->_defaultValues = ['titre' => $this->_('Sélection d\'auteurs'), + 'op_largeur_img' => 260, + 'authors_count' => 10, + 'authors_selection_mode' => static::AUTHORS_SELECTION_MODE_ALL]; + } + + + public function getAuthorsSelectionModeOptions() { + return [ + static::AUTHORS_SELECTION_MODE_ALL => $this->_('Tous les auteurs'), + static::AUTHORS_SELECTION_MODE_MAIN => $this->_('Auteurs principaux'), + static::AUTHORS_SELECTION_MODE_RESPONSIBILITIES => $this->_('Par responsabilité') + ]; + } + + + public function getDefaultAuthorsSelectionMode() { + return $this->_defaultValues['authors_selection_mode']; + } +} \ No newline at end of file diff --git a/library/ZendAfi/Form/Configuration/Widget/Authors.php b/library/ZendAfi/Form/Configuration/Widget/Authors.php new file mode 100644 index 0000000000000000000000000000000000000000..f664f2ce4eff7e0d0d385c0b1a74e781f4ce7f73 --- /dev/null +++ b/library/ZendAfi/Form/Configuration/Widget/Authors.php @@ -0,0 +1,80 @@ +<?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_Widget_Authors extends ZendAfi_Form_Configuration_Widget_Base { + public function init() { + parent::init(); + + Class_ScriptLoader::getInstance() + ->addJQueryReady('radioToggleVisibilityForElement("input[name=\'authors_selection_mode\']", + $("#responsibilities").closest("tr"), + ["responsibilities"]);'); + + $authors_module = new Class_Systeme_ModulesAccueil_Authors(); + + $this + ->addElement('domainePanier', + 'data_source') + ->addElement('number', + 'authors_count', + ['label' => $this->_('Nombre maximum d\'auteurs'), + 'min' => 1, + 'max' => 200]) + ->addElement('slider', + 'op_largeur_img', + ['label' => $this->_('Largeur des colonnes'), + 'min' => 100, + 'max' => 2000, + 'step' => 1]) + ->addElement('radio', + 'authors_selection_mode', + ['label' => $this->_('Auteurs sélectionnés'), + 'multiOptions' => $authors_module->getAuthorsSelectionModeOptions(), + 'value' => $authors_module->getDefaultAuthorsSelectionMode()]) + ->addElement('listeSuggestion', + 'responsibilities', + ['label' => $this->_('Responsabilité auteur'), + 'rubrique' => 'responsibility']) + + ->addToSelectionGroup(['data_source']) + + ->addToDisplaySettingsGroup(['authors_selection_mode', + 'responsibilities', + 'authors_count']) + + ->addToStyleGroup(['op_largeur_img']); + } + + + public function populate(array $datas) { + $this->customPopulate($datas); + return parent::populate($datas); + } + + + public function customPopulate($datas) { + $this + ->getElement('data_source') + ->setOptions(['IdItems' => isset($datas['id_panier']) ? $datas['id_panier'] : '', + 'IdCategories' => isset($datas['id_catalogue']) ? $datas['id_catalogue'] : '']); + return $this; + } +} \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Accueil/Authors.php b/library/ZendAfi/View/Helper/Accueil/Authors.php new file mode 100644 index 0000000000000000000000000000000000000000..4a5fb2e0b6db643e139f3bf33ddd3fd5afe0ec3b --- /dev/null +++ b/library/ZendAfi/View/Helper/Accueil/Authors.php @@ -0,0 +1,203 @@ +<?php +/** + * Copyright (c) 2012, 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_Accueil_Authors extends ZendAfi_View_Helper_Accueil_Base { + public function getHTML() { + $this->titre = $this->preferences['titre']; + $this->contenu = $this->_renderContent(); + + return $this->getHtmlArray(); + } + + + public function performAction($action) { + if ($action === 'refresh') + $this->refreshAuthorsWithoutThumbnail(); + } + + + public function refreshAuthorsWithoutThumbnail() { + $authors = array_filter($this->_findAuthorsFromPreferences(), + function($author) + { + return !$author->isThumbnailValid(); + }); + array_map(function($author) + { + (new Class_CodifAuteur_Description($author))->fetchBiography(); + }, + $authors); + return $this; + } + + + protected function _extendedActions() { + if (!Class_Users::isCurrentUserCanAccesBackend()) + return null; + + return [ + function() + { + return $this->view->tagAnchor($this->view->url(['module' => 'admin', + 'controller' => 'widget', + 'action' => 'widget-action', + 'named' => 'refresh', + 'id_module' => $this->id_module, + 'id_profil' => Class_Profil::getCurrentProfil()->getId()]), + Class_Admin_Skin::current() + ->renderActionIconOn('images', + $this->view), + [ + 'title' => $this->view->_('Recharger les vignettes de la boite: %s', + htmlspecialchars($this->preferences['titre'])) + ]); + } + ]; + } + + + protected function _findAuthorsFromPreferences() { + $records = Class_Notice::getNoticesFromPreferences($this->preferences); + return $this->_getAuthorsFromRecords($records); + } + + + protected function _renderContent() { + $authors = array_filter($this->_findAuthorsFromPreferences(), + function($author) + { + return $author->isThumbnailValid(); + }); + + return $this->_tag('div', + implode('', array_map([$this, '_renderAuthor'], + $authors)), + ['class' => 'authors_wall', + 'style' => 'column-width:' . $this->preferences['op_largeur_img'] . 'px']); + } + + + protected function _getAuthorsFromRecords($records) { + $authors_ids = $this->_getAuthorsIdsFromRecords($records); + + return $authors_ids + ? Class_CodifAuteur::findAllBy(['id_auteur' => array_slice($authors_ids, + 0, + $this->preferences['authors_count'])]) + : []; + } + + + protected function _getAuthorsIdsFromRecords($records) { + if ($this->preferences['authors_selection_mode'] === Class_Systeme_ModulesAccueil_Authors::AUTHORS_SELECTION_MODE_MAIN) + return $this->_getMainAuthorsFromRecords($records); + + if ($this->preferences['authors_selection_mode'] === Class_Systeme_ModulesAccueil_Authors::AUTHORS_SELECTION_MODE_RESPONSIBILITIES) { + return $this->_getAuthorsByResponsibilitiesFromRecords($records); + } + + return $this->_getAllAuthorsFromRecords($records); + } + + + protected function _getAuthorsByResponsibilitiesFromRecords($records) { + $responsibilities_labels = $this->_getResponsibilitiesPreferenceLabels(); + + $authors_ids = []; + foreach($records as $record) { + $authors_ids = array_merge($authors_ids, + $this->_getAuthorsByResponsibilities($record, + $responsibilities_labels)); + } + + return array_filter(array_unique($authors_ids)); + } + + + protected function _getResponsibilitiesPreferenceLabels() { + $responsibilities_ids = array_filter(explode(';', + $this->preferences['responsibilities'])); + return array_filter( + array_map(function($responsibility) + { + return $responsibility->getLibelle(); + }, + $responsibilities_ids + ? Class_CodifAuteurFonction::findAllBy(['id_fonction' => $responsibilities_ids]) + : [])); + } + + + protected function _getAuthorsByResponsibilities($record, $responsibilities_labels) { + $authors = array_filter($record->getAuteursUnimarc(false, true), + function($author) use ($responsibilities_labels) + { + + return in_array($author->getFonction(), $responsibilities_labels); + }); + + return array_map(function($author) + { + return $author->getId(); + }, + $authors); + } + + + protected function _getMainAuthorsFromRecords($records) { + $authors_ids = array_map(function($record) + { + return current(Class_Notice_Facette::facetsValuesFromRecordFilteredBy($record, 'isAuthor')); + }, + $records); + + return array_filter(array_unique($authors_ids)); + } + + + protected function _getAllAuthorsFromRecords($records) { + $authors_ids = []; + foreach($records as $record) { + $authors_ids = array_merge($authors_ids, + Class_Notice_Facette::facetsValuesFromRecordFilteredBy($record, 'isAuthor')); + } + + return array_filter(array_unique($authors_ids)); + } + + + protected function _renderAuthor($author) { + return $this->_tag('div', + $this->_tag('a', + $this->_tag('img', + null, + ['src' => $author->getThumbnailUrl(), + 'width' => $this->preferences['op_largeur_img'], + 'alt' => $author->getLibelle() . '. ' . $this->_('Source: Wikipedia')]), + ['href' => $this->view->url(['controller' => 'author', + 'action' => 'view', + 'id' => $author->getId()]), + 'title' => $this->_('En savoir plus sur %s', $author->getLibelle())]), + ['class' => 'author']); + } +} + +?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/Accueil/Base.php b/library/ZendAfi/View/Helper/Accueil/Base.php index 26a27cf4dbee65780313b606ce1d8d1ce3d00467..8d8c9e30d9661bbbf654cd308d62e2dff1314e67 100644 --- a/library/ZendAfi/View/Helper/Accueil/Base.php +++ b/library/ZendAfi/View/Helper/Accueil/Base.php @@ -74,6 +74,11 @@ class ZendAfi_View_Helper_Accueil_Base extends ZendAfi_View_Helper_ModuleAbstrac } + public function performAction($action) { + //@see Admin_WidgetController::widgetActionAction() + } + + public function setIdMenu($id_menu) { $this->_id_menu = $id_menu; return $this; diff --git a/library/ZendAfi/View/Helper/Accueil/Kiosque.php b/library/ZendAfi/View/Helper/Accueil/Kiosque.php index db4fe90426828419fd2892ea41fc40c40d00f3f2..802d8d8c5ffb3eb3e48022b1d687cb111c712856 100644 --- a/library/ZendAfi/View/Helper/Accueil/Kiosque.php +++ b/library/ZendAfi/View/Helper/Accueil/Kiosque.php @@ -89,13 +89,13 @@ class ZendAfi_View_Helper_Accueil_Kiosque extends ZendAfi_View_Helper_Accueil_Ba return ''; return $this->view->tagAnchor($this->view->url(['module' => 'admin', - 'controller' => 'catalogue', - 'action' => 'edit', - 'id_catalogue' => $this->preferences['id_catalogue']]), - Class_Admin_Skin::current() - ->renderActionIconOn('edit', $this->view, - ['title' => $this->view->_('Modifier le domaine : %s', htmlspecialchars($catalogue->getLibelle()))]), - ['data-popup' => 'true']); + 'controller' => 'catalogue', + 'action' => 'edit', + 'id_catalogue' => $this->preferences['id_catalogue']]), + Class_Admin_Skin::current() + ->renderActionIconOn('edit', $this->view, + ['title' => $this->view->_('Modifier le domaine : %s', htmlspecialchars($catalogue->getLibelle()))]), + ['data-popup' => 'true']); } @@ -108,10 +108,10 @@ class ZendAfi_View_Helper_Accueil_Kiosque extends ZendAfi_View_Helper_Accueil_Ba return null; return $this->view->tagAnchor($this->view->url(['module' => 'admin', - 'controller' => 'catalogue', - 'action' => 'add', - 'id_catalogue' => $domaine_parent->getId(), - 'id_module' => $this->id_module]), + 'controller' => 'catalogue', + 'action' => 'add', + 'id_catalogue' => $domaine_parent->getId(), + 'id_module' => $this->id_module]), Class_Admin_Skin::current() ->renderActionIconOn('add', $this->view, ['title' => $this->view->_('Afficher un nouveau domaine')]), ['data-popup' => 'true']); diff --git a/library/ZendAfi/View/Helper/Admin/TagListeSuggestion.php b/library/ZendAfi/View/Helper/Admin/TagListeSuggestion.php index 670babfa5c7662203c3ebc0d375fd36066aa224b..c506440f4c347655eca1372d1d89b1393c294896 100644 --- a/library/ZendAfi/View/Helper/Admin/TagListeSuggestion.php +++ b/library/ZendAfi/View/Helper/Admin/TagListeSuggestion.php @@ -149,6 +149,7 @@ class ZendAfi_View_Helper_Admin_TagListeSuggestion $map = [ 'auteur' => ['Class_CodifAuteur', [1 => $this->_('commence par')]], + 'responsibility' => ['Class_CodifAuteurFonction', [1 => $this->_('commence par')]], 'matiere' => ['Class_CodifMatiere'], 'interet' => ['Class_CodifCentreInteret'], 'dewey' => ['Class_CodifDewey', $dewey_pcdm4_options], diff --git a/library/ZendAfi/View/Helper/RenderAuthorMetadata.php b/library/ZendAfi/View/Helper/RenderAuthorMetadata.php index 7dc65e4e8c9e9004656d0ff156f433c854c20986..70703e887dc3ddafbfe004160d5b6e85b248b1c1 100644 --- a/library/ZendAfi/View/Helper/RenderAuthorMetadata.php +++ b/library/ZendAfi/View/Helper/RenderAuthorMetadata.php @@ -28,17 +28,27 @@ class ZendAfi_View_Helper_renderAuthorMetadata extends ZendAfi_View_Helper_BaseH if ($id = $attributes['ark']) $attributes['ark'] = $this->_tag('a', $id, - ['href' => 'https://data.bnf.fr/fr/atelier/' . $id]); + ['href' => 'https://data.bnf.fr/' . $id, + 'target' => '_blank']); if ($id = $attributes['wikidata_id']) $attributes['wikidata_id'] = $this->_tag('a', $id, - ['href' => 'https://www.wikidata.org/wiki/' . $id]); + ['href' => 'https://www.wikidata.org/wiki/' . $id, + 'target' => '_blank']); if ($id = $attributes['youtube_channel_id']) $attributes['youtube_channel_id'] = $this->_tag('a', $id, - ['href' => Class_WebService_Youtube::CHANNEL_URL . $id]); + ['href' => Class_WebService_Youtube::CHANNEL_URL . $id, + 'target' => '_blank']); + + + if ($thumbnail_url = $attributes['thumbnail_url']) + $attributes['thumbnail_url'] = $this->_tag('a', + $thumbnail_url, + ['href' => $thumbnail_url, + 'target' => '_blank']); return $this->_tag('h2', $this->_('Auteur : %s', diff --git a/public/opac/css/global.css b/public/opac/css/global.css index 0175dae05a3a53fbf7774326ecbd40918240a5e7..190e01a01286d85d634f553c3e860b27910ea585 100644 --- a/public/opac/css/global.css +++ b/public/opac/css/global.css @@ -3718,18 +3718,21 @@ a[href*="bookmarked-searches/notify"] img { overflow: hidden; } + .simple_wall > a > img { width: 100%; } .simple_wall > a > img, -.simple_wall > div { +.simple_wall > div, +.authors_wall div { transition: opacity 0.3s; } .simple_wall:hover > a:not(:hover), -.simple_wall:hover > div:not(:hover) { +.simple_wall:hover > div:not(:hover), +.authors_wall:hover div:not(:hover){ opacity: 0.4; } diff --git a/public/opac/js/widget_templates/authors.jpg b/public/opac/js/widget_templates/authors.jpg new file mode 100644 index 0000000000000000000000000000000000000000..c7dc96512b093e9d3b838f312da344c51712f4c5 Binary files /dev/null and b/public/opac/js/widget_templates/authors.jpg differ diff --git a/public/opac/js/widget_templates/widget_templates.json b/public/opac/js/widget_templates/widget_templates.json index a939603c921181a8fa2b38c8ac1e40018a678a61..b24428962ab9f0434cce046e4ac5f31b11983c77 100755 --- a/public/opac/js/widget_templates/widget_templates.json +++ b/public/opac/js/widget_templates/widget_templates.json @@ -225,7 +225,14 @@ } }, - { + { + "title": "Auteurs", + "icon": "authors.jpg", + "type": "AUTHORS", + "configuration": {} + }, + + { "title": "Nuage de tags", "icon": "nuage_tags.jpg", "type": "TAGS", diff --git a/tests/db/UpgradeDBTest.php b/tests/db/UpgradeDBTest.php index fb412af4b8d982366cd6e97be8cf1a532620cf60..6fe50e6c25d2d2df3378674852c57a904e90d833 100644 --- a/tests/db/UpgradeDBTest.php +++ b/tests/db/UpgradeDBTest.php @@ -2739,4 +2739,20 @@ class UpgradeDB_375_Test extends UpgradeDBTestCase { $this->assertEquals('Hello<br><br>You have a new friend', $this->query('select valeur from bib_admin_var where clef="NOTIFICATION_TEMPLATE_NEW_USER"')->fetch()['valeur']); } -} \ No newline at end of file +} + + + + +class UpgradeDB_376_Test extends UpgradeDBTestCase { + public function prepare() { + $this + ->silentQuery('ALTER TABLE codif_auteur DROP COLUMN thumbnail_url'); + } + + + /** @test */ + public function tableCodifAuteurShouldHaveColumnThumbnailUrlVarChar255() { + $this->assertFieldType('codif_auteur', 'thumbnail_url', 'varchar(255)'); + } +} diff --git a/tests/scenarios/AuthorPage/AuthorPageTest.php b/tests/scenarios/AuthorPage/AuthorPageTest.php index 7c13953da0e92b771382af62649dbe153f4302b2..327a3fddd6f5bc1827e61e054450d2408f3856f9 100644 --- a/tests/scenarios/AuthorPage/AuthorPageTest.php +++ b/tests/scenarios/AuthorPage/AuthorPageTest.php @@ -56,6 +56,7 @@ abstract class AuthorPageTestCase extends AbstractControllerTestCase { 'facettes' => 'A2408 A3', 'url_vignette' => 'paris.jpg']); + $this->fixture('Class_CodifAuteur', ['id' => 2408, 'libelle' => 'Victor Hugo']); @@ -190,17 +191,25 @@ class AuthorPageViewByIdTest extends AuthorPageTestCase { $this->assertEquals('UC1l7wYrva1qCH-wgqcHaaRg', Class_CodifAuteur::find(2408)->getYoutubeChannelId()); } - /** @test */ + /** @test */ public function authorISNIShouldBe0000000078391751() { $this->assertEquals('0000 0000 7839 1751', Class_CodifAuteur::find(2408)->getIsni()); } - /** @test */ + + /** @test */ public function authorARKShouldBecb13971020f() { $this->assertEquals('ark:/12148/cb13971020f', Class_CodifAuteur::find(2408)->getArk()); } + /** @test */ + public function authorThumbnailUrlShouldBeHugoThumbDotJpg() { + $this->assertEquals('http://images.fr/hugo_thumb.jpg', + Class_CodifAuteur::find(2408)->getThumbnailUrl()); + } + + /** @test */ public function pageTitleShouldBeVictorHugo() { $this->assertXPath('//title[text()="Auteur - Victor Hugo"]', $this->_response->getBody()); diff --git a/tests/scenarios/AuthorPage/AuthorWidgetTest.php b/tests/scenarios/AuthorPage/AuthorWidgetTest.php new file mode 100644 index 0000000000000000000000000000000000000000..d271480cad68d880e35f7a855d5ec49aa56098a5 --- /dev/null +++ b/tests/scenarios/AuthorPage/AuthorWidgetTest.php @@ -0,0 +1,501 @@ +<?php +/** + * Copyright (c) 2012-2019, 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 AuthorWidgetOnPageTestCase extends Admin_AbstractControllerTestCase { + protected + $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + + Class_AdminVar::set('AUTHOR_PAGE', 1); + + $cfg_accueil = ['modules' => ['1' => ['division' => '2', + 'type_module' => 'AUTHORS', + 'preferences' => ['titre' => 'Mes auteurs', + 'id_panier' => 3]]]]; + + $this->fixture('Class_Profil', + ['id' => 2, + 'libelle' => 'auteurs', + 'cfg_accueil' => $cfg_accueil]) + ->beCurrentProfil(); + + + $this->fixture('Class_Notice', + ['id' => 8, + 'type_doc' => Class_TypeDoc::LIVRE, + 'clef_alpha'=>'GAVROCHE_HUGO', + 'titre_principal' => 'Gavroche', + 'facettes' => 'A2408 A3 A666 G4 M6', + 'url_vignette' => 'gavroche.jpg']); + + $this->fixture('Class_Notice', + ['id' => 9, + 'type_doc' => Class_TypeDoc::LIVRE, + 'clef_alpha'=>'MISERABLES_HUGO', + 'titre_principal' => 'Les Misérables', + 'facettes' => 'A2408 M6 A4', + 'unimarc' => file_get_contents(__DIR__ . '/les_miserables.marc'), + 'url_vignette' => 'miserables.jpg', + 'url_image' => 'miserables.jpg']); + + $this->fixture('Class_Notice', + ['id' => 10, + 'type_doc' => Class_TypeDoc::DVD, + 'clef_alpha'=>'DAMEPARIS_HUGO', + 'titre_principal' => 'Notre Dame de Paris', + 'unimarc' => file_get_contents(__DIR__ . '/notre_dame.marc'), + 'facettes' => 'A2408 A3', + 'url_vignette' => 'paris.jpg']); + + $this->fixture('Class_CodifAuteur', + ['id' => 2408, + 'libelle' => 'Victor Hugo', + 'thumbnail_url' => 'http://wp/hugo.jpg']); + + $this->fixture('Class_CodifAuteur', + ['id' => 3, + 'libelle' => 'Robert Hossein', + 'thumbnail_url' => 'http://wp/hossein.jpg']); + + $this->fixture('Class_CodifAuteur', + ['id' => 4, + 'libelle' => 'Marcus %s \Mill', + 'thumbnail_url' => 'http://wp&f=Defaut.svg']); + + $this->fixture('Class_CodifAuteur', + ['id' => 5, + 'libelle' => 'Delannoy Jean', + 'thumbnail_url' => 'http://wp/delannoy.jpg']); + + $this->fixture('Class_CodifAuteurFonction', + ['id' => 635, + 'libelle' => 'Programmeur informatique']); + + $this->fixture('Class_CodifAuteurFonction', + ['id' => '370', + 'libelle' => 'Réalisateur']); + } +} + + + + +class AuthorWidgetActionRefreshThumbnailsTest extends AuthorWidgetOnPageTestCase { + public function setUp() { + parent::setUp(); + + $mock_sql = $this->mock() + ->whenCalled('fetchAll') + ->answers([[9, 'A2408 M6 A4']]); + Zend_Registry::set('sql', $mock_sql); + Class_CosmoVar::newInstanceWithId('url_services')->setValeur('http://cache.org'); + Class_WebService_AllServices::setHttpClient($http_client = $this->mock()); + + $http_client + ->whenCalled('open_url') + ->answers(json_encode(['statut_recherche' => 2, + 'erreur' => '', + 'vignette' => 'http://wp/marcus.jpg'])); + + $this->onLoaderOfModel('Class_Notice') + ->whenCalled('getNoticesFromPreferences') + ->answers(Class_Notice::findAll()); + + $this->dispatch('/admin/widget/widget-action/named/refresh/id_module/1/id_profil/2'); + } + + + /** @test */ + public function withIdModuleOneIdProfilTwoShouldSetThumbnailForMarcusMiller() { + $this->assertEquals('http://wp/marcus.jpg', + Class_CodifAuteur::find(4)->getThumbnailUrl()); + } + + + /** @test */ + public function answerShouldRedirectToReferrer() { + $this->assertRedirect(); + } +} + + + + +class AuthorWidgetActionRefreshThumbnailsWithWrongParamsTest extends AuthorWidgetOnPageTestCase { + public function errors() { + return [ + ['id_module/1/id_profil/66655', + [404, 'Profil inexistant']], + + ['id_module/134245/id_profil/2', + [404, 'Boite inexistante']], + ]; + } + + + /** + * @dataProvider errors + * @test + */ + public function withWrongIdProfilShouldAnswer404($url, $expected) { + try { + $this->dispatch('/admin/widget/widget-action/named/refresh/' . $url); + } catch(Zend_Controller_Action_Exception $e) { + $this->assertEquals($expected, + [$e->getCode(), $e->getMessage()]); + return; + } + $this->fail('should raise error 404 not found'); + } +} + + + + +class AuthorWidgetOnPageTest extends AuthorWidgetOnPageTestCase { + public function setUp() { + parent::setUp(); + + + $this->onLoaderOfModel('Class_Notice') + ->whenCalled('getNoticesFromPreferences') + ->willDo(function($preferences) + { + $this->assertEquals(3, $preferences['id_panier']); + $this->assertEquals(10, $preferences['authors_count']); + $this->assertEquals(Class_Systeme_ModulesAccueil_Authors::AUTHORS_SELECTION_MODE_ALL, + $preferences['authors_selection_mode']); + return Class_Notice::findAll(); + }); + + $this->dispatch('/'); + } + + + /** @test */ + public function pageShouldContainsWidgetAuthorWithH1MesAuteurs() { + $this->assertXPathContentContains('//div[@class="boite authors"]//div[@class="titre"]//h1', + 'Mes auteurs'); + } + + + /** @test */ + public function authorsWidgetShouldContainsLinkWithImageHosseinDotJpg() { + $this->assertXPath('//div[@class="boite authors"]//div[@class="author"]//a[contains(@href, "author/view/id/3")][@title="En savoir plus sur Robert Hossein"]//img[@src="http://wp/hossein.jpg"]'); + } + + + /** @test */ + public function numberOfAuthorsShouldBeTwo() { + $this->assertXPathCount('//div[@class="boite authors"]//div[@class="author"]', + 2); + } + + + /** @test */ + public function widgetConfigurationShouldContainsButtonToRefreshThumbnails() { + $this->assertXPath('//div[@class="configuration_module"]//a[contains(@href, "/admin/widget/widget-action/named/refresh/id_module/1/id_profil/2")]'); + } + + + /** @test */ + public function pageShouldBeHTML5Valid() { + $this->assertHTML5(); + } + + + /** @test */ + public function pageShouldBeAccessible() { + $this->assertAccessible(); + } +} + + + + +class AuthorWidgetOnPageWithMainAuthorSelectionModeTest extends AuthorWidgetOnPageTestCase { + public function setUp() { + parent::setUp(); + + Class_Profil::find(2) + ->setCfgAccueil(['modules' => ['1' => ['division' => '2', + 'type_module' => 'AUTHORS', + 'preferences' => ['titre' => 'Une sélection', + 'op_largeur_img' => '50', + 'authors_selection_mode' => Class_Systeme_ModulesAccueil_Authors::AUTHORS_SELECTION_MODE_MAIN, + 'id_catalogue' => 5]]]]); + + + $this->onLoaderOfModel('Class_Notice') + ->whenCalled('getNoticesFromPreferences') + ->willDo(function($preferences) + { + $this->assertEquals(5, $preferences['id_catalogue']); + $this->assertEquals(Class_Systeme_ModulesAccueil_Authors::AUTHORS_SELECTION_MODE_MAIN, + $preferences['authors_selection_mode']); + return Class_Notice::findAll(); + }); + + $this->dispatch('/'); + } + + + /** @test */ + public function numberOfAuthorsShouldBeOne() { + $this->assertXPathCount('//div[@class="boite authors"]//div[@class="author"]', + 1); + } + + + /** @test */ + public function authorsWidgetShouldContainsLinkWithImageHugoDotJpg() { + $this->assertXPath('//div[@class="boite authors"]//div[@class="author"]//a[contains(@href, "author/view/id/2408")][@title="En savoir plus sur Victor Hugo"]//img[@src="http://wp/hugo.jpg"][@width="50"]'); + } + + + /** @test */ + public function divAuthorsWallShouldHaveStyleColumnWidth50px() { + $this->assertXPath('//div[@class="authors_wall"][@style="column-width:50px"]'); + } +} + + + + +class AuthorWidgetOnPageFilteredByResponsibilityTest extends AuthorWidgetOnPageTestCase { + public function setUp() { + parent::setUp(); + + Class_Profil::find(2) + ->setCfgAccueil(['modules' => ['1' => ['division' => '2', + 'type_module' => 'AUTHORS', + 'preferences' => ['titre' => 'Une sélection', + 'op_largeur_img' => '50', + 'authors_selection_mode' => Class_Systeme_ModulesAccueil_Authors::AUTHORS_SELECTION_MODE_RESPONSIBILITIES, + 'responsibilities' => '230;370;', + 'id_catalogue' => 5]]]]); + + + $this->onLoaderOfModel('Class_Notice') + ->whenCalled('getNoticesFromPreferences') + ->answers(Class_Notice::findAll()); + + $this->onLoaderOfModel('Class_CodifAuteur') + ->whenCalled('findByLastNameFirstName') + ->with('Delannoy', 'Jean') + ->answers(Class_CodifAuteur::find(5)); + + $this->dispatch('/'); + } + + + /** @test */ + public function numberOfAuthorsShouldBeOne() { + $this->assertXPathCount('//div[@class="boite authors"]//div[@class="author"]', + 1); + } + + + /** @test */ + public function authorsWidgetShouldContainsLinkWithImageDelannoyJpg() { + $this->assertXPath('//a[contains(@href, "author/view/id/5")][@title="En savoir plus sur Delannoy Jean"]//img[@src="http://wp/delannoy.jpg"]'); + } +} + + + + +class AuthorWidgetOnPageLimitOneTest extends AuthorWidgetOnPageTestCase { + public function setUp() { + parent::setUp(); + + Class_Profil::find(2) + ->setCfgAccueil(['modules' => ['1' => ['division' => '2', + 'type_module' => 'AUTHORS', + 'preferences' => ['titre' => 'Une sélection', + 'authors_count' => 1, + 'id_catalogue' => 5]]]]); + + + $this->onLoaderOfModel('Class_Notice') + ->whenCalled('getNoticesFromPreferences') + ->willDo(function($preferences) + { + $this->assertEquals(1, $preferences['authors_count']); + return Class_Notice::findAll(); + }); + + $this->dispatch('/'); + } + + + /** @test */ + public function numberOfAuthorsShouldBeOne() { + $this->assertXPathCount('//div[@class="boite authors"]//div[@class="author"]', + 1); + } + + + /** @test */ + public function authorsWidgetShouldContainsLinkWithImageHugoDotJpg() { + $this->assertXPath('//div[@class="boite authors"]//div[@class="author"]//a[contains(@href, "author/view/id/2408")][@title="En savoir plus sur Victor Hugo"]//img[@src="http://wp/hugo.jpg"]'); + } +} + + + + +class AuthorWidgetConfigurationTest extends AuthorWidgetOnPageTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/admin/widget/edit-widget/id/1/id_profil/2'); + } + + + /** @test */ + public function formShouldContainsInputForTitre() { + $this->assertXPath('//input[@name="titre"][@value="Mes auteurs"]', + $this->_response->getBody()); + } + + + /** @test **/ + public function formShouldContainsHiddenInputWithIdCatalogue() { + $this->assertXPath('//input[@type="hidden"][@id="id_catalogue"]'); + } + + + /** @test **/ + public function formShouldContainsHiddenInputWithIdPanierValueThree() { + $this->assertXPath('//input[@type="hidden"][@id="id_panier"][@value="3"]'); + } + + + /** @test **/ + public function formShouldContainsInputAuthorsCountValueTen() { + $this->assertXPath('//input[@type="number"][@name="authors_count"][@value="10"][@min="1"][@max="200"]'); + } + + + /** @test **/ + public function formShouldContainsInputSliderForOpLargeurImg() { + $this->assertXPath('//input[@name="op_largeur_img"]'); + $this->assertXPathContentContains('//script', '$("#op_largeur_img-slider").slider'); + } + + + /** @test */ + public function formShouldContainsRadioButtonForAuthorsSelectionModeMain() { + $this->assertXPath('//input[@type="radio"][@name="authors_selection_mode"][@value="main"][not(@checked)]'); + } + + + /** @test */ + public function formShouldContainsCheckedRadioButtonForAuthorsSelectionModeAll() { + $this->assertXPath('//input[@type="radio"][@name="authors_selection_mode"][@value="all"][@checked]'); + } +} + + + + +class AuthorWidgetConfigurationWithDomainTest extends AuthorWidgetOnPageTestCase { + public function setUp() { + parent::setUp(); + Class_Profil::find(2) + ->setCfgAccueil(['modules' => ['1' => ['division' => '2', + 'type_module' => 'AUTHORS', + 'preferences' => ['titre' => 'Une sélection', + 'id_catalogue' => 5]]]]) + ->save(); + + $this->dispatch('/admin/widget/edit-widget/id/1/id_profil/2'); + } + + + /** @test */ + public function formShouldContainsInputForTitreWithVlueUneSelection() { + $this->assertXPath('//input[@name="titre"][@value="Une sélection"]'); + } + + + /** @test **/ + public function formShouldContainsHiddenInputWithIdCategorieValueFive() { + $this->assertXPath('//input[@type="hidden"][@id="id_catalogue"][@value="5"]'); + } +} + + + + +class AuthorWidgetConfigurationPostTest extends AuthorWidgetOnPageTestCase { + protected $_saved_settings; + + public function setUp() { + parent::setUp(); + $this->postDispatch('/admin/widget/edit-widget/id/1/id_profil/2', + ['id_panier' => '5', + 'titre' => 'Des gens']); + Class_Profil::clearCache(); + $this->_saved_settings = Class_Profil::find(2) + ->getCfgAccueilAsArray()['modules'][1]; + } + + + /** @test **/ + public function shouldRedirect() { + $this->assertRedirect(); + } + + + /** @test */ + public function titleShouldBeDesGens() { + $this->assertEquals('Des gens', $this->_saved_settings['preferences']['titre']); + } + + + /** @test */ + public function idPanierShouldBeFive() { + $this->assertEquals('5', $this->_saved_settings['preferences']['id_panier']); + } +} + + + + +class AuthorWidgetResponsibilitiesInputSuggestTest extends AuthorWidgetOnPageTestCase { + /** @test */ + public function onSearchTermProShouldRetunProgrammeurInformatique() { + $this->onLoaderOfModel('Class_CodifAuteurFonction') + ->whenCalled('findAllBy') + ->with(['where' => 'libelle like "Pro%"', + 'order' => 'libelle']) + ->answers([Class_CodifAuteurFonction::find(635)]); + + $this->dispatch('/admin/ajax/listesuggestion?type_autorite=responsibility&id_champ=responsibilities&mode=1&valeur=Pro'); + + $this->assertEquals('<div class="tag_liste" clef="635" onclick="selectSuggest(\'responsibilities\',this)">Programmeur informatique</div>', + $this->_response->getBody()); + } +} diff --git a/tests/scenarios/AuthorPage/notre_dame.marc b/tests/scenarios/AuthorPage/notre_dame.marc new file mode 100644 index 0000000000000000000000000000000000000000..aab37b06f3e73861df5f10d19f6acac7a28ec1f2 --- /dev/null +++ b/tests/scenarios/AuthorPage/notre_dame.marc @@ -0,0 +1 @@ +01365nam0 2200253 450 001000700000100001300007200002400020210006200044215009600106300002600202330029900228700003800527702018000565702004000745702005500785702002900840702003300869702002900902702002600931702002600957702002900983702008201012801001701094256387 a201105051 aNotre-Dame de Paris a[Issy-les-Moulineaux]cStudioCanal vidéo éd.dcop. 2005 a1 DVD vidéo monoface double couche zone 2, 1h58 min.c. 2.35, 16/9 comp. 4/3, coul. (PAL), aPays : France (1956). aDans le Paris médiéval, la belle danseuse Esméralda déchaine les passions. Au milieu des mendiants et des truands de la cour des Miracles, le drame se noue peu à peu entre Phoebus, le capitaine des gardes dont elle est amoureuse, le monstrueux Quasimodo et l'inquiétant alchimiste Frollo. 1aDelannoybJean40006Réalisateur 1aHugobVictorf1802-188531190796640106Adaptateur8Hugo, Victor-Marie (1802-1885)8Hugo, Vittor (1802-1885)8Hugo, Vittorio (1802-1885)8Yu guo (1802-1885)8Yuguo (1802-1885) 1aAurenchebJean40006Dialogues avec 1aPrévertbJacques3OPS117832940006Dialogues avec 1aAuricbGeorges40006230 1aLollobrigidabGina48006005 1aQuinnbAnthony48006005 1aDanetbJean48006005 1aCunybAlain48006005 1aHirschbRobert48006005 1aClaybPhilippef1927-2007311935067480060058Mathevet, Philippe (1927-2007) 2aFrc20150404 \ No newline at end of file