[Cartoweb-dev] Extention to the locate plugin

Pierre GIRAUD pierre.giraud at camptocamp.com
Fri Feb 23 04:59:02 EST 2007


Hi Dirk,

I encountered the same problem you did.
I also had to extend the "locate" plugin to get this working on several 
layers.
I will propose a patch fixing this in a slightly different way but 
including some of your ideas.

Thanks for the report and the contribution.

Regards

Pierre

Dirk Jesko wrote:
> Hello,
>
> I had to provide multiple locate entries for the same layer (one for 
> company name, one for ident number and one on type of business). This 
> did not work with the current locate plugin, since the layername is 
> the id. Therefore, I added a new configuration option and changed the 
> ClientLocation.php (changed version and example ini are attached). 
> Maybe, this change is of general interest. However, please be aware 
> that I did not test it completely yet. Please let me know, what you 
> think about it.
>
>
> Regards,
> Dirk
>
>
> ------------------------------------------------------------------------
>
> log =& LoggerManager::getLogger(__CLASS__); } /** * Retrieves list of 
> records * @param string Layer id * @param string feature name * 
> @return array Db result array */ private function getList($layerId, 
> $substr) { $locate = 
> ConfigParser::parseObjectArray($this->getConfig(), 'locate', 
> array('id', 'sql')); foreach($locate as $layer) { if ($layer->id == 
> $layerId) { $sql = $layer->sql; break; } } if (!isset($sql)) return 
> false; $sql = sprintf($sql, $substr); $this->db = 
> Utils::getDb($this->db, $this->getConfig()->dsn); $result = 
> $this->db->getAll($sql); if (DB::isError($result)) 
> die($result->getMessage()); 
> $this->db->setFetchMode(DB_FETCHMODE_ASSOC); return $result; } /** * 
> @see GuiProvider::handleHttpPostRequest() */ public function 
> handleHttpPostRequest($request) {} /** * @see 
> GuiProvider::handleHttpGetRequest() */ public function 
> handleHttpGetRequest($request) { if 
> (isset($request['locate_layer_id']) && $request['locate_layer_id']) { 
> $formRenderer = $this->getCartoclient()->getFormRenderer(); 
> $formRenderer->setCustomForm('locateResults.tpl'); 
> $this->getCartoclient()->setInterruptFlow(true); $result = 
> $this->getList($request['locate_layer_id'], 
> $request['locate_'.$request['locate_layer_id']]); if ($result) { print 
> $this->drawLocateUlLi($result); } else { die(); } } } /** * Draws 
> locate specific template * @return string fetched template */ 
> protected function drawLocate() { $smarty = new 
> Smarty_Plugin($this->getCartoclient(), $this); $locateArray = 
> ConfigParser::parseObjectArray($this->getConfig(), 'locate', 
> array('id', 'label', 'sql', 'layer')); $smarty->assign('locates', 
> $locateArray); return $smarty->fetch('locate.tpl'); } /** * @see 
> GuiProvider::renderForm() */ public function renderForm(Smarty 
> $template) { $template->assign('locate_form', $this->drawLocate()); 
> $template->assign('locate_active', true); } /** * Generates HTML code 
> for dropdown element (autocompleter) * @param array Array of results 
> (key[0] means id, key[1] means title) */ public function 
> drawLocateUlLi($result) { print '
>
>       '; foreach ($result as $resultItem) { $keys =
>     * array_keys($resultItem); printf(' %s
>       ', $resultItem[$keys[0]], $resultItem[$keys[1]],
>       $resultItem[$keys[1]]); } print ' 
>
> '; die(); } } ?>
> ------------------------------------------------------------------------
>
> locate.0.id = cities
> locate.0.layer = cities
> locate.0.label = "Cities"
> locate.0.sql= "SELECT gid, c_name FROM cities WHERE c_name ~* '%s' order by c_name LIMIT 10"
>
> locate.1.id = comp_identnr
> locate.1.layer = comp
> locate.1.label = "Identnr"
> locate.1.sql= "SELECT gid, identnr FROM companies WHERE identnr ~* '^%s' order by identnr LIMIT 10"
>
> locate.2.id = comp_name
> locate.2.layer = comp
> locate.2.label = "Name"
> locate.2.sql= "SELECT gid, comp_name FROM companies WHERE comp_name ~* '%s' order by firma LIMIT 10"
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> Cartoweb-dev mailing list
> Cartoweb-dev at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/cartoweb-dev
>   


-- 
_________________________________________________________
Pierre GIRAUD
Géomaticien, Analyste

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex 

Tel : 00 33 4 79 44 44 93
Mail : pierre.giraud at camptocamp.com
http://www.camptocamp.com  



More information about the Cartoweb-dev mailing list