From fb348661bdc5b278617f42f3ff5377409a6b1618 Mon Sep 17 00:00:00 2001
From: Ghislain Loas <ghislo@sandbox.pergame.net>
Date: Tue, 16 Feb 2016 11:32:37 +0100
Subject: [PATCH] hotline #37996 fix url

---
 VERSIONS_HOTLINE/37996                          |  1 +
 .../controllers/PremierChapitreController.php   | 17 +++++++++--------
 .../scripts/accueil/premier-chapitre.phtml      |  4 ++--
 .../controllers/PremierChapitreController.php   | 10 +++++-----
 .../views/scripts/premier-chapitre/index.phtml  |  2 +-
 .../View/Helper/PremierChapitre/Vignettes.php   | 14 ++++++++++----
 6 files changed, 28 insertions(+), 20 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/37996

diff --git a/VERSIONS_HOTLINE/37996 b/VERSIONS_HOTLINE/37996
new file mode 100644
index 00000000000..aa85ade59c0
--- /dev/null
+++ b/VERSIONS_HOTLINE/37996
@@ -0,0 +1 @@
+ - ticket #37996 : Correction des liens Premier Chapitre
diff --git a/application/modules/admin/controllers/PremierChapitreController.php b/application/modules/admin/controllers/PremierChapitreController.php
index e3c9aa79e2c..a521e3a416c 100644
--- a/application/modules/admin/controllers/PremierChapitreController.php
+++ b/application/modules/admin/controllers/PremierChapitreController.php
@@ -18,9 +18,9 @@
  * along with BOKEH; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
-class Admin_PremierChapitreController extends Zend_Controller_Action {
-	use Trait_Translator;
-	protected $_baseUrlOptions = ['module' => 'admin', 'controller' => 'premier-chapitre'];
+class Admin_PremierChapitreController extends ZendAfi_Controller_Action {
+	protected $_baseUrlOptions = ['module' => 'admin', 'controller' => 'premier-chapitre'],
+    $_back_to_index;
 
 	private $active;
 	private $pc_bib_id;
@@ -35,6 +35,7 @@ class Admin_PremierChapitreController extends Zend_Controller_Action {
 		$this->pc_bmid = Class_AdminVar::get('PREMIERCHAPITRE_BMID');
 		$this->pc_bmkey = Class_AdminVar::get('PREMIERCHAPITRE_BMKEY');
 		$this->active = (!empty($this->pc_bib_id) && !empty($this->pc_bmid) && !empty($this->pc_bmkey));
+    $this->_back_to_index = $this->view->tagAnchor(['action' => 'index'] , $this->_('Retour à l\'index du service Premier-chapitre'));
 	}
 
 	public function preDispatch() {
@@ -73,11 +74,11 @@ class Admin_PremierChapitreController extends Zend_Controller_Action {
 		$data = $pc_ws->getDatafile();
 		if ($data){
 			$contenu = date('H:i:s')." Le référentiel a bien été téléchargé sur le serveur\nIl est possible de procéder à la mise à jour de la base\n";
-			$contenu .= '<a href="/admin/premier-chapitre/maj-db/">Mise à jour de la base</a>';
+			$contenu .= $this->view->tagAnchor(['action' => 'maj-db'], $this->_('Mise à jour de la base'));
 		}
 		else $contenu = "Une erreur est survenue\nle référentiel n'a pas pu être téléchargé\nVeuillez réessayer ultérieurement";
 		$this->view->contenu = '<pre>'.$contenu.'</pre>';
-		$this->view->contenu .= "<br/><a href='/admin/premier-chapitre/'>Retour à l'index du service Premier-chapitre</a>";
+		$this->view->contenu .= "<br/>" . $this->back_to_index;
 		$this->view->titre .= ' :: Téléchargement du référentiel';
 
 	}
@@ -92,11 +93,11 @@ class Admin_PremierChapitreController extends Zend_Controller_Action {
 			if ($data['new']) $contenu .= '* '.$data['new'].(($data['new']>1)?" ont été ajoutées":" a été ajoutée")."\n";
 			if ($data['maj']) $contenu .= '* '.$data['maj'].(($data['maj']>1)?" ont été mises":" a été mise")." à jour\n";
 			if ($data['err']) $contenu .= '* '.$data['err'].(($data['err']>1)?" erreurs n'ont pas été traitées":" erreur n'a pas été traitée")."\n";
-			$contenu .= '<a href="/admin/premier-chapitre/link-notices/">Lier les notices</a>';
+			$contenu .= $this->view->tagAnchor(['action' => 'link-notices'], $this->_('Lier les notices'));
 		}
 		else $contenu = "Une erreur est survenue\nLa base n'a pu être mise à jour\nVeuillez réessayer ultérieurement";
 		$this->view->contenu = '<pre>'.$contenu.'</pre>';
-		$this->view->contenu .= "<br/><a href='/admin/premier-chapitre/'>Retour à l'index du service Premier-chapitre</a>";
+		$this->view->contenu .= "<br/>" . $this->_back_to_index;
 		$this->view->titre .= ' :: Mise à jour de la base';
 	}
 
@@ -111,7 +112,7 @@ class Admin_PremierChapitreController extends Zend_Controller_Action {
 		}
 		else $contenu = "Une erreur est survenue\nLes liaisons n'ont pu être faites\nVeuillez réessayer ultérieurement";
 		$this->view->contenu = '<pre>'.$contenu.'</pre>';
-		$this->view->contenu .= "<br/><a href='/admin/premier-chapitre/'>Retour à l'index du service Premier-chapitre</a>";
+		$this->view->contenu .= "<br/>" . $this->_back_to_index;
 		$this->view->titre .= ' :: Liaison aux notices';
 
 	}
diff --git a/application/modules/admin/views/scripts/accueil/premier-chapitre.phtml b/application/modules/admin/views/scripts/accueil/premier-chapitre.phtml
index 8c18b86fa53..5ee9ef4ecb2 100644
--- a/application/modules/admin/views/scripts/accueil/premier-chapitre.phtml
+++ b/application/modules/admin/views/scripts/accueil/premier-chapitre.phtml
@@ -18,7 +18,7 @@
 		pc_ref_url();
 	}
 	function pc_ref_url() {
-		var urlref = "/premier-chapitre"
+		var urlref = baseUrl + "/premier-chapitre"
 		var type = $("#type")[0].value;
 		var format = $("#format")[0].value;
 		if (type == 0) {
@@ -92,7 +92,7 @@
 			<tr id="pc_conf_panier">
 				<td class="droite">Panier&nbsp;</td>
 				<td class="gauche"><?php echo $this->formSelect("id_panier", $this->preferences["id_panier"],['onchange'=>'pc_ref_url();'],$this->paniers) ?></td>
-			</tr>	
+			</tr>
     		<tr id="pc_conf_format">
     			<td class="droite" valign="top">Format d'affichage</td>
     			<td class="gauche">
diff --git a/application/modules/opac/controllers/PremierChapitreController.php b/application/modules/opac/controllers/PremierChapitreController.php
index 498c04bb5f4..56a65a0e1e9 100644
--- a/application/modules/opac/controllers/PremierChapitreController.php
+++ b/application/modules/opac/controllers/PremierChapitreController.php
@@ -71,13 +71,13 @@ class PremierChapitreController extends Zend_Controller_Action {
 			$pc = Class_PremierChapitre::findFirstBy(['ean' => $ean]);
 			if ($pc) {
 				$ntc = $pc->getNotice();
-				$url_notice = ZendAfi_View_Helper_UrlNotice::urlNotice($ntc);
+				$url_notice = Class_Url::absolute(ZendAfi_View_Helper_UrlNotice::urlNotice($ntc));
 				$this->_redirect($url_notice);
 			}
-			else 
+			else
 				$this->_redirect('/');
 		}
-		else 
+		else
 			$this->_redirect('/');
 	}
 
@@ -107,7 +107,7 @@ class PremierChapitreController extends Zend_Controller_Action {
 		$format = $this->_request->getParam('format');
 		if (!preg_match('@^\d+$@',$nb))
 			$pcs =  Class_PremierChapitre::getAleatoire();
-		else 
+		else
 			$pcs =  Class_PremierChapitre::getAleatoire($nb);
 		$preferences = [];
 		if ($format == 1 || $format == 2) $preferences['target'] = 'frame';
@@ -139,7 +139,7 @@ class PremierChapitreController extends Zend_Controller_Action {
 		$this->getResponse()->setHeader('Pragma', 'no-cache', true);
 		$this->getResponse()->setBody($html . Class_ScriptLoader::getInstance()->loadJQuery()->html());
 	}
-	
+
 	public function __call($method, $args) {
 		if ('Action' == substr($method, -6)) {
 			// Si une méthode d'action n'est pas trouvée,
diff --git a/application/modules/opac/views/scripts/premier-chapitre/index.phtml b/application/modules/opac/views/scripts/premier-chapitre/index.phtml
index f1e43c1af94..7d9acfa910b 100644
--- a/application/modules/opac/views/scripts/premier-chapitre/index.phtml
+++ b/application/modules/opac/views/scripts/premier-chapitre/index.phtml
@@ -10,7 +10,7 @@
 		<div>
 			<p><img src="/public/opac/images/lireavecpremierchapitre.png" alt="premierchapitre" style="position:relative;top:-5px;"></p>
 			<p><span style="font-size:12px">Cliquez sur une couverture pour lire un extrait. Vous pouvez ensuite récupérer le livre à la bibliothèque.</span></p>
-			<p><span style="font-size:12px"><a href="/premier-chapitre/liste-complete/">Cliquez ici Pour voir la liste complète <img src="/public/opac/images/buttons/2rightarrow.png"></a></span></p>
+			<p><span style="font-size:12px"><?php echo $this->tagAnchor(['action' => 'liste-complete'], $this->_('Cliquez ici pour voir la liste complète') . '<img src="/public/opac/images/buttons/2rightarrow.png">')?> </span></p>
 		</div>
 <?php echo $this->premierChapitre_Vignettes($this->pc_ids,['target' => 'frame', 'linkNotice' => 1]); ?>
 		</div>
diff --git a/library/ZendAfi/View/Helper/PremierChapitre/Vignettes.php b/library/ZendAfi/View/Helper/PremierChapitre/Vignettes.php
index 9f83521639e..258106d1cd3 100644
--- a/library/ZendAfi/View/Helper/PremierChapitre/Vignettes.php
+++ b/library/ZendAfi/View/Helper/PremierChapitre/Vignettes.php
@@ -72,8 +72,12 @@ class ZendAfi_View_Helper_PremierChapitre_Vignettes
   protected function _vignetteFrame($model, $preferences){
     $onclick = "\$('#pc_frame')[0].src='".$model->getUrl()."';";
 
-    if ($this->_isLinkToRecord($preferences))
-      $onclick .= "\$('#pc_lienNotice')[0].href='/premier-chapitre/notice/ean/" . $model->getId()."';";
+    if ($this->_isLinkToRecord($preferences)) {
+      $url = $this->view->url(['controller'=>'premier-chapitre',
+                               'action' => 'notice',
+                               'ean' => $model->getId()], null ,true);
+      $onclick .= sprintf("\$('#pc_lienNotice')[0].href='%s';", $url);
+    }
 
     return $this->_tag('a', $this->_vignetteImg($model),
                        ['onclick' => $onclick,
@@ -87,10 +91,12 @@ class ZendAfi_View_Helper_PremierChapitre_Vignettes
 
 
   protected function _vignetteNotice($model, $preferences){
-    $lnk_attribs = ['href' => '/premier-chapitre/notice/ean/' . $model->getId()];
+    $lnk_attribs = $this->view->url(['controller' => 'premier-chapitre',
+                                     'action' => 'notice',
+                                     'ean' => $model->getId()], null, true);
 
     return $this->_tag('a', $this->_vignetteImg($model),
-                       $lnk_attribs);
+                       ['href' => $lnk_attribs]);
   }
 
 
-- 
GitLab