From: Stéphane Jacob Date: Fri, 20 May 2011 12:32:39 +0000 (+0200) Subject: Adds MapView. X-Git-Tag: xorg/1.1.2~62^2~2 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=0a928a2f2d5ded38bb30237efa6037397538e049;p=platal.git Adds MapView. Signed-off-by: Stéphane Jacob --- diff --git a/htdocs/javascript/maps.js b/htdocs/javascript/maps.js index db3020d..a2f1864 100644 --- a/htdocs/javascript/maps.js +++ b/htdocs/javascript/maps.js @@ -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; diff --git a/include/userset.inc.php b/include/userset.inc.php index c590527..55521c7 100644 --- a/include/userset.inc.php +++ b/include/userset.inc.php @@ -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) diff --git a/modules/carnet.php b/modules/carnet.php index b813289..3a126a1 100644 --- a/modules/carnet.php +++ b/modules/carnet.php @@ -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) diff --git a/modules/geoloc.php b/modules/geoloc.php index 6952510..c0402bf 100644 --- a/modules/geoloc.php +++ b/modules/geoloc.php @@ -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', ''); } - 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); + } } } diff --git a/modules/lists.php b/modules/lists.php index 8b417e0..8c52f23 100644 --- a/modules/lists.php +++ b/modules/lists.php @@ -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'); diff --git a/modules/search.php b/modules/search.php index 1dc226c..7c33bd5 100644 --- a/modules/search.php +++ b/modules/search.php @@ -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); }