stimulus.class.inc.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * A stimulus is the trigger that makes the lifecycle go ahead (state machine)
  4. *
  5. * @package iTopORM
  6. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  7. * @author Denis Flaven <denisflave@free.fr>
  8. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  9. * @link www.itop.com
  10. * @since 1.0
  11. * @version 1.1.1.1 $
  12. */
  13. // #@# Really dirty !!!
  14. // #@# TO BE CLEANED -> ALIGN WITH OTHER METAMODEL DECLARATIONS
  15. class ObjectStimulus
  16. {
  17. private $m_aParams = array();
  18. private $m_sHostClass = null;
  19. private $m_sCode = null;
  20. public function __construct($sCode, $aParams)
  21. {
  22. $this->m_sCode = $sCode;
  23. $this->m_aParams = $aParams;
  24. $this->ConsistencyCheck();
  25. }
  26. public function SetHostClass($sHostClass)
  27. {
  28. $this->m_sHostClass = $sHostClass;
  29. }
  30. public function GetHostClass()
  31. {
  32. return $this->m_sHostClass;
  33. }
  34. public function GetCode()
  35. {
  36. return $this->m_sCode;
  37. }
  38. public function GetLabel()
  39. {
  40. return Dict::S('Class:'.$this->m_sHostClass.'/Stimulus:'.$this->m_sCode, $this->m_sCode);
  41. }
  42. public function GetDescription()
  43. {
  44. return Dict::S('Class:'.$this->m_sHostClass.'/Stimulus:'.$this->m_sCode.'+', '');
  45. }
  46. public function GetLabel_Obsolete()
  47. {
  48. // Written for compatibility with a data model written prior to version 0.9.1
  49. if (array_key_exists('label', $this->m_aParams))
  50. {
  51. return $this->m_aParams['label'];
  52. }
  53. else
  54. {
  55. return $this->GetLabel();
  56. }
  57. }
  58. public function GetDescription_Obsolete()
  59. {
  60. // Written for compatibility with a data model written prior to version 0.9.1
  61. if (array_key_exists('description', $this->m_aParams))
  62. {
  63. return $this->m_aParams['description'];
  64. }
  65. else
  66. {
  67. return $this->GetDescription();
  68. }
  69. }
  70. // obsolete- public function Get($sParamName) {return $this->m_aParams[$sParamName];}
  71. // Note: I could factorize this code with the parameter management made for the AttributeDef class
  72. // to be overloaded
  73. static protected function ListExpectedParams()
  74. {
  75. return array();
  76. }
  77. private function ConsistencyCheck()
  78. {
  79. // Check that any mandatory param has been specified
  80. //
  81. $aExpectedParams = $this->ListExpectedParams();
  82. foreach($aExpectedParams as $sParamName)
  83. {
  84. if (!array_key_exists($sParamName, $this->m_aParams))
  85. {
  86. $aBacktrace = debug_backtrace();
  87. $sTargetClass = $aBacktrace[2]["class"];
  88. $sCodeInfo = $aBacktrace[1]["file"]." - ".$aBacktrace[1]["line"];
  89. throw new CoreException("missing parameter '$sParamName' in ".get_class($this)." declaration for class $sTargetClass ($sCodeInfo)");
  90. }
  91. }
  92. }
  93. }
  94. class StimulusUserAction extends ObjectStimulus
  95. {
  96. }
  97. ?>