[Chameleon] Custom Query Results

Tracy Howlett thowlett at whistlermuseum.org
Thu May 20 16:26:48 EDT 2004


Here's my bit of code for URLs returned by a local datasource.  This code
also strips out unwanted fields automatically generated by Chameleon from
the query results.  Thanks Paul and Jason for sending me in the right
direction!

// loop and add a cell for each result - modified by Tracy Howlett
foreach ( $aRow as $key => $xCell )
{
	//String comparison to search for fields that should NOT be returned
in query results.
	if (strcasecmp($key, "SHAPE_INDEX") == 0 ||
             strcasecmp($key, "TILE_INDEX") == 0 ||
             strcasecmp($key, "LAYER_INDEX") == 0)
             continue;
             {
	     //Look for strings containing an http header.  If exists then
format as a link, if not format as normal text.
	     if ( stristr ($xCell, 'http://' ))
	 	$szReturnValue .= "<td class=\"subContentArea1\"><p
class=\"text\"><a href='". $xCell."' target='_blank'>Click here for more
information</a></p></td>\n";
	     else
		$szReturnValue .= "<td class=\"subContentArea1\"><p
class=\"text\">". $xCell."</p></td>\n";
	     }
             }
                 $szReturnValue .= "</tr>\n";
             }


-----Original Message-----
From: chameleon-bounces at lists.maptools.org
[mailto:chameleon-bounces at lists.maptools.org] On Behalf Of Jason Fournier
Sent: Monday, May 10, 2004 7:03 AM
To: spencer at dmsolutions.ca
Cc: thowlett at whistlermuseum.org; chameleon at lists.maptools.org
Subject: Re: [Chameleon] Custom Query Results

Hi Tracy,

I have enabled this functionality for MapServer WMS Sources.  If this is 
your primary datasource then the following lines of code shold suffice:

LINE 958 QueryResults.phtml

                    if( stristr( $szValue, 'http://' ) )
                        $szResult .= "<td><p 
class=\"CWCQueryResultsValue\"><a href='".$szValue."' 
target='_blank'>Click here for more information</a></p></td>\n";
                    else
                        $szResult .= "<td><p 
class=\"CWCQueryResultsValue\">".$szValue."</p></td>\n";


If you are using local datasources (eg, shp, OGR-based, etc.) then some 
additional coding will be required.  Essentially you must mimick the WMS 
version of the code.  QueryResults.phtml handles three different 
datasources - local, MapServer WMS, and CubeServ WMS.  Find the 
appropriate loop for printing out Attribute values and replacestrings as 
necessary.  I hope to have this functionality integrated within the 
Query widget for various protocols  in the near future.

Hope this helps,
Jason





Paul Spencer wrote:

> Tracy,
>
> I've cc'd Jason, he's customized the query widget for this kind of 
> thing before.  His approach was to write a function to test a string 
> value and turn it from text into a hyperlink if it started with http://
>
> This function was inserted into the query widget at the point that 
> each attribute is written out so that every linkable field is 
> automagically turned into a hyperlink.
>
> Cheers,
>
> Paul
>
> Tracy Howlett wrote:
>
>> Thanks Paul - that did just the trick.
>>
>> And now for more questions...is there a way to have the query result 
>> contain
>> a URL to a document?  If I include the URL in a field can I have the 
>> display
>> results say 'Click here for more info' instead of actually listing 
>> the URL?
>>
>> Tracy
>>
>> -----Original Message-----
>> From: chameleon-bounces at lists.maptools.org
>> [mailto:chameleon-bounces at lists.maptools.org] On Behalf Of Paul Spencer
>> Sent: Tuesday, April 20, 2004 1:09 PM
>> To: thowlett at whistlermuseum.org
>> Cc: chameleon at lists.maptools.org
>> Subject: Re: [Chameleon] Custom Query Results
>>
>> Tracy,
>>
>> I think that the important part of QueryResults.phtml starts around 
>> line 376 (in my version which is the latest from CVS) and looks like 
>> this:
>>
>> // loop and use key for titles
>>              foreach ($aRows[0] as $key => $value)
>>              {
>>                  $szReturnValue .= "<td class=\"subContentArea2\"><p 
>> class=\"text\">".$key."</p></td>\n";
>>              }
>>              $szReturnValue .= "</tr>\n";
>>
>>              // loop through the results and format each row
>>              foreach ( $aRows as $aRow )
>>              {
>>                  // add a row for each
>>                  $szReturnValue .= "<tr>\n";
>>
>>                  // loop and add a cell for each result
>>                  foreach ( $aRow as $xCell )
>>                  {
>>                      $szReturnValue .= "<td 
>> class=\"subContentArea1\"><p class=\"text\">". $xCell."</p></td>\n";
>>                  }
>>
>>                  $szReturnValue .= "</tr>\n";
>>              }
>>
>> I think you want to put something like this:
>>
>>              // loop and use key for titles
>>              foreach ($aRows[0] as $key => $value)
>>              {
>>                  if (strcasecmp($key, "SHAPE_INDEX") == 0 ||
>>                      strcasecmp($key, "TILE_INDEX") == 0 ||
>>                      strcasecmp($key, "LAYER_INDEX") == 0)
>>                      continue;
>>                  $szReturnValue .= "<td class=\"subContentArea2\"><p 
>> class=\"text\">".$key."</p></td>\n";
>>              }
>>              $szReturnValue .= "</tr>\n";
>>
>>              // loop through the results and format each row
>>              foreach ( $aRows as $aRow )
>>              {
>>                  // add a row for each
>>                  $szReturnValue .= "<tr>\n";
>>
>>                  // loop and add a cell for each result
>>                  foreach ( $aRow as $key => $xCell )
>>                  {
>>                      if (strcasecmp($key, "SHAPE_INDEX") == 0 ||
>>                          strcasecmp($key, "TILE_INDEX") == 0 ||
>>                          strcasecmp($key, "LAYER_INDEX") == 0)
>>                          continue;
>>                      $szReturnValue .= "<td 
>> class=\"subContentArea1\"><p class=\"text\">". $xCell."</p></td>\n";
>>                  }
>>
>>                  $szReturnValue .= "</tr>\n";
>>              }
>>
>> I just tried this and it seems to work.
>>
>> Alternately you could invert the logic and restrict the query results 
>> to exactly what you do want ...
>>
>>              // loop and use key for titles
>>              foreach ($aRows[0] as $key => $value)FID; Shape; Name; 
>> Detail
>>              {
>>                  if (strcasecmp($key, "FID") != 0 ||
>>                      strcasecmp($key, "Shape") != 0 ||
>>                      strcasecmp($key, "Name") != 0 ||
>>                      strcasecmp($key, "Detail") != 0)
>>                  {
>>                      $szReturnValue .= "<td 
>> class=\"subContentArea2\"><p class=\"text\">".$key."</p></td>\n";
>>                  }
>>              }
>>              $szReturnValue .= "</tr>\n";
>>
>>              // loop through the results and format each row
>>              foreach ( $aRows as $aRow )
>>              {
>>                  // add a row for each
>>                  $szReturnValue .= "<tr>\n";
>>
>>                  // loop and add a cell for each result
>>                  foreach ( $aRow as $key => $xCell )
>>                  {
>>                      if (strcasecmp($key, "FID") != 0 ||
>>                          strcasecmp($key, "Shape") != 0 ||
>>                          strcasecmp($key, "Name") != 0 ||
>>                          strcasecmp($key, "Detail") != 0)
>>                      {
>>                          $szReturnValue .= "<td 
>> class=\"subContentArea1\"><p class=\"text\">". $xCell."</p></td>\n";
>>                      }
>>                  }
>>
>>                  $szReturnValue .= "</tr>\n";
>>              }
>>
>> Cheers,
>>
>> Paul
>>
>> Tracy Howlett wrote:
>>
>>
>>>> Pardon the duplicate post - just wanted to make sure the subject 
>>>> heading
>>>
>>>
>>> wasn't misleading!
>>>
>>> Hello All,
>>> My application is pretty much finished now but I do have a couple of
>>
>>
>> tweaks
>>
>>> I'd like to get done.
>>>
>>> My query tool works well but in my query results I always get these 
>>> three
>>> additional fields:
>>>
>>> SHAPE_INDEX; TILE_INDEX; LAYER_INDEX
>>>
>>> I'd like to suppress this information as it means nothing to the 
>>> user.  In
>>> order to try and streamline my query results all of my shapefiles 
>>> contain
>>> only the following fields:
>>>
>>> FID; Shape; Name; Detail
>>>
>>> I've dug around and I think that the table is being written out in the
>>> QueryResults.phtml file.  I see a number of arrays in there which I 
>>> assume
>>> are populated with my layers and the fields for each layer.  Could 
>>> someone
>>> give me some hint as to how I can tell the array to ignore the above 
>>> named
>>> fields???  The part I can't figure out is how the names of the 
>>> fields are
>>> being changed from FID in my shapefile to SHAPE_INDEX in the 
>>> results.  Is
>>> there a file I'm missing which includes this name switch?
>>>
>>> Any help would be appreciated.  I'm guessing that I'm not the only 
>>> person
>>> who'd like to have these ID fields be invisible!
>>>
>>> Cheers!
>>>
>>> Tracy
>>>
>>>
>>> _______________________________________________
>>> Chameleon mailing list
>>> Chameleon at lists.maptools.org
>>> http://lists.maptools.org/mailman/listinfo/chameleon
>>>
>>>
>>> _______________________________________________
>>> Chameleon mailing list
>>> Chameleon at lists.maptools.org
>>> http://lists.maptools.org/mailman/listinfo/chameleon
>>>
>>
>>
>

-- 
________________________
Jason Fournier
Application Developer
DM Solutions Group Inc.
jfournier at dmsolutions.ca
www.dmsolutions.ca
613.565.5056 x18


_______________________________________________
Chameleon mailing list
Chameleon at lists.maptools.org
http://lists.maptools.org/mailman/listinfo/chameleon




More information about the Chameleon mailing list