Add UFC_Networking
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Sun, 17 Jan 2010 01:46:05 +0000 (02:46 +0100)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Sun, 17 Jan 2010 01:46:05 +0000 (02:46 +0100)
For filtering users by network ID (IRC, ICQ, jabber, ...)

Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
classes/userfilter.php

index 972cffe..5470d05 100644 (file)
@@ -747,6 +747,35 @@ class UFC_Job_Description extends UserFilterCondition
 }
 // }}}
 
+// {{{ class UFC_Networking
+/** Filters users based on network identity (IRC, ...)
+ * @param $type Type of network (-1 for any)
+ * @param $value Value to search
+ */
+class UFC_Networking extends UserFilterCondition
+{
+    private $type;
+    private $value;
+
+    public function __construct($type, $value)
+    {
+        $this->type = $type;
+        $this->value = $value;
+    }
+
+    public function buildCondition(UserFilter &$uf)
+    {
+        $sub = $uf->addNetworkingFilter();
+        $conds = array();
+        $conds[] = $sub . '.address = ' . XDB::format('CONCAT(\'%\', {?}, \'%\')', $this->value);
+        if ($this->type != -1) {
+            $conds[] = $sub . '.network_type = ' . XDB::format('{?}', $this->type);
+        }
+        return implode(' AND ', $conds);
+    }
+}
+// }}}
+
 // {{{ class UFC_UserRelated
 /** Filters users based on a relation toward on user
  * @param $user User to which searched users are related
@@ -1609,6 +1638,25 @@ class UserFilter
         return $joins;
     }
 
+    /** NETWORKING
+     */
+
+    private $with_pnw = false;
+    public function addNetworkingFilter()
+    {
+        $this->with_pnw = true;
+        return 'pnw';
+    }
+
+    private function networkingJoins()
+    {
+        $joins = array();
+        if ($this->with_pnw) {
+            $joins['pnw'] = array('left', 'profile_networking', '$ME.uid = $UID');
+        }
+        return $joins;
+    }
+
     /** CONTACTS
      */
     private $cts = array();