From 7510b316c0957ef2b02ba4a05f8a1aa281237bd2 Mon Sep 17 00:00:00 2001
From: gloas <gloas@git-test.afi-sa.fr>
Date: Wed, 5 Jun 2013 17:08:26 +0000
Subject: [PATCH] Skin: resultat mur :  amelioration affichage tooltip du
 resume et de la dispo , ajout de la barre de lien.

---
 .../opac/controllers/NoticeajaxController.php | 10 +++
 library/Class/Notice.php                      |  8 +++
 library/ZendAfi/View/Helper/Avis.php          | 18 +++++
 library/ZendAfi/View/Helper/ListeNotices.php  |  3 +-
 library/ZendAfi/View/Helper/Notice/Mur.php    | 47 ++++++++++---
 .../ZendAfi/View/Helper/Notice/Vignette.php   |  1 -
 public/opac/js/liste_notices_mur.js           | 38 ++++++++---
 .../controllers/NoticeAjaxControllerTest.php  | 48 +++++++++++++
 .../ZendAfi/View/Helper/Notice/MurTest.php    | 68 ++++++++++++++++++-
 9 files changed, 215 insertions(+), 26 deletions(-)

diff --git a/application/modules/opac/controllers/NoticeajaxController.php b/application/modules/opac/controllers/NoticeajaxController.php
index 77f9d431289..484b256d191 100644
--- a/application/modules/opac/controllers/NoticeajaxController.php
+++ b/application/modules/opac/controllers/NoticeajaxController.php
@@ -357,7 +357,17 @@ class NoticeAjaxController extends Zend_Controller_Action {
 		$this->_sendResponse($html);
 	}
 
+	public function avisAbonneAction() {
+		$notice = Class_Notice::getLoader()->find($this->id_notice);
+		$html = $this->view->getHelper('Avis')->getAvisPopup($notice, $notice->getAvisAbonne());
+		$this->_sendResponse($html);
+	}
 
+	public function avisBibliothecaireAction() {
+		$notice = Class_Notice::getLoader()->find($this->id_notice);
+		$html = $this->view->getHelper('Avis')->getAvisPopup($notice, $notice->getAvisBibliothecaire());
+		$this->_sendResponse($html);
+	}
 
 
 	public function babelthequeAction() {
diff --git a/library/Class/Notice.php b/library/Class/Notice.php
index 062dc749b05..6734b9d6920 100644
--- a/library/Class/Notice.php
+++ b/library/Class/Notice.php
@@ -271,11 +271,19 @@ class Class_Notice extends Storm_Model_Abstract {
 		return Class_AvisNotice::filterByBibliothequaire($this->getAvis());
 	}
 
+	public function numberOfAvisBibliothecaire() {
+		return Class_AvisNotice::countBy(['abon_ou_bib' => 1, 'clef_oeuvre' => $this->getClefOeuvre()]);
+	}
+
 	public function getAvisAbonnes()
 	{
 		return Class_AvisNotice::filterByAbonne($this->getAvis());
 	}
 
+	public function numberOfAvisAbonne() {
+		return Class_AvisNotice::countBy(['abon_ou_bib' => 0, 'clef_oeuvre' => $this->getClefOeuvre()]);
+	}
+
 	public function getNoteMoyenneAvisBibliothequaires()
 	{
 		return Class_AvisNotice::getNoteAverage($this->getAvisBibliothequaires());
diff --git a/library/ZendAfi/View/Helper/Avis.php b/library/ZendAfi/View/Helper/Avis.php
index 86157c7dbea..c9642367ac1 100644
--- a/library/ZendAfi/View/Helper/Avis.php
+++ b/library/ZendAfi/View/Helper/Avis.php
@@ -118,6 +118,24 @@ class ZendAfi_View_Helper_Avis extends ZendAfi_View_Helper_BaseHelper {
 	}
 
 
+	public function getAvisPopup($notice, $avis) {
+		$html = '<ul>';
+		foreach($avis as $item)
+			$html .= $this->renderOneAvisPopup($item);
+		return $html .= '</ul>';
+	}
+
+
+	public function renderOneAvisPopup($avis) {
+		return '<li>' 
+			. $this->view->noteImg($avis->getNote()) 
+			. $avis->getReadableDateAvis()
+			. $avis->getEntete()
+			. $avis->getAvis()
+			. '</li>';
+	}
+
+
 	protected function _getModerationTag($avis) {
 		if ($avis->isWaitingForModeration())
 			return sprintf('<div class="moderation">%s</div>', 
diff --git a/library/ZendAfi/View/Helper/ListeNotices.php b/library/ZendAfi/View/Helper/ListeNotices.php
index 9e79054c081..2b67f7a604f 100644
--- a/library/ZendAfi/View/Helper/ListeNotices.php
+++ b/library/ZendAfi/View/Helper/ListeNotices.php
@@ -240,7 +240,8 @@ class ZendAfi_View_Helper_ListeNotices extends ZendAfi_View_Helper_BaseHelper {
 			->addInlineScript("var resumeAjaxBaseUrl='".$this->view->url(['controller' => 'noticeajax', 'action' => 'resumenotice'])."';")
 			->addInlineScript("var disponibiliteAjaxBaseUrl='".$this->view->url(['controller' => 'noticeajax', 'action' => 'dispo-notice'], null, true)."';")
 			->addOPACScript('liste_notices_mur')
-			->addJQueryReady("vignetteHover($('.liste_mur .notice[data-id]'));");
+			->addJQueryReady("vignetteHover($('.liste_mur .notice[data-id]'));")
+			->loadPrettyPhoto();
 		
 		$notices = [];
 		foreach($data as $notice)
diff --git a/library/ZendAfi/View/Helper/Notice/Mur.php b/library/ZendAfi/View/Helper/Notice/Mur.php
index 76cb58e6f80..d4eb0e42a10 100644
--- a/library/ZendAfi/View/Helper/Notice/Mur.php
+++ b/library/ZendAfi/View/Helper/Notice/Mur.php
@@ -20,8 +20,6 @@
  */
 class ZendAfi_View_Helper_Notice_Mur extends Zend_View_Helper_HtmlElement {
 	public function notice_Mur($notice) {
-		$vignette = $this->view->notice_Vignette($notice);
-
 		$datas = sprintf('<span><a href="%s">%s</a></span>',
 										 $this->view->urlNotice($notice),
 										 $notice->getTitreEtSousTitre());
@@ -30,17 +28,44 @@ class ZendAfi_View_Helper_Notice_Mur extends Zend_View_Helper_HtmlElement {
 											$this->view->notice_LienRebondAuteur($notice),
 											$notice->getAuteurPrincipal());
 
-
-        $html= 
-            '<div class="notice_wrapper">'.
-            '<div class="notice" data-id="'.$notice->getId().'" data-type="'.$notice->getTypeDoc().'">'.
+        $html= '<div class="notice_wrapper">';
+        $html.='<div class="notice" data-id="'.$notice->getId().'" data-type="'.$notice->getTypeDoc().'">'.
             '<div>'.$this->view->iconeSupport($notice->getTypeDoc()).'</div>'.
-            $vignette.
-            '<div class="titre_auteur">'.$datas.'</div>'
-		.'</div></div>';
+            $this->view->notice_Vignette($notice).
+            '<div class="titre_auteur">'.$datas.
+            '</div>'.
+            $this->barreDeLien($notice).
+            '</div>';
 
-		return $html;
+		return $html.'</div>';
 	}
+
+    public function barreDeLien($notice){
+        $html = '<ul class="barre-de-lien">';
+				$html .= $this->barreDeLienAvis($this->view->url(['controller'=>'noticeajax', 
+																																	 'action' => 'avis-abonne', 
+																													'id_notice' => $notice->getId()], null, true) . '?iframe=true', $notice->numberOfAvisAbonne(), 'Avis abonn&eacute;s');
+
+				$html .= $this->barreDeLienAvis($this->view->url(['controller'=>'noticeajax', 
+																																	 'action' => 'avis-bibliothecaire', 
+																													'id_notice' => $notice->getId()], null, true) . '?iframe=true', $notice->numberOfAvisBibliothecaire(), 'Coups de coeur');
+
+				$html .= '<li><a href="#" >&nbsp;</a></li>'.
+					'<li><a href="' . $this->view->url(['controller' => 'panier', 
+																							'action' => 'panierajouternotice',
+																							'id_notice' => $notice->getId()], null, true) . '" title="Ajouter au panier">&nbsp;</a></li>'.
+					'<li title="Réserver">' . $this->view->notice_LienReserver($notice) . '</li>';
+
+        return $html.'</ul>';
+    }
+
+		
+
+		public function barreDeLienAvis($url, $count, $title) {
+			if (0 < $count)
+        return '<li data-avis="true"><a href="' . $url .'" data-prettyphoto="true" title="' . $title . '"><span>'. sprintf('%02s', $count) . '</span></a></li>';
+			return '<li></li>';
+		}
 }
 
-?>
\ No newline at end of file
+?>
diff --git a/library/ZendAfi/View/Helper/Notice/Vignette.php b/library/ZendAfi/View/Helper/Notice/Vignette.php
index d0467e1c70a..e94c49b96a6 100644
--- a/library/ZendAfi/View/Helper/Notice/Vignette.php
+++ b/library/ZendAfi/View/Helper/Notice/Vignette.php
@@ -36,7 +36,6 @@ class ZendAfi_View_Helper_Notice_Vignette extends Zend_View_Helper_HtmlElement {
 			  '<div class="nothumbnail type_doc_'.$notice->getTypeDoc().'" onclick="javascript:window.location=\''.$url.'\'">'.
 			      '<img src="'.URL_ADMIN_IMG.'blank.gif'.'" title="" alt=""/>'.
 			    '<a href="'.$url.'">'.
-
 			      '<div>'.$notice->getAuteurPrincipal().'</div>'. 
 			      '<div>'.$notice->getTitrePrincipal().'</div>'.
 			    '</a>'.
diff --git a/public/opac/js/liste_notices_mur.js b/public/opac/js/liste_notices_mur.js
index 815fb26ddc7..b12b6b85707 100644
--- a/public/opac/js/liste_notices_mur.js
+++ b/public/opac/js/liste_notices_mur.js
@@ -1,22 +1,38 @@
 var liste_resumes = {};
-var liste_disponibilites = {};
-
 
 function vignetteHover(vignettes) {
     vignettes.each(function() {
-	var id = $(this).data('id');
 	var notice = $(this);
         notice.find('img').attr('title','');
 	notice.find('.nothumbnail img').width(notice.parent('.notice_wrapper').width());
-	$.get(resumeAjaxBaseUrl+'?id_notice='+id , function(data) {
-            var resume = ('' == data) ? '' : data;
-	    $.get(disponibiliteAjaxBaseUrl+'?id_notice='+id, function(data) {
-		var dispo = ('true' == data) ? '<span class="disponible">Disponible</span>' : '<span class="dispo">Non disponible</span>';
-		noticeMurTooltip(notice,'<span class="resume">'+resume+'</span>'+dispo);
-	    });})})
+	noticeMurTooltip(notice);});
+}
+
+function noticeMurOpen(context, id){
+    if (null != liste_resumes[id]) {
+	context.tooltip('option', 'content', liste_resumes[id]);
+	return;
+    }
+    $.get(resumeAjaxBaseUrl+'?id_notice='+id , function(data) {
+        var resume = ('' == data) ? '' : data;
+	$.get(disponibiliteAjaxBaseUrl+'?id_notice='+id, function(data) {
+	    var dispo = ('true' == data) ? '<span class="disponible">Disponible</span>' : '<span class="dispo">Non disponible</span>';
+	    var content = '<span class="resume">' + resume + '</span>' + dispo;
+	    liste_resumes[id] = content;
+	    context.tooltip('option', 'content', content);
+	});});
 }
 
 
-function noticeMurTooltip(item, contenu) {
-    $(item).tooltip({content: contenu, items: 'img:not(.icone_support)', tooltipClass: 'notice-mur-tooltip', position: {my: 'left top', at: 'right top' , collision: 'none'}} );
+function noticeMurTooltip(item) {
+    var id = $(item).data('id');
+    $(item).tooltip({
+	show:{delay:250},
+	content:'<div style="text-align:center;padding:15px;"><img src="' + imagesUrl +'patience.gif" /></div>', 
+	open:function(event, ui){
+	    var context = $(this);
+	    noticeMurOpen(context, id)}, 
+	items: 'img:not(.icone_support)', 
+	tooltipClass: 'notice-mur-tooltip', 
+	position: {my: 'left top', at: 'right top' , collision: 'none'}} );
 }
diff --git a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php
index 56ef977d5cc..4bbfa61c2ed 100644
--- a/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php
+++ b/tests/application/modules/opac/controllers/NoticeAjaxControllerTest.php
@@ -656,4 +656,52 @@ class NoticeAjaxControllerDisponibiliteNoticeTest extends AbstractControllerTest
 	}
 }
 
+
+
+
+class NoticeAjaxControllerNoticeWithAvisAvisAbonneTest extends AbstractControllerTestCase {
+	public function setup() {
+		parent::setup();
+
+		$avis_de_paul = Class_AvisNotice::newInstanceWithId(23,['entete'=>'Tres Bien',
+																			'note'=>'4',
+																			'user'=>Class_Users::newInstanceWithId(15,['login'=>'polo'])->beAbonneSIGB(),
+																			'avis'=>'de la balle',
+																			'date_avis'=>'15/03/2013',
+																			'clef_oeuvre'=>'potter',
+																			'abon_ou_bib'=>'0'])
+			->setModerationOk();
+
+		$avis_de_francois = Class_AvisNotice::newInstanceWithId(24,['entete'=>'Cool',
+																			'note'=>'4',
+																			'user'=>Class_Users::newInstanceWithId(15,['login'=>'francois'])->beAdminPortail(),
+																			'avis'=>'tres bien',
+																			'date_avis'=>'16/02/2013',
+																																'clef_oeuvre'=>'potter',
+																															'abon_ou_bib'=>'1'])
+			->setModerationOk();
+
+		Class_Notice::newInstanceWithId(34,['titre_principal'=>'Potter', 
+																				'clef_oeuvre'=>'potter',
+																				'avis' => [$avis_de_paul, $avis_de_francois]]);
+
+		$this->dispatch('/opac/noticeajax/avis-abonne/id_notice/34', true);
+	}
+
+
+	/** @test */ 
+	public function answerShouldContainsAvisDePaul() {
+		$this->assertXPathContentContains('//body', 'Tres Bien');
+		$this->assertXPath('//img[contains(@class, "note-4")]');
+		$this->assertXPathContentContains('//body', '15 mars 2013');
+		$this->assertXPathContentContains('//body', 'de la balle');
+	}
+
+
+	/** @test */ 
+	public function answerShouldNotContainsAvisDeFrancois() {
+		$this->assertNotXPathContentContains('//body', 'Cool');
+	}
+}
+
 ?>
\ No newline at end of file
diff --git a/tests/library/ZendAfi/View/Helper/Notice/MurTest.php b/tests/library/ZendAfi/View/Helper/Notice/MurTest.php
index 67ab8fa33fa..917fca1120a 100644
--- a/tests/library/ZendAfi/View/Helper/Notice/MurTest.php
+++ b/tests/library/ZendAfi/View/Helper/Notice/MurTest.php
@@ -44,7 +44,8 @@ class ZendAfi_View_Helper_Notice_MurForNoticeTest extends ZendAfi_View_Helper_No
 																							['unimarc' => "00627nam0 22002291  450 00100080000001000180000802100070002610000410003310100130007410500390008720000690012621000360019521500290023122500230026067600060028368600100028970000290029983000270032883500060035593000140036193200220037500028922  a2-07-052818-9  aFR  a20010130         d   0frea01      ba1 afreceng  1[2001-01-30-00.00.00.000000][][][]1 aHarry Potter et le prisonnier d'AzkabanfJoanne Kathleen Rowling  aPariscGallimard jeunessed2000  a465 p.3465cill.d18 cm 2aFolio juniorv1006  10  aR ROW1 aRowlingbJoanne Kathleen  1A32A partir de 10 ans  aJ  aRomans4R  aSorcier-Sorcière",
 																							 'url_vignette' => 'hp.png',
 																							 'url_image' => 'hp_big.png',
-																							 'facettes' => 'D123 A400 Y2']);
+																							 'facettes' => 'D123 A400 Y2',
+																							 'clef_oeuvre' => 'HPELPA']);
 		$this->_html = $this->_helper->notice_Mur($potter, 'TAECRN');
 	}
 
@@ -74,6 +75,11 @@ class ZendAfi_View_Helper_Notice_MurForNoticeTest extends ZendAfi_View_Helper_No
 																			'//div//a[contains(@href, "recherche/simple/code_rebond/A400")]',
 																			'Joanne Kathleen Rowling');
 	}
+
+	/** @test */
+	public function divShouldContainsBarreDeLien() {
+		$this->assertXPath($this->_html, '//ul[@class="barre-de-lien"]' );
+	}
 }
 
 
@@ -85,7 +91,8 @@ class ZendAfi_View_Helper_Notice_MurForArticleTest extends ZendAfi_View_Helper_N
 
 		$concert = Class_Notice::newInstanceWithId(2, ['url_vignette' => '',
 																									 'url_image' => '',
-																									 'type_doc' => Class_TypeDoc::ARTICLE]);
+																									 'type_doc' => Class_TypeDoc::ARTICLE, 
+																									 'clef_oeuvre' => 'toto']);
 		$concert->set_subfield('200', 'a', 'Concert')
 						->set_subfield('856', 'b', '5');
 
@@ -103,4 +110,61 @@ class ZendAfi_View_Helper_Notice_MurForArticleTest extends ZendAfi_View_Helper_N
 	}
 }
 
+
+class ZendAfi_View_Helper_Notice_Mur_BarreDeLienTest extends ZendAfi_View_Helper_Notice_MurTestCase {
+	public function setUp() {
+		parent::setUp();
+
+		$avis_de_paul = Class_AvisNotice::newInstanceWithId(23,['entete'=>'Tres Bien',
+																														'note'=>'4',
+																														'user'=> Class_Users::newInstanceWithId(15,['login'=>'polo'])->beAbonneSIGB(),
+																														'avis'=>'de la balle',
+																														'date_avis'=>'15/03/2013',
+																														'clef_oeuvre'=>'potter',
+																														'abon_ou_bib'=>'0'])
+			->setModerationOk();
+
+		$avis_de_francois = Class_AvisNotice::newInstanceWithId(24,['entete'=>'Cool',
+																																'note'=>'4',
+																																'user'=>Class_Users::newInstanceWithId(15,['login'=>'francois'])->beAdminPortail(),
+																																'avis'=>'tres bien',
+																																'date_avis'=>'16/02/2013',
+																																'clef_oeuvre'=>'potter',
+																																'abon_ou_bib'=>'1'])
+			->setModerationOk();
+
+		$notice = Class_Notice::newInstanceWithId(34,['titre_principal'=>'Potter', 
+																									'clef_oeuvre'=>'potter',
+																									'avis' => [$avis_de_paul, $avis_de_francois],
+																									'url_vignette' => '',
+																									'url_image' => '']);
+
+		Storm_Test_ObjectWrapper::onLoaderOfModel('Class_AvisNotice')
+			->whenCalled('countBy')
+			->answers(1);
+		
+		$this->_html = $this->_helper->notice_Mur($notice, 'TAECRN');
+	}
+
+
+	/** @test */
+	public function barreDeLienShouldContainUrlAvisAbonne() {
+		$this->assertXPath($this->_html, '//a[contains(@href, "avis-abonne/id_notice/34")]');
+	}
+
+	/** @test */
+	public function barreDeLienShouldContainUrlAvisBibliothecaire() {
+		$this->assertXPath($this->_html, '//a[contains(@href, "avis-bibliothecaire/id_notice/34")]');
+	}
+
+	/** @test */
+	public function barreDeLienShouldContainUrlAjoutPanier() {
+		$this->assertXPath($this->_html, '//a[contains(@href, "panierajouternotice/id_notice/34")]');
+	}
+
+	/** @test */
+	public function barreDeLienShouldContainUrlReserver() {
+		$this->assertXPath($this->_html, '//a[contains(@href, "panierajouternotice/id_notice/34")]');
+	}
+}
 ?>
\ No newline at end of file
-- 
GitLab