renderingoutput.class.inc.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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\Renderer;
  19. /**
  20. * Description of RenderingOutput
  21. *
  22. * @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
  23. */
  24. class RenderingOutput
  25. {
  26. protected $sHtml;
  27. protected $sJsInline;
  28. protected $aJsFiles;
  29. protected $sCssInline;
  30. protected $aCssFiles;
  31. protected $aCssClasses;
  32. public function __construct()
  33. {
  34. $this->sHtml = '';
  35. $this->sJsInline = '';
  36. $this->aJsFiles = array();
  37. $this->sCssInline = '';
  38. $this->aCssFiles = array();
  39. $this->aCssClasses = array();
  40. }
  41. /**
  42. *
  43. * @return string
  44. */
  45. public function GetHtml()
  46. {
  47. return $this->sHtml;
  48. }
  49. /**
  50. *
  51. * @return string
  52. */
  53. public function GetJs()
  54. {
  55. return $this->sJsInline;
  56. }
  57. /**
  58. *
  59. * @return array
  60. */
  61. public function GetJsFiles()
  62. {
  63. return $this->aJsFiles;
  64. }
  65. /**
  66. *
  67. * @return string
  68. */
  69. public function GetCss()
  70. {
  71. return $this->sCssInline;
  72. }
  73. /**
  74. *
  75. * @return array
  76. */
  77. public function GetCssFiles()
  78. {
  79. return $this->aCssFiles;
  80. }
  81. /**
  82. *
  83. * @return array
  84. */
  85. public function GetCssClasses()
  86. {
  87. return $this->aCssClasses;
  88. }
  89. /**
  90. *
  91. * @param string $sHtml
  92. * @return \Combodo\iTop\Renderer\RenderingOutput
  93. */
  94. public function AddHtml($sHtml, $bEncodeHtmlEntities = false)
  95. {
  96. $this->sHtml .= ($bEncodeHtmlEntities) ? htmlentities($sHtml, ENT_QUOTES, 'UTF-8') : $sHtml;
  97. return $this;
  98. }
  99. /**
  100. *
  101. * @param string $sJs
  102. * @return \Combodo\iTop\Renderer\RenderingOutput
  103. */
  104. public function AddJs($sJs)
  105. {
  106. $this->sJsInline .= $sJs . "\n";
  107. return $this;
  108. }
  109. /**
  110. *
  111. * @param string $sFile
  112. * @return \Combodo\iTop\Renderer\RenderingOutput
  113. */
  114. public function AddJsFile($sFile)
  115. {
  116. if (!in_array($sFile, $this->aJsFiles))
  117. {
  118. $this->aJsFiles[] = $sFile;
  119. }
  120. return $this;
  121. }
  122. /**
  123. *
  124. * @param string $sFile
  125. * @return \Combodo\iTop\Renderer\RenderingOutput
  126. */
  127. public function RemoveJsFile($sFile)
  128. {
  129. if (in_array($sFile, $this->aJsFiles))
  130. {
  131. unset($this->aJsFiles[$sFile]);
  132. }
  133. return $this;
  134. }
  135. /**
  136. *
  137. * @param string $sCss
  138. * @return \Combodo\iTop\Renderer\RenderingOutput
  139. */
  140. public function AddCss($sCss)
  141. {
  142. $this->sCssInline .= $sCss . "\n";
  143. return $this;
  144. }
  145. /**
  146. *
  147. * @param string $sFile
  148. * @return \Combodo\iTop\Renderer\RenderingOutput
  149. */
  150. public function AddCssFile($sFile)
  151. {
  152. if (!in_array($sFile, $this->aCssFiles))
  153. {
  154. $this->aCssFiles[] = $sFile;
  155. }
  156. return $this;
  157. }
  158. /**
  159. *
  160. * @param string $sFile
  161. * @return \Combodo\iTop\Renderer\RenderingOutput
  162. */
  163. public function RemoveCssFile($sFile)
  164. {
  165. if (in_array($sFile, $this->aCssFiles))
  166. {
  167. unset($this->aCssFiles[$sFile]);
  168. }
  169. return $this;
  170. }
  171. /**
  172. *
  173. * @param string $sClass
  174. * @return \Combodo\iTop\Renderer\RenderingOutput
  175. */
  176. public function AddCssClass($sClass)
  177. {
  178. if (!in_array($sClass, $this->aCssClasses))
  179. {
  180. $this->aCssClasses[] = $sClass;
  181. }
  182. return $this;
  183. }
  184. /**
  185. *
  186. * @param string $sClass
  187. * @return \Combodo\iTop\Renderer\RenderingOutput
  188. */
  189. public function RemoveCssClass($sClass)
  190. {
  191. if (in_array($sClass, $this->aCssClasses))
  192. {
  193. unset($this->aCssClasses[$sClass]);
  194. }
  195. return $this;
  196. }
  197. }