Temporarily fixes promo in xnet announces.
authorStéphane Jacob <sj@m4x.org>
Mon, 19 Jul 2010 19:04:00 +0000 (21:04 +0200)
committerStéphane Jacob <sj@m4x.org>
Tue, 20 Jul 2010 08:49:59 +0000 (10:49 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
include/validations/evts.inc.php
modules/axletter/axletter.inc.php
modules/xnetgrp.php
templates/xnetgrp/announce-edit.tpl

index ddfdef5..4a7416f 100644 (file)
@@ -134,6 +134,7 @@ class EvtReq extends Validate
 
     public function commit()
     {
+        /* TODO: refines this filter on promotions by using userfilter. */
         if (XDB::execute("INSERT INTO  announces
                          SET  uid = {?}, creation_date=NOW(), titre={?}, texte={?},
                               expiration={?}, promo_min={?}, promo_max={?}, flags=CONCAT(flags,',valide,wiki')",
index 761724c..f31f979 100644 (file)
@@ -175,6 +175,7 @@ class AXLetter extends MassMailer
         if (!$this->_promo_min && !$this->_promo_max && !$this->_subset) {
             return '1';
         }
+        /* TODO: refines this filter on promotions by using userfilter. */
         $where = array();
         if ($this->_promo_min) {
             $where[] = "((ni.uid = 0 AND ni.promo >= {$this->_promo_min}) OR (ni.uid != 0 AND u.promo >= {$this->_promo_min}))";
index b46ffed..e4449a0 100644 (file)
@@ -81,24 +81,34 @@ class XnetGrpModule extends PLModule
                             Env::i('unread'), S::i('uid'));
                 pl_redirect("#art" . Env::i('unread'));
             }
-            // XXX: Fix promo_min; promo_max
-            $arts = XDB::iterator("SELECT  a.*, FIND_IN_SET('photo', a.flags) AS photo
+
+            /* TODO: refines this filter on promotions by using userfilter. */
+            $user = S::user();
+            if ($user->hasProfile()) {
+                $promo = XDB::format('{?}', $user->profile()->entry_year);
+                $minCondition = ' OR promo_min <= ' . $promo;
+                $maxCondition = ' OR promo_max >= ' . $promo;
+            } else {
+                $minCondition = '';
+                $maxCondition = '';
+            }
+            $arts = XDB::iterator('SELECT  a.*, FIND_IN_SET(\'photo\', a.flags) AS photo
                                      FROM  group_announces      AS a
                                 LEFT JOIN  group_announces_read AS r ON (r.uid = {?} AND r.announce_id = a.id)
                                     WHERE  asso_id = {?} AND expiration >= CURRENT_DATE()
-                                           AND (promo_min = 0 OR promo_min <= {?})
-                                           AND (promo_max = 0 OR promo_max >= {?})
+                                           AND (promo_min = 0' . $minCondition . ')
+                                           AND (promo_max = 0' . $maxCondition . ')
                                            AND r.announce_id IS NULL
-                                 ORDER BY  a.expiration",
-                                   S::i('uid'), $globals->asso('id'), S::i('promo'), S::i('promo'));
-            $index = XDB::iterator("SELECT  a.id, a.titre, r.uid IS NULL AS nonlu
+                                 ORDER BY  a.expiration',
+                                   S::i('uid'), $globals->asso('id'));
+            $index = XDB::iterator('SELECT  a.id, a.titre, r.uid IS NULL AS nonlu
                                       FROM  group_announces      AS a
                                  LEFT JOIN  group_announces_read AS r ON (a.id = r.announce_id AND r.uid = {?})
                                      WHERE  asso_id = {?} AND expiration >= CURRENT_DATE()
-                                            AND (promo_min = 0 OR promo_min <= {?})
-                                            AND (promo_max = 0 OR promo_max >= {?})
-                                  ORDER BY  a.expiration",
-                                   S::i('uid'), $globals->asso('id'), S::i('promo'), S::i('promo'));
+                                            AND (promo_min = 0' . $minCondition . ')
+                                            AND (promo_max = 0' . $maxCondition . ')
+                                  ORDER BY  a.expiration',
+                                   S::i('uid'), $globals->asso('id'));
             $page->assign('article_index', $index);
         } else {
             $arts = XDB::iterator("SELECT  *, FIND_IN_SET('photo', flags) AS photo
index 92ecf00..b387273 100644 (file)
@@ -26,6 +26,7 @@ function visibilityChange(box)
 {
     var state = (box.checked ? 'none' : '');
     document.getElementById('promo_titre').style.display = state;
+    document.getElementById('promo_explanation').style.display = state;
     document.getElementById('promo_min_tr').style.display = state;
     document.getElementById('promo_max_tr').style.display = state;
     document.getElementById('promo_range_tr').style.display = state;
@@ -163,7 +164,10 @@ function visibilityChange(box)
       </td>
     </tr>
     <tr id="promo_titre" {if $art.public}style="display: none"{/if}>
-      <th colspan="2">Promotions cibles</th>
+      <th colspan="2">Promotions d'entrée cibles</th>
+    </tr>
+    <tr id="promo_explanation" {if $art.public}style="display: none"{/if}>
+      <td colspan="2"><span class="smaller">{icon name=information} par exemple 2004 pour les X2004</span></td>
     </tr>
     {include file="include/field.promo.tpl" promo_min=$art.promo_min promo_max=$art.promo_max}
     {if $art.public}