Commit 37d5a856 authored by Patrick Barroca's avatar Patrick Barroca 🐧

rel #46014 : starting from previous story

parent 233d250e
- ticket #44823 : Newsletter : Inscrire automatiquement un nouvel inscrit
\ No newline at end of file
- ticket #46014 : Newsletter : gestion des destinataires par les groupes utilisateurs
\ No newline at end of file
<?php
$adapter = Zend_Db_Table_Abstract::getDefaultAdapter();
$adapter->query('CREATE TABLE IF NOT EXISTS `newsletter_group_autosubscribe` ('
$adapter->query('CREATE TABLE IF NOT EXISTS `newsletter_group_subscription` ('
. 'id int(11) unsigned not null auto_increment,'
. 'user_group_id int(11) not null,'
. 'newsletter_id int(11) not null,'
......
......@@ -65,11 +65,11 @@ class Class_Newsletter extends Storm_Model_Abstract {
'role' => 'newsletter',
'dependents' => 'delete'],
'newsletter_group_autosubscribes' => ['model' => 'Class_NewsletterGroupAutosubscribe',
'role' => 'newsletter',
'dependents' => 'delete'],
'newsletter_group_subscriptions' => ['model' => 'Class_NewsletterGroupSubscription',
'role' => 'newsletter',
'dependents' => 'delete'],
'user_groups' => ['through' => 'newsletter_group_autosubscribes']];
'user_groups' => ['through' => 'newsletter_group_subscriptions']];
protected $_notices_finder;
protected $_recipent_size = 20;
......
......@@ -19,13 +19,13 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class NewsletterGroupAutosubscribeLoader extends Storm_Model_Loader {
class NewsletterGroupSubscriptionLoader extends Storm_Model_Loader {
public function newslettersForUser($user) {
if (!$groups = $user->getDynamicUserGroups())
return [];
$ids = (new Storm_Model_Collection($groups))->collect('id')->getArrayCopy();
$autos = Class_NewsletterGroupAutosubscribe::findAllBy(['user_group_id' => $ids]);
$autos = Class_NewsletterGroupSubscription::findAllBy(['user_group_id' => $ids]);
return (new Storm_Model_Collection($autos))->collect('newsletter')->getArrayCopy();
}
......@@ -34,9 +34,9 @@ class NewsletterGroupAutosubscribeLoader extends Storm_Model_Loader {
class Class_NewsletterGroupAutosubscribe extends Storm_Model_Abstract {
protected $_table_name = 'newsletter_group_autosubscribe';
protected $_loader_class = 'NewsletterGroupAutosubscribeLoader';
class Class_NewsletterGroupSubscription extends Storm_Model_Abstract {
protected $_table_name = 'newsletter_group_subscription';
protected $_loader_class = 'NewsletterGroupSubscriptionLoader';
protected $_belongs_to = ['user_group' => ['model' => 'Class_UserGroup'],
'newsletter' => ['model' => 'Class_Newsletter']];
......
......@@ -38,12 +38,12 @@ class Class_UserGroup extends Storm_Model_Abstract {
'permissions' => ['through' => 'user_group_permissions',
'unique' => true],
'newsletter_group_autosubscribes' => ['model' => 'Class_NewsletterGroupAutosubscribe',
'role' => 'user_group',
'dependents' => 'delete'],
'newsletter_group_subscriptions' => ['model' => 'Class_NewsletterGroupSubscription',
'role' => 'user_group',
'dependents' => 'delete'],
'newsletter_autosubscribes' => ['through' => 'newsletter_group_autosubscribes',
'unique' => true]
'newsletter_subscriptions' => ['through' => 'newsletter_group_subscriptions',
'unique' => true]
];
protected $_belongs_to = ['categorie' => ['model' => 'Class_UserGroupCategorie',
......
......@@ -1330,17 +1330,6 @@ class Class_Users extends Storm_Model_Abstract {
public function beforeSave() {
$this->setDateMaj(Class_Multimedia_Utils_DateTimeFormat::getInstance()
->getCurrentDateFormatInYmdHMS());
if (!$this->isNew())
return;
$this->_autoSubscribeToNewsletters();
}
protected function _autoSubscribeToNewsletters() {
$newsletters = Class_NewsletterGroupAutosubscribe::newslettersForUser($this);
$this->setNewsletters($newsletters);
}
......
......@@ -45,8 +45,7 @@ class ZendAfi_Form_Admin_Newsletter extends ZendAfi_Form {
'categories_selectable' => false,
'url' => $this->getView()->url(['module' => 'admin',
'controller' => 'usergroup',
'action' => 'list.json',
'type' => Class_UserGroup::TYPE_DYNAMIC])])
'action' => 'list.json'])])
->addElement('ckeditor', 'contenu',
['required' => true,
......
......@@ -854,28 +854,6 @@ class UsersControllerAddActionPostTest extends UsersControllerWithMarcusTestCase
$this->_postData();
$this->assertAction('add');
}
/** @test */
public function addWithMatchingNewsletterGroupAutosubscribeShouldSubscribe() {
$group = $this->fixture('Class_UserGroup',
['id' => 42,
'libelle' => 'Dynamic Patrons',
'group_type' => Class_UserGroup::TYPE_DYNAMIC,
'role_level' => ZendAfi_Acl_AdminControllerRoles::ABONNE_SIGB]);
$this->fixture('Class_Newsletter',
['id' => 34,
'titre' => 'Autosubscribe Newsletter',
'user_groups' => [$group]]);
$this->_postData();
$this->assertEquals(34,
Class_Users::findFirstBy(['login' => 'mdavis'])
->getNewsletters()[0]
->getId());
}
}
......
......@@ -844,7 +844,7 @@ class UpgradeDB_303_Test extends UpgradeDBTestCase {
class UpgradeDB_304_Test extends UpgradeDBTestCase {
public function prepare() {
try {
$this->query('DROP TABLE `newsletter_group_autosubscribe`');
$this->query('DROP TABLE `newsletter_group_subscription`');
} catch(Exception $e) {
}
......@@ -853,6 +853,6 @@ class UpgradeDB_304_Test extends UpgradeDBTestCase {
/** @test */
public function tableNewsletterGroupAutosubscribeShouldExists() {
$this->assertTable('newsletter_group_autosubscribe');
$this->assertTable('newsletter_group_subscription');
}
}
\ No newline at end of file
......@@ -22,32 +22,38 @@ require_once 'library/ZendAfi/View/Helper/ViewHelperTestCase.php';
class NewslettersTestWithConnectedUser extends ViewHelperTestCase {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
$helper = new ZendAfi_View_Helper_Accueil_Newsletters(2, [
'type_module'=>'NEWSLETTERS',
'type_module' => 'NEWSLETTERS',
'division' => '1',
'preferences' => [
'titre' => 'Newsletters']]);
$helper->setView(new ZendAfi_Controller_Action_Helper_View());
'preferences' => ['titre' => 'Newsletters']]);
$helper->setView($this->view);
$account = new StdClass();
$account->ID_USER = '123456';
ZendAfi_Auth::getInstance()->getStorage()->write($account);
$user=Class_Users::newInstanceWithId('123456',['nom'=>'Estelle']);
$nouveautes_musique = Class_Newsletter::newInstanceWithId(2,['titre' =>'Nouveautes Musique']);
$user->setNewsletters([$nouveautes_musique]);
$user = $this->fixture('Class_Users',
['id' => 123456,
'nom' => 'Estelle',
'login' => 'stl',
'password' => 'viv3 l3s manchots']);
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Newsletter')
->whenCalled('count')
->answers(2)
->whenCalled('findAll')
->answers( [ $nouveautes_musique,
Class_Newsletter::newInstanceWithId(3,['titre' =>'Animations'])
]);
$nouveautes_musique = $this->fixture('Class_Newsletter',
['id' => 2,
'titre' => 'Nouveautes Musique']);
$user->setNewsletters([$nouveautes_musique]);
$this->fixture('Class_Newsletter',
['id' => 3,
'titre' =>'Animations']);
$this->html = $helper->getBoite();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment