From f1a4e73be46740390fb7a5402e80482240c8143d Mon Sep 17 00:00:00 2001
From: efalcy <efalcy@git-test.afi-sa.fr>
Date: Wed, 12 Jun 2013 16:16:26 +0000
Subject: [PATCH] Recherche Federee numilog : affichage dans la partie admin du
 moissonage + lien vers numilog dans la notice

---
 .gitattributes                                |  3 ++
 .../scripts/harvest/numilog-browse.phtml      |  2 +
 .../admin/views/scripts/harvest/numilog.phtml |  1 +
 .../modules/recherche_viewnotice.phtml        |  2 +-
 .../opac/controllers/AbonneController.php     |  2 +-
 .../opac/controllers/NoticeajaxController.php |  1 +
 library/Class/Album.php                       |  5 +++
 library/Class/Notice.php                      |  2 +-
 library/Class/NumilogLink.php                 |  6 +++
 library/Class/Systeme/ModulesMenu/CVS.php     |  2 +-
 library/Class/Systeme/ModulesMenu/Numilog.php |  2 +-
 library/Class/TypeDoc.php                     |  2 +-
 .../BibNumerique/LivreNumerique.php           |  4 +-
 .../BibNumerique/RessourceNumerique.php       | 13 +++++-
 library/Class/WebService/DublinCoreParser.php |  2 +
 .../View/Helper/Admin/MenuGaucheAdmin.php     |  1 +
 library/ZendAfi/View/Helper/RenderAlbum.php   |  5 ++-
 .../ZendAfi/View/Helper/TagLivreNumerique.php | 40 +++++++++++++++++++
 .../AbonneControllerMultimediaTest.php        |  2 +-
 tests/library/Class/TypeDocTest.php           |  4 +-
 .../library/Class/WebService/NumilogTest.php  | 14 ++++++-
 21 files changed, 102 insertions(+), 13 deletions(-)
 create mode 100644 application/modules/admin/views/scripts/harvest/numilog-browse.phtml
 create mode 100644 application/modules/admin/views/scripts/harvest/numilog.phtml
 create mode 100644 library/ZendAfi/View/Helper/TagLivreNumerique.php

diff --git a/.gitattributes b/.gitattributes
index 10c7085039d..d2dbf32c432 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -517,6 +517,8 @@ application/modules/admin/views/scripts/frbr-linktype/index.phtml -text
 application/modules/admin/views/scripts/googleMaps.phtml -text
 application/modules/admin/views/scripts/harvest/arte-vod-browse.phtml -text
 application/modules/admin/views/scripts/harvest/arte-vod.phtml -text
+application/modules/admin/views/scripts/harvest/numilog-browse.phtml -text
+application/modules/admin/views/scripts/harvest/numilog.phtml -text
 application/modules/admin/views/scripts/harvest/vodeclic-browse.phtml -text
 application/modules/admin/views/scripts/harvest/vodeclic.phtml -text
 application/modules/admin/views/scripts/head.phtml -text
@@ -2762,6 +2764,7 @@ library/ZendAfi/View/Helper/TagFormationVodeclic.php -text
 library/ZendAfi/View/Helper/TagHistoriqueRecherche.php -text
 library/ZendAfi/View/Helper/TagImg.php -text
 library/ZendAfi/View/Helper/TagImgHover.php -text
+library/ZendAfi/View/Helper/TagLivreNumerique.php -text
 library/ZendAfi/View/Helper/TagModelTable.php -text
 library/ZendAfi/View/Helper/TagObjetsImgProperties.php -text
 library/ZendAfi/View/Helper/TagPageTitle.php -text
diff --git a/application/modules/admin/views/scripts/harvest/numilog-browse.phtml b/application/modules/admin/views/scripts/harvest/numilog-browse.phtml
new file mode 100644
index 00000000000..59993f6a833
--- /dev/null
+++ b/application/modules/admin/views/scripts/harvest/numilog-browse.phtml
@@ -0,0 +1,2 @@
+<form id="numilog_harvest" action="<?php echo $this->url(['action' => 'numilog'])?>" method="get">
+	<input type="submit" value="<?php echo $this->_('Lancer le moissonnage');?>">
diff --git a/application/modules/admin/views/scripts/harvest/numilog.phtml b/application/modules/admin/views/scripts/harvest/numilog.phtml
new file mode 100644
index 00000000000..d104ffc3aa9
--- /dev/null
+++ b/application/modules/admin/views/scripts/harvest/numilog.phtml
@@ -0,0 +1 @@
+<div><pre><?php echo $this->log;?><pre></div>
\ No newline at end of file
diff --git a/application/modules/admin/views/scripts/modules/recherche_viewnotice.phtml b/application/modules/admin/views/scripts/modules/recherche_viewnotice.phtml
index fc28f494eb7..df4928a488c 100644
--- a/application/modules/admin/views/scripts/modules/recherche_viewnotice.phtml
+++ b/application/modules/admin/views/scripts/modules/recherche_viewnotice.phtml
@@ -53,7 +53,7 @@ $codif = Class_Codification::getInstance();
     			$nom_onglet=$codif->getNomOnglet($clef);
     			if(!$valeurs["titre"]) $valeurs["titre"]=$nom_onglet;
     			print('<tr>');
-    			print('<td class="droite">'.$nom_onglet.'&nbsp;</td>');
+    			print('<td class="droite">BLABLA'.$nom_onglet.'&nbsp;</td>');
     			$combo=$this->formSelect($clef.'_aff',$valeurs["aff"],"",array("0" => "Ne pas afficher","1"=>"Bloc déplié","2" => "Bloc fermé", "3" => "Dans un onglet"));
     			print('<td class="gauche">'.$combo.'</td>');
     			print('<td class="gauche"><input type="text" name="'.$clef.'_ordre" size="3" value="'.$valeurs["ordre"].'"></td>');
diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php
index b31c15ec4b5..aed53f037cc 100644
--- a/application/modules/opac/controllers/AbonneController.php
+++ b/application/modules/opac/controllers/AbonneController.php
@@ -840,7 +840,7 @@ class AbonneController extends ZendAfi_Controller_Action {
 		}
 			
 		$form = new ZendAfi_Form_SuggestionAchat();
-
+		xdebug_break();
 		if ($this->_request->isPost()) {
 			$post = $this->_request->getPost();
 			unset($post['submit']);
diff --git a/application/modules/opac/controllers/NoticeajaxController.php b/application/modules/opac/controllers/NoticeajaxController.php
index 4d7bc0c3b34..023850d045f 100644
--- a/application/modules/opac/controllers/NoticeajaxController.php
+++ b/application/modules/opac/controllers/NoticeajaxController.php
@@ -266,6 +266,7 @@ class NoticeAjaxController extends Zend_Controller_Action {
 
 
 	public function resnumeriquesAction() {
+		xdebug_break();
 		$html = sprintf('<p>%s</p>', $this->view->_('Aucune ressource correspondante'));
 		if (null !== $exemplaire = Class_Exemplaire::getLoader()->findFirstBy(array('id_notice' => $this->id_notice)))
 			$html = $this->view->renderAlbum($exemplaire->getAlbum());
diff --git a/library/Class/Album.php b/library/Class/Album.php
index 2bdbd896934..60ff7816a81 100644
--- a/library/Class/Album.php
+++ b/library/Class/Album.php
@@ -384,6 +384,11 @@ class Class_Album extends Storm_Model_Abstract {
 		return $this->setTypeDocId(Class_TypeDoc::NUMILOG);
 	}
 
+	public function isNumilog() {
+		return $this->getTypeDocId() == Class_TypeDoc::NUMILOG;
+
+	}
+
 
 	public function beFormationVodeclic() {
 		return $this->setTypeDocId(Class_TypeDoc::VODECLIC);
diff --git a/library/Class/Notice.php b/library/Class/Notice.php
index 6734b9d6920..2efc14a24fc 100644
--- a/library/Class/Notice.php
+++ b/library/Class/Notice.php
@@ -483,7 +483,7 @@ class Class_Notice extends Storm_Model_Abstract {
 				else $notice["entete"][$rubrique] = $this->getChampNotice($clef, $notice["facettes"]);
 			}
 		}
-
+		xdebug_break();
 		// Blocs et onglets
 		if (!$preferences["onglets"]) $preferences["onglets"] = array();
 		$notice["blocs"] = array();
diff --git a/library/Class/NumilogLink.php b/library/Class/NumilogLink.php
index 5d099b932ab..403c7559720 100644
--- a/library/Class/NumilogLink.php
+++ b/library/Class/NumilogLink.php
@@ -51,6 +51,12 @@ class Class_NumilogLink extends Class_WebService_Abstract {
 		return md5(Zend_Session::getId());
 	}
 
+	function urlExternal($url_external){
+		if ($this->_user)
+			return $url_external.'&ticket='.$this->getTicket();
+		else 
+			return $url_external;
+	}
 
 
 	function url(){
diff --git a/library/Class/Systeme/ModulesMenu/CVS.php b/library/Class/Systeme/ModulesMenu/CVS.php
index 64bf0e80fe5..1da9d558730 100644
--- a/library/Class/Systeme/ModulesMenu/CVS.php
+++ b/library/Class/Systeme/ModulesMenu/CVS.php
@@ -45,7 +45,7 @@ class Class_Systeme_ModulesMenu_CVS extends Class_Systeme_ModulesMenu_Null {
 	public function getDynamiqueUrl() {
 		return ($user = Class_Users::getIdentity())
 		   ? $this->getCVSUrlForUser($user)
-		   : BASE_URL.'/auth/login';
+		   : '/auth/login';
 
 	}
 
diff --git a/library/Class/Systeme/ModulesMenu/Numilog.php b/library/Class/Systeme/ModulesMenu/Numilog.php
index ba52605fcb0..d026347182b 100644
--- a/library/Class/Systeme/ModulesMenu/Numilog.php
+++ b/library/Class/Systeme/ModulesMenu/Numilog.php
@@ -30,7 +30,7 @@ class Class_Systeme_ModulesMenu_Numilog extends Class_Systeme_ModulesMenu_Null {
 
 
 	public function getNumilogUrlForUser($user) {
-		if ($user->isAbonne() && $user->isAbonnementValid()) 
+		if ($user && $user->hasRightAccesRessourcesNumeriques())
 			return Class_NumilogLink::forUser($user)->url();
 		return Class_AdminVar::get('NUMILOG_URL');
 	}
diff --git a/library/Class/TypeDoc.php b/library/Class/TypeDoc.php
index fe937698063..dcb7c8408c8 100644
--- a/library/Class/TypeDoc.php
+++ b/library/Class/TypeDoc.php
@@ -175,7 +175,7 @@ class Class_TypeDoc extends Storm_Model_Abstract {
 						self::OAI => 'OAI',
 			      self::ARTEVOD => 'Arte VOD',
 						self::VODECLIC => 'Formation Vodeclic',
-						self::NUMILOG => 'Livres Numériques'];
+						self::NUMILOG => 'Livres numériques'];
 	}
 
 
diff --git a/library/Class/WebService/BibNumerique/LivreNumerique.php b/library/Class/WebService/BibNumerique/LivreNumerique.php
index 96c6e53df8f..baed437de44 100644
--- a/library/Class/WebService/BibNumerique/LivreNumerique.php
+++ b/library/Class/WebService/BibNumerique/LivreNumerique.php
@@ -40,7 +40,9 @@ class Class_WebService_BibNumerique_LivreNumerique extends Class_WebService_BibN
 
   public function fillAlbum($album) {
 		$album->beNumilog()
-			->setDescription($this->getDescription());
+			->setDescription($this->getDescription())
+			->setEditeur($this->getEditeur())
+			->setAuteur(implode(', ', $this->getAuthors()));;
 			
 		return $album;
 	}
diff --git a/library/Class/WebService/BibNumerique/RessourceNumerique.php b/library/Class/WebService/BibNumerique/RessourceNumerique.php
index c281c8ae8dc..753d4617a5b 100644
--- a/library/Class/WebService/BibNumerique/RessourceNumerique.php
+++ b/library/Class/WebService/BibNumerique/RessourceNumerique.php
@@ -32,7 +32,7 @@
 	protected $_posters = array();
 	protected $_trailers = array();
 	protected $_photos = array();
-
+	protected $_editeur;
 
 	public function setId($id) {
 		$this->_id = $id;
@@ -100,6 +100,17 @@
 	}
 
 
+	public function setEditeur($editeur) {
+		$this->_editeur = $editeur;
+		return $this;
+	}
+
+
+	public function getEditeur() {
+		return trim($this->_editeur);
+	}
+
+
 	public function setDescription($description) {
 		$this->_description = $description;
 		return $this;
diff --git a/library/Class/WebService/DublinCoreParser.php b/library/Class/WebService/DublinCoreParser.php
index e4199d5e2fe..726ddbc1b49 100644
--- a/library/Class/WebService/DublinCoreParser.php
+++ b/library/Class/WebService/DublinCoreParser.php
@@ -132,6 +132,7 @@ class Class_WebService_DublinCoreParser {
 
 
 	protected function end_dc_publisher($parser) {
+		$this->ressource_numerique->setEditeur($this->current_data);
 		$this->assign_data_to('editeur');
 	}
 
@@ -145,6 +146,7 @@ class Class_WebService_DublinCoreParser {
 	protected function end_dc_relation($parser) {
 		$this->assign_data_to('relation');
 		$this->ressource_numerique->setExternalUri($this->current_data);
+		$this->ressource_numerique->addTrailer($this->current_data);
 	}
 
 	protected function end_dc_description($parser) {
diff --git a/library/ZendAfi/View/Helper/Admin/MenuGaucheAdmin.php b/library/ZendAfi/View/Helper/Admin/MenuGaucheAdmin.php
index d33caf9a254..a5b658d870b 100644
--- a/library/ZendAfi/View/Helper/Admin/MenuGaucheAdmin.php
+++ b/library/ZendAfi/View/Helper/Admin/MenuGaucheAdmin.php
@@ -75,6 +75,7 @@ class ZendAfi_View_Helper_Admin_MenuGaucheAdmin extends ZendAfi_View_Helper_Base
 			$menu_bibnum .= $this->addMenu("collections_16.png",		$this->translate()->_("Collections"),						"/admin/album",								 $acl_admins);
 			$menu_bibnum .= $this->addMenu("artevod_16.png",				$this->translate()->_("Arte VOD"),							"/admin/harvest/arte-vod-browse",	$acl_admins);
 			$menu_bibnum .= $this->addMenu("vodeclic_16.png",				$this->translate()->_("Vodeclic"),							"/admin/harvest/vodeclic-browse",	$acl_admins);
+			$menu_bibnum .= $this->addMenu("oai_16.png",				$this->translate()->_("Numilog"),							"/admin/harvest/numilog-browse",	$acl_admins);
 			if (Class_AdminVar::isBibNumEnabled()) {
 				$menu_bibnum .= $this->addMenu("epub_16.png",						$this->translate()->_("Catalogues OPDS"),				"/admin/opds",								 $acl_admins);
 				$menu_bibnum .= $this->addMenu("oai_16.png",						$this->translate()->_("Entrepôts OAI"),					"/admin/oai",									 $acl_admins);
diff --git a/library/ZendAfi/View/Helper/RenderAlbum.php b/library/ZendAfi/View/Helper/RenderAlbum.php
index 0b1241a4fd4..3d92023c3c1 100644
--- a/library/ZendAfi/View/Helper/RenderAlbum.php
+++ b/library/ZendAfi/View/Helper/RenderAlbum.php
@@ -28,11 +28,14 @@ class ZendAfi_View_Helper_RenderAlbum extends Zend_View_Helper_HtmlElement {
 
 
 	public function renderAlbumHelper($album) {
+
 		if ($album->isLivreNumerique()) {
 			Class_ScriptLoader::getInstance()->loadBooklet($album->getId(), '#resnum');
 			return '';
 		}
-
+		
+		if ($album->isNumilog())
+			return $this->view->tagLivreNumerique($album);
 		if ($album->isDiaporama() && $album->hasOnlyImages())
 			return $this->view->tagSlideshow($album);
 
diff --git a/library/ZendAfi/View/Helper/TagLivreNumerique.php b/library/ZendAfi/View/Helper/TagLivreNumerique.php
new file mode 100644
index 00000000000..49af71fb8b8
--- /dev/null
+++ b/library/ZendAfi/View/Helper/TagLivreNumerique.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_TagLivreNumerique extends ZendAfi_View_Helper_TagRessourceNumerique {
+	use Trait_Translator;
+	
+	public function tagLivreNumerique($album) {
+		$current_user = Class_Users::getIdentity();
+/*		if (!$this->canAccessRessourceNumerique())
+			return '<p>'.$this->_('Vous devez être connecté sous un compte avec abonnement valide pour pouvoir accéder au livre numérique').'</p>';
+*/
+
+		$url_album = $album->getExternalUri();
+
+		$numilog = Class_NumilogLink::forUser($current_user);
+
+		
+		return '<a href="'.$numilog->urlExternal($album->getExternalUri()).'">Accéder au livre numérique</a>';
+
+	}
+}
+?>
\ No newline at end of file
diff --git a/tests/application/modules/opac/controllers/AbonneControllerMultimediaTest.php b/tests/application/modules/opac/controllers/AbonneControllerMultimediaTest.php
index fd7f6a3dbd6..99f2539677a 100644
--- a/tests/application/modules/opac/controllers/AbonneControllerMultimediaTest.php
+++ b/tests/application/modules/opac/controllers/AbonneControllerMultimediaTest.php
@@ -533,7 +533,7 @@ abstract class AbonneControllerMultimediaHoldTestCase extends AbstractController
 
 
 /* Premier écran de choix du lieu */
-class AbonneControllerMultimediaHoldLocationTest extends AbonneControllerMultimediaHoldTestCase {
+abstract class AbonneControllerMultimediaHoldLocationTest extends AbonneControllerMultimediaHoldTestCase {
 	public function setUp() {
 		parent::setUp();
 		Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_Location')
diff --git a/tests/library/Class/TypeDocTest.php b/tests/library/Class/TypeDocTest.php
index e4c7c44e1e8..5f327c8cbff 100644
--- a/tests/library/Class/TypeDocTest.php
+++ b/tests/library/Class/TypeDocTest.php
@@ -67,7 +67,7 @@ class TypeDocTest extends Storm_Test_ModelTestCase {
 	function saveNewInstanceVideoShouldUpdateTypesDocsVars() {
 		Class_TypeDoc::newWithLabel('videos')->save();
 
-		$this->assertEquals("0:non identifié\r\n1:livres\r\n2:périodiques\r\n100:Livres numérisés\r\n101:Diaporamas\r\n102:E-Books\r\n103:OAI\r\n104:Arte VOD\r\n105:Formation Vodeclic\r\n106:videos",
+		$this->assertEquals("0:non identifié\r\n1:livres\r\n2:périodiques\r\n100:Livres numérisés\r\n101:Diaporamas\r\n102:E-Books\r\n103:OAI\r\n104:Arte VOD\r\n105:Formation Vodeclic\r\n106:Livres numériques\r\n107:videos",
 													$this->cosmo_types->getListe());
 	}
 
@@ -96,7 +96,7 @@ class TypeDocTest extends Storm_Test_ModelTestCase {
 			->setLabel('CD')
 			->save();
 
-		$this->assertEquals("0:non identifié\r\n1:livres\r\n2:périodiques\r\n100:Livres numérisés\r\n101:Diaporamas\r\n102:E-Books\r\n103:OAI\r\n104:Arte VOD\r\n105:Formation Vodeclic\r\n106:videos\r\n107:CD",
+		$this->assertEquals("0:non identifié\r\n1:livres\r\n2:périodiques\r\n100:Livres numérisés\r\n101:Diaporamas\r\n102:E-Books\r\n103:OAI\r\n104:Arte VOD\r\n105:Formation Vodeclic\r\n106:Livres numériques\r\n107:videos\r\n108:CD",
 												$this->cosmo_types->getListe(),
 												'Current value: '.$this->cosmo_types->getListe());
 	}
diff --git a/tests/library/Class/WebService/NumilogTest.php b/tests/library/Class/WebService/NumilogTest.php
index 6be11ee2797..54e6cf531f4 100644
--- a/tests/library/Class/WebService/NumilogTest.php
+++ b/tests/library/Class/WebService/NumilogTest.php
@@ -109,9 +109,21 @@ class NumilogTest extends Storm_Test_ModelTestCase{
 	}	
 
 
+	/** @test */
+	public function firstAlbumAuteurShouldBeAzzedine (){
+		$this->assertEquals('Saphia Azzeddine',$this->_first_album->getAuteur());
+	}	
+
+
+	/** @test */
+	public function firstAlbumAuteurShouldBeEditeur (){
+		$this->assertEquals('Grasset',$this->_first_album->getEditeur());
+	}	
+
+
 	/** @test */
 	public function firstAlbumTypeDocShouldBeLivre() {
-		$this->assertEquals('Livres Numériques',$this->_first_album->getTypeDoc()->getLabel());
+		$this->assertEquals('Livres numériques',$this->_first_album->getTypeDoc()->getLabel());
 	}
 
 
-- 
GitLab