diff --git a/library/Class/Bib.php b/library/Class/Bib.php index 8789f5fa2ec6ee60bbd68c7176fe8c46ece94da8..39d594031ccaab74a28eafe4cf4cee335c6984a7 100644 --- a/library/Class/Bib.php +++ b/library/Class/Bib.php @@ -37,7 +37,7 @@ class BibLoader extends Storm_Model_Loader { protected $_portail; public function findAllWithPortail() { - $all_bibs = $this->findAll(); + $all_bibs = Class_Bib::getLoader()->findAll(); array_unshift($all_bibs, $this->getPortail()); return $all_bibs; } diff --git a/library/ZendAfi/View/Helper/ComboParentCategorie.php b/library/ZendAfi/View/Helper/ComboParentCategorie.php index a0378b5c0c78d66eaaf641f00b5fc283798c611e..21f5d4517ab7a4ab1cf76856bd7d8794170e29c6 100644 --- a/library/ZendAfi/View/Helper/ComboParentCategorie.php +++ b/library/ZendAfi/View/Helper/ComboParentCategorie.php @@ -19,28 +19,31 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -class ZendAfi_View_Helper_ComboParentCategorie extends ZendAfi_View_Helper_BaseHelper { +class ZendAfi_View_Helper_ComboParentCategorie extends ZendAfi_View_Helper_ComboCategories { public function comboParentCategorie($category) { - $html = '<select name="id_cat_mere" id="id_cat_mere" style="width:100%">'; - $html .= '<option value="0">Aucune</option>'; - - $rootCategories = $category->getBibRootCategories(); - - foreach ($rootCategories as $rootCategory) { - $html .= $this->_getLeveledParentCategoryOption($rootCategory, $category); + if (Class_Users::isCurrentUserCanAccessAllBibs()) + $bibs = Class_Bib::findAllWithPortail(); + else { + $bib = $category->getBib(); + if (0 == $bib->getId()) + $bib = $this->_bib; + $bibs = array($bib); } - return $html . '</select>'; + return sprintf('<select name="id_cat_mere" id="id_cat_mere">%s</select>', + $this->_getAllBibCategories($bibs, $category) + ); } + /** * @param Class_ArticleCategorie $category * @param Class_ArticleCategorie $origin * @param int $level * @return string */ - protected function _getLeveledParentCategoryOption($category, $origin, $level = 0) { + protected function _getLeveledCategoryOption($category, $origin, $level = 0) { // on exclut la categorie courante => impossible de se déplacer sous // soi-même ou un de ses descendants if ($category->getId() == $origin->getId()) { @@ -53,7 +56,7 @@ class ZendAfi_View_Helper_ComboParentCategorie extends ZendAfi_View_Helper_BaseH . $prefix . $category->getLibelle() . '</option>'; foreach ($category->getSousCategories() as $subCategory) { - $html .= $this->_getLeveledParentCategoryOption($subCategory, $origin, $level+1); + $html .= $this->_getLeveledCategoryOption($subCategory, $origin, $level+1); } return $html; diff --git a/tests/application/modules/admin/controllers/SitothequeControllerTest.php b/tests/application/modules/admin/controllers/SitothequeControllerTest.php index 30753a0fbed1fc597cb9eab9ea37cd7b1bcf00d1..e38c8e9b860bfaf03a358ba6275eaadab37ab4b1 100644 --- a/tests/application/modules/admin/controllers/SitothequeControllerTest.php +++ b/tests/application/modules/admin/controllers/SitothequeControllerTest.php @@ -43,13 +43,18 @@ abstract class SitothequeControllerTestCase extends Admin_AbstractControllerTest $bib_annecy = Class_Bib::newInstanceWithId(3, ['libelle' => 'Annecy']) - ->setSitothequeCategories([$categorie_informations]); + ->setSitothequeCategories([$categorie_informations]); Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Bib') ->whenCalled('findAllBy') ->with(['order' => 'libelle']) + ->answers([$bib_annecy]) + + ->whenCalled('findAll') ->answers([$bib_annecy]); + Class_Bib::getPortail()->setSitothequeCategories([]); + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Sitotheque') ->whenCalled('save')->answers(true) @@ -411,7 +416,8 @@ class SitothequeControllerAddCategorieTest extends SitothequeControllerTestCase /** @test */ public function selectIdCatMereShouldHaveCategorieInformationsSelected() { - $this->assertXPathContentContains('//select/option[@value="2"][@selected="selected"]', 'Informations'); + $this->assertXPathContentContains('//select/optgroup[@label="Annecy"]/option[@value="2"][@selected="selected"]', 'Informations', + $this->_response->getBody()); } }