Commit 05f18906 authored by efalcy's avatar efalcy

dev #46014 : clean dependencies of NewsletterSubscribers

parent 55cd4152
......@@ -61,10 +61,7 @@ class Class_Newsletter extends Storm_Model_Abstract {
protected $_table_name = 'newsletters';
protected $_has_many =
['subscriptions' => ['model' => 'Class_NewsletterSubscription',
'role' => 'newsletter',
'dependents' => 'delete'],
[
'dispatchs' => ['model' => 'Class_Newsletter_Dispatch',
'role' => 'newsletter',
'dependents' => 'delete'],
......@@ -87,11 +84,6 @@ class Class_Newsletter extends Storm_Model_Abstract {
}
public function getSubscriptionsPage($page=0, $items_by_page=20) {
return Class_NewsletterSubscription::findAllBy(['newsletter_id' => $this->getId(),
'limitPage' => [$page, $items_by_page]]);
}
public function getPublishedNewsletters() {
return Class_Newsletter::findAllBy(['draft' => 0]);
......@@ -100,7 +92,7 @@ class Class_Newsletter extends Storm_Model_Abstract {
public function send() {
if (!$dispatch = $this->getLastDispatchInProgress())
$dispatch = $Class_Newsletter_Dispatch::newFrom($this);
$dispatch = Class_Newsletter_Dispatch::newFrom($this);
return (new Class_Batch_SendNewsletters($dispatch))->run();
}
......@@ -300,11 +292,6 @@ class Class_Newsletter extends Storm_Model_Abstract {
}
public function hasToBeSend() {
return 1 < Class_NewsletterSubscription::countDistributionProgress($this->getId());
}
public function unsubscribeByMail($mail) {
if (!$mail)
return;
......@@ -312,12 +299,6 @@ class Class_Newsletter extends Storm_Model_Abstract {
$user_ids = [];
foreach(Class_Users::findAllBy(['mail' => $mail]) as $user)
$user_ids[] = $user->getId();
if (!$user_ids)
return;
Class_NewsletterSubscription::deleteBy(['newsletter_id' => $this->getId(),
'user_id' => $user_ids]);
}
......
<?php
/**
* Copyright (c) 2012-2014, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH 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).
*
* BOKEH 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 BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class ZendAfi_View_Helper_Admin_NewsletterSubscribers extends ZendAfi_View_Helper_Admin_SubscribeUsers {
protected $_total = 0;
protected $_paginator;
public function newsletterSubscribers($newsletter, $search='', $page=0, $items_by_page=20) {
if(!$page)
$page = 0;
$this->_total = Class_NewsletterSubscription::countAvailableUserForNewsletter($newsletter->getId());
$this->_paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Null($this->_total));
$this->_paginator->setItemCountPerPage($items_by_page);
$this->_paginator->setCurrentPageNumber($page);
$this->_paginator->setView($this->view);
$subscriptions = $newsletter->getSubscriptionsPage($page, $items_by_page);
$items = array_map(
function($subscription) {
return new ZendAfi_View_Helper_Admin_NewsletterSubscribersItem($subscription);
},
$subscriptions);
return $this
->setUsers($items)
->setSearch($search)
->render();
}
protected function _findUsersForm($search) {
$form = parent::_findUsersForm($search);
$form->setMethod('post');
return $form;
}
protected function _getCount() {
return '';
}
protected function _getPagination() {
return $this->view->tag('div', $this->_paginator->render(),
['style' => 'text-align:center']);
}
}
class ZendAfi_View_Helper_Admin_NewsletterSubscribersItem {
protected $_subscription;
public function __construct($subscription) {
$this->_subscription = $subscription;
}
public function __call($name, $params) {
if ('getId' == $name)
return $this->_subscription->getId();
if (null == $this->_subscription->getUser())
return '';
return call_user_func_array([$this->_subscription->getUser(), $name], $params);
}
}
?>
\ No newline at end of file
......@@ -38,32 +38,6 @@ abstract class Admin_NewsletterControllerTestCase
->whenCalled('findAllBelongsToAdmin')
->answers([]);
$this->onLoaderOfModel('Class_NewsletterSubscription')
->whenCalled('countAvailableUserForNewsletter')
->with(1)
->answers(1)
->whenCalled('countAvailableUserForNewsletter')
->with(2)
->answers(1)
->whenCalled('countDistributionProgress')
->with(1)
->answers(0)
->whenCalled('countDistributionProgress')
->with(2)
->answers(0)
->whenCalled('countTotalDistribution')
->with(1)
->answers(1)
->whenCalled('countTotalDistribution')
->with(2)
->answers(1)
->beStrict();
$pat = $this->fixture('Class_Users',
......
......@@ -48,20 +48,6 @@ abstract class NewsletterControllerTestCase extends AbstractControllerTestCase {
['id' => 34,
'titre' => 'Last news']);
$this->fixture('Class_NewsletterSubscription',
['id' => 99,
'newsletter_id' => 34,
'user_id' => 23]);
$this->fixture('Class_NewsletterSubscription',
['id' => 100,
'newsletter_id' => 34,
'user_id' => 24]);
$this->fixture('Class_NewsletterSubscription',
['id' => 101,
'newsletter_id' => 34,
'user_id' => 25]);
}
......
......@@ -16,7 +16,7 @@
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; 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 'Class/Newsletter.php';
require_once 'ModelTestCase.php';
......@@ -27,7 +27,7 @@ class NewsletterFixtures {
'titre' => 'Nouveautés classique',
'contenu' => 'Notre sélection du mois');
}
public static function animations() {
return array('id' => 2,
'titre' => 'Animations',
......@@ -35,7 +35,7 @@ class NewsletterFixtures {
}
public static function all() {
return array(self::nouveautesClassique(),
return array(self::nouveautesClassique(),
self::animations());
}
}
......@@ -110,10 +110,6 @@ class NewsletterTimeSourceTest extends ModelTestCase {
}
/** @test */
public function hasToBeSendShouldReturnFalse() {
$this->assertFalse($this->newsletter->hasToBeSend());
}
}
?>
\ No newline at end of file
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