From 18e0974e92d985ecdb6556f79fe8f843d3026e9d Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Wed, 20 Feb 2019 18:18:02 +0100 Subject: [PATCH] dev #64573 wip on record view --- .../opac/controllers/NoticeajaxController.php | 11 ++ .../opac/controllers/RecordController.php | 12 ++ .../opac/views/scripts/record/author.phtml | 2 + .../views/scripts/record/description.phtml | 2 + .../opac/views/scripts/record/related.phtml | 2 + .../opac/views/scripts/record/reviews.phtml | 2 + library/Class/CodifAuteur/Description.php | 72 +++++++++- .../Intonation/Assets/css/intonation.css | 14 +- .../templates/Intonation/Library/Settings.php | 2 + .../View/Author/EditBiographyUrl.php | 31 +++++ .../View/Author/RenderCollaborations.php | 62 +++++++++ .../Intonation/View/Author/RenderFacets.php | 43 ++++++ .../Intonation/View/Author/RenderRecords.php | 64 +++++++++ .../View/Author/RenderThumbnail.php | 37 +++++ .../View/Author/RenderWikipedia.php | 76 ++++++++++ .../View/Author/RenderYoutubeChan.php | 54 ++++++++ library/templates/Intonation/View/Gridify.php | 11 +- .../View/RenderAuthorDescription.php | 50 +++++++ .../templates/Intonation/View/RenderEmbed.php | 1 + .../View/RenderMultipleCarousel.php | 9 +- .../Intonation/View/RenderRecord.php | 8 +- .../Intonation/View/RenderRecord/Author.php | 37 +++++ .../View/RenderRecord/Description.php | 37 +++++ .../Intonation/View/RenderRecord/Related.php | 37 +++++ .../Intonation/View/RenderRecord/Reviews.php | 37 +++++ .../Intonation/View/RenderTracks.php | 40 +++--- tests/scenarios/Templates/TemplatesTest.php | 131 ++++++++++++++++++ 27 files changed, 843 insertions(+), 41 deletions(-) create mode 100644 application/modules/opac/views/scripts/record/author.phtml create mode 100644 application/modules/opac/views/scripts/record/description.phtml create mode 100644 application/modules/opac/views/scripts/record/related.phtml create mode 100644 application/modules/opac/views/scripts/record/reviews.phtml create mode 100644 library/templates/Intonation/View/Author/EditBiographyUrl.php create mode 100644 library/templates/Intonation/View/Author/RenderCollaborations.php create mode 100644 library/templates/Intonation/View/Author/RenderFacets.php create mode 100644 library/templates/Intonation/View/Author/RenderRecords.php create mode 100644 library/templates/Intonation/View/Author/RenderThumbnail.php create mode 100644 library/templates/Intonation/View/Author/RenderWikipedia.php create mode 100644 library/templates/Intonation/View/Author/RenderYoutubeChan.php create mode 100644 library/templates/Intonation/View/RenderAuthorDescription.php create mode 100644 library/templates/Intonation/View/RenderRecord/Author.php create mode 100644 library/templates/Intonation/View/RenderRecord/Description.php create mode 100644 library/templates/Intonation/View/RenderRecord/Related.php create mode 100644 library/templates/Intonation/View/RenderRecord/Reviews.php diff --git a/application/modules/opac/controllers/NoticeajaxController.php b/application/modules/opac/controllers/NoticeajaxController.php index 7635e9d7ed9..20e4df2e8f2 100644 --- a/application/modules/opac/controllers/NoticeajaxController.php +++ b/application/modules/opac/controllers/NoticeajaxController.php @@ -527,4 +527,15 @@ class NoticeAjaxController extends ZendAfi_Controller_Action { $this->_sendResponseWithScripts($this->view->renderTracks($tracks)); } + + + public function authorAction() { + session_write_close(); + + if (!$author = Class_CodifAuteur::findWithFullName($this->notice->getAuteurPrincipal())) + return $this->_sendResponse(''); + + $author_description = new Class_CodifAuteur_Description($author); + $this->_sendResponseWithScripts($this->view->renderAuthorDescription($author_description)); + } } \ No newline at end of file diff --git a/application/modules/opac/controllers/RecordController.php b/application/modules/opac/controllers/RecordController.php index 42b8b105e9b..ca5aa4fd02a 100644 --- a/application/modules/opac/controllers/RecordController.php +++ b/application/modules/opac/controllers/RecordController.php @@ -36,4 +36,16 @@ class RecordController extends ZendAfi_Controller_Action { public function mediaAction() {} + + + public function reviewsAction() {} + + + public function descriptionAction() {} + + + public function relatedAction() {} + + + public function authorAction() {} } diff --git a/application/modules/opac/views/scripts/record/author.phtml b/application/modules/opac/views/scripts/record/author.phtml new file mode 100644 index 00000000000..252a367591a --- /dev/null +++ b/application/modules/opac/views/scripts/record/author.phtml @@ -0,0 +1,2 @@ +<?php +echo $this->RenderRecord_Author($this->record); diff --git a/application/modules/opac/views/scripts/record/description.phtml b/application/modules/opac/views/scripts/record/description.phtml new file mode 100644 index 00000000000..3fb1fb46e44 --- /dev/null +++ b/application/modules/opac/views/scripts/record/description.phtml @@ -0,0 +1,2 @@ +<?php +echo $this->RenderRecord_Description($this->record); diff --git a/application/modules/opac/views/scripts/record/related.phtml b/application/modules/opac/views/scripts/record/related.phtml new file mode 100644 index 00000000000..9115ea507c7 --- /dev/null +++ b/application/modules/opac/views/scripts/record/related.phtml @@ -0,0 +1,2 @@ +<?php +echo $this->RenderRecord_Related($this->record); diff --git a/application/modules/opac/views/scripts/record/reviews.phtml b/application/modules/opac/views/scripts/record/reviews.phtml new file mode 100644 index 00000000000..d6a4d1107bb --- /dev/null +++ b/application/modules/opac/views/scripts/record/reviews.phtml @@ -0,0 +1,2 @@ +<?php +echo $this->RenderRecord_Reviews($this->record); diff --git a/library/Class/CodifAuteur/Description.php b/library/Class/CodifAuteur/Description.php index dc080df7f02..8758804c1cd 100644 --- a/library/Class/CodifAuteur/Description.php +++ b/library/Class/CodifAuteur/Description.php @@ -24,16 +24,23 @@ class Class_CodifAuteur_Description { use Trait_Translator; protected + $_biography, $_author, $_search_result, $_all_records, $_associated_authors; + public function __construct($author) { $this->_author = $author; } + public function getAuthor() { + return $this->_author; + } + + public function getId() { return $this->_author->getId(); } @@ -197,14 +204,24 @@ class Class_CodifAuteur_Description { protected function _fetchBiography($author, $all_records, $associated_authors) { + if ($this->_biography) + return $this->_biography; + if (!$all_records) - return ''; + return []; $args = ['auteur' => $author->getLibelle(), 'clef_oeuvre' => $all_records[0]->getClefOeuvre(), 'language' => Class_Profil::getCurrentProfil()->getLocale()]; - return Class_WebService_AllServices::runServiceAfiBiographie($args); + return $this->_biography = Class_WebService_AllServices::runServiceAfiBiographie($args); + } + + + public function fetchBiography() { + return new Class_Entity($this->_fetchBiography($this->_author, + $this->getRecords(), + $this->getAssociatedAuthors())); } @@ -264,5 +281,52 @@ class Class_CodifAuteur_Description { return $records_by_doctype; } -} -?> \ No newline at end of file + + + public function renderEditButtonOn($view) { + if (!$records = $this->getRecords()) + return ''; + + return $view->biographie_UpdateButton($this->getRecords()[0], + $this->getLabel()); + } + + + public function renderThumbnailOn($view) { + $data = new Class_Entity($this->_fetchBiography($this->_author, + $this->getRecords(), + $this->getAssociatedAuthors())); + return $data->getvignette() + ? $view->tag('img', + null, + ['src' => $data->getvignette(), + '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(); + + if (!$biography = $data->getbiographie()) + return ''; + + $biography = $this->_enrichBiographyWithRecords($biography, + $this->getRecords(), + $view); + + return $this->_enrichBiographyWithAuthorLinks($biography, + $this->getAssociatedAuthors(), + $view); + } +} \ No newline at end of file diff --git a/library/templates/Intonation/Assets/css/intonation.css b/library/templates/Intonation/Assets/css/intonation.css index 8fff34044b7..58a04d42b67 100644 --- a/library/templates/Intonation/Assets/css/intonation.css +++ b/library/templates/Intonation/Assets/css/intonation.css @@ -298,7 +298,7 @@ pre { margin-bottom: 0; } -.list-group-item { +[id*='resources'] .list-group-item { padding-left: 0; padding-right: 0; } @@ -415,4 +415,14 @@ label[for=note] ~ div label.multi-element-label + br { .blockquote-footer { color: inherit; -} \ No newline at end of file +} + +.biography_scroll { + position: relative; + max-height: 500px; + overflow-y: scroll; +} + +[class*='text-'] .btn-link { + color: inherit; +} diff --git a/library/templates/Intonation/Library/Settings.php b/library/templates/Intonation/Library/Settings.php index 96c32d92788..d5cdf4834c8 100644 --- a/library/templates/Intonation/Library/Settings.php +++ b/library/templates/Intonation/Library/Settings.php @@ -100,6 +100,7 @@ class Intonation_Library_Settings extends Intonation_System_Abstract { 'a class active' => '', 'a class nav-link' => '', 'a class card-link' => '', + 'a class list-group-item' => '', 'a class account-loans' => 'list-group-item-info', 'ul' => 'list-unstyled', 'div class success_notify' => 'alert-success', @@ -144,6 +145,7 @@ class Intonation_Library_Settings extends Intonation_System_Abstract { 'star' => 'class fas fa-star', 'star-empty' => 'class far fa-star', 'track' => 'class fas fa-music', + 'video' => 'class fas fa-video', ] ]; diff --git a/library/templates/Intonation/View/Author/EditBiographyUrl.php b/library/templates/Intonation/View/Author/EditBiographyUrl.php new file mode 100644 index 00000000000..a6c2933db40 --- /dev/null +++ b/library/templates/Intonation/View/Author/EditBiographyUrl.php @@ -0,0 +1,31 @@ +<?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 + */ + + +class Intonation_View_Author_EditBiographyUrl extends ZendAfi_View_Helper_BaseHelper { + public function Author_EditBiographyUrl($author) { + if (!$records = $author->getRecords()) + return ''; + + return $this->view->biographie_UpdateButton(array_shift($records), + $author->getLabel()); + } +} diff --git a/library/templates/Intonation/View/Author/RenderCollaborations.php b/library/templates/Intonation/View/Author/RenderCollaborations.php new file mode 100644 index 00000000000..18a24bf083f --- /dev/null +++ b/library/templates/Intonation/View/Author/RenderCollaborations.php @@ -0,0 +1,62 @@ +<?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 + */ + + +class Intonation_View_Author_RenderCollaborations extends ZendAfi_View_Helper_BaseHelper { + public function Author_RenderCollaborations($author) { + $callback = function ($collaboration) use ($author) { + return $this->_renderCollaboration($author, $collaboration); + }; + + + return $this->_tag('h3', $this->_('Auteurs associés')) + . $this->view->renderMultipleCarousel(new Storm_Collection($author->getAssociatedAuthors()), + $callback, + 20); + } + + + protected function _renderCollaboration($author_description, $collaboration) { + $author = $collaboration['author']; + $occurences = $collaboration['occurences']; + + $collaboration_link = $this->view->tagAnchor(Class_Url::assemble(['controller' => 'recherche', + 'action' => 'simple', + 'code_rebond' => $author_description->getFacetCode(), + 'facette' => $author->getFacetCode()]), + $this->_plural($occurences, + 'aucune collaboration', + '1 collaboration', + '%s collaborations', + $occurences), + ['class' => 'text-dark', + 'title' => sprintf('Voir les documents du fonds issus d\'une collaboration entre %s et %s', + $author_description->getLabel(), + $author->getLibelle())]); + return $this->_div(['class' => 'p-1 bg-primary rounded pl-3 ml-3 mb-3'], + $this->_tag('span', + (new Class_Notice_FieldAuthor($author))->renderOn($this->view), + ['class' => 'mr-3 text-white']) + . $this->_tag('span', + $collaboration_link, + ['class' => 'badge badge-light'])); + } +} diff --git a/library/templates/Intonation/View/Author/RenderFacets.php b/library/templates/Intonation/View/Author/RenderFacets.php new file mode 100644 index 00000000000..caf1425689b --- /dev/null +++ b/library/templates/Intonation/View/Author/RenderFacets.php @@ -0,0 +1,43 @@ +<?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 + */ + + +class Intonation_View_Author_RenderFacets extends ZendAfi_View_Helper_BaseHelper { + public function Author_RenderFacets($author) { + $badges = []; + + foreach ($author->getFacets() as $facet_code => $count) { + $facet_label = Class_Notice_Facette::find($facet_code)->getLibelleFacette(); + $badges [] = ['tag' => 'a', + 'url' => Class_Url::assemble(['controller' => 'recherche', + 'action' => 'simple', + 'code_rebond' => $author->getFacetCode(), + 'facette' => $facet_code]), + 'class' => 'primary', + 'text' => $facet_label, + 'title' => $this->_('Voir les documents de %s correspondants au terme %s', + $author->getLabel(), + $facet_label)]; + } + + return $this->view->renderBadges($badges); + } +} diff --git a/library/templates/Intonation/View/Author/RenderRecords.php b/library/templates/Intonation/View/Author/RenderRecords.php new file mode 100644 index 00000000000..444c275c332 --- /dev/null +++ b/library/templates/Intonation/View/Author/RenderRecords.php @@ -0,0 +1,64 @@ +<?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 + */ + + +class Intonation_View_Author_RenderRecords extends ZendAfi_View_Helper_BaseHelper { + public function Author_RenderRecords($author) { + $records_by_doctype = []; + foreach($author->getRecordsByDocType() as $doc_type_id => $records) + $records_by_doctype [] = $this->_renderRecord($author, + $doc_type_id, + $records); + + return $this->view->grid(implode($records_by_doctype), ['class' => 'records']); + } + + + protected function _renderRecord($author_description, $doc_type_id, $records) { + $type_doc = Class_TypeDoc::find($doc_type_id); + + $header = $this->_tag('h3', + $this->view->tagAnchor(Class_Url::assemble(['controller' => 'recherche', + 'action' => 'simple', + 'code_rebond' => $author_description->getFacetCode(), + 'facette' => $type_doc->getFacetCode()]), + ucfirst($type_doc->getLibelle()), + ['title' => $this->_('Afficher tous les documents de type %s pour %s', + $type_doc->getLibelle(), + $author_description->getLabel())] )); + + $elements = array_map(function($element) + { + return (new Intonation_Library_View_Wrapper_Record) + ->setView($this->view) + ->setModel($element); + }, $records); + + $elements = new Storm_Collection($elements); + + $records = $this->view->renderWall($elements, function($record) + { + return $this->view->cardifyWithOverlay($record); + }); + + return $this->_div(['class' => 'col-12'], $header . $records); + } +} diff --git a/library/templates/Intonation/View/Author/RenderThumbnail.php b/library/templates/Intonation/View/Author/RenderThumbnail.php new file mode 100644 index 00000000000..67d7d6fdaa3 --- /dev/null +++ b/library/templates/Intonation/View/Author/RenderThumbnail.php @@ -0,0 +1,37 @@ +<?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 + */ + + +class Intonation_View_Author_RenderThumbnail extends ZendAfi_View_Helper_BaseHelper { + public function Author_RenderThumbnail($author) { + $bio = $author->fetchBiography(); + + return $bio->getvignette() + ? $this->_div(['onclick' => '$(this).toggleClass(\'modal_image\');'], + $this->view->tagImg($bio->getvignette(), + ['class' => 'img-thumbnail', + 'title' => $this->_('Portrait de %s. Source: Wikipedia', + $author->getLabel()), + 'alt' => $this->_('%s. Source: Wikipedia', + $author->getLabel())])) + : ''; + } +} diff --git a/library/templates/Intonation/View/Author/RenderWikipedia.php b/library/templates/Intonation/View/Author/RenderWikipedia.php new file mode 100644 index 00000000000..2089d3bb0a1 --- /dev/null +++ b/library/templates/Intonation/View/Author/RenderWikipedia.php @@ -0,0 +1,76 @@ +<?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 + */ + + +class Intonation_View_Author_RenderWikipedia extends ZendAfi_View_Helper_BaseHelper { + public function Author_RenderWikipedia($author) { + if (!$bio = $author->renderWikipediaOn($this->view)) + return ''; + + $dom = new DOMDocument(); + + try { + $dom->loadHTML(mb_convert_encoding($bio, 'HTML-ENTITIES', 'UTF-8')); + } catch (Exception $e) { + return $bio; + } + + $h2_ids = []; + foreach ($dom->getElementsByTagName('h2') as $h2) { + $id = 'nav_anchor_' . uniqid(); + $h2_ids [$id] = $h2->nodeValue; + $h2->setAttribute('id', $id); + } + + try { + $edited_bio = $dom->saveHTML(); + } catch (Exception $e) { + return $bio; + } + + if (!$h2_ids) + return $bio; + + $anchors = []; + foreach($h2_ids as $id => $text) + $anchors [] = $this->_tag('a', + $text, + ['href' => '#' . $id, + 'class' => 'list-group-item list-group-item-action']); + + $nav_id = 'nav_id_' . uniqid(); + $nav = $this->_div(['id' => $nav_id, + 'class' => 'list-group mr-3'], + implode($anchors)); + + Class_ScriptLoader::getInstance()->addJQueryReady('$(".biography_scroll").scrollspy({target: "#' . $nav_id . '"});'); + + return $this->view->grid($this->_div(['class' => 'col-4'], + $nav) + . $this->_div(['class' => 'col-8'], + $this->_div(['class' => 'biography_scroll'], + $edited_bio)) + . $this->_div(['class' => 'col-12'], + $this->_tag('p', + $this->_('Source: Wikipedia'), + ['class' => 'm-0 mt-1 blockquote-footer text-right']))); + } +} diff --git a/library/templates/Intonation/View/Author/RenderYoutubeChan.php b/library/templates/Intonation/View/Author/RenderYoutubeChan.php new file mode 100644 index 00000000000..62c12988cb2 --- /dev/null +++ b/library/templates/Intonation/View/Author/RenderYoutubeChan.php @@ -0,0 +1,54 @@ +<?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 + */ + + +class Intonation_View_Author_RenderYoutubeChan extends ZendAfi_View_Helper_BaseHelper { + public function Author_RenderYoutubeChan($author) { + if (!$id = $author->getYoutubeChannelId()) + return ''; + + $items = []; + foreach((new Class_WebService_Youtube()) + ->videosOfChannel($id) as $video) + $items[] = new Class_Entity(['Title' => $video->getTitle(), + 'Player' => $this->view->renderEmbed($this->_('Youtube'), + $video->getEmbedUrl())]); + + $callback = function($video) { + return + $this->_div(['class' => 'card bg-info text-white shadow'], + $this->_div(['class' => 'card-body'], + $this->_div(['class' => 'card-title'], + $this->_tag('h3', + Class_Template::current()->getIco($this->view, + 'video', + 'utils') + . $video->getTitle())) + . $this->_div(['class' => 'text-center'], + $video->getPlayer()))); + }; + + return + $this->_tag('h3', $this->_('Chaîne Youtube')) + . $this->view->renderCarousel(new Storm_Collection($items), + $callback); + } +} diff --git a/library/templates/Intonation/View/Gridify.php b/library/templates/Intonation/View/Gridify.php index 9eff029112f..2b11154130a 100644 --- a/library/templates/Intonation/View/Gridify.php +++ b/library/templates/Intonation/View/Gridify.php @@ -22,18 +22,15 @@ class Intonation_View_Gridify extends ZendAfi_View_Helper_BaseHelper { - protected $_number_of_items_by_row = 3; - - - public function gridify($elements) { - $number_of_rows = ceil(count($elements) / $this->_number_of_items_by_row); + public function gridify($elements, $columns = 3) { + $number_of_rows = ceil(count($elements) / $columns); $rows = []; for ($i = 0; $i < $number_of_rows; $i++) { $items = array_slice($elements, - $i * $this->_number_of_items_by_row, - $this->_number_of_items_by_row); + $i * $columns, + $columns); $rows [$i] = $this->_tag('div', implode($items), diff --git a/library/templates/Intonation/View/RenderAuthorDescription.php b/library/templates/Intonation/View/RenderAuthorDescription.php new file mode 100644 index 00000000000..e066e9c0cbd --- /dev/null +++ b/library/templates/Intonation/View/RenderAuthorDescription.php @@ -0,0 +1,50 @@ +<?php +/** + * Copyright (c) 2012-2018, 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 Intonation_View_RenderAuthorDescription extends ZendAfi_View_Helper_BaseHelper { + + public function renderAuthorDescription($description) { + $html = [ + $this->_div(['class' => 'col-3'], + $this->view->Author_RenderThumbnail($description)), + + $this->_div(['class' => 'col-9 col-xl-5 pl-3'], + $this->view->Author_RenderFacets($description)), + + $this->_div(['class' => 'col-12 col-xl-4 text-right'], + $this->view->Author_EditBiographyUrl($description)), + + $this->_div(['class' => 'col-12 mt-3'], + $this->view->Author_RenderWikipedia($description)), + + $this->_div(['class' => 'col-12 mt-3'], + $this->view->Author_RenderCollaborations($description)), + + $this->_div(['class' => 'col-12 mt-3'], + $this->view->Author_RenderRecords($description)), + + $this->_div(['class' => 'col-12 mt-3'], + $this->view->Author_RenderYoutubeChan($description)), + ]; + + return $this->view->grid(implode($html)); + } +} \ No newline at end of file diff --git a/library/templates/Intonation/View/RenderEmbed.php b/library/templates/Intonation/View/RenderEmbed.php index 0bd45182372..a91a7400011 100644 --- a/library/templates/Intonation/View/RenderEmbed.php +++ b/library/templates/Intonation/View/RenderEmbed.php @@ -29,6 +29,7 @@ class Intonation_View_RenderEmbed extends ZendAfi_View_Helper_BaseHelper { ['src' => $url, 'crossorigin' => 1, 'allowfullscreen' => 1, + 'allow' => 'accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture', 'class' => 'embed-responsive-item'])) . $this->_tag('p', $source, diff --git a/library/templates/Intonation/View/RenderMultipleCarousel.php b/library/templates/Intonation/View/RenderMultipleCarousel.php index 6b71d1a0db0..94390ac40d6 100644 --- a/library/templates/Intonation/View/RenderMultipleCarousel.php +++ b/library/templates/Intonation/View/RenderMultipleCarousel.php @@ -22,13 +22,16 @@ class Intonation_View_RenderMultipleCarousel extends Intonation_View_Abstract_Carousel { - public function renderMultipleCarousel($collection, $callback) { + protected $_columns; + + public function renderMultipleCarousel($collection, $callback, $columns = 3) { + $this->_columns = $columns; return $this->_renderCarousel($collection, $callback); } protected function _numberOfPages($collection) { - return ceil($collection->count() / 3); + return ceil($collection->count() / $this->_columns); } @@ -49,7 +52,7 @@ class Intonation_View_RenderMultipleCarousel extends Intonation_View_Abstract_Ca return $html; })); - $grid = $this->view->gridify($cards); + $grid = $this->view->gridify($cards, $this->_columns); return parent::_carouselInner($grid, $id, function ($element) { return $element; diff --git a/library/templates/Intonation/View/RenderRecord.php b/library/templates/Intonation/View/RenderRecord.php index dfa9382e503..c2e869ac87e 100644 --- a/library/templates/Intonation/View/RenderRecord.php +++ b/library/templates/Intonation/View/RenderRecord.php @@ -66,7 +66,7 @@ class Intonation_View_RenderRecord extends ZendAfi_View_Helper_BaseHelper { $this->_renderMedia(), $this->_renderReviews(), $this->_renderDetails(), - $this->_renderCollection(), + $this->_renderRelated(), $this->_renderAuthor()]; } @@ -125,7 +125,7 @@ class Intonation_View_RenderRecord extends ZendAfi_View_Helper_BaseHelper { } - protected function _renderCollection() { + protected function _renderRelated() { return $this->_renderBloc($this->_('Voir Aussi'), $this->_grid($this->_renderAjaxBloc('series') . $this->_renderAjaxBloc('frbr') @@ -136,7 +136,7 @@ class Intonation_View_RenderRecord extends ZendAfi_View_Helper_BaseHelper { protected function _renderAuthor() { return $this->_renderBloc($this->_('Auteur principal'), - $this->_renderAjaxBloc('biographie')); + $this->_renderAjaxBloc('author')); } @@ -249,7 +249,7 @@ class Intonation_View_RenderRecord extends ZendAfi_View_Helper_BaseHelper { 'action' => $action, 'id' => $this->_record->getId()]))); return $this->_div(['id' => $id, - 'class' => 'col-12 mb-3'], ''); + 'class' => 'col-12 mb-3 p-0'], ''); } diff --git a/library/templates/Intonation/View/RenderRecord/Author.php b/library/templates/Intonation/View/RenderRecord/Author.php new file mode 100644 index 00000000000..f653643de99 --- /dev/null +++ b/library/templates/Intonation/View/RenderRecord/Author.php @@ -0,0 +1,37 @@ +<?php +/** + * Copyright (c) 2012-2018, 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 Intonation_View_RenderRecord_Author extends Intonation_View_RenderRecord { + public function RenderRecord_Author($record) { + return parent::renderRecord($record); + } + + + protected function _getSubtitle() { + return $this->_(' : Auteur principal'); + } + + + protected function _getContentBlocs() { + return [$this->_renderAuthor()]; + } +} \ No newline at end of file diff --git a/library/templates/Intonation/View/RenderRecord/Description.php b/library/templates/Intonation/View/RenderRecord/Description.php new file mode 100644 index 00000000000..443631081a2 --- /dev/null +++ b/library/templates/Intonation/View/RenderRecord/Description.php @@ -0,0 +1,37 @@ +<?php +/** + * Copyright (c) 2012-2018, 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 Intonation_View_RenderRecord_Description extends Intonation_View_RenderRecord { + public function RenderRecord_Description($record) { + return parent::renderRecord($record); + } + + + protected function _getSubtitle() { + return $this->_(' : Description'); + } + + + protected function _getContentBlocs() { + return [$this->_renderDetails()]; + } +} \ No newline at end of file diff --git a/library/templates/Intonation/View/RenderRecord/Related.php b/library/templates/Intonation/View/RenderRecord/Related.php new file mode 100644 index 00000000000..08d0ac07da8 --- /dev/null +++ b/library/templates/Intonation/View/RenderRecord/Related.php @@ -0,0 +1,37 @@ +<?php +/** + * Copyright (c) 2012-2018, 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 Intonation_View_RenderRecord_Related extends Intonation_View_RenderRecord { + public function RenderRecord_Related($record) { + return parent::renderRecord($record); + } + + + protected function _getSubtitle() { + return $this->_(' : Voir aussi'); + } + + + protected function _getContentBlocs() { + return [$this->_renderRelated()]; + } +} \ No newline at end of file diff --git a/library/templates/Intonation/View/RenderRecord/Reviews.php b/library/templates/Intonation/View/RenderRecord/Reviews.php new file mode 100644 index 00000000000..a2b341f85e7 --- /dev/null +++ b/library/templates/Intonation/View/RenderRecord/Reviews.php @@ -0,0 +1,37 @@ +<?php +/** + * Copyright (c) 2012-2018, 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 Intonation_View_RenderRecord_Reviews extends Intonation_View_RenderRecord { + public function RenderRecord_Reviews($record) { + return parent::renderRecord($record); + } + + + protected function _getSubtitle() { + return $this->_(' : Avis'); + } + + + protected function _getContentBlocs() { + return [$this->_renderReviews()]; + } +} \ No newline at end of file diff --git a/library/templates/Intonation/View/RenderTracks.php b/library/templates/Intonation/View/RenderTracks.php index d27cf648069..4376a25ebd7 100644 --- a/library/templates/Intonation/View/RenderTracks.php +++ b/library/templates/Intonation/View/RenderTracks.php @@ -26,21 +26,19 @@ class Intonation_View_RenderTracks extends ZendAfi_View_Helper_BaseHelper { return ''; return $this->view->renderCarousel($tracks, function($track) - { - return - $this->_div(['class' => 'card bg-info text-white shadow'], - $this->_div(['class' => 'card-body'], - $this->_div(['class' => 'card-title'], - $this->_tag('h3', - Class_Template::current()->getIco($this->view, - 'track', - 'utils') - . $track->getTitle())) - . $this->_div(['class' => 'text-center'], - $this->_getPlayer($track)))); - - return ''; - }); + { + return + $this->_div(['class' => 'card bg-info text-white shadow'], + $this->_div(['class' => 'card-body'], + $this->_div(['class' => 'card-title'], + $this->_tag('h3', + Class_Template::current()->getIco($this->view, + 'track', + 'utils') + . $track->getTitle())) + . $this->_div(['class' => 'text-center'], + $this->_getPlayer($track)))); + }); } @@ -49,12 +47,12 @@ class Intonation_View_RenderTracks extends ZendAfi_View_Helper_BaseHelper { return false === strpos($url, 'youtube') ? ($this->_tag('audio', - '', - ['class' => '', - 'src' => $url, - 'preload' => 'auto', - 'onplaying' => "$('audio, video').not($(this)).trigger('pause');", - 'controls' => 'true']) + '', + ['class' => '', + 'src' => $url, + 'preload' => 'auto', + 'onplaying' => "$('audio, video').not($(this)).trigger('pause');", + 'controls' => 'true']) . $this->_tag('p', $track->getSource(), diff --git a/tests/scenarios/Templates/TemplatesTest.php b/tests/scenarios/Templates/TemplatesTest.php index fc117429c20..8494682df0e 100644 --- a/tests/scenarios/Templates/TemplatesTest.php +++ b/tests/scenarios/Templates/TemplatesTest.php @@ -2217,3 +2217,134 @@ class TemplatesDispatchNoticeAjaxTracksTest extends TemplatesIntonationTestCase $this->assertXPath('//div//audio'); } } + + + +class TemplatesRecordReviewsActionTest extends TemplatesIntonationTestCase { + protected $_storm_default_to_volatile = true; + + + public function setUp() { + parent::setUp(); + + $this->fixture('Class_AvisNotice', + ['id' => 4, + 'id_notice' => 2, + 'clef_oeuvre' => 'PSYKO', + 'note' => '4', + 'entete' => 'Le Roi', + 'avis' => 'Le Roi des cons sur son throne']); + + $this->fixture('Class_AvisNotice', + ['id' => 5, + 'id_notice' => 2, + 'clef_oeuvre' => 'PSYKO', + 'note' => '4', + 'entete' => 'La Reine', + 'avis' => 'La Reine des connes sur son throne']); + + $this->fixture('Class_Notice', + ['id' => 2, + 'clef_oeuvre' => 'PSYKO', + ]); + + + $this->dispatch('/record/reviews/id/2/id_profil/72'); + } + + + /** @test */ + public function leRoiShouldBePresent() { + $this->assertXPathContentContains('//div', 'Le Roi'); + } +} + + + +class TemplatesDispatchRecordDescriptionTest extends TemplatesIntonationTestCase { + + /** @test */ + public function shouldRenderDescription() { + $record = $this->fixture('Class_Notice', + ['id' => 456, + 'type_doc' => 8, + 'clef_oeuvre' => 'THE BOOK OF SOULS', + 'facettes' => 'G13 M12']); + + $this->dispatch('/record/description/id/456/id_profil/72'); + $this->assertXPath('//dl'); + } +} + + + +class TemplatesDispatchRecordRelatedTest extends TemplatesIntonationTestCase { + + /** @test */ + public function shouldRenderDescription() { + $record = $this->fixture('Class_Notice', + ['id' => 456, + 'type_doc' => 8, + 'clef_oeuvre' => 'THE BOOK OF SOULS', + 'facettes' => 'G13 M12']); + + $this->dispatch('/record/related/id/456/id_profil/72'); + $this->assertXPath('//div'); + } +} + + + +class TemplatesDispatchRecordAuthorTest extends TemplatesIntonationTestCase { + + /** @test */ + public function shouldDisplayAuthor() { + $unimarc = (new Class_NoticeUnimarc_Fluent) + ->zoneWithContent('001', '12345') + + ->zoneWithChildren('200', ['f' => 'Iron Maiden']) + + ->zoneWithChildren('461', ['t' => 'The book of souls']); + + + $record = $this->fixture('Class_Notice', + ['id' => 456, + 'unimarc' => $unimarc->render(), + 'type_doc' => 8, + 'clef_oeuvre' => 'THE BOOK OF SOULS', + 'facettes' => 'G13 M12']); + + $this->dispatch('/record/author/id/456/id_profil/72'); + $this->assertXPath('//div'); + } +} + + + +class TemplatesDispatchNoticeajaxAuthorActionTest extends TemplatesIntonationTestCase { + + /** @test */ + public function shouldDisplayAuthor() { + $unimarc = (new Class_NoticeUnimarc_Fluent) + ->zoneWithContent('001', '12345') + + ->zoneWithChildren('200', ['f' => 'Iron Maiden']) + + ->zoneWithChildren('461', ['t' => 'The book of souls']); + + $record = $this->fixture('Class_Notice', + ['id' => 456, + 'unimarc' => $unimarc->render(), + 'type_doc' => 8, + 'clef_oeuvre' => 'THE BOOK OF SOULS', + 'facettes' => 'G13 M12']); + + $this->fixture('Class_CodifAuteur', + ['id' => 10, + 'libelle' => 'Iron Maiden', + 'formes' => 'IRONxMAIDEN']); + + $this->dispatch('/noticeajax/author/id/456/id_profil/72'); + $this->assertXPath('//div'); + } +} -- GitLab