schema.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. <?php
  2. require_once('../application/application.inc.php');
  3. require_once('../application/itopwebpage.class.inc.php');
  4. require_once('../application/startup.inc.php');
  5. /**
  6. * Helper for this page -> link to a class
  7. */
  8. function MakeClassHLink($sClass)
  9. {
  10. return "<a href=\"?operation=details_class&class=$sClass\" title=\"".MetaModel::GetClassDescription($sClass)."\">".MetaModel::GetName($sClass)."</a>";
  11. }
  12. /**
  13. * Helper for this page -> link to a class
  14. */
  15. function MakeRelationHLink($sRelCode)
  16. {
  17. $sDec = MetaModel::GetRelationProperty($sRelCode, 'description');
  18. //$sVerbDown = MetaModel::GetRelationProperty($sRelCode, 'verb_down');
  19. //$sVerbUp = MetaModel::GetRelationProperty($sRelCode, 'verb_up');
  20. return "<a href=\"?operation=details_relation&relcode=$sRelCode\" title=\"$sDec\">".$sRelCode."</a>";
  21. }
  22. /**
  23. * Helper for the global list and the details of a given class
  24. */
  25. function DisplaySubclasses($oPage, $sClass)
  26. {
  27. $aChildClasses = MetaModel::EnumChildClasses($sClass);
  28. if (count($aChildClasses) != 0)
  29. {
  30. $oPage->add("<ul>\n");
  31. foreach($aChildClasses as $sClassName)
  32. {
  33. // Skip indirect childs, they will be handled somewhere else
  34. if (MetaModel::GetParentPersistentClass($sClassName) == $sClass)
  35. {
  36. $oPage->add("<li>".MakeClassHLink($sClassName)."\n");
  37. DisplaySubclasses($oPage, $sClassName);
  38. $oPage->add("</li>\n");
  39. }
  40. }
  41. $oPage->add("</ul>\n");
  42. }
  43. }
  44. /**
  45. * Helper for the global list and the details of a given class
  46. */
  47. function DisplayReferencingClasses($oPage, $sClass)
  48. {
  49. $bSkipLinkingClasses = false;
  50. $aRefs = MetaModel::EnumReferencingClasses($sClass, $bSkipLinkingClasses);
  51. if (count($aRefs) != 0)
  52. {
  53. $oPage->add("<ul>\n");
  54. foreach ($aRefs as $sRemoteClass => $aRemoteKeys)
  55. {
  56. foreach ($aRemoteKeys as $sExtKeyAttCode => $oExtKeyAttDef)
  57. {
  58. $oPage->add("<li>".MakeClassHLink($sRemoteClass)." by <em>$sExtKeyAttCode</em></li>\n");
  59. }
  60. }
  61. $oPage->add("</ul>\n");
  62. }
  63. }
  64. /**
  65. * Helper for the global list and the details of a given class
  66. */
  67. function DisplayLinkingClasses($oPage, $sClass)
  68. {
  69. $bSkipLinkingClasses = false;
  70. $aRefs = MetaModel::EnumLinkingClasses($sClass);
  71. if (count($aRefs) != 0)
  72. {
  73. $oPage->add("<ul>\n");
  74. foreach ($aRefs as $sLinkClass => $aRemoteClasses)
  75. {
  76. foreach($aRemoteClasses as $sExtKeyAttCode => $sRemoteClass)
  77. {
  78. $oPage->add("<li>".MakeClassHLink($sRemoteClass)." by <em>".MakeClassHLink($sLinkClass)."::$sExtKeyAttCode</em></li>\n");
  79. }
  80. }
  81. $oPage->add("</ul>\n");
  82. }
  83. }
  84. /**
  85. * Helper for the global list and the details of a given class
  86. */
  87. function DisplayRelatedClassesBestInClass($oPage, $sClass, $iLevels = 20, &$aVisitedClasses = array(), $bSubtree = true)
  88. {
  89. if ($iLevels <= 0) return;
  90. $iLevels--;
  91. if (array_key_exists($sClass, $aVisitedClasses)) return;
  92. $aVisitedClasses[$sClass] = true;
  93. if ($bSubtree) $oPage->add("<ul class=\"treeview\">\n");
  94. foreach (MetaModel::EnumParentClasses($sClass) as $sParentClass)
  95. {
  96. DisplayRelatedClassesBestInClass($oPage, $sParentClass, $iLevels, $aVisitedClasses, false);
  97. }
  98. ////$oPage->add("<div style=\"background-color:#ccc; border: 1px dashed #333;\">");
  99. foreach (MetaModel::EnumReferencedClasses($sClass) as $sExtKeyAttCode => $sRemoteClass)
  100. {
  101. $sVisited = (array_key_exists($sRemoteClass, $aVisitedClasses)) ? " ..." : "";
  102. if (MetaModel::GetAttributeOrigin($sClass, $sExtKeyAttCode) == $sClass)
  103. {
  104. $oPage->add("<li>$sClass| <em>$sExtKeyAttCode</em> =&gt;".MakeClassHLink($sRemoteClass)."$sVisited</li>\n");
  105. DisplayRelatedClassesBestInClass($oPage, $sRemoteClass, $iLevels, $aVisitedClasses);
  106. }
  107. }
  108. foreach (MetaModel::EnumReferencingClasses($sClass) as $sRemoteClass => $aRemoteKeys)
  109. {
  110. foreach ($aRemoteKeys as $sExtKeyAttCode => $oExtKeyAttDef)
  111. {
  112. $sVisited = (array_key_exists($sRemoteClass, $aVisitedClasses)) ? " ..." : "";
  113. $oPage->add("<li>$sClass| &lt;=".MakeClassHLink($sRemoteClass)."::<em>$sExtKeyAttCode</em>$sVisited</li>\n");
  114. DisplayRelatedClassesBestInClass($oPage, $sRemoteClass, $iLevels, $aVisitedClasses);
  115. }
  116. }
  117. ////$oPage->add("</div>");
  118. if ($bSubtree) $oPage->add("</ul>\n");
  119. }
  120. /**
  121. * Helper for the list of classes related to the given class
  122. */
  123. function DisplayRelatedClasses($oPage, $sClass)
  124. {
  125. $oPage->add("<h3>Childs</h3>\n");
  126. DisplaySubclasses($oPage, $sClass);
  127. $oPage->add("<h3>Pointed to by...</h3>\n");
  128. DisplayReferencingClasses($oPage, $sClass);
  129. $oPage->add("<h3>Linked to ...</h3>\n");
  130. DisplayLinkingClasses($oPage, $sClass);
  131. $oPage->add("<h3>ZE Graph ...</h3>\n");
  132. DisplayRelatedClassesBestInClass($oPage, $sClass, 4);
  133. }
  134. /**
  135. * Helper for the lifecycle details of a given class
  136. */
  137. function DisplayLifecycle($oPage, $sClass)
  138. {
  139. $sStateAttCode = MetaModel::GetStateAttributeCode($sClass);
  140. if (empty($sStateAttCode))
  141. {
  142. $oPage->p("no lifecycle for this class");
  143. }
  144. else
  145. {
  146. $aStates = MetaModel::EnumStates($sClass);
  147. $aStimuli = MetaModel::EnumStimuli($sClass);
  148. $oPage->add("<img src=\"../pages/graphviz.php?class=$sClass\">\n");
  149. $oPage->add("<h3>Transitions</h3>\n");
  150. $oPage->add("<ul>\n");
  151. foreach ($aStates as $sStateCode => $aStateDef)
  152. {
  153. $sStateLabel = MetaModel::GetStateLabel($sClass, $sStateCode);
  154. $sStateDescription = MetaModel::GetStateDescription($sClass, $sStateCode);
  155. $oPage->add("<li title=\"code: $sStateCode\">$sStateLabel <span style=\"color:grey;\">($sStateDescription)</span></li>\n");
  156. $oPage->add("<ul>\n");
  157. foreach(MetaModel::EnumTransitions($sClass, $sStateCode) as $sStimulusCode => $aTransitionDef)
  158. {
  159. $sStimulusLabel = $aStimuli[$sStimulusCode]->GetLabel();
  160. $sTargetStateLabel = MetaModel::GetStateLabel($sClass, $aTransitionDef['target_state']);
  161. if (count($aTransitionDef['actions']) > 0)
  162. {
  163. $sActions = " <em>(".implode(', ', $aTransitionDef['actions']).")</em>";
  164. }
  165. else
  166. {
  167. $sActions = "";
  168. }
  169. $oPage->add("<li><span style=\"color:red;font-weight=bold;\">$sStimulusLabel</span> =&gt; $sTargetStateLabel $sActions</li>\n");
  170. }
  171. $oPage->add("</ul>\n");
  172. }
  173. $oPage->add("</ul>\n");
  174. $oPage->add("<h3>Attribute options</h3>\n");
  175. $oPage->add("<ul>\n");
  176. foreach ($aStates as $sStateCode => $aStateDef)
  177. {
  178. $sStateLabel = MetaModel::GetStateLabel($sClass, $sStateCode);
  179. $sStateDescription = MetaModel::GetStateDescription($sClass, $sStateCode);
  180. $oPage->add("<li title=\"code: $sStateCode\">$sStateLabel <span style=\"color:grey;\">($sStateDescription)</span></li>\n");
  181. if (count($aStates[$sStateCode]['attribute_list']) > 0)
  182. {
  183. $oPage->add("<ul>\n");
  184. foreach($aStates[$sStateCode]['attribute_list'] as $sAttCode => $iOptions)
  185. {
  186. $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
  187. $sAttLabel = $oAttDef->GetLabel();
  188. $aOptions = array();
  189. if ($iOptions & OPT_ATT_HIDDEN) $aOptions[] = 'Hidden';
  190. if ($iOptions & OPT_ATT_READONLY) $aOptions[] = 'Read-only';
  191. if ($iOptions & OPT_ATT_MANDATORY) $aOptions[] = 'Mandatory';
  192. if ($iOptions & OPT_ATT_MUSTCHANGE) $aOptions[] = 'Must change';
  193. if ($iOptions & OPT_ATT_MUSTPROMPT) $aOptions[] = 'Must be proposed for changing';
  194. if (count($aOptions))
  195. {
  196. $sOptions = implode(', ', $aOptions);
  197. }
  198. else
  199. {
  200. $sOptions = "";
  201. }
  202. $oPage->add("<li><span style=\"color:purple;font-weight=bold;\">$sAttLabel</span> $sOptions</li>\n");
  203. }
  204. $oPage->add("</ul>\n");
  205. }
  206. else
  207. {
  208. $oPage->p("<em>empty list</em>");
  209. }
  210. }
  211. $oPage->add("</ul>\n");
  212. }
  213. }
  214. /**
  215. * Helper for the trigger
  216. */
  217. function DisplayTriggers($oPage, $sClass)
  218. {
  219. $oSet = new CMDBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnStateChange WHERE target_class = '$sClass'"));
  220. cmdbAbstractObject::DisplaySet($oPage, $oSet);
  221. }
  222. /**
  223. * Display the list of classes from the business model
  224. */
  225. function DisplayClassesList($oPage)
  226. {
  227. $oPage->add("<h1>iTop objects schema</h1>\n");
  228. $oPage->add("<ul id=\"ClassesList\" class=\"treeview fileview\">\n");
  229. foreach(MetaModel::EnumCategories() as $sCategory)
  230. {
  231. if (empty($sCategory)) continue; // means 'all' -> skip
  232. $sClosed = ($sCategory == 'bizmodel') ? '' : ' class="closed"';
  233. $oPage->add("<li$sClosed>Category <b>$sCategory</b>\n");
  234. $oPage->add("<ul>\n");
  235. foreach(MetaModel::GetClasses($sCategory) as $sClassName)
  236. {
  237. if (MetaModel::IsStandaloneClass($sClassName))
  238. {
  239. $oPage->add("<li>".MakeClassHLink($sClassName)."</li>\n");
  240. }
  241. else if (MetaModel::IsRootClass($sClassName))
  242. {
  243. $oPage->add("<li class=\"closed\">".MakeClassHLink($sClassName)."\n");
  244. DisplaySubclasses($oPage, $sClassName);
  245. $oPage->add("</li>\n");
  246. }
  247. }
  248. $oPage->add("</ul>\n");
  249. $oPage->add("</li>\n");
  250. }
  251. $oPage->add("</ul>\n");
  252. $oPage->add("<h1>Relationships</h1>\n");
  253. $oPage->add("<ul id=\"ClassesRelationships\" class=\"treeview\">\n");
  254. foreach (MetaModel::EnumRelations() as $sRelCode)
  255. {
  256. $oPage->add("<li>".MakeRelationHLink($sRelCode)."\n");
  257. $oPage->add("<ul>\n");
  258. foreach (MetaModel::EnumRelationProperties($sRelCode) as $sProp => $sValue)
  259. {
  260. $oPage->add("<li>$sProp: ".htmlentities($sValue)."</li>\n");
  261. }
  262. $oPage->add("</ul>\n");
  263. $oPage->add("</li>\n");
  264. }
  265. $oPage->add("</ul>\n");
  266. $oPage->add_ready_script('$("#ClassesList").treeview();');
  267. $oPage->add_ready_script('$("#ClassesRelationships").treeview();');
  268. }
  269. /**
  270. * Display the details of a given class of objects
  271. */
  272. function DisplayClassDetails($oPage, $sClass)
  273. {
  274. $oPage->p("<h2>$sClass</h2><br/>\n".MetaModel::GetClassDescription($sClass)."<br/>\n");
  275. $oPage->p("<h3>Class Hierarchy</h3>");
  276. $oPage->p("[<a href=\"?operation='list'\">All classes</a>]");
  277. // List the parent classes
  278. $sParent = MetaModel::GetParentPersistentClass($sClass);
  279. $aParents = array();
  280. $aParents[] = $sClass;
  281. while($sParent != "" && $sParent != 'cmdbAbstractObject')
  282. {
  283. $aParents[] = $sParent;
  284. $sParent = MetaModel::GetParentPersistentClass($sParent);
  285. }
  286. $iIndex = count($aParents);
  287. $sSpace ="";
  288. $oPage->add("<ul id=\"ClassHierarchy\">");
  289. while ($iIndex > 0)
  290. {
  291. $iIndex--;
  292. $oPage->add("<li>".MakeClassHLink($aParents[$iIndex])."\n");
  293. $oPage->add("<ul>\n");
  294. }
  295. for($iIndex = 0; $iIndex < count($aParents); $iIndex++)
  296. {
  297. $oPage->add("</ul>\n</li>\n");
  298. }
  299. $oPage->add("</ul>\n");
  300. $oPage->add_ready_script('$("#ClassHierarchy").treeview();');
  301. $oPage->p('');
  302. $oPage->AddTabContainer('details');
  303. $oPage->SetCurrentTabContainer('details');
  304. // List the attributes of the object
  305. $aDetails = array();
  306. foreach(MetaModel::ListAttributeDefs($sClass) as $sAttCode=>$oAttDef)
  307. {
  308. if ($oAttDef->IsExternalKey())
  309. {
  310. $sValue = "External key to ".MakeClassHLink($oAttDef->GetTargetClass());
  311. }
  312. else
  313. {
  314. $sValue = $oAttDef->GetDescription();
  315. }
  316. $sType = $oAttDef->GetType().' ('.$oAttDef->GetTypeDesc().')';
  317. $sOrigin = MetaModel::GetAttributeOrigin($sClass, $sAttCode);
  318. $sAllowedValues = "";
  319. $oAllowedValuesDef = $oAttDef->GetValuesDef();
  320. $sMoreInfo = "";
  321. $aCols = array();
  322. foreach($oAttDef->GetSQLColumns() as $sCol => $sFieldDesc)
  323. {
  324. $aCols[] = "$sCol: $sFieldDesc";
  325. }
  326. if (count($aCols) > 0)
  327. {
  328. $sCols = implode(', ', $aCols);
  329. $aMoreInfo = array();
  330. $aMoreInfo[] = "Column(s): <em>$sCols</em>";
  331. $aMoreInfo[] = "Default: '".$oAttDef->GetDefaultValue()."'";
  332. $aMoreInfo[] = $oAttDef->IsNullAllowed() ? "Null allowed" : "Null NOT allowed";
  333. $sMoreInfo .= implode(', ', $aMoreInfo);
  334. }
  335. if (is_object($oAllowedValuesDef)) $sAllowedValues = $oAllowedValuesDef->GetValuesDescription();
  336. else $sAllowedValues = '';
  337. $aDetails[] = array('code' => $oAttDef->GetCode(), 'type' => $sType, 'origin' => $sOrigin, 'label' => $oAttDef->GetLabel(), 'description' => $sValue, 'values' => $sAllowedValues, 'moreinfo' => $sMoreInfo);
  338. }
  339. $oPage->SetCurrentTab('Attributes');
  340. $aConfig = array( 'code' => array('label' => 'Attribute code', 'description' => 'Code of this attribute'),
  341. 'label' => array('label' => 'Label', 'description' => 'Label of this attribute'),
  342. 'type' => array('label' => 'Type', 'description' => 'Data type of this attribute'),
  343. 'origin' => array('label' => 'Origin', 'description' => 'The base class for this attribute'),
  344. 'description' => array('label' => 'Description', 'description' => 'Description of this attribute'),
  345. 'values' => array('label' => 'Allowed Values', 'description' => 'Restrictions on the possible values for this attribute'),
  346. 'moreinfo' => array('label' => 'More info', 'description' => 'More info for the fields related to a Database field'),
  347. );
  348. $oPage->table($aConfig, $aDetails);
  349. // List the search criteria for this object
  350. $aDetails = array();
  351. foreach (MetaModel::GetClassFilterDefs($sClass) as $sFilterCode => $oFilterDef)
  352. {
  353. $aOpDescs = array();
  354. foreach ($oFilterDef->GetOperators() as $sOpCode => $sOpDescription)
  355. {
  356. $sIsTheLooser = ($sOpCode == $oFilterDef->GetLooseOperator()) ? " (loose search)" : "";
  357. $aOpDescs[] = "$sOpCode ($sOpDescription)$sIsTheLooser";
  358. }
  359. $aDetails[] = array( 'code' => $sFilterCode, 'description' => $oFilterDef->GetLabel(),'operators' => implode(" / ", $aOpDescs));
  360. }
  361. $oPage->SetCurrentTab('Search criteria');
  362. $aConfig = array( 'code' => array('label' => 'Filter code', 'description' => 'Code of this search criteria'),
  363. 'description' => array('label' => 'Description', 'description' => 'Description of this search criteria'),
  364. 'operators' => array('label' => 'Available operators', 'description' => 'Possible operators for this search criteria')
  365. );
  366. $oPage->table($aConfig, $aDetails);
  367. $oPage->SetCurrentTab('Child classes');
  368. DisplaySubclasses($oPage, $sClass);
  369. $oPage->SetCurrentTab('Referencing classes');
  370. DisplayReferencingClasses($oPage, $sClass);
  371. $oPage->SetCurrentTab('Related classes');
  372. DisplayRelatedClasses($oPage, $sClass);
  373. $oPage->SetCurrentTab('Lifecycle');
  374. DisplayLifecycle($oPage, $sClass);
  375. $oPage->SetCurrentTab('Triggers');
  376. DisplayTriggers($oPage, $sClass);
  377. $oPage->SetCurrentTab();
  378. $oPage->SetCurrentTabContainer();
  379. }
  380. /**
  381. * Display the details of a given relation (e.g. "impacts")
  382. */
  383. function DisplayRelationDetails($oPage, $sRelCode)
  384. {
  385. $sDesc = MetaModel::GetRelationProperty($sRelCode, 'description');
  386. $sVerbDown = MetaModel::GetRelationProperty($sRelCode, 'verb_down');
  387. $sVerbUp = MetaModel::GetRelationProperty($sRelCode, 'verb_up');
  388. $oPage->add("<h1>Relation <em>$sRelCode</em> ($sDesc)</h1>");
  389. $oPage->p("Down: $sVerbDown");
  390. $oPage->p("Up: $sVerbUp");
  391. $oPage->add("<ul id=\"RelationshipDetails\" class=\"treeview\">\n");
  392. foreach(MetaModel::GetClasses() as $sClass)
  393. {
  394. $aRelQueries = MetaModel::EnumRelationQueries($sClass, $sRelCode);
  395. if (count($aRelQueries) > 0)
  396. {
  397. $oPage->add("<li>class ".MakeClassHLink($sClass)."\n");
  398. $oPage->add("<ul>\n");
  399. foreach ($aRelQueries as $sRelKey => $aQuery)
  400. {
  401. $sQuery = $aQuery['sQuery'];
  402. $bPropagate = $aQuery['bPropagate'] ? "Propagate" : "Do not propagate";
  403. $iDistance = $aQuery['iDistance'];
  404. $oPage->add("<li>$sRelKey: $bPropagate ($iDistance) ".DBObjectSearch::SibuSQLAsHtml($sQuery)."</li>\n");
  405. }
  406. $oPage->add("</ul>\n");
  407. $oPage->add("</li>\n");
  408. }
  409. }
  410. $oPage->add_ready_script('$("#RelationshipDetails").treeview();');
  411. }
  412. require_once('../application/loginwebpage.class.inc.php');
  413. LoginWebPage::DoLogin(); // Check user rights and prompt if needed
  414. // Display the menu on the left
  415. $oContext = new UserContext();
  416. $oAppContext = new ApplicationContext();
  417. $iActiveNodeId = utils::ReadParam('menu', -1);
  418. $currentOrganization = utils::ReadParam('org_id', 1);
  419. $operation = utils::ReadParam('operation', '');
  420. $oPage = new iTopWebPage("iTop objects schema", $currentOrganization);
  421. $oPage->no_cache();
  422. $operation = utils::ReadParam('operation', '');
  423. switch($operation)
  424. {
  425. case 'details_class':
  426. $sClass = utils::ReadParam('class', 'logRealObject');
  427. DisplayClassDetails($oPage, $sClass);
  428. break;
  429. case 'details_relation':
  430. $sRelCode = utils::ReadParam('relcode', '');
  431. DisplayRelationDetails($oPage, $sRelCode);
  432. break;
  433. case 'details':
  434. $oPage->p('operation=details has been deprecated, please use details_class');
  435. break;
  436. case 'list':
  437. default:
  438. DisplayClassesList($oPage);
  439. }
  440. $oPage->output();
  441. ?>