ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
BaseDrawing.php
Go to the documentation of this file.
1 <?php
2 
4 
8 
9 class BaseDrawing implements IComparable
10 {
16  private static $imageCounter = 0;
17 
23  private $imageIndex = 0;
24 
30  protected $name;
31 
37  protected $description;
38 
44  protected $worksheet;
45 
51  protected $coordinates;
52 
58  protected $offsetX;
59 
65  protected $offsetY;
66 
72  protected $width;
73 
79  protected $height;
80 
87 
93  protected $rotation;
94 
100  protected $shadow;
101 
107  private $hyperlink;
108 
112  public function __construct()
113  {
114  // Initialise values
115  $this->name = '';
116  $this->description = '';
117  $this->worksheet = null;
118  $this->coordinates = 'A1';
119  $this->offsetX = 0;
120  $this->offsetY = 0;
121  $this->width = 0;
122  $this->height = 0;
123  $this->resizeProportional = true;
124  $this->rotation = 0;
125  $this->shadow = new Drawing\Shadow();
126 
127  // Set image index
128  ++self::$imageCounter;
129  $this->imageIndex = self::$imageCounter;
130  }
131 
137  public function getImageIndex()
138  {
139  return $this->imageIndex;
140  }
141 
147  public function getName()
148  {
149  return $this->name;
150  }
151 
159  public function setName($pValue)
160  {
161  $this->name = $pValue;
162 
163  return $this;
164  }
165 
171  public function getDescription()
172  {
173  return $this->description;
174  }
175 
183  public function setDescription($description)
184  {
185  $this->description = $description;
186 
187  return $this;
188  }
189 
195  public function getWorksheet()
196  {
197  return $this->worksheet;
198  }
199 
208  public function setWorksheet(?Worksheet $pValue = null, $pOverrideOld = false)
209  {
210  if ($this->worksheet === null) {
211  // Add drawing to \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet
212  $this->worksheet = $pValue;
213  $this->worksheet->getCell($this->coordinates);
214  $this->worksheet->getDrawingCollection()->append($this);
215  } else {
216  if ($pOverrideOld) {
217  // Remove drawing from old \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet
218  $iterator = $this->worksheet->getDrawingCollection()->getIterator();
219 
220  while ($iterator->valid()) {
221  if ($iterator->current()->getHashCode() === $this->getHashCode()) {
222  $this->worksheet->getDrawingCollection()->offsetUnset($iterator->key());
223  $this->worksheet = null;
224 
225  break;
226  }
227  }
228 
229  // Set new \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet
230  $this->setWorksheet($pValue);
231  } else {
232  throw new PhpSpreadsheetException('A Worksheet has already been assigned. Drawings can only exist on one \\PhpOffice\\PhpSpreadsheet\\Worksheet.');
233  }
234  }
235 
236  return $this;
237  }
238 
244  public function getCoordinates()
245  {
246  return $this->coordinates;
247  }
248 
256  public function setCoordinates($pValue)
257  {
258  $this->coordinates = $pValue;
259 
260  return $this;
261  }
262 
268  public function getOffsetX()
269  {
270  return $this->offsetX;
271  }
272 
280  public function setOffsetX($pValue)
281  {
282  $this->offsetX = $pValue;
283 
284  return $this;
285  }
286 
292  public function getOffsetY()
293  {
294  return $this->offsetY;
295  }
296 
304  public function setOffsetY($pValue)
305  {
306  $this->offsetY = $pValue;
307 
308  return $this;
309  }
310 
316  public function getWidth()
317  {
318  return $this->width;
319  }
320 
328  public function setWidth($pValue)
329  {
330  // Resize proportional?
331  if ($this->resizeProportional && $pValue != 0) {
332  $ratio = $this->height / ($this->width != 0 ? $this->width : 1);
333  $this->height = (int) round($ratio * $pValue);
334  }
335 
336  // Set width
337  $this->width = $pValue;
338 
339  return $this;
340  }
341 
347  public function getHeight()
348  {
349  return $this->height;
350  }
351 
359  public function setHeight($pValue)
360  {
361  // Resize proportional?
362  if ($this->resizeProportional && $pValue != 0) {
363  $ratio = $this->width / ($this->height != 0 ? $this->height : 1);
364  $this->width = (int) round($ratio * $pValue);
365  }
366 
367  // Set height
368  $this->height = $pValue;
369 
370  return $this;
371  }
372 
389  public function setWidthAndHeight($width, $height)
390  {
391  $xratio = $width / ($this->width != 0 ? $this->width : 1);
392  $yratio = $height / ($this->height != 0 ? $this->height : 1);
393  if ($this->resizeProportional && !($width == 0 || $height == 0)) {
394  if (($xratio * $this->height) < $height) {
395  $this->height = (int) ceil($xratio * $this->height);
396  $this->width = $width;
397  } else {
398  $this->width = (int) ceil($yratio * $this->width);
399  $this->height = $height;
400  }
401  } else {
402  $this->width = $width;
403  $this->height = $height;
404  }
405 
406  return $this;
407  }
408 
414  public function getResizeProportional()
415  {
417  }
418 
426  public function setResizeProportional($pValue)
427  {
428  $this->resizeProportional = $pValue;
429 
430  return $this;
431  }
432 
438  public function getRotation()
439  {
440  return $this->rotation;
441  }
442 
450  public function setRotation($pValue)
451  {
452  $this->rotation = $pValue;
453 
454  return $this;
455  }
456 
462  public function getShadow()
463  {
464  return $this->shadow;
465  }
466 
474  public function setShadow(?Drawing\Shadow $pValue = null)
475  {
476  $this->shadow = $pValue;
477 
478  return $this;
479  }
480 
486  public function getHashCode()
487  {
488  return md5(
489  $this->name .
490  $this->description .
491  $this->worksheet->getHashCode() .
492  $this->coordinates .
493  $this->offsetX .
494  $this->offsetY .
495  $this->width .
496  $this->height .
497  $this->rotation .
498  $this->shadow->getHashCode() .
499  __CLASS__
500  );
501  }
502 
506  public function __clone()
507  {
508  $vars = get_object_vars($this);
509  foreach ($vars as $key => $value) {
510  if ($key == 'worksheet') {
511  $this->worksheet = null;
512  } elseif (is_object($value)) {
513  $this->$key = clone $value;
514  } else {
515  $this->$key = $value;
516  }
517  }
518  }
519 
520  public function setHyperlink(?Hyperlink $pHyperlink = null): void
521  {
522  $this->hyperlink = $pHyperlink;
523  }
524 
528  public function getHyperlink()
529  {
530  return $this->hyperlink;
531  }
532 }
setWorksheet(?Worksheet $pValue=null, $pOverrideOld=false)
Set Worksheet.
setDescription($description)
Set Description.
__clone()
Implement PHP __clone to create a deep clone, not just a shallow copy.
setShadow(?Drawing\Shadow $pValue=null)
Set Shadow.
setWidthAndHeight($width, $height)
Set width and height with proportional resize.
setHyperlink(?Hyperlink $pHyperlink=null)
getResizeProportional()
Get ResizeProportional.
$key
Definition: croninfo.php:18
setResizeProportional($pValue)
Set ResizeProportional.