From 31e135ff6e7845038f1fb9ab64df6035855fc33d Mon Sep 17 00:00:00 2001 From: llaffont <llaffont@afi-sa.fr> Date: Fri, 6 Nov 2015 16:37:47 +0100 Subject: [PATCH] rel #32494 album website module --- .../admin/views/scripts/sito/create.phtml | 3 ++ .../bib-numerique/view-categorie.phtml | 18 ++----- .../Accueil/BibNumerique/TreeRenderer.php | 19 +++---- .../View/Helper/RenderAlbumPreview.php | 49 +++++++++++++++++++ .../Helper/RenderAlbumPreview/WebSite.php | 49 +++++++++++++++++++ .../RechercheControllerAlbumWebSiteTest.php | 31 ++++++++++++ 6 files changed, 146 insertions(+), 23 deletions(-) create mode 100644 application/modules/admin/views/scripts/sito/create.phtml create mode 100644 library/ZendAfi/View/Helper/RenderAlbumPreview.php create mode 100644 library/ZendAfi/View/Helper/RenderAlbumPreview/WebSite.php diff --git a/application/modules/admin/views/scripts/sito/create.phtml b/application/modules/admin/views/scripts/sito/create.phtml new file mode 100644 index 00000000000..df1c0246027 --- /dev/null +++ b/application/modules/admin/views/scripts/sito/create.phtml @@ -0,0 +1,3 @@ +<?php +echo $this->renderForm($this->import_form); +?> diff --git a/application/modules/opac/views/scripts/bib-numerique/view-categorie.phtml b/application/modules/opac/views/scripts/bib-numerique/view-categorie.phtml index d0fee9d783f..026a117f789 100644 --- a/application/modules/opac/views/scripts/bib-numerique/view-categorie.phtml +++ b/application/modules/opac/views/scripts/bib-numerique/view-categorie.phtml @@ -1,5 +1,5 @@ <?php $this->openBoite($this->categorie->getLibelle()); ?> -<?php echo $this->partial('bib-numerique/_breadcrum.phtml', +<?php echo $this->partial('bib-numerique/_breadcrum.phtml', array('parents' => $this->categorie->getHierarchy(), 'action' => 'view-categorie'));?> <?php if (0 < count($this->subCategories)) { ?> @@ -7,7 +7,7 @@ <h3><?php echo $this->_('Catégorie(s)');?></h3> <ul> <?php foreach ($this->subCategories as $categorie) { ?> - <li><?php echo $this->tagAnchor($this->url(array('action' => 'view-categorie', + <li><?php echo $this->tagAnchor($this->url(array('action' => 'view-categorie', 'id' => $categorie->getId())), $categorie->getLibelle());?></li> <?php } ?> @@ -20,20 +20,10 @@ <ul> <?php foreach ($this->albums as $album) { ?> <li> - <?php if ('' != ($thumbUrl = $album->getThumbnailUrl())) { ?> - <?php echo $this->tagImg($thumbUrl);?> - <?php } ?> - <?php echo $this->tagAnchor( - $this->url(array('action' => 'view-album', - 'id' => $album->getId())), - $album->getTitre() - );?> - <p><?php if ('' != $album->getDescription()) { - echo $this->subwords($album->getDescription(), 20); - }?></p> + <?php echo $this->renderAlbumPreview($album); ?> </li> <?php } ?> </ul> </div> <?php } ?> -<?php $this->closeBoite(); ?> \ No newline at end of file +<?php $this->closeBoite(); ?> diff --git a/library/ZendAfi/View/Helper/Accueil/BibNumerique/TreeRenderer.php b/library/ZendAfi/View/Helper/Accueil/BibNumerique/TreeRenderer.php index 6efe5eaeb62..40384370da0 100644 --- a/library/ZendAfi/View/Helper/Accueil/BibNumerique/TreeRenderer.php +++ b/library/ZendAfi/View/Helper/Accueil/BibNumerique/TreeRenderer.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 ZendAfi_View_Helper_Accueil_BibNumerique_TreeRenderer { public $preferences; @@ -69,7 +69,7 @@ class ZendAfi_View_Helper_Accueil_BibNumerique_TreeRenderer { . $this->_getCategoriesOf($collection) . '</li>'; } - + return '<ul>' . $content . '</ul>'; } @@ -84,7 +84,7 @@ class ZendAfi_View_Helper_Accueil_BibNumerique_TreeRenderer { $content .= '<ul>'; foreach ($categories as $categorie) { $options = ($this->_isCurrentCategorie($categorie)) ? array('class' => 'selected') : array(); - $content .= '<li class="lien">' + $content .= '<li class="lien">' . $this->_getLinkedItemFor($categorie, 'view-categorie', $options) . $this->_getAlbumsOf($categorie) . '</li>'; @@ -105,7 +105,7 @@ class ZendAfi_View_Helper_Accueil_BibNumerique_TreeRenderer { $content .= '<ul>'; foreach ($albums as $album) { $options = ($this->_isCurrentAlbum($album)) ? ['class' => 'selected'] : []; - $content .= '<li>' . $this->_getLinkedItemFor($album, 'view-album', $options) . '</li>'; + $content .= '<li>' . $this->view->renderAlbumPreview($album) . '</li>'; } $content .= '</ul>'; } @@ -114,6 +114,7 @@ class ZendAfi_View_Helper_Accueil_BibNumerique_TreeRenderer { } + /** * @param Storm_Model_Abstract $item * @param string $action @@ -124,8 +125,8 @@ class ZendAfi_View_Helper_Accueil_BibNumerique_TreeRenderer { return $this->view->tagAnchor($this->view->url(array('module' => 'opac', 'controller' => 'bib-numerique', 'action' => $action, - 'id' => $item->getId()), - null, true), + 'id' => $item->getId()), + null, true), $item->getLibelle(), $options); } @@ -133,7 +134,7 @@ class ZendAfi_View_Helper_Accueil_BibNumerique_TreeRenderer { /** * @param Class_Album $album - * @return bool + * @return bool */ protected function _isCurrentAlbum($album) { if (null === $this->_currentAlbum) { @@ -144,8 +145,8 @@ class ZendAfi_View_Helper_Accueil_BibNumerique_TreeRenderer { } /** - * @param Class_AlbumCategorie - * @return bool + * @param Class_AlbumCategorie + * @return bool */ protected function _isCurrentCategorie($categorie) { if ((null !== $this->_currentCategorie) && ($categorie->getId() == $this->_currentCategorie->getId())) { diff --git a/library/ZendAfi/View/Helper/RenderAlbumPreview.php b/library/ZendAfi/View/Helper/RenderAlbumPreview.php new file mode 100644 index 00000000000..ca48f24681e --- /dev/null +++ b/library/ZendAfi/View/Helper/RenderAlbumPreview.php @@ -0,0 +1,49 @@ +<?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_RenderAlbumPreview extends ZendAfi_View_Helper_BaseHelper { + public function renderAlbumPreview($album) { + if ($album->isWebSite()) + return $this->view->renderAlbumPreview_WebSite($album); + + return $this->defaultRender($album); + } + + + public function defaultRender($album) { + return + $this->_tag('div', + $this->_tag('h2', + $this->_tag('a', + $this->_tag('img', + '', + ['src' => $album->getThumbnailUrl()]). + $album->getTitre(), + ['href' => $this->view->url(['controller' => 'bib-numerique', + 'action' => 'view-album', + 'id' => $album->getId()])] + )) + . $album->getDescription() + ); + } +} + +?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/RenderAlbumPreview/WebSite.php b/library/ZendAfi/View/Helper/RenderAlbumPreview/WebSite.php new file mode 100644 index 00000000000..38c3a7e4b8d --- /dev/null +++ b/library/ZendAfi/View/Helper/RenderAlbumPreview/WebSite.php @@ -0,0 +1,49 @@ +<?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_RenderAlbumPreview_WebSite extends ZendAfi_View_Helper_RenderAlbumPreview { + public function renderAlbumPreview_WebSite($album) { + if ($album->numberOfRessources() == 1) + return $this->renderWebSite($album->getRessources()[0]); + + return $this->defaultRender($album); + } + + + public function renderWebSite($ressource) { + return + $this->_tag('div', + $this->_tag('h2', + $this->_tag('a', + $this->_tag('img', + '', + ['src' => $ressource->getPosterUrl()]). + $ressource->getTitre(), + ['href' => $ressource->getUrl(), + 'target' => '_blank'] + )) + . $ressource->getDescription(), + ['class' => 'sitotheque'] + ); + } +} + +?> \ No newline at end of file diff --git a/tests/application/modules/opac/controllers/RechercheControllerAlbumWebSiteTest.php b/tests/application/modules/opac/controllers/RechercheControllerAlbumWebSiteTest.php index eff17e35c58..d294075c6ca 100644 --- a/tests/application/modules/opac/controllers/RechercheControllerAlbumWebSiteTest.php +++ b/tests/application/modules/opac/controllers/RechercheControllerAlbumWebSiteTest.php @@ -24,10 +24,16 @@ abstract class RechercheControllerAlbumWebSiteTestCase extends AbstractControlle $_wikipedia, $_linuxfr, $_framasoft, + $_website_category, $_storm_default_to_volatile = true; public function setUp() { parent::setUp(); + + $this->_website_category = $this->fixture('Class_AlbumCategorie', + ['id' => 1, + 'libelle' => 'Websites']); + $this ->_setupWikipedia() ->_setupLinuxFr() @@ -41,11 +47,13 @@ abstract class RechercheControllerAlbumWebSiteTestCase extends AbstractControlle ['id' => 1, 'type_doc_id' => Class_TypeDoc::WEBSITE, 'titre' => 'Wikipedia', + 'cat_id' => 1, 'status' => Class_Album::STATUS_VALIDATED]); $this->_wikipedia ->addRessource($this->fixture('Class_AlbumRessource', ['id' => 1, 'titre' => 'Wikipedia', + 'cat_id' => 1, 'url' => 'http://www.wikipedia.org'])) ->assertSave(); $this->_wikipedia->index(); @@ -59,6 +67,7 @@ abstract class RechercheControllerAlbumWebSiteTestCase extends AbstractControlle ['id' => 2, 'type_doc_id' => Class_TypeDoc::WEBSITE, 'titre' => 'Linuxfr', + 'cat_id' => 1, 'status' => Class_Album::STATUS_VALIDATED]); $this->_linuxfr ->addRessource($this->fixture('Class_AlbumRessource', @@ -79,6 +88,7 @@ abstract class RechercheControllerAlbumWebSiteTestCase extends AbstractControlle ['id' => 3, 'type_doc_id' => Class_TypeDoc::WEBSITE, 'titre' => 'Framasoft', + 'cat_id' => 1, 'status' => Class_Album::STATUS_VALIDATED]); $this->_framasoft ->addRessource($this->fixture('Class_AlbumRessource', @@ -189,4 +199,25 @@ class RechercheControllerAlbumWebSiteFramasoftResNumeriquesTest extends Recherch } } + + +class RechercheControllerAlbumWebSiteViewBibNumCategoryTest extends RechercheControllerAlbumWebSiteTestCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/opac/bib-numerique/view-categorie/id/1'); + } + + + /** @test */ + public function linuxFrTitleShouldLinkToWebsite() { + $this->assertXPathContentContains('//div[@class="sitotheque"]/h2/a[@href="http://www.linuxfr.org"][@target="_blank"]', 'Linuxfr'); + } + + + /** @test */ + public function framasoftTitleShouldLinkToViewAlbum() { + $this->assertXPathContentContains('//div/h2/a[@href="/bib-numerique/view-album/id/3"]', 'Framasoft', $this->_response->getBody()); + } +} + ?> \ No newline at end of file -- GitLab