Outputs csv of postal formatted addresses corresponding to an advanced query (#Closes...
[platal.git] / include / userset.inc.php
index 0612d2f..48c07b0 100644 (file)
@@ -50,10 +50,11 @@ class SearchSet extends ProfileSet
     public  $advanced = false;
     private $score    = null;
     private $quick    = false;
+    private $valid    = true;
 
     public function __construct($quick = false, PlFilterCondition $cond = null)
     {
-        if ($no_search) {
+        if (isset($no_search)) {
             return;
         }
 
@@ -74,6 +75,11 @@ class SearchSet extends ProfileSet
         }
     }
 
+    public function isValid()
+    {
+        return $this->valid;
+    }
+
     /** Sets up the conditions for a Quick Search
      * @param $conds Additional conds (as a PFC_And)
      */
@@ -87,6 +93,7 @@ class SearchSet extends ProfileSet
         $ufb = new UFB_QuickSearch();
 
         if (!$ufb->isValid()) {
+            $this->valid = false;
             return;
         }
 
@@ -115,6 +122,7 @@ class SearchSet extends ProfileSet
         $ufb = new UFB_AdvancedSearch();
 
         if (!$ufb->isValid()) {
+            $this->valid = false;
             return;
         }
 
@@ -342,5 +350,43 @@ 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)
+    {
+        $res = $this->set->get(new PlLimit());
+        $visibility = new ProfileVisibility(ProfileVisibility::VIS_AX);
+        pl_content_headers('text/x-csv');
+
+        $csv = fopen('php://output', 'w');
+        fputcsv($csv, array('adresses'), ';');
+        foreach ($res as $profile) {
+            $addresses = $profile->getAddresses(Profile::ADDRESS_POSTAL);
+            if (!empty($addresses)) {
+                foreach ($addresses as $address) {
+                    if ($visibility->isVisible($address->pub)) {
+                        fputcsv($csv, array($profile->public_name, $address->postalText), ';');
+                        break;
+                    }
+                }
+            }
+        }
+        fclose($csv);
+        exit();
+    }
+
+    public function args()
+    {
+        return $this->set->args();
+    }
+}
+
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
 ?>