Source for file PGSQLMapContextConfig.php
Documentation is available at PGSQLMapContextConfig.php
* Get configuration from database using the "MapContext" way of defining it.
* @copyright 2010, Nippour Geomatik
* @license http://www.geoprisma.org/license BSD License
* @link http://www.geoprisma.org
* Get configuration from database using the "MapContext" way of defining it.
* @var org_geoprisma_config_PGSQLMapContextConfig
private static $s_objInstance =
null;
* @var boolean Whether the driver should create (MapPanel and Layer) OR
* (Map and MapFishLayerTree) widgets
private static $s_bUseLegacyWidgets =
false;
private static $s_strConnection =
null;
private static $s_iCurrentSession = -
1;
private static $s_iCurrentMapContext = -
1;
private static $s_iCurrentApplication = -
1;
private static $s_strCurrentSessionName =
"";
private static $s_strCurrentMapContextName =
"";
private static $s_strCurrentApplicationName =
"";
private static $s_strServiceFeature =
"service";
private static $s_strDataStoreFeature =
"datastore";
private static $s_strResourceFeature =
"resource";
private static $s_strFieldFeature =
"field";
private static $s_strMapContextFeature =
"mapcontext";
private static $s_strWidgetFeature =
"widget";
private static $s_strAccessFilterFeature =
"accessfilter";
private static $s_strApplicationFeature =
"application";
private static $s_strSessionFeature =
"session";
private static $s_strTablePrefix =
"mcconfig_";
private static $s_strTableOptionSuffix =
"option";
* Only used if isUsingLegacyWidgets() != true
"visibility" =>
"visibility",
"maxscaledenom" =>
"minscale",
"minscaledenom" =>
"maxscale"
1 =>
org_geoprisma_service_WMSService::TYPE,
2 =>
org_geoprisma_service_TileCacheService::TYPE,
3 =>
org_geoprisma_service_FeatureServerService::TYPE,
4 =>
org_geoprisma_service_GYMOService::TYPE,
5 =>
org_geoprisma_service_WidgetService::TYPE,
6 =>
org_geoprisma_service_MapServerService::TYPE,
7 =>
org_geoprisma_service_MapFishPrintService::TYPE,
8 =>
org_geoprisma_service_FileService::TYPE,
9 =>
org_geoprisma_service_WFSService::TYPE,
10 =>
org_geoprisma_service_HttpRequestService::TYPE,
11 =>
org_geoprisma_service_WPSService::TYPE,
12 =>
org_geoprisma_service_TMSService::TYPE
14 =>
"getmouseposition",
16 =>
"editfeature_create",
17 =>
"editfeature_update",
18 =>
"editfeature_delete",
19 =>
"featurepanel_form",
20 =>
"featurepanel_selector",
26 =>
"geoextux_geonamessearchcombo",
27 =>
"geoextux_redliningpanel",
30 =>
"geoextux_shortcutcombo",
36 =>
"geoextux_layertreebuilder",
40 =>
"featurepanel_attributeform",
41 =>
"featurepanel_customform",
42 =>
"geoextux_wmsbrowser",
44 =>
"resultvectorlayer",
45 =>
"queryonclickwizard",
46 =>
"geoextux_printpreview",
47 =>
"wfsfilterbuilder",
50 =>
"editfeature_split",
51 =>
"editfeature_drag",
52 =>
"editfeature_copy",
53 =>
"editfeature_confirm",
54 =>
"keepactivesession",
// for user-defined widgets, use numbers grater than 9999 ??
10666 =>
"multiprojectionmouseposition"
* Construct a new instance of org_geoprisma_config_PGSQLMapContextConfig.
* Force the use of 'getInstance' (Singleton)
* @throws org_geoprisma_exception_BadPGSQLMapContextConfig
* @return org_geoprisma_config_PGSQLMapContextConfig
private function __construct()
* Connect to database using connection string.
throw
new Exception("Unable to connect to the database");
* Disconnect from database.
* Get config from database.
protected function load()
// First, check if there is/are 'osmresource' parameter(s) in the
// url, meaning a specific list of Resources accessed
if (count($objArrayResourceNames) >
0)
$objArrayResourceNames, array('loadFields' =>
false)
// Else, that means we load the whole config. Check if we load from
// it from a Session id (not PHP Session, but GeoPrisma session)
else if (self::getCurrentSession() != -
1
||
self::getCurrentSessionName() !=
""
// Else, check if we load from MapContext + Application combinaison
else if ((self::getCurrentMapContext() != -
1 ||
self::getCurrentMapContextName() !=
"")
&&
(self::getCurrentApplication() != -
1 ||
self::getCurrentApplicationName() !=
"")
// well, there is nothing to load from...
exit("no session OR mapcontext+application defined");
//print_r($this->getAuthorizedResources());
catch
(Exception $objError)
* Using current 'Session' id or name, get the according 'MapContext' and
* 'Application' ids and load them.
if (self::getCurrentSession() != -
1)
$objArrayOptions =
array(
'singleRecord' =>
self::getCurrentSession()
$objArrayOptions =
array(
'singleRecordName' =>
self::getCurrentSessionName()
if (self::getCurrentSession() == -
1)
self::setCurrentSession($objSession['id']);
self::setCurrentMapContext(
self::setCurrentApplication(
* Using current 'MapContext' id, load :
* Resources, DataStores, Services, Fields and MapWidget.
// get mapcontext with resource ids
$objArrayOptions =
array(
'foreignFeature' =>
$strForeignFeature,
if (self::getCurrentMapContext() != -
1)
$objArrayOptions['singleRecord'] =
self::getCurrentMapContext();
$objArrayOptions['singleRecordName']
=
self::getCurrentMapContextName();
if (self::getCurrentMapContext() == -
1)
self::setCurrentMapContext($objMapContext['id']);
// get resource ids array
array($objMapContext), $strForeignFeature
// load service, datastore, fields and resources from resource ids list
// load layout and widgets
// load map widget from mapcontext
// load mappanel and layer widgets from mapcontext
* Using a resource ids array, load : Resources, DataStores, Services and
* @param array $pobjArrayResourceIds A resource id list
* @param array $pobjArrayOptions Options for this method.
$pobjArrayOptions =
array('loadFields' =>
true, 'otherResources' =>
false)
$bLoadFields =
$pobjArrayOptions['loadFields'];
if (isset
($pobjArrayOptions['otherResources']))
$bOtherResources =
$pobjArrayOptions['otherResources'];
$bOtherResources =
false;
// get resources with datastore ids
$objArrayOptions =
array(
'specificRecords' =>
$pobjArrayResourceIds,
'foreignFeatures' =>
$objArrayForeignFeatures,
if (self::getCurrentMapContext() != -
1)
$objArrayOptions['orderingTable']
$objArrayOptions['orderingMasterFeatureId']
=
self::getCurrentMapContext();
$objArrayOptions['foreignOrdering'] =
array(
// get datastore ids array
$objArrayResources, $objArrayForeignFeatures[0]
$objArrayResources, $objArrayForeignFeatures[2]
$objArrayOptions =
array(
'specificRecords' =>
$objArrayFieldIds,
$objArrayOptions =
array(
'specificRecords' =>
$objArrayDatastoreIds,
$objArrayDataStores, $strForeignFeature
$objArrayOptions =
array(
'specificRecords' =>
$objArrayServiceIds,
$objArrayResources, $objArrayForeignFeatures[1]
$objArrayOptions =
array(
'specificRecords' =>
$objArrayAccessFilterIds,
$this->loadDatastores($objArrayDataStores);
$this->loadAccessFilters($objArrayAccessFilters);
$this->loadFields($objArrayFields);
Array('otherResources' =>
$bOtherResources)
* Using current 'Application' id, load : Layout and Widgets
// get application with widget ids
$objArrayOptions =
array(
'foreignFeature' =>
$strForeignFeature
if (self::getCurrentApplication() != -
1)
$objArrayOptions['singleRecord'] =
self::getCurrentApplication();
$objArrayOptions['singleRecordName']
=
self::getCurrentApplicationName();
if (self::getCurrentApplication() == -
1)
self::setCurrentApplication($objApplication['id']);
array($objApplication), $strForeignFeature
$objArrayOptions =
array(
'specificRecords' =>
$objArrayWidgetIds,
if (self::getCurrentApplication() != -
1)
$objArrayOptions['orderingTable']
$objArrayOptions['orderingMasterFeatureId']
=
self::getCurrentApplication();
* Load all 'org_geoprisma_service_Service' object inside the service array
* @param array $pobjArrayServices Array of service records
foreach ($pobjArrayServices as $objService)
* Load the 'org_geoprisma_layout_Layout' object using the application
* @param array $pobjApplication A single application record.
(string)
$pobjApplication['id'],
(string)
$pobjApplication['template'],
* Load all 'org_geoprisma_datastore_Datastore' objects inside the datastore
* array using datastore records.
* @param array $pobjArrayDatastores Array of datastore records
private function loadDatastores($pobjArrayDatastores)
foreach ($pobjArrayDatastores as $objDatastore)
* Load all 'org_geoprisma_accessfilter_AccessFilter' objects inside the accessfilter
* array using accessfilter records.
* @param array $pobjArrayAccessFilters Array of accessfilter records
private function loadAccessFilters($pobjArrayAccessFilters)
foreach ($pobjArrayAccessFilters as $objAccessFilter)
$objArrayConditions =
array();
foreach ($objAccessFilter['options'] as $strName =>
$strValue)
if ($strName ==
'condition')
$objArrayConditions[] =
$strValue;
* Load all 'org_geoprisma_field_Field' objects inside the field array using
* @param array $pobjArrayFields Array of field records
private function loadFields($pobjArrayFields)
foreach ($pobjArrayFields as $objField)
$objArrayOption =
new ArrayObject();
// field title (with i18n support)
if ($objField['key'] !=
'' &&
$objField['domain'] !=
'')
'key' =>
$objField['key'],
'domain' =>
$objField['domain']
$strTitle = (string)
$objField['title'];
* Load all 'org_geoprisma_widget_Widget' objects inside the widget
* array using widget records.
* @param array $pobjArrayWidgets Array of widget records
foreach ($pobjArrayWidgets as $objWidgetRecord)
=
$objWidget->getMandatoryResourceOptionList();
// if widget doesn't need to be linked to any resource, add it.
if ($objArrayResourceOptions ===
null)
// the name 'linkResource' becomes irrevelant here, but the
// purpose of this method should remain the same (call before
// each widget added and do custom stuff with or without a
// resource)... If the method returns
if ($objWidget->linkResource(null, $this) !==
false)
// add widget to config only
=
$objWidget->resourceHasRequiredWidgetOptions(
// if resource has all required options used by the widget
// and user is authorized to access the resource, add the
// the widget and add the resource to it.
// if widget and resource has a 1:1 relation, then it
if ($objWidget->mustClone())
$objWidgetClone =
clone $objWidget;
$strOriginalName =
$objWidgetClone->getName();
$strCloneName =
$strOriginalName.
'_'.
uniqid();
$strOriginalName, $strCloneName
$objWidgetClone->setName($strCloneName);
$objArrayWidgetResourceOptions
=
$objWidgetClone->getOptionsFromResource(
foreach ($objArrayWidgetResourceOptions
$objWidgetClone->addOrReplaceOption(
// if clone linked, then add widget to resource and
// add it to widget array
if ($objWidgetClone->linkResource($objResource, $this) !==
false)
$objResource->addWidget($objWidgetClone);
// the widget has a 1:x relation with resources, so
// we simply need to link
// if linked, then add widget to resource
if ($objWidget->linkResource($objResource, $this) !==
false)
$objResource->addWidget($objWidget);
} // end of foreach resources
} // end of foreach widgets
* Add a new clone name in the 'clone' array using the original name as
* @param string $pstrOriginalName The original name
* @param string $pstrCloneName The name of the clone
protected function addCloneName($pstrOriginalName, $pstrCloneName)
* This config driver sometimes clones widget and change their name. The
* names that appears in some widgets have to be changed accordingly.
* This is done using the 'getCloneNames' method.
// key : widgettype that can contain reference to cloned widgets
// value : the node name to check
$objArrayWidgetsToCheck =
array(
"geoexttoolbar" =>
"widget",
"queryonclick" =>
"featurepanel"
$strType =
$objWidget->getType();
if (!isset
($objArrayWidgetsToCheck[$strType]))
$strSingleNodeName =
$objArrayWidgetsToCheck[$strType];
$strMultipleNodeName =
$strSingleNodeName.
"s";
$objOption =
$objWidget->getOption($strSingleNodeName);
if ($objArrayClonedNames !==
false)
if (count($objArrayClonedNames) ==
1)
$objOption->setValue($objArrayClonedNames[0]);
$objOption->setValue($objArrayClonedNames);
$objOption->setName($objOption->getName().
's');
catch
(Exception $objError)
$objArrayNewValues =
array();
$objOption =
$objWidget->getOption($strMultipleNodeName);
$objArrayWidgetNames =
$objOption->getValue();
foreach ($objArrayWidgetNames as $strWidgetName)
if ($objArrayClonedNames !==
false)
$objArrayNewValues, $objArrayClonedNames
$objOption->setValue($objArrayNewValues);
catch
(Exception $objError) {
// no option was found, so carry on...
* Load all 'org_geoprisma_resource_Resource' objects inside the resource
* array using resource records. Since widgets are no longer directly
* attached to resources, they are loaded separately.
* @param array $pobjArrayResources Array of resource records
* @param array $pobjArrayOptions Array of options for this method
$pobjArrayOptions =
array('otherResources' =>
false)
$bOtherResources =
$pobjArrayOptions['otherResources'];
$objArrayDestResource =
'm_objArrayOtherResource';
$objArrayDestResource =
'm_objArrayResource';
foreach ($pobjArrayResources as $objResource)
$strName = (string)
$objResource['id'];
$strACLName = (string)
$objResource['acl_name'];
// resource title (with i18n support)
if ($objResource['key'] !=
'' &&
$objResource['domain'] !=
'')
'key' =>
$objResource['key'],
'domain' =>
$objResource['domain']
$strTitle = (string)
$objResource['name'];
$objArrayDatastore =
new ArrayObject();
$objArrayField =
new ArrayObject();
$objArrayWidget =
new ArrayObject();
$objArrayAccessFilter =
new ArrayObject();
$objArrayOption =
new ArrayObject();
$objArrayDatastore[$strDatastore]
$objArrayField[$strField]
foreach ($objResource['options']
as $strOptionName =>
$strOptionValue)
$strOptionName, $strOptionValue
$objArrayAccessFilter[$strAccessFilter]
$this->$objArrayDestResource->append(
* Load all 'org_geoprisma_resource_Resource' objects inside the other resource array.
$objArrayOptions =
array(
//'specificRecords' => $pobjArrayResourceIds,
'foreignFeatures' =>
$objArrayForeignFeatures,
$objArrayOtherResourceIds =
Array();
//créer un array d'id qui sera charger par la fontion loadFromResourceList.
foreach ($objArrayOtherResources as $objOtherResource)
$objArrayOtherResourceIds[] =
$objOtherResource['id'];
$pobjArrayOptions =
array('loadFields' =>
true, 'otherResources' =>
true);
$iSavedMapContext =
self::getCurrentMapContext();
self::setCurrentMapContext(-
1);
$objArrayOtherResourceIds,
self::getCurrentMapContext($iSavedMapContext);
* Create the 'mappanel' widget and append it to widget array using the
* Only used if isUsingLegacyWidgets() != true
* @param array $pobjMapContext The MapContext record.
$objArrayMapPanel =
array(
'name' =>
$pobjMapContext['name'],
'options' =>
$pobjMapContext['options']
// add mappanel widget as first element of the widget array
array('mappanel'=>
$objMapPanelWidget) +
* For each resource, create 'layer' widgets according to the datastores
* they have, link them to and append them to widget array.
* Only used if isUsingLegacyWidgets() != true
$objArrayLayers =
array();
foreach ($objArrayResources as $objResource)
$objArrayResourceOptions =
$objResource->getOptions();
$objArrayDataStores =
$objResource->getDatastores();
$strResourceName =
$objResource->getName();
foreach ($objArrayDataStores as $objDataStore)
$objService =
$objDataStore->getService();
$strServiceType =
$objService->getType();
$strServiceName =
$objService->getName();
$strDataStoreName =
$objDataStore->getName();
switch ($strServiceType) {
=
$objResource->getDatastoreByServiceType(
=
$objResource->getDatastoreByServiceType(
// add WMS layer if there is no tilecache or tms
$bAddLayer =
($objTileCacheDS ||
$objTMSDS)
// TileCache, GYMO and TMS
// always add tilecache, gymo and tms layers
// if there is at least one widget requiring to interact
// with a vector layer OR the resource only has one
// datastore, add a 'featureserver' or 'wfs' layer
=
$objResource->hasWidgetUsingServiceType(
if ($bLayerNeededByWidgets
||
$objResource->getDatastores()->count() ==
1
(array)
$objArrayResourceOptions,
$objService->getDefaultLayerOptions($this),
array('servicetype' =>
$strServiceType)
$strLayerId =
"layer_S".
$strServiceName.
"_DS".
$strDataStoreName.
"_R".
$strResourceName;
'options' =>
$objArrayLayerOptions
$objArrayLayers[$strLayerId] =
$objLayerWidget;
$objResource->addWidget($objLayerWidget);
// add all created layer widgets to the widget array
// add mappanel widget as first element of the widget array
* Load 'org_geoprisma_widget_MapWidget' object and append to widget
* array using MapContext record.
* @param array $pobjMapContext The MapContext record.
$objArrayLayers =
array();
$objArrayWMSServiceLayerKeys =
array();
foreach ($objArrayResources as $objResource)
$objArrayResourceOptions =
$objResource->getOptions();
$objArrayDataStores =
$objResource->getDatastores();
$strResourceName =
$objResource->getName();
foreach ($objArrayDataStores as $objDataStore)
$objService =
$objDataStore->getService();
$strServiceType =
$objService->getType();
$strServiceName =
$objService->getName();
(array)
$objArrayResourceOptions,
switch ($strServiceType) {
=
$objResource->getDatastoreByServiceType(
// if resource has tilecache datastore, don't add a
// wms layer. Remove the node from the layertree as
if ($objMapFishLayerTree)
$objMapFishLayerTree->removeLeaf(
$objMapFishLayerTree->getNodes(),
// check if a layer object with the same service name
// has already been created. If not, create a new layer
// and keep the layer+servicename link using an array.
if (!isset
($objArrayWMSServiceLayerKeys[$strServiceName]))
$strLayerName =
"L_".
$strServiceType.
"_R_".
$strResourceName;
$objService->getDefaultLayerOptions($this),
array('layername' =>
$strLayerName)
'resourcenames' =>
array($strResourceName),
'servicetype' =>
$strServiceType,
'options' =>
$objArrayLayerOptions
// keep the layer+service name link
$objArrayWMSServiceLayerKeys[$strServiceName]
=
count($objArrayLayers) -
1;
array_push($objArrayLayers[$objArrayWMSServiceLayerKeys[$strServiceName]]['resourcenames'], $strResourceName);
$objArrayLayers[$objArrayWMSServiceLayerKeys[$strServiceName]]['options']['layername'] .=
"_".
$strResourceName;
$strLayerName =
"L_".
$strServiceType.
"_R_".
$strResourceName;
$objService->getDefaultLayerOptions($this),
array('layername' =>
$strLayerName)
'resourcenames' =>
array($strResourceName),
'servicetype' =>
$strServiceType,
'options' =>
$objArrayLayerOptions
// if there are no widgets requiring direct
// interaction AND there and resource has more than
// one datastore, don't add a 'featureserver' or 'wfs'
=
$objResource->hasWidgetUsingServiceType(
if ($bLayerNeededByWidgets
||
$objResource->getDatastores()->count() ==
1
$strLayerName =
"L_".
$strServiceType.
"_R_".
$strResourceName;
$objService->getDefaultLayerOptions($this),
array('layername' =>
$strLayerName)
'resourcenames' =>
array($strResourceName),
'servicetype' =>
$strServiceType,
'options' =>
$objArrayLayerOptions
// if the layer is not added, we need to make sure
// the according layertree node is removed as well
if ($objMapFishLayerTree)
$objMapFishLayerTree->removeLeaf(
$objMapFishLayerTree->getNodes(),
$strLayerName =
"L_".
$strServiceType.
"_R_".
$strResourceName;
$objService->getDefaultLayerOptions($this),
array('layername' =>
$strLayerName)
'resourcenames' =>
array($strResourceName),
'servicetype' =>
$strServiceType,
'options' =>
$objArrayLayerOptions
// create map with layers
'name' =>
$pobjMapContext['name'],
'options' =>
$pobjMapContext['options'],
'layers' =>
$objArrayLayers
// ==========================================================
// getRecords method and utilities (connecting to database)
// ==========================================================
* Get records from specific table.
* @param sring $pstrFeature Name of the feature we need to get
* @param array $pobjArrayOptions Array of options used to fetch more
* elements inside the records
protected function getRecords ( $pstrFeature, $pobjArrayOptions=
array() )
// when set to true, get the records options as well
$bGetOptions = isset
($pobjArrayOptions['getOptions'])
?
$pobjArrayOptions['getOptions'] :
null;
// merge record options to the record properties OR create a separate
// 'options' array to put them there
$bMergeOptions = isset
($pobjArrayOptions['mergeOptions'])
?
$pobjArrayOptions['mergeOptions'] :
null;
// when set, get foreign records as well in defined foreignFeatures
$objArrayForeignFeatures = isset
($pobjArrayOptions['foreignFeatures'])
?
$pobjArrayOptions['foreignFeatures'] :
array();
// when set, get foreign records as well in defined foreignFeature
if (isset
($pobjArrayOptions['foreignFeature']))
$objArrayForeignFeatures,
$pobjArrayOptions['foreignFeature']
// if set, get a single record using a specific id. Not compatible
// with 'singleRecordName' nor 'specificRecords'.
$iSingleRecord = isset
($pobjArrayOptions['singleRecord'])
?
$pobjArrayOptions['singleRecord'] :
null;
// if set, get a single record using a specific name. Not compatible
// with 'singleRecord' nor 'specificRecords'.
$strSingleRecordName = isset
($pobjArrayOptions['singleRecordName'])
?
$pobjArrayOptions['singleRecordName'] :
null;
// if set, get records from the specified list of ids. Not compatible
// with 'singleRecordName' nor 'singleRecord'.
$objArraySpecificRecords = isset
($pobjArrayOptions['specificRecords'])
?
$pobjArrayOptions['specificRecords'] :
null;
// the name of the table related to the feature
// the name of the ordering table to use to order the features
$strOrderMasterFeature =
null;
if (isset
($pobjArrayOptions['orderingTable']))
$pobjArrayOptions['orderingTable'],
$strOrderMasterFeature =
$pobjArrayOptions['orderingTable'];
// the id of the 'master' feature used when ordering. Is not mandatory
// for all kinds of features.
if (isset
($pobjArrayOptions['orderingMasterFeatureId']))
$iOrderMasterId =
$pobjArrayOptions['orderingMasterFeatureId'];
// when set to 'true', order the options by 'order'
$bOptionOrdering = isset
($pobjArrayOptions['optionOrdering'])
?
$pobjArrayOptions['optionOrdering'] :
null;
// when set to 'true', foreign requests are going to be ordered by
$objArrayForeignOrdering = isset
($pobjArrayOptions['foreignOrdering'])
?
$pobjArrayOptions['foreignOrdering'] :
array();
$strSQL =
'SELECT '.
$strTable.
'.* ';
$strSQL .=
($strOrderTable) ?
", ".
$strOrderTable.
".order " :
"";
$strSQL .=
'FROM '.
$strTable;
$strSQL .=
($strOrderTable) ?
", ".
$strOrderTable :
"";
$strSQL .=
" WHERE ".
$strTable.
".id='".
$iSingleRecord.
"'";
else if ($objArraySpecificRecords)
$objArrayWhere =
array();
for ($iIter=
0, $iLen=
count($objArraySpecificRecords); $iIter<
$iLen; $iIter++
)
$objArrayWhere[$iIter] =
$strTable.
".id='".
$objArraySpecificRecords[$iIter].
"'";
$strSQL .=
" WHERE ( ".
implode(" OR ", $objArrayWhere).
" ) ";
else if ($strSingleRecordName)
$strSQL .=
" WHERE ".
$strTable.
".name='".
$strSingleRecordName.
"'";
$strSQL .=
($bWhere) ?
" AND " :
" WHERE ";
$strSQL .=
$strOrderTable.
'.'.
$pstrFeature.
'_id = '.
$strSQL .=
" AND ".
$strOrderTable.
'.'.
$strOrderMasterFeature.
'_id = '.
$iOrderMasterId;
$strSQL .=
($strOrderTable) ?
' ORDER BY "order"' :
"";
$objArrayRecords =
array();
$objResult =
pg_query($this->m_objDB, $strSQL);
$objArrayRecords[$objArrayRow['id']] =
$objArrayRow;
if ($bGetOptions &&
!$bMergeOptions)
$objArrayRecords[$objArrayRow['id']]['options'] =
array();
// at least one record is required if asking for a specific one(s)
if (count($objArrayRecords) ==
0
&&
($iSingleRecord ||
$objArraySpecificRecords ||
$strSingleRecordName)
$strMessage =
"Failed to fetch the specific \"$pstrFeature\" record(s)";
throw
new Exception($strMessage);
// if we were using the 'single record name' method, keep track of
if ($strSingleRecordName)
$objArrayRecord =
end($objArrayRecords);
$iSingleRecord =
$objArrayRecord['id'];
// get options (optional) START
"SELECT $strOptionTable.* FROM $strTable, $strOptionTable"
'WHERE '.
$strOptionTable.
'.'.
$pstrFeature.
'_id ='
$strSQL =
implode(" ", $objArraySQL);
$strSQL .=
" AND ".
$pstrFeature.
"_id='".
$iSingleRecord.
"'";
else if ($objArraySpecificRecords)
$objArrayWhere =
array();
for ($iIter=
0, $iLen=
count($objArraySpecificRecords); $iIter<
$iLen; $iIter++
)
$objArrayWhere[$iIter] =
$pstrFeature.
"_id='".
$objArraySpecificRecords[$iIter].
"'";
$strSQL .=
" AND ( ".
implode(" OR ", $objArrayWhere).
" )";
$strSQL .=
'ORDER BY '.
$strOptionTable.
'."order"';
$objArrayOptions =
array();
$objResult =
pg_query($this->m_objDB, $strSQL);
$objArrayRow['options'] =
array();
$iNumRec =
count($objArrayOptions);
for ($iIter=
0; $iIter<
$iNumRec; $iIter++
)
// if option has 'domain' and 'key' properties set, then
// create the option value from these values
if (isset
($objArrayOptions[$iIter]['domain'])
&& isset
($objArrayOptions[$iIter]['key'])
&&
$objArrayOptions[$iIter]['domain'] !=
""
&&
$objArrayOptions[$iIter]['key'] !=
""
'domain' =>
$objArrayOptions[$iIter]['domain'],
'key' =>
$objArrayOptions[$iIter]['key']
$objArrayValue =
$objArrayOptions[$iIter]['value'];
$strOptionName =
$objArrayOptions[$iIter]['name'];
$objArrayRecords[$objArrayOptions[$iIter][$pstrFeature.
'_id']]['options'],
$objArrayRecords[$objArrayOptions[$iIter][$pstrFeature.
'_id']],
// get options (optional) END
// get associated records from all foreign tables
foreach ($objArrayForeignFeatures as $strForeignFeature)
array_push($objArraySQL, "SELECT $strAssociatedTable.*");
array_push($objArraySQL, "FROM $strTable, $strAssociatedTable");
'WHERE '.
$strAssociatedTable.
'.'.
$pstrFeature.
'_id = '
" AND ".
$pstrFeature.
"_id='".
$iSingleRecord.
"'"
else if ($objArraySpecificRecords)
$objArrayWhere =
array();
$iLen =
count($objArraySpecificRecords);
for ($iIter=
0; $iIter<
$iLen; $iIter++
)
$objArrayWhere[$iIter] =
$pstrFeature.
"_id='".
$objArraySpecificRecords[$iIter].
"'";
" AND ( ".
implode(" OR ", $objArrayWhere).
" )"
if (in_array($strForeignFeature, $objArrayForeignOrdering))
'ORDER BY '.
$strAssociatedTable.
'."order"'
$strSQL =
implode(" ", $objArraySQL);
$objArrayAssociatedRecords =
array();
$objResult =
pg_query($this->m_objDB, $strSQL);
array_push($objArrayAssociatedRecords, $objArrayRow);
$iNumRec =
count($objArrayAssociatedRecords);
for ($iIter=
0; $iIter<
$iNumRec; $iIter++
)
if (!isset
($objArrayRecords[$objArrayAssociatedRecords[$iIter][$pstrFeature.
'_id']][$strForeignFeature]))
$objArrayRecords[$objArrayAssociatedRecords[$iIter][$pstrFeature.
'_id']][$strForeignFeature] =
array();
array_push($objArrayRecords[$objArrayAssociatedRecords[$iIter][$pstrFeature.
'_id']][$strForeignFeature], $objArrayAssociatedRecords[$iIter][$strForeignFeature.
'_id']);
$strMessage =
"An unknown error occured while querying the DB.";
throw
new Exception($strMessage);
* Set a new property to an array. If the property already exists, create
* a 'parent' property with the same name + an 's' at the end and push
* the values into it. If the 'parent' array already exists, simply push
* @param array &$pobjArrayOptions Array of options
* @param string $pstrName The name of the option to set
* @param object $pobjValue The value of the new option to set
array &$pobjArrayOptions, $pstrName, $pobjValue
$strParent =
$pstrName.
"s";
if (isset
($pobjArrayOptions[$strParent]))
array_push($pobjArrayOptions[$strParent], $pobjValue);
// if option was already set, create the
// 'parent' array and unset old option
if (isset
($pobjArrayOptions[$pstrName]))
$objArrayOption =
array();
// push old value and unset it
array_push($objArrayOption, $pobjArrayOptions[$pstrName]);
unset
($pobjArrayOptions[$pstrName]);
array_push($objArrayOption, $pobjValue);
// set new 'parent' array option
$pobjArrayOptions[$strParent] =
$objArrayOption;
$pobjArrayOptions[$pstrName] =
$pobjValue;
// -------------------------------
// org_geoprisma objects getters
// -------------------------------
* Retourne un object service
* @param string $pstrServiceName Service Name
* @return org_geoprisma_service_Service
com_borealis_foundation_util_Assert::assertIsNotEmptyString($pstrServiceName);
if ($objService->getName() ==
$pstrServiceName)
// we may be asking for a service that doesn't need to be linked to
// datastores and resources, so try to get it manually. We need to
// reconnect to the database first. If the service is not found at
// this point, then the 'getRecords' method will throw the according
// error so no need to do that here.
array('singleRecord' =>
$pstrServiceName)
$strType, $objServiceRecord
* Retourne la liste de service disponible service
* @return ArrayObject of org_geoprisma_service_Service
* Retourne un object layout
* @param string $pstrLayoutName Layout name
* @return org_geoprisma_layout_Layout
com_borealis_foundation_util_Assert::assertIsNotEmptyString($pstrLayoutName);
if ($objLayout->getName() ==
$pstrLayoutName)
* Retourne la liste des layouts disponible
* @return ArrayObject of org_geoprisma_layout_Layout
* Retourne un object datastore
* @param string $pstrDatastoreName Datastore name
* @return org_geoprisma_datastore_Datastore
com_borealis_foundation_util_Assert::assertIsNotEmptyString($pstrDatastoreName);
if ($objDatastore->getName() ==
$pstrDatastoreName)
* Retourne la liste des datastores disponible
* @return ArrayObject of org_geoprisma_datastore_Datastore
* Retourne un object widget
* @param string $pstrWidgetName Widget name
* @return org_geoprisma_widget_Widget
com_borealis_foundation_util_Assert::assertIsNotEmptyString($pstrWidgetName);
if ($objWidget->getName() ==
$pstrWidgetName)
* Retourne la liste des widget disponible
* @return ArrayObject of org_geoprisma_widget_Widget
* Retorrne un object accessfilter
* @param string $pstrAccessFilterName AccessFilter name
* @param boolean $pbKey Returns the key or the value.
* @return org_geoprisma_accessfilter_AccessFilter
com_borealis_foundation_util_Assert::assertIsNotEmptyString($pstrAccessFilterName);
if ($objAccessFilter->getName() ==
$pstrAccessFilterName)
return ($pbKey) ?
$iKey :
$objAccessFilter ;
* Retorrne la liste des accessfilter disponible
* @return ArrayObject of org_geoprisma_accessfilter_AccessFilter
* Retourne un object resource
* @param string $pstrResourceName Resource name
* @return org_geoprisma_resource_Resource
com_borealis_foundation_util_Assert::assertIsNotEmptyString($pstrResourceName);
if ($objResource->getName() ==
$pstrResourceName)
* Retourne la liste des resources disponible du mapcontext
* @return ArrayObject of org_geoprisma_resource_Resource
* Retourne la liste de tous les resources disponibles.
* @return ArrayObject of org_geoprisma_resource_Resource
* Get a specific field object using its id
* @param string $piFieldId Field id
* @return org_geoprisma_field_Field
com_borealis_foundation_util_Assert::assertIsNotEmptyString($piFieldId);
if ($objField->getId() ==
$piFieldId)
* Retourne la liste des fields disponible
* @return ArrayObject of org_geoprisma_field_Field
* Get org_geoprisma_widget_MapFishLayerTree widget
* Only used if isUsingLegacyWidgets() == true
* @return org_geoprisma_widget_MapFishLayerTree or false if not found
* return instanceof org_geoprisma_config_PGSQLMapContextConfig
* return instanceof org_geoprisma_config_Config
* return instanceof com_borealis_foundation_util_Singleton
* @return org_geoprisma_config_PGSQLMapContextConfig
if (self::$s_objInstance ===
null)
self::$s_objInstance =
new org_geoprisma_config_PGSQLMapContextConfig();
return self::$s_objInstance;
* Returns an array of foreign ids from a record list
* @param array $pobjArrayRecords array of records
* @param string $pstrForeignFeature name of the foreign table
protected function getForeignIds($pobjArrayRecords, $pstrForeignFeature)
$objArrayForeignIds =
array();
foreach ($pobjArrayRecords as $objRecord)
if (isset
($objRecord[$pstrForeignFeature]))
foreach ($objRecord[$pstrForeignFeature] as $iForeignId)
if (!in_array($iForeignId, $objArrayForeignIds))
else if (isset
($objRecord[$pstrForeignFeature.
"_id"]))
$iForeignId =
$objRecord[$pstrForeignFeature.
"_id"];
if (!in_array($iForeignId, $objArrayForeignIds))
asort($objArrayForeignIds);
return $objArrayForeignIds;
* Browse each resource option. If it's an option ending by any servicetype,
* check if it's equal to given servicetype in parameter. If not, skip
* Then, if the option is inside the 'LayersResourcesOptions' array, use
* the alternate name (the key is the resource option, the value is the
* related layer option to use instead).
* Finally, push the option inside an array. In the end, this method returns
* the complete list of options from a resource for a specific layer
* @param array $pobjArrayResourceOptions Array of options of a specific
* org_geoprisma_resource_Resource
* @param string &$pstrServiceType Service type
$pobjArrayResourceOptions, &$pstrServiceType
$objArrayLayerOptions =
array();
foreach ($pobjArrayResourceOptions as $objResourceOption)
$strLayerOptionName =
$objResourceOption->getName();
// check if the option ends with a 'servicetype' string. If it
// does, make sure it's the same as the service type in params, els
foreach ($objArrayServiceTypes as $strServiceType)
$strPattern =
"/$strServiceType$/";
if (count($objArrayMatches) ==
1)
if ($objArrayMatches[0] !=
$pstrServiceType)
// since the option is set specifically for this
// service type, we allow replacement of existing
// options with the same name.
$objArrayLayerResourceOptions
// if option is set LayerResourceOptions array, then use the
// alternative name instead
if (isset
($objArrayLayerResourceOptions[$strLayerOptionName]))
=
$objArrayLayerResourceOptions[$strLayerOptionName];
// if option is set LayerResourceOptions array, then use the
// alternative name instead
if (isset
($objArrayLayerResourceOptions[$strLayerOptionName]))
=
$objArrayLayerResourceOptions[$strLayerOptionName];
// set new option. Skip if already set unless 'allow replace' flag
if (!isset
($objArrayLayerOptions[$strLayerOptionName])
$objArrayLayerOptions[$strLayerOptionName]
=
$objResourceOption->getValue();
return $objArrayLayerOptions;
* Returns the array of clone names. If the 'key' parameter is set, returns
* only a portion of the array (if it exists, else returns false).
* @param string $pstrKey Optional key refering to an orignal name. Defaults
* Returns how many resources the current loaded mapcontext has and which
* resources and actions the current logged role has access to (their names).
* @param array $pobjArrayActions Actions. In order to be considered
* 'authorized', the role must have all
* action defined there allowed.
* @param array $pobjArrayOptions Options for this method
* @return array containing 2 keys : 'total' (integer), 'authorized'
* (array) and 'authorizedActions' (array)
$pobjArrayActions=
array("read"),
$pobjArrayOptions=
array('otherResources' =>
false)
$objArrayAuthorizedResources =
array();
$objArrayAuthorizedResourcesActions =
array();
$bOtherResources =
$pobjArrayOptions['otherResources'];
$strGetResourceFunction =
'getOtherResources';
$strGetResourceFunction =
'getResources';
foreach ($this->$strGetResourceFunction() as $objResource)
$objArrayAuthorizedResourcesActions[$objResource->getName()] =
array();
foreach ($pobjArrayActions as $strAction)
$objArrayAuthorizedResourcesActions[$objResource->getName()][$strAction] =
true;
$objArrayAuthorizedResources,
'total' =>
count($objArrayAuthorizedResources),
'authorized' =>
$objArrayAuthorizedResources,
'authorizedActions' =>
$objArrayAuthorizedResourcesActions
* Get reource name strings from current request (from the 'osmresource'
* parameter). This is the first method called by this config.
* If there ARE resources in the url, that means the access is made from
* the proxy, so we don't need to load everything, just the requested
* Resources, their DataStores and Services.
$objArrayResources =
array();
if (isset
($_REQUEST) && isset
($_REQUEST['osmresource']))
$objArrayResources =
$_REQUEST['osmresource'];
$objArrayResources =
array($_REQUEST['osmresource']);
return $objArrayResources;
// ------------------------
// other property getters
// ------------------------
return self::$s_strConnection;
* Returns all service types
public function getServiceTypes()
return self::$s_iCurrentSession;
* Get config session name
public static function getCurrentSessionName()
return self::$s_strCurrentSessionName;
* Get config mapcontext id
public static function getCurrentMapContext()
return self::$s_iCurrentMapContext;
* Get config mapcontext name
public static function getCurrentMapContextName()
return self::$s_strCurrentMapContextName;
* Get config application id
public static function getCurrentApplication()
return self::$s_iCurrentApplication;
* Get config application name
public static function getCurrentApplicationName()
return self::$s_strCurrentApplicationName;
* Get service feature name
public static function getServiceFeatureName()
return self::$s_strServiceFeature;
* Get datastore feature name
public static function getDataStoreFeatureName()
return self::$s_strDataStoreFeature;
* Get resource feature name
public static function getResourceFeatureName()
return self::$s_strResourceFeature;
public static function getFieldFeatureName()
return self::$s_strFieldFeature;
* Get mapcontext feature name
public static function getMapContextFeatureName()
return self::$s_strMapContextFeature;
* Get widget feature name
public static function getWidgetFeatureName()
return self::$s_strWidgetFeature;
* Get widget feature name
public static function getAccessFilterFeatureName()
return self::$s_strAccessFilterFeature;
* Get application feature name
public static function getApplicationFeatureName()
return self::$s_strApplicationFeature;
* Get session feature name
public static function getSessionFeatureName()
return self::$s_strSessionFeature;
* Get table prefix string
public static function getTablePrefix()
return self::$s_strTablePrefix;
* Get option table suffix string
public static function getOptionTableSuffix()
return self::$s_strTableOptionSuffix;
* Get table name using a given feature name.
* @param string $pstrFeatureName Name of the feature
public static function getTableName($pstrFeatureName)
return self::getTablePrefix().
$pstrFeatureName;
* Get option table name using a given feature name.
* @param string $pstrFeatureName Name of the feature
return self::getTablePrefix().
$pstrFeatureName.
self::getOptionTableSuffix();
* Get relation table name using a given master feature name and a slave
* @param string $pstrMasterFeatureName Name of the master feature
* @param string $pstrSlaveFeatureName Name of the slave feature
$pstrMasterFeatureName, $pstrSlaveFeatureName
return self::getTablePrefix().
$pstrMasterFeatureName.
$pstrSlaveFeatureName;
* Get option table name using a given feature name.
* @param string $pstrMasterFeatureName Name of the master feature
* @param string $pstrSlaveFeatureName Name of the slave feature
$pstrMasterFeatureName, $pstrSlaveFeatureName
return self::getTablePrefix().
$pstrMasterFeatureName.
$pstrSlaveFeatureName.
self::getOptionTableSuffix();
* Get whether the config should use the 'legacy' widgets
* (Map and MapFishLayerTree) or not (MapPanel and Layer).
return self::$s_bUseLegacyWidgets;
* Returns the layer 'resource options' array.
* Only used when isUsingLegacyWidgets() == true
public function getLayerResourceOptions()
* @param string $pstrConnection Connection string used when connecting to
self::$s_strConnection =
$pstrConnection;
* @param integer $piValue Value
public static function setCurrentSession($piValue)
self::$s_iCurrentSession =
$piValue;
* Set config session name
* @param string $pstrValue Value
public static function setCurrentSessionName($pstrValue)
self::$s_strCurrentSessionName =
$pstrValue;
* Set config mapcontext id
* @param integer $piValue Value
public static function setCurrentMapContext($piValue)
self::$s_iCurrentMapContext =
$piValue;
* Set config mapcontext name
* @param string $pstrValue Value
public static function setCurrentMapContextName($pstrValue)
self::$s_strCurrentMapContextName =
$pstrValue;
* Set config application id
* @param integer $piValue Value
public static function setCurrentApplication($piValue)
self::$s_iCurrentApplication =
$piValue;
* Set config application name
* @param string $pstrValue Value
public static function setCurrentApplicationName($pstrValue)
self::$s_strCurrentApplicationName =
$pstrValue;
* Set service feature name
* @param string $pstrValue Value
public static function setServiceFeatureName($pstrValue)
self::$s_strServiceFeature =
$pstrValue;
* Set datastore feature name
* @param string $pstrValue Value
public static function setDataStoreFeatureName($pstrValue)
self::$s_strDataStoreFeature =
$pstrValue;
* Set resource feature name
* @param string $pstrValue Value
public static function setResourceFeatureName($pstrValue)
self::$s_strResourceFeature =
$pstrValue;
* @param string $pstrValue Value
public static function setFieldFeatureName($pstrValue)
self::$s_strFieldFeature =
$pstrValue;
* Set mapcontext feature name
* @param string $pstrValue Value
public static function setMapContextFeatureName($pstrValue)
self::$s_strMapContextFeature =
$pstrValue;
* Set widget feature name
* @param string $pstrValue Value
public static function setWidgetFeatureName($pstrValue)
self::$s_strWidgetFeature =
$pstrValue;
* Set accessfilter feature name
* @param string $pstrValue Value
public static function setAccessFilterFeatureName($pstrValue)
self::$s_strAccessFilterFeature =
$pstrValue;
* Set application feature name
* @param string $pstrValue Value
public static function setApplicationFeatureName($pstrValue)
self::$s_strApplicationFeature =
$pstrValue;
* Set session feature name
* @param string $pstrValue Value
public static function setSessionFeatureName($pstrValue)
self::$s_strSessionFeature =
$pstrValue;
* Set table prefix string
* @param string $pstrValue Value
public static function setTablePrefix($pstrValue)
self::$s_strTablePrefix =
$pstrValue;
* Set option table suffix string
* @param string $pstrValue Value
public static function setOptionTableSuffix($pstrValue)
self::$s_strTableOptionSuffix =
$pstrValue;
* Set legacy widget using (flag)
* @param string $pstrValue Value
public static function useLegacyWidgets($pstrValue)
self::$s_bUseLegacyWidgets =
$pstrValue;
Documentation generated on Thu, 19 Jan 2012 00:08:48 +0400 by phpDocumentor 1.4.1