Adds MapView.
authorStéphane Jacob <sj@m4x.org>
Fri, 20 May 2011 12:32:39 +0000 (14:32 +0200)
committerStéphane Jacob <sj@m4x.org>
Tue, 24 May 2011 06:31:47 +0000 (08:31 +0200)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
htdocs/javascript/maps.js
include/userset.inc.php
modules/carnet.php
modules/geoloc.php
modules/lists.php
modules/search.php

index db3020d..a2f1864 100644 (file)
@@ -31,7 +31,7 @@ function map_initialize()
     };
     var map = new google.maps.Map($('#map_canvas').get(0), myOptions);
 
-    $.xget('map/ajax', function(json_data) {
+    $.xget(window.location.href, {ajax: true}, function(json_data) {
         var data = jQuery.parseJSON(json_data);
         var dots = data.data;
         var count = dots.length;
index c590527..55521c7 100644 (file)
@@ -359,6 +359,37 @@ class TrombiView extends MixedView
     }
 }
 
+class MapView implements PlView
+{
+    private $set;
+
+    public function __construct(PlSet $set, array $params)
+    {
+        $this->set = $set;
+    }
+
+    public function apply(PlPage $page)
+    {
+        Platal::load('geoloc');
+
+        if (Get::b('ajax')) {
+            $pids = $this->set->getIds(new PlLimit());
+            GeolocModule::assign_json_to_map($page, $pids);
+            $page->runJSON();
+            exit;
+        } else {
+            $this->set->getIds(new PlLimit());
+            GeolocModule::prepare_map($page);
+            return 'geoloc/index.tpl';
+        }
+    }
+
+    public function args()
+    {
+        return $this->set->args();
+    }
+}
+
 class GadgetView implements PlView
 {
     public function __construct(PlSet $set, array $params)
index b813289..3a126a1 100644 (file)
@@ -324,12 +324,9 @@ class CarnetModule extends PLModule
 
         $view->addMod('minifiche', 'Mini-fiches', true);
         $view->addMod('trombi', 'Trombinoscope', false, array('with_admin' => false, 'with_promo' => true));
-        // TODO: Reactivate when the new map is completed.
-        // $view->addMod('geoloc', 'Planisphère', false, array('with_annu' => 'carnet/contacts/search'));
+        $view->addMod('map', 'Planisphère');
         $view->apply('carnet/contacts', $page, $action, $subaction);
-        //if ($action != 'geoloc' || ($search && !$ssaction) || (!$search && !$subaction)) {
         $page->changeTpl('carnet/mescontacts.tpl');
-        //}
     }
 
     function handler_pdf($page, $arg0 = null, $arg1 = null)
index 6952510..c0402bf 100644 (file)
@@ -24,8 +24,7 @@ class GeolocModule extends PLModule
     function handlers()
     {
         return array(
-            'map'      => $this->make_hook('map',      AUTH_COOKIE),
-            'map/ajax' => $this->make_hook('map_ajax', AUTH_COOKIE)
+            'map' => $this->make_hook('map', AUTH_COOKIE)
         );
     }
 
@@ -41,24 +40,33 @@ class GeolocModule extends PLModule
         $page->assign('pl_extra_header', '<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />');
     }
 
-    function handler_map($page)
+    static public function assign_json_to_map(PlPage $page, $pids = null)
     {
-        self::prepare_map($page);
-    }
+        if (!is_null($pids)) {
+            $where = XDB::format(' AND pa.pid IN {?}', $pids);
+        } else {
+            $where = '';
+        }
 
-    function handler_map_ajax($page)
-    {
         $data = XDB::rawFetchAllAssoc('SELECT  pa.latitude, pa.longitude, GROUP_CONCAT(DISTINCT p.hrpid SEPARATOR \',\') AS hrpid,
                                                GROUP_CONCAT(pd.promo SEPARATOR \',\') AS promo,
                                                GROUP_CONCAT(DISTINCT CONCAT(pd.private_name, \' (\', pd.promo, \')\') SEPARATOR \',\') AS name
                                          FROM  profile_addresses AS pa
                                    INNER JOIN  profiles          AS p  ON (pa.pid = p.pid)
                                    INNER JOIN  profile_display   AS pd ON (pd.pid = pa.pid)
-                                        WHERE  pa.type = \'home\' AND pa.latitude IS NOT NULL AND pa.longitude IS NOT NULL
+                                        WHERE  pa.type = \'home\' AND pa.latitude IS NOT NULL AND pa.longitude IS NOT NULL' . $where . '
                                      GROUP BY  pa.latitude, pa.longitude');
         $page->jsonAssign('data', $data);
+    }
 
-        return PL_JSON;
+    function handler_map($page)
+    {
+        if (Get::b('ajax')) {
+            self::assign_json_to_map($page);
+            return PL_JSON;
+        } else {
+            self::prepare_map($page);
+        }
     }
 }
 
index 8b417e0..8c52f23 100644 (file)
@@ -399,8 +399,7 @@ class ListsModule extends PLModule
         if (empty($GLOBALS['IS_XNET_SITE'])) {
             $view->addMod('minifiche', 'Mini-fiches', false);
         }
-        // TODO: Reactivate when the new map is completed.
-        // $view->addMod('geoloc', 'Planisphère');
+        $view->addMod('map', 'Planisphère');
         $view->apply("lists/annu/$liste", $page, $action, $subaction);
 
         $page->changeTpl('lists/annu.tpl');
index 1dc226c..7c33bd5 100644 (file)
@@ -123,8 +123,7 @@ class SearchModule extends PLModule
             $view->addMod('minifiche', 'Mini-fiches', true, array('with_score' => true, 'starts_with' => $byletter));
             if (S::logged() && !Env::i('nonins')) {
                 $view->addMod('trombi', 'Trombinoscope', false, array('with_promo' => true, 'with_score' => true));
-                // TODO: Reactivate when the new map is completed.
-                // $view->addMod('geoloc', 'Planisphère', false, array('with_annu' => 'search/adv'));
+                $view->addMod('map', 'Planisphère');
             }
             $view->apply('search', $page, $model);
 
@@ -188,8 +187,7 @@ class SearchModule extends PLModule
             } else {
                 $view->addMod('minifiche', 'Mini-fiches', true, array('starts_with' => $byletter));
                 $view->addMod('trombi', 'Trombinoscope', false, array('with_promo' => true));
-                // TODO: Reactivate when the new map is completed.
-                // $view->addMod('geoloc', 'Planisphère', false, array('with_annu' => 'search/adv'));
+                $view->addMod('map', 'Planisphère');
                 if (S::user()->checkPerms(User::PERM_EDIT_DIRECTORY) || S::admin()) {
                     $view->addMod('addresses', 'Adresses postales', false);
                 }