From c557ed51da3a61401c6723f57d36605352d867de Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Thu, 1 Nov 2007 11:39:10 +0100 Subject: [PATCH] Cache the NbNotifs in session data. Signed-off-by: Florent Bruneau --- include/notifs.inc.php | 25 +--------- include/xorg.misc.inc.php | 8 +++- include/xorg/session.inc.php | 1 + modules/carnet.php | 1 + plugins/insert.getNbNotifs.php | 31 ------------ templates/skin/common.title.header.tpl | 87 ++++++++++++++++++---------------- 6 files changed, 57 insertions(+), 96 deletions(-) delete mode 100644 plugins/insert.getNbNotifs.php diff --git a/include/notifs.inc.php b/include/notifs.inc.php index 4daeaf6..9b367c2 100644 --- a/include/notifs.inc.php +++ b/include/notifs.inc.php @@ -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 "$n événement".($n > 1 ? 's' : '')." !"; -} - -// }}} // {{{ global $prf_desc; diff --git a/include/xorg.misc.inc.php b/include/xorg.misc.inc.php index 7c75cba..ff3064e 100644 --- a/include/xorg.misc.inc.php +++ b/include/xorg.misc.inc.php @@ -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: ?> diff --git a/include/xorg/session.inc.php b/include/xorg/session.inc.php index 3dccb92..0075c28 100644 --- a/include/xorg/session.inc.php +++ b/include/xorg/session.inc.php @@ -305,6 +305,7 @@ function start_connexion ($uid, $identified) send_warning_mail($mail_subject); } set_skin(); + update_NbNotifs(); check_redirect(); return true; } diff --git a/modules/carnet.php b/modules/carnet.php index dfc2d6d..ee8a87d 100644 --- a/modules/carnet.php +++ b/modules/carnet.php @@ -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 index 3da1aad..0000000 --- a/plugins/insert.getNbNotifs.php +++ /dev/null @@ -1,31 +0,0 @@ - diff --git a/templates/skin/common.title.header.tpl b/templates/skin/common.title.header.tpl index fd4585d..fd0222a 100644 --- a/templates/skin/common.title.header.tpl +++ b/templates/skin/common.title.header.tpl @@ -1,42 +1,47 @@ -{**************************************************************************} -{* *} -{* 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 *} -{* *} -{**************************************************************************} - - - - - -
- - - {insert name="getNbIns"} polytechniciens sur le web -
-
- -
-
- {insert name="getNbNotifs"} -
+{**************************************************************************} +{* *} +{* 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 *} +{* *} +{**************************************************************************} + + + + + +
+ + + {insert name="getNbIns"} polytechniciens sur le web +
+
+ +
+
+ {if $smarty.session.auth gt AUTH_PUBLIC && $smarty.session.notifs} + {$smarty.session.notifs} événement{if $smarty.session.notifs gt 1}s{/if} + {/if} +
{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} -- 2.1.4