[mapguide-users] Re: How to do a php report

Jackie Ng jumpinjackie at gmail.com
Mon Jul 5 09:01:56 EDT 2010


Your InvokeUrl command is effectively just passing the string value "GDM_UPI"
to the PHP script. 

What you want to do is have $CurrentSelection as your parameter value. This
is a special value which represents the XML of your selection set.

In your PHP script, you need to process this XML selection set to collect
all the GDM_UPI values to feed to your SQL query. 

Here's a rough code sample that shows how to process the XML selection. This
should go at the beginning of your php code block (after the <?php ). Ignore
the < raw > tags if you're not using Nabble to read this message: 


//Initialize the web tier
$webconfig = "webconfig.ini"; //Path to mapguide's webconfig.ini
MgInitializeWebTier($webconfig);

//Init our connection from our session ID. I believe Invoke URL commands are
always passing the map name (MAPNAME) and session ID (SESSION), so you don't
actually have to specify these parameters.
$conn = new MgSiteConnection();
$userInfo = new MgUserInformation($_REQUEST["SESSION"]);
$conn->Open($userInfo);

//Init our runtime map and our selection set.
$map = new MgMap($conn);
$map->Open($_REQUEST["MAPNAME"]);
$selection = new MgSelection($map, $_REQUEST["SELECTION"]); //assuming
Key=SELECTION, Value=$CurrentSelection in your invokeurl command

//Query the selection set for all GDM_UPI property values from our selected
objects
$pipesLayer = $selection->GetLayers()->GetItem("SuperPipes_AB");
$query = new MgFeatureQueryOptions();
$query->AddFeatureProperty("GDM_UPI");
$queryFilter = $selection->GenerateFilter($pipesLayer,
$pipesLayer->GetFeatureClassName());
$query->SetFilter($queryFilter);

//Execute the query and store all GDM_UPI values in an array
$selReader = $pipesLayer->SelectFeatures($query);
$pipeValues = array();
while($selReader->ReadNext())
{
    //I don't know about your data, but some feature may not even have this
property value
    //so we only add 
    if (!$selReader->IsNull("GDM_UPI"))
    {
        $gdm_upi = stripslashes($selReader->GetString("GDM_UPI"));
//Assuming GDM_UPI is a string property
        array_push($pipeValues, $gdm_upi); 
    }
}
$selReader->Close();

//string together all the collected GDM_UPI values
$pipeList = join("','", $pipeValues);


Then the your actual sql query can change from this:


$sql="SELECT * FROM SuperPipes_AB where GDM_UPI in(" .
stripslashes($_REQUEST["OBJ_KEYS"]) .") order by STATUS "; 


To this:


$sql="SELECT * FROM SuperPipes_AB where GDM_UPI in(" . $pipeList .") order
by STATUS "; 


Please note I wrote this code sample "by hand". There may be some syntatical
errors. Hope this helps.

- Jackie
-- 
View this message in context: http://osgeo-org.1803224.n2.nabble.com/How-to-do-a-php-report-tp5244035p5255973.html
Sent from the MapGuide Users mailing list archive at Nabble.com.


More information about the mapguide-users mailing list