From fc16a44a9ca0c362396119ac37415879c9a4d940 Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Thu, 10 May 2012 14:06:11 +0000
Subject: [PATCH] =?UTF-8?q?Bib=20nume=CC=81rique:=20affichage=20des=20ress?=
 =?UTF-8?q?ources=20si=20EPUB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .gitattributes                                |  4 ++
 afi                                           |  1 +
 .../views/scripts/album/edit-images.phtml     |  3 +-
 .../controllers/BibNumeriqueController.php    |  3 +-
 doc/extern_libs.txt                           |  3 +-
 library/Class/Album.php                       | 17 ++++++
 library/Class/File/Mime.php                   |  2 +
 library/Class/TypeDoc.php                     |  1 +
 .../View/Helper/AlbumRessourceInfos.php       | 33 ++++++++++
 library/ZendAfi/View/Helper/RenderAlbum.php   |  4 +-
 .../ZendAfi/View/Helper/TagAlbumMediaList.php | 40 ++++++++++++
 .../BibNumeriqueControllerTest.php            |  3 +-
 .../ZendAfi/View/Helper/RenderAlbumTest.php   | 61 +++++++++++++++++++
 13 files changed, 168 insertions(+), 7 deletions(-)
 create mode 120000 afi
 create mode 100644 library/ZendAfi/View/Helper/AlbumRessourceInfos.php
 create mode 100644 library/ZendAfi/View/Helper/TagAlbumMediaList.php
 create mode 100644 tests/library/ZendAfi/View/Helper/RenderAlbumTest.php

diff --git a/.gitattributes b/.gitattributes
index e00c5d930d6..91630169e79 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -3,6 +3,7 @@
 /COPYING -text
 /INSTALL -text
 /README -text
+/afi -text
 amber/.htaccess -text
 amber/afi/js/AFI-Core.deploy.js -text
 amber/afi/js/AFI-Core.js -text
@@ -1922,6 +1923,7 @@ library/ZendAfi/View/Helper/Admin/TagListeSuggestion.php -text
 library/ZendAfi/View/Helper/Admin/TagSelectionChamps.php -text
 library/ZendAfi/View/Helper/Admin/TreeSelect.php -text
 library/ZendAfi/View/Helper/AjaxMessage.php -text
+library/ZendAfi/View/Helper/AlbumRessourceInfos.php -text
 library/ZendAfi/View/Helper/Avis.php -text
 library/ZendAfi/View/Helper/BarreNav.php -text
 library/ZendAfi/View/Helper/BaseHelper.php -text
@@ -1962,6 +1964,7 @@ library/ZendAfi/View/Helper/RenderForm.php -text
 library/ZendAfi/View/Helper/RenderLieu.php -text
 library/ZendAfi/View/Helper/ReseauxSociaux.php -text
 library/ZendAfi/View/Helper/Subwords.php -text
+library/ZendAfi/View/Helper/TagAlbumMediaList.php -text
 library/ZendAfi/View/Helper/TagAnchor.php -text
 library/ZendAfi/View/Helper/TagArticleEvent.php -text
 library/ZendAfi/View/Helper/TagBanniere.php -text
@@ -3586,6 +3589,7 @@ tests/library/ZendAfi/View/Helper/AvisTest.php -text
 tests/library/ZendAfi/View/Helper/FicheAbonneLinksTest.php -text
 tests/library/ZendAfi/View/Helper/IconeSupportTest.php -text
 tests/library/ZendAfi/View/Helper/IframeContainerTest.php -text
+tests/library/ZendAfi/View/Helper/RenderAlbumTest.php -text
 tests/library/ZendAfi/View/Helper/RenderFormTest.php -text
 tests/library/ZendAfi/View/Helper/RenderLieuTest.php -text
 tests/library/ZendAfi/View/Helper/SubwordsTest.php -text
diff --git a/afi b/afi
new file mode 120000
index 00000000000..5d16148b3c6
--- /dev/null
+++ b/afi
@@ -0,0 +1 @@
+../afi-opac3-svn/afi/
\ No newline at end of file
diff --git a/application/modules/admin/views/scripts/album/edit-images.phtml b/application/modules/admin/views/scripts/album/edit-images.phtml
index 07c49df91ab..9a8408e33f8 100644
--- a/application/modules/admin/views/scripts/album/edit-images.phtml
+++ b/application/modules/admin/views/scripts/album/edit-images.phtml
@@ -69,8 +69,7 @@ echo $this->partial('album/_album_panel.phtml',
 						?></div>
 
 						<div class="info">
-						 <?php if ($ressource->hasTitre()) echo $ressource->getTitre().'<br/>';?>
-						 <?php echo $this->fileInfos($ressource->getOriginalPath());?>
+						 <?php echo $this->albumRessourceInfos($ressource) ?>
 						 </div>
 
 						<div class="actions">
diff --git a/application/modules/opac/controllers/BibNumeriqueController.php b/application/modules/opac/controllers/BibNumeriqueController.php
index 84a3e3f5ade..ae2a4e86569 100644
--- a/application/modules/opac/controllers/BibNumeriqueController.php
+++ b/application/modules/opac/controllers/BibNumeriqueController.php
@@ -219,7 +219,7 @@ class BibNumeriqueController extends Zend_Controller_Action {
 			exit;
 		}
 
-		echo $this->_renderFile($resource->getOriginalPath());
+		echo $this->_renderFile($resource->getOriginalPath(), $as_attachment);
 	}
 
 
@@ -237,7 +237,6 @@ class BibNumeriqueController extends Zend_Controller_Action {
 
 		// puis son type mime
 		$mimeType = Class_File_Mime::getType($ext);
-
 		$fileInfos = stat($filepath);
 		$parts = pathinfo($filepath);
 
diff --git a/doc/extern_libs.txt b/doc/extern_libs.txt
index 1de11657bbf..b25cb9da2c9 100644
--- a/doc/extern_libs.txt
+++ b/doc/extern_libs.txt
@@ -28,6 +28,7 @@
 | Image SlideShow                     | LGPL                        |               | kiosques                          |                  | http://www.dhtmlgoodies.com/index.html?whichScript=image_slideshow                                                             |
 | FPDF                                | MIT like                    |               |                                   |                  | http://www.fpdf.org/                                                                                                           |
 | Nuvola icons                        | LGPL                        |               | icônes                            |                  | http://www.icon-king.com/projects/nuvola/                                                                                      |
-| JQuery PlaceHolder plugin           | MIT/GPL                     |               | compat IE                         |                  | https://github.com/mathiasbynens/jquery-placeholder                                                                                                                               |
+| JQuery PlaceHolder plugin           | MIT/GPL                     |               | compat IE                         |                  | https://github.com/mathiasbynens/jquery-placeholder                                                                            |
+| Monocle                             | MIT                         |               | lecture epub                      |                  | https://github.com/joseph/Monocle                                                                                                                               |
 
 
diff --git a/library/Class/Album.php b/library/Class/Album.php
index e03a37da3a9..ba9b4590060 100644
--- a/library/Class/Album.php
+++ b/library/Class/Album.php
@@ -302,10 +302,27 @@ class Class_Album extends Storm_Model_Abstract {
 	}
 
 
+	/** @return boolean */
+	public function isDiaporama() {
+		return $this->getTypeDocId() == Class_TypeDoc::DIAPORAMA;
+	}
+
+
 	public function beLivreNumerique() {
 		return $this->setTypeDocId(Class_TypeDoc::LIVRE_NUM);
 	}
 
+
+	public function beDiaporama() {
+		return $this->setTypeDocId(Class_TypeDoc::DIAPORAMA);
+	}
+
+
+	public function beEPUB() {
+		return $this->setTypeDocId(Class_TypeDoc::EPUB);
+	}
+
+
 	/**
 	 * @param Zend_Controller_Request_Http $request
 	 * @return array
diff --git a/library/Class/File/Mime.php b/library/Class/File/Mime.php
index f641d00300c..b0cb0233d3b 100644
--- a/library/Class/File/Mime.php
+++ b/library/Class/File/Mime.php
@@ -198,6 +198,8 @@ class Class_File_Mime {
 		'wvx'		=> 'video/x-ms-wvx',
 		'avi'		=> 'video/x-msvideo',
 		'mpv'		=> 'video/matroska',
+
+		'epub' => 'application/epub+zip'
 	);
 
 	/**
diff --git a/library/Class/TypeDoc.php b/library/Class/TypeDoc.php
index 0616f5f08e2..f12a55434bb 100644
--- a/library/Class/TypeDoc.php
+++ b/library/Class/TypeDoc.php
@@ -113,6 +113,7 @@ class Class_TypeDoc extends Storm_Model_Abstract {
   protected $_loader_class = 'TypeDocLoader';
 	const LIVRE_NUM = 100;
 	const DIAPORAMA = 101;
+	const EPUB = 102;
 
 
 	/**
diff --git a/library/ZendAfi/View/Helper/AlbumRessourceInfos.php b/library/ZendAfi/View/Helper/AlbumRessourceInfos.php
new file mode 100644
index 00000000000..de47833add7
--- /dev/null
+++ b/library/ZendAfi/View/Helper/AlbumRessourceInfos.php
@@ -0,0 +1,33 @@
+<?php
+/**
+ * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * AFI-OPAC 2.0 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).
+ *
+ * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ */
+
+class ZendAfi_View_Helper_AlbumRessourceInfos extends Zend_View_Helper_HtmlElement {
+	public function albumRessourceInfos($ressource) {
+		$infos = $this->view->fileInfos($ressource->getOriginalPath());
+		
+		if (!$ressource->hasTitre()) 
+			return $infos;
+
+		return $ressource->getTitre().'<br/>'.$infos;
+	}
+}
+
+?>
\ No newline at end of file
diff --git a/library/ZendAfi/View/Helper/RenderAlbum.php b/library/ZendAfi/View/Helper/RenderAlbum.php
index 660ff789f6d..1b7f8e3a966 100644
--- a/library/ZendAfi/View/Helper/RenderAlbum.php
+++ b/library/ZendAfi/View/Helper/RenderAlbum.php
@@ -27,8 +27,10 @@ class ZendAfi_View_Helper_RenderAlbum extends Zend_View_Helper_HtmlElement {
 		$content = '';
 		if ($album->isLivreNumerique())
 			Class_ScriptLoader::getInstance()->loadBooklet($album->getId(), '#resnum');
-		else
+		else if ($album->isDiaporama())
 			$content = $this->view->tagSlideshow($album);
+		else
+			$content = $this->view->tagAlbumMediaList($album);
 		
 		return sprintf('<div id="resnum">%s</div>', $content); 
 	}
diff --git a/library/ZendAfi/View/Helper/TagAlbumMediaList.php b/library/ZendAfi/View/Helper/TagAlbumMediaList.php
new file mode 100644
index 00000000000..5bbf93fa8f2
--- /dev/null
+++ b/library/ZendAfi/View/Helper/TagAlbumMediaList.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * AFI-OPAC 2.0 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).
+ *
+ * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ */
+
+class ZendAfi_View_Helper_TagAlbumMediaList extends Zend_View_Helper_HtmlElement {
+	public function tagAlbumMediaList($album) {
+		$html = '<ul>';
+
+		$ressources = $album->getRessources();
+		foreach($ressources as $ressource) {
+			$html .= sprintf('<li>%s</li>',
+											 $this->view->tagAnchor(array('controller' => 'bib-numerique',
+																										'action' => 'download-resource',
+																										'id' => $ressource->getId()),
+																							$this->view->albumRessourceInfos($ressource)));
+		}
+		
+		$html .= '</ul>';
+		return $html;
+	}
+}
+
+?>
\ No newline at end of file
diff --git a/tests/application/modules/opac/controllers/BibNumeriqueControllerTest.php b/tests/application/modules/opac/controllers/BibNumeriqueControllerTest.php
index 7671166967e..08176c2853e 100644
--- a/tests/application/modules/opac/controllers/BibNumeriqueControllerTest.php
+++ b/tests/application/modules/opac/controllers/BibNumeriqueControllerTest.php
@@ -46,6 +46,7 @@ abstract class AbstractBibNumeriqueControllerAlbumActionPremierVolumeTestCase ex
 		
 		$album = Class_Album::getLoader()
 			->newInstanceWithId(999)
+			->beDiaporama()
 			->setTitre('Premier volume')
 			->setDescription("On ne peut que reconnaitre le talent de l'artiste !")
 			->setCategorie(Class_AlbumCategorie::getLoader()
@@ -291,7 +292,7 @@ class BibNumeriqueControllerAlbumPremierVolumeWithoutPDFTestToJSON extends Abstr
 
 
 
-class BibNumeriqueControllerDownloadRessoucesTest extends AbstractBibNumeriqueControllerAlbumActionPremierVolumeTestCase {
+class BibNumeriqueControllerDownloadRessourcesTest extends AbstractBibNumeriqueControllerAlbumActionPremierVolumeTestCase {
 	/** @test */
 	public function thumbnailIdOneShouldRenderThumbnail() {
 		$this->dispatch('/opac/bib-numerique/thumbnail/id/1');
diff --git a/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php b/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php
new file mode 100644
index 00000000000..1d8aefee303
--- /dev/null
+++ b/tests/library/ZendAfi/View/Helper/RenderAlbumTest.php
@@ -0,0 +1,61 @@
+<?php
+/**
+ * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * AFI-OPAC 2.0 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).
+ *
+ * AFI-OPAC 2.0 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 AFI-OPAC 2.0; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ */
+
+class ZendAfi_View_Helper_RenderAlbumEPUBTest extends ViewHelperTestCase {
+	/** @var ZendAfi_View_Helper_RenderForm */
+	protected $_helper;
+
+	/** @var string */
+	protected $_html;
+
+	public function setUp() {
+		parent::setUp();
+
+		$view = new ZendAfi_Controller_Action_Helper_View();
+		$this->_helper = new ZendAfi_View_Helper_RenderAlbum();
+		$this->_helper->setView($view);
+
+		$this->_album_epub = Class_Album::getLoader()
+			->newInstanceWithId(999)
+			->setLibelle('Versailles')
+			->beEPUB()
+			->setRessources(array(Class_AlbumRessource::getLoader()
+														->newInstanceWithId(123)
+														->setFichier('versailles.epub')
+														->setIdAlbum(999)));
+
+		$this->html = $this->_helper->renderAlbum($this->_album_epub);
+	}
+
+
+	/** @test */
+	public function albumTypeDocShouldBe102() {
+		$this->assertEquals(102, $this->_album_epub->getTypeDocId());
+	}
+
+
+	/** @test */
+	public function pageShouldContainsLinkToDownloadEPUB() {
+		$this->assertXPathContentContains($this->html, 
+																			'//a[contains(@href, "bib-numerique/download-resource/id/123")]',
+																			'versailles.epub');
+	}
+}
\ No newline at end of file
-- 
GitLab