diff --git a/application/modules/admin/controllers/ModulesController.php b/application/modules/admin/controllers/ModulesController.php index 816e71e259967c11ec2f1dbe26b43744aaef187d..03a39b495d662703dc4be51f101cb7358a9f9323 100644 --- a/application/modules/admin/controllers/ModulesController.php +++ b/application/modules/admin/controllers/ModulesController.php @@ -83,6 +83,8 @@ class Admin_ModulesController extends ZendAfi_Controller_Action { public function indexAction() { + if($this->_getParam('action1') === 'formulairecontact') + return $this->_simpleAction('formulaire_contact'); return $this->_simpleAction('index_all'); } diff --git a/application/modules/admin/views/scripts/modules/formulaire_contact.phtml b/application/modules/admin/views/scripts/modules/formulaire_contact.phtml index b4c461fa86692fc3b3c62533f15fd97874d81e45..9c353ca362bcc97d0e5e211218613efd7f43b10c 100644 --- a/application/modules/admin/views/scripts/modules/formulaire_contact.phtml +++ b/application/modules/admin/views/scripts/modules/formulaire_contact.phtml @@ -6,8 +6,8 @@ <tr> <td class="droite">Proposer la sélection de bibliothèques </td> <td class="gauche"><?php echo $this->tag('input', '', ['type' => 'checkbox', - 'value' => $this->preferences['bib_selector'], - 'name' => 'bib_selector']);?> + 'value' => $this->preferences['bib_selector'], + 'name' => 'bib_selector']);?> </tr> </table> </fieldset> diff --git a/application/modules/opac/controllers/IndexController.php b/application/modules/opac/controllers/IndexController.php index af34afb57e3c804b79056e1baabef64b6818731b..441c7309c1cb6f8f0d6177f106b89f2d0d064290 100644 --- a/application/modules/opac/controllers/IndexController.php +++ b/application/modules/opac/controllers/IndexController.php @@ -59,8 +59,7 @@ class IndexController extends Zend_Controller_Action { public function formulairecontactAction() { - $this->view->_current_module['controller'] = 'formulairecontact'; - $form = $this->_formulaireContact(); + $this->view->form = new ZendAfi_Form_ContactForm(); if ($this->_request->isPost() && $form->isValid($this->_request->getPost())) { try { $this->_sendFormulaireContact(); @@ -70,81 +69,13 @@ class IndexController extends Zend_Controller_Action { } } - $this->view->form = $form; + } public function formulairecontactsentAction() {} - protected function _formulaireContact() { - return $this->view->newForm(array('id' => 'contact')) - ->setAttrib('class', 'zend_form') - ->addElement('text', 'nom', array( - 'label' => $this->view->_('Nom').' *', - 'size' => 50, - 'required' => true, - 'allowEmpty' => false)) - ->addElement('text', 'prenom', array( - 'label' => $this->view->_('Prénom').' *', - 'size' => 50, - 'required' => true, - 'allowEmpty' => false)) - ->addElement('text', 'adresse', array( - 'label' => $this->view->_('Adresse'), - 'size' => 50)) - ->addElement('text', 'code_postal', array( - 'label' => $this->view->_('Code postal').' *', - 'size' => 8, - 'required' => true, - 'allowEmpty' => false)) - ->addElement('text', 'ville', array( - 'label' => $this->view->_('Ville'), - 'size' => 50)) - ->addElement('text', 'mail', array( - 'label' => $this->view->_('E-mail').' *', - 'size' => 50, - 'required' => true, - 'allowEmpty' => false, - 'validators' => array('emailAddress'))) - ->addElement('text', 'sujet', array( - 'label' => $this->view->_('Sujet').' *', - 'size' => 50, - 'required' => true, - 'allowEmpty' => false)) - ->addElement('textarea', 'message', array( - 'label' => $this->view->_('Message').' *', - 'cols' => 60, - 'required' => true, - 'allowEmpty' => false)) - ->Adddisplaygroup( - array('nom', - 'prenom', - 'adresse', - 'ville', - 'code_postal', - 'mail'), - 'form_coordonnees', - array('legend' => $this->view->_('Vos coordonnées'))) - - ->addDisplayGroup( - array('sujet', - 'message'), - 'form_message', - array('legend' => $this->view->_('Votre message'))) - - ->addElement('captcha', 'captcha', array('captcha' => 'Image', - 'label' => $this->view->_('Recopiez le code'), - 'captchaOptions' => array('font' => PATH_FONTS.'/Vera.ttf', - 'imgDir' => PATH_CAPTCHA, - 'imgUrl' => URL_CAPTCHA))) - ->addDisplayGroup( - array('captcha'), - 'form_security', - array('legend' => $this->view->_('Sécurité'))); - } - - protected function _sendFormulaireContact() { if (!$mail_address = Class_Profil::getCurrentProfil()->getMailSiteOrPortail()) throw new Exception($this->view->_("destinataire non configuré. Vérifiez les paramètres du profil, champ 'E-mail du webmestre'")); diff --git a/library/Class/Bib.php b/library/Class/Bib.php index b71dbfeafd467b9ac72048ff0cefe0dc545549f2..efaa920b8b2ae93cdc879a185388ef5be76f4225 100644 --- a/library/Class/Bib.php +++ b/library/Class/Bib.php @@ -16,7 +16,7 @@ * * 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 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Table Name @@ -64,6 +64,17 @@ class BibLoader extends Storm_Model_Loader { $this->_portail = $this->newInstanceWithId(0)->setLibelle('Portail'); return $this->_portail; } + + + public function getBibsWithMail() { + $all_bibs = Class_Bib::findAll(); + $all_bibs = array_filter($all_bibs, function($bib) {return $bib->hasMail() ? $bib->getLibelle(): '';}); + $libelles = []; + foreach($all_bibs as $bib) { + $libelles[$bib->getId()] = $bib->getLibelle(); + } + return $libelles; + } } @@ -174,10 +185,10 @@ class Class_Bib extends Storm_Model_Abstract { public function getAffZoneAsArray() { if (!$aff_zone = ZendAfi_Filters_Serialize::unserialize($this->getAffZone())) - $aff_zone = array('profilID' => null, - 'libelle' => '', - 'posX' => 0, - 'posY' => 0, + $aff_zone = array('profilID' => null, + 'libelle' => '', + 'posX' => 0, + 'posY' => 0, 'posPoint' => ''); return $aff_zone; } diff --git a/library/Class/Systeme/ModulesAppli.php b/library/Class/Systeme/ModulesAppli.php index df3321c81bd432b1483315c87bab6b1cfbabd655..b82a6a04b791a921582f434449d9d8acffa3e027 100644 --- a/library/Class/Systeme/ModulesAppli.php +++ b/library/Class/Systeme/ModulesAppli.php @@ -46,9 +46,9 @@ class Class_Systeme_ModulesAppli extends Class_Systeme_ModulesAbstract { /** * @var array */ - private $modules = ['formulairecontact' => ['formulairecontact' => ['libelle' => 'Contact', - 'popup_width' => 500, - 'popup_height' => 300]], + private $modules = ['index' => ['formulairecontact' => ['libelle' => 'Contact', + 'popup_width' => 500, + 'popup_height' => 300]], 'abonne' => ['*' => ['libelle' => 'Abonne', 'popup_width' => 500, @@ -231,13 +231,13 @@ class Class_Systeme_ModulesAppli extends Class_Systeme_ModulesAbstract { break; case "bib": $valeurs = $this->getDefautBib($action); break; - case "formulairecontact": $valeurs = $this->getDefautFormulairecontactBib($action); + case "index": $valeurs = $this->getDefautIndex($action); break; case 'domains': $valeurs = (new Class_Systeme_ModulesAccueil_DomainBrowser())->getDefaultValues(); break; - default : $valeurs = array(); + default : $valeurs = []; } if (!array_key_exists('boite', $valeurs)) @@ -438,9 +438,10 @@ class Class_Systeme_ModulesAppli extends Class_Systeme_ModulesAbstract { } - protected function getDefautFormulairecontactBib($action) { - return ['barre_nav' => $this->_('Formulaire de contact'), - 'bib_selector' => '']; + protected function getDefautIndex($action) { + if($action === 'formulairecontact') + return (new Class_Systeme_ModulesMenu_FormulaireContact())->getDefaultValues(); + return []; } public function acceptVisitor($visitor) { diff --git a/library/Class/Systeme/ModulesMenu/FormulaireContact.php b/library/Class/Systeme/ModulesMenu/FormulaireContact.php index 4880c6536a4a6a3aaec094ebc66f0eab9657c761..64853cb2628927f1ed3748f9d0d2e634415711ff 100644 --- a/library/Class/Systeme/ModulesMenu/FormulaireContact.php +++ b/library/Class/Systeme/ModulesMenu/FormulaireContact.php @@ -16,9 +16,11 @@ * * 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 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Class_Systeme_ModulesMenu_FormulaireContact extends Class_Systeme_ModulesMenu_Null { + use Trait_Translator; + /** @var string */ protected $_group = Class_Systeme_ModulesMenu::GROUP_MENU_ABONNES; @@ -31,5 +33,8 @@ class Class_Systeme_ModulesMenu_FormulaireContact extends Class_Systeme_ModulesM /** @var string */ protected $_url = ['controller' => 'index', 'action' => 'formulairecontact']; + + protected $_default_values = ['barre_nav' => 'Formulaire de contact', + 'bib_selector' => '']; } ?> \ No newline at end of file diff --git a/library/ZendAfi/Form/ContactForm.php b/library/ZendAfi/Form/ContactForm.php new file mode 100644 index 0000000000000000000000000000000000000000..8fc1afc4abb413e7fd7fdd826409359382003be2 --- /dev/null +++ b/library/ZendAfi/Form/ContactForm.php @@ -0,0 +1,89 @@ +<?php +/** + * Copyright (c) 2012-2014, 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 + */ + + +class ZendAfi_Form_ContactForm extends ZendAfi_Form { + + public function init() { + parent::init(); + $this->setAttrib('class', 'zend_form') + ->addElement('text', 'nom', ['label' => $this->_('Nom').' *', + 'size' => 50, + 'required' => true, + 'allowEmpty' => false]) + ->addElement('text', 'prenom', ['label' => $this->_('Prénom').' *', + 'size' => 50, + 'required' => true, + 'allowEmpty' => false]) + ->addElement('text', 'adresse', ['label' => $this->_('Adresse'), + 'size' => 50]) + ->addElement('text', 'code_postal', ['label' => $this->_('Code postal').' *', + 'size' => 8, + 'required' => true, + 'allowEmpty' => false]) + ->addElement('text', 'ville', ['label' => $this->_('Ville'), + 'size' => 50]) + ->addElement('text', 'mail', ['label' => $this->_('E-mail').' *', + 'size' => 50, + 'required' => true, + 'allowEmpty' => false, + 'validators' => ['emailAddress']]) + ->addElement('text', 'sujet', [ + 'label' => $this->_('Sujet').' *', + 'size' => 50, + 'required' => true, + 'allowEmpty' => false]) + ->addElement('textarea', 'message', ['label' => $this->_('Message').' *', + 'cols' => 60, + 'required' => true, + 'allowEmpty' => false]) + ->addElement('select', 'bib_selector', ['label' => $this->_('Choississez votre bibliothèque'), 'multiOptions' => Class_Bib::getBibsWithMail()]) + + ->adddisplaygroup(['bib_selector'], + 'form_bib', + ['legend' => $this->_('Votre bibbliothèque')]) + + ->adddisplaygroup(['nom', + 'prenom', + 'adresse', + 'ville', + 'code_postal', + 'mail'], + 'form_coordonnees', + ['legend' => $this->_('Vos coordonnées')]) + + ->addDisplayGroup(['sujet', + 'message'], + 'form_message', + ['legend' => $this->_('Votre message')]) + + ->addElement('captcha', 'captcha', ['captcha' => 'Image', + 'label' => $this->_('Recopiez le code'), + 'captchaOptions' => ['font' => PATH_FONTS.'/Vera.ttf', + 'imgDir' => PATH_CAPTCHA, + 'imgUrl' => URL_CAPTCHA]]) + ->addDisplayGroup(['captcha'], + 'form_security', + ['legend' => $this->_('Sécurité')]); + + } +} +?> \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/ModulesControllerTest.php b/tests/application/modules/admin/controllers/ModulesControllerTest.php index 48d683106fe05d7ded18a6cde183496c1642df66..757235302170b9a38bea3ae2685288b8dd300199 100644 --- a/tests/application/modules/admin/controllers/ModulesControllerTest.php +++ b/tests/application/modules/admin/controllers/ModulesControllerTest.php @@ -771,7 +771,7 @@ class ModulesControllerSearchPostValidationTest extends Admin_AbstractController class ModulesControllerFormulaireContactTest extends Admin_AbstractControllerTestCase { public function setUp() { parent::setUp(); - $this->dispatch('/admin/modules/formulairecontact?config=site&type_module=formulairecontact&id_profil=1&action1=formulairecontact&action2=', true); + $this->dispatch('/admin/modules/index?config=site&type_module=index&id_profil=1&action1=formulairecontact&action2=', true); } diff --git a/tests/application/modules/opac/controllers/AbonneVSmartTest.php b/tests/application/modules/opac/controllers/AbonneVSmartTest.php index 25e865a03e144680b2d5518583f1ff0679442272..57999abf09eb94a37bb00b71c2f74ee760112b5d 100644 --- a/tests/application/modules/opac/controllers/AbonneVSmartTest.php +++ b/tests/application/modules/opac/controllers/AbonneVSmartTest.php @@ -16,7 +16,7 @@ * * 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 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'AbstractControllerTestCase.php'; @@ -32,7 +32,7 @@ abstract class AbonneVSmartTestCase extends AbstractControllerTestCase { Class_Notice::beVolatile(); Class_PanierNotice::beVolatile(); Class_PanierNoticeCatalogue::beVolatile(); - $this->manon = Class_Users::newInstanceWithId(34, ['pseudo' => 'Marcus', + $this->manon = Class_Users::newInstanceWithId(34, ['pseudo' => 'Marcus', 'login' => 'mlaffont', 'password' => '123', 'role_level' =>ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB]); @@ -62,13 +62,13 @@ abstract class AbonneVSmartTestCase extends AbstractControllerTestCase { ->method('getUserInformationsPopupUrl') ->will($this->returnValue('http://12.34.56.78/moulins/LoginWebSSo.csp')); - $this->manon + $this->manon ->setPrenom('Manon') ->setNom('Laffont') ->setMail('mlaffont@gmail.com') ->setPseudo('manoune') ->setDateDebut(null) - ->setFicheSIGB(array('type_comm' => Class_IntBib::COM_VSMART, + ->setFicheSIGB(array('type_comm' => Class_IntBib::COM_VSMART, 'nom_aff' => 'Marcus', 'fiche' => $emprunteur)) ->setRole('abonne_sigb') @@ -94,7 +94,6 @@ abstract class AbonneVSmartTestCase extends AbstractControllerTestCase { 'notices' => 'MONTESPAN', 'user' => $this->manon]); $this->panier_romans->save(); - xdebug_break(); } } @@ -104,7 +103,7 @@ abstract class AbonneVSmartTestCase extends AbstractControllerTestCase { class AbonneVSmartTest extends AbonneVSmartTestCase { public function setUp() { parent::setUp(); - + Class_AdminVar::newInstanceWithId('INTERDIRE_MODIF_FICHE_ABONNE', ['valeur' => false]); $this->dispatch('/opac/abonne/fiche/id/34', true); } @@ -118,21 +117,21 @@ class AbonneVSmartTest extends AbonneVSmartTestCase { /** @test */ function aDivAbonneFicheShouldContainsVousAvezDeuxPretsEnCoursUnEnRetard() { - $this->assertXPathContentContains('//div/a[contains(@href, "abonne/prets")]', + $this->assertXPathContentContains('//div/a[contains(@href, "abonne/prets")]', 'Vous avez 2 prêts en cours (1 en retard)'); } /** @test */ function aDivAbonneFicheShouldContainsVousAvezTroisReservationsEnCours() { - $this->assertXPathContentContains('//div/a[contains(@href, "abonne/reservations")]', + $this->assertXPathContentContains('//div/a[contains(@href, "abonne/reservations")]', 'Vous avez 3 réservations en cours'); } /** @test */ function aDivAbonneFicheShouldContainsVousAvezDeuxPaniersDeNotice() { - $this->assertXPathContentContains('//div/a[contains(@href, "panier")]', + $this->assertXPathContentContains('//div/a[contains(@href, "panier")]', 'Vous avez 2 paniers',$this->_response->getBody()); } diff --git a/tests/application/modules/opac/controllers/IndexControllerTest.php b/tests/application/modules/opac/controllers/IndexControllerTest.php index e0d4e57ce24076045ad7987d7ab1a1f5a57fe23b..2af481701889525a1c20b610012d84951207bff8 100644 --- a/tests/application/modules/opac/controllers/IndexControllerTest.php +++ b/tests/application/modules/opac/controllers/IndexControllerTest.php @@ -137,4 +137,56 @@ class IndexControllerFormulaireActionAsAdminTest extends IndexControllerAsAdminT $this->assertXPath('//img[contains(@onclick,"/admin/modules/formulairecontact")]', $this->_response->getBody()); } } + + + +class IndexControllerFormulaireActionWithBibSelectorSettingCheckedTest extends AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + + $this->fixture('Class_Bib', + ['id' => 1, + 'libelle' => 'my bib', + 'mail' => 'bib@bib.com']); + + $this->dispatch('/opac/index/formulairecontact',true); + } + + + /** @test */ + public function bibSelectorShouldBePresent() { + $this->assertXPath('//select[@name="bib_selector"]'); + } + + + /** @test */ + public function myBibOptionShouldBePresent() { + $this->assertXPathContentContains('//select//option', 'my bib'); + } +} + + + +class IndexControllerFormulaireActionWithBibSelectorSettingUncheckedTest extends AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + + $this->fixture('Class_Bib', + ['id' => 1, + 'libelle' => 'my bib', + 'mail' => 'bib@bib.com']); + + $this->dispatch('/opac/index/formulairecontact',true); + } + /** @test */ + public function bibSelectorShouldNotBePresent() { + $this->assertNotXPath('//select[@name="bib_selector"]'); + } + + + /** @test */ + public function myBibOptionShouldNotBePresent() { + $this->assertNotXPathContentContains('//select//option', 'my bib'); + } +} ?>