Merge branch 'xorg/1.0.2/master' into xorg/master
[platal.git] / include / userset.inc.php
index 7ffe768..f99faf2 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  Copyright (C) 2003-2011 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -45,21 +45,15 @@ class ProfileSet extends PlSet
     }
 }
 
+require_once "ufbuilder.inc.php";
+
 class SearchSet extends ProfileSet
 {
-    public  $advanced = false;
-    private $score    = null;
-    private $quick    = false;
-    private $valid    = true;
+    protected $score    = null;
+    protected $valid    = true;
 
-    public function __construct($quick = false, PlFilterCondition $cond = null)
+    public function __construct(UserFilterBuilder &$ufb, PlFilterCondition $cond = null)
     {
-        if ($no_search) {
-            return;
-        }
-
-        $this->quick = $quick;
-
         if (is_null($cond)) {
             $conds = new PFC_And();
         } else if ($cond instanceof PFC_And) {
@@ -68,30 +62,6 @@ class SearchSet extends ProfileSet
             $conds = new PFC_And($cond);
         }
 
-        if ($quick) {
-            $this->getQuick($conds);
-        } else {
-            $this->getAdvanced($conds);
-        }
-    }
-
-    public function isValid()
-    {
-        return $this->valid;
-    }
-
-    /** Sets up the conditions for a Quick Search
-     * @param $conds Additional conds (as a PFC_And)
-     */
-    private function getQuick($conds)
-    {
-        if (!S::logged()) {
-            Env::kill('with_soundex');
-        }
-
-        require_once 'ufbuilder.inc.php';
-        $ufb = new UFB_QuickSearch();
-
         if (!$ufb->isValid()) {
             $this->valid = false;
             return;
@@ -102,36 +72,12 @@ class SearchSet extends ProfileSet
 
         $orders = $ufb->getOrders();
 
-        if (S::logged() && Env::has('nonins')) {
-            $conds = new PFC_And($conds,
-                new PFC_Not(new UFC_Dead()),
-                new PFC_Not(new UFC_Registered())
-            );
-        }
-
         parent::__construct($conds, $orders);
     }
 
-    /** Sets up the conditions for an Advanced Search
-     * @param $conds Additional conds (as a PFC_And)
-     */
-    private function getAdvanced($conds)
+    public function isValid()
     {
-        $this->advanced = true;
-        require_once 'ufbuilder.inc.php';
-        $ufb = new UFB_AdvancedSearch();
-
-        if (!$ufb->isValid()) {
-            $this->valid = false;
-            return;
-        }
-
-        $ufc = $ufb->getUFC();
-        $conds->addChild($ufc);
-
-        $orders = $ufb->getOrders();
-
-        parent::__construct($conds, $orders);
+        return $this->valid;
     }
 
     /** Add a "rechercher=Chercher" field to the query to simulate the POST
@@ -153,6 +99,30 @@ class SearchSet extends ProfileSet
     }
 }
 
+// Specialized SearchSet for quick search.
+class QuickSearchSet extends SearchSet
+{
+    public function __construct(PlFilterCondition $cond = null)
+    {
+        if (!S::logged()) {
+            Env::kill('with_soundex');
+        }
+
+        parent::__construct(new UFB_QuickSearch(), $cond);
+    }
+}
+
+// Specialized SearchSet for advanced search.
+class AdvancedSearchSet extends SearchSet
+{
+    public function __construct($xorg_admin_fields, $ax_admin_fields,
+                                PlFilterCondition $cond = null)
+    {
+        parent::__construct(new UFB_AdvancedSearch($xorg_admin_fields, $ax_admin_fields),
+                            $cond);
+    }
+}
+
 /** Simple set based on an array of User objects
  */
 class ArraySet extends ProfileSet
@@ -350,5 +320,40 @@ class GadgetView implements PlView
     }
 }
 
+class AddressesView implements PlView
+{
+    private $set;
+
+    public function __construct(PlSet &$set, array $params)
+    {
+        $this->set =& $set;
+    }
+
+    public function apply(PlPage &$page)
+    {
+        $pids = $this->set->getIds(new PlLimit());
+        $visibility = new ProfileVisibility(ProfileVisibility::VIS_AX);
+        pl_cached_content_headers('text/x-csv', 1);
+
+        $csv = fopen('php://output', 'w');
+        fputcsv($csv, array('adresses'), ';');
+        $res = XDB::query('SELECT  pd.public_name, pa.postalText
+                             FROM  profile_addresses AS pa
+                       INNER JOIN  profile_display   AS pd ON (pd.pid = pa.pid)
+                            WHERE  pa.type = \'home\' AND pa.pub IN (\'public\', \'ax\') AND FIND_IN_SET(\'mail\', pa.flags) AND pa.pid IN {?}
+                         GROUP BY  pa.pid', $pids);
+        foreach ($res->fetchAllAssoc() as $item) {
+            fputcsv($csv, $item, ';');
+        }
+        fclose($csv);
+        exit();
+    }
+
+    public function args()
+    {
+        return $this->set->args();
+    }
+}
+
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>