Comment.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <?php
  2. /**
  3. * PHPExcel_Comment
  4. *
  5. * Copyright (c) 2006 - 2015 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel
  23. * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. class PHPExcel_Comment implements PHPExcel_IComparable
  28. {
  29. /**
  30. * Author
  31. *
  32. * @var string
  33. */
  34. private $author;
  35. /**
  36. * Rich text comment
  37. *
  38. * @var PHPExcel_RichText
  39. */
  40. private $text;
  41. /**
  42. * Comment width (CSS style, i.e. XXpx or YYpt)
  43. *
  44. * @var string
  45. */
  46. private $width = '96pt';
  47. /**
  48. * Left margin (CSS style, i.e. XXpx or YYpt)
  49. *
  50. * @var string
  51. */
  52. private $marginLeft = '59.25pt';
  53. /**
  54. * Top margin (CSS style, i.e. XXpx or YYpt)
  55. *
  56. * @var string
  57. */
  58. private $marginTop = '1.5pt';
  59. /**
  60. * Visible
  61. *
  62. * @var boolean
  63. */
  64. private $visible = false;
  65. /**
  66. * Comment height (CSS style, i.e. XXpx or YYpt)
  67. *
  68. * @var string
  69. */
  70. private $height = '55.5pt';
  71. /**
  72. * Comment fill color
  73. *
  74. * @var PHPExcel_Style_Color
  75. */
  76. private $fillColor;
  77. /**
  78. * Alignment
  79. *
  80. * @var string
  81. */
  82. private $alignment;
  83. /**
  84. * Create a new PHPExcel_Comment
  85. *
  86. * @throws PHPExcel_Exception
  87. */
  88. public function __construct()
  89. {
  90. // Initialise variables
  91. $this->author = 'Author';
  92. $this->text = new PHPExcel_RichText();
  93. $this->fillColor = new PHPExcel_Style_Color('FFFFFFE1');
  94. $this->alignment = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
  95. }
  96. /**
  97. * Get Author
  98. *
  99. * @return string
  100. */
  101. public function getAuthor()
  102. {
  103. return $this->author;
  104. }
  105. /**
  106. * Set Author
  107. *
  108. * @param string $pValue
  109. * @return PHPExcel_Comment
  110. */
  111. public function setAuthor($pValue = '')
  112. {
  113. $this->author = $pValue;
  114. return $this;
  115. }
  116. /**
  117. * Get Rich text comment
  118. *
  119. * @return PHPExcel_RichText
  120. */
  121. public function getText()
  122. {
  123. return $this->text;
  124. }
  125. /**
  126. * Set Rich text comment
  127. *
  128. * @param PHPExcel_RichText $pValue
  129. * @return PHPExcel_Comment
  130. */
  131. public function setText(PHPExcel_RichText $pValue)
  132. {
  133. $this->text = $pValue;
  134. return $this;
  135. }
  136. /**
  137. * Get comment width (CSS style, i.e. XXpx or YYpt)
  138. *
  139. * @return string
  140. */
  141. public function getWidth()
  142. {
  143. return $this->width;
  144. }
  145. /**
  146. * Set comment width (CSS style, i.e. XXpx or YYpt)
  147. *
  148. * @param string $value
  149. * @return PHPExcel_Comment
  150. */
  151. public function setWidth($value = '96pt')
  152. {
  153. $this->width = $value;
  154. return $this;
  155. }
  156. /**
  157. * Get comment height (CSS style, i.e. XXpx or YYpt)
  158. *
  159. * @return string
  160. */
  161. public function getHeight()
  162. {
  163. return $this->height;
  164. }
  165. /**
  166. * Set comment height (CSS style, i.e. XXpx or YYpt)
  167. *
  168. * @param string $value
  169. * @return PHPExcel_Comment
  170. */
  171. public function setHeight($value = '55.5pt')
  172. {
  173. $this->height = $value;
  174. return $this;
  175. }
  176. /**
  177. * Get left margin (CSS style, i.e. XXpx or YYpt)
  178. *
  179. * @return string
  180. */
  181. public function getMarginLeft()
  182. {
  183. return $this->marginLeft;
  184. }
  185. /**
  186. * Set left margin (CSS style, i.e. XXpx or YYpt)
  187. *
  188. * @param string $value
  189. * @return PHPExcel_Comment
  190. */
  191. public function setMarginLeft($value = '59.25pt')
  192. {
  193. $this->marginLeft = $value;
  194. return $this;
  195. }
  196. /**
  197. * Get top margin (CSS style, i.e. XXpx or YYpt)
  198. *
  199. * @return string
  200. */
  201. public function getMarginTop()
  202. {
  203. return $this->marginTop;
  204. }
  205. /**
  206. * Set top margin (CSS style, i.e. XXpx or YYpt)
  207. *
  208. * @param string $value
  209. * @return PHPExcel_Comment
  210. */
  211. public function setMarginTop($value = '1.5pt')
  212. {
  213. $this->marginTop = $value;
  214. return $this;
  215. }
  216. /**
  217. * Is the comment visible by default?
  218. *
  219. * @return boolean
  220. */
  221. public function getVisible()
  222. {
  223. return $this->visible;
  224. }
  225. /**
  226. * Set comment default visibility
  227. *
  228. * @param boolean $value
  229. * @return PHPExcel_Comment
  230. */
  231. public function setVisible($value = false)
  232. {
  233. $this->visible = $value;
  234. return $this;
  235. }
  236. /**
  237. * Get fill color
  238. *
  239. * @return PHPExcel_Style_Color
  240. */
  241. public function getFillColor()
  242. {
  243. return $this->fillColor;
  244. }
  245. /**
  246. * Set Alignment
  247. *
  248. * @param string $pValue
  249. * @return PHPExcel_Comment
  250. */
  251. public function setAlignment($pValue = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL)
  252. {
  253. $this->alignment = $pValue;
  254. return $this;
  255. }
  256. /**
  257. * Get Alignment
  258. *
  259. * @return string
  260. */
  261. public function getAlignment()
  262. {
  263. return $this->alignment;
  264. }
  265. /**
  266. * Get hash code
  267. *
  268. * @return string Hash code
  269. */
  270. public function getHashCode()
  271. {
  272. return md5(
  273. $this->author .
  274. $this->text->getHashCode() .
  275. $this->width .
  276. $this->height .
  277. $this->marginLeft .
  278. $this->marginTop .
  279. ($this->visible ? 1 : 0) .
  280. $this->fillColor->getHashCode() .
  281. $this->alignment .
  282. __CLASS__
  283. );
  284. }
  285. /**
  286. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  287. */
  288. public function __clone()
  289. {
  290. $vars = get_object_vars($this);
  291. foreach ($vars as $key => $value) {
  292. if (is_object($value)) {
  293. $this->$key = clone $value;
  294. } else {
  295. $this->$key = $value;
  296. }
  297. }
  298. }
  299. /**
  300. * Convert to string
  301. *
  302. * @return string
  303. */
  304. public function __toString()
  305. {
  306. return $this->text->getPlainText();
  307. }
  308. }