customfieldshandler.class.inc.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 $oHostObject;
  29. protected $sAttCode;
  30. protected $aValues;
  31. protected $oForm;
  32. /**
  33. * This constructor's prototype must be frozen.
  34. * Any specific behavior must be implemented in BuildForm()
  35. *
  36. * @param DBObject $oHostObject
  37. * @param $sAttCode
  38. */
  39. final public function __construct(DBObject $oHostObject, $sAttCode)
  40. {
  41. $this->oHostObject = $oHostObject;
  42. $this->sAttCode = $sAttCode;
  43. $this->aValues = null;
  44. }
  45. abstract public function BuildForm($sFormId);
  46. /**
  47. *
  48. * @return \Combodo\iTop\Form\Form
  49. */
  50. public function GetForm()
  51. {
  52. return $this->oForm;
  53. }
  54. public function SetCurrentValues($aValues)
  55. {
  56. $this->aValues = $aValues;
  57. }
  58. static public function GetPrerequisiteAttributes($sClass = null)
  59. {
  60. return array();
  61. }
  62. /**
  63. * List the available verbs for 'GetForTemplate'
  64. */
  65. static public function EnumTemplateVerbs()
  66. {
  67. return array();
  68. }
  69. /**
  70. * Get various representations of the value, for insertion into a template (e.g. in Notifications)
  71. * @param $aValues array The current values
  72. * @param $sVerb string The verb specifying the representation of the value
  73. * @param $bLocalize bool Whether or not to localize the value
  74. * @return string
  75. */
  76. abstract public function GetForTemplate($aValues, $sVerb, $bLocalize = true);
  77. /**
  78. * @param $aValues
  79. * @param bool|true $bLocalize
  80. * @return mixed
  81. */
  82. abstract public function GetAsHTML($aValues, $bLocalize = true);
  83. /**
  84. * @param $aValues
  85. * @param bool|true $bLocalize
  86. * @return mixed
  87. */
  88. abstract public function GetAsXML($aValues, $bLocalize = true);
  89. /**
  90. * @param $aValues
  91. * @param string $sSeparator
  92. * @param string $sTextQualifier
  93. * @param bool|true $bLocalize
  94. * @return mixed
  95. */
  96. abstract public function GetAsCSV($aValues, $sSeparator = ',', $sTextQualifier = '"', $bLocalize = true);
  97. /**
  98. * @return array Associative array id => value
  99. */
  100. abstract public function ReadValues();
  101. /**
  102. * Record the data (currently in the processing of recording the host object)
  103. * It is assumed that the data has been checked prior to calling Write()
  104. * @param array Associative array id => value
  105. */
  106. abstract public function WriteValues($aValues);
  107. /**
  108. * Cleanup data upon object deletion (object id still available here)
  109. */
  110. abstract public function DeleteValues();
  111. }