schema.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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. * Presentation of the data model
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  23. */
  24. require_once('../approot.inc.php');
  25. require_once(APPROOT.'/application/application.inc.php');
  26. require_once(APPROOT.'/application/itopwebpage.class.inc.php');
  27. require_once(APPROOT.'/application/startup.inc.php');
  28. require_once(APPROOT.'/application/loginwebpage.class.inc.php');
  29. LoginWebPage::DoLogin(true); // Check user rights and prompt if needed (must be admin)
  30. /**
  31. * Helper for this page -> link to a class
  32. */
  33. function MakeClassHLink($sClass)
  34. {
  35. return "<a href=\"?operation=details_class&class=$sClass\" title=\"".MetaModel::GetClassDescription($sClass)."\">".MetaModel::GetName($sClass)."</a>";
  36. }
  37. /**
  38. * Helper for this page -> link to a class
  39. */
  40. function MakeRelationHLink($sRelCode)
  41. {
  42. $sDesc = MetaModel::GetRelationDescription($sRelCode);
  43. return "<a href=\"?operation=details_relation&relcode=$sRelCode\" title=\"$sDesc\">".$sRelCode."</a>";
  44. }
  45. /**
  46. * Helper for the global list and the details of a given class
  47. */
  48. function DisplaySubclasses($oPage, $sClass)
  49. {
  50. $aChildClasses = MetaModel::EnumChildClasses($sClass);
  51. if (count($aChildClasses) != 0)
  52. {
  53. $oPage->add("<ul>\n");
  54. $aOrderedClasses = array();
  55. foreach($aChildClasses as $sClassName)
  56. {
  57. // Skip indirect childs, they will be handled somewhere else
  58. if (MetaModel::GetParentPersistentClass($sClassName) == $sClass)
  59. {
  60. $aOrderedClasses[$sClassName] = MetaModel::GetName($sClassName);
  61. }
  62. }
  63. // Sort on the display name
  64. asort($aOrderedClasses);
  65. foreach($aOrderedClasses as $sClassName => $sDisplayName)
  66. {
  67. // Skip indirect childs, they will be handled somewhere else
  68. if (MetaModel::GetParentPersistentClass($sClassName) == $sClass)
  69. {
  70. $oPage->add("<li>".MakeClassHLink($sClassName)."\n");
  71. DisplaySubclasses($oPage, $sClassName);
  72. $oPage->add("</li>\n");
  73. }
  74. }
  75. $oPage->add("</ul>\n");
  76. }
  77. }
  78. /**
  79. * Helper for the global list and the details of a given class
  80. */
  81. function DisplayReferencingClasses($oPage, $sClass)
  82. {
  83. $bSkipLinkingClasses = false;
  84. $aRefs = MetaModel::EnumReferencingClasses($sClass, $bSkipLinkingClasses);
  85. if (count($aRefs) != 0)
  86. {
  87. $oPage->add("<ul>\n");
  88. foreach ($aRefs as $sRemoteClass => $aRemoteKeys)
  89. {
  90. foreach ($aRemoteKeys as $sExtKeyAttCode => $oExtKeyAttDef)
  91. {
  92. $oPage->add("<li>".Dict::Format('UI:Schema:Class_ReferencingClasses_From_By', $sClass, MakeClassHLink($sRemoteClass), $sExtKeyAttCode)."</li>\n");
  93. }
  94. }
  95. $oPage->add("</ul>\n");
  96. }
  97. }
  98. /**
  99. * Helper for the global list and the details of a given class
  100. */
  101. function DisplayLinkingClasses($oPage, $sClass)
  102. {
  103. $bSkipLinkingClasses = false;
  104. $aRefs = MetaModel::EnumLinkingClasses($sClass);
  105. if (count($aRefs) != 0)
  106. {
  107. $oPage->add("<ul>\n");
  108. foreach ($aRefs as $sLinkClass => $aRemoteClasses)
  109. {
  110. foreach($aRemoteClasses as $sExtKeyAttCode => $sRemoteClass)
  111. {
  112. $oPage->add("<li>".Dict::Format('UI:Schema:Class_IsLinkedTo_Class_Via_ClassAndAttribute', $sClass, MakeClassHLink($sRemoteClass), MakeClassHLink($sLinkClass), $sExtKeyAttCode));
  113. }
  114. }
  115. $oPage->add("</ul>\n");
  116. }
  117. }
  118. /**
  119. * Helper for the global list and the details of a given class
  120. */
  121. function DisplayRelatedClassesBestInClass($oPage, $sClass, $iLevels = 20, &$aVisitedClasses = array(), $bSubtree = true)
  122. {
  123. if ($iLevels <= 0) return;
  124. $iLevels--;
  125. if (array_key_exists($sClass, $aVisitedClasses)) return;
  126. $aVisitedClasses[$sClass] = true;
  127. if ($bSubtree) $oPage->add("<ul class=\"treeview\">\n");
  128. foreach (MetaModel::EnumParentClasses($sClass) as $sParentClass)
  129. {
  130. DisplayRelatedClassesBestInClass($oPage, $sParentClass, $iLevels, $aVisitedClasses, false);
  131. }
  132. ////$oPage->add("<div style=\"background-color:#ccc; border: 1px dashed #333;\">");
  133. foreach (MetaModel::EnumReferencedClasses($sClass) as $sExtKeyAttCode => $sRemoteClass)
  134. {
  135. $sVisited = (array_key_exists($sRemoteClass, $aVisitedClasses)) ? " ..." : "";
  136. if (MetaModel::GetAttributeOrigin($sClass, $sExtKeyAttCode) == $sClass)
  137. {
  138. $oPage->add("<li>$sClass| <em>$sExtKeyAttCode</em> =&gt;".MakeClassHLink($sRemoteClass)."$sVisited</li>\n");
  139. DisplayRelatedClassesBestInClass($oPage, $sRemoteClass, $iLevels, $aVisitedClasses);
  140. }
  141. }
  142. foreach (MetaModel::EnumReferencingClasses($sClass) as $sRemoteClass => $aRemoteKeys)
  143. {
  144. foreach ($aRemoteKeys as $sExtKeyAttCode => $oExtKeyAttDef)
  145. {
  146. $sVisited = (array_key_exists($sRemoteClass, $aVisitedClasses)) ? " ..." : "";
  147. $oPage->add("<li>$sClass| &lt;=".MakeClassHLink($sRemoteClass)."::<em>$sExtKeyAttCode</em>$sVisited</li>\n");
  148. DisplayRelatedClassesBestInClass($oPage, $sRemoteClass, $iLevels, $aVisitedClasses);
  149. }
  150. }
  151. ////$oPage->add("</div>");
  152. if ($bSubtree) $oPage->add("</ul>\n");
  153. }
  154. /**
  155. * Helper for the list of classes related to the given class
  156. */
  157. function DisplayRelatedClasses($oPage, $sClass)
  158. {
  159. $oPage->add("<h3>".Dict::Format('UI:Schema:Links:1-n', $sClass)."</h3>\n");
  160. DisplayReferencingClasses($oPage, $sClass);
  161. $oPage->add("<h3>".Dict::Format('UI:Schema:Links:n-n', $sClass)."</h3>\n");
  162. DisplayLinkingClasses($oPage, $sClass);
  163. $oPage->add("<h3>".Dict::S('UI:Schema:Links:All')."</h3>\n");
  164. DisplayRelatedClassesBestInClass($oPage, $sClass, 4);
  165. }
  166. /**
  167. * Helper for the lifecycle details of a given class
  168. */
  169. function DisplayLifecycle($oPage, $sClass)
  170. {
  171. $sStateAttCode = MetaModel::GetStateAttributeCode($sClass);
  172. if (empty($sStateAttCode))
  173. {
  174. $oPage->p(Dict::S('UI:Schema:NoLifeCyle'));
  175. }
  176. else
  177. {
  178. $aStates = MetaModel::EnumStates($sClass);
  179. $aStimuli = MetaModel::EnumStimuli($sClass);
  180. $oPage->add("<img src=\"".utils::GetAbsoluteUrlAppRoot()."pages/graphviz.php?class=$sClass\">\n");
  181. $oPage->add("<h3>".Dict::S('UI:Schema:LifeCycleTransitions')."</h3>\n");
  182. $oPage->add("<ul>\n");
  183. foreach ($aStates as $sStateCode => $aStateDef)
  184. {
  185. $sStateLabel = MetaModel::GetStateLabel($sClass, $sStateCode);
  186. $sStateDescription = MetaModel::GetStateDescription($sClass, $sStateCode);
  187. $oPage->add("<li title=\"code: $sStateCode\">$sStateLabel <span style=\"color:grey;\">($sStateCode) $sStateDescription</span></li>\n");
  188. $oPage->add("<ul>\n");
  189. foreach(MetaModel::EnumTransitions($sClass, $sStateCode) as $sStimulusCode => $aTransitionDef)
  190. {
  191. $sStimulusLabel = $aStimuli[$sStimulusCode]->GetLabel();
  192. $sTargetStateLabel = MetaModel::GetStateLabel($sClass, $aTransitionDef['target_state']);
  193. if (count($aTransitionDef['actions']) > 0)
  194. {
  195. $sActions = " <em>(".implode(', ', $aTransitionDef['actions']).")</em>";
  196. }
  197. else
  198. {
  199. $sActions = "";
  200. }
  201. $oPage->add("<li><span style=\"color:red;font-weight=bold;\">$sStimulusLabel</span> =&gt; $sTargetStateLabel $sActions</li>\n");
  202. }
  203. $oPage->add("</ul>\n");
  204. }
  205. $oPage->add("</ul>\n");
  206. $oPage->add("<h3>".Dict::S('UI:Schema:LifeCyleAttributeOptions')."</h3>\n");
  207. $oPage->add("<ul>\n");
  208. foreach ($aStates as $sStateCode => $aStateDef)
  209. {
  210. $sStateLabel = MetaModel::GetStateLabel($sClass, $sStateCode);
  211. $sStateDescription = MetaModel::GetStateDescription($sClass, $sStateCode);
  212. $oPage->add("<li title=\"code: $sStateCode\">$sStateLabel <span style=\"color:grey;\">($sStateCode) $sStateDescription</span></li>\n");
  213. if (count($aStates[$sStateCode]['attribute_list']) > 0)
  214. {
  215. $oPage->add("<ul>\n");
  216. foreach($aStates[$sStateCode]['attribute_list'] as $sAttCode => $iOptions)
  217. {
  218. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  219. $sAttLabel = $oAttDef->GetLabel();
  220. $aOptions = array();
  221. if ($iOptions & OPT_ATT_HIDDEN) $aOptions[] = Dict::S('UI:Schema:LifeCycleHiddenAttribute');
  222. if ($iOptions & OPT_ATT_READONLY) $aOptions[] = Dict::S('UI:Schema:LifeCycleReadOnlyAttribute');
  223. if ($iOptions & OPT_ATT_MANDATORY) $aOptions[] = Dict::S('UI:Schema:LifeCycleMandatoryAttribute');
  224. if ($iOptions & OPT_ATT_MUSTCHANGE) $aOptions[] = Dict::S('UI:Schema:LifeCycleAttributeMustChange');
  225. if ($iOptions & OPT_ATT_MUSTPROMPT) $aOptions[] = Dict::S('UI:Schema:LifeCycleAttributeMustPrompt');
  226. if (count($aOptions))
  227. {
  228. $sOptions = implode(', ', $aOptions);
  229. }
  230. else
  231. {
  232. $sOptions = "";
  233. }
  234. $oPage->add("<li><span style=\"color:purple;font-weight=bold;\">$sAttLabel</span> $sOptions</li>\n");
  235. }
  236. $oPage->add("</ul>\n");
  237. }
  238. else
  239. {
  240. $oPage->p("<em>".Dict::S('UI:Schema:LifeCycleEmptyList')."</em>");
  241. }
  242. }
  243. $oPage->add("</ul>\n");
  244. }
  245. }
  246. /**
  247. * Helper for the trigger
  248. */
  249. function DisplayTriggers($oPage, $sClass)
  250. {
  251. $sClassList = implode("', '", MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL));
  252. $oSet = new CMDBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnObject WHERE target_class IN ('$sClassList')"));
  253. cmdbAbstractObject::DisplaySet($oPage, $oSet, array('block_id' => 'triggers'));
  254. }
  255. /**
  256. * Display the list of classes from the business model
  257. */
  258. function DisplayClassesList($oPage)
  259. {
  260. $oPage->add("<h1>".Dict::S('UI:Schema:Title')."</h1>\n");
  261. $oPage->add("<ul id=\"ClassesList\" class=\"treeview fileview\">\n");
  262. // Get all the "root" classes for display
  263. $aRootClasses = array();
  264. foreach(MetaModel::GetClasses() as $sClassName)
  265. {
  266. if (MetaModel::IsRootClass($sClassName))
  267. {
  268. $aRootClasses[$sClassName] = MetaModel::GetName($sClassName);
  269. }
  270. elseif (MetaModel::IsStandaloneClass($sClassName))
  271. {
  272. $aRootClasses[$sClassName] = MetaModel::GetName($sClassName);
  273. }
  274. }
  275. // Sort them alphabetically on their display name
  276. asort($aRootClasses);
  277. foreach($aRootClasses as $sClassName => $sDisplayName)
  278. {
  279. if (MetaModel::IsRootClass($sClassName))
  280. {
  281. $oPage->add("<li class=\"closed\">".MakeClassHLink($sClassName)."\n");
  282. DisplaySubclasses($oPage, $sClassName);
  283. $oPage->add("</li>\n");
  284. }
  285. elseif (MetaModel::IsStandaloneClass($sClassName))
  286. {
  287. $oPage->add("<li>".MakeClassHLink($sClassName)."</li>\n");
  288. }
  289. }
  290. $oPage->add("</ul>\n");
  291. $oPage->add("<h1>".Dict::S('UI:Schema:Relationships')."</h1>\n");
  292. $oPage->add("<ul id=\"ClassesRelationships\" class=\"treeview\">\n");
  293. foreach (MetaModel::EnumRelations() as $sRelCode)
  294. {
  295. $oPage->add("<li>".MakeRelationHLink($sRelCode)."\n");
  296. $oPage->add("<ul>\n");
  297. $oPage->add("<li>Description: ".htmlentities(MetaModel::GetRelationDescription($sRelCode), ENT_QUOTES, 'UTF-8')."</li>\n");
  298. $oPage->add("<li>Verb up: ".htmlentities(MetaModel::GetRelationVerbUp($sRelCode), ENT_QUOTES, 'UTF-8')."</li>\n");
  299. $oPage->add("<li>Verb down: ".htmlentities(MetaModel::GetRelationVerbDown($sRelCode), ENT_QUOTES, 'UTF-8')."</li>\n");
  300. $oPage->add("</ul>\n");
  301. $oPage->add("</li>\n");
  302. }
  303. $oPage->add("</ul>\n");
  304. $oPage->add_ready_script('$("#ClassesList").treeview();');
  305. $oPage->add_ready_script('$("#ClassesRelationships").treeview();');
  306. }
  307. /**
  308. * Display the details of a given class of objects
  309. */
  310. function DisplayClassDetails($oPage, $sClass)
  311. {
  312. $oPage->add("<h2>$sClass - ".MetaModel::GetClassDescription($sClass)."</h2>\n");
  313. if (MetaModel::IsAbstract($sClass))
  314. {
  315. $oPage->p(Dict::S('UI:Schema:AbstractClass'));
  316. }
  317. else
  318. {
  319. $oPage->p(Dict::S('UI:Schema:NonAbstractClass'));
  320. }
  321. // $oPage->p("<h3>".Dict::S('UI:Schema:ClassHierarchyTitle')."</h3>");
  322. $aParentClasses = array();
  323. foreach(MetaModel::EnumParentClasses($sClass) as $sParentClass)
  324. {
  325. $aParentClasses[] = MakeClassHLink($sParentClass);
  326. }
  327. if (count($aParentClasses) > 0)
  328. {
  329. $sParents = implode(' &gt;&gt; ', $aParentClasses)." &gt;&gt; <b>$sClass</b>";
  330. }
  331. else
  332. {
  333. $sParents = '';
  334. }
  335. $oPage->p("[<a href=\"?operation='list'\">".Dict::S('UI:Schema:AllClasses')."</a>] $sParents");
  336. if (MetaModel::HasChildrenClasses($sClass))
  337. {
  338. $oPage->add("<ul id=\"ClassHierarchy\">");
  339. $oPage->add("<li class=\"closed\">".$sClass."\n");
  340. DisplaySubclasses($oPage, $sClass);
  341. $oPage->add("</li>\n");
  342. $oPage->add("</ul>\n");
  343. $oPage->add_ready_script('$("#ClassHierarchy").treeview();');
  344. }
  345. $oPage->p('');
  346. $oPage->AddTabContainer('details');
  347. $oPage->SetCurrentTabContainer('details');
  348. // List the attributes of the object
  349. $aDetails = array();
  350. foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode=>$oAttDef)
  351. {
  352. if ($oAttDef->IsExternalKey())
  353. {
  354. $sValue = Dict::Format('UI:Schema:ExternalKey_To',MakeClassHLink($oAttDef->GetTargetClass()));
  355. }
  356. else
  357. {
  358. $sValue = $oAttDef->GetDescription();
  359. }
  360. $sType = $oAttDef->GetType().' ('.$oAttDef->GetTypeDesc().')';
  361. $sOrigin = MetaModel::GetAttributeOrigin($sClass, $sAttCode);
  362. $sAllowedValues = "";
  363. $oAllowedValuesDef = $oAttDef->GetValuesDef();
  364. $sMoreInfo = "";
  365. $aCols = array();
  366. foreach($oAttDef->GetSQLColumns() as $sCol => $sFieldDesc)
  367. {
  368. $aCols[] = "$sCol: $sFieldDesc";
  369. }
  370. if (count($aCols) > 0)
  371. {
  372. $sCols = implode(', ', $aCols);
  373. $aMoreInfo = array();
  374. $aMoreInfo[] = Dict::Format('UI:Schema:Columns_Description', $sCols);
  375. $aMoreInfo[] = Dict::Format('UI:Schema:Default_Description', $oAttDef->GetDefaultValue());
  376. $aMoreInfo[] = $oAttDef->IsNullAllowed() ? Dict::S('UI:Schema:NullAllowed') : Dict::S('UI:Schema:NullNotAllowed');
  377. $sMoreInfo .= implode(', ', $aMoreInfo);
  378. }
  379. if (is_object($oAllowedValuesDef)) $sAllowedValues = $oAllowedValuesDef->GetValuesDescription();
  380. else $sAllowedValues = '';
  381. $aDetails[] = array('code' => $oAttDef->GetCode(), 'type' => $sType, 'origin' => $sOrigin, 'label' => $oAttDef->GetLabel(), 'description' => $sValue, 'values' => $sAllowedValues, 'moreinfo' => $sMoreInfo);
  382. }
  383. $oPage->SetCurrentTab(Dict::S('UI:Schema:Attributes'));
  384. $aConfig = array( 'code' => array('label' => Dict::S('UI:Schema:AttributeCode'), 'description' => Dict::S('UI:Schema:AttributeCode+')),
  385. 'label' => array('label' => Dict::S('UI:Schema:Label'), 'description' => Dict::S('UI:Schema:Label+')),
  386. 'type' => array('label' => Dict::S('UI:Schema:Type'), 'description' => Dict::S('UI:Schema:Type+')),
  387. 'origin' => array('label' => Dict::S('UI:Schema:Origin'), 'description' => Dict::S('UI:Schema:Origin+')),
  388. 'description' => array('label' => Dict::S('UI:Schema:Description'), 'description' => Dict::S('UI:Schema:Description+')),
  389. 'values' => array('label' => Dict::S('UI:Schema:AllowedValues'), 'description' => Dict::S('UI:Schema:AllowedValues+')),
  390. 'moreinfo' => array('label' => Dict::S('UI:Schema:MoreInfo'), 'description' => Dict::S('UI:Schema:MoreInfo+')),
  391. );
  392. $oPage->table($aConfig, $aDetails);
  393. // List the search criteria for this object
  394. $aDetails = array();
  395. foreach (MetaModel::GetClassFilterDefs($sClass) as $sFilterCode => $oFilterDef)
  396. {
  397. $aOpDescs = array();
  398. foreach ($oFilterDef->GetOperators() as $sOpCode => $sOpDescription)
  399. {
  400. $sIsTheLooser = ($sOpCode == $oFilterDef->GetLooseOperator()) ? " (loose search)" : "";
  401. $aOpDescs[] = "$sOpCode ($sOpDescription)$sIsTheLooser";
  402. }
  403. $aDetails[] = array( 'code' => $sFilterCode, 'description' => $oFilterDef->GetLabel(),'operators' => implode(" / ", $aOpDescs));
  404. }
  405. $oPage->SetCurrentTab(Dict::S('UI:Schema:SearchCriteria'));
  406. $aConfig = array( 'code' => array('label' => Dict::S('UI:Schema:FilterCode'), 'description' => Dict::S('UI:Schema:FilterCode+')),
  407. 'description' => array('label' => Dict::S('UI:Schema:FilterDescription'), 'description' => Dict::S('UI:Schema:FilterDescription+')),
  408. 'operators' => array('label' => Dict::S('UI:Schema:AvailOperators'), 'description' => Dict::S('UI:Schema:AvailOperators+'))
  409. );
  410. $oPage->table($aConfig, $aDetails);
  411. $oPage->SetCurrentTab(Dict::S('UI:Schema:ChildClasses'));
  412. DisplaySubclasses($oPage, $sClass);
  413. $oPage->SetCurrentTab(Dict::S('UI:Schema:ReferencingClasses'));
  414. DisplayReferencingClasses($oPage, $sClass);
  415. $oPage->SetCurrentTab(Dict::S('UI:Schema:RelatedClasses'));
  416. DisplayRelatedClasses($oPage, $sClass);
  417. $oPage->SetCurrentTab(Dict::S('UI:Schema:LifeCycle'));
  418. DisplayLifecycle($oPage, $sClass);
  419. $oPage->SetCurrentTab(Dict::S('UI:Schema:Triggers'));
  420. DisplayTriggers($oPage, $sClass);
  421. $oPage->SetCurrentTab();
  422. $oPage->SetCurrentTabContainer();
  423. }
  424. /**
  425. * Display the details of a given relation (e.g. "impacts")
  426. */
  427. function DisplayRelationDetails($oPage, $sRelCode)
  428. {
  429. $sDesc = MetaModel::GetRelationDescription($sRelCode);
  430. $sVerbDown = MetaModel::GetRelationVerbDown($sRelCode);
  431. $sVerbUp = MetaModel::GetRelationVerbUp($sRelCode);
  432. $oPage->add("<h1>".Dict::Format('UI:Schema:Relation_Code_Description', $sRelCode, $sDesc)."</h1>");
  433. $oPage->p(Dict::Format('UI:Schema:RelationDown_Description', $sVerbDown));
  434. $oPage->p(Dict::Format('UI:Schema:RelationUp_Description', $sVerbUp));
  435. $oPage->add("<ul id=\"RelationshipDetails\" class=\"treeview\">\n");
  436. foreach(MetaModel::GetClasses() as $sClass)
  437. {
  438. $aRelQueries = MetaModel::EnumRelationQueries($sClass, $sRelCode);
  439. if (count($aRelQueries) > 0)
  440. {
  441. $oPage->add("<li>class ".MakeClassHLink($sClass)."\n");
  442. $oPage->add("<ul>\n");
  443. foreach ($aRelQueries as $sRelKey => $aQuery)
  444. {
  445. $sQuery = $aQuery['sQuery'];
  446. $iDistance = $aQuery['iDistance'];
  447. if ($aQuery['bPropagate'])
  448. {
  449. $oPage->add("<li>".Dict::Format('UI:Schema:RelationPropagates', $sRelKey, $iDistance, $sQuery)."</li>\n");
  450. }
  451. else
  452. {
  453. $oPage->add("<li>".Dict::Format('UI:Schema:RelationDoesNotPropagate', $sRelKey, $iDistance, $sQuery)."</li>\n");
  454. }
  455. }
  456. $oPage->add("</ul>\n");
  457. $oPage->add("</li>\n");
  458. }
  459. }
  460. $oPage->add_ready_script('$("#RelationshipDetails").treeview();');
  461. }
  462. // Display the menu on the left
  463. $oAppContext = new ApplicationContext();
  464. $operation = utils::ReadParam('operation', '');
  465. $oPage = new iTopWebPage(Dict::S('UI:Schema:Title'));
  466. $oPage->no_cache();
  467. $operation = utils::ReadParam('operation', '');
  468. switch($operation)
  469. {
  470. case 'details_class':
  471. $sClass = utils::ReadParam('class', 'logRealObject');
  472. DisplayClassDetails($oPage, $sClass);
  473. break;
  474. case 'details_relation':
  475. $sRelCode = utils::ReadParam('relcode', '');
  476. DisplayRelationDetails($oPage, $sRelCode);
  477. break;
  478. case 'list':
  479. default:
  480. DisplayClassesList($oPage);
  481. }
  482. $oPage->output();
  483. ?>