xml.navigator.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Specific page to build the XML data describing the "relation" around a given seed object
  18. * This XML is desgined to be consumed by the Flash Navigator object (see ../navigator folder)
  19. *
  20. * @author Erwan Taloc <erwan.taloc@combodo.com>
  21. * @author Romain Quetiez <romain.quetiez@combodo.com>
  22. * @author Denis Flaven <denis.flaven@combodo.com>
  23. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  24. */
  25. require_once('../application/application.inc.php');
  26. require_once('../application/webpage.class.inc.php');
  27. require_once('../application/ajaxwebpage.class.inc.php');
  28. require_once('../application/wizardhelper.class.inc.php');
  29. require_once('../application/ui.linkswidget.class.inc.php');
  30. define('MAX_RECURSION_DEPTH', 20);
  31. /**
  32. * Fills the given XML node with te details of the specified object
  33. */
  34. function AddNodeDetails(&$oNode, $oObj)
  35. {
  36. $aZlist = MetaModel::GetZListItems(get_class($oObj), 'details');
  37. $aLabels = array();
  38. $index = 0;
  39. foreach($aZlist as $sAttCode)
  40. {
  41. $oAttDef = MetaModel::GetAttributeDef(get_class($oObj), $sAttCode);
  42. $aLabels[] = $oAttDef->GetLabel();
  43. $oNode->SetAttribute('att_'.$index, $oObj->Get($sAttCode));
  44. $index++;
  45. }
  46. $oNode->SetAttribute('zlist', implode(',', $aLabels));
  47. }
  48. /**
  49. * Get the related objects through the given relation
  50. * @param DBObject $oObj The current object
  51. * @param string $sRelation The name of the relation to search with
  52. */
  53. function GetRelatedObjects(DBObject $oObj, $sRelationName, &$oLinks, &$oXmlDoc, &$oXmlNode)
  54. {
  55. $oContext = new UserContext();
  56. $aResults = array();
  57. $oObj->GetRelatedObjects($sRelationName, 1 /* iMaxDepth */, $aResults);
  58. static $iDepth = 0;
  59. $iDepth++;
  60. if ($iDepth > MAX_RECURSION_DEPTH) return;
  61. foreach($aResults as $sRelatedClass => $aObjects)
  62. {
  63. foreach($aObjects as $id => $oTargetObj)
  64. {
  65. if (is_object($oTargetObj))
  66. {
  67. $oLinkingNode = $oXmlDoc->CreateElement('link');
  68. $oLinkingNode->SetAttribute('relation', $sRelationName);
  69. $oLinkingNode->SetAttribute('arrow', 1); // Such relations have a direction, display an arrow
  70. $oLinkedNode = $oXmlDoc->CreateElement('node');
  71. $oLinkedNode->SetAttribute('id', $oTargetObj->GetKey());
  72. $oLinkedNode->SetAttribute('obj_class', get_class($oTargetObj));
  73. $oLinkedNode->SetAttribute('name', $oTargetObj->GetName());
  74. $oLinkedNode->SetAttribute('icon', BuildIconPath($oTargetObj->GetIcon()));
  75. AddNodeDetails($oLinkedNode, $oTargetObj);
  76. $oSubLinks = $oXmlDoc->CreateElement('links');
  77. GetRelatedObjects($oTargetObj, $sRelationName, $oSubLinks, $oXmlDoc, $oLinkedNode);
  78. $oLinkingNode->AppendChild($oLinkedNode);
  79. $oLinks->AppendChild($oLinkingNode);
  80. }
  81. }
  82. }
  83. if (count($aResults) > 0)
  84. {
  85. $oXmlNode->AppendChild($oLinks);
  86. }
  87. }
  88. function BuildIconPath($sIconPath)
  89. {
  90. $sFullURL = utils::GetAbsoluteURL(false, false);
  91. $iLastSlashPos = strrpos($sFullURL, '/');
  92. $sFullURLPath = substr($sFullURL, 0, 1 + $iLastSlashPos);
  93. return $sFullURLPath.$sIconPath;
  94. }
  95. require_once('../application/startup.inc.php');
  96. require_once('../application/loginwebpage.class.inc.php');
  97. //// For developping the Navigator
  98. //session_start();
  99. //$_SESSION['auth_user'] = 'admin';
  100. //$_SESSION['auth_pwd'] = 'admin2';
  101. //UserRights::Login($_SESSION['auth_user'], $_SESSION['auth_pwd']); // Set the user's language
  102. LoginWebPage::DoLogin(); // Check user rights and prompt if needed
  103. $oPage = new ajax_page("");
  104. $oPage->no_cache();
  105. $oContext = new UserContext();
  106. $sClass = utils::ReadParam('class', 'Contact');
  107. $id = utils::ReadParam('id', 1);
  108. $sRelation = utils::ReadParam('relation', 'impacts');
  109. $aValidRelations = MetaModel::EnumRelations();
  110. if (!in_array($sRelation, $aValidRelations))
  111. {
  112. // Not a valid relation, use the default one instead
  113. $sRelation = 'impacts';
  114. }
  115. if ($id != 0)
  116. {
  117. $oObj = $oContext->GetObject($sClass, $id);
  118. // Build the root XML part
  119. $oXmlDoc = new DOMDocument( '1.0', 'UTF-8' );
  120. $oXmlRoot = $oXmlDoc->CreateElement('root');
  121. $oXmlNode = $oXmlDoc->CreateElement('node');
  122. $oXmlNode->SetAttribute('id', $oObj->GetKey());
  123. $oXmlNode->SetAttribute('obj_class', get_class($oObj));
  124. $oXmlNode->SetAttribute('name', $oObj->GetName());
  125. $oXmlNode->SetAttribute('icon', BuildIconPath($oObj->GetIcon())); // Hard coded for the moment
  126. AddNodeDetails($oXmlNode, $oObj);
  127. $oLinks = $oXmlDoc->CreateElement("links");
  128. $oXmlRoot->SetAttribute('position', 'left');
  129. $oXmlRoot->SetAttribute('title', MetaModel::GetRelationDescription($sRelation).' '.$oObj->GetName());
  130. GetRelatedObjects($oObj, $sRelation, $oLinks, $oXmlDoc, $oXmlNode);
  131. $oXmlRoot->AppendChild($oXmlNode);
  132. $oXmlDoc->AppendChild($oXmlRoot);
  133. $oPage->add($oXmlDoc->SaveXML());
  134. }
  135. $oPage->output();
  136. ?>