iGoogle gadget.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 14 Feb 2009 18:20:34 +0000 (19:20 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sat, 14 Feb 2009 18:20:34 +0000 (19:20 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
modules/events.php
modules/events/feed.inc.php
modules/gadgets.php
templates/gadgets/ig-events.tpl

index 1076a6a..6e7cb1f 100644 (file)
@@ -158,18 +158,6 @@ class EventsModule extends PLModule
             pl_redirect('events#newsid'.$eid);
         }
 
-        function next_event(PlIterator &$it)
-        {
-            $user = S::user();
-            while ($body = $it->next()) {
-                $uf = UserFilter::getLegacy($body['promo_min'], $body['promo_max']);
-                if ($uf->checkUser($user)) {
-                    return $body;
-                }
-            }
-            return null;
-        }
-
         // Fetch the events to display, along with their metadata.
         $array = array();
         $it = XDB::iterator("SELECT  e.id, e.titre, e.texte, e.post_id, e.user_id,
@@ -185,7 +173,10 @@ class EventsModule extends PLModule
                            ORDER BY  important DESC, news DESC, end DESC, e.peremption, e.creation_date DESC",
                             S::i('uid'));
         $cats = array('important', 'news', 'end', 'body');
-        $body  = next_event($it);
+
+        $this->load('feed.inc.php');
+        $user = S::user();
+        $body  = EventFeed::nextEvent($it, $user);
         foreach ($cats as $cat) {
             $data = array();
             if (!$body) {
@@ -197,7 +188,7 @@ class EventsModule extends PLModule
                 } else {
                     break;
                 }
-                $body = next_event($it);
+                $body = EventFeed::nextEvent($it);
             } while ($body);
             if (!empty($data)) {
                 $array[$cat] = $data;
index 02bb8be..802725c 100644 (file)
@@ -31,7 +31,7 @@ class EventFeed extends PlFeed
                             'events/rss.tpl');
     }
 
-    private static function nextEvent(PlIterator &$it, PlUser &$user)
+    public static function nextEvent(PlIterator &$it, PlUser &$user)
     {
         while ($body = $it->next()) {
             $uf = UserFilter::getLegacy($body['promo_min'], $body['promo_max']);
index e2068dc..ede101f 100644 (file)
@@ -31,31 +31,37 @@ class GadgetsModule extends PLModule
         );
     }
 
-    function handler_ig_events_xml(&$page) {
+    function handler_ig_events_xml(&$page)
+    {
         require_once 'gadgets/gadgets.inc.php';
         init_igoogle_xml('gadgets/ig-events.xml.tpl');
     }
 
-    function handler_ig_events(&$page) {
+    function handler_ig_events(&$page)
+    {
         require_once 'gadgets/gadgets.inc.php';
         init_igoogle_html('gadgets/ig-events.tpl', AUTH_COOKIE);
 
-        $events = XDB::iterator(
-            'SELECT  SQL_CALC_FOUND_ROWS
-                     e.id, e.titre, UNIX_TIMESTAMP(e.creation_date) AS creation_date,
-                     IF(u.nom_usage = "", u.nom, u.nom_usage) AS nom, u.prenom, u.promo,
-                     ev.user_id IS NULL AS nonlu
-               FROM  evenements AS e
-         INNER JOIN  auth_user_md5 AS u ON e.user_id = u.user_id
-          LEFT JOIN  evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?})
-              WHERE  FIND_IN_SET("valide", e.flags) AND peremption >= NOW()
-                     AND (e.promo_min = 0 || e.promo_min <= {?})
-                     AND (e.promo_max = 0 || e.promo_max >= {?})
-           ORDER BY  e.creation_date DESC
-              LIMIT  {?}',
-            S::i('uid'), S::i('promo'), S::i('promo'), 5);
-        $page->assign('events', $events);
+        $events = XDB::iterator('SELECT  SQL_CALC_FOUND_ROWS
+                                         e.id, e.titre, UNIX_TIMESTAMP(e.creation_date) AS creation_date,
+                                         IF(u.nom_usage = "", u.nom, u.nom_usage) AS nom, u.prenom, u.promo,
+                                         ev.user_id IS NULL AS nonlu, e.user_id
+                                   FROM  evenements AS e
+                              LEFT JOIN  evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?})
+                                  WHERE  FIND_IN_SET("valide", e.flags) AND peremption >= NOW()
+                               ORDER BY  e.creation_date DESC', S::i('uid'));
         $page->assign('event_count', XDB::query("SELECT FOUND_ROWS()")->fetchOneCell());
+
+        Platal::load('events', 'feed.inc.php');
+        $user = S::user();
+        $data = array();
+        while ($e = PlFeed::nextEvent($events, $user)) {
+            $data[] = $e;
+            if (count($data) == 5) {
+                break;
+            }
+        }
+        $page->assign('events', $data);
     }
 
     function handler_ig_search_xml(&$page) {
index e4032ba..673d6bd 100644 (file)
@@ -22,7 +22,7 @@
 
 <div class="events">
   <ul>
-  {iterate from=$events item=ev}
+  {foreach from=$events item=ev}
     <li class="{if $ev.nonlu}unread{else}read{/if}" id="evt-{$ev.id}">
       {if $ev.nonlu}
       <div  id="mark-read-{$ev.id}" style="float: right">
       </div>
       {/if}
       <a href="events{if !$ev.nonlu}/unread/{$ev.id}{else}#newsid{$ev.id}{/if}" target="_blank" id="link-{$ev.id}"
-         title="Ajouté le {$ev.creation_date|date_format} par {$ev.prenom} {$ev.nom} (X{$ev.promo})">
+         title="Ajouté le {$ev.creation_date|date_format} par {profile user=$ev.user_id link=false sex=false promo=true}">
         {tidy}
           {$ev.titre|nl2br}
         {/tidy}
       </a>
     </li>
   {assign var="has_evts" value=true}
-  {/iterate}
+  {/foreach}
   {if !$has_evts}
     <li><em>Aucun article actuellement.</em></li>
   {/if}