From 32461f91e803c80dc61c0cce059fb515a9d1661b Mon Sep 17 00:00:00 2001
From: Ghislain Loas <ghislo@sandbox.pergame.net>
Date: Fri, 21 Nov 2014 17:03:48 +0100
Subject: [PATCH] 
 hotline_#17774_remove_link_to_mobile_version_if_no_profil_is_set

---
 ...link_to_mobile_version_if_no_profil_is_set |  2 +
 .../modules/opac/views/scripts/portail.phtml  | 18 ++++-----
 library/Class/Profil.php                      |  4 ++
 .../opac/controllers/IndexControllerTest.php  | 37 +++++++++++++++++++
 4 files changed, 52 insertions(+), 9 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/hotline_#17774_remove_link_to_mobile_version_if_no_profil_is_set

diff --git a/VERSIONS_HOTLINE/hotline_#17774_remove_link_to_mobile_version_if_no_profil_is_set b/VERSIONS_HOTLINE/hotline_#17774_remove_link_to_mobile_version_if_no_profil_is_set
new file mode 100644
index 00000000000..eba21b7eb45
--- /dev/null
+++ b/VERSIONS_HOTLINE/hotline_#17774_remove_link_to_mobile_version_if_no_profil_is_set
@@ -0,0 +1,2 @@
+ - ticket: accueil
+   - Suppression du message de redirection vers le site version mobile si aucun profil poiur téléphone a été configuré.
\ No newline at end of file
diff --git a/application/modules/opac/views/scripts/portail.phtml b/application/modules/opac/views/scripts/portail.phtml
index fd642a2d821..84027e77d84 100644
--- a/application/modules/opac/views/scripts/portail.phtml
+++ b/application/modules/opac/views/scripts/portail.phtml
@@ -3,23 +3,23 @@ ob_start();
 echo '<body '.$this->bodyParam.'>';
 ?>
 
-<?php 
-if (isTelephone()) 
-	echo sprintf('<div class="back_to_phone">%s</div>', 
-								 $this->tagAnchor($this->url(array('module' => 'telephone'), null, true), 
-																	$this->_('Afficher le site en mode mobile')));  
+<?php
+if (isTelephone() && Class_Profil::isAPhoneProfilEnabeld())
+	echo sprintf('<div class="back_to_phone">%s</div>',
+								 $this->tagAnchor($this->url(array('module' => 'telephone'), null, true),
+																	$this->_('Afficher le site en mode mobile')));
 
-echo $this->partial('accueil.phtml', 
+echo $this->partial('accueil.phtml',
 										['profil' => $this->profil]);
 
-echo $this->partial('footer.phtml', 
+echo $this->partial('footer.phtml',
 										array('portail_cfg_site' => $this->profil->getCfgSiteAsArray()));
 
 $html = ob_get_contents();
 ob_end_clean();
 
-echo $this->partial('head.phtml', 
-										array_merge($this->profil->getCfgSiteAsArray(), 
+echo $this->partial('head.phtml',
+										array_merge($this->profil->getCfgSiteAsArray(),
 																array('titre' => $this->getTitre())));
 echo $html;
 ?>
diff --git a/library/Class/Profil.php b/library/Class/Profil.php
index 821408bc7d6..aac321ed157 100644
--- a/library/Class/Profil.php
+++ b/library/Class/Profil.php
@@ -55,6 +55,10 @@ class ProfilLoader extends Storm_Model_Loader {
 	public function getRoot() {
 		return Class_profil::newInstanceWithId(null,[]);
 	}
+
+	public function isAPhoneProfilEnabeld() {
+		return Class_profil::countBy(['browser' => 'telephone']) >= 1;
+	}
 }
 
 
diff --git a/tests/application/modules/opac/controllers/IndexControllerTest.php b/tests/application/modules/opac/controllers/IndexControllerTest.php
index 10b4adbfa0c..808ccee32c3 100644
--- a/tests/application/modules/opac/controllers/IndexControllerTest.php
+++ b/tests/application/modules/opac/controllers/IndexControllerTest.php
@@ -142,4 +142,41 @@ class IndexControllerWithLoggedUserTest extends AbstractControllerTestCase {
 		$this->assertXPath('//body[@data-logged="true"]');
 	}
 }
+
+
+
+class IndexControllerAsPhoneWithPhoneProfilTest extends AbstractControllerTestCase {
+	public function setUp() {
+		parent::setUp();
+ 		$_SERVER['HTTP_USER_AGENT'] = 'iphone';
+		$this->fixture('Class_Profil',
+									 ['id' => 9999,
+										'browser' => 'telephone']);
+
+		$this->dispatch('/opac', true);
+	}
+
+
+	/** @test */
+	public function messageToRedirectToPhoneModeShouldBePresent() {
+		$this->assertXPath('//div[@class="back_to_phone"]');
+	}
+}
+
+
+
+class IndexControllerAsPhoneWithNoPhoneProfilTest extends AbstractControllerTestCase {
+	public function setUp() {
+		parent::setUp();
+ 		$_SERVER['HTTP_USER_AGENT'] = 'iphone';
+		$this->dispatch('/opac', true);
+	}
+
+
+	/** @test */
+	public function messageToRedirectToPhoneModeShouldBePresent() {
+		$this->assertNotXPath('//div[@class="back_to_phone"]');
+	}
+}
+
 ?>
\ No newline at end of file
-- 
GitLab