Rewrite FlagSet in order to run flag operation in constant time.
[platal.git] / modules / payment / money.inc.php
index a79f03a..c38d1c3 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2007 Polytechnique.org                              *
+ *  Copyright (C) 2003-2008 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -43,13 +43,13 @@ class Payment
         global $globals;
         $r   = $ref==-1 ? $globals->money->mpay_def_id : $ref;
         $res = XDB::query("SELECT  id, text, url, flags, mail, montant_min, montant_max, montant_def, asso_id
-                                       FROM  {$globals->money->mpay_tprefix}paiements WHERE id={?}", $r);
+                             FROM  {$globals->money->mpay_tprefix}paiements WHERE id={?}", $r);
         list($this->id, $this->text, $this->url, $flags, $this->mail,
-                $this->montant_min, $this->montant_max, $this->montant_def, $this->asso_id) = $res->fetchOneRow();
+             $this->montant_min, $this->montant_max, $this->montant_def, $this->asso_id) = $res->fetchOneRow();
 
         $this->montant_min = (float)$this->montant_min;
         $this->montant_max = (float)$this->montant_max;
-        $this->flags       = new Flagset($flags);
+        $this->flags       = new PlFlagSet($flags);
     }
 
     // }}}
@@ -87,8 +87,14 @@ class Payment
     function event()
     {
         if ($this->asso_id) {
-            $res = XDB::query("SELECT eid, a.diminutif FROM groupex.evenements AS e, groupex.asso AS a WHERE e.asso_id = {?} AND a.id = {?}", $this->asso_id, $this->asso_id);
-            return $res->fetchOneAssoc();
+            $res = XDB::query("SELECT  e.eid, a.diminutif
+                                 FROM  groupex.evenements AS e
+                           INNER JOIN  groupex.asso AS a ON (e.asso_id = a.id)
+                            LEFT JOIN  groupex.evenements_participants AS p ON (p.eid = e.eid AND p.uid = {?})
+                                WHERE  e.paiement_id = {?} AND p.uid IS NULL", S::i('uid'), $this->id);
+            if ($res->numRows()) {
+                return $res->fetchOneAssoc();
+            }
         }
         return null;
     }