+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();
+ }
+}
+
+class JSonView implements PlView
+{
+ private $set;
+ private $params;
+
+ public function __construct(PlSet $set, array $params)
+ {
+ $this->set = $set;
+ $this->params = $params;
+ }
+
+ public function apply(PlPage $page)
+ {
+ $export = array();
+ $start = isset($this->params['offset']) ? $this->params['offset'] : 0;
+ $count = isset($this->params['count']) ? $this->params['count'] : 10;
+ $profiles = $this->set->get(new PlLimit($start, $count));
+ foreach ($profiles as $profile) {
+ $export[] = $profile->export();
+ }
+ $page->jsonAssign('profile_count', $this->set->count());
+ $page->jsonAssign('profiles', $export);
+ }
+
+ public function args()
+ {
+ return $this->set->args();
+ }
+}
+