Commit 83e0662a authored by Ghislain Loas's avatar Ghislain Loas

dev #46014 remove -1

parent 8d61d534
......@@ -553,11 +553,8 @@ class AbonneController extends ZendAfi_Controller_Action {
return ;
if (!$form->isValid($_POST))
return;
$newsletters = [];
$newsletters_id = $this->_request->getParam('subscriptions', []);
foreach($newsletters_id as $nl_id)
$newsletters []= Class_Newsletter::find($nl_id);
$newsletters = Class_Newsletter::findAllBy(['id' => $this->_request->getParam('subscriptions', [])]);
try {
$password = $this->_request->getParam('password');
......
......@@ -40,7 +40,7 @@ class NewsletterController extends ZendAfi_Controller_Action {
if (!$this->_unsubscribeValidate())
return;
$this->_letter->unsubscribeByMail($this->_user->getMail());
$this->_letter->unsubscribeByMail($this->_user->getMail(), $this->_letter->getId());
}
......
......@@ -302,7 +302,7 @@ class Class_Newsletter extends Storm_Model_Abstract {
public function unsubscribeByMail($mail) {
if (!$mail)
return false;
return Class_Newsletter_Blacklist::unsubscribeByMail($mail,$this->getId());
return Class_Newsletter_Blacklist::unsubscribeByMail($mail, $this->getId());
}
......
......@@ -22,27 +22,17 @@
class Newsletter_BlacklistLoader extends Storm_Model_Loader {
public function getMailsForNewsletter($newsletter_id) {
return (new Storm_Model_Collection(Class_Newsletter_Blacklist::findAllBy(['newsletter_id' => [$newsletter_id, -1]])))
return (new Storm_Model_Collection(Class_Newsletter_Blacklist::findAllBy(['newsletter_id' => $newsletter_id])))
->collect('mail')
->getArrayCopy();
}
public function unsubscribeByMail($mail, $newsletter_id = -1) {
public function unsubscribeByMail($mail, $newsletter_id) {
$blacklist = Class_Newsletter_Blacklist::newInstance(['mail' => $mail,
'newsletter_id' => $newsletter_id]);
return $blacklist->save();
}
public function removeMailForNewsletter($mail, $newsletter_id = -1) {
if ($blacklist = Class_Newsletter_Blacklist::findFirstBy(['mail'=> $mail,
'newsletter_id' => $newsletter_id]))
return $blacklist->delete();
if ($newsletter_id<0)
$blacklist->deleteBy(['mail'=> $mail]);
}
}
......
......@@ -1579,7 +1579,8 @@ class Class_Users extends Storm_Model_Abstract {
public function setNewsletters($newsletters) {
Class_Newsletter_Blacklist::deleteBy(['mail' =>$this->getMail(),'newsletter_id' => -1]);
Class_Newsletter_Blacklist::deleteBy(['mail' => $this->getMail(),
'newsletter_id' => -1]);
foreach(Class_Newsletter::findAll() as $newsletter) {
if (in_array($newsletter,$newsletters)) {
......@@ -1612,11 +1613,11 @@ class Class_Users extends Storm_Model_Abstract {
public function unsubscribeAllNewsletters() {
foreach (Class_Newsletter::findAll() as $newsletter)
foreach (Class_Newsletter::findAll() as $newsletter) {
Class_UserGroupMembership::deleteBy(['user_id' => $this->getId(),
'user_group_id' => $newsletter->getDedicatedGroup()->getId()]);
Class_Newsletter_Blacklist::unsubscribeByMail($this->getMail(), -1);
Class_Newsletter_Blacklist::unsubscribeByMail($this->getMail(), $newsletter->getId());
}
return $this;
}
......
......@@ -143,7 +143,7 @@ class NewsletterControllerValidUnsubscribeConfirmTest extends NewsletterControll
/** @test */
public function harlockShouldBeUnsubscribed() {
$this->assertEquals(['c.harlock@arcadia.net'],Class_Newsletter_Blacklist::getMailsForNewsletter(34));
$this->assertEquals(['c.harlock@arcadia.net'], Class_Newsletter_Blacklist::getMailsForNewsletter(34));
}
}
\ No newline at end of file
......@@ -117,7 +117,7 @@ abstract class NewsletterMailingTestCase extends ModelTestCase {
$this->zorkglub,
$anonymous])
->save();
Class_Newsletter_Blacklist::unsubscribeByMail($anonymous->getMail(),1);
Class_Newsletter_Blacklist::unsubscribeByMail($anonymous->getMail(), 1);
$this->onLoaderOfModel('Class_Notice')
->whenCalled('getNoticesFromPreferences')
......
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