stimulus.class.inc.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. * Object lifecycle management: stimulus
  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. /**
  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. ?>