stimulus.class.inc.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. // Copyright (C) 2010-2012 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. * Object lifecycle management: stimulus
  20. *
  21. * @copyright Copyright (C) 2010-2012 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  23. */
  24. /**
  25. * A stimulus is the trigger that makes the lifecycle go ahead (state machine)
  26. *
  27. * @package iTopORM
  28. */
  29. // #@# Really dirty !!!
  30. // #@# TO BE CLEANED -> ALIGN WITH OTHER METAMODEL DECLARATIONS
  31. class ObjectStimulus
  32. {
  33. private $m_aParams = array();
  34. private $m_sHostClass = null;
  35. private $m_sCode = null;
  36. public function __construct($sCode, $aParams)
  37. {
  38. $this->m_sCode = $sCode;
  39. $this->m_aParams = $aParams;
  40. $this->ConsistencyCheck();
  41. }
  42. public function SetHostClass($sHostClass)
  43. {
  44. $this->m_sHostClass = $sHostClass;
  45. }
  46. public function GetHostClass()
  47. {
  48. return $this->m_sHostClass;
  49. }
  50. public function GetCode()
  51. {
  52. return $this->m_sCode;
  53. }
  54. public function GetLabel()
  55. {
  56. return Dict::S('Class:'.$this->m_sHostClass.'/Stimulus:'.$this->m_sCode, $this->m_sCode);
  57. }
  58. public function GetDescription()
  59. {
  60. return Dict::S('Class:'.$this->m_sHostClass.'/Stimulus:'.$this->m_sCode.'+', '');
  61. }
  62. public function GetLabel_Obsolete()
  63. {
  64. // Written for compatibility with a data model written prior to version 0.9.1
  65. if (array_key_exists('label', $this->m_aParams))
  66. {
  67. return $this->m_aParams['label'];
  68. }
  69. else
  70. {
  71. return $this->GetLabel();
  72. }
  73. }
  74. public function GetDescription_Obsolete()
  75. {
  76. // Written for compatibility with a data model written prior to version 0.9.1
  77. if (array_key_exists('description', $this->m_aParams))
  78. {
  79. return $this->m_aParams['description'];
  80. }
  81. else
  82. {
  83. return $this->GetDescription();
  84. }
  85. }
  86. // obsolete- public function Get($sParamName) {return $this->m_aParams[$sParamName];}
  87. // Note: I could factorize this code with the parameter management made for the AttributeDef class
  88. // to be overloaded
  89. static protected function ListExpectedParams()
  90. {
  91. return array();
  92. }
  93. private function ConsistencyCheck()
  94. {
  95. // Check that any mandatory param has been specified
  96. //
  97. $aExpectedParams = $this->ListExpectedParams();
  98. foreach($aExpectedParams as $sParamName)
  99. {
  100. if (!array_key_exists($sParamName, $this->m_aParams))
  101. {
  102. $aBacktrace = debug_backtrace();
  103. $sTargetClass = $aBacktrace[2]["class"];
  104. $sCodeInfo = $aBacktrace[1]["file"]." - ".$aBacktrace[1]["line"];
  105. throw new CoreException("missing parameter '$sParamName' in ".get_class($this)." declaration for class $sTargetClass ($sCodeInfo)");
  106. }
  107. }
  108. }
  109. }
  110. class StimulusUserAction extends ObjectStimulus
  111. {
  112. // Entry in the menus
  113. }
  114. class StimulusInternal extends ObjectStimulus
  115. {
  116. // Applied from page xxxx
  117. }
  118. ?>