From 791c31693e5abc0b606572c9290dc29be1b3ec32 Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Sat, 9 Feb 2013 16:55:22 +0000
Subject: [PATCH] =?UTF-8?q?Adaptation=20controller=20RSS=20=C3=A0=20la=20r?=
 =?UTF-8?q?efacto=20de=20la=20s=C3=A9lection=20des=20cat=C3=A9gories?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .gitattributes                                |  1 +
 .../admin/controllers/RssController.php       | 23 +++++---
 .../admin/views/scripts/rss/index.phtml       |  2 +-
 library/Class/Bib.php                         |  5 ++
 library/Class/Rss.php                         |  2 +-
 library/Class/RssCategorie.php                |  9 ++-
 library/Class/SitothequeCategorie.php         |  3 -
 .../ZendAfi/View/Helper/ComboCategories.php   |  2 +-
 .../admin/controllers/RssControllerTest.php   | 56 +++++++++++++++++++
 9 files changed, 87 insertions(+), 16 deletions(-)
 create mode 100644 tests/application/modules/admin/controllers/RssControllerTest.php

diff --git a/.gitattributes b/.gitattributes
index a3bf139364f..339c2cc172c 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -4944,6 +4944,7 @@ tests/application/modules/admin/controllers/ProfilControllerIndexTest.php -text
 tests/application/modules/admin/controllers/ProfilControllerPageAccueilTest.php -text
 tests/application/modules/admin/controllers/ProfilControllerProfilJeunesseAndAdultesWithMenusTest.php -text
 tests/application/modules/admin/controllers/ProfilControllerTest.php -text
+tests/application/modules/admin/controllers/RssControllerTest.php -text
 tests/application/modules/admin/controllers/SitothequeControllerTest.php -text
 tests/application/modules/admin/controllers/StatControllerTest.php -text
 tests/application/modules/admin/controllers/SuggestionAchatControllerTest.php -text
diff --git a/application/modules/admin/controllers/RssController.php b/application/modules/admin/controllers/RssController.php
index 1bd573441f6..b2d09a79591 100644
--- a/application/modules/admin/controllers/RssController.php
+++ b/application/modules/admin/controllers/RssController.php
@@ -22,8 +22,9 @@
 // OPAC3 : Controller fils RSS
 ////////////////////////////////////////////////////////////////////////////////
 
-class Admin_RssController extends Zend_Controller_Action
-{
+class Admin_RssController extends Zend_Controller_Action {
+	use Trait_Translator;
+
 	private $id_zone;
 	private $id_bib;
 	private $_today;
@@ -66,7 +67,7 @@ class Admin_RssController extends Zend_Controller_Action
 		$class_rss = new Class_Rss();
 		$rss=$class_rss->rendArray($this->id_bib);
 		$this->view->rss=$class_rss->rendHTML();
-		$this->view->titre = 'Mise à jour des flux RSS';
+		$this->view->titre = $this->_('Mise à jour des flux RSS');
 	}
 
 
@@ -190,6 +191,14 @@ class Admin_RssController extends Zend_Controller_Action
 		$this->view->titre = "Ajouter un flux RSS";
 		$class_rss = new Class_Rss();
 
+
+		$this->view->rss = new stdClass();
+		$this->view->rss->TITRE = '';
+		$this->view->rss->DESCRIPTION = '';
+		$this->view->rss->URL = '';
+		$this->view->rss->TAGS = '';
+		$this->view->rss->ID_RSS = 0;
+
 		if ($this->_request->isPost())
 		{
 			$filter = new Zend_Filter_StripTags();
@@ -217,8 +226,6 @@ class Admin_RssController extends Zend_Controller_Action
 			{
 				$combo_cat = $class_rss->rendComboCategorie($this->id_bib,$id_cat);
 				$menu_deploy = $this->saveTreeMenu($id_cat);
-
-				$this->view->rss = new stdClass();
 				$this->view->rss->ID_CAT = $id_cat;
 				$this->view->rss->TITRE = $titre;
 				$this->view->rss->DESCRIPTION = $commentaire;
@@ -226,6 +233,7 @@ class Admin_RssController extends Zend_Controller_Action
 				$this->view->rss->TAGS = $tags;
 				$this->view->combo_cat = $combo_cat;
 				$this->view->message = $errorMessage;
+
 			}
 
 		}
@@ -233,8 +241,7 @@ class Admin_RssController extends Zend_Controller_Action
 		{
 			$id_cat = (int)$this->_request->getParam('id', 0);
 			// set up an "empty" Rss
-			$combo_categories = new ZendAfi_View_Helper_ComboCategories();
-			$combo_cat = $combo_categories->rendComboCategories($this,$id_cat);
+			$combo_cat = $this->view->comboCategories(Class_RssCategorie::findFirstBy(['ID_CAT' => $id_cat]));
 			$menu_deploy = $this->saveTreeMenu($id_cat);
 			$this->view->combo_cat = $combo_cat;
 		}
@@ -284,7 +291,7 @@ class Admin_RssController extends Zend_Controller_Action
 					else
 					{
 						$combo_categories = new ZendAfi_View_Helper_ComboCategories();
-						$combo_cat = $combo_categories->rendComboCategories($this,Class_RssCategorie::findFirstBy(['ID_CAT' => $id_cat ] ));
+						$combo_cat = $combo_categories->comboCategories(Class_RssCategorie::findFirstBy(['ID_CAT' => $id_cat ] ));
 						$this->view->rss = new stdClass();
 						$this->view->rss->ID_CAT = $id_cat;
 						$this->view->rss->ID_RSS = $id_rss;
diff --git a/application/modules/admin/views/scripts/rss/index.phtml b/application/modules/admin/views/scripts/rss/index.phtml
index d8bf007d04c..71d4e370886 100644
--- a/application/modules/admin/views/scripts/rss/index.phtml
+++ b/application/modules/admin/views/scripts/rss/index.phtml
@@ -10,7 +10,7 @@ else echo ('<center><div align="center"><br />'.$this->bouton('id=c_19','picto=a
 if(!$this->rss and $this->id_bib) echo ("<br /><p align='center' class='error'>Aucune catégorie trouvée pour le critères spécifiés.</b></p>");
 echo $this->rss;
 
-if($_SESSION["MENU_DEPLOY"]["RSS"])
+if(isset($_SESSION["MENU_DEPLOY"]["RSS"]))
 {
     $menus = array_reverse($_SESSION["MENU_DEPLOY"]["RSS"]);
     echo '<script>';
diff --git a/library/Class/Bib.php b/library/Class/Bib.php
index 8d45d49b826..8789f5fa2ec 100644
--- a/library/Class/Bib.php
+++ b/library/Class/Bib.php
@@ -95,6 +95,11 @@ class Class_Bib extends Storm_Model_Abstract {
 																											'scope' => ['ID_CAT_MERE' => 0],
 																											'order' => 'libelle'],
 
+													'rss_categories' => ['model' => 'Class_RssCategorie',
+																							 'role' => 'bib',
+																							 'scope' => ['ID_CAT_MERE' => 0],
+																							 'order' => 'libelle'],
+
 													'ouvertures' => ['model' => 'Class_Ouverture',
 																					 'role' => 'bib',
 																					 'order' => ['jour', 'debut_matin'],
diff --git a/library/Class/Rss.php b/library/Class/Rss.php
index 91046a6169a..5841f3f8619 100644
--- a/library/Class/Rss.php
+++ b/library/Class/Rss.php
@@ -363,7 +363,7 @@ class Class_Rss extends Storm_Model_Abstract {
 			->where('ID_CAT=?', $id_cat_fille);
 		$stmt = $select->query();
 		$row = $stmt->fetchAll();
-		return ($row[0]["ID_CAT_MERE"]);
+		return isset($row[0]["ID_CAT_MERE"]) ? $row[0]["ID_CAT_MERE"] : 0;
 	}
 
 	public function rendComboCategorie($id_bib,$id_cat)
diff --git a/library/Class/RssCategorie.php b/library/Class/RssCategorie.php
index 90e4a26f090..bd437bf73d3 100644
--- a/library/Class/RssCategorie.php
+++ b/library/Class/RssCategorie.php
@@ -36,8 +36,13 @@ class Class_RssCategorie extends Storm_Model_Abstract {
 																									'dependents' => 'delete'));
 
 
-	public static function getLoader() {
-		return self::getLoaderFor(__CLASS__);
+	/**
+	 * @return array
+	 */
+	public function getBibRootCategories($bib=null) {
+		if (!$bib)
+			$bib = $this->getBib();
+		return $bib->getRssCategories();
 	}
 
 
diff --git a/library/Class/SitothequeCategorie.php b/library/Class/SitothequeCategorie.php
index a8ab86407d1..586f1b71f92 100644
--- a/library/Class/SitothequeCategorie.php
+++ b/library/Class/SitothequeCategorie.php
@@ -60,9 +60,6 @@ class Class_SitothequeCategorie extends Storm_Model_Abstract {
 	}
 
 
-	/**
-	 * @return array
-	 */
 	/**
 	 * @return array
 	 */
diff --git a/library/ZendAfi/View/Helper/ComboCategories.php b/library/ZendAfi/View/Helper/ComboCategories.php
index d89fd4c2a58..daa19269a76 100644
--- a/library/ZendAfi/View/Helper/ComboCategories.php
+++ b/library/ZendAfi/View/Helper/ComboCategories.php
@@ -52,7 +52,7 @@ class ZendAfi_View_Helper_ComboCategories extends ZendAfi_View_Helper_BaseHelper
 	 */
 	protected function _getCategorySelectGroupForBib($bib, $category) {
 		$html = sprintf('<optgroup label="%s">', $bib->getLibelle());
-		$rootCategories = $category->getBibRootCategories($bib);
+		$rootCategories = isset($category) ? $category->getBibRootCategories($bib) : [];
 		foreach ($rootCategories as $rootCategory) {
 			$html .= $this->_getLeveledCategoryOption($rootCategory, $category);
 		}
diff --git a/tests/application/modules/admin/controllers/RssControllerTest.php b/tests/application/modules/admin/controllers/RssControllerTest.php
new file mode 100644
index 00000000000..2422e0d89f9
--- /dev/null
+++ b/tests/application/modules/admin/controllers/RssControllerTest.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
+ *
+ * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
+ * the Free Software Foundation.
+ *
+ * There are special exceptions to the terms and conditions of the AGPL as it
+ * is applied to this software (see README file).
+ *
+ * AFI-OPAC 2.0 is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * along with AFI-OPAC 2.0; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA 
+ */
+require_once 'AdminAbstractControllerTestCase.php';
+
+abstract class RssControllerTestCase extends Admin_AbstractControllerTestCase {
+}
+
+
+
+
+class RssControllerIndexActionTest extends RssControllerTestCase {
+	public function setUp() {
+		parent::setUp();
+		$this->dispatch('/admin/rss', true);
+	}
+
+	/** @test */
+	public function titreShouldBeMiseAJourDesFluxRss() {
+		$this->assertXPathContentContains('//h1', 'Mise à jour des flux RSS');
+	}
+}
+
+
+
+
+class RssControllerAddActionTest extends RssControllerTestCase {
+	public function setUp() {
+		parent::setUp();
+		$this->dispatch('/admin/rss/rssadd', true);
+	}
+
+	/** @test */
+	public function titreShouldBeAjouterUnRss() {
+		$this->assertXPathContentContains('//h1', 'Ajouter un flux RSS');
+	}
+}
+
+?>
\ No newline at end of file
-- 
GitLab