schema.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. <?php
  2. // Copyright (C) 2010-2016 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * Presentation of the data model
  20. *
  21. * @copyright Copyright (C) 2010-2016 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  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, $sContext)
  34. {
  35. return "<a href=\"schema.php?operation=details_class&class=$sClass{$sContext}\" title=\"".MetaModel::GetClassDescription($sClass)."\">".MetaModel::GetName($sClass)." ($sClass)</a>";
  36. }
  37. /**
  38. * Helper for this page -> link to a class
  39. */
  40. function MakeRelationHLink($sRelCode, $sContext)
  41. {
  42. $sDesc = MetaModel::GetRelationDescription($sRelCode);
  43. return "<a href=\"schema.php?operation=details_relation&relcode=$sRelCode{$sContext}\" 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, $sContext)
  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 class=\"open\">".MakeClassHLink($sClassName, $sContext)."\n");
  71. DisplaySubclasses($oPage, $sClassName, $sContext);
  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, $sContext)
  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, $sContext), $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, $sContext)
  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, $sContext), MakeClassHLink($sLinkClass, $sContext), $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, $sContext)
  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, $sContext);
  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, $sContext)."$sVisited</li>\n");
  139. DisplayRelatedClassesBestInClass($oPage, $sRemoteClass, $iLevels, $aVisitedClasses, true, $sContext);
  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, $sContext)."::<em>$sExtKeyAttCode</em>$sVisited</li>\n");
  148. DisplayRelatedClassesBestInClass($oPage, $sRemoteClass, $iLevels, $aVisitedClasses, true, $sContext);
  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, $sContext)
  158. {
  159. $oPage->add("<h3>".Dict::Format('UI:Schema:Links:1-n', $sClass)."</h3>\n");
  160. DisplayReferencingClasses($oPage, $sClass, $sContext);
  161. $oPage->add("<h3>".Dict::Format('UI:Schema:Links:n-n', $sClass)."</h3>\n");
  162. DisplayLinkingClasses($oPage, $sClass, $sContext);
  163. $oPage->add("<h3>".Dict::S('UI:Schema:Links:All')."</h3>\n");
  164. $aEmpty = array();
  165. DisplayRelatedClassesBestInClass($oPage, $sClass, 4, $aEmpty, true, $sContext);
  166. }
  167. /**
  168. * Helper for the lifecycle details of a given class
  169. */
  170. function DisplayLifecycle($oPage, $sClass)
  171. {
  172. $sStateAttCode = MetaModel::GetStateAttributeCode($sClass);
  173. if (empty($sStateAttCode))
  174. {
  175. $oPage->p(Dict::S('UI:Schema:NoLifeCyle'));
  176. }
  177. else
  178. {
  179. $aStates = MetaModel::EnumStates($sClass);
  180. $aStimuli = MetaModel::EnumStimuli($sClass);
  181. $oPage->add("<img src=\"".utils::GetAbsoluteUrlAppRoot()."pages/graphviz.php?class=$sClass\">\n");
  182. $oPage->add("<h3>".Dict::S('UI:Schema:LifeCycleTransitions')."</h3>\n");
  183. $oPage->add("<ul>\n");
  184. foreach ($aStates as $sStateCode => $aStateDef)
  185. {
  186. $sStateLabel = MetaModel::GetStateLabel($sClass, $sStateCode);
  187. $sStateDescription = MetaModel::GetStateDescription($sClass, $sStateCode);
  188. $oPage->add("<li title=\"code: $sStateCode\">$sStateLabel <span style=\"color:grey;\">($sStateCode) $sStateDescription</span></li>\n");
  189. $oPage->add("<ul>\n");
  190. foreach(MetaModel::EnumTransitions($sClass, $sStateCode) as $sStimulusCode => $aTransitionDef)
  191. {
  192. $sStimulusLabel = $aStimuli[$sStimulusCode]->GetLabel();
  193. $sTargetStateLabel = MetaModel::GetStateLabel($sClass, $aTransitionDef['target_state']);
  194. if (count($aTransitionDef['actions']) > 0)
  195. {
  196. $aActionsDesc = array();
  197. foreach ($aTransitionDef['actions'] as $actionHandler)
  198. {
  199. if (is_string($actionHandler))
  200. {
  201. $aActionsDesc[] = $actionHandler;
  202. }
  203. else
  204. {
  205. $aParamsDesc = array();
  206. foreach ($actionHandler['params'] as $aParamData)
  207. {
  208. $aParamsDesc[] = $aParamData['type'].':'.$aParamData['value'];
  209. }
  210. $aActionsDesc[] = $actionHandler['verb'].'('.implode(', ', $aParamsDesc).')';
  211. }
  212. }
  213. $sActions = " <em>(".implode(', ', $aActionsDesc).")</em>";
  214. }
  215. else
  216. {
  217. $sActions = "";
  218. }
  219. $oPage->add("<li><span title=\"code: $sStimulusCode\" style=\"color:red;font-weight=bold;\">$sStimulusLabel</span> =&gt; $sTargetStateLabel $sActions</li>\n");
  220. }
  221. $oPage->add("</ul>\n");
  222. }
  223. $oPage->add("</ul>\n");
  224. $oPage->add("<h3>".Dict::S('UI:Schema:LifeCyleAttributeOptions')."</h3>\n");
  225. $oPage->add("<ul>\n");
  226. foreach ($aStates as $sStateCode => $aStateDef)
  227. {
  228. $sStateLabel = MetaModel::GetStateLabel($sClass, $sStateCode);
  229. $sStateDescription = MetaModel::GetStateDescription($sClass, $sStateCode);
  230. $oPage->add("<li title=\"code: $sStateCode\">$sStateLabel <span style=\"color:grey;\">($sStateCode) $sStateDescription</span></li>\n");
  231. if (count($aStates[$sStateCode]['attribute_list']) > 0)
  232. {
  233. $oPage->add("<ul>\n");
  234. foreach($aStates[$sStateCode]['attribute_list'] as $sAttCode => $iOptions)
  235. {
  236. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  237. $sAttLabel = $oAttDef->GetLabel();
  238. $aOptions = array();
  239. if ($iOptions & OPT_ATT_HIDDEN) $aOptions[] = Dict::S('UI:Schema:LifeCycleHiddenAttribute');
  240. if ($iOptions & OPT_ATT_READONLY) $aOptions[] = Dict::S('UI:Schema:LifeCycleReadOnlyAttribute');
  241. if ($iOptions & OPT_ATT_MANDATORY) $aOptions[] = Dict::S('UI:Schema:LifeCycleMandatoryAttribute');
  242. if ($iOptions & OPT_ATT_MUSTCHANGE) $aOptions[] = Dict::S('UI:Schema:LifeCycleAttributeMustChange');
  243. if ($iOptions & OPT_ATT_MUSTPROMPT) $aOptions[] = Dict::S('UI:Schema:LifeCycleAttributeMustPrompt');
  244. if (count($aOptions))
  245. {
  246. $sOptions = implode(', ', $aOptions);
  247. }
  248. else
  249. {
  250. $sOptions = "";
  251. }
  252. $oPage->add("<li><span style=\"color:purple;font-weight=bold;\">$sAttLabel</span> $sOptions</li>\n");
  253. }
  254. $oPage->add("</ul>\n");
  255. }
  256. else
  257. {
  258. $oPage->p("<em>".Dict::S('UI:Schema:LifeCycleEmptyList')."</em>");
  259. }
  260. }
  261. $oPage->add("</ul>\n");
  262. }
  263. }
  264. /**
  265. * Helper for the trigger
  266. */
  267. function DisplayTriggers($oPage, $sClass)
  268. {
  269. $sClassList = implode("', '", MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL));
  270. $oSet = new CMDBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnObject WHERE target_class IN ('$sClassList')"));
  271. cmdbAbstractObject::DisplaySet($oPage, $oSet, array('block_id' => 'triggers'));
  272. }
  273. /**
  274. * Display the list of classes from the business model
  275. */
  276. function DisplayClassesList($oPage, $sContext)
  277. {
  278. $oPage->add("<h1>".Dict::S('UI:Schema:Title')."</h1>\n");
  279. $oPage->add("<ul id=\"ClassesList\" class=\"treeview fileview\">\n");
  280. // Get all the "root" classes for display
  281. $aRootClasses = array();
  282. foreach(MetaModel::GetClasses() as $sClassName)
  283. {
  284. if (MetaModel::IsRootClass($sClassName))
  285. {
  286. $aRootClasses[$sClassName] = MetaModel::GetName($sClassName);
  287. }
  288. elseif (MetaModel::IsStandaloneClass($sClassName))
  289. {
  290. $aRootClasses[$sClassName] = MetaModel::GetName($sClassName);
  291. }
  292. }
  293. // Sort them alphabetically on their display name
  294. asort($aRootClasses);
  295. foreach($aRootClasses as $sClassName => $sDisplayName)
  296. {
  297. if (MetaModel::IsRootClass($sClassName))
  298. {
  299. $oPage->add("<li class=\"open\">".MakeClassHLink($sClassName, $sContext)."\n");
  300. DisplaySubclasses($oPage, $sClassName, $sContext);
  301. $oPage->add("</li>\n");
  302. }
  303. elseif (MetaModel::IsStandaloneClass($sClassName))
  304. {
  305. $oPage->add("<li>".MakeClassHLink($sClassName, $sContext)."</li>\n");
  306. }
  307. }
  308. $oPage->add("</ul>\n");
  309. $oPage->add("<h1>".Dict::S('UI:Schema:Relationships')."</h1>\n");
  310. $oPage->add("<ul id=\"ClassesRelationships\" class=\"treeview\">\n");
  311. foreach (MetaModel::EnumRelations() as $sRelCode)
  312. {
  313. $oPage->add("<li>".MakeRelationHLink($sRelCode, $sContext)."\n");
  314. $oPage->add("<ul>\n");
  315. $oPage->add("<li>Description: ".htmlentities(MetaModel::GetRelationDescription($sRelCode), ENT_QUOTES, 'UTF-8')."</li>\n");
  316. $oPage->add("<li>Label: ".htmlentities(MetaModel::GetRelationLabel($sRelCode), ENT_QUOTES, 'UTF-8')."</li>\n");
  317. $oPage->add("</ul>\n");
  318. $oPage->add("</li>\n");
  319. }
  320. $oPage->add("</ul>\n");
  321. $oPage->add_ready_script('$("#ClassesList").treeview();');
  322. $oPage->add_ready_script('$("#ClassesRelationships").treeview();');
  323. }
  324. /**
  325. * Display the details of a given class of objects
  326. */
  327. function DisplayClassDetails($oPage, $sClass, $sContext)
  328. {
  329. $oPage->add("<h2>".MetaModel::GetName($sClass)." ($sClass) - ".MetaModel::GetClassDescription($sClass)."</h2>\n");
  330. if (MetaModel::IsAbstract($sClass))
  331. {
  332. $oPage->p(Dict::S('UI:Schema:AbstractClass'));
  333. }
  334. else
  335. {
  336. $oPage->p(Dict::S('UI:Schema:NonAbstractClass'));
  337. }
  338. // $oPage->p("<h3>".Dict::S('UI:Schema:ClassHierarchyTitle')."</h3>");
  339. $aParentClasses = array();
  340. foreach(MetaModel::EnumParentClasses($sClass) as $sParentClass)
  341. {
  342. $aParentClasses[] = MakeClassHLink($sParentClass, $sContext);
  343. }
  344. if (count($aParentClasses) > 0)
  345. {
  346. $sParents = implode(' &gt;&gt; ', $aParentClasses)." &gt;&gt; <b>$sClass</b>";
  347. }
  348. else
  349. {
  350. $sParents = '';
  351. }
  352. $oPage->p("[<a href=\"schema.php?operation=list{$sContext}\">".Dict::S('UI:Schema:AllClasses')."</a>] $sParents");
  353. if (MetaModel::HasChildrenClasses($sClass))
  354. {
  355. $oPage->add("<ul id=\"ClassHierarchy\">");
  356. $oPage->add("<li class=\"closed\">".$sClass."\n");
  357. DisplaySubclasses($oPage, $sClass,$sContext);
  358. $oPage->add("</li>\n");
  359. $oPage->add("</ul>\n");
  360. $oPage->add_ready_script('$("#ClassHierarchy").treeview();');
  361. }
  362. $oPage->p('');
  363. $oPage->AddTabContainer('details');
  364. $oPage->SetCurrentTabContainer('details');
  365. // List the attributes of the object
  366. $aForwardChangeTracking = MetaModel::GetTrackForwardExternalKeys($sClass);
  367. $aDetails = array();
  368. foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode=>$oAttDef)
  369. {
  370. if ($oAttDef->IsExternalKey())
  371. {
  372. $sValue = Dict::Format('UI:Schema:ExternalKey_To',MakeClassHLink($oAttDef->GetTargetClass(), $sContext));
  373. if (array_key_exists($sAttCode, $aForwardChangeTracking))
  374. {
  375. $oLinkSet = $aForwardChangeTracking[$sAttCode];
  376. $sRemoteClass = $oLinkSet->GetHostClass();
  377. $sValue = $sValue."<span title=\"Forward changes to $sRemoteClass\">*</span>";
  378. }
  379. }
  380. elseif ($oAttDef->IsLinkSet())
  381. {
  382. $sValue = MakeClassHLink($oAttDef->GetLinkedClass(), $sContext);
  383. }
  384. else
  385. {
  386. $sValue = $oAttDef->GetDescription();
  387. }
  388. $sType = $oAttDef->GetType().' ('.$oAttDef->GetTypeDesc().')';
  389. $sOrigin = MetaModel::GetAttributeOrigin($sClass, $sAttCode);
  390. $sAllowedValues = "";
  391. $sMoreInfo = "";
  392. $aCols = array();
  393. foreach($oAttDef->GetSQLColumns() as $sCol => $sFieldDesc)
  394. {
  395. $aCols[] = "$sCol: $sFieldDesc";
  396. }
  397. if (count($aCols) > 0)
  398. {
  399. $sCols = implode(', ', $aCols);
  400. $aMoreInfo = array();
  401. $aMoreInfo[] = Dict::Format('UI:Schema:Columns_Description', $sCols);
  402. $aMoreInfo[] = Dict::Format('UI:Schema:Default_Description', $oAttDef->GetDefaultValue());
  403. $aMoreInfo[] = $oAttDef->IsNullAllowed() ? Dict::S('UI:Schema:NullAllowed') : Dict::S('UI:Schema:NullNotAllowed');
  404. $sMoreInfo .= implode(', ', $aMoreInfo);
  405. }
  406. if ($oAttDef instanceof AttributeEnum)
  407. {
  408. // Display localized values for the enum (which depend on the localization provided by the class)
  409. $aLocalizedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, array());
  410. $aDescription = array();
  411. foreach($aLocalizedValues as $val => $sDisplay)
  412. {
  413. $aDescription[] = htmlentities("$val => ", ENT_QUOTES, 'UTF-8').$sDisplay;
  414. }
  415. $sAllowedValues = implode(', ', $aDescription);
  416. }
  417. elseif (is_object($oAllowedValuesDef = $oAttDef->GetValuesDef()))
  418. {
  419. $sAllowedValues = $oAllowedValuesDef->GetValuesDescription();
  420. }
  421. else
  422. {
  423. $sAllowedValues = '';
  424. }
  425. $aDetails[] = array('code' => $oAttDef->GetCode(), 'type' => $sType, 'origin' => $sOrigin, 'label' => $oAttDef->GetLabel(), 'description' => $sValue, 'values' => $sAllowedValues, 'moreinfo' => $sMoreInfo);
  426. }
  427. $oPage->SetCurrentTab(Dict::S('UI:Schema:Attributes'));
  428. $aConfig = array( 'code' => array('label' => Dict::S('UI:Schema:AttributeCode'), 'description' => Dict::S('UI:Schema:AttributeCode+')),
  429. 'label' => array('label' => Dict::S('UI:Schema:Label'), 'description' => Dict::S('UI:Schema:Label+')),
  430. 'type' => array('label' => Dict::S('UI:Schema:Type'), 'description' => Dict::S('UI:Schema:Type+')),
  431. 'origin' => array('label' => Dict::S('UI:Schema:Origin'), 'description' => Dict::S('UI:Schema:Origin+')),
  432. 'description' => array('label' => Dict::S('UI:Schema:Description'), 'description' => Dict::S('UI:Schema:Description+')),
  433. 'values' => array('label' => Dict::S('UI:Schema:AllowedValues'), 'description' => Dict::S('UI:Schema:AllowedValues+')),
  434. 'moreinfo' => array('label' => Dict::S('UI:Schema:MoreInfo'), 'description' => Dict::S('UI:Schema:MoreInfo+')),
  435. );
  436. $oPage->table($aConfig, $aDetails);
  437. // List the search criteria for this object
  438. $aDetails = array();
  439. foreach (MetaModel::GetClassFilterDefs($sClass) as $sFilterCode => $oFilterDef)
  440. {
  441. $aOpDescs = array();
  442. foreach ($oFilterDef->GetOperators() as $sOpCode => $sOpDescription)
  443. {
  444. $sIsTheLooser = ($sOpCode == $oFilterDef->GetLooseOperator()) ? " (loose search)" : "";
  445. $aOpDescs[] = "$sOpCode ($sOpDescription)$sIsTheLooser";
  446. }
  447. $aDetails[] = array( 'code' => $sFilterCode, 'description' => $oFilterDef->GetLabel(),'operators' => implode(" / ", $aOpDescs));
  448. }
  449. $oPage->SetCurrentTab(Dict::S('UI:Schema:SearchCriteria'));
  450. $aConfig = array( 'code' => array('label' => Dict::S('UI:Schema:FilterCode'), 'description' => Dict::S('UI:Schema:FilterCode+')),
  451. 'description' => array('label' => Dict::S('UI:Schema:FilterDescription'), 'description' => Dict::S('UI:Schema:FilterDescription+')),
  452. 'operators' => array('label' => Dict::S('UI:Schema:AvailOperators'), 'description' => Dict::S('UI:Schema:AvailOperators+'))
  453. );
  454. $oPage->table($aConfig, $aDetails);
  455. $oPage->SetCurrentTab(Dict::S('UI:Schema:ChildClasses'));
  456. DisplaySubclasses($oPage, $sClass, $sContext);
  457. $oPage->SetCurrentTab(Dict::S('UI:Schema:ReferencingClasses'));
  458. DisplayReferencingClasses($oPage, $sClass, $sContext);
  459. $oPage->SetCurrentTab(Dict::S('UI:Schema:RelatedClasses'));
  460. DisplayRelatedClasses($oPage, $sClass, $sContext);
  461. $oPage->SetCurrentTab(Dict::S('UI:Schema:LifeCycle'));
  462. DisplayLifecycle($oPage, $sClass, $sContext);
  463. $oPage->SetCurrentTab(Dict::S('UI:Schema:Triggers'));
  464. DisplayTriggers($oPage, $sClass, $sContext);
  465. $oPage->SetCurrentTab();
  466. $oPage->SetCurrentTabContainer();
  467. }
  468. /**
  469. * Display the details of a given relation (e.g. "impacts")
  470. */
  471. function DisplayRelationDetails($oPage, $sRelCode, $sContext)
  472. {
  473. $sDesc = MetaModel::GetRelationDescription($sRelCode);
  474. $sLabel = MetaModel::GetRelationLabel($sRelCode);
  475. $oPage->add("<h1>".Dict::Format('UI:Schema:Relation_Code_Description', $sRelCode, $sDesc)."</h1>");
  476. $oPage->p(Dict::Format('UI:Schema:RelationUp_Description', $sLabel));
  477. $oPage->add("<ul id=\"RelationshipDetails\" class=\"treeview\">\n");
  478. foreach(MetaModel::GetClasses() as $sClass)
  479. {
  480. $aRelQueries = MetaModel::EnumRelationQueries($sClass, $sRelCode);
  481. if (count($aRelQueries) > 0)
  482. {
  483. $oPage->add("<li>class ".MakeClassHLink($sClass, $sContext)."\n");
  484. $oPage->add("<ul>\n");
  485. foreach ($aRelQueries as $sRelKey => $aQuery)
  486. {
  487. $sQueryDown = isset($aQuery['sQueryDown']) ? $aQuery['sQueryDown'] : '';
  488. $sQueryUp = isset($aQuery['sQueryUp']) ? $aQuery['sQueryUp'] : '';
  489. $sAttribute = isset($aQuery['sAttribute']) ? $aQuery['sAttribute'] : '';
  490. /*
  491. if ($aQuery['bPropagate'])
  492. {
  493. $oPage->add("<li>".Dict::Format('UI:Schema:RelationPropagates', $sRelKey, $iDistance, $sQuery)."</li>\n");
  494. }
  495. else
  496. {
  497. $oPage->add("<li>".Dict::Format('UI:Schema:RelationDoesNotPropagate', $sRelKey, $iDistance, $sQuery)."</li>\n");
  498. }
  499. */
  500. $sLabel = (strlen($sQueryDown) > 0) ? $sQueryDown : $sAttribute;
  501. if ($aQuery['_legacy_'])
  502. {
  503. $sLabel .= ' (<b>Old style specification</b>: it is recommended to upgrade to XML)';
  504. }
  505. $oPage->add("<li>".$sLabel."</li>\n");
  506. }
  507. $oPage->add("</ul>\n");
  508. $oPage->add("</li>\n");
  509. }
  510. }
  511. $oPage->add_ready_script('$("#RelationshipDetails").treeview();');
  512. }
  513. // Display the menu on the left
  514. $oAppContext = new ApplicationContext();
  515. $sContext = $oAppContext->GetForLink();
  516. if (!empty($sContext))
  517. {
  518. $sContext = '&'.$sContext;
  519. }
  520. $operation = utils::ReadParam('operation', '');
  521. $oPage = new iTopWebPage(Dict::S('UI:Schema:Title'));
  522. $oPage->no_cache();
  523. $oPage->SetBreadCrumbEntry('ui-tool-datamodel', Dict::S('Menu:DataModelMenu'), Dict::S('Menu:DataModelMenu+'), '', utils::GetAbsoluteUrlAppRoot().'images/wrench.png');
  524. $operation = utils::ReadParam('operation', '');
  525. switch($operation)
  526. {
  527. case 'details_class':
  528. $sClass = utils::ReadParam('class', 'logRealObject', false, 'class');
  529. DisplayClassDetails($oPage, $sClass, $sContext);
  530. break;
  531. case 'details_relation':
  532. $sRelCode = utils::ReadParam('relcode', '');
  533. DisplayRelationDetails($oPage, $sRelCode, $sContext);
  534. break;
  535. case 'list':
  536. default:
  537. DisplayClassesList($oPage, $sContext);
  538. }
  539. $oPage->output();
  540. ?>