Moves skills edition to mentor edition page.
[platal.git] / include / newsletter.inc.php
index 3359249..2f6ccca 100644 (file)
@@ -361,11 +361,26 @@ class NewsLetter
         }
         if (self::maySubscribe($user)) {
             XDB::execute('INSERT IGNORE INTO  newsletter_ins (nlid, uid, last, hash)
-                                      VALUES  ({?}, {?}, 0, hash)',
+                                      VALUES  ({?}, {?}, NULL, hash)',
                          $this->id, $user->id());
         }
     }
 
+    /** Subscribe a batch of users to a newsletter.
+     * This skips 'maySubscribe' test.
+     *
+     * @p $user_ids Array of user IDs to subscribe to the newsletter.
+     */
+    public function bulkSubscribe($user_ids)
+    {
+        // TODO: use a 'bulkMaySubscribe'.
+        XDB::execute('INSERT IGNORE INTO  newsletter_ins (nlid, uid, last, hash)
+                                  SELECT  {?}, a.uid, NULL, NULL
+                                    FROM  accounts AS a
+                                   WHERE  a.uid IN {?}',
+                     $this->id, $user_ids);
+    }
+
     /** Retrieve subscription state of a user
      * @p $user Target user; if null, use current user.
      * @return Boolean: true if the user has subscribed to the NL.