customfieldshandler.class.inc.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. // Copyright (C) 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. use Combodo\iTop\Form\Form;
  19. use Combodo\iTop\Form\FormManager;
  20. /**
  21. * Base class to implement a handler for AttributeCustomFields
  22. *
  23. * @copyright Copyright (C) 2016 Combodo SARL
  24. * @license http://opensource.org/licenses/AGPL-3.0
  25. */
  26. abstract class CustomFieldsHandler
  27. {
  28. protected $sAttCode;
  29. protected $aValues;
  30. protected $oForm;
  31. /**
  32. * This constructor's prototype must be frozen.
  33. * Any specific behavior must be implemented in BuildForm()
  34. *
  35. * @param $sAttCode
  36. */
  37. final public function __construct($sAttCode)
  38. {
  39. $this->sAttCode = $sAttCode;
  40. $this->aValues = null;
  41. }
  42. abstract public function BuildForm(DBObject $oHostObject, $sFormId);
  43. /**
  44. *
  45. * @return \Combodo\iTop\Form\Form
  46. */
  47. public function GetForm()
  48. {
  49. return $this->oForm;
  50. }
  51. public function SetCurrentValues($aValues)
  52. {
  53. $this->aValues = $aValues;
  54. }
  55. static public function GetPrerequisiteAttributes($sClass = null)
  56. {
  57. return array();
  58. }
  59. /**
  60. * List the available verbs for 'GetForTemplate'
  61. */
  62. static public function EnumTemplateVerbs()
  63. {
  64. return array();
  65. }
  66. /**
  67. * Get various representations of the value, for insertion into a template (e.g. in Notifications)
  68. * @param $aValues array The current values
  69. * @param $sVerb string The verb specifying the representation of the value
  70. * @param $bLocalize bool Whether or not to localize the value
  71. * @return string
  72. */
  73. abstract public function GetForTemplate($aValues, $sVerb, $bLocalize = true);
  74. /**
  75. * @param $aValues
  76. * @param bool|true $bLocalize
  77. * @return mixed
  78. */
  79. abstract public function GetAsHTML($aValues, $bLocalize = true);
  80. /**
  81. * @param $aValues
  82. * @param bool|true $bLocalize
  83. * @return mixed
  84. */
  85. abstract public function GetAsXML($aValues, $bLocalize = true);
  86. /**
  87. * @param $aValues
  88. * @param string $sSeparator
  89. * @param string $sTextQualifier
  90. * @param bool|true $bLocalize
  91. * @return mixed
  92. */
  93. abstract public function GetAsCSV($aValues, $sSeparator = ',', $sTextQualifier = '"', $bLocalize = true);
  94. /**
  95. * @param DBObject $oHostObject
  96. * @return array Associative array id => value
  97. */
  98. abstract public function ReadValues(DBObject $oHostObject);
  99. /**
  100. * Record the data (currently in the processing of recording the host object)
  101. * It is assumed that the data has been checked prior to calling Write()
  102. * @param DBObject $oHostObject
  103. * @param array Associative array id => value
  104. */
  105. abstract public function WriteValues(DBObject $oHostObject, $aValues);
  106. /**
  107. * Cleanup data upon object deletion (object id still available here)
  108. * @param DBObject $oHostObject
  109. */
  110. abstract public function DeleteValues(DBObject $oHostObject);
  111. /**
  112. * @param $aValuesA
  113. * @param $aValuesB
  114. * @return bool
  115. */
  116. abstract public function CompareValues($aValuesA, $aValuesB);
  117. /**
  118. * String representation of the value, must depend solely on the semantics
  119. * @return string
  120. */
  121. abstract public function GetValueFingerprint();
  122. }