Enables NLs filling from group members.
authorStéphane Jacob <sj@m4x.org>
Mon, 9 May 2011 15:15:55 +0000 (17:15 +0200)
committerStéphane Jacob <sj@m4x.org>
Mon, 9 May 2011 17:32:53 +0000 (19:32 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
ChangeLog
include/newsletter.inc.php
modules/xnetnl.php
templates/newsletter/admin.tpl

index b7e1777..7d0da62 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -44,6 +44,7 @@ Bug/Wish:
         - #1470: Fixes autocomplete on countries                           -JAC
 
     * XnetGrp:
+        - Enables NLs filling from group members                           -JAC
         - #1179: Adds alphabetic choices for group directories             -XEL
         - #1460: Enables NLs creation for groups                           -XEL
         - #1473: Enables group filling from its MLs and aliases            -JAC
index b7e00ca..447c7b7 100644 (file)
@@ -567,6 +567,18 @@ class NewsLetter
         return $this->custom_css;
     }
 
+    public function canSyncWithGroup()
+    {
+        switch ($this->group) {
+          case self::GROUP_XORG:
+          case self::GROUP_AX:
+          case self::GROUP_EP:
+            return false;
+          default:
+            return true;
+        }
+    }
+
     // }}}
 }
 
index e04c4d3..a6fb168 100644 (file)
@@ -30,6 +30,7 @@ class XnetNlModule extends NewsletterModule
             '%grp/nl/show'              => $this->make_hook('nl_show',         AUTH_MDP),
             '%grp/nl/search'            => $this->make_hook('nl_search',       AUTH_MDP),
             '%grp/admin/nl'             => $this->make_hook('admin_nl',        AUTH_MDP, 'groupadmin'),
+            '%grp/admin/nl/sync'        => $this->make_hook('admin_nl_sync',   AUTH_MDP, 'groupadmin'),
             '%grp/admin/nl/enable'      => $this->make_hook('admin_nl_enable', AUTH_MDP, 'groupadmin'),
             '%grp/admin/nl/edit'        => $this->make_hook('admin_nl_edit',   AUTH_MDP, 'groupadmin'),
             '%grp/admin/nl/edit/cancel' => $this->make_hook('admin_nl_cancel', AUTH_MDP, 'groupadmin'),
@@ -45,6 +46,43 @@ class XnetNlModule extends NewsletterModule
        return NewsLetter::forGroup($group);
     }
 
+    public function handler_admin_nl_sync($page)
+    {
+        global $globals;
+        $nl = $this->getNl();
+        if (!$nl) {
+            return PL_FORBIDDEN;
+        }
+
+        if (Env::has('add_users')) {
+            S::assert_xsrf_token();
+
+            XDB::execute('INSERT IGNORE INTO  newsletter_ins (uid, nlid)
+                                      SELECT  g.uid, n.id
+                                        FROM  group_members AS g
+                                  INNER JOIN  newsletters   AS n  ON (n.group_id = g.asso_id)
+                                       WHERE  g.uid IN {?} AND g.asso_id = {?}',
+                         array_keys(Env::v('add_users')), $globals->asso('id'));
+
+            $page->trigSuccess('Ajouts réalisés avec succès.');
+        }
+
+        $uids = XDB::fetchColumn('SELECT  DISTINCT(g.uid)
+                                    FROM  group_members AS g
+                                   WHERE  g.asso_id = {?} AND NOT EXISTS (SELECT  ni.*
+                                                                            FROM  newsletter_ins AS ni
+                                                                      INNER JOIN  newsletters    AS n  ON (ni.nlid = n.id)
+                                                                           WHERE  g.uid = ni.uid AND n.group_id = g.asso_id)',
+                                 $globals->asso('id'));
+
+        $users = User::getBulkUsersWithUIDs($uids);
+        usort($users, 'User::compareDirectoryName');
+
+        $page->setTitle('Synchronisation de la newsletter');
+        $page->changeTpl('newsletter/sync.tpl');
+        $page->assign('users', $users);
+    }
+
     public function handler_admin_nl_enable($page)
     {
         global $globals;
index 2f724ab..a5d2c03 100644 (file)
   <a href="{$nl->adminPrefix()}/categories">Gérer les catégories d'articles</a>
 </h3>
 
+{if $nl->canSyncWithGroup()}
+<h3>
+  <a href="{$nl->adminPrefix()}/sync">Synchroniser avec les membres du groupe</a>
+</h3>
+{/if}
+
 <table class="bicol" cellpadding="3" cellspacing="0" summary="liste des NL">
   <tr>
     <th>Date</th>