ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
Fill.php
Go to the documentation of this file.
1 <?php
30 if (!defined('PHPEXCEL_ROOT')) {
34  define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
35 }
36 
38 require_once PHPEXCEL_ROOT . 'PHPExcel/Style/Color.php';
39 
41 require_once PHPEXCEL_ROOT . 'PHPExcel/IComparable.php';
42 
43 
52 {
53  /* Fill types */
54  const FILL_NONE = 'none';
55  const FILL_SOLID = 'solid';
56  const FILL_GRADIENT_LINEAR = 'linear';
57  const FILL_GRADIENT_PATH = 'path';
58  const FILL_PATTERN_DARKDOWN = 'darkDown';
59  const FILL_PATTERN_DARKGRAY = 'darkGray';
60  const FILL_PATTERN_DARKGRID = 'darkGrid';
61  const FILL_PATTERN_DARKHORIZONTAL = 'darkHorizontal';
62  const FILL_PATTERN_DARKTRELLIS = 'darkTrellis';
63  const FILL_PATTERN_DARKUP = 'darkUp';
64  const FILL_PATTERN_DARKVERTICAL = 'darkVertical';
65  const FILL_PATTERN_GRAY0625 = 'gray0625';
66  const FILL_PATTERN_GRAY125 = 'gray125';
67  const FILL_PATTERN_LIGHTDOWN = 'lightDown';
68  const FILL_PATTERN_LIGHTGRAY = 'lightGray';
69  const FILL_PATTERN_LIGHTGRID = 'lightGrid';
70  const FILL_PATTERN_LIGHTHORIZONTAL = 'lightHorizontal';
71  const FILL_PATTERN_LIGHTTRELLIS = 'lightTrellis';
72  const FILL_PATTERN_LIGHTUP = 'lightUp';
73  const FILL_PATTERN_LIGHTVERTICAL = 'lightVertical';
74  const FILL_PATTERN_MEDIUMGRAY = 'mediumGray';
75 
81  private $_fillType;
82 
88  private $_rotation;
89 
95  private $_startColor;
96 
102  private $_endColor;
103 
110 
116  private $_isSupervisor;
117 
123  private $_parent;
124 
128  public function __construct($isSupervisor = false)
129  {
130  // Supervisor?
131  $this->_isSupervisor = $isSupervisor;
132 
133  // Initialise values
134  $this->_fillType = PHPExcel_Style_Fill::FILL_NONE;
135  $this->_rotation = 0;
136  $this->_startColor = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_WHITE, $isSupervisor);
137  $this->_endColor = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLACK, $isSupervisor);
138 
139  // bind parent if we are a supervisor
140  if ($isSupervisor) {
141  $this->_startColor->bindParent($this, '_startColor');
142  $this->_endColor->bindParent($this, '_endColor');
143  }
144  }
145 
152  public function bindParent($parent)
153  {
154  $this->_parent = $parent;
155  return $this;
156  }
157 
163  public function getIsSupervisor()
164  {
165  return $this->_isSupervisor;
166  }
167 
174  public function getSharedComponent()
175  {
176  return $this->_parent->getSharedComponent()->getFill();
177  }
178 
184  public function getActiveSheet()
185  {
186  return $this->_parent->getActiveSheet();
187  }
188 
195  public function getXSelectedCells()
196  {
197  return $this->getActiveSheet()->getXSelectedCells();
198  }
199 
206  public function getXActiveCell()
207  {
208  return $this->getActiveSheet()->getXActiveCell();
209  }
210 
217  public function getStyleArray($array)
218  {
219  return array('fill' => $array);
220  }
221 
244  public function applyFromArray($pStyles = null) {
245  if (is_array($pStyles)) {
246  if ($this->_isSupervisor) {
247  $this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
248  } else {
249  if (array_key_exists('type', $pStyles)) {
250  $this->setFillType($pStyles['type']);
251  }
252  if (array_key_exists('rotation', $pStyles)) {
253  $this->setRotation($pStyles['rotation']);
254  }
255  if (array_key_exists('startcolor', $pStyles)) {
256  $this->getStartColor()->applyFromArray($pStyles['startcolor']);
257  }
258  if (array_key_exists('endcolor', $pStyles)) {
259  $this->getEndColor()->applyFromArray($pStyles['endcolor']);
260  }
261  if (array_key_exists('color', $pStyles)) {
262  $this->getStartColor()->applyFromArray($pStyles['color']);
263  }
264  }
265  } else {
266  throw new Exception("Invalid style array passed.");
267  }
268  return $this;
269  }
270 
276  public function getFillType() {
277  if ($this->_isSupervisor) {
278  return $this->getSharedComponent()->getFillType();
279  }
280  return $this->_fillType;
281  }
282 
289  public function setFillType($pValue = PHPExcel_Style_Fill::FILL_NONE) {
290  if ($this->_isSupervisor) {
291  $styleArray = $this->getStyleArray(array('type' => $pValue));
292  $this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray);
293  } else {
294  $this->_fillType = $pValue;
295  }
296  return $this;
297  }
298 
304  public function getRotation() {
305  if ($this->_isSupervisor) {
306  return $this->getSharedComponent()->getRotation();
307  }
308  return $this->_rotation;
309  }
310 
317  public function setRotation($pValue = 0) {
318  if ($this->_isSupervisor) {
319  $styleArray = $this->getStyleArray(array('rotation' => $pValue));
320  $this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray);
321  } else {
322  $this->_rotation = $pValue;
323  }
324  return $this;
325  }
326 
332  public function getStartColor() {
333  return $this->_startColor;
334  }
335 
343  public function setStartColor(PHPExcel_Style_Color $pValue = null) {
344  // make sure parameter is a real color and not a supervisor
345  $color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue;
346 
347  if ($this->_isSupervisor) {
348  $styleArray = $this->getStartColor()->getStyleArray(array('argb' => $color->getARGB()));
349  $this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray);
350  } else {
351  $this->_startColor = $color;
352  }
353  return $this;
354  }
355 
361  public function getEndColor() {
362  return $this->_endColor;
363  }
364 
372  public function setEndColor(PHPExcel_Style_Color $pValue = null) {
373  // make sure parameter is a real color and not a supervisor
374  $color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue;
375 
376  if ($this->_isSupervisor) {
377  $styleArray = $this->getEndColor()->getStyleArray(array('argb' => $color->getARGB()));
378  $this->getActiveSheet()->getStyle($this->getXSelectedCells())->applyFromArray($styleArray);
379  } else {
380  $this->_endColor = $color;
381  }
382  return $this;
383  }
384 
390  public function getHashCode() {
391  if ($this->_isSupervisor) {
392  return $this->getSharedComponent()->getHashCode();
393  }
394  return md5(
395  $this->getFillType()
396  . $this->getRotation()
397  . $this->getStartColor()->getHashCode()
398  . $this->getEndColor()->getHashCode()
399  . __CLASS__
400  );
401  }
402 
408  private $_hashIndex;
409 
418  public function getHashIndex() {
419  return $this->_hashIndex;
420  }
421 
430  public function setHashIndex($value) {
431  $this->_hashIndex = $value;
432  }
433 
437  public function __clone() {
438  $vars = get_object_vars($this);
439  foreach ($vars as $key => $value) {
440  if (is_object($value)) {
441  $this->$key = clone $value;
442  } else {
443  $this->$key = $value;
444  }
445  }
446  }
447 }