ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
Fill.php
Go to the documentation of this file.
1 <?php
37 {
38  /* Fill types */
39  const FILL_NONE = 'none';
40  const FILL_SOLID = 'solid';
41  const FILL_GRADIENT_LINEAR = 'linear';
42  const FILL_GRADIENT_PATH = 'path';
43  const FILL_PATTERN_DARKDOWN = 'darkDown';
44  const FILL_PATTERN_DARKGRAY = 'darkGray';
45  const FILL_PATTERN_DARKGRID = 'darkGrid';
46  const FILL_PATTERN_DARKHORIZONTAL = 'darkHorizontal';
47  const FILL_PATTERN_DARKTRELLIS = 'darkTrellis';
48  const FILL_PATTERN_DARKUP = 'darkUp';
49  const FILL_PATTERN_DARKVERTICAL = 'darkVertical';
50  const FILL_PATTERN_GRAY0625 = 'gray0625';
51  const FILL_PATTERN_GRAY125 = 'gray125';
52  const FILL_PATTERN_LIGHTDOWN = 'lightDown';
53  const FILL_PATTERN_LIGHTGRAY = 'lightGray';
54  const FILL_PATTERN_LIGHTGRID = 'lightGrid';
55  const FILL_PATTERN_LIGHTHORIZONTAL = 'lightHorizontal';
56  const FILL_PATTERN_LIGHTTRELLIS = 'lightTrellis';
57  const FILL_PATTERN_LIGHTUP = 'lightUp';
58  const FILL_PATTERN_LIGHTVERTICAL = 'lightVertical';
59  const FILL_PATTERN_MEDIUMGRAY = 'mediumGray';
60 
67 
73  private $_rotation = 0;
74 
80  private $_startColor;
81 
87  private $_endColor;
88 
95 
101  private $_isSupervisor;
102 
108  private $_parent;
109 
113  public function __construct($isSupervisor = false)
114  {
115  // Supervisor?
116  $this->_isSupervisor = $isSupervisor;
117 
118  // Initialise values
119  $this->_startColor = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_WHITE, $isSupervisor);
120  $this->_endColor = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLACK, $isSupervisor);
121 
122  // bind parent if we are a supervisor
123  if ($isSupervisor) {
124  $this->_startColor->bindParent($this, '_startColor');
125  $this->_endColor->bindParent($this, '_endColor');
126  }
127  }
128 
135  public function bindParent($parent)
136  {
137  $this->_parent = $parent;
138  return $this;
139  }
140 
146  public function getIsSupervisor()
147  {
148  return $this->_isSupervisor;
149  }
150 
157  public function getSharedComponent()
158  {
159  return $this->_parent->getSharedComponent()->getFill();
160  }
161 
167  public function getActiveSheet()
168  {
169  return $this->_parent->getActiveSheet();
170  }
171 
178  public function getSelectedCells()
179  {
180  return $this->getActiveSheet()->getSelectedCells();
181  }
182 
189  public function getActiveCell()
190  {
191  return $this->getActiveSheet()->getActiveCell();
192  }
193 
200  public function getStyleArray($array)
201  {
202  return array('fill' => $array);
203  }
204 
227  public function applyFromArray($pStyles = null) {
228  if (is_array($pStyles)) {
229  if ($this->_isSupervisor) {
230  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($this->getStyleArray($pStyles));
231  } else {
232  if (array_key_exists('type', $pStyles)) {
233  $this->setFillType($pStyles['type']);
234  }
235  if (array_key_exists('rotation', $pStyles)) {
236  $this->setRotation($pStyles['rotation']);
237  }
238  if (array_key_exists('startcolor', $pStyles)) {
239  $this->getStartColor()->applyFromArray($pStyles['startcolor']);
240  }
241  if (array_key_exists('endcolor', $pStyles)) {
242  $this->getEndColor()->applyFromArray($pStyles['endcolor']);
243  }
244  if (array_key_exists('color', $pStyles)) {
245  $this->getStartColor()->applyFromArray($pStyles['color']);
246  }
247  }
248  } else {
249  throw new Exception("Invalid style array passed.");
250  }
251  return $this;
252  }
253 
259  public function getFillType() {
260  if ($this->_isSupervisor) {
261  return $this->getSharedComponent()->getFillType();
262  }
263  return $this->_fillType;
264  }
265 
272  public function setFillType($pValue = PHPExcel_Style_Fill::FILL_NONE) {
273  if ($this->_isSupervisor) {
274  $styleArray = $this->getStyleArray(array('type' => $pValue));
275  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
276  } else {
277  $this->_fillType = $pValue;
278  }
279  return $this;
280  }
281 
287  public function getRotation() {
288  if ($this->_isSupervisor) {
289  return $this->getSharedComponent()->getRotation();
290  }
291  return $this->_rotation;
292  }
293 
300  public function setRotation($pValue = 0) {
301  if ($this->_isSupervisor) {
302  $styleArray = $this->getStyleArray(array('rotation' => $pValue));
303  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
304  } else {
305  $this->_rotation = $pValue;
306  }
307  return $this;
308  }
309 
315  public function getStartColor() {
316  return $this->_startColor;
317  }
318 
326  public function setStartColor(PHPExcel_Style_Color $pValue = null) {
327  // make sure parameter is a real color and not a supervisor
328  $color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue;
329 
330  if ($this->_isSupervisor) {
331  $styleArray = $this->getStartColor()->getStyleArray(array('argb' => $color->getARGB()));
332  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
333  } else {
334  $this->_startColor = $color;
335  }
336  return $this;
337  }
338 
344  public function getEndColor() {
345  return $this->_endColor;
346  }
347 
355  public function setEndColor(PHPExcel_Style_Color $pValue = null) {
356  // make sure parameter is a real color and not a supervisor
357  $color = $pValue->getIsSupervisor() ? $pValue->getSharedComponent() : $pValue;
358 
359  if ($this->_isSupervisor) {
360  $styleArray = $this->getEndColor()->getStyleArray(array('argb' => $color->getARGB()));
361  $this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
362  } else {
363  $this->_endColor = $color;
364  }
365  return $this;
366  }
367 
373  public function getHashCode() {
374  if ($this->_isSupervisor) {
375  return $this->getSharedComponent()->getHashCode();
376  }
377  return md5(
378  $this->getFillType()
379  . $this->getRotation()
380  . $this->getStartColor()->getHashCode()
381  . $this->getEndColor()->getHashCode()
382  . __CLASS__
383  );
384  }
385 
389  public function __clone() {
390  $vars = get_object_vars($this);
391  foreach ($vars as $key => $value) {
392  if ((is_object($value)) && ($key != '_parent')) {
393  $this->$key = clone $value;
394  } else {
395  $this->$key = $value;
396  }
397  }
398  }
399 }