Reorganize events menu
authorx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Mon, 26 Feb 2007 22:24:58 +0000 (22:24 +0000)
committerx2003bruneau <x2003bruneau@839d8a87-29fc-0310-9880-83ba4fa771e5>
Mon, 26 Feb 2007 22:24:58 +0000 (22:24 +0000)
git-svn-id: svn+ssh://murphy/home/svn/platal/trunk@1526 839d8a87-29fc-0310-9880-83ba4fa771e5

ChangeLog
htdocs/images/icons/bell.gif [new file with mode: 0644]
htdocs/images/icons/clock.gif [new file with mode: 0644]
modules/events.php
templates/events/index.tpl

index 91911aa..b6a6a3b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,9 @@ New:
         - UTF-8                                                            -FRU
         - New Backtrace tool                                               -FRU
 
+    * Events:
+        - #643: Sort menu                                                  -FRU
+
     * Search:
         - Search Engine IE7 compatible                                     -FRU
 
diff --git a/htdocs/images/icons/bell.gif b/htdocs/images/icons/bell.gif
new file mode 100644 (file)
index 0000000..b0a1965
Binary files /dev/null and b/htdocs/images/icons/bell.gif differ
diff --git a/htdocs/images/icons/clock.gif b/htdocs/images/icons/clock.gif
new file mode 100644 (file)
index 0000000..5629813
Binary files /dev/null and b/htdocs/images/icons/clock.gif differ
index 894d5c2..3601aef 100644 (file)
@@ -59,6 +59,41 @@ class EventsModule extends PLModule
         return $res->fetchOneAssoc();
     }
 
+    function get_events($where, $order, array &$array, $name)
+    {
+        // affichage des evenements
+        // annonces promos triées par présence d'une limite sur les promos
+        // puis par dates croissantes d'expiration
+        $promo = S::v('promo');
+        $uid   = S::i('uid'); 
+        $sql = "SELECT  e.id,e.titre, ev.user_id IS NULL AS nonlu
+                  FROM  evenements    AS e
+            LEFT JOIN   evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?})
+                 WHERE  FIND_IN_SET(e.flags, 'valide') AND peremption >= NOW()
+                        AND (e.promo_min = 0 || e.promo_min <= {?})
+                        AND (e.promo_max = 0 || e.promo_max >= {?})
+                        AND $where
+              ORDER BY  $order";
+        $sum = XDB::iterator($sql, $uid, $promo, $promo);
+        if (!$sum->total()) {
+            return false;
+        }
+        $sql = "SELECT  e.id,e.titre,e.texte,a.user_id,a.nom,a.prenom,a.promo,l.alias AS forlife
+                  FROM  evenements     AS e
+            INNER JOIN  auth_user_md5  AS a ON e.user_id=a.user_id
+            INNER JOIN  aliases        AS l ON ( a.user_id=l.id AND l.type='a_vie' )
+             LEFT JOIN  evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?})
+                 WHERE  FIND_IN_SET(e.flags, 'valide') AND peremption >= NOW()
+                        AND (e.promo_min = 0 || e.promo_min <= {?})
+                        AND (e.promo_max = 0 || e.promo_max >= {?})
+                        AND ev.user_id IS NULL
+                        AND $where
+              ORDER BY  $order";
+        $evt = XDB::iterator($sql, $uid, $promo, $promo);
+        $array[$name] = array('events' => $evt, 'summary' => $sum);
+        return true;
+    }
+
     function handler_ev(&$page, $action = 'list', $eid = null, $pound = null)
     {
         $page->changeTpl('events/index.tpl');
@@ -66,7 +101,7 @@ class EventsModule extends PLModule
         $page->assign('tips', $this->get_tips());
 
         $res = XDB::query('SELECT date, naissance FROM auth_user_md5
-                                      WHERE user_id={?}', S::v('uid'));
+                            WHERE user_id={?}', S::v('uid'));
         list($date, $naissance) = $res->fetchOneRow();
 
         // incitation à mettre à jour la fiche
@@ -87,7 +122,7 @@ class EventsModule extends PLModule
         // incitation à mettre une photo
 
         $res = XDB::query('SELECT COUNT(*) FROM photo
-                                      WHERE uid={?}', S::v('uid'));
+                            WHERE uid={?}', S::v('uid'));
         $page->assign('photo_incitation', $res->fetchOneCell() == 0);
 
         // Incitation à se géolocaliser
@@ -119,36 +154,16 @@ class EventsModule extends PLModule
             pl_redirect('events#newsid'.$eid);
         }
 
-        // affichage des evenements
-        // annonces promos triées par présence d'une limite sur les promos
-        // puis par dates croissantes d'expiration
-        $promo = S::v('promo');
-        $sql = "SELECT  e.id,e.titre,e.texte,a.user_id,a.nom,a.prenom,a.promo,l.alias AS forlife
-                  FROM  evenements     AS e
-            INNER JOIN  auth_user_md5  AS a ON e.user_id=a.user_id
-            INNER JOIN  aliases        AS l ON ( a.user_id=l.id AND l.type='a_vie' )
-             LEFT JOIN  evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?})
-                 WHERE  FIND_IN_SET(e.flags, 'valide') AND peremption >= NOW()
-                        AND (e.promo_min = 0 || e.promo_min <= {?})
-                        AND (e.promo_max = 0 || e.promo_max >= {?})
-                        AND ev.user_id IS NULL
-              ORDER BY  (e.promo_min != 0 AND  e.promo_max != 0) DESC,  e.peremption";
-        $page->assign('evenement',
-                      XDB::iterator($sql, S::v('uid'),
-                                              $promo, $promo)
-                      );
-
-        $sql = "SELECT  e.id,e.titre, ev.user_id IS NULL AS nonlu
-                  FROM  evenements    AS e
-            LEFT JOIN   evenements_vus AS ev ON (e.id = ev.evt_id AND ev.user_id = {?})
-                 WHERE  FIND_IN_SET(e.flags, 'valide') AND peremption >= NOW()
-                        AND (e.promo_min = 0 || e.promo_min <= {?})
-                        AND (e.promo_max = 0 || e.promo_max >= {?})
-              ORDER BY  (e.promo_min != 0 AND  e.promo_max != 0) DESC,  e.peremption";
-        $page->assign('evenement_summary',
-                      XDB::iterator($sql, S::v('uid'),
-                                              $promo, $promo)
-                     );
+        $array = array();
+        $this->get_events('e.creation_date > DATE_SUB(CURDATE(), INTERVAL 2 DAY)',
+                          'e.creation_date DESC', $array, 'news');
+        $this->get_events('e.peremption < DATE_ADD(CURDATE(), INTERVAL 2 DAY)
+                          AND e.creation_date <= DATE_SUB(CURDATE(), INTERVAL 2 DAY)',
+                          'e.peremption, e.creation_date DESC', $array, 'end');
+        $this->get_events('e.peremption >= DATE_ADD(CURDATE(), INTERVAL 2 DAY)
+                          AND e.creation_date <= DATE_SUB(CURDATE(), INTERVAL 2 DAY)',
+                          'e.peremption, e.creation_date DESC', $array, 'body');
+        $page->assign_by_ref('events', $array);
     }
 
     function handler_rss(&$page, $user = null, $hash = null)
@@ -300,7 +315,8 @@ class EventsModule extends PLModule
                 $action = 'edit';
             } else {
                 XDB::execute('UPDATE evenements
-                                 SET titre={?}, texte={?}, peremption={?}, promo_min={?}, promo_max={?}
+                                 SET creation_date = creation_date, 
+                                     titre={?}, texte={?}, peremption={?}, promo_min={?}, promo_max={?}
                                WHERE id = {?}', 
                               Post::v('titre'), Post::v('texte'), Post::v('peremption'),
                               Post::v('promo_min'), Post::v('promo_max'), $eid);
index 6fc4e72..7e64ba8 100644 (file)
@@ -104,8 +104,22 @@ Bienvenue {$smarty.session.prenom}
         Sommaire des informations événementielles
       </th>
     </tr>
-    {iterate item=ev from=$evenement_summary}
-    <tr class="{cycle values="impair,pair"}">
+    {foreach from=$events name=events key=category item=evenement}
+    {if $smarty.foreach.events.total neq 1}
+    <tr class="pair" style="height: 18px">
+      <td class="half titre" style="height: 18px; padding-top: 1px; padding-bottom: 1px;">
+        {if $category eq 'news'}
+          {icon name=bell} Nouvelles annonces&nbsp;:
+        {elseif $category eq 'end'}
+          {icon name=clock} Dernières minutes&nbsp;:
+        {else}
+          {icon name=magnifier} Mais encore...
+        {/if}
+      </td>
+    </tr>
+    {/if}
+    {iterate item=ev from=$evenement.summary}
+    <tr class="impair">
       <td class="half">
         &bull;
         <a href="events{if !$ev.nonlu}/unread/{$ev.id}{else}#newsid{$ev.id}{/if}" id="link-evt{$ev.id}">
@@ -119,6 +133,7 @@ Bienvenue {$smarty.session.prenom}
     </tr>
     {assign var="has_evts" value=true}
     {/iterate}
+    {/foreach}
     {if !$has_evts}
     <tr>
       <td class="half">Aucun article actuellement</td>
@@ -141,14 +156,24 @@ Bienvenue {$smarty.session.prenom}
   }
   {/literal}
   </script>
-  
-  {iterate item=ev from=$evenement}
+  {foreach from=$events key=category item=evenement}
+  {iterate item=ev from=$evenement.events}
   <div id="content-evt{$ev.id}">
   <br />
 
   <table class="bicol">
     <tr>
       <th>
+        <div style="float: left">
+          {if $category eq 'news'}
+            {icon name=bell title="Nouvelle annonce"}
+          {elseif $category eq 'end'}
+            {icon name=clock title="Bientôt fini"}
+          {else}
+            {icon name=magnifier title="Annonce"}
+          {/if}
+        </div>
         <div style="float:right">
           {if $smarty.session.perms eq 'admin'}
           <a href="admin/events/edit/{$ev.id}">{icon name=page_edit title="Editer cet article"}</a>
@@ -178,6 +203,7 @@ Bienvenue {$smarty.session.prenom}
   </table>
   </div>
   {/iterate}
+  {/foreach}
 
   <p class="smaller">
   Nota Bene : les informations présentées ici n'engagent que leurs auteurs