Provides statistics about subscribers.
authorStéphane Jacob <sj@m4x.org>
Sun, 6 Nov 2011 00:31:13 +0000 (01:31 +0100)
committerStéphane Jacob <sj@m4x.org>
Sun, 6 Nov 2011 00:31:13 +0000 (01:31 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
ChangeLog
include/newsletter.inc.php
modules/newsletter.php
templates/newsletter/statistics.tpl

index 893729b..64d69e1 100644 (file)
--- 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
index 9016bdd..5dbe438 100644 (file)
@@ -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.
index 199bab6..8983bd6 100644 (file)
@@ -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);
     }
 }
 
index 43fa8e6..4ae9d1f 100644 (file)
 
 {include file="newsletter/header.tpl" current="stats"}
 
-<p>Il y a actuellement {$nl->subscriberCount()} inscrits aux envois, parmi lesquels {$nl->lostSubscriberCount()} n'ont aucune redirection active.</p>
-
+<p>
+  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.
+</p>
 
+<table class="bicol">
+{foreach from=$data item=education key=cycle}
+  <tr>
+    <th colspan="3">Cycle {$cycle}</th>
+  </tr>
+  <tr>
+    <td class="titre">Décade</td>
+    <td class="titre">Total (dont perdus)</td>
+    <td class="titre">Femmes (dont perdues)</td>
+  </tr>
+  {foreach from=$education item=counts key=period}
+  <tr>
+    <td>{$period}</td>
+    <td>{$counts.count} ({$counts.lost})</td>
+    <td>{$counts.count_female} ({$counts.lost_female})</td>
+  </tr>
+  {/foreach}
+{/foreach}
+</table>
 
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}