From 40040d9a8150730b255d84122d2dac2c2aa3afa0 Mon Sep 17 00:00:00 2001
From: pbarroca <pbarroca@afi-sa.fr>
Date: Mon, 17 Feb 2014 14:38:11 +0100
Subject: [PATCH] SAV rel #12119 : permalink is now absolute URL in news edit
 screen

---
 .../admin/controllers/CmsController.php       | 50 ++++++++-----------
 .../views/scripts/cms/_newsform_head.phtml    | 21 ++++----
 library/ZendAfi/View/Helper/Permalink.php     | 19 ++++---
 .../admin/controllers/CmsControllerTest.php   |  7 +--
 4 files changed, 46 insertions(+), 51 deletions(-)

diff --git a/application/modules/admin/controllers/CmsController.php b/application/modules/admin/controllers/CmsController.php
index 78355c89f1a..00090010914 100644
--- a/application/modules/admin/controllers/CmsController.php
+++ b/application/modules/admin/controllers/CmsController.php
@@ -26,30 +26,24 @@ class Admin_CmsController extends ZendAfi_Controller_Action {
 	protected $_article_old_status = null;
 
 	public function init() {
-		$identity = Class_Users::getLoader()->getIdentity();
+		$identity = Class_Users::getIdentity();
 
-		if (ZendAfi_Acl_AdminControllerRoles::ADMIN_BIB >= $identity->getRoleLevel()) {
-			$this->_bib = $identity->getBib();
-
-		} else {
-			$this->_bib = Class_Bib::getLoader()->getPortail();
-		}
+		$this->_bib = (ZendAfi_Acl_AdminControllerRoles::ADMIN_BIB >= $identity->getRoleLevel()) ?
+			$identity->getBib() : 
+			$this->_bib = Class_Bib::getPortail();
 	}
 
 
 	public function indexAction()	{
-		$identity = Class_Users::getLoader()->getIdentity();
+		$identity = Class_Users::getIdentity();
 
 		if (0 != $this->_bib->getId()) {
 			$bibs = [$this->_bib];
-
 		} else {
-			$bibs = Class_Bib::getLoader()->findAllBy(['order' => 'libelle']);
+			$bibs = Class_Bib::findAllBy(['order' => 'libelle']);
 			array_unshift($bibs, $this->_bib);
 		}
 
-
-
 		$add_link_label = $this->view->tagImg(URL_ADMIN_IMG . 'ico/add_cat.gif')
 			. $this->view->_(' Ajouter une catégorie');
 
@@ -66,7 +60,7 @@ class Admin_CmsController extends ZendAfi_Controller_Action {
 																																		['id_bib' => $bib->getId()])),
 																											$add_link_label)];
 			},
-				
+			
 			$bibs);
 
 		$this->view->categories = $categories;
@@ -77,17 +71,15 @@ class Admin_CmsController extends ZendAfi_Controller_Action {
 		$this->view->titre = $this->view->_('Mise à jour des articles');
 
 		$this->view->headScript()->appendScript('var treeViewSelectedCategory = '
-																			. (int)$this->_getParam('id_cat') . ';');
+																						. (int)$this->_getParam('id_cat') . ';');
 		$this->view->headScript()->appendFile(URL_ADMIN_JS . 'tree-view.js');
 
 	}
 
 
 	public function cataddAction() {
-		$category = Class_ArticleCategorie::getLoader()
-										->newInstance()
-										->setLibelle('');
-		$parent = Class_ArticleCategorie::getLoader()->find((int)$this->_getParam('id'));
+		$category = Class_ArticleCategorie::newInstance()->setLibelle('');
+		$parent = Class_ArticleCategorie::find((int)$this->_getParam('id'));
 
 		if (null !== $parent) {
 			$category->setParentCategorie($parent);
@@ -119,9 +111,8 @@ class Admin_CmsController extends ZendAfi_Controller_Action {
 			return;
 		}
 
-		if (null === $category->getBib()) {
+		if (null === $category->getBib())
 			$category->setBib($this->_bib);
-		}
 
 		$this->view->category = $category;
 		$this->view->combo_cat = $this->view->comboParentCategorie($category); 
@@ -229,15 +220,17 @@ class Admin_CmsController extends ZendAfi_Controller_Action {
 
 
 	public function newseditAction() {
-		$article = Class_Article::getLoader()->find((int)$this->_getParam('id'));
+		if (!$article = Class_Article::find((int)$this->_getParam('id'))) {
+			$this->_redirect('admin/cms');
+			return;
+		}
+
 	 	$this->_article_old_status = $article->getStatus();
-		if (null === ($article->getCategorie()->getBib())) {
+		if (null === ($article->getCategorie()->getBib()))
 			$article->getCategorie()->setBib($this->_bib);
-		}
 
-		if ($lang = $this->_getParam('lang')) {
+		if ($lang = $this->_getParam('lang'))
 			$article = $article->getOrCreateTraductionLangue($lang);
-		}
 
 		if ($this->_isArticleSaved($article)) {
 			$this->_notifyArticleChanged($article);
@@ -254,10 +247,11 @@ class Admin_CmsController extends ZendAfi_Controller_Action {
 		if ($article->isTraduction()) {
 			$this->view->titre = 'Traduire un article';
 			$this->render('traductionform');
-		}	else {
-			$this->view->titre = 'Modifier un article';
-			$this->render('newsform');
+			return;
 		}
+
+		$this->view->titre = 'Modifier un article';
+		$this->render('newsform');
 	}
 
 
diff --git a/application/modules/admin/views/scripts/cms/_newsform_head.phtml b/application/modules/admin/views/scripts/cms/_newsform_head.phtml
index 451b2852ba4..c3ad970a254 100644
--- a/application/modules/admin/views/scripts/cms/_newsform_head.phtml
+++ b/application/modules/admin/views/scripts/cms/_newsform_head.phtml
@@ -2,20 +2,21 @@
 
 <?php 
 if (!$this->article->isNew())  { 
-	$article_url = $this->url(array('module' => 'opac', 
-																	'controller' => 'cms', 
-																	'action' => 'articleview', 
-																	'render' => null,
-																	'id' => $this->article->getId()));
-	echo $this->tagPreview($article_url, "Visualisation de l'article: ".$this->article->getTitre());
-	echo $this->permalink($article_url);
+	$article_url = $this->url(['module' => 'opac', 
+														 'controller' => 'cms', 
+														 'action' => 'articleview', 
+														 'id' => $this->article->getId()],
+														null, true);
+	echo $this->tagPreview($article_url, "Visualisation de l'article: " . $this->article->getTitre());
+	echo $this->permalink($this->absoluteUrl($article_url));
 }
 
 echo $this->partial('cms/_traduction_navigator.phtml',
-										array('article' => $this->article));
-if ($this->article->hasDateMaj())  {
+										['article' => $this->article]);
+
+if ($this->article->hasDateMaj()) {
   echo sprintf('<br/><br/>%s : %s', 
-               $this->_("Dernière modification"), 
+               $this->_('Dernière modification'), 
                $this->humanDate($this->article->getDateMaj())); 
 }
 ?>
diff --git a/library/ZendAfi/View/Helper/Permalink.php b/library/ZendAfi/View/Helper/Permalink.php
index f52f168a29d..5f709cc8e05 100644
--- a/library/ZendAfi/View/Helper/Permalink.php
+++ b/library/ZendAfi/View/Helper/Permalink.php
@@ -20,12 +20,11 @@
  */
 class ZendAfi_View_Helper_Permalink extends ZendAfi_View_Helper_BaseHelper {
 	public function permalink($url) {
-		$icone_permalink= 'reseaux/permalink.png';
-		$path_icone_permalink = PATH_SKIN.'images/'.$icone_permalink;
+		$icone_permalink = 'reseaux/permalink.png';
+		$path_icone_permalink = PATH_SKIN . 'images/' . $icone_permalink;
 		$url_icone_permalink = file_exists($path_icone_permalink)
-		                       ? URL_IMG.$icone_permalink
-                        	 : URL_ADMIN_IMG.'reseaux/permalink.gif';
-
+			? URL_IMG . $icone_permalink
+			: URL_ADMIN_IMG . 'reseaux/permalink.gif';
 
 		$lien_permanent = $this->translate()->_('Lien permanent');
 		$html = $this->view->tagImgHover($url_icone_permalink,
@@ -34,13 +33,13 @@ class ZendAfi_View_Helper_Permalink extends ZendAfi_View_Helper_BaseHelper {
 																			'alt' => $lien_permanent,
 																			'onclick' => '$(this).next().children().first().toggle()']);
 
-		$html.= '<div><div style="display:none;">';
-		$html.= '<div>' . $this->translate()->_('Lien permanent') . '</div>';
-		$html.= '<div>' .
+		$html .= '<div><div style="display:none;">';
+		$html .= '<div>' . $lien_permanent . '</div>';
+		$html .= '<div>' .
 			'<a href="#" onclick="$(this).parent().parent().hide(); return false">&raquo;&nbsp;' . $this->translate()->_('fermer cette fenêtre') . '</a>'.
 			'</div>';
-		$html.='<input type="text" value="'.$url.'"/>';
-		$html.='</div></div>';
+		$html .='<input type="text" value="' . $url . '"/>';
+		$html .='</div></div>';
 
 		return $html;
 	}
diff --git a/tests/application/modules/admin/controllers/CmsControllerTest.php b/tests/application/modules/admin/controllers/CmsControllerTest.php
index 8bf5bed6758..5fa1e44a714 100644
--- a/tests/application/modules/admin/controllers/CmsControllerTest.php
+++ b/tests/application/modules/admin/controllers/CmsControllerTest.php
@@ -229,7 +229,7 @@ class CmsControllerArticleEditWithoutLanguesTest extends CmsControllerTestCase {
 
 
 	/** @test */
-	function traductionsSelectorShouldNotBeVisible() {
+	public function traductionsSelectorShouldNotBeVisible() {
 		$this->assertNotXPath('//div[@class="traduction_navigator"]');
 	}
 }
@@ -252,6 +252,7 @@ class CmsControllerArticleConcertAsAdminPortailEditActionTest extends CmsControl
 		$this->dispatch('/admin/cms/newsedit/id/4', true);
 	}
 
+
 	/** @test */
 	public function articleShouldcontainsAuteurTomEtJerry() {
 		$this->assertXPathContentContains('//td','Tom et Jerry');
@@ -638,8 +639,8 @@ class CmsControllerArticleConcertEditActionTest extends CmsControllerTestCase {
 
 
 	/** @test */
-	function permalinkShouldContainsArticleUrl() {
-		$this->assertXPath('//div//input[contains(@value, "cms/articleview/id/4")]');
+	public function permalinkShouldContainsArticleAbsoluteUrl() {
+		$this->assertXPath('//div//input[contains(@value, "cms/articleview/id/4")][contains(@value, "http://")]');
 	}
 
 
-- 
GitLab