Links nl unsubscribtions to the issues that caused them (Closes #1394).
authorStéphane Jacob <sj@m4x.org>
Fri, 29 Apr 2011 09:45:23 +0000 (11:45 +0200)
committerStéphane Jacob <sj@m4x.org>
Fri, 29 Apr 2011 19:19:38 +0000 (21:19 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
ChangeLog
include/newsletter.inc.php
modules/newsletter.php
templates/newsletter/nl.AX.mail.tpl
templates/newsletter/nl.Polytechnique.org.mail.tpl
upgrade/1.1.1/12_nl.sql [new file with mode: 0644]

index 7913578..9a99433 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,6 +15,9 @@ Bug/Wish:
     * Events:
         - #1475: Fixes date storage for next reminder                      -JAC
 
+    * Newsletter:
+        - #1394: Links nl unsubscribtions to the issues that caused them   -JAC
+
     * Profile:
         - #1445: Add job entry year                                        -JAC
         - #1478: Uses user's visibility limitations to display vcards      -JAC
index 623121f..2faf993 100644 (file)
@@ -321,7 +321,7 @@ class NewsLetter
      * @p $hash True if the uid is actually a hash.
      * @return True if the user was successfully unsubscribed.
      */
-    public function unsubscribe($uid = null, $hash = false)
+    public function unsubscribe($issue_id = null, $uid = null, $hash = false)
     {
         if (is_null($uid) && $hash) {
             // Unable to unsubscribe from an empty hash
@@ -342,6 +342,12 @@ class NewsLetter
         XDB::execute('DELETE FROM  newsletter_ins
                             WHERE  nlid = {?} AND uid = {?}',
                             $this->id, $user);
+        if (!is_null($issue_id)) {
+            XDB::execute('UPDATE  newsletter_issues
+                             SET  unsubscribe = unsubscribe + 1
+                           WHERE  id = {?}',
+                         $id);
+        }
         return true;
     }
 
index 9dd9240..3accf5f 100644 (file)
@@ -48,7 +48,7 @@ class NewsletterModule extends PLModule
         return NewsLetter::forGroup(NewsLetter::GROUP_XORG);
     }
 
-    function handler_nl($page, $action = null, $hash = null)
+    function handler_nl($page, $action = null, $hash = null, $issue_id = null)
     {
         $nl = $this->getNl();
         if (!$nl) {
@@ -58,8 +58,9 @@ class NewsletterModule extends PLModule
         $page->changeTpl('newsletter/index.tpl');
         $page->setTitle('Lettres mensuelles');
 
+        $hash = ($hash == 'nohash') ? null : $hash;
         switch ($action) {
-          case 'out': $nl->unsubscribe($hash, $hash != null); break;
+          case 'out': $nl->unsubscribe($issue_id, $hash, $hash != null); break;
           case 'in':  $nl->subscribe(); break;
           default: ;
         }
index 5a8b0b8..9898404 100644 (file)
@@ -43,10 +43,10 @@ Cette lettre est envoyée par l'AX grâce aux outils de Polytechnique.org.
 
 {if $is_mail}
 archives         : <https://www.polytechnique.org/ax>
-ne plus recevoir : <https://www.polytechnique.org/ax/out{if $hash}/{$hash}{/if}>
+ne plus recevoir : <https://www.polytechnique.org/ax/out/{if $hash}{$hash}{else}nohash{/if}/issue/{$issue->id}>
 {else}
 archives         : &lt;https://www.polytechnique.org/ax&gt;
-ne plus recevoir : &lt;https://www.polytechnique.org/ax/out{if $hash}/{$hash}{/if}&gt;
+ne plus recevoir : &lt;https://www.polytechnique.org/ax/out/{if $hash}{$hash}{else}nohash{/if}/issue/{$issue->id}&gt;
 {/if}
 
 {if !$is_mail}
@@ -80,7 +80,7 @@ ne plus recevoir : &lt;https://www.polytechnique.org/ax/out{if $hash}/{$hash}{/i
       </div>
       <div class="foot2">
         [<a href="https://www.polytechnique.org/ax">archives</a>&nbsp;|
-        <a href="https://www.polytechnique.org/ax/out{if $hash}/{$hash}{/if}">ne plus recevoir</a>]
+        <a href="https://www.polytechnique.org/ax/out/{if $hash}{$hash}{else}nohash{/if}/{$issue->id}">ne plus recevoir</a>]
       </div>
     </div>
 {if $is_mail}
index 43ddf9f..84472e4 100644 (file)
@@ -63,11 +63,11 @@ l'intermédiaire de Polytechnique.org.
 {if $is_mail}
 archives         : <https://www.polytechnique.org/nl>
 écrire           : <https://www.polytechnique.org/nl/submit>
-ne plus recevoir : <https://www.polytechnique.org/nl/out>
+ne plus recevoir : <https://www.polytechnique.org/nl/out/nohash/{$issue->id}>
 {else}
 archives         : &lt;https://www.polytechnique.org/nl&gt;
 écrire           : &lt;https://www.polytechnique.org/nl/submit&gt;
-ne plus recevoir : &lt;https://www.polytechnique.org/nl/out&gt;
+ne plus recevoir : &lt;https://www.polytechnique.org/nl/out/nohash/{$issue->id}&gt;
 {/if}
 {if !$is_mail}
 </pre>
@@ -119,7 +119,7 @@ ne plus recevoir : &lt;https://www.polytechnique.org/nl/out&gt;
       <div class="foot2">
         [<a href="https://www.polytechnique.org/nl">archives</a>&nbsp;|
          <a href="https://www.polytechnique.org/nl/submit">écrire dans la NL</a>&nbsp;|
-         <a href="https://www.polytechnique.org/nl/out">ne plus recevoir</a>]
+         <a href="https://www.polytechnique.org/nl/out/nohash/{$issue->id}">ne plus recevoir</a>]
       </div>
       </div>
 {if $is_mail}
diff --git a/upgrade/1.1.1/12_nl.sql b/upgrade/1.1.1/12_nl.sql
new file mode 100644 (file)
index 0000000..08ee9b6
--- /dev/null
@@ -0,0 +1,3 @@
+ALTER TABLE newsletter_issues ADD COLUMN unsubscribe INT(5) NOT NULL DEFAULT 0;
+
+-- vim:set syntax=mysql: