From bc17eedae60402a7388430f504b2a4d297ceae1a Mon Sep 17 00:00:00 2001
From: Ghislain Loas <ghislo@sandbox.pergame.net>
Date: Thu, 21 Jan 2016 15:29:30 +0100
Subject: [PATCH] hotline #36324 fix numeric ressources display in embed mode

---
 VERSIONS_HOTLINE/36324                        |  1 +
 .../controllers/RechercheController.php       | 58 ++++++++++++-------
 .../recherche/ressourcesnumeriques.phtml      | 13 ++---
 .../View/Helper/Telephone/RenderAlbum.php     | 12 ++--
 ...hercheControllerRessourceNumeriqueTest.php | 42 ++++++++++++--
 5 files changed, 88 insertions(+), 38 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/36324

diff --git a/VERSIONS_HOTLINE/36324 b/VERSIONS_HOTLINE/36324
new file mode 100644
index 00000000000..2420d01cb7b
--- /dev/null
+++ b/VERSIONS_HOTLINE/36324
@@ -0,0 +1 @@
+ - ticket #36324 : Correction de l'afffichage des ressources numériques en mode téléphone
diff --git a/application/modules/telephone/controllers/RechercheController.php b/application/modules/telephone/controllers/RechercheController.php
index 02299af1e24..79cff911ccd 100644
--- a/application/modules/telephone/controllers/RechercheController.php
+++ b/application/modules/telephone/controllers/RechercheController.php
@@ -28,37 +28,53 @@ class Telephone_RechercheController extends RechercheController {
     }
 
     $actions = [$this->_('Description du document') =>  ['action' => 'detail'],
-    $this->_('Où le trouver ?') => ['action' => 'exemplaires'],
-    $this->_('Critiques') => ['action' => 'avis'],
-    $this->_('Résumé') =>  ['action' => 'resume'],
-    $this->_('Vidéos associées') =>  ['action' => 'videos'],
-    $this->_('Rebondir dans le catalogue') =>  ['action' => 'tags'],
-    $this->_('Biographie de l\'auteur') => ['action' => 'biographie'],
-    $this->_('Documents similaires') => ['action' => 'similaires'],
-    $this->_('Notices liées') => ['action' => 'frbr']
-    ];
+                $this->_('Où le trouver ?') => ['action' => 'exemplaires'],
+                $this->_('Critiques') => ['action' => 'avis'],
+                $this->_('Résumé') =>  ['action' => 'resume'],
+                $this->_('Vidéos associées') =>  ['action' => 'videos'],
+                $this->_('Rebondir dans le catalogue') =>  ['action' => 'tags'],
+                $this->_('Biographie de l\'auteur') => ['action' => 'biographie'],
+                $this->_('Documents similaires') => ['action' => 'similaires'],
+                $this->_('Notices liées') => ['action' => 'frbr']];
+
+    $actions = $this->getActionForTypeDoc($actions, $notice);
+
+    $this->view->notice = $notice;
+    $this->view->actions = $actions;
+  }
+
+
+  protected function getActionForTypeDoc($actions, $notice) {
+    if(!$notice->isRessourceNumerique())
+      return $actions;
+
+    Class_ScriptLoader::getInstance()
+      ->addAdminScript('onload_utils')
+      ->addJQueryReady('setupAnchorsTarget();');
+
+    $action_array = ['action' => 'ressourcesnumeriques',
+                     'attribs' => ['data-ajax' => 'false']];
 
     if ($notice->isLivreNumerique()|| $notice->isEpub()) {
-      $actions[$this->_('Feuilleter le livre')] = ['action' => 'ressourcesnumeriques',
-                                                   'attribs' => ['data-ajax' => 'false']];
-                                                   }
+      $actions[$this->_('Feuilleter le livre')] = $action_array;
+      return $actions;
+    }
 
     if ($notice->isArteVOD()) {
-      $actions[$this->_('Bande-annonce')] = ['action' => 'ressourcesnumeriques',
-                                             'attribs' => ['data-ajax' => 'false']];
+      $actions[$this->_('Bande-annonce')] = $action_array;
+      return $actions;
     }
 
     if ($notice->isAudioRecord()) {
-      $actions[$this->_('Ecouter l\'album')] = ['action' => 'ressourcesnumeriques',
-                                                'attribs' => ['data-ajax' => 'false']];
-        }
+      $actions[$this->_('Ecouter l\'album')] = $action_array;
+      return $actions;
+    }
 
-    $this->view->notice = $notice;
-    $this->view->actions = $actions;
+    $actions[$this->_('Ressources numériques')] = $action_array;
+    return $actions;
   }
 
 
-
   public function grandeimageAction() {
     if (!$this->view->notice = Class_Notice::getLoader()->find($this->_getParam('id')))
       $this->_redirect('/');
@@ -85,7 +101,7 @@ class Telephone_RechercheController extends RechercheController {
 
 
   public function ressourcesnumeriquesAction() {
-    if (!$this->view->notice = Class_Notice::getLoader()->find($this->_getParam('id')))
+    if (!$this->view->notice = Class_Notice::find($this->_getParam('id')))
       $this->_redirect('/');
   }
 
diff --git a/application/modules/telephone/views/scripts/recherche/ressourcesnumeriques.phtml b/application/modules/telephone/views/scripts/recherche/ressourcesnumeriques.phtml
index 8237fd39f56..39359e51cc0 100644
--- a/application/modules/telephone/views/scripts/recherche/ressourcesnumeriques.phtml
+++ b/application/modules/telephone/views/scripts/recherche/ressourcesnumeriques.phtml
@@ -1,9 +1,6 @@
-<?php 
-echo $this->toolbar($this->_("Livre numérisé"), 
-                    array('action' => 'simple'));
-
-echo '<h1>'.$this->notice->getTitrePrincipal().'</h1>';
-
+<?php
+echo $this->toolbar($this->_("Livre numérisé"),
+                    ['action' => 'simple']);
+echo $this->tag('h1', $this->notice->getTitrePrincipal());
 echo $this->renderAlbum($this->notice->getAlbum());
-
-?>
\ No newline at end of file
+?>
diff --git a/library/ZendAfi/View/Helper/Telephone/RenderAlbum.php b/library/ZendAfi/View/Helper/Telephone/RenderAlbum.php
index 6169d7616e7..73fcdf38cf4 100644
--- a/library/ZendAfi/View/Helper/Telephone/RenderAlbum.php
+++ b/library/ZendAfi/View/Helper/Telephone/RenderAlbum.php
@@ -16,14 +16,14 @@
  *
  * 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_Telephone_RenderAlbum extends ZendAfi_View_Helper_RenderAlbum {
   public function renderAlbum($album) {
-    return $album 
+    return $album
       ? sprintf('<div id="resnum">%s</div>', $this->renderAlbumHelper($album))
-      : '';
+      : $this->view->_('Aucune ressource numérique trouvée.');
   }
 
 
@@ -48,7 +48,11 @@ class ZendAfi_View_Helper_Telephone_RenderAlbum extends ZendAfi_View_Helper_Rend
     if ($album->isAudioRecord())
       return $this->view->tagAlbumTrackList($album);
 
-    return $this->view->tagAlbumMediaList($album);
+    Class_ScriptLoader::getInstance()
+      ->addAdminScript('onload_utils')
+      ->addJQueryReady('setupAnchorsTarget();');
+
+    return parent::renderAlbumHelper($album);
   }
 }
 
diff --git a/tests/application/modules/telephone/controllers/RechercheControllerRessourceNumeriqueTest.php b/tests/application/modules/telephone/controllers/RechercheControllerRessourceNumeriqueTest.php
index f05ee05a226..4acb8b472f8 100644
--- a/tests/application/modules/telephone/controllers/RechercheControllerRessourceNumeriqueTest.php
+++ b/tests/application/modules/telephone/controllers/RechercheControllerRessourceNumeriqueTest.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
  */
 
 require_once 'TelephoneAbstractControllerTestCase.php';
@@ -55,10 +55,10 @@ class Telephone_RechercheControllerPropagandaViewNoticeTest extends Telephone_Re
     $this->dispatch('/telephone/recherche/viewnotice/id/9', true);
   }
 
-  
+
   /** @test */
   public function pageShouldContainsLinkToRessouresNumeriquesEpub() {
-    $this->assertNotXPathContentContains('//a[contains(@href, "ressourcesnumeriques/id/9")][@data-ajax="false"]', 
+    $this->assertNotXPathContentContains('//a[contains(@href, "ressourcesnumeriques/id/9")][@data-ajax="false"]',
                                          'Feuilleter le livre',$this->_response->getBody());
   }
 
@@ -66,8 +66,40 @@ class Telephone_RechercheControllerPropagandaViewNoticeTest extends Telephone_Re
 
 
 
+class Telephone_RechercheControllerNumericRessourcesTest extends TelephoneAbstractControllerTestCase {
+  protected $_storm_default_to_volatile = true;
+
+  public function setUp() {
+    parent::setUp();
+    $this->fixture('Class_Album',
+                   ['id' => 1,
+                    'titre' => 'smalltalk',
+                    'type_doc_id' => Class_TypeDoc::TOUTAPPRENDRE]);
+
+    $item = $this->fixture('Class_Exemplaire',
+                           ['id' => 16,
+                            'id_notice' => 15,
+                            'id_origine' => 1]);
+
+    $record = $this->fixture('Class_Notice',
+                             ['id' => 15,
+                              'type_doc' => Class_TypeDoc::TOUTAPPRENDRE]);
+
+    $record->setTitrePrincipal('SmallTalk')
+           ->setExemplaire($item);
+
+    $this->dispatch('/recherche/ressourcesnumeriques/id/15', true);
+  }
 
-  
 
+  /** @test */
+  public function onloadUtilShouldBeLoaded() {
+    $this->assertXPath('//script[contains(@src, "/public/admin/js/onload_utils.js")]');
+  }
 
-?>
\ No newline at end of file
+
+  /** @test */
+  public function wrongAccountRequirementMessageShouldBeDisplay() {
+    $this->assertXPathContentContains('//div//p', 'Vous devez être connecté sous un compte avec abonnement valide pour pouvoir accéder au cours en ligne');
+  }
+}
\ No newline at end of file
-- 
GitLab