You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

332 lines
5.6 KiB

  1. <?php
  2. namespace PhpOffice\PhpSpreadsheet;
  3. use PhpOffice\PhpSpreadsheet\RichText\RichText;
  4. class Comment implements IComparable
  5. {
  6. /**
  7. * Author.
  8. *
  9. * @var string
  10. */
  11. private $author;
  12. /**
  13. * Rich text comment.
  14. *
  15. * @var RichText
  16. */
  17. private $text;
  18. /**
  19. * Comment width (CSS style, i.e. XXpx or YYpt).
  20. *
  21. * @var string
  22. */
  23. private $width = '96pt';
  24. /**
  25. * Left margin (CSS style, i.e. XXpx or YYpt).
  26. *
  27. * @var string
  28. */
  29. private $marginLeft = '59.25pt';
  30. /**
  31. * Top margin (CSS style, i.e. XXpx or YYpt).
  32. *
  33. * @var string
  34. */
  35. private $marginTop = '1.5pt';
  36. /**
  37. * Visible.
  38. *
  39. * @var bool
  40. */
  41. private $visible = false;
  42. /**
  43. * Comment height (CSS style, i.e. XXpx or YYpt).
  44. *
  45. * @var string
  46. */
  47. private $height = '55.5pt';
  48. /**
  49. * Comment fill color.
  50. *
  51. * @var Style\Color
  52. */
  53. private $fillColor;
  54. /**
  55. * Alignment.
  56. *
  57. * @var string
  58. */
  59. private $alignment;
  60. /**
  61. * Create a new Comment.
  62. */
  63. public function __construct()
  64. {
  65. // Initialise variables
  66. $this->author = 'Author';
  67. $this->text = new RichText();
  68. $this->fillColor = new Style\Color('FFFFFFE1');
  69. $this->alignment = Style\Alignment::HORIZONTAL_GENERAL;
  70. }
  71. /**
  72. * Get Author.
  73. *
  74. * @return string
  75. */
  76. public function getAuthor()
  77. {
  78. return $this->author;
  79. }
  80. /**
  81. * Set Author.
  82. *
  83. * @param string $author
  84. *
  85. * @return $this
  86. */
  87. public function setAuthor($author)
  88. {
  89. $this->author = $author;
  90. return $this;
  91. }
  92. /**
  93. * Get Rich text comment.
  94. *
  95. * @return RichText
  96. */
  97. public function getText()
  98. {
  99. return $this->text;
  100. }
  101. /**
  102. * Set Rich text comment.
  103. *
  104. * @param RichText $pValue
  105. *
  106. * @return $this
  107. */
  108. public function setText(RichText $pValue)
  109. {
  110. $this->text = $pValue;
  111. return $this;
  112. }
  113. /**
  114. * Get comment width (CSS style, i.e. XXpx or YYpt).
  115. *
  116. * @return string
  117. */
  118. public function getWidth()
  119. {
  120. return $this->width;
  121. }
  122. /**
  123. * Set comment width (CSS style, i.e. XXpx or YYpt).
  124. *
  125. * @param string $width
  126. *
  127. * @return $this
  128. */
  129. public function setWidth($width)
  130. {
  131. $this->width = $width;
  132. return $this;
  133. }
  134. /**
  135. * Get comment height (CSS style, i.e. XXpx or YYpt).
  136. *
  137. * @return string
  138. */
  139. public function getHeight()
  140. {
  141. return $this->height;
  142. }
  143. /**
  144. * Set comment height (CSS style, i.e. XXpx or YYpt).
  145. *
  146. * @param string $value
  147. *
  148. * @return $this
  149. */
  150. public function setHeight($value)
  151. {
  152. $this->height = $value;
  153. return $this;
  154. }
  155. /**
  156. * Get left margin (CSS style, i.e. XXpx or YYpt).
  157. *
  158. * @return string
  159. */
  160. public function getMarginLeft()
  161. {
  162. return $this->marginLeft;
  163. }
  164. /**
  165. * Set left margin (CSS style, i.e. XXpx or YYpt).
  166. *
  167. * @param string $value
  168. *
  169. * @return $this
  170. */
  171. public function setMarginLeft($value)
  172. {
  173. $this->marginLeft = $value;
  174. return $this;
  175. }
  176. /**
  177. * Get top margin (CSS style, i.e. XXpx or YYpt).
  178. *
  179. * @return string
  180. */
  181. public function getMarginTop()
  182. {
  183. return $this->marginTop;
  184. }
  185. /**
  186. * Set top margin (CSS style, i.e. XXpx or YYpt).
  187. *
  188. * @param string $value
  189. *
  190. * @return $this
  191. */
  192. public function setMarginTop($value)
  193. {
  194. $this->marginTop = $value;
  195. return $this;
  196. }
  197. /**
  198. * Is the comment visible by default?
  199. *
  200. * @return bool
  201. */
  202. public function getVisible()
  203. {
  204. return $this->visible;
  205. }
  206. /**
  207. * Set comment default visibility.
  208. *
  209. * @param bool $value
  210. *
  211. * @return $this
  212. */
  213. public function setVisible($value)
  214. {
  215. $this->visible = $value;
  216. return $this;
  217. }
  218. /**
  219. * Get fill color.
  220. *
  221. * @return Style\Color
  222. */
  223. public function getFillColor()
  224. {
  225. return $this->fillColor;
  226. }
  227. /**
  228. * Set Alignment.
  229. *
  230. * @param string $alignment see Style\Alignment::HORIZONTAL_*
  231. *
  232. * @return $this
  233. */
  234. public function setAlignment($alignment)
  235. {
  236. $this->alignment = $alignment;
  237. return $this;
  238. }
  239. /**
  240. * Get Alignment.
  241. *
  242. * @return string
  243. */
  244. public function getAlignment()
  245. {
  246. return $this->alignment;
  247. }
  248. /**
  249. * Get hash code.
  250. *
  251. * @return string Hash code
  252. */
  253. public function getHashCode()
  254. {
  255. return md5(
  256. $this->author .
  257. $this->text->getHashCode() .
  258. $this->width .
  259. $this->height .
  260. $this->marginLeft .
  261. $this->marginTop .
  262. ($this->visible ? 1 : 0) .
  263. $this->fillColor->getHashCode() .
  264. $this->alignment .
  265. __CLASS__
  266. );
  267. }
  268. /**
  269. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  270. */
  271. public function __clone()
  272. {
  273. $vars = get_object_vars($this);
  274. foreach ($vars as $key => $value) {
  275. if (is_object($value)) {
  276. $this->$key = clone $value;
  277. } else {
  278. $this->$key = $value;
  279. }
  280. }
  281. }
  282. /**
  283. * Convert to string.
  284. *
  285. * @return string
  286. */
  287. public function __toString()
  288. {
  289. return $this->text->getPlainText();
  290. }
  291. }