diff --git a/library/Class/Profil.php b/library/Class/Profil.php index bcabb2dfbc21848f3a89fa44530893d5b604d104..18e72344d11419ce2cb1f6f9c23944531b0f7ee3 100644 --- a/library/Class/Profil.php +++ b/library/Class/Profil.php @@ -65,6 +65,7 @@ class Class_Profil extends Storm_Model_Abstract { use Trait_TreeNode; const DIV_BANNIERE = 4; + const DIV_FLOTANTTE = 5; protected static $_default_translator = null; protected $_loader_class = 'ProfilLoader'; @@ -1087,9 +1088,19 @@ class Class_Profil extends Storm_Model_Abstract { * @return bool */ public function isTypeBoiteInBanniere($type_module) { - $modules_banniere = $this->getBoitesDivision(self::DIV_BANNIERE); - foreach ($modules_banniere as $module) { - if ($module['type_module'] == $type_module) + return $this->hasBoiteInDivision(self::DIV_BANNIERE,$type_module); + } + + + public function hasBoiteInDivision($division, $type_module) { + if ($division == self::DIV_BANNIERE and $this->hasParentProfil()) + $cfg_accueil = $this->getParentProfil()->getCfgAccueilAsArray(); + else + $cfg_accueil = $this->getCfgAccueilAsArray(); + + $boites = $this->_filterCfgAccueilByDivision($cfg_accueil, $division); + foreach ($boites as $boite) { + if ($boite['type_module'] == $type_module) return true; } return false; @@ -1103,9 +1114,15 @@ class Class_Profil extends Storm_Model_Abstract { public function getBoitesDivision($division) { if ($division == self::DIV_BANNIERE and $this->hasParentProfil()) $cfg_accueil = $this->getParentProfil()->getCfgAccueilAsArray(); + else if ($division == '5') + $cfg_accueil = $this->getCfgDivisionFiveAsArray(); else $cfg_accueil = $this->getCfgAccueilAsArray(); + return $this->_filterCfgAccueilByDivision($cfg_accueil, $division); + } + + protected function _filterCfgAccueilByDivision($cfg_accueil, $division) { $boites = array(); $modules = $cfg_accueil['modules'] ? $cfg_accueil['modules'] : []; @@ -1130,31 +1147,59 @@ class Class_Profil extends Storm_Model_Abstract { } + protected function getCfgDivisionFiveAsArray() { + return $this->setBoitePanierInDivisionFive() + ->getCfgAccueilAsArray(); + } + + + protected function setBoitePanierInDivisionFive() { + return $this->setBoiteOfTypeInDivision(5, 'PANIER'); + } + + + protected function setBoiteOfTypeInDivision($division, $type_module, $preferences = []) { + if($this->hasBoiteInDivision($division,$type_module)) + return $this; + + $id = $this->createNewModuleAccueilId(); + $module = ['division' => $division, + 'type_module' => $type_module, + 'preferences' => $this->getDefautBoite($type_module)]; + $module['preferences']['id_module'] = $id; + $module['preferences'] = array_merge($module['preferences'], $preferences); + + $cfg_accueil = $this->getCfgAccueilAsArray(); + $cfg_accueil['modules'][$id] = $module; + + return $this->setCfgAccueil($cfg_accueil); + } + + /** * @param bool $is_present * @param string $type_module * @return Class_Profil */ - public function setBoiteOfTypeInBanniere($is_present, $type_module) { - $cfg_accueil = $this->getCfgAccueilAsArray(); + public function addBoiteOfTypeInBanniere($type_module) { + $style_boite = ($type_module == 'LOGIN') + ? 'boite_banniere_droite' + : 'boite_banniere_gauche'; - if ($is_present) { - $id = $this->createNewModuleAccueilId(); - - $module = array('division' => self::DIV_BANNIERE, - 'type_module' => $type_module, - 'preferences' => $this->getDefautBoite($type_module)); - $module['preferences']['id_module'] = $id; - $module['preferences']['boite'] = $type_module == 'LOGIN' ? 'boite_banniere_droite' : 'boite_banniere_gauche'; - $cfg_accueil['modules'][$id] = $module; - - } else { - foreach ($cfg_accueil['modules'] as $index => $module) { - if ($module['division'] == self::DIV_BANNIERE and - $module['type_module'] == $type_module) - unset($cfg_accueil['modules'][$index]); - } + return $this->setBoiteOfTypeInDivision(self::DIV_BANNIERE, + $type_module, + ['boite' => $style_boite]); + } + + + public function removeBoiteOfTypeBanniere($type_module) { + $cfg_accueil = $this->getCfgAccueilAsArray(); + foreach ($cfg_accueil['modules'] as $index => $module) { + if ($module['division'] == self::DIV_BANNIERE and + $module['type_module'] == $type_module) + unset($cfg_accueil['modules'][$index]); } + return $this->setCfgAccueil($cfg_accueil); } @@ -1180,24 +1225,27 @@ class Class_Profil extends Storm_Model_Abstract { * @param bool $is_present * @return Class_Profil */ - public function setBoiteLoginInBanniere($is_present) { - if ($is_present and $this->getBoiteLoginInBanniere()) + public function setBoiteLoginInBanniere($add_or_remove) { + if ($add_or_remove and $this->getBoiteLoginInBanniere()) return $this; - return $this->setBoiteOfTypeInBanniere($is_present, 'LOGIN'); + return $add_or_remove + ? $this->addBoiteOfTypeInBanniere('LOGIN') + : $this->removeBoiteOfTypeBanniere('LOGIN'); } /** - * @param bool $is_present + * @param bool $add_or_remove * @return Class_Profil */ - public function setBoiteRechercheSimpleInBanniere($is_present) { - if ($is_present and $this->getBoiteRechercheSimpleInBanniere()) + public function setBoiteRechercheSimpleInBanniere($add_or_remove) { + if ($add_or_remove and $this->getBoiteRechercheSimpleInBanniere()) return $this; - - return $this->setBoiteOfTypeInBanniere($is_present, 'RECH_SIMPLE'); + return $add_or_remove + ? $this->addBoiteOfTypeInBanniere('RECH_SIMPLE') + : $this->removeBoiteOfTypeBanniere('RECH_SIMPLE'); } @@ -1655,13 +1703,12 @@ class Class_Profil extends Storm_Model_Abstract { public function hasBoitePanier() { - return $this->recursive_array_search_boite('PANIER', $this->getCfgAccueilAsArray()['modules']); return $this->hasBoite('PANIER'); } public function hasBoite($type) { - return $this->recursive_array_search_boite($type, $this->getCfgAccueilAsArray()['modules']); + return 0 < $this->getBoiteId($type); } diff --git a/tests/application/modules/admin/controllers/ProfilControllerPageAccueilTest.php b/tests/application/modules/admin/controllers/ProfilControllerPageAccueilTest.php index e9072113524d21a8c0a69794e5e275dbad1f7517..7c1b90f87ea25a684e3bc84bba3883426af02b23 100644 --- a/tests/application/modules/admin/controllers/ProfilControllerPageAccueilTest.php +++ b/tests/application/modules/admin/controllers/ProfilControllerPageAccueilTest.php @@ -724,4 +724,54 @@ class Admin_ProfilControllerPageAccueilJeunesseConfigEmptyPanierTest extends Adm +abstract class Admin_ProfilControllerPageAccueilNoBoitePanierTestCase extends Admin_AbstractControllerTestCase { + + protected $profil_no_panier; + + public function setup() { + parent::setup(); + + Class_Profil::beVolatile(); + + $cfg_accueil = ['page_css' => '', + 'use_parent_css' => 1, + 'modules' => ['1' => ['division' => 4, + 'type_module' => 'RECH_SIMPLE', + 'preferences' => []], + '2' => ['division' => 1, + 'type_module' => 'NEWS', + 'preferences' => []], + '3' => ['division' => 2, + 'type_module' => 'KIOSQUE', + 'preferences' => ['nb_notices' => 12, + 'nb_analyse' => 36, + 'only_img' => 1]]]]; + + $this->profil_no_panier = Class_Profil::newInstanceWithId(47897) + ->setLibelle('Profil sans panier') + ->setCfgAccueil($cfg_accueil); + + $this->profil_no_panier->save(); + } + +} + + + + +class Admin_ProfilControllerPageAccueilNoPanierTest extends Admin_ProfilControllerPageAccueilNoBoitePanierTestCase { + + public function setUp() { + parent::setUp(); + + ZendAfi_Auth::getInstance()->getIdentity()->ROLE_LEVEL = 7; + $this->dispatch('/admin/profil/accueil/id_profil/47897', true); + } + + + /** @test **/ + public function boitePanierShouldHaveBeenAddedInDivision5() { + $this->assertXPath('//ul[@id="box5"]/li[@id="PANIER"]'); + } +} ?> diff --git a/tests/library/Class/ProfilTest.php b/tests/library/Class/ProfilTest.php index d75171a864d440da04795c02890ebd3070c51855..0b0eba9f0429683b0e5907800be84129c231f997 100644 --- a/tests/library/Class/ProfilTest.php +++ b/tests/library/Class/ProfilTest.php @@ -385,8 +385,8 @@ abstract class ProfilAdulteChatenayTestCase extends ModelTestCase { public function setUp() { parent::setUp(); $cfg_accueil = array('modules' => array('1' => array('division' => '4', - 'type_module' => 'RECH_SIMPLE', - 'preferences' => array()), + 'type_module' => 'RECH_SIMPLE', + 'preferences' => array()), '2' => array('division' => '4', 'type_module' => 'LOGIN', @@ -683,6 +683,13 @@ class ProfilAdulteChatenayTest extends ProfilAdulteChatenayTestCase { Class_Profil::getPortail()->setMailSuggestionAchat('')->setMailSite('admin@chatenay.fr'); $this->assertEquals('admin@chatenay.fr', Class_Profil::getPortail()->getMailSuggestionAchatOrPortail()); } + + + /** @test **/ + public function modulePanierShouldHaveBeendAdded() { + $this->profil->getBoitesDivision(5); + $this->assertTrue($this->profil->hasBoitePanier()); + } }