|
@@ -1,10 +1,37 @@
|
|
|
<?php
|
|
|
+// Copyright (C) 2010 Combodo SARL
|
|
|
+//
|
|
|
+// This program is free software; you can redistribute it and/or modify
|
|
|
+// it under the terms of the GNU General Public License as published by
|
|
|
+// the Free Software Foundation; version 3 of the License.
|
|
|
+//
|
|
|
+// This program is distributed in the hope that it will be useful,
|
|
|
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
+// GNU General Public License for more details.
|
|
|
+//
|
|
|
+// You should have received a copy of the GNU General Public License
|
|
|
+// along with this program; if not, write to the Free Software
|
|
|
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
+
|
|
|
+/**
|
|
|
+ * Specific page to build the XML data describing the "relation" around a given seed object
|
|
|
+ * This XML is desgined to be consumed by the Flash Navigator object (see ../navigator folder)
|
|
|
+ *
|
|
|
+ * @author Erwan Taloc <erwan.taloc@combodo.com>
|
|
|
+ * @author Romain Quetiez <romain.quetiez@combodo.com>
|
|
|
+ * @author Denis Flaven <denis.flaven@combodo.com>
|
|
|
+ * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
|
|
|
+ */
|
|
|
+
|
|
|
require_once('../application/application.inc.php');
|
|
|
require_once('../application/webpage.class.inc.php');
|
|
|
require_once('../application/ajaxwebpage.class.inc.php');
|
|
|
require_once('../application/wizardhelper.class.inc.php');
|
|
|
require_once('../application/ui.linkswidget.class.inc.php');
|
|
|
|
|
|
+define('MAX_RECURSION_DEPTH', 20);
|
|
|
+
|
|
|
/**
|
|
|
* Fills the given XML node with te details of the specified object
|
|
|
*/
|
|
@@ -24,108 +51,6 @@ function AddNodeDetails(&$oNode, $oObj)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Get the neighbours i.e. objects linked to the current object
|
|
|
- * @param DBObject $oObj The current object
|
|
|
- */
|
|
|
-function GetNeighbours(DBObject $oObj, &$oLinks, &$oXmlDoc, &$oXmlNode)
|
|
|
-{
|
|
|
- $oContext = new UserContext();
|
|
|
- $aRefs = MetaModel::EnumReferencingClasses(get_class($oObj));
|
|
|
- $aExtKeys = MetaModel::EnumLinkingClasses(get_class($oObj));
|
|
|
- if ((count($aRefs) != 0) || (count($aExtKeys) != 0))
|
|
|
- {
|
|
|
- foreach ($aRefs as $sRemoteClass => $aRemoteKeys)
|
|
|
- {
|
|
|
- foreach ($aRemoteKeys as $sExtKeyAttCode => $oExtKeyAttDef)
|
|
|
- {
|
|
|
- $oFilter = $oContext->NewFilter($sRemoteClass);
|
|
|
- $oFilter->AddCondition($sExtKeyAttCode, $oObj->GetKey());
|
|
|
- $oSet = new DBObjectSet($oFilter);
|
|
|
- if ($oSet->Count() > 0)
|
|
|
- {
|
|
|
- if (substr($sRemoteClass,0,3) == 'lnk')
|
|
|
- {
|
|
|
- // Special processing for "links":
|
|
|
- // Find out the first field which is an external key to another object,
|
|
|
- // and display this object as the one linked to the root object
|
|
|
- $sTargetClass = '';
|
|
|
- $sTargetAttCode = '';
|
|
|
- foreach(MetaModel::ListAttributeDefs($sRemoteClass) as $sAttCode=>$oAttDef)
|
|
|
- {
|
|
|
- if (($sAttCode != $sExtKeyAttCode) && ($oAttDef->IsExternalKey()) )
|
|
|
- {
|
|
|
- $sTargetClass = $oAttDef->GetTargetClass();
|
|
|
- $sTargetAttCode = $sAttCode;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if ($sTargetClass != '')
|
|
|
- {
|
|
|
- while( $oRelatedObj = $oSet->Fetch())
|
|
|
- {
|
|
|
- $oTargetObj = $oContext->GetObject($sTargetClass, $oRelatedObj->Get($sTargetAttCode));
|
|
|
- if (is_object($oTargetObj))
|
|
|
- {
|
|
|
- $oLinkingNode = $oXmlDoc->CreateElement('link');
|
|
|
- $oLinkedNode = $oXmlDoc->CreateElement('node');
|
|
|
- $oLinkedNode->SetAttribute('id', $oTargetObj->GetKey());
|
|
|
- $oLinkedNode->SetAttribute('obj_class', get_class($oTargetObj));
|
|
|
- $oLinkedNode->SetAttribute('name', $oTargetObj->GetName());
|
|
|
- $oLinkedNode->SetAttribute('icon', BuildIconPath($oTargetObj->GetIcon()) );
|
|
|
- AddNodeDetails($oLinkedNode, $oTargetObj);
|
|
|
- $oLinkingNode->AppendChild($oLinkedNode);
|
|
|
- $oLinks->AppendChild($oLinkingNode);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- while( $oRelatedObj = $oSet->Fetch())
|
|
|
- {
|
|
|
- $oLinkingNode = $oXmlDoc->CreateElement('link');
|
|
|
- $oLinkedNode = $oXmlDoc->CreateElement('node');
|
|
|
- $oLinkedNode->SetAttribute('id', $oRelatedObj->GetKey());
|
|
|
- $oLinkedNode->SetAttribute('obj_class', get_class($oRelatedObj));
|
|
|
- $oLinkedNode->SetAttribute('name', $oRelatedObj->GetName());
|
|
|
- $oLinkedNode->SetAttribute('icon', BuildIconPath($oRelatedObj->GetIcon()));
|
|
|
- AddNodeDetails($oLinkedNode, $oRelatedObj);
|
|
|
- $oLinkingNode->AppendChild($oLinkedNode);
|
|
|
- $oLinks->AppendChild($oLinkingNode);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- foreach ($aExtKeys as $sLinkClass => $aRemoteClasses)
|
|
|
- {
|
|
|
- foreach($aRemoteClasses as $sExtKeyAttCode => $sRemoteClass)
|
|
|
- {
|
|
|
- // Special case to exclude such "silos" classes that will be linked
|
|
|
- // to almost all the objects of a chart and thus would make the chart
|
|
|
- // un-readable if all the links are displayed...
|
|
|
- if (($sLinkClass == get_class($oObj)) &&
|
|
|
- ($sRemoteClass != 'Location') &&
|
|
|
- ($sRemoteClass != 'Organization') )
|
|
|
- {
|
|
|
- $oRelatedObj = $oContext->GetObject($sRemoteClass, $oObj->Get($sExtKeyAttCode));
|
|
|
- $oLinkingNode = $oXmlDoc->CreateElement('link');
|
|
|
- $oLinkedNode = $oXmlDoc->CreateElement('node');
|
|
|
- $oLinkedNode->SetAttribute('id', $oRelatedObj->GetKey());
|
|
|
- $oLinkedNode->SetAttribute('obj_class', get_class($oRelatedObj));
|
|
|
- $oLinkedNode->SetAttribute('name', $oRelatedObj->GetName());
|
|
|
- $oLinkedNode->SetAttribute('icon', BuildIconPath($oRelatedObj->GetIcon()));
|
|
|
- AddNodeDetails($oLinkedNode, $oRelatedObj);
|
|
|
- $oLinkingNode->AppendChild($oLinkedNode);
|
|
|
- $oLinks->AppendChild($oLinkingNode);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- $oXmlNode->AppendChild($oLinks);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
* Get the related objects through the given relation
|
|
|
* @param DBObject $oObj The current object
|
|
|
* @param string $sRelation The name of the relation to search with
|
|
@@ -135,6 +60,9 @@ function GetRelatedObjects(DBObject $oObj, $sRelationName, &$oLinks, &$oXmlDoc,
|
|
|
$oContext = new UserContext();
|
|
|
$aResults = array();
|
|
|
$oObj->GetRelatedObjects($sRelationName, 1 /* iMaxDepth */, $aResults);
|
|
|
+ static $iDepth = 0;
|
|
|
+ $iDepth++;
|
|
|
+ if ($iDepth > MAX_RECURSION_DEPTH) return;
|
|
|
|
|
|
foreach($aResults as $sRelatedClass => $aObjects)
|
|
|
{
|
|
@@ -145,7 +73,6 @@ function GetRelatedObjects(DBObject $oObj, $sRelationName, &$oLinks, &$oXmlDoc,
|
|
|
$oLinkingNode = $oXmlDoc->CreateElement('link');
|
|
|
$oLinkingNode->SetAttribute('relation', $sRelationName);
|
|
|
$oLinkingNode->SetAttribute('arrow', 1); // Such relations have a direction, display an arrow
|
|
|
- $oLinkingNode->SetAttribute('debug', 142); // Such relations have a direction, display an arrow
|
|
|
$oLinkedNode = $oXmlDoc->CreateElement('node');
|
|
|
$oLinkedNode->SetAttribute('id', $oTargetObj->GetKey());
|
|
|
$oLinkedNode->SetAttribute('obj_class', get_class($oTargetObj));
|
|
@@ -188,13 +115,13 @@ $oPage->no_cache();
|
|
|
$oContext = new UserContext();
|
|
|
$sClass = utils::ReadParam('class', 'Contact');
|
|
|
$id = utils::ReadParam('id', 1);
|
|
|
-$sRelation = utils::ReadParam('relation', 'impact');
|
|
|
+$sRelation = utils::ReadParam('relation', 'impacts');
|
|
|
$aValidRelations = MetaModel::EnumRelations();
|
|
|
|
|
|
if (!in_array($sRelation, $aValidRelations))
|
|
|
{
|
|
|
// Not a valid relation, use the default one instead
|
|
|
- $sRelation = 'neighbours';
|
|
|
+ $sRelation = 'impacts';
|
|
|
}
|
|
|
|
|
|
if ($id != 0)
|
|
@@ -211,20 +138,10 @@ if ($id != 0)
|
|
|
AddNodeDetails($oXmlNode, $oObj);
|
|
|
|
|
|
$oLinks = $oXmlDoc->CreateElement("links");
|
|
|
- switch($sRelation)
|
|
|
- {
|
|
|
- case 'neighbours':
|
|
|
- // Now search for all the neighboor objects and append them
|
|
|
- $oXmlRoot->SetAttribute('title', 'Neighbours of '.$oObj->GetName());
|
|
|
- GetNeighbours($oObj, $oLinks, $oXmlDoc, $oXmlNode);
|
|
|
- $oXmlRoot->SetAttribute('position', 'center');
|
|
|
- break;
|
|
|
-
|
|
|
- default:
|
|
|
- $oXmlRoot->SetAttribute('position', 'left');
|
|
|
- $oXmlRoot->SetAttribute('title', MetaModel::GetRelationDescription($sRelation).' '.$oObj->GetName());
|
|
|
- GetRelatedObjects($oObj, $sRelation, $oLinks, $oXmlDoc, $oXmlNode);
|
|
|
- }
|
|
|
+
|
|
|
+ $oXmlRoot->SetAttribute('position', 'left');
|
|
|
+ $oXmlRoot->SetAttribute('title', MetaModel::GetRelationDescription($sRelation).' '.$oObj->GetName());
|
|
|
+ GetRelatedObjects($oObj, $sRelation, $oLinks, $oXmlDoc, $oXmlNode);
|
|
|
|
|
|
$oXmlRoot->AppendChild($oXmlNode);
|
|
|
$oXmlDoc->AppendChild($oXmlRoot);
|