Commit 0ad2a557 authored by efalcy's avatar efalcy
Browse files

Boite "Lettre d'informations" (Newsletter)

parent 214eaca6
......@@ -332,6 +332,7 @@ application/modules/admin/views/scripts/accueil/langue.phtml -text
application/modules/admin/views/scripts/accueil/login.phtml -text
application/modules/admin/views/scripts/accueil/menuvertical.phtml -text
application/modules/admin/views/scripts/accueil/news.phtml -text
application/modules/admin/views/scripts/accueil/newsletters.phtml -text
application/modules/admin/views/scripts/accueil/prets.phtml -text
application/modules/admin/views/scripts/accueil/rechguidee.phtml -text
application/modules/admin/views/scripts/accueil/rechsimple.phtml -text
......@@ -1857,6 +1858,7 @@ library/Class/Systeme/ModulesAccueil/Langue.php -text
library/Class/Systeme/ModulesAccueil/Login.php -text
library/Class/Systeme/ModulesAccueil/MenuVertical.php -text
library/Class/Systeme/ModulesAccueil/News.php -text
library/Class/Systeme/ModulesAccueil/Newsletters.php -text
library/Class/Systeme/ModulesAccueil/Null.php -text
library/Class/Systeme/ModulesAccueil/Prets.php -text
library/Class/Systeme/ModulesAccueil/RechercheGuidee.php -text
......@@ -2070,6 +2072,7 @@ library/ZendAfi/View/Helper/Accueil/Langue.php -text
library/ZendAfi/View/Helper/Accueil/Login.php -text
library/ZendAfi/View/Helper/Accueil/MenuVertical.php -text
library/ZendAfi/View/Helper/Accueil/News.php -text
library/ZendAfi/View/Helper/Accueil/Newsletters.php -text
library/ZendAfi/View/Helper/Accueil/Prets.php -text
library/ZendAfi/View/Helper/Accueil/RechGuidee.php -text
library/ZendAfi/View/Helper/Accueil/RechSimple.php -text
......@@ -4599,6 +4602,7 @@ tests/library/ZendAfi/View/Helper/Accueil/CritiquesTest.php -text
tests/library/ZendAfi/View/Helper/Accueil/LangueTest.php -text
tests/library/ZendAfi/View/Helper/Accueil/MenuVerticalTest.php -text
tests/library/ZendAfi/View/Helper/Accueil/NewsTest.php -text
tests/library/ZendAfi/View/Helper/Accueil/NewslettersTest.php -text
tests/library/ZendAfi/View/Helper/Accueil/PretsTest.php -text
tests/library/ZendAfi/View/Helper/Accueil/ReservationsTest.php -text
tests/library/ZendAfi/View/Helper/Accueil/RssTest.php -text
......
......@@ -144,6 +144,10 @@ class Admin_AccueilController extends Zend_Controller_Action {
$this->_simpleAction();
}
public function newslettersAction() {
$this->_simpleAction();
}
public function bibliothequeNumeriqueAction() {
if (1 == $this->_getParam('styles_reload')) {
$this->view->preferences = $this->_request->getPost();
......
<center>
<h1>Propriétés du module Lettres d'informations</h1><br>
<div class="formTable">
<form method="post" action="<?php echo $this->url ?>">
<fieldset>
<legend>Affichage</legend>
<table cellspacing="2">
<tr>
<td class="droite">Style de boite&nbsp;</td>
<td class="gauche"><?php echo $this->combo_templates ?></td>
</tr>
<tr>
<td class="droite">Titre de la boite&nbsp;</td>
<td class="gauche"><input type="text" name="titre" size="52" value="<?php print($this->preferences["titre"]); ?>"></td>
</tr>
</table>
</fieldset>
<?php echo $this->formSubmit("Valider","Valider",array("class" => "bouton")) ?>
</form>
</div>
......@@ -18,12 +18,13 @@
* 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 AbonneController extends Zend_Controller_Action {
class AbonneController extends ZendAfi_Controller_Action {
use Trait_Translator;
protected $_user = null; // Le user connecté
public function init() {
parent::init();
if ("authenticate" == $this->getRequest()->getActionName())
return;
......@@ -91,6 +92,47 @@ class AbonneController extends Zend_Controller_Action {
}
public function subscribeNewsletterAction() {
$this->_stayOnPage();
if (!$newsletter = Class_Newsletter::find((int)$this->_getParam('id'))) {
$this->_helper->notify('Newsletter non trouvée');
return;
}
$this->_user->addNewsletter($newsletter);
if ($this->_user->save()) {
$this->_helper->notify(sprintf('Vous êtes inscrit à la liste de diffusion: %s',
$newsletter->getTitre()));
};
}
public function unsubscribeNewsletterAction() {
$this->_stayOnPage();
if (!$newsletter = Class_Newsletter::find((int)$this->_getParam('id'))) {
$this->_helper->notify('Newsletter non trouvée');
return;
}
$this->_user->removeNewsletter($newsletter);
if ($this->_user->save()) {
$this->_helper->notify(sprintf('Vous êtes désinscrit de la liste de diffusion: %s',
$newsletter->getTitre()));
};
}
public function detailsessionAction() {
if (!$session = Class_SessionFormation::getLoader()->find((int)$this->_getParam('id')))
$this->_redirect('/abonne/formations');
......@@ -429,6 +471,35 @@ class AbonneController extends Zend_Controller_Action {
}
public function newslettersAction() {
/* $newsletters = array();
$newsletters_id = $this->_request->getParam('subscriptions', array());
foreach($newsletters_id as $nl_id)
$newsletters []= Class_Newsletter::getLoader()->find($nl_id);
$this->_user
->setNewsletters($newsletters) */
}
public function subscribeAction() {
/* $newsletters = array();
$newsletters_id = $this->_request->getParam('subscriptions', array());
foreach($newsletters_id as $nl_id)
$newsletters []= Class_Newsletter::getLoader()->find($nl_id);
$this->_user
->setNewsletters($newsletters) */
}
public function authenticateAction() {
$this->getHelper('ViewRenderer')->setNoRender();
......
......@@ -220,3 +220,6 @@ var openDialogExemplaires = function() {
** Affichage "propriétés de la boite"
[[file:application/modules/admin/controllers/AccueilController.php::public%20function%20reservationsAction()%20{][Action Mes reservations]]
[[file:application/modules/admin/views/scripts/accueil/reservations.phtml][Html de la boite propriete]]
[[file:library/Class/Systeme/ModulesAccueil.php::'NEWSLETTERS'%20%3D>%20new%20Class_Systeme_ModulesAccueil_Newsletters,][Ajout de la boite dans le drag-drop]]
**
......@@ -118,7 +118,12 @@ class Class_Systeme_ModulesAccueil extends Class_Systeme_ModulesAbstract {
'LANGUE' => new Class_Systeme_ModulesAccueil_Langue,
'BIB_NUMERIQUE' => new Class_Systeme_ModulesAccueil_BibliothequeNumerique,
'RESERVATIONS' => new Class_Systeme_ModulesAccueil_Reservations,
'PRETS' => new Class_Systeme_ModulesAccueil_Prets
'PRETS' => new Class_Systeme_ModulesAccueil_Prets,
'NEWSLETTERS' => new Class_Systeme_ModulesAccueil_Newsletters
// 'FORMATIONS' => new Class_Systeme_ModulesAccueil_Formations,
// 'MULTIMEDIA' => new Class_Systeme_ModulesAccueil_Multimedia
];
}
......
<?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
*/
class Class_Systeme_ModulesAccueil_Newsletters extends Class_Systeme_ModulesAccueil_Null{
/** @var string */
protected $_group = Class_Systeme_ModulesAccueil::GROUP_INFO;
/** @var string */
protected $_libelle = 'Lettres d\'informations';
/** @var string */
protected $_action = 'newsletters';
/** @var int */
protected $_popupWidth = 570;
/** @var int */
protected $_popupHeight = 400;
/** @var array */
protected $_defaultValues = array(
'titre' => "Lettres d'informations", // Titre de la boite
);
}
?>
\ No newline at end of file
......@@ -434,6 +434,7 @@ class Class_Users extends Storm_Model_Abstract {
}
/**
* @return array
*/
......
......@@ -131,5 +131,9 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action {
* @param $model Storm_Model_Abstract
*/
protected function _postEditAction($model) {}
protected function _stayOnPage() {
$this->_redirect($this->_request->getServer('HTTP_REFERER'));
}
}
?>
\ No newline at end of file
<?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
*/
class ZendAfi_View_Helper_Accueil_Newsletters extends ZendAfi_View_Helper_Accueil_Base {
public function getHTML() {
$this->titre = $this->view->tagAnchor($this->view->url([ 'controller' => 'abonne',
'action' => 'newsletters'
]),$this->preferences['titre']);
$user = Class_Users::getIdentity();
if (!isset($user))
return $this->getHtmlArray() ;
$newsletters = sprintf('<ul>%s</ul>',
implode('',
array_map(
function($newsletter) {
$start_li='<li>';
$titre = $newsletter->getTitre();
$button_subscribe = $this->view->tagAnchor($this->view->url(['controller' => 'abonne',
'action' => 'subscribe-newsletter',
'id' => $newsletter->getId()]),
$this->view->_("S'inscrire"));
$button_unsubscribe = $this->view->tagAnchor($this->view->url(['controller' => 'abonne',
'action' => 'unsubscribe-newsletter',
'id' => $newsletter->getId()]),
$this->view->_('Se désinscrire'));
$user = Class_Users::getIdentity();
foreach( $user->getNewsletters() as $user_newsletter ) {
if ($newsletter->getId() == $user_newsletter->getId())
return $start_li.$titre.' '.$button_unsubscribe.'</li>';
}
return $start_li.$titre.' '.$button_subscribe.'</li>';
},
Class_Newsletter::getLoader()->findAll())));
$this->contenu = sprintf('<div class="boite_newsletters">%s</div>',$newsletters);
return $this->getHtmlArray();
}
public function isBoiteVisible() {
return null != Class_Users::getIdentity();
}
public function shouldCacheContent() {
return false;
}
}
?>
\ No newline at end of file
......@@ -274,13 +274,13 @@ table.calendar_main {margin-left: auto; margin-right: auto}
}
.boite_prets ul, .boite_prets li, .boite_reservations ul, .boite_reservations li {
.boite_prets ul, .boite_prets li, .boite_reservations ul, .boite_reservations li, .boite_newsletters li , .boite_newsletters ul {
list-style: none;
padding: 0;
margin:0;
}
.boite_prets li, .boite_reservations li {
.boite_prets li, .boite_reservations li, .boite_newsletters li {
margin-bottom: 5px;
}
......
......@@ -47,6 +47,18 @@ abstract class Admin_ProfilControllerJeunessePageAccueilTestCase extends Admin_A
'type_module' => 'PRETS',
'preferences' => array()),
'10' => array('division' => 1,
'type_module' => 'NEWSLETTERS',
'preferences' => array()),
'11' => array('division' => 1,
'type_module' => 'FORMATIONS',
'preferences' => array()),
'12' => array('division' => 1,
'type_module' => 'MULTIMEDIA',
'preferences' => array()),
'666' => array('division' => 1,
'type_module' => 'WRONG',
......@@ -405,8 +417,59 @@ class Admin_ProfilControllerJeunessePageAccueilConfigEmptyReservationTest extend
/** @test */
public function titreInputShouldHaveValueMesReservations() {
$this->assertXPath('//input[@name="titre"][@value="Mes réservations"]',$this->html);
$this->assertXPath('//input[@name="titre"][@value="Mes réservations"]');
}
}
class Admin_ProfilControllerJeunessePageAccueilConfigNewslettersTest extends Admin_ProfilControllerJeunessePageAccueilTestCase {
public function setup() {
parent::setup();
$this->dispatch('admin/accueil/newsletters?config=admin&id_profil=7&type_module=NEWSLETTERS&id_module=10&proprietes=boite=/titre=Mes newsletters/',true);
}
/** @test */
public function actionShouldBeNewsletters() {
$this->assertAction('newsletters');
}
/** @test */
public function titleShouldBeProprieteDuModuleNewsletters() {
$this->assertXPathContentContains('//h1','Propriétés du module Lettres d\'informations',$this->_response->getBody());
}
/** @test */
public function comboBoiteShouldBePresent() {
$this->assertXPath('//select[@name="boite"]/option[@value="boite_de_la_division_droite"]');
}
/** @test */
public function titreInputShouldHaveValueMesNewsletters() {
$this->assertXPath('//input[@name="titre"][@value="Mes newsletters"]',$this->_response->getBody());
}
}
class Admin_ProfilControllerJeunessePageAccueilConfigEmptyNewsletterTest extends Admin_ProfilControllerJeunessePageAccueilTestCase {
public function setup() {
parent::setup();
$this->dispatch('admin/accueil/newsletters?config=admin&id_profil=7&type_module=NEWSLETTERS&id_module=11',true);
}
/** @test */
public function titreInputShouldHaveValueMesNewsletters() {
$this->assertXPath('//input[@name="titre"][@value="Lettres d\'informations"]',$this->_response->getBody());
}
}
?>
\ No newline at end of file
......@@ -48,10 +48,8 @@ abstract class AbstractAbonneControllerNewslettersTestCase extends AbstractContr
->whenCalled('save')
->answers(true);
$this->newsletter_loader = $this->getMock('MockModelLoader', array('findAll', 'find'));
Storm_Model_Abstract::setLoaderFor('Class_Newsletter', $this->newsletter_loader);
$this->newsletter_loader = Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Newsletter');
parent::setUp();
}
}
......@@ -61,22 +59,14 @@ abstract class AbonneControllerWithTwoNewslettersTestCase extends AbstractAbonne
public function setUp() {
parent::setUp();
$this->concerts = new Class_Newsletter();
$this->concerts
->setId(12)
->setTitre('Concerts')
->setContenu('Festival jazz');
$this->concerts = Class_Newsletter::newInstanceWithId(12, ['titre' =>'Concerts',
'contenu' => 'Festival jazz']);
$this->visites = new Class_Newsletter();
$this->visites
->setId(14)
->setTitre('Visites')
->setContenu('du patrimoine');
$this->visites = Class_Newsletter::newInstanceWithId(14, [ 'titre' =>'Visites',
'contenu' => 'du patrimoine']);
$this->newsletter_loader
->expects($this->any())
->method('findAll')
->will($this->returnValue(array($this->concerts, $this->visites)));
$this->newsletter_loader->whenCalled('findAll')
->answers(array($this->concerts, $this->visites));
$this->marcus
->setNewsletters(array($this->concerts)); //Marcus is subscribed to concerts newsletter
......@@ -84,16 +74,13 @@ abstract class AbonneControllerWithTwoNewslettersTestCase extends AbstractAbonne
}
class AbonneControllerFicheActionWithNoExistingNewsletterTest extends AbstractAbonneControllerNewslettersTestCase {
class AbonneControllerNewslettersFicheActionWithNoExistingNewslettersTest extends AbstractAbonneControllerNewslettersTestCase {
public function setUp() {
parent::setUp();
$this->marcus->setNewsletters(array());
$this->newsletter_loader
->expects($this->any())
->method('findAll')
->will($this->returnValue(array()));
$this->newsletter_loader->whenCalled('findAll')
->answers(array());
$this->dispatch('/opac/abonne');
}
......@@ -118,7 +105,7 @@ class AbonneControllerFicheActionWithNoExistingNewsletterTest extends AbstractAb
}
class AbonneControllerFicheActionWithOneSubscriptionTest extends AbonneControllerWithTwoNewslettersTestCase {
class AbonneControllerNewslettersFicheActionWithOneSubscriptionTest extends AbonneControllerWithTwoNewslettersTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/opac/abonne', true);
......@@ -154,7 +141,7 @@ class AbonneControllerFicheActionWithOneSubscriptionTest extends AbonneControlle
}
class AbonneControllerFicheActionWithTwoSubscriptionsTest extends AbonneControllerWithTwoNewslettersTestCase {
class AbonneControllerNewslettersFicheActionWithTwoSubscriptionsTest extends AbonneControllerWithTwoNewslettersTestCase {
public function setUp() {
parent::setUp();
......@@ -172,7 +159,7 @@ class AbonneControllerFicheActionWithTwoSubscriptionsTest extends AbonneControll
}
class AbonneControllerFicheActionWithNoSubscriptionTest extends AbonneControllerWithTwoNewslettersTestCase {
class AbonneControllerNewslettersFicheActionWithNoSubscriptionTest extends AbonneControllerWithTwoNewslettersTestCase {
public function setUp() {
parent::setUp();
......@@ -189,7 +176,7 @@ class AbonneControllerFicheActionWithNoSubscriptionTest extends AbonneController
}
class AbonneControllerNewsletterEditActionTest extends AbonneControllerWithTwoNewslettersTestCase {
class AbonneControllerNewslettersEditActionTest extends AbonneControllerWithTwoNewslettersTestCase {
public function setUp() {
parent::setUp();
......@@ -259,16 +246,10 @@ class AbonneControllerNewsletterEditActionTest extends AbonneControllerWithTwoNe
class AbonneControllerNewsletterSaveActionTest extends AbonneControllerWithTwoNewslettersTestCase {
class AbonneControllerNewslettersSaveActionTest extends AbonneControllerWithTwoNewslettersTestCase {
public function setUp() {
parent::setUp();
$this->newsletter_loader
->expects($this->once())
->method('find')
->with(14)
->will($this->returnValue($this->visites));
$data = array('nom' => 'MILLER',
'prenom' => 'MARCUS',
'mail' => 'marcus@free.fr',
......@@ -319,7 +300,7 @@ class AbonneControllerNewsletterSaveActionTest extends AbonneControllerWithTwoNe
}
class AbonneControllerNewsletterSaveWithEmptyDataTest extends AbonneControllerWithTwoNewslettersTestCase {
class AbonneControllerNewslettersSaveWithEmptyDataTest extends AbonneControllerWithTwoNewslettersTestCase {
public function setUp() {
parent::setUp();
......@@ -345,7 +326,7 @@ class AbonneControllerNewsletterSaveWithEmptyDataTest extends AbonneControllerWi
class AbonneControllerNewsletterOpsysCommunicationTest extends AbonneControllerWithTwoNewslettersTestCase {
class AbonneControllerNewslettersOpsysCommunicationTest extends AbonneControllerWithTwoNewslettersTestCase {
public function setUp() {
parent::setUp();
......@@ -402,8 +383,74 @@ class AbonneControllerNewsletterOpsysCommunicationTest extends AbonneControllerW
class AbonneControllerNewslettersSubscriptionTest extends AbonneControllerWithTwoNewslettersTestCase {
public function setUp() {
parent::setUp();
$_SERVER['HTTP_REFERER'] = '/opac/index';
$this->dispatch('/opac/abonne/subscribe-newsletter/id/14',true);
}
/** @test **/
public function subscribeActionShouldCallSubscribenewsletterAction() {
$this->assertAction('subscribe-newsletter');
}
/** @test **/
public function subscribeActionShouldRedirectToCurrentPage() {
$this->assertRedirectTo('/opac/index');
}
/** @test **/
public function subscribeActionShouldAddNewsletterToUser() {
$this->assertContains( $this->visites,$this->marcus->getNewsletters());
}
/** @test **/
public function userShouldHaveBeenSaved() {
$this->assertTrue(Class_Users::methodHasBeenCalled('save'));
}
}
class AbonneControllerNewslettersUnsubscriptionTest extends AbonneControllerWithTwoNewslettersTestCase {
public function setUp() {