textareafield.class.inc.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. // Copyright (C) 2010-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. namespace Combodo\iTop\Form\Field;
  19. use \Closure;
  20. use \DBObject;
  21. use \InlineImage;
  22. use \AttributeText;
  23. use \Combodo\iTop\Form\Field\TextField;
  24. /**
  25. * Description of TextAreaField
  26. *
  27. * @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
  28. */
  29. class TextAreaField extends TextField
  30. {
  31. const ENUM_FORMAT_TEXT = 'text';
  32. const ENUM_FORMAT_HTML = 'html';
  33. const DEFAULT_FORMAT = 'html';
  34. protected $sFormat;
  35. protected $oObject;
  36. protected $sTransactionId;
  37. public function __construct($sId, Closure $onFinalizeCallback = null, DBObject $oObject = null)
  38. {
  39. parent::__construct($sId, $onFinalizeCallback);
  40. $this->sFormat = static::DEFAULT_FORMAT;
  41. $this->oObject = $oObject;
  42. $this->sTransactionId = null;
  43. }
  44. /**
  45. *
  46. * @return string
  47. */
  48. public function GetFormat()
  49. {
  50. return $this->sFormat;
  51. }
  52. /**
  53. *
  54. * @param string $sFormat
  55. * @return \Combodo\iTop\Form\Field\TextAreaField
  56. */
  57. public function SetFormat($sFormat)
  58. {
  59. $this->sFormat = $sFormat;
  60. return $this;
  61. }
  62. /**
  63. *
  64. * @return DBObject
  65. */
  66. public function GetObject()
  67. {
  68. return $this->oObject;
  69. }
  70. /**
  71. *
  72. * @param DBObject $oObject
  73. * @return \Combodo\iTop\Form\Field\TextAreaField
  74. */
  75. public function SetObject(DBObject $oObject)
  76. {
  77. $this->oObject = $oObject;
  78. return $this;
  79. }
  80. /**
  81. * Returns the transaction id for the field. This is usally used/setted when using a html format that allows upload of files/images
  82. *
  83. * @return string
  84. */
  85. public function GetTransactionId()
  86. {
  87. return $this->sTransactionId;
  88. }
  89. /**
  90. *
  91. * @param string $sTransactionId
  92. * @return \Combodo\iTop\Form\Field\TextAreaField
  93. */
  94. public function SetTransactionId($sTransactionId)
  95. {
  96. $this->sTransactionId = $sTransactionId;
  97. return $this;
  98. }
  99. public function GetDisplayValue()
  100. {
  101. if ($this->GetFormat() == TextAreaField::ENUM_FORMAT_TEXT)
  102. {
  103. $sValue = $this->GetCurrentValue();
  104. $sValue = AttributeText::RenderWikiHtml($sValue);
  105. return "<div>".str_replace("\n", "<br>\n", $sValue).'</div>';
  106. }
  107. else
  108. {
  109. $sValue = AttributeText::RenderWikiHtml($this->GetCurrentValue(), true /* wiki only */);
  110. return "<div class=\"HTML\">".InlineImage::FixUrls($sValue).'</div>';
  111. }
  112. }
  113. }