From b1b1ad14aabc1b12f610954c80703a2c55b811b8 Mon Sep 17 00:00:00 2001
From: gloas <gloas@git-test.afi-sa.fr>
Date: Fri, 12 Apr 2013 15:16:59 +0000
Subject: [PATCH] =?UTF-8?q?Ajout=20=C3=A9crans=20admin=20pour=20moissonage?=
 =?UTF-8?q?=20vod=C3=A9clic?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .gitattributes                                |   6 +
 .../admin/controllers/HarvestController.php   |  27 ++
 .../scripts/harvest/vodeclic-browse.phtml     |   3 +
 .../views/scripts/harvest/vodeclic.phtml      |   1 +
 library/Class/Album.php                       |   1 -
 library/Class/TypeDoc.php                     |  15 +-
 library/Class/WebService/Abstract.php         |   2 +
 .../WebService/BibNumerique/Abstract.php      |  17 +-
 .../Class/WebService/BibNumerique/ArteVOD.php |  18 +-
 .../WebService/BibNumerique/ArteVOD/Film.php  | 157 +----------
 .../BibNumerique/RessourceNumerique.php       |   6 +
 .../WebService/BibNumerique/Vodeclic.php      |  25 +-
 .../BibNumerique/Vodeclic/CatalogueParser.php |  24 +-
 library/Class/WebService/XMLParser.php        |   2 +-
 .../View/Helper/Admin/MenuGaucheAdmin.php     |   3 +-
 public/admin/images/picto/vodeclic_16.png     | Bin 0 -> 709 bytes
 public/admin/images/picto/vodeclic_48.png     | Bin 0 -> 2092 bytes
 public/admin/images/supports/vodeclic.png     | Bin 0 -> 709 bytes
 .../HarvestControllerVodeclicTest.php         | 265 ++++++++++++++++++
 .../library/Class/WebService/ArteVODTest.php  |  11 +-
 20 files changed, 391 insertions(+), 192 deletions(-)
 create mode 100644 application/modules/admin/views/scripts/harvest/vodeclic-browse.phtml
 create mode 100644 application/modules/admin/views/scripts/harvest/vodeclic.phtml
 create mode 100644 public/admin/images/picto/vodeclic_16.png
 create mode 100644 public/admin/images/picto/vodeclic_48.png
 create mode 100644 public/admin/images/supports/vodeclic.png
 create mode 100644 tests/application/modules/admin/controllers/HarvestControllerVodeclicTest.php

diff --git a/.gitattributes b/.gitattributes
index 19564915c62..6dcc0563b47 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -516,6 +516,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/vodeclic-browse.phtml -text
+application/modules/admin/views/scripts/harvest/vodeclic.phtml -text
 application/modules/admin/views/scripts/head.phtml -text
 application/modules/admin/views/scripts/i18n/index.phtml -text
 application/modules/admin/views/scripts/index/adminvar.phtml -text
@@ -3239,6 +3241,8 @@ public/admin/images/picto/utilisateurs.png -text svneol=unset#unset
 public/admin/images/picto/utilisateurs_16.png -text
 public/admin/images/picto/utilisateurs_48.png -text
 public/admin/images/picto/vcard.png -text
+public/admin/images/picto/vodeclic_16.png -text svneol=unset#unset
+public/admin/images/picto/vodeclic_48.png -text svneol=unset#unset
 public/admin/images/picto/web.gif -text
 public/admin/images/picto/website.gif -text
 public/admin/images/plan_acces/icon0.png -text
@@ -3415,6 +3419,7 @@ public/admin/images/supports/vid_s_chap.png -text
 public/admin/images/supports/vid_s_dep.png -text
 public/admin/images/supports/video.gif -text
 public/admin/images/supports/vignette_vide.gif -text
+public/admin/images/supports/vodeclic.png -text svneol=unset#unset
 public/admin/images/zone/color1.gif -text
 public/admin/images/zone/color2.gif -text
 public/admin/images/zone/color3.gif -text
@@ -4960,6 +4965,7 @@ tests/application/modules/admin/controllers/FormationControllerTest.php -text
 tests/application/modules/admin/controllers/FrbrLinkControllerTest.php -text
 tests/application/modules/admin/controllers/FrbrLinktypeControllerTest.php -text
 tests/application/modules/admin/controllers/HarvestControllerTest.php -text
+tests/application/modules/admin/controllers/HarvestControllerVodeclicTest.php -text
 tests/application/modules/admin/controllers/I18nControllerTest.php -text
 tests/application/modules/admin/controllers/ImportFichierCsvElectreTest.php -text
 tests/application/modules/admin/controllers/ImportFichierGenerationSiteTest.php -text
diff --git a/application/modules/admin/controllers/HarvestController.php b/application/modules/admin/controllers/HarvestController.php
index b7d3eb116c7..2d777273515 100644
--- a/application/modules/admin/controllers/HarvestController.php
+++ b/application/modules/admin/controllers/HarvestController.php
@@ -20,6 +20,7 @@
  */
 
 class Admin_HarvestController extends Zend_Controller_Action {
+	
 	public function arteVodAction() {
 		if (!Class_AdminVar::isArteVodEnabled())
 			$this->_redirect('/admin/index');
@@ -44,6 +45,32 @@ class Admin_HarvestController extends Zend_Controller_Action {
 	}
 
 
+	public function vodeclicAction() {
+		if (!Class_AdminVar::isVodeclicEnabled())
+			$this->_redirect('/admin/index');
+
+		$this->view->titre = $this->view->_('Moissonnage Vodeclic');
+		$logger = new Zend_Log();
+		$logger->addWriter(new Zend_Log_Writer_Stream('php://output'));
+		ob_start();
+		$logger->info('Début du moissonnage');
+		
+		$service = new Class_WebService_BibNumerique_Vodeclic();
+		$service->setLogger($logger);
+		$service->harvest(['partenaire_id'=>Class_AdminVar::get('VODECLIC_ID'),
+											 'key'=>Class_AdminVar::get('VODECLIC_KEY'),
+											 'bib_id'=>Class_AdminVar::get('VODECLIC_BIB_ID')]);
+
+		$logger->info('Fin du moissonnage');
+		
+		$this->view->log = ob_get_clean();
+	}
+
+
+	public function vodeclicBrowseAction() {
+		$this->view->titre = $this->view->_('Moissonnage Vodeclic');
+	}
+
 	public function arteVodAjaxAction() {
 		$this->_helper->viewRenderer->setNoRender();
 		if (!Class_AdminVar::isArteVodEnabled())
diff --git a/application/modules/admin/views/scripts/harvest/vodeclic-browse.phtml b/application/modules/admin/views/scripts/harvest/vodeclic-browse.phtml
new file mode 100644
index 00000000000..a1458641eff
--- /dev/null
+++ b/application/modules/admin/views/scripts/harvest/vodeclic-browse.phtml
@@ -0,0 +1,3 @@
+<form id="vodeclic_harvest" action="<?php echo $this->url(['action' => 'vodeclic'])?>" method="get">
+	<input type="submit" value="<?php echo $this->_('Lancer le moissonnage');?>">
+</form>
\ No newline at end of file
diff --git a/application/modules/admin/views/scripts/harvest/vodeclic.phtml b/application/modules/admin/views/scripts/harvest/vodeclic.phtml
new file mode 100644
index 00000000000..d104ffc3aa9
--- /dev/null
+++ b/application/modules/admin/views/scripts/harvest/vodeclic.phtml
@@ -0,0 +1 @@
+<div><pre><?php echo $this->log;?><pre></div>
\ No newline at end of file
diff --git a/library/Class/Album.php b/library/Class/Album.php
index a74f78f7bb2..498e4209fb2 100644
--- a/library/Class/Album.php
+++ b/library/Class/Album.php
@@ -1226,7 +1226,6 @@ class Class_Album extends Storm_Model_Abstract {
 	public function getIdEad() {
 		return  $this->hasIdOrigine() ? $this->getIdOrigine() : "A".$this->getId();
 	}
-
 }
 
 ?>
\ No newline at end of file
diff --git a/library/Class/TypeDoc.php b/library/Class/TypeDoc.php
index 4295135094c..f55cea06db8 100644
--- a/library/Class/TypeDoc.php
+++ b/library/Class/TypeDoc.php
@@ -20,12 +20,14 @@
  */
 
 class TypeDocLoader {
+	
 	protected $_all_instances;
 	
 	public function __construct() {
 		$this->findAll();
 	}
 
+
 	public function newInstance($attributes = null) {
 		$instance = new Class_TypeDoc();
 
@@ -63,9 +65,8 @@ class TypeDocLoader {
 	public function findAll() {
 		if (isset($this->_all_instances))
 			return $this->_all_instances;
-
+	
 		$types_docs = Class_CosmoVar::getLoader()->find('types_docs');
-
 		$lines = explode("\r\n", $types_docs->getListe());
 		$instances = array();
 
@@ -100,7 +101,6 @@ class TypeDocLoader {
 			$serialized []= $this->serialize($model);
 		}
 
-
 		return $this->_saveSerialized($serialized);
 	}
 
@@ -140,7 +140,8 @@ class TypeDocLoader {
 
 
 	public function findUsedTypeDocIds() {
-		$rows = Class_Notice::getTable()->getAdapter()->fetchAll('select distinct(type_doc) from notices');
+		$rows = Class_Notice::getTable()->getAdapter()
+																		->fetchAll('select distinct(type_doc) from notices');
 		return array_map(function($row){return $row['type_doc'];},
 										 $rows);
 	}
@@ -148,7 +149,9 @@ class TypeDocLoader {
 
 
 class Class_TypeDoc extends Storm_Model_Abstract {
-  protected $_loader_class = 'TypeDocLoader';
+ 
+	protected $_loader_class = 'TypeDocLoader';
+	
 	const LIVRE = 1;
 	const PERIODIQUE = 2;
 	const DISQUE = 3;
@@ -163,6 +166,7 @@ class Class_TypeDoc extends Storm_Model_Abstract {
 	const ARTEVOD = 104;
 	const VODECLIC = 105;
 
+	
 	public static function getDefaultTypeDocs() {
 		return [self::LIVRE_NUM => 'Livres numérisés',
 			      self::DIAPORAMA => 'Diaporamas',
@@ -172,6 +176,7 @@ class Class_TypeDoc extends Storm_Model_Abstract {
 						self::VODECLIC => 'Formation Vodeclic'];
 	}
 
+
 	/**
 	 * @param String label
 	 * @return Class_Type_Doc
diff --git a/library/Class/WebService/Abstract.php b/library/Class/WebService/Abstract.php
index b36229b3d02..e617415d978 100644
--- a/library/Class/WebService/Abstract.php
+++ b/library/Class/WebService/Abstract.php
@@ -20,8 +20,10 @@
  */
 
 abstract class Class_WebService_Abstract {
+
 	protected static $_http_client;
 
+
 	public static function setDefaultHttpClient($http_client) {
 		static::$_http_client = $http_client;
 	}
diff --git a/library/Class/WebService/BibNumerique/Abstract.php b/library/Class/WebService/BibNumerique/Abstract.php
index a74fe97bdb8..e6004ce3928 100644
--- a/library/Class/WebService/BibNumerique/Abstract.php
+++ b/library/Class/WebService/BibNumerique/Abstract.php
@@ -20,8 +20,23 @@
  */
 
 abstract class Class_WebService_BibNumerique_Abstract extends Class_WebService_Abstract {
-  abstract public function harvest($params);
+ 	protected $_logger;
+
+	abstract public function harvest($params);
   
+
+	public function setLogger($logger) {
+		$this->_logger = $logger;
+		return $this;
+	}
+
+
+	public function getLogger() {
+		if (null == $this->_logger)
+			return new Zend_Log(new Zend_Log_Writer_Null());
+		return $this->_logger;
+	}
+
 	
 }
 ?>
\ No newline at end of file
diff --git a/library/Class/WebService/BibNumerique/ArteVOD.php b/library/Class/WebService/BibNumerique/ArteVOD.php
index 8f7b675b635..a26caa5d3cf 100644
--- a/library/Class/WebService/BibNumerique/ArteVOD.php
+++ b/library/Class/WebService/BibNumerique/ArteVOD.php
@@ -26,7 +26,6 @@ class Class_WebService_BibNumerique_ArteVOD extends Class_WebService_BibNumeriqu
 	protected static $_harvested_ids_cache;
 
 	protected $web_client;
-	protected $_logger;
 	protected $_harvested_ids = array();
 
 	const BASE_URL = 'http://www.mediatheque-numerique.com/ws/';
@@ -74,19 +73,6 @@ class Class_WebService_BibNumerique_ArteVOD extends Class_WebService_BibNumeriqu
 	}
 
 
-	public function setLogger($logger) {
-		$this->_logger = $logger;
-		return $this;
-	}
-
-
-	public function getLogger() {
-		if (null == $this->_logger)
-			return new Zend_Log(new Zend_Log_Writer_Null());
-		return $this->_logger;
-	}
-
-
 	public function harvest($params) {
 		$current_page = 1;
 		$total_page = 0;
@@ -220,4 +206,6 @@ class Class_WebService_BibNumerique_ArteVOD extends Class_WebService_BibNumeriqu
 	public function getBaseUrl() {
 		return self::BASE_URL;
 	}
-}
\ No newline at end of file
+}
+
+?>
\ No newline at end of file
diff --git a/library/Class/WebService/BibNumerique/ArteVOD/Film.php b/library/Class/WebService/BibNumerique/ArteVOD/Film.php
index b508f74ff92..e0650ca8642 100644
--- a/library/Class/WebService/BibNumerique/ArteVOD/Film.php
+++ b/library/Class/WebService/BibNumerique/ArteVOD/Film.php
@@ -32,159 +32,6 @@ class Class_WebService_BibNumerique_ArteVOD_Film  extends Class_WebService_BibNu
 	protected $_photos = array();
 
 
-/*	public function setId($id) {
-		$this->_id = $id;
-		return $this;
-	}
-
-
-	public function getId() {
-		return $this->_id;
-	}
-
-
-	public function setExternalUri($uri) {
-		$this->_external_uri = $uri;
-		return $this;
-	}
-
-
-	public function getExternalUri() {
-		return $this->_external_uri;
-	}
-
-
-	public function setTitle($title) {
-		$this->_title = $title;
-		return $this;
-	}
-
-
-	public function getTitle() {
-		return trim($this->_title);
-	}
-
-
-	public function setDescription($description) {
-		$this->_description = $description;
-		return $this;
-	}
-
-
-	public function getDescription() {
-		return $this->_description;
-	}
-
-
-	public function setYear($year) {
-		$this->_year = $year;
-		return $this;
-	}
-
-
-	public function getYear() {
-		return $this->_year;
-	}
-*/
-
-
-/*
-	public function addAuthor($author) {
-		$this->_authors[] = $author;
-		return $this;
-	}
-
-
-	public function getAuthors() {
-		return $this->_authors;
-	}
-
-
-	public function addPoster($url) {
-		$this->_posters[] = $url;
-		return $this;
-	}
-
-
-	public function getPosters() {
-		return $this->_posters;
-	}
-
-
-	public function addTrailer($url) {
-		$this->_trailers[] = $url;
-		return $this;
-	}
-
-
-	public function getTrailers() {
-		return $this->_trailers;
-	}
-
-
-	public function addPhoto($url) {
-		$this->_photos[] = $url;
-		return $this;
-	}
-
-	public function getPhotos() {
-		return $this->_photos;
-	}
-*/
-
-
-/*
-	public function import() {
-		if ($this->isAlreadyHarvested())
-			return;
-
-		$category = $this->_ensureArteVODCategory();
-		$album = Class_Album::getLoader()->newInstance()
-			->setTitre($this->getTitle())
-			->setAuteur(implode(', ', $this->getAuthors()))
-			->setAnnee($this->getYear())
-			->setIdOrigine($this->getId())
-			->setUrlOrigine(Class_WebService_ArteVOD::BASE_URL)
-			->setCategorie($category)
-			->beArteVOD();
-
-		$this->updateAlbumNotes($album);
-
-		if ($album->save())
-			Class_WebService_Album_Vignette::getInstance()->updateAlbum($album);
-	}
-*/
-
-
-
-	public function isAlreadyHarvested() {
-		$album = Class_Album::getLoader()
-			->findFirstBy(array('url_origine' => Class_WebService_BibNumerique_ArteVOD::BASE_URL,
-													'id_origine' => $this->_id));
-
-		return (null != $album);
-	}
-
-
-
-/*
-	public function updateAlbumNotes($album) {
-		$notes = array();
-		foreach ($this->_posters as $url)
-		  $album->addPosterUri($url);
-
-		foreach ($this->_trailers as $url)
-		  $album->addTrailerUri($url);
-		  
-		foreach ($this->_photos as $url)
-		  $album->addPhotoUri($url);
-		
-		$album->setExternalUri($this->_external_uri);
-		return $this;
-	}
-*/
-
-
   public function fillAlbum($album) {
 		$album->beArteVOD()
 					->setAuteur(implode(', ', $this->getAuthors()));
@@ -199,4 +46,6 @@ class Class_WebService_BibNumerique_ArteVOD_Film  extends Class_WebService_BibNu
 	public function getBaseUrl(){
 		return Class_WebService_BibNumerique_ArteVOD::BASE_URL;
 	}
-}
\ No newline at end of file
+}
+
+?>
\ No newline at end of file
diff --git a/library/Class/WebService/BibNumerique/RessourceNumerique.php b/library/Class/WebService/BibNumerique/RessourceNumerique.php
index e9dcbee5934..15b3404fab7 100644
--- a/library/Class/WebService/BibNumerique/RessourceNumerique.php
+++ b/library/Class/WebService/BibNumerique/RessourceNumerique.php
@@ -213,6 +213,12 @@ abstract class Class_WebService_BibNumerique_RessourceNumerique {
 	}
 
 
+	public function isAlreadyHarvested() {
+		$album = $this->findAlbumInDB();
+		return (null != $album);
+}
+
+
 	public function updateRessourceNumeriqueNotes($ressource_numerique) {
 		$notes = array();
 		foreach ($this->_posters as $url)
diff --git a/library/Class/WebService/BibNumerique/Vodeclic.php b/library/Class/WebService/BibNumerique/Vodeclic.php
index 3cb33922262..20fc57546ff 100644
--- a/library/Class/WebService/BibNumerique/Vodeclic.php
+++ b/library/Class/WebService/BibNumerique/Vodeclic.php
@@ -21,8 +21,10 @@
 
 class Class_Webservice_BibNumerique_Vodeclic extends Class_WebService_BibNumerique_Abstract {
 	
+
 	const BASE_URL = "https://lms.vodeclic.com/api/catalogue.xml?";
 
+
 	protected $_albums;
 
 
@@ -36,13 +38,31 @@ class Class_Webservice_BibNumerique_Vodeclic extends Class_WebService_BibNumeriq
 		}
 	}
 
-  //$partenaire_id,$key,$bib_id
+
 	public function harvest($params) {
 		$http_client = self::getHttpClient();
 		$content = $http_client->open_url($this->url($params['partenaire_id'],
 																								 $params['key'],
 																								 $params['bib_id']));
-		$catalogue = $this->parseXML($content);	
+		if (!$content) {
+			$this->getLogger()->err('Erreur de communication');
+			return;
+		}
+			
+		$this->getLogger()->info('Réponse reçue');
+		$this->parseXML($content);	
+		$this->_deleteNonHarvested();
+		$this->getLogger()->info(sprintf('%d formations dans la base', count($this->_albums)));
+	}
+
+
+	protected function _deleteNonHarvested() {
+		$ids = [];
+		foreach($this->_albums as $album)
+			$ids []= $album->getIdOrigine();
+
+		Class_Album::deleteBy(['url_origine = \'' . self::BASE_URL . '\'',
+													 'id_origine not in (\'' . implode("', '", $ids) . '\')']);
 	}
 
 
@@ -67,7 +87,6 @@ class Class_Webservice_BibNumerique_Vodeclic extends Class_WebService_BibNumeriq
 	}
 
 
-
 	public function encryptedPartenaire($partenaire_id,$key){
 		$hash = Class_Hash::sha256WithKey('');
 		return $hash->encrypt($partenaire_id.$key);
diff --git a/library/Class/WebService/BibNumerique/Vodeclic/CatalogueParser.php b/library/Class/WebService/BibNumerique/Vodeclic/CatalogueParser.php
index a1872d0b36d..3878afe9d2a 100644
--- a/library/Class/WebService/BibNumerique/Vodeclic/CatalogueParser.php
+++ b/library/Class/WebService/BibNumerique/Vodeclic/CatalogueParser.php
@@ -20,9 +20,11 @@
  */
 
 class Class_WebService_BibNumerique_Vodeclic_CatalogueParser {
-	protected   	
-	  $_formations,
-	  $_current_formation;
+	
+
+	protected	$_formations=[];
+	protected $_current_formation;
+
 
 	public function parseXML($xml) {
 		$parser = new Class_WebService_XMLParser();
@@ -30,6 +32,7 @@ class Class_WebService_BibNumerique_Vodeclic_CatalogueParser {
 		$parser->parse($xml);
 	}
 
+
 	public function getFormations() {
 		return $this->_formations;
 	}
@@ -45,42 +48,45 @@ class Class_WebService_BibNumerique_Vodeclic_CatalogueParser {
 		$this->_current_formation->setTitle($data);
 	}
 
+
 	public function endVodeclic_id($data) {
 		$this->_current_formation->setId($data);
 	}
 
+
 	public function endLink($data) {
 		$this->_current_formation->setExternalUri($data);
 	}
 	
+
 	public function endDescription($data) {
 		$this->_current_formation->setDescription($data);
 	}
 
 
-	/** Initialisation du parametre Id_Langue a fre  */
+	/** Initialisation du parametre id_Langue a fre  */
 	public function endLanguage($data) {
 		$idLangue='fre';
 		if($data=='fr'){
-		$idLangue='fre';
-	}
+			$idLangue='fre';
+		}
 		$this->_current_formation->setIdLangue($idLangue);
 	}
+
 	
 	public function endPublishdate($data){
 		$this->_current_formation->setDateMaj($data);
 	}
 
+
 	public function endPublishyear($data) {
 		$this->_current_formation->setAnnee($data);
 	}
 
+
 	public function endImage_jacket_url($data) {
 		$this->_current_formation->addPoster($data);
 	}
-
-
 }
 
-
 ?>
\ No newline at end of file
diff --git a/library/Class/WebService/XMLParser.php b/library/Class/WebService/XMLParser.php
index 486cd8d5b23..e8be1bad8ae 100644
--- a/library/Class/WebService/XMLParser.php
+++ b/library/Class/WebService/XMLParser.php
@@ -20,6 +20,7 @@
  */
 
 class Class_WebService_XMLParser {
+
 	protected $_current_data ;
 	protected $_parents ;
 	protected $_element_handler ;
@@ -133,7 +134,6 @@ class Class_WebService_XMLParser {
 	}
 
 
-
 	/**
 	 * @param string $tag
 	 * @return string
diff --git a/library/ZendAfi/View/Helper/Admin/MenuGaucheAdmin.php b/library/ZendAfi/View/Helper/Admin/MenuGaucheAdmin.php
index 76e6a27b54a..c9dc51f4081 100644
--- a/library/ZendAfi/View/Helper/Admin/MenuGaucheAdmin.php
+++ b/library/ZendAfi/View/Helper/Admin/MenuGaucheAdmin.php
@@ -71,9 +71,10 @@ class ZendAfi_View_Helper_Admin_MenuGaucheAdmin extends ZendAfi_View_Helper_Base
 
 		$menu_bibnum = '';
 		$menu_bibnum .= $this->openBoite($this->translate()->_("Bibliothèque numérique"));
-		if (Class_AdminVar::isBibNumEnabled() || Class_AdminVar::isArteVODEnabled()) {
+		if (Class_AdminVar::isBibNumEnabled() || Class_AdminVar::isArteVODEnabled() || Class_AdminVar::isVodeclicEnabled()) {
 			$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);
 			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/public/admin/images/picto/vodeclic_16.png b/public/admin/images/picto/vodeclic_16.png
new file mode 100644
index 0000000000000000000000000000000000000000..04ab06b0b2de265b33b05dd07b8d786eacaf733e
GIT binary patch
literal 709
zcmV;$0y_PPP)<h;3K|Lk000e1NJLTq000mG000mO1^@s6AM^iV00006VoOIv0RI60
z0RN!9r;`8x010qNS#tmY3ljhU3ljkVnw%H_000McNliru-2@B?85~{ma`6BF0#Zpt
zK~y-)m6J_RQ&A9xpE<p4DYT?D1VTiNi17o6x<M8$z_@VXQdqe$QGWu7|HH(%a4+b>
z#Dy3V7lt4#h$I?<L_uNzZ5w*&2eiGnXIxylQdv2>Gc)JS%#(Ly<KC0UeztU9g#QXv
z71J7<cl>Pep@>A)Z=ekefH)B(Vwyi#MLj>L8$qHDcE3LA2#ER(l4AoThtC2~o?oLp
z_XUg~BB(0yGo57a45O;l*R$+SEnwmf4ge8@w_PAPdI^B|`EH7{pNJ$|Kta6*?YFOn
z^_};tNHl_~VgN)0|CfuOFQTeMyEDZ5I)kxMXejMB2LWgl52&qYgEd4jh$ukA-KVyZ
zL;lcAkB@-0V3pL^MZ}2!;AM;WyX63kfT?d6u$3xm6?b|egq9fSK@u?lQn#*z`O@2E
zwCZ6iHR@X~M(aLau7v;7#eKbmpDzL6bfgdjtR>cSA{59!eTSdj!^;)Xx`z=7c0oZ9
z3NID`Fo_uPb6pUR;&h|{*n6{#t=5BHIb?7oB<4_@Sw{T^0GYejX}>WTdZIA(0f|SO
z{NeoLF1#HVZ>vD;bO(tGCu!;H0>ICesDI0XRn!o|Zk|8{Tdq=B{2IKY5lmYgfP>X7
zynKoD#5J6B8>)I-AjlYYpU;OA9X7fz7wCQVfOKC!{WFiys{hwWO;Z@*;NvE>@3{~Z
zfct6*0i-nwR)IiRR)!|MqbyVvRB0JFMeF5WP^Gq+r!uz&1~L;Plx9EUyA>4?k(Hsz
rX<+==x!OSJ&~ai+AZ|50GT_H=&43bZm?zh_00000NkvXXu0mjf0BJ6|

literal 0
HcmV?d00001

diff --git a/public/admin/images/picto/vodeclic_48.png b/public/admin/images/picto/vodeclic_48.png
new file mode 100644
index 0000000000000000000000000000000000000000..b3612ff43700f65e03507704b37c084982001d91
GIT binary patch
literal 2092
zcmV+{2-Ek8P)<h;3K|Lk000e1NJLTq001xm001xu1^@s6R|5Hm00006VoOIv0RI60
z0RN!9r;`8x010qNS#tmY3ljhU3ljkVnw%H_000McNliru-2@B?7&#B^m-hew2f0Z^
zK~!ko)tXyu6z3Jke`jX);`I$<jDdi;r-T9$1XV;zfi@+o)T*f>MXjnztyDF6i2Bf%
zDvy0_tLCYy5~)%nwTTpncnFawG(;q%fj}`=V_VQb0~l<K_kNw3@AP5U2E)#**M`U)
zX|)ggeczn_`Jel@qN?jB{&uV{edzqlCR^O4N=!hR$B)>OvKM#mUG&Ru@0IblKK@Q>
z|H;3rXL=D3=JzwDSyimo_)#Zw==`hdn_jU*Yd_9w3^IvB1XC#Qc1*ssbMm+OuKfpb
zhzOP%jr|`9{?OwD3a>h2PnOwo_XytM1RiV&Vy3xGpi`;ptU%~Y9nKQe)PIK)=;^M{
z+Jmn(JUesnEMtE<+_dYfQ6fF<toZXUuoBVGwWGg(pUjZ~B>J$pRuEn48B+UC)(8n^
zA-c8~r>nJj^D%~&Eq#b%g)hsO$sQd<B6fXp0&Onpkp7^*p^eAaFU9U|3k6yC{D?z*
z<MO&%y+7b*KN>(?KTw8X0G8m5=O|yk7080Bf<R*1>ZS>>yAs5nT-q?;rw^PC1{nrm
z(wVbI2LrRjq*mH@Kh;!3QB|Ct4q|H-2fi1ee02=>Rtm9Xb^uhB(#0E?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000000000000000000000000000000000000000..04ab06b0b2de265b33b05dd07b8d786eacaf733e
GIT binary patch
literal 709
zcmV;$0y_PPP)<h;3K|Lk000e1NJLTq000mG000mO1^@s6AM^iV00006VoOIv0RI60
z0RN!9r;`8x010qNS#tmY3ljhU3ljkVnw%H_000McNliru-2@B?85~{ma`6BF0#Zpt
zK~y-)m6J_RQ&A9xpE<p4DYT?D1VTiNi17o6x<M8$z_@VXQdqe$QGWu7|HH(%a4+b>
z#Dy3V7lt4#h$I?<L_uNzZ5w*&2eiGnXIxylQdv2>Gc)JS%#(Ly<KC0UeztU9g#QXv
z71J7<cl>Pep@>A)Z=ekefH)B(Vwyi#MLj>L8$qHDcE3LA2#ER(l4AoThtC2~o?oLp
z_XUg~BB(0yGo57a45O;l*R$+SEnwmf4ge8@w_PAPdI^B|`EH7{pNJ$|Kta6*?YFOn
z^_};tNHl_~VgN)0|CfuOFQTeMyEDZ5I)kxMXejMB2LWgl52&qYgEd4jh$ukA-KVyZ
zL;lcAkB@-0V3pL^MZ}2!;AM;WyX63kfT?d6u$3xm6?b|egq9fSK@u?lQn#*z`O@2E
zwCZ6iHR@X~M(aLau7v;7#eKbmpDzL6bfgdjtR>cSA{59!eTSdj!^;)Xx`z=7c0oZ9
z3NID`Fo_uPb6pUR;&h|{*n6{#t=5BHIb?7oB<4_@Sw{T^0GYejX}>WTdZIA(0f|SO
z{NeoLF1#HVZ>vD;bO(tGCu!;H0>ICesDI0XRn!o|Zk|8{Tdq=B{2IKY5lmYgfP>X7
zynKoD#5J6B8>)I-AjlYYpU;OA9X7fz7wCQVfOKC!{WFiys{hwWO;Z@*;NvE>@3{~Z
zfct6*0i-nwR)IiRR)!|MqbyVvRB0JFMeF5WP^Gq+r!uz&1~L;Plx9EUyA>4?k(Hsz
rX<+==x!OSJ&~ai+AZ|50GT_H=&43bZm?zh_00000NkvXXu0mjf0BJ6|

literal 0
HcmV?d00001

diff --git a/tests/application/modules/admin/controllers/HarvestControllerVodeclicTest.php b/tests/application/modules/admin/controllers/HarvestControllerVodeclicTest.php
new file mode 100644
index 00000000000..36a807de800
--- /dev/null
+++ b/tests/application/modules/admin/controllers/HarvestControllerVodeclicTest.php
@@ -0,0 +1,265 @@
+<?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 
+ */
+
+require_once 'AdminAbstractControllerTestCase.php';
+
+abstract class HarvestControllerVodeclicTestCase extends Admin_AbstractControllerTestCase {
+
+	protected $_web_client;
+
+	public function setUp() {
+		parent::setUp();
+
+		$this->_web_client = Storm_Test_ObjectWrapper::mock()
+		->whenCalled('open_url')->answers('');
+		
+		Class_WebService_BibNumerique_Vodeclic::setDefaultHttpClient($this->_web_client);
+		Class_WebService_BibNumerique_Vignette::setInstance(Storm_Test_ObjectWrapper::mock()
+																								 ->whenCalled('updateAlbum')
+																								 ->answers(true));
+
+	}
+
+}
+abstract class HarvestControllerVodeclicNotActivatedTestCase extends HarvestControllerVodeclicTestCase {
+	public function setUp() {
+		parent::setUp();
+		Class_AdminVar::getLoader()
+			->newInstanceWithId('VODECLIC_KEY')
+			->setValeur('');
+	}
+}
+
+
+
+abstract class HarvestControllerVodeclicActivatedTestCase extends HarvestControllerVodeclicTestCase {
+	
+	protected $_partenaire_id = 'api-test';
+	protected $_key  = '6m5js1dPpFNrtAJbsfXO';
+	protected	$_bib_id = "12";
+
+	public function setUp() {
+		parent::setUp();
+	Class_AdminVar::newInstanceWithId('VODECLIC_ID', ['valeur' => 'api-test']);	
+	Class_AdminVar::newInstanceWithId('VODECLIC_KEY', ['valeur' => '6m5js1dPpFNrtAJbsfXO']);	
+	Class_AdminVar::newInstanceWithId('VODECLIC_BIB_ID', ['valeur' => '12']);	
+
+	}
+}
+
+
+
+abstract class HarvestControllerVodeclicWithFormationTestCase extends HarvestControllerVodeclicActivatedTestCase {
+	
+	protected $_categoryWrapper;
+	protected $_albumWrapper;
+	
+	public function setUp(){
+		parent::setUp();
+
+	$this->_web_client
+		->whenCalled('open_url')
+		->with('https://lms.vodeclic.com/api/catalogue.xml?partenaire=api-test&encrypted_partenaire=f13eba4953115a58bdf7952266ecca9fee8f91ddac6ac901042fdb188db02778&bib_id=12')
+		->answers(HarvestVodeclicFixtures::catalogueXML());
+		
+
+		$this->_categoryWrapper = Storm_Test_ObjectWrapper::onLoaderOfModel('Class_AlbumCategorie')
+			->whenCalled('findFirstBy')->answers(null)
+			->whenCalled('save')->answers(true);
+
+
+		$this->_albumWrapper =Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Album')
+		->whenCalled('save')->answers(true)
+		->whenCalled('findFirstBy')->answers(null)
+		->whenCalled('deleteBy')->answers(null);
+	}
+}
+
+
+
+class HarvestControllerVodeclicActionNotActivatedTest extends HarvestControllerVodeclicNotActivatedTestCase {
+	public function setUp() {
+		parent::setUp();
+		$this->dispatch('/admin/harvest/vodeclic', true);
+	}
+
+
+	/** @test */
+	public function shouldRedirect() {
+		$this->assertRedirectTo('/admin/index');
+	}
+}
+
+
+
+class HarvestControllerVodeclicActivatedWithErrorTest extends HarvestControllerVodeclicActivatedTestCase {
+	public function setUp() {
+		parent::setUp();
+		$this->_web_client
+		  ->whenCalled('open_url')
+			->with('https://lms.vodeclic.com/api/catalogue.xml?partenaire=api-test&encrypted_partenaire=f13eba4953115a58bdf7952266ecca9fee8f91ddac6ac901042fdb188db02778&bib_id=12')
+		  ->answers('');
+
+		$this->dispatch('/admin/harvest/vodeclic', true);		
+	}
+
+
+	/** @test */
+	public function shouldLogHarvestStart() {
+		$this->assertXPathContentContains('//div', 'Début du moissonnage');
+	}
+
+
+	/** @test */
+	public function shouldLogHarvestError() {
+		$this->assertXPathContentContains('//div', 'Erreur de communication');
+	}
+}
+
+
+
+
+class HarvestControllerVodeclicActivatedWithFormationsTest extends HarvestControllerVodeclicWithFormationTestCase {
+	public function setUp() {
+		parent::setUp();
+		$this->dispatch('/admin/harvest/vodeclic', true);		
+	}
+
+
+	/** @test */
+	public function shouldLogReceivedResponse() {
+		$this->assertXPathContentContains('//div', 'Réponse reçue');
+	}
+
+
+	/** @test */
+	public function shouldLogTotalCount() {
+		$this->assertXPathContentContains('//div', '2 formations dans la base');
+	}
+
+	/** @test */
+	public function shouldDeleteNotHarvestedIds() {
+		$this->assertTrue($this->_albumWrapper->methodHasBeenCalled('deleteBy'));
+		$parameter = $this->_albumWrapper->getFirstAttributeForLastCallOn('deleteBy');
+		$this->assertEquals(2, count($parameter));
+		$this->assertTrue(false !== strpos($parameter[0], Class_WebService_BibNumerique_Vodeclic::BASE_URL));
+		$this->assertTrue(false !== strpos($parameter[1], "not in ('4', '35')"), $parameter[1]);
+	}
+}
+
+
+
+
+class HarvestControllerVodeclicBrowse extends HarvestControllerVodeclicWithFormationTestCase {
+	public function setUp() {
+		parent::setUp();
+		$this->dispatch('/admin/harvest/vodeclic-browse', true);		
+	}
+
+
+	/** @test */
+	public function buttonShouldOpenVodeclicAction() {
+		$this->assertXPath('//form[contains(@action, "admin/harvest/vodeclic")][@method="get"]');
+	}
+}
+
+
+
+class HarvestVodeclicFixtures {
+	public static function catalogueXML() {
+		return '<?xml version="1.0" encoding="UTF-8"?>    
+    <data>
+       <formations>
+        <formation>
+            <vodeclic_id>4</vodeclic_id>
+            <link>http://biblio.vodeclic.com/formation/4</link>
+            <titre>Windows Mail (Vista)</titre>
+            <duree>1h19</duree>
+            <description>Le parcours pédagogique intégral sur Windows Mail ...</description>
+            <nb_formations>21 formations</nb_formations>
+            <language>fr</language>
+            <publishDate>2007-08-06T00:00:00+02:00</publishDate>
+            <publishYear>2007</publishYear>
+            <image_jacket_url>http://biblio.vodeclic.com/system/data_db/metasujet/imageproduits/4/original/windows-mail_27768_0.jpg</image_jacket_url>
+        </formation>
+            
+        <formation>
+            <vodeclic_id>35</vodeclic_id>
+            <link>http://biblio.vodeclic.com/formation/5</link>
+            <titre>Outlook Express 6</titre>
+            <duree>1h24</duree>
+            <description>Outlook Express 6 est le logiciel …</description>
+            <nb_formations>27 formations</nb_formations>
+            <language>fr</language>
+            <publishDate>2007-09-06T00:00:00+02:00</publishDate>
+            <publishYear>2007</publishYear>
+            <image_jacket_url>http://biblio.vodeclic.com/system/data_db/metasujet/imageproduits/5/original/outlookexpress6_27768_0.jpg</image_jacket_url>
+        </formation>
+    </formations>
+  </data>';
+	}
+}
+
+
+/*
+class HarvestControllerVodeclicAjaxNotActivatedTest extends HarvestControllerVodeclicNotActivatedTestCase {
+	public function setUp() {
+		parent::setUp();
+		$this->dispatch('/admin/harvest/vodeclic-ajax', true);
+	}
+
+
+	/** @test *//*
+	public function shouldReturnEmptyResponse() {
+		$this->assertEquals('', $this->_response->getBody());
+	}
+}
+
+
+
+class HarvestControllerVodeclicAjaxFirstPageTest extends HarvestControllerVodeclicWithFormationTestCase {
+	protected $_json;
+	public function setUp() {
+		parent::setUp();
+		$this->dispatch('/admin/harvest/vodeclic-ajax', true);
+		$this->_json = json_decode($this->_response->getBody());
+	}
+
+
+	/** @test *//*
+	public function responseShouldContainFormationsCount() {
+		$this->assertEquals(1, $this->_json->total_count);
+	}
+
+
+/** @test *//*
+	public function responseShouldContainCurrentPage() {
+		$this->assertEquals(1, $this->_json->current_page);
+	}
+
+
+	/** @test *//*
+	public function responseShouldNotHaveNextPage() {
+		$this->assertFalse($this->_json->has_next);
+	}
+	}*/
+
+?>
\ No newline at end of file
diff --git a/tests/library/Class/WebService/ArteVODTest.php b/tests/library/Class/WebService/ArteVODTest.php
index 68e03d080ab..c535cfae550 100644
--- a/tests/library/Class/WebService/ArteVODTest.php
+++ b/tests/library/Class/WebService/ArteVODTest.php
@@ -18,12 +18,15 @@
  * 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 
  */
+
+
 require_once 'ArteVODFixtures.php';
 
 abstract class ArteVODHarverstingTestCase extends Storm_Test_ModelTestCase {
 	protected $_web_client;
 
 	public function setUp() {
+		
 		parent::setUp();
 
 		Class_AdminVar::getLoader()
@@ -49,6 +52,7 @@ abstract class ArteVODHarverstingTestCase extends Storm_Test_ModelTestCase {
 
 
 class ArteVODHarverstingTwoFilmsInTwoPages extends ArteVODHarverstingTestCase {
+	
 	protected $_category_wrapper;
 	protected $_album_wrapper;
 
@@ -109,6 +113,9 @@ class ArteVODHarverstingTwoFilmsInTwoPages extends ArteVODHarverstingTestCase {
 
 	/** @test */
 	public function vignetteShouldHaveBeenUploaded() {
-		$this->assertTrue(Class_WebService_BibNumerique_Vignette::getInstance()->methodHasBeenCalled('updateAlbum'));
+		$this->assertTrue(Class_WebService_BibNumerique_Vignette::getInstance()
+											->methodHasBeenCalled('updateAlbum'));
 	}
-}
\ No newline at end of file
+}
+
+?>
\ No newline at end of file
-- 
GitLab