MDL-63044 course: add get_enrolled_courses_by_timeline_classification
[moodle.git] / lib / phpexcel / PHPExcel / Worksheet / BaseDrawing.php
blob9ad15c70f3f2b8570b8f589a6345ce35b0d965df
1 <?php
3 /**
4 * PHPExcel_Worksheet_BaseDrawing
6 * Copyright (c) 2006 - 2015 PHPExcel
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 * @category PHPExcel
23 * @package PHPExcel_Worksheet
24 * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
25 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
26 * @version ##VERSION##, ##DATE##
28 class PHPExcel_Worksheet_BaseDrawing implements PHPExcel_IComparable
30 /**
31 * Image counter
33 * @var int
35 private static $imageCounter = 0;
37 /**
38 * Image index
40 * @var int
42 private $imageIndex = 0;
44 /**
45 * Name
47 * @var string
49 protected $name;
51 /**
52 * Description
54 * @var string
56 protected $description;
58 /**
59 * Worksheet
61 * @var PHPExcel_Worksheet
63 protected $worksheet;
65 /**
66 * Coordinates
68 * @var string
70 protected $coordinates;
72 /**
73 * Offset X
75 * @var int
77 protected $offsetX;
79 /**
80 * Offset Y
82 * @var int
84 protected $offsetY;
86 /**
87 * Width
89 * @var int
91 protected $width;
93 /**
94 * Height
96 * @var int
98 protected $height;
101 * Proportional resize
103 * @var boolean
105 protected $resizeProportional;
108 * Rotation
110 * @var int
112 protected $rotation;
115 * Shadow
117 * @var PHPExcel_Worksheet_Drawing_Shadow
119 protected $shadow;
122 * Create a new PHPExcel_Worksheet_BaseDrawing
124 public function __construct()
126 // Initialise values
127 $this->name = '';
128 $this->description = '';
129 $this->worksheet = null;
130 $this->coordinates = 'A1';
131 $this->offsetX = 0;
132 $this->offsetY = 0;
133 $this->width = 0;
134 $this->height = 0;
135 $this->resizeProportional = true;
136 $this->rotation = 0;
137 $this->shadow = new PHPExcel_Worksheet_Drawing_Shadow();
139 // Set image index
140 self::$imageCounter++;
141 $this->imageIndex = self::$imageCounter;
145 * Get image index
147 * @return int
149 public function getImageIndex()
151 return $this->imageIndex;
155 * Get Name
157 * @return string
159 public function getName()
161 return $this->name;
165 * Set Name
167 * @param string $pValue
168 * @return PHPExcel_Worksheet_BaseDrawing
170 public function setName($pValue = '')
172 $this->name = $pValue;
173 return $this;
177 * Get Description
179 * @return string
181 public function getDescription()
183 return $this->description;
187 * Set Description
189 * @param string $pValue
190 * @return PHPExcel_Worksheet_BaseDrawing
192 public function setDescription($pValue = '')
194 $this->description = $pValue;
195 return $this;
199 * Get Worksheet
201 * @return PHPExcel_Worksheet
203 public function getWorksheet()
205 return $this->worksheet;
209 * Set Worksheet
211 * @param PHPExcel_Worksheet $pValue
212 * @param bool $pOverrideOld If a Worksheet has already been assigned, overwrite it and remove image from old Worksheet?
213 * @throws PHPExcel_Exception
214 * @return PHPExcel_Worksheet_BaseDrawing
216 public function setWorksheet(PHPExcel_Worksheet $pValue = null, $pOverrideOld = false)
218 if (is_null($this->worksheet)) {
219 // Add drawing to PHPExcel_Worksheet
220 $this->worksheet = $pValue;
221 $this->worksheet->getCell($this->coordinates);
222 $this->worksheet->getDrawingCollection()->append($this);
223 } else {
224 if ($pOverrideOld) {
225 // Remove drawing from old PHPExcel_Worksheet
226 $iterator = $this->worksheet->getDrawingCollection()->getIterator();
228 while ($iterator->valid()) {
229 if ($iterator->current()->getHashCode() == $this->getHashCode()) {
230 $this->worksheet->getDrawingCollection()->offsetUnset($iterator->key());
231 $this->worksheet = null;
232 break;
236 // Set new PHPExcel_Worksheet
237 $this->setWorksheet($pValue);
238 } else {
239 throw new PHPExcel_Exception("A PHPExcel_Worksheet has already been assigned. Drawings can only exist on one PHPExcel_Worksheet.");
242 return $this;
246 * Get Coordinates
248 * @return string
250 public function getCoordinates()
252 return $this->coordinates;
256 * Set Coordinates
258 * @param string $pValue
259 * @return PHPExcel_Worksheet_BaseDrawing
261 public function setCoordinates($pValue = 'A1')
263 $this->coordinates = $pValue;
264 return $this;
268 * Get OffsetX
270 * @return int
272 public function getOffsetX()
274 return $this->offsetX;
278 * Set OffsetX
280 * @param int $pValue
281 * @return PHPExcel_Worksheet_BaseDrawing
283 public function setOffsetX($pValue = 0)
285 $this->offsetX = $pValue;
286 return $this;
290 * Get OffsetY
292 * @return int
294 public function getOffsetY()
296 return $this->offsetY;
300 * Set OffsetY
302 * @param int $pValue
303 * @return PHPExcel_Worksheet_BaseDrawing
305 public function setOffsetY($pValue = 0)
307 $this->offsetY = $pValue;
308 return $this;
312 * Get Width
314 * @return int
316 public function getWidth()
318 return $this->width;
322 * Set Width
324 * @param int $pValue
325 * @return PHPExcel_Worksheet_BaseDrawing
327 public function setWidth($pValue = 0)
329 // Resize proportional?
330 if ($this->resizeProportional && $pValue != 0) {
331 $ratio = $this->height / ($this->width != 0 ? $this->width : 1);
332 $this->height = round($ratio * $pValue);
335 // Set width
336 $this->width = $pValue;
338 return $this;
342 * Get Height
344 * @return int
346 public function getHeight()
348 return $this->height;
352 * Set Height
354 * @param int $pValue
355 * @return PHPExcel_Worksheet_BaseDrawing
357 public function setHeight($pValue = 0)
359 // Resize proportional?
360 if ($this->resizeProportional && $pValue != 0) {
361 $ratio = $this->width / ($this->height != 0 ? $this->height : 1);
362 $this->width = round($ratio * $pValue);
365 // Set height
366 $this->height = $pValue;
368 return $this;
372 * Set width and height with proportional resize
373 * Example:
374 * <code>
375 * $objDrawing->setResizeProportional(true);
376 * $objDrawing->setWidthAndHeight(160,120);
377 * </code>
379 * @author Vincent@luo MSN:kele_100@hotmail.com
380 * @param int $width
381 * @param int $height
382 * @return PHPExcel_Worksheet_BaseDrawing
384 public function setWidthAndHeight($width = 0, $height = 0)
386 $xratio = $width / ($this->width != 0 ? $this->width : 1);
387 $yratio = $height / ($this->height != 0 ? $this->height : 1);
388 if ($this->resizeProportional && !($width == 0 || $height == 0)) {
389 if (($xratio * $this->height) < $height) {
390 $this->height = ceil($xratio * $this->height);
391 $this->width = $width;
392 } else {
393 $this->width = ceil($yratio * $this->width);
394 $this->height = $height;
396 } else {
397 $this->width = $width;
398 $this->height = $height;
401 return $this;
405 * Get ResizeProportional
407 * @return boolean
409 public function getResizeProportional()
411 return $this->resizeProportional;
415 * Set ResizeProportional
417 * @param boolean $pValue
418 * @return PHPExcel_Worksheet_BaseDrawing
420 public function setResizeProportional($pValue = true)
422 $this->resizeProportional = $pValue;
423 return $this;
427 * Get Rotation
429 * @return int
431 public function getRotation()
433 return $this->rotation;
437 * Set Rotation
439 * @param int $pValue
440 * @return PHPExcel_Worksheet_BaseDrawing
442 public function setRotation($pValue = 0)
444 $this->rotation = $pValue;
445 return $this;
449 * Get Shadow
451 * @return PHPExcel_Worksheet_Drawing_Shadow
453 public function getShadow()
455 return $this->shadow;
459 * Set Shadow
461 * @param PHPExcel_Worksheet_Drawing_Shadow $pValue
462 * @throws PHPExcel_Exception
463 * @return PHPExcel_Worksheet_BaseDrawing
465 public function setShadow(PHPExcel_Worksheet_Drawing_Shadow $pValue = null)
467 $this->shadow = $pValue;
468 return $this;
472 * Get hash code
474 * @return string Hash code
476 public function getHashCode()
478 return md5(
479 $this->name .
480 $this->description .
481 $this->worksheet->getHashCode() .
482 $this->coordinates .
483 $this->offsetX .
484 $this->offsetY .
485 $this->width .
486 $this->height .
487 $this->rotation .
488 $this->shadow->getHashCode() .
489 __CLASS__
494 * Implement PHP __clone to create a deep clone, not just a shallow copy.
496 public function __clone()
498 $vars = get_object_vars($this);
499 foreach ($vars as $key => $value) {
500 if (is_object($value)) {
501 $this->$key = clone $value;
502 } else {
503 $this->$key = $value;