Fixes payment for group non member.
[platal.git] / classes / userfilter / conditions.inc.php
index 85d1d03..4070c3f 100644 (file)
@@ -583,67 +583,35 @@ class UFC_EducationField extends UserFilterCondition
     }
 }
 // }}}
-// {{{ class UFC_Name
-/** Filters users based on name
- * @param $type Type of name field on which filtering is done (firstname, lastname...)
- * @param $text Text on which to filter
- * @param $mode Flag indicating search type (prefix, suffix, with particule...)
+// {{{ class UFC_NameInitial
+/** Filters users based on sort_name
+ * @param $initial Initial on which to filter
  */
-class UFC_Name extends UserFilterCondition
+class UFC_NameInitial extends UserFilterCondition
 {
-    const EXACT    = XDB::WILDCARD_EXACT;    // 0x000
-    const PREFIX   = XDB::WILDCARD_PREFIX;   // 0x001
-    const SUFFIX   = XDB::WILDCARD_SUFFIX;   // 0x002
-    const CONTAINS = XDB::WILDCARD_CONTAINS; // 0x003
-    const PARTICLE = 0x004;
-    const VARIANTS = 0x008;
+    private $initial;
 
-    private $type;
-    private $text;
-    private $mode;
-
-    public function __construct($type, $text, $mode)
+    public function __construct($initial)
     {
-        $this->type = $type;
-        $this->text = $text;
-        $this->mode = $mode;
-    }
-
-    private function buildNameQuery($type, $variant, $where, UserFilter $uf)
-    {
-        $sub = $uf->addNameFilter($type, $variant);
-        return str_replace('$ME', 'pn' . $sub, $where);
+        $this->initial = $initial;
     }
 
     public function buildCondition(PlFilter $uf)
     {
-        $left = '$ME.name';
-        if (($this->mode & self::PARTICLE) == self::PARTICLE) {
-            $left = 'CONCAT($ME.particle, \' \', $ME.name)';
-        }
-        $right = XDB::formatWildcards($this->mode & self::CONTAINS, $this->text);
-
-        $cond = $left . $right;
-        $conds = array($this->buildNameQuery($this->type, null, $cond, $uf));
-        if (($this->mode & self::VARIANTS) != 0 && isset(Profile::$name_variants[$this->type])) {
-            foreach (Profile::$name_variants[$this->type] as $var) {
-                $conds[] = $this->buildNameQuery($this->type, $var, $cond, $uf);
-            }
+        $table = 'sort_name';
+        if ($uf->accountsRequired()) {
+            $table = Profile::getAccountEquivalentName($table);
+            $sub = 'a';
+        } else {
+            $uf->addDisplayFilter();
+            $sub = 'pd';
         }
-        return implode(' OR ', $conds);
+        return 'SUBSTRING(' . $sub . '.' . $table . ', 1, 1) ' . XDB::formatWildcards(XDB::WILDCARD_PREFIX, $this->initial);
     }
 
     public function export()
     {
-        $export = $this->buildExport($this->type);
-        if ($this->mode & self::VARIANTS) {
-            $export['search_in_variants'] = true;
-        }
-        if ($this->mode & self::PARTICLE) {
-            $export['search_in_particle'] = true;
-        }
-        $export['comparison'] = self::comparisonFromXDBWildcard($this->mode & 0x3);
-        $export['text'] = $this->text;
+        $export = $this->buildExport($this->initial);
         return $export;
     }
 }
@@ -878,7 +846,7 @@ class UFC_NLSubscribed extends UserFilterCondition
     public function buildCondition(PlFilter $uf)
     {
         $sub = $uf->addNewsLetterFilter($this->nlid);
-        return XDB::format($sub . '.last < {?}', $this->issue_id);
+        return XDB::format($sub . '.nlid IS NOT NULL AND ( ' . $sub . '.last IS NULL OR ' . $sub . '.last < {?})', $this->issue_id);
     }
 }
 // }}}
@@ -912,6 +880,30 @@ class UFC_Group extends UserFilterCondition
     }
 }
 // }}}
+// {{{ class UFC_GroupFormerMember
+/** Filters users based on group former membership
+ * @param $group Group whose former members we are selecting
+ */
+class UFC_GroupFormerMember extends UserFilterCondition
+{
+    private $group;
+
+    public function __construct($group)
+    {
+        $this->group = $group;
+    }
+
+    public function buildCondition(PlFilter $uf)
+    {
+        // Groups are only visible for users with perm 'groups'.
+        if (!S::user()->checkPerms(User::PERM_GROUPS)) {
+            return self::COND_FALSE;
+        }
+        $sub = $uf->addGroupFormerMemberFilter();
+        return XDB::format('gpfm' . $sub . '.asso_id = {?}', $this->group);
+    }
+}
+// }}}
 // {{{ class UFC_Binet
 /** Selects users based on their belonging to a given (list of) binet
  * @param $binet either a binet_id or an array of binet_ids
@@ -993,7 +985,7 @@ class UFC_Email extends UserFilterCondition
 
         if (count($foreign) > 0) {
             $sub = $uf->addEmailRedirectFilter($foreign);
-            $cond[] = XDB::format('ra' . $sub . '.redirect IS NOT NULL OR ra' . $sub . '.redirect IN {?}', $foreign);
+            $cond[] = XDB::format('ra' . $sub . '.redirect IS NOT NULL OR ra' . $sub . '.redirect IN {?} OR a.email IN {?}', $foreign, $foreign);
         }
         if (count($local) > 0) {
             $sub = $uf->addAliasFilter($local);
@@ -1088,7 +1080,7 @@ abstract class UFC_Address extends UserFilterCondition
  */
 class UFC_AddressComponent extends UFC_Address
 {
-    static $components = array('sublocality', 'locality', 'administrative_area_level_3', 'administrative_area_level_2', 'administrative_area_level_1', 'country');
+    static $components = array('postal_code', 'locality', 'administrative_area_level_3', 'administrative_area_level_2', 'administrative_area_level_1', 'country');
 
     /** Data of the filter
      */
@@ -1115,7 +1107,7 @@ class UFC_AddressComponent extends UFC_Address
     {
         $sub = $uf->addAddressFilter($this->fieldtype);
         $conds = $this->initConds($sub, $uf->getVisibilityCondition('pa' . $sub . '.pub'));
-        $conds[] = XDB::format('pace' . $sub . '.short_name IN {?}', $this->val);
+        $conds[] = XDB::format('pace' . $sub . '.id IN {?}', $this->val);
 
         return implode(' AND ', $conds);
     }
@@ -1513,6 +1505,36 @@ abstract class UFC_UserRelated extends UserFilterCondition
     }
 }
 // }}}
+// {{{ class UFC_DeltaTen
+class UFC_DeltaTen extends UserFilterCondition
+{
+    public function buildCondition(PlFilter $uf)
+    {
+        $sub = $uf->addDeltaTenFilter(UserFilter::DELTATEN);
+        return $sub . '.message IS NOT NULL';
+    }
+}
+// }}}
+// {{{ class UFC_DeltaTen_Message
+/** Filters users by deltaten message
+ * @param $message Message for the DeltaTen program
+ */
+class UFC_DeltaTen_Message extends UserFilterCondition
+{
+    private $message;
+
+    public function __construct($message)
+    {
+        $this->message = $message;
+    }
+
+    public function buildCondition(PlFilter $uf)
+    {
+        $sub = $uf->addDeltaTenFilter(UserFilter::DELTATEN_MESSAGE);
+        return $sub . '.message ' . XDB::formatWildcards(XDB::WILDCARD_CONTAINS, $this->message);
+    }
+}
+// }}}
 // {{{ class UFC_Contact
 /** Filters users who belong to selected user's contacts
  */