[1] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * PHPExcel |
---|
| 4 | * |
---|
| 5 | * Copyright (c) 2006 - 2014 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 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) |
---|
| 24 | * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL |
---|
| 25 | * @version 1.8.0, 2014-03-02 |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | /** |
---|
| 30 | * PHPExcel_Comment |
---|
| 31 | * |
---|
| 32 | * @category PHPExcel |
---|
| 33 | * @package PHPExcel |
---|
| 34 | * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) |
---|
| 35 | */ |
---|
| 36 | class PHPExcel_Comment implements PHPExcel_IComparable |
---|
| 37 | { |
---|
| 38 | /** |
---|
| 39 | * Author |
---|
| 40 | * |
---|
| 41 | * @var string |
---|
| 42 | */ |
---|
| 43 | private $_author; |
---|
| 44 | |
---|
| 45 | /** |
---|
| 46 | * Rich text comment |
---|
| 47 | * |
---|
| 48 | * @var PHPExcel_RichText |
---|
| 49 | */ |
---|
| 50 | private $_text; |
---|
| 51 | |
---|
| 52 | /** |
---|
| 53 | * Comment width (CSS style, i.e. XXpx or YYpt) |
---|
| 54 | * |
---|
| 55 | * @var string |
---|
| 56 | */ |
---|
| 57 | private $_width = '96pt'; |
---|
| 58 | |
---|
| 59 | /** |
---|
| 60 | * Left margin (CSS style, i.e. XXpx or YYpt) |
---|
| 61 | * |
---|
| 62 | * @var string |
---|
| 63 | */ |
---|
| 64 | private $_marginLeft = '59.25pt'; |
---|
| 65 | |
---|
| 66 | /** |
---|
| 67 | * Top margin (CSS style, i.e. XXpx or YYpt) |
---|
| 68 | * |
---|
| 69 | * @var string |
---|
| 70 | */ |
---|
| 71 | private $_marginTop = '1.5pt'; |
---|
| 72 | |
---|
| 73 | /** |
---|
| 74 | * Visible |
---|
| 75 | * |
---|
| 76 | * @var boolean |
---|
| 77 | */ |
---|
| 78 | private $_visible = false; |
---|
| 79 | |
---|
| 80 | /** |
---|
| 81 | * Comment height (CSS style, i.e. XXpx or YYpt) |
---|
| 82 | * |
---|
| 83 | * @var string |
---|
| 84 | */ |
---|
| 85 | private $_height = '55.5pt'; |
---|
| 86 | |
---|
| 87 | /** |
---|
| 88 | * Comment fill color |
---|
| 89 | * |
---|
| 90 | * @var PHPExcel_Style_Color |
---|
| 91 | */ |
---|
| 92 | private $_fillColor; |
---|
| 93 | |
---|
| 94 | /** |
---|
| 95 | * Alignment |
---|
| 96 | * |
---|
| 97 | * @var string |
---|
| 98 | */ |
---|
| 99 | private $_alignment; |
---|
| 100 | |
---|
| 101 | /** |
---|
| 102 | * Create a new PHPExcel_Comment |
---|
| 103 | * |
---|
| 104 | * @throws PHPExcel_Exception |
---|
| 105 | */ |
---|
| 106 | public function __construct() |
---|
| 107 | { |
---|
| 108 | // Initialise variables |
---|
| 109 | $this->_author = 'Author'; |
---|
| 110 | $this->_text = new PHPExcel_RichText(); |
---|
| 111 | $this->_fillColor = new PHPExcel_Style_Color('FFFFFFE1'); |
---|
| 112 | $this->_alignment = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | /** |
---|
| 116 | * Get Author |
---|
| 117 | * |
---|
| 118 | * @return string |
---|
| 119 | */ |
---|
| 120 | public function getAuthor() { |
---|
| 121 | return $this->_author; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | /** |
---|
| 125 | * Set Author |
---|
| 126 | * |
---|
| 127 | * @param string $pValue |
---|
| 128 | * @return PHPExcel_Comment |
---|
| 129 | */ |
---|
| 130 | public function setAuthor($pValue = '') { |
---|
| 131 | $this->_author = $pValue; |
---|
| 132 | return $this; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | /** |
---|
| 136 | * Get Rich text comment |
---|
| 137 | * |
---|
| 138 | * @return PHPExcel_RichText |
---|
| 139 | */ |
---|
| 140 | public function getText() { |
---|
| 141 | return $this->_text; |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | /** |
---|
| 145 | * Set Rich text comment |
---|
| 146 | * |
---|
| 147 | * @param PHPExcel_RichText $pValue |
---|
| 148 | * @return PHPExcel_Comment |
---|
| 149 | */ |
---|
| 150 | public function setText(PHPExcel_RichText $pValue) { |
---|
| 151 | $this->_text = $pValue; |
---|
| 152 | return $this; |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | /** |
---|
| 156 | * Get comment width (CSS style, i.e. XXpx or YYpt) |
---|
| 157 | * |
---|
| 158 | * @return string |
---|
| 159 | */ |
---|
| 160 | public function getWidth() { |
---|
| 161 | return $this->_width; |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | /** |
---|
| 165 | * Set comment width (CSS style, i.e. XXpx or YYpt) |
---|
| 166 | * |
---|
| 167 | * @param string $value |
---|
| 168 | * @return PHPExcel_Comment |
---|
| 169 | */ |
---|
| 170 | public function setWidth($value = '96pt') { |
---|
| 171 | $this->_width = $value; |
---|
| 172 | return $this; |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | /** |
---|
| 176 | * Get comment height (CSS style, i.e. XXpx or YYpt) |
---|
| 177 | * |
---|
| 178 | * @return string |
---|
| 179 | */ |
---|
| 180 | public function getHeight() { |
---|
| 181 | return $this->_height; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | /** |
---|
| 185 | * Set comment height (CSS style, i.e. XXpx or YYpt) |
---|
| 186 | * |
---|
| 187 | * @param string $value |
---|
| 188 | * @return PHPExcel_Comment |
---|
| 189 | */ |
---|
| 190 | public function setHeight($value = '55.5pt') { |
---|
| 191 | $this->_height = $value; |
---|
| 192 | return $this; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | /** |
---|
| 196 | * Get left margin (CSS style, i.e. XXpx or YYpt) |
---|
| 197 | * |
---|
| 198 | * @return string |
---|
| 199 | */ |
---|
| 200 | public function getMarginLeft() { |
---|
| 201 | return $this->_marginLeft; |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | /** |
---|
| 205 | * Set left margin (CSS style, i.e. XXpx or YYpt) |
---|
| 206 | * |
---|
| 207 | * @param string $value |
---|
| 208 | * @return PHPExcel_Comment |
---|
| 209 | */ |
---|
| 210 | public function setMarginLeft($value = '59.25pt') { |
---|
| 211 | $this->_marginLeft = $value; |
---|
| 212 | return $this; |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | /** |
---|
| 216 | * Get top margin (CSS style, i.e. XXpx or YYpt) |
---|
| 217 | * |
---|
| 218 | * @return string |
---|
| 219 | */ |
---|
| 220 | public function getMarginTop() { |
---|
| 221 | return $this->_marginTop; |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | /** |
---|
| 225 | * Set top margin (CSS style, i.e. XXpx or YYpt) |
---|
| 226 | * |
---|
| 227 | * @param string $value |
---|
| 228 | * @return PHPExcel_Comment |
---|
| 229 | */ |
---|
| 230 | public function setMarginTop($value = '1.5pt') { |
---|
| 231 | $this->_marginTop = $value; |
---|
| 232 | return $this; |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | /** |
---|
| 236 | * Is the comment visible by default? |
---|
| 237 | * |
---|
| 238 | * @return boolean |
---|
| 239 | */ |
---|
| 240 | public function getVisible() { |
---|
| 241 | return $this->_visible; |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | /** |
---|
| 245 | * Set comment default visibility |
---|
| 246 | * |
---|
| 247 | * @param boolean $value |
---|
| 248 | * @return PHPExcel_Comment |
---|
| 249 | */ |
---|
| 250 | public function setVisible($value = false) { |
---|
| 251 | $this->_visible = $value; |
---|
| 252 | return $this; |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | /** |
---|
| 256 | * Get fill color |
---|
| 257 | * |
---|
| 258 | * @return PHPExcel_Style_Color |
---|
| 259 | */ |
---|
| 260 | public function getFillColor() { |
---|
| 261 | return $this->_fillColor; |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | /** |
---|
| 265 | * Set Alignment |
---|
| 266 | * |
---|
| 267 | * @param string $pValue |
---|
| 268 | * @return PHPExcel_Comment |
---|
| 269 | */ |
---|
| 270 | public function setAlignment($pValue = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL) { |
---|
| 271 | $this->_alignment = $pValue; |
---|
| 272 | return $this; |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | /** |
---|
| 276 | * Get Alignment |
---|
| 277 | * |
---|
| 278 | * @return string |
---|
| 279 | */ |
---|
| 280 | public function getAlignment() { |
---|
| 281 | return $this->_alignment; |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | /** |
---|
| 285 | * Get hash code |
---|
| 286 | * |
---|
| 287 | * @return string Hash code |
---|
| 288 | */ |
---|
| 289 | public function getHashCode() { |
---|
| 290 | return md5( |
---|
| 291 | $this->_author |
---|
| 292 | . $this->_text->getHashCode() |
---|
| 293 | . $this->_width |
---|
| 294 | . $this->_height |
---|
| 295 | . $this->_marginLeft |
---|
| 296 | . $this->_marginTop |
---|
| 297 | . ($this->_visible ? 1 : 0) |
---|
| 298 | . $this->_fillColor->getHashCode() |
---|
| 299 | . $this->_alignment |
---|
| 300 | . __CLASS__ |
---|
| 301 | ); |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | /** |
---|
| 305 | * Implement PHP __clone to create a deep clone, not just a shallow copy. |
---|
| 306 | */ |
---|
| 307 | public function __clone() { |
---|
| 308 | $vars = get_object_vars($this); |
---|
| 309 | foreach ($vars as $key => $value) { |
---|
| 310 | if (is_object($value)) { |
---|
| 311 | $this->$key = clone $value; |
---|
| 312 | } else { |
---|
| 313 | $this->$key = $value; |
---|
| 314 | } |
---|
| 315 | } |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | /** |
---|
| 319 | * Convert to string |
---|
| 320 | * |
---|
| 321 | * @return string |
---|
| 322 | */ |
---|
| 323 | public function __toString() { |
---|
| 324 | return $this->_text->getPlainText(); |
---|
| 325 | } |
---|
| 326 | |
---|
| 327 | } |
---|