Cache the NbNotifs in session data.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 1 Nov 2007 10:39:10 +0000 (11:39 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 1 Nov 2007 10:39:10 +0000 (11:39 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
include/notifs.inc.php
include/xorg.misc.inc.php
include/xorg/session.inc.php
modules/carnet.php
plugins/insert.getNbNotifs.php [deleted file]
templates/skin/common.title.header.tpl

index 4daeaf6..9b367c2 100644 (file)
@@ -54,6 +54,8 @@ function register_watch_op($uid, $cid, $date='', $info='')
                              WHERE  ni_id={?}', $uid);
         XDB::execute('DELETE FROM watch_nonins WHERE ni_id={?}', $uid);
     }
+    require_once 'xorg.misc.inc.php';
+    update_NbNotifs();
 }
 
 // }}}
@@ -134,29 +136,6 @@ function select_notifs($mail, $uid=null, $last=null, $iterator=true)
 }
 
 // }}}
-// {{{ function getNbNotifs
-
-function getNbNotifs()
-{
-    if (!S::has('uid')) {
-        return 0;
-    }
-    $uid       = S::v('uid', -1);
-    $watchlast = S::v('watch_last');
-
-    // selectionne les notifs de uid, sans detail sur le watcher, depuis
-    // $watchlast, meme ceux sans surveillance, non ordonnés
-    $res = select_notifs(false, $uid, $watchlast, false);
-    $n   = $res->numRows();
-    $res->free();
-    if ($n == 0) {
-        return;
-    }
-
-    return "<a href='carnet/panel'>$n événement".($n > 1 ? 's' : '')." !</a>";
-}
-
-// }}}
 // {{{
 
 global $prf_desc;
index 7c75cba..ff3064e 100644 (file)
@@ -315,7 +315,6 @@ function send_warning_mail($title)
     $mailer->send();
 }
 
-    
 function update_NbIns()
 {
     global $globals;
@@ -324,5 +323,12 @@ function update_NbIns()
     $globals->change_dynamic_config(array('NbIns' => $cnt));
 }
 
+function update_NbNotifs()
+{
+    require_once 'notifs.inc.php';
+    $n = select_notifs(false, S::i('uid'), S::v('watch_last'), false);
+    $_SESSION['notifs'] = $n->numRows();
+}
+
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>
index 3dccb92..0075c28 100644 (file)
@@ -305,6 +305,7 @@ function start_connexion ($uid, $identified)
         send_warning_mail($mail_subject);
     }
     set_skin();
+    update_NbNotifs();
     check_redirect();
     return true;
 }
index dfc2d6d..ee8a87d 100644 (file)
@@ -66,6 +66,7 @@ class CarnetModule extends PLModule
 
         if (Get::has('read')) {
             $_SESSION['watch_last'] = Get::v('read');
+            update_NbNotifs();
             pl_redirect('carnet/panel');
         }
 
diff --git a/plugins/insert.getNbNotifs.php b/plugins/insert.getNbNotifs.php
deleted file mode 100644 (file)
index 3da1aad..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<?php
-/***************************************************************************
- *  Copyright (C) 2003-2007 Polytechnique.org                              *
- *  http://opensource.polytechnique.org/                                   *
- *                                                                         *
- *  This program is free software; you can redistribute it and/or modify   *
- *  it under the terms of the GNU General Public License as published by   *
- *  the Free Software Foundation; either version 2 of the License, or      *
- *  (at your option) any later version.                                    *
- *                                                                         *
- *  This program is distributed in the hope that it will be useful,        *
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
- *  GNU General Public License for more details.                           *
- *                                                                         *
- *  You should have received a copy of the GNU General Public License      *
- *  along with this program; if not, write to the Free Software            *
- *  Foundation, Inc.,                                                      *
- *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
- ***************************************************************************/
-
-
-function smarty_insert_getNbNotifs($params, &$smarty)
-{
-    if(S::logged()) {
-       require_once('notifs.inc.php');
-       return getNbNotifs();
-    }
-}
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
-?>
index fd4585d..fd0222a 100644 (file)
@@ -1,42 +1,47 @@
-{**************************************************************************}\r
-{*                                                                        *}\r
-{*  Copyright (C) 2003-2007 Polytechnique.org                             *}\r
-{*  http://opensource.polytechnique.org/                                  *}\r
-{*                                                                        *}\r
-{*  This program is free software; you can redistribute it and/or modify  *}\r
-{*  it under the terms of the GNU General Public License as published by  *}\r
-{*  the Free Software Foundation; either version 2 of the License, or     *}\r
-{*  (at your option) any later version.                                   *}\r
-{*                                                                        *}\r
-{*  This program is distributed in the hope that it will be useful,       *}\r
-{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}\r
-{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}\r
-{*  GNU General Public License for more details.                          *}\r
-{*                                                                        *}\r
-{*  You should have received a copy of the GNU General Public License     *}\r
-{*  along with this program; if not, write to the Free Software           *}\r
-{*  Foundation, Inc.,                                                     *}\r
-{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}\r
-{*                                                                        *}\r
-{**************************************************************************}\r
-          <table>\r
-            <tr>\r
-              <td class="date-heure">\r
-                <script type="text/javascript">\r
-                  <!--\r
-                  document.write(getNow());\r
-                  //-->\r
-                </script>\r
-              </td>\r
-              <td class="inscrits">\r
-                {insert name="getNbIns"} polytechniciens sur le web\r
-                <form action="search" method="get">\r
-                    <div>\r
-                        <input type="text" size="30" name="quick" class="quick_search" value="{$smarty.request.quick|default:"recherche dans l'annuaire"}" onfocus="if (this.value == '{$smarty.request.quick|default:"recherche dans l'annuaire"|escape:javascript}') this.value=''" onblur="if (this.value == '') this.value='{$smarty.request.quick|default:"recherche dans l'annuaire"|escape:javascript}'"/>                        \r
-                    </div>\r
-                </form>\r
-                {insert name="getNbNotifs"}\r
-              </td>\r
-            </tr>\r
-          </table>\r
+{**************************************************************************}
+{*                                                                        *}
+{*  Copyright (C) 2003-2007 Polytechnique.org                             *}
+{*  http://opensource.polytechnique.org/                                  *}
+{*                                                                        *}
+{*  This program is free software; you can redistribute it and/or modify  *}
+{*  it under the terms of the GNU General Public License as published by  *}
+{*  the Free Software Foundation; either version 2 of the License, or     *}
+{*  (at your option) any later version.                                   *}
+{*                                                                        *}
+{*  This program is distributed in the hope that it will be useful,       *}
+{*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *}
+{*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *}
+{*  GNU General Public License for more details.                          *}
+{*                                                                        *}
+{*  You should have received a copy of the GNU General Public License     *}
+{*  along with this program; if not, write to the Free Software           *}
+{*  Foundation, Inc.,                                                     *}
+{*  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA               *}
+{*                                                                        *}
+{**************************************************************************}
+          <table>
+            <tr>
+              <td class="date-heure">
+                <script type="text/javascript">
+                  <!--
+                  document.write(getNow());
+                  //-->
+                </script>
+              </td>
+              <td class="inscrits">
+                {insert name="getNbIns"} polytechniciens sur le web
+                <form action="search" method="get">
+                    <div>
+                        <input type="text" size="30" name="quick" class="quick_search"
+                               value="{$smarty.request.quick|default:"recherche dans l'annuaire"}"
+                               onfocus="if (this.value == '{$smarty.request.quick|default:"recherche dans l'annuaire"|escape:javascript}') this.value=''"
+                               onblur="if (this.value == '') this.value='{$smarty.request.quick|default:"recherche dans l'annuaire"|escape:javascript}'"/>                        
+                    </div>
+                </form>
+                {if $smarty.session.auth gt AUTH_PUBLIC && $smarty.session.notifs}
+                <a href="carnet/panel">{$smarty.session.notifs} événement{if $smarty.session.notifs gt 1}s{/if}</a>
+                {/if}
+              </td>
+            </tr>
+          </table>
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}