From ccabe1acecea0bfc0f84f1d8c805e05d741c9a93 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Sun, 6 Nov 2011 01:31:13 +0100 Subject: [PATCH] Provides statistics about subscribers. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- ChangeLog | 1 + include/newsletter.inc.php | 24 +++++++++++++++++++----- modules/newsletter.php | 31 +++++++++++++++++++++++++++++++ templates/newsletter/statistics.tpl | 25 +++++++++++++++++++++++-- 4 files changed, 74 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 893729b..64d69e1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ New: * Newsletter: - Displays number of subscribers without any valid redirection -JAC + - Provides statistics about subscribers -JAC * Search: - Switches autocomplete to jQuery UI -JAC diff --git a/include/newsletter.inc.php b/include/newsletter.inc.php index 9016bdd..5dbe438 100644 --- a/include/newsletter.inc.php +++ b/include/newsletter.inc.php @@ -398,18 +398,32 @@ class NewsLetter /** Get the count of subscribers to the NL. * @return Number of subscribers. */ - public function subscriberCount() + public function subscriberCount($lost = null, $sex = null, $grade = null, $first_promo = null, $last_promo = null) { - $uf = new UserFilter(new UFC_NLSubscribed($this->id)); + $cond = new PFC_And(new UFC_NLSubscribed($this->id)); + if (!is_null($sex)) { + $cond->addChild(new UFC_Sex($sex)); + } + if (!is_null($grade)) { + $cond->addChild(new UFC_Promo('>=', $grade, $first_promo)); + $cond->addChild(new UFC_Promo('<=', $grade, $last_promo)); + } + if (!($lost === null)) { + if ($lost === true) { + $cond->addChild(new PFC_Not(new UFC_HasEmailRedirect())); + } else { + $cond->addChild(new UFC_HasEmailRedirect()); + } + } + $uf = new UserFilter($cond); return $uf->getTotalCount(); } /** Get the count of subscribers with non valid redirection. */ - public function lostSubscriberCount() + public function lostSubscriberCount($sex = null) { - $uf = new UserFilter(new PFC_And(new UFC_NLSubscribed($this->id), new PFC_Not(new UFC_HasEmailRedirect()))); - return $uf->getTotalCount(); + return $this->subscriberCount(true, $sex); } /** Get the number of subscribers to the NL whose last received mailing was $last. diff --git a/modules/newsletter.php b/modules/newsletter.php index 199bab6..8983bd6 100644 --- a/modules/newsletter.php +++ b/modules/newsletter.php @@ -505,7 +505,38 @@ class NewsletterModule extends PLModule $page->setTitle('Statistiques - Newsletter'); $page->changeTpl('newsletter/statistics.tpl'); + + $data = array(); + foreach (Profile::$cycles as $grade => $name) { + $data[$name] = array(); + list($min, $max) = Profile::extremePromotions($grade); + $bound = (((int)($min / 10)) + 1) * 10; + while ($bound <= $max) { + $data[$name][$min . ' - ' . $bound] = array( + 'count' => $nl->subscriberCount(null, null, $grade, $min, $bound), + 'lost' => $nl->subscriberCount(true, null, $grade, $min, $bound), + 'count_female' => $nl->subscriberCount(null, User::GENDER_FEMALE, $grade, $min, $bound), + 'lost_female' => $nl->subscriberCount(true, User::GENDER_FEMALE, $grade, $min, $bound) + ); + $min = $bound + 1; + $bound += 10; + } + $bound -= 9; + if ($bound <= $max) { + $data[$name][$bound . ' - ' . $max] = array( + 'count' => $nl->subscriberCount(null, null, $grade, $bound, $max), + 'lost' => $nl->subscriberCount(true, null, $grade, $bound, $max), + 'count_female' => $nl->subscriberCount(null, User::GENDER_FEMALE, $grade, $bound, $max), + 'lost_female' => $nl->subscriberCount(true, User::GENDER_FEMALE, $grade, $bound, $max) + ); + } + } $page->assign_by_ref('nl', $nl); + $page->assign('count', $nl->subscriberCount()); + $page->assign('lost', $nl->lostSubscriberCount()); + $page->assign('count_female', $nl->subscriberCount(null, User::GENDER_FEMALE)); + $page->assign('lost_female', $nl->lostSubscriberCount(User::GENDER_FEMALE)); + $page->assign('data', $data); } } diff --git a/templates/newsletter/statistics.tpl b/templates/newsletter/statistics.tpl index 43fa8e6..4ae9d1f 100644 --- a/templates/newsletter/statistics.tpl +++ b/templates/newsletter/statistics.tpl @@ -22,8 +22,29 @@ {include file="newsletter/header.tpl" current="stats"} -

Il y a actuellement {$nl->subscriberCount()} inscrits aux envois, parmi lesquels {$nl->lostSubscriberCount()} n'ont aucune redirection active.

- +

+ Il y a actuellement {$count} inscrits aux envois, parmi lesquels {$lost} n'ont aucune redirection active. + En particulier, il y a {$count_female} femmes, parmi lesquelles {$lost_female} n'ont aucune redirection active. +

+ +{foreach from=$data item=education key=cycle} + + + + + + + + + {foreach from=$education item=counts key=period} + + + + + + {/foreach} +{/foreach} +
Cycle {$cycle}
DécadeTotal (dont perdus)Femmes (dont perdues)
{$period}{$counts.count} ({$counts.lost}){$counts.count_female} ({$counts.lost_female})
{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} -- 2.1.4